DepartmentAllocationController.java 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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.DeptAssessmentDeclaration;
  11. import com.ims.eval.entity.EvaluationDept;
  12. import com.ims.eval.entity.dto.request.UserDTO;
  13. import com.ims.eval.entity.dto.result.R;
  14. import com.ims.eval.service.IDeptAssessmentDeclarationService;
  15. import com.ims.eval.service.IEvaluationDeptService;
  16. import com.ims.eval.service.IUserService;
  17. import lombok.extern.slf4j.Slf4j;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.web.bind.annotation.*;
  20. import javax.servlet.http.HttpServletRequest;
  21. import java.util.ArrayList;
  22. import java.util.Arrays;
  23. import java.util.List;
  24. /**
  25. * 考评部门配置
  26. *
  27. * @author hlf
  28. * @date 2023/7/14 16:54
  29. * 文件说明:
  30. */
  31. @Slf4j
  32. @RestController
  33. @RequestMapping("//evaluation-dept-allocation")
  34. public class DepartmentAllocationController {
  35. @Autowired
  36. private IEvaluationDeptService evaluationDeptService;
  37. @Autowired
  38. private HttpServletRequest request;
  39. @Autowired
  40. private IUserService userService;
  41. @Autowired
  42. private IDeptAssessmentDeclarationService deptAssessmentDeclarationService;
  43. /**
  44. * 考评部门配置列表信息(分页)
  45. *
  46. * @param pageNum 当前记录起始索引
  47. * @param pageSize 每页显示记录数
  48. * @param deptName 部门名称
  49. * @param chargePersonName 部门领导名称
  50. * @return 结果
  51. */
  52. @GetMapping(value = "/list")
  53. public R list(
  54. @RequestParam(value = "pageNum") Integer pageNum,
  55. @RequestParam(value = "pageSize") Integer pageSize,
  56. @RequestParam(value = "deptName", required = false) String deptName,
  57. @RequestParam(value = "chargePersonName", required = false) String chargePersonName) {
  58. QueryWrapper<EvaluationDept> qw = new QueryWrapper<>();
  59. if (StringUtils.isNotEmpty(deptName)) {
  60. qw.lambda().like(EvaluationDept::getDeptName, deptName);
  61. }
  62. if (StringUtils.isNotEmpty(chargePersonName)) {
  63. qw.lambda().like(EvaluationDept::getChargePersonName, chargePersonName);
  64. }
  65. qw.lambda().orderByAsc(EvaluationDept::getSerialNumber);
  66. Page<EvaluationDept> page = new Page<>(pageNum, pageSize);
  67. IPage<EvaluationDept> list = evaluationDeptService.page(page, qw);
  68. return R.ok().data(list);
  69. }
  70. /**
  71. * 考评部门配置信息
  72. *
  73. * @return 结果
  74. */
  75. @GetMapping(value = "/listAll")
  76. public R listAll() {
  77. QueryWrapper<EvaluationDept> qw = new QueryWrapper<>();
  78. qw.lambda().eq(EvaluationDept::getJxjgkhsbType, "1");
  79. qw.lambda().orderByAsc(EvaluationDept::getSerialNumber);
  80. List<EvaluationDept> list = evaluationDeptService.list(qw);
  81. return R.ok().data(list);
  82. }
  83. /**
  84. * 新增/修改考评部门配置信息
  85. *
  86. * @param evaluationDept 考评部门配置实体
  87. * @return 结果
  88. */
  89. @PostMapping(value = "/save")
  90. public R addAll(@RequestBody EvaluationDept evaluationDept) {
  91. try {
  92. if (StringUtils.isEmpty(evaluationDept.getId())) {
  93. QueryWrapper<EvaluationDept> qw = new QueryWrapper<>();
  94. if (StringUtils.isNotEmpty(evaluationDept.getParentId())) {
  95. qw.lambda().eq(EvaluationDept::getParentId, evaluationDept.getParentId());
  96. }
  97. if (StringUtils.isNotEmpty(evaluationDept.getDeptId())) {
  98. qw.lambda().eq(EvaluationDept::getDeptId, evaluationDept.getDeptId());
  99. }
  100. EvaluationDept obj = evaluationDeptService.getOne(qw);
  101. if (obj != null) {
  102. return R.error("部门重复,请重新添加!");
  103. }
  104. }
  105. if (StringUtils.isNotEmpty(evaluationDept.getId())) {
  106. QueryWrapper<DeptAssessmentDeclaration> qw = new QueryWrapper<>();
  107. if (StringUtils.isNotEmpty(evaluationDept.getDeptId())) {
  108. qw.lambda().eq(DeptAssessmentDeclaration::getDeptId, evaluationDept.getDeptId());
  109. }
  110. List<DeptAssessmentDeclaration> list = new ArrayList<>();
  111. List<DeptAssessmentDeclaration> deptAssessmentDeclarationList = deptAssessmentDeclarationService.list(qw);
  112. for (DeptAssessmentDeclaration deptAssessmentDeclaration : deptAssessmentDeclarationList) {
  113. if (!"流程已结束".equals(deptAssessmentDeclaration.getStage())) {
  114. deptAssessmentDeclaration.setDeptLeaderId(evaluationDept.getChargePersonId());
  115. deptAssessmentDeclaration.setDeptLeaderName(evaluationDept.getChargePersonName());
  116. list.add(deptAssessmentDeclaration);
  117. }
  118. }
  119. deptAssessmentDeclarationService.updateBatchById(list);
  120. }
  121. boolean b = evaluationDeptService.saveOrUpdate(evaluationDept);
  122. if (b) {
  123. return R.ok().data(b);
  124. } else {
  125. return R.error("保存失败!");
  126. }
  127. } catch (CustomException e) {
  128. return R.customError(e.getMessage()).data("失败!");
  129. }
  130. }
  131. /**
  132. * 获取部门领导
  133. *
  134. * @return 结果
  135. */
  136. @GetMapping(value = "/getDepartmentLeader/{id}")
  137. public R getDepartmentLeader(@PathVariable String id) {
  138. JSONObject jsonArr = userService.pageList(1, 500, id, "", "", "", "", "", request);
  139. JSONObject jsonArr1 = (JSONObject) jsonArr.get("data");
  140. JSONArray array = JSONUtil.parseArray(jsonArr1.get("records"));
  141. List<UserDTO> list = JSONUtil.toList(array, UserDTO.class);
  142. return R.ok().data(list);
  143. }
  144. /**
  145. * 批量删除考评部门配置信息
  146. *
  147. * @param ids 主键s
  148. * @return 结果
  149. */
  150. @PostMapping(value = "/removeAll/{ids}")
  151. public R deleteAll(@PathVariable("ids") String ids) {
  152. try {
  153. String[] strings = ids.split(",");
  154. boolean b = evaluationDeptService.removeByIds(Arrays.asList(strings));
  155. if (b) {
  156. return R.ok().data(b);
  157. } else {
  158. return R.error("删除失败!");
  159. }
  160. } catch (CustomException e) {
  161. return R.customError(e.getMessage()).data("失败!");
  162. }
  163. }
  164. }