package com.pj.project.app_menu;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.pj.project4sp.SP;
import com.pj.utils.sg.AjaxJson;
import com.pj.utils.so.SoMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * Controller: app_menu -- app菜单管理
 * @author qzy 
 */
@RestController
@RequestMapping("/AppMenu/")
public class PcMenuController {

	/** 底层 Service 对象 */
	@Autowired
	AppMenuService appMenuService;

	/** 增 */  
	@RequestMapping("add")
	@SaCheckPermission(AppMenu.PERMISSION_CODE_ADD)
	public AjaxJson add(AppMenu a){
		appMenuService.add(a);
		a = appMenuService.getById(SP.publicMapper.getPrimarykey());
		return AjaxJson.getSuccessData(a);
	}

	/** 删 */  
	@RequestMapping("delete")
	@SaCheckPermission(AppMenu.PERMISSION_CODE_DEL)
	public AjaxJson delete(Long id){
		 appMenuService.delete(id);
		return AjaxJson.getSuccess();
	}
	
	/** 删 - 根据id列表 */  
	@RequestMapping("deleteByIds")
	@SaCheckPermission(AppMenu.PERMISSION_CODE_DEL)
	public AjaxJson deleteByIds(){
		List<Long> ids = SoMap.getRequestSoMap().getListByComma("ids", long.class); 
		int line = SP.publicMapper.deleteByIds(AppMenu.TABLE_NAME, ids);
		return AjaxJson.getByLine(line);
	}
	
	/** 改 */  
	@RequestMapping("update")
	@SaCheckPermission(AppMenu.PERMISSION_CODE_EDIT)
	public AjaxJson update(AppMenu a){
		appMenuService.update(a);
		return AjaxJson.getSuccess();
	}

	/** 查 - 根据id */  
	@RequestMapping("getById")
		@SaCheckPermission(AppMenu.PERMISSION_CODE)
	public AjaxJson getById(Long id){
		AppMenu a = appMenuService.getById(id);
		return AjaxJson.getSuccessData(a);
	}

	/** 查集合 - 根据条件（参数为空时代表忽略指定条件） */  
	@RequestMapping("getList")
		@SaCheckPermission(AppMenu.PERMISSION_CODE)
	public AjaxJson getList() {
		SoMap so = SoMap.getRequestSoMap();
		List<AppMenu> list = appMenuService.getList(so.startPage());
		return AjaxJson.getPageData(so.getDataCount(), list);
	}
	
	
	
	/** 改 - 状态(0=禁用,1=启用) */  
	@RequestMapping("updateEnable")
	@SaCheckPermission(AppMenu.PERMISSION_CODE_EDIT)
	public AjaxJson updateEnable(Long id, String value){
		int line = SP.publicMapper.updateColumnById(AppMenu.TABLE_NAME, "enable", value, id);
		return AjaxJson.getByLine(line);
	}
	
	/** 改 - 是否认证后访问(0=否,1=是) */  
	@RequestMapping("updateAuth")
	@SaCheckPermission(AppMenu.PERMISSION_CODE_EDIT)
	public AjaxJson updateAuth(Long id, String value){
		int line = SP.publicMapper.updateColumnById(AppMenu.TABLE_NAME, "auth", value, id);
		return AjaxJson.getByLine(line);
	}
	
	

	
	
	

}
