package com.chinaitop.depot.system.controller; import com.chinaitop.depot.system.model.FuncInfo; import com.chinaitop.depot.system.model.FuncInfoExample; import com.chinaitop.depot.system.model.FuncInfoExample.Criteria; import com.chinaitop.depot.system.service.FuncInfoService; import com.chinaitop.depot.system.service.OrgInfoService; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 功能信息控制类 * @author xueenxi * */ @RestController @RequestMapping(value="/funcInfo") @Api(description = "功能信息管理类") public class FuncInfoController { @Resource private FuncInfoService funcInfoService; @Resource private OrgInfoService orgInfoService; /** * 查找功能信息 * @param pageNum 页码 * @param pageSize 每页条数 * @return */ @RequestMapping(value="/getFunc", method = RequestMethod.GET) @ApiOperation(value="功能列表", notes = "查询功能列表") @ApiImplicitParams({ @ApiImplicitParam(name = "funcName", value = "功能名称", paramType = "query") }) public PageInfo getFuncInfo(Integer pageNum, Integer pageSize, Integer parentId, String funcName) { FuncInfoExample example = new FuncInfoExample(); Criteria criteria = example.createCriteria(); if (parentId != null) { criteria.andParentIdEqualTo(parentId); } if (StringUtils.isNotBlank(funcName)) { criteria.andFuncNameLike("%" + funcName + "%"); } if (pageNum!=null && pageSize!=null) { PageHelper.startPage(pageNum, pageSize); } List list = funcInfoService.queryByExample(example); PageInfo pageInfo = new PageInfo(list); return pageInfo; } /** * 查找功能信息 * @return */ @RequestMapping(value="/getFuncList", method = RequestMethod.GET) @ApiOperation(value="功能列表", notes = "查询功能列表") public List getFuncInfo(String funcName) { FuncInfoExample example = new FuncInfoExample(); Criteria criteria = example.createCriteria(); if (StringUtils.isNotBlank(funcName)) { criteria.andFuncNameLike("%" + funcName + "%"); } return funcInfoService.queryByExample(example); } /** * 根据编号查找功能信息 * @param funcId 编号 * @return FuncInfo 功能信息 */ @RequestMapping(value="/edit", method = RequestMethod.GET) @ApiOperation(value="功能编辑", notes = "根据功能编号获取功能信息") @ApiImplicitParams({ @ApiImplicitParam(name = "funcId", value = "功能编号", paramType = "query") }) public FuncInfo edit(Integer funcId) { FuncInfo funcInfo = new FuncInfo(); if (funcId != null) { funcInfo = funcInfoService.findById(funcId); } return funcInfo; } /** * 保存功能信息 * @param funcInfoJson 功能信息json串 * @return * @throws JsonParseException * @throws JsonMappingException * @throws IOException */ @RequestMapping(value="/save", method = RequestMethod.POST) @ApiOperation(value="保存功能信息", notes = "保存功能信息,新增或者修改") @ApiImplicitParams({ @ApiImplicitParam(name = "funcInfoJson", value = "功能信息JSON串", paramType = "form") }) public Map save(String funcInfoJson) throws JsonParseException, JsonMappingException, IOException { Map modelMap = new HashMap<>(); // JSON字符串转对象 ObjectMapper mapper = new ObjectMapper(); FuncInfo funcInfo = (FuncInfo)mapper.readValue(funcInfoJson, FuncInfo.class); if (funcInfo.getFuncId() == null) { funcInfoService.add(funcInfo); } else { funcInfoService.update(funcInfo); } modelMap.put("status", "success"); return modelMap; } /** * 根据编号删除功能信息 * @param funcId 功能编号 * @return */ @RequestMapping(value="/remove", method = RequestMethod.POST) @ApiOperation(value="删除功能", notes = "按功能编号删除功能") @ApiImplicitParams({ @ApiImplicitParam(name = "funcId", value = "功能编号", paramType = "form") }) public Map remove(Integer funcId) { Map modelMap = new HashMap<>(); if (funcId != null) { funcInfoService.remove(funcId); } modelMap.put("status", "success"); return modelMap; } }