FuncInfoController.java 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. package com.chinaitop.depot.system.controller;
  2. import com.chinaitop.depot.system.model.FuncInfo;
  3. import com.chinaitop.depot.system.model.FuncInfoExample;
  4. import com.chinaitop.depot.system.model.FuncInfoExample.Criteria;
  5. import com.chinaitop.depot.system.service.FuncInfoService;
  6. import com.chinaitop.depot.system.service.OrgInfoService;
  7. import com.fasterxml.jackson.core.JsonParseException;
  8. import com.fasterxml.jackson.databind.JsonMappingException;
  9. import com.fasterxml.jackson.databind.ObjectMapper;
  10. import com.github.pagehelper.PageHelper;
  11. import com.github.pagehelper.PageInfo;
  12. import io.swagger.annotations.Api;
  13. import io.swagger.annotations.ApiImplicitParam;
  14. import io.swagger.annotations.ApiImplicitParams;
  15. import io.swagger.annotations.ApiOperation;
  16. import org.apache.commons.lang3.StringUtils;
  17. import org.springframework.web.bind.annotation.RequestMapping;
  18. import org.springframework.web.bind.annotation.RequestMethod;
  19. import org.springframework.web.bind.annotation.RestController;
  20. import javax.annotation.Resource;
  21. import javax.servlet.http.HttpServletRequest;
  22. import java.io.IOException;
  23. import java.util.HashMap;
  24. import java.util.List;
  25. import java.util.Map;
  26. /**
  27. * 功能信息控制类
  28. * @author xueenxi
  29. *
  30. */
  31. @RestController
  32. @RequestMapping(value="/funcInfo")
  33. @Api(description = "功能信息管理类")
  34. public class FuncInfoController {
  35. @Resource
  36. private FuncInfoService funcInfoService;
  37. @Resource
  38. private OrgInfoService orgInfoService;
  39. /**
  40. * 查找功能信息
  41. * @param pageNum 页码
  42. * @param pageSize 每页条数
  43. * @return
  44. */
  45. @RequestMapping(value="/getFunc", method = RequestMethod.GET)
  46. @ApiOperation(value="功能列表", notes = "查询功能列表")
  47. @ApiImplicitParams({
  48. @ApiImplicitParam(name = "funcName", value = "功能名称", paramType = "query")
  49. })
  50. public PageInfo<FuncInfo> getFuncInfo(Integer pageNum, Integer pageSize, Integer parentId, String funcName) {
  51. FuncInfoExample example = new FuncInfoExample();
  52. Criteria criteria = example.createCriteria();
  53. if (parentId != null) {
  54. criteria.andParentIdEqualTo(parentId);
  55. }
  56. if (StringUtils.isNotBlank(funcName)) {
  57. criteria.andFuncNameLike("%" + funcName + "%");
  58. }
  59. if (pageNum!=null && pageSize!=null) {
  60. PageHelper.startPage(pageNum, pageSize);
  61. }
  62. List<FuncInfo> list = funcInfoService.queryByExample(example);
  63. PageInfo<FuncInfo> pageInfo = new PageInfo<FuncInfo>(list);
  64. return pageInfo;
  65. }
  66. /**
  67. * 查找功能信息
  68. * @return
  69. */
  70. @RequestMapping(value="/getFuncList", method = RequestMethod.GET)
  71. @ApiOperation(value="功能列表", notes = "查询功能列表")
  72. public List<FuncInfo> getFuncInfo(String funcName) {
  73. FuncInfoExample example = new FuncInfoExample();
  74. Criteria criteria = example.createCriteria();
  75. if (StringUtils.isNotBlank(funcName)) {
  76. criteria.andFuncNameLike("%" + funcName + "%");
  77. }
  78. return funcInfoService.queryByExample(example);
  79. }
  80. /**
  81. * 根据编号查找功能信息
  82. * @param funcId 编号
  83. * @return FuncInfo 功能信息
  84. */
  85. @RequestMapping(value="/edit", method = RequestMethod.GET)
  86. @ApiOperation(value="功能编辑", notes = "根据功能编号获取功能信息")
  87. @ApiImplicitParams({
  88. @ApiImplicitParam(name = "funcId", value = "功能编号", paramType = "query")
  89. })
  90. public FuncInfo edit(Integer funcId) {
  91. FuncInfo funcInfo = new FuncInfo();
  92. if (funcId != null) {
  93. funcInfo = funcInfoService.findById(funcId);
  94. }
  95. return funcInfo;
  96. }
  97. /**
  98. * 保存功能信息
  99. * @param funcInfoJson 功能信息json串
  100. * @return
  101. * @throws JsonParseException
  102. * @throws JsonMappingException
  103. * @throws IOException
  104. */
  105. @RequestMapping(value="/save", method = RequestMethod.POST)
  106. @ApiOperation(value="保存功能信息", notes = "保存功能信息,新增或者修改")
  107. @ApiImplicitParams({
  108. @ApiImplicitParam(name = "funcInfoJson", value = "功能信息JSON串", paramType = "form")
  109. })
  110. public Map<String, Object> save(String funcInfoJson) throws JsonParseException, JsonMappingException, IOException {
  111. Map<String, Object> modelMap = new HashMap<>();
  112. // JSON字符串转对象
  113. ObjectMapper mapper = new ObjectMapper();
  114. FuncInfo funcInfo = (FuncInfo)mapper.readValue(funcInfoJson, FuncInfo.class);
  115. if (funcInfo.getFuncId() == null) {
  116. funcInfoService.add(funcInfo);
  117. } else {
  118. funcInfoService.update(funcInfo);
  119. }
  120. modelMap.put("status", "success");
  121. return modelMap;
  122. }
  123. /**
  124. * 根据编号删除功能信息
  125. * @param funcId 功能编号
  126. * @return
  127. */
  128. @RequestMapping(value="/remove", method = RequestMethod.POST)
  129. @ApiOperation(value="删除功能", notes = "按功能编号删除功能")
  130. @ApiImplicitParams({
  131. @ApiImplicitParam(name = "funcId", value = "功能编号", paramType = "form")
  132. })
  133. public Map<String, Object> remove(Integer funcId) {
  134. Map<String, Object> modelMap = new HashMap<>();
  135. if (funcId != null) {
  136. funcInfoService.remove(funcId);
  137. }
  138. modelMap.put("status", "success");
  139. return modelMap;
  140. }
  141. }