DepartmentAllocationController.java 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. package com.ims.eval.controller;
  2. import cn.hutool.json.JSONArray;
  3. import cn.hutool.json.JSONUtil;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  6. import com.baomidou.mybatisplus.core.metadata.IPage;
  7. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  8. import com.ims.common.utils.StringUtils;
  9. import com.ims.eval.config.CustomException;
  10. import com.ims.eval.entity.EvaluationDept;
  11. import com.ims.eval.entity.dto.request.DeptDTO;
  12. import com.ims.eval.entity.dto.request.UserDTO;
  13. import com.ims.eval.entity.dto.result.R;
  14. import com.ims.eval.service.IEvaluationDeptService;
  15. import com.ims.eval.service.IUserService;
  16. import lombok.extern.slf4j.Slf4j;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.web.bind.annotation.*;
  19. import javax.servlet.http.HttpServletRequest;
  20. import java.util.*;
  21. /**
  22. * 考评部门配置
  23. *
  24. * @author hlf
  25. * @date 2023/7/14 16:54
  26. * 文件说明:
  27. */
  28. @Slf4j
  29. @RestController
  30. @RequestMapping("//evaluation-dept-allocation")
  31. public class DepartmentAllocationController {
  32. @Autowired
  33. private IEvaluationDeptService evaluationDeptService;
  34. @Autowired
  35. private HttpServletRequest request;
  36. @Autowired
  37. private IUserService userService;
  38. /**
  39. * 考评部门配置列表信息(分页)
  40. *
  41. * @param pageNum 当前记录起始索引
  42. * @param pageSize 每页显示记录数
  43. * @param deptName 部门名称
  44. * @param chargePersonName 部门领导名称
  45. * @return 结果
  46. */
  47. @GetMapping(value = "/list")
  48. public R list(
  49. @RequestParam(value = "pageNum") Integer pageNum,
  50. @RequestParam(value = "pageSize") Integer pageSize,
  51. @RequestParam(value = "deptName", required = false) String deptName,
  52. @RequestParam(value = "chargePersonName", required = false) String chargePersonName) {
  53. QueryWrapper<EvaluationDept> qw = new QueryWrapper<>();
  54. if (StringUtils.isNotEmpty(deptName)) {
  55. qw.lambda().like(EvaluationDept::getDeptName, deptName);
  56. }
  57. if (StringUtils.isNotEmpty(chargePersonName)) {
  58. qw.lambda().like(EvaluationDept::getChargePersonName, chargePersonName);
  59. }
  60. qw.lambda().orderByAsc(EvaluationDept::getSerialNumber);
  61. Page<EvaluationDept> page = new Page<>(pageNum, pageSize);
  62. IPage<EvaluationDept> list = evaluationDeptService.page(page, qw);
  63. return R.ok().data(list);
  64. }
  65. /**
  66. * 考评部门配置信息
  67. *
  68. * @return 结果
  69. */
  70. @GetMapping(value = "/listAll")
  71. public R listAll() {
  72. QueryWrapper<EvaluationDept> qw = new QueryWrapper<>();
  73. qw.lambda().eq(EvaluationDept::getJxjgkhsbType, "1");
  74. qw.lambda().orderByAsc(EvaluationDept::getSerialNumber);
  75. List<EvaluationDept> list = evaluationDeptService.list(qw);
  76. return R.ok().data(list);
  77. }
  78. /**
  79. * 新增/修改考评部门配置信息
  80. *
  81. * @param evaluationDept 考评部门配置实体
  82. * @return 结果
  83. */
  84. @PostMapping(value = "/save")
  85. public R addAll(@RequestBody EvaluationDept evaluationDept) {
  86. try {
  87. if (StringUtils.isEmpty(evaluationDept.getId())) {
  88. QueryWrapper<EvaluationDept> qw = new QueryWrapper<>();
  89. if (StringUtils.isNotEmpty(evaluationDept.getParentId())) {
  90. qw.lambda().eq(EvaluationDept::getParentId, evaluationDept.getParentId());
  91. }
  92. if (StringUtils.isNotEmpty(evaluationDept.getDeptId())) {
  93. qw.lambda().eq(EvaluationDept::getDeptId, evaluationDept.getDeptId());
  94. }
  95. EvaluationDept obj = evaluationDeptService.getOne(qw);
  96. if (obj != null) {
  97. return R.error("部门重复,请重新添加!");
  98. }
  99. }
  100. boolean b = evaluationDeptService.saveOrUpdate(evaluationDept);
  101. if (b) {
  102. return R.ok().data(b);
  103. } else {
  104. return R.error("保存失败!");
  105. }
  106. } catch (CustomException e) {
  107. return R.customError(e.getMessage()).data("失败!");
  108. }
  109. }
  110. /**
  111. * 获取部门领导
  112. *
  113. * @return 结果
  114. */
  115. @GetMapping(value = "/getDepartmentLeader/{id}")
  116. public R getDepartmentLeader(@PathVariable String id) {
  117. JSONObject jsonArr = userService.pageList(1, 500, id, "", "", "", "", "", request);
  118. JSONObject jsonArr1 = (JSONObject) jsonArr.get("data");
  119. JSONArray array = JSONUtil.parseArray(jsonArr1.get("records"));
  120. List<UserDTO> list = JSONUtil.toList(array, UserDTO.class);
  121. return R.ok().data(list);
  122. }
  123. /**
  124. * 批量删除考评部门配置信息
  125. *
  126. * @param ids 主键s
  127. * @return 结果
  128. */
  129. @PostMapping(value = "/removeAll/{ids}")
  130. public R deleteAll(@PathVariable("ids") String ids) {
  131. try {
  132. String[] strings = ids.split(",");
  133. boolean b = evaluationDeptService.removeByIds(Arrays.asList(strings));
  134. if (b) {
  135. return R.ok().data(b);
  136. } else {
  137. return R.error("删除失败!");
  138. }
  139. } catch (CustomException e) {
  140. return R.customError(e.getMessage()).data("失败!");
  141. }
  142. }
  143. /**
  144. * 人员假数据
  145. *
  146. * @return 结果
  147. */
  148. @GetMapping(value = "/getUser")
  149. public R getUser() {
  150. List<UserDTO> userList = new ArrayList<>();
  151. Map<String, String> map = new HashMap<>();
  152. map.put("bffe73e031d44e00a8c8506e317aa41f", "孙志廷");
  153. map.put("48063c851236d1347900e6e9667ac0d6", "云天宝");
  154. map.put("df2c3798f5b14994aac7eb3410cf1c69", "孙严冬");
  155. map.put("06a45127a25f49e798d13233f881b382", "李宝岩");
  156. map.put("53c5bb07e6834d928aea5f9d2f57aa7f", "任晓霞");
  157. map.put("972f3f68fac44c9b95c2e479bb3de815", "李金柱");
  158. map.put("b4ee5ccdec1941f889176e3d913b1994", "刘全");
  159. map.put("5014b41d06dd4b428348cbfcdf36c160", "宫广正");
  160. map.put("8cfbb27966264920b24635f95ca6b0a7", "孙纳新");
  161. map.put("f9305976eaab4edca55538238914b07c", "刘景春");
  162. map.put("34c57c2ad8184e9795b2a77501e97671", "车晔");
  163. map.put("5b7c61a5556742baa9018d17ee5f42c2", "杨建国");
  164. map.put("9ea19aa48cc1483b9efcf3210e50de4f", "陈宏");
  165. map.put("5eca483c13c94639bdfae0754c314164", "王颖聪");
  166. map.put("aa300762de524c27b9ca3439b76c9e26", "朱传兴");
  167. for (Map.Entry<String, String> entry : map.entrySet()) {
  168. UserDTO user = new UserDTO();
  169. user.setId(entry.getKey());
  170. user.setName(entry.getValue());
  171. userList.add(user);
  172. }
  173. return R.ok().data(userList);
  174. }
  175. /**
  176. * 部门假数据
  177. *
  178. * @return 结果
  179. */
  180. @GetMapping(value = "/getDept")
  181. public R getDept() {
  182. List<DeptDTO> deptList = new ArrayList<>();
  183. Map<String, String> map = new HashMap<>();
  184. map.put("23031004", "综合管理部(党委办公室)");
  185. map.put("23031015", "纪委办公室(党委巡察办)");
  186. map.put("23031006", "计划发展部");
  187. map.put("23031007", "市场营销部");
  188. map.put("23031008", "资本运营部(董事会办公室)");
  189. map.put("23031010", "财务部");
  190. map.put("23031005", "企业管理与法律事务部");
  191. map.put("23031023", "安全环保监察部");
  192. map.put("23031014", "生产调运部(调度中心)");
  193. map.put("23032496", "科技信息部");
  194. map.put("23031016", "审计部");
  195. map.put("23031018", "工会工作部");
  196. map.put("23031019", "采购与物资管理部");
  197. map.put("23031020", "国际业务部");
  198. map.put("23031022", "工程建设部");
  199. for (Map.Entry<String, String> entry : map.entrySet()) {
  200. DeptDTO dept = new DeptDTO();
  201. dept.setId(entry.getKey());
  202. dept.setName(entry.getValue());
  203. deptList.add(dept);
  204. }
  205. return R.ok().data(deptList);
  206. }
  207. /**
  208. * 子部门假数据
  209. *
  210. * @return 结果
  211. */
  212. @GetMapping(value = "/getSubdepartment/{id}")
  213. public R getSubdepartment(@PathVariable String id) {
  214. List<DeptDTO> deptList = new ArrayList<>();
  215. Map<String, String> map = new HashMap<>();
  216. if ("23031004".equals(id)) {
  217. map.put("11111111", "子部门1");
  218. map.put("22222222", "子部门2");
  219. map.put("33333333", "子部门3");
  220. map.put("44444444", "子部门4");
  221. }
  222. if ("23031015".equals(id)) {
  223. map.put("55555555", "子部门1");
  224. map.put("66666666", "子部门2");
  225. map.put("77777777", "子部门3");
  226. map.put("88888888", "子部门4");
  227. }
  228. for (Map.Entry<String, String> entry : map.entrySet()) {
  229. DeptDTO dept = new DeptDTO();
  230. dept.setId(entry.getKey());
  231. dept.setName(entry.getValue());
  232. deptList.add(dept);
  233. }
  234. return R.ok().data(deptList);
  235. }
  236. }