AdminOrganizationController.java 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. package com.goafanti.organization.controller;
  2. import com.goafanti.common.bo.Result;
  3. import com.goafanti.common.constant.ErrorConstants;
  4. import com.goafanti.common.controller.BaseApiController;
  5. import com.goafanti.common.dao.DepartmentMapper;
  6. import com.goafanti.common.utils.ParamUtils;
  7. import com.goafanti.common.utils.StringUtils;
  8. import com.goafanti.organization.bo.InputDep;
  9. import com.goafanti.organization.bo.OrganizationListOut;
  10. import com.goafanti.organization.service.OrganizationService;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.validation.BindingResult;
  13. import org.springframework.validation.annotation.Validated;
  14. import org.springframework.web.bind.annotation.RequestMapping;
  15. import org.springframework.web.bind.annotation.RequestMethod;
  16. import org.springframework.web.bind.annotation.RestController;
  17. import javax.annotation.Resource;
  18. import java.util.Objects;
  19. @RestController
  20. @RequestMapping("/api/admin/organization")
  21. public class AdminOrganizationController extends BaseApiController{
  22. @Resource
  23. private OrganizationService organizationService;
  24. @Autowired
  25. private DepartmentMapper departmentMapper;
  26. /**部门组织管理列表 **/
  27. @RequestMapping(value = "/listOrganizationManagement" , method = RequestMethod.POST)
  28. public Result listOrganizationManagement(OrganizationListOut olo, Integer pageNo,
  29. Integer pageSize){
  30. Result res = new Result();
  31. res.setData(organizationService.listOrganizationManagement(olo, pageNo, pageSize));
  32. return res;
  33. }
  34. /**获取科德集团以下的部门 **/
  35. @RequestMapping(value = "/getAllDep" , method = RequestMethod.GET)
  36. public Result getAllDep(Integer hideSign){
  37. Result res = new Result();
  38. res.setData(organizationService.getAllDep(hideSign));
  39. return res;
  40. }
  41. /**获取所有部门 **/
  42. @RequestMapping(value = "/selectSuperId" , method = RequestMethod.GET)
  43. public Result selectSuperId(Integer hideSign){
  44. Result res = new Result();
  45. res.setData(organizationService.selectSuperId(hideSign));
  46. return res;
  47. }
  48. /**部门组织管理上级组织查询 **/
  49. @RequestMapping(value = "/selectSuperIdS" , method = RequestMethod.GET)
  50. public Result selectsuperIdS(){
  51. Result res = new Result();
  52. res.setData(organizationService.selectSuperId(1));
  53. return res;
  54. }
  55. /**部门组织管理新增**/
  56. @RequestMapping(value = "/addOrganization" , method = RequestMethod.POST)
  57. public Result addOrganization(String name, String managerId, String type, String superId, String remarks,
  58. Integer workingHoursType,Integer hideSign,String depNo) {
  59. Result res = new Result();
  60. if(StringUtils.isBlank(name) || StringUtils.isBlank(type) || StringUtils.isBlank(superId)||StringUtils.isBlank(depNo)){
  61. res.getError().add(buildError(ErrorConstants.PARAM_ERROR,"",""));
  62. return res;
  63. }
  64. String olo=departmentMapper.selectDepNoByName(name);
  65. if(olo!=null){
  66. res.getError().add(buildError("","部门已存在"));
  67. return res;
  68. }
  69. if (organizationService.checkDepNo(depNo,0)){
  70. res.getError().add(buildError("","部门编号已存在"));
  71. return res;
  72. }
  73. organizationService.addOrganization(name, managerId, type, superId, remarks,workingHoursType,hideSign,depNo);
  74. return res;
  75. }
  76. /**负责人自动补全查询**/
  77. @RequestMapping(value = "/selectName" , method = RequestMethod.POST)
  78. public Result selectName(String name){
  79. Result res = new Result();
  80. res.setData(organizationService.selectName(name));
  81. return res;
  82. }
  83. /**编辑页面数据读取**/
  84. @RequestMapping(value = "/selectAllById" , method = RequestMethod.POST)
  85. public Result selectAllById(String id){
  86. Result res = new Result();
  87. res.data(organizationService.selectAllById(id));
  88. return res;
  89. }
  90. /**
  91. * 修改部门信息
  92. **/
  93. @RequestMapping(value = "/updateOrganization" , method = RequestMethod.POST)
  94. public Result updateOrganization(@Validated InputDep in, BindingResult bindingResult){
  95. Result res = new Result();
  96. if (bindingResult.hasErrors()) {
  97. res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
  98. ParamUtils.getParamName(in,bindingResult.getFieldError().getField())));
  99. return res;
  100. }
  101. if (Objects.equals(in.getId(), in.getSuperId())){
  102. res.getError().add(buildError("不能设置自己为上级"));
  103. return res;
  104. }
  105. if (organizationService.checkDepNo(in.getDepNo(),1)){
  106. res.getError().add(buildError("","部门编号已存在"));
  107. return res;
  108. }
  109. if (in.getApproval()==null||(in.getApproval()==1&&StringUtils.isBlank(in.getApprovalAid()))){
  110. res.getError().add(buildError("特批审核开启必须设置特批人"));
  111. return res;
  112. }
  113. if (StringUtils.isBlank(in.getFinanceId())){
  114. res.getError().add(buildError("部门财务审核必须设置"));
  115. return res;
  116. }
  117. int i=organizationService.updateOrganization(in);
  118. return res.data(i);
  119. }
  120. /**删除列表信息**/
  121. @RequestMapping(value = "/deleteById" , method = RequestMethod.POST)
  122. public Result deleteById(String id){
  123. Result res = new Result();
  124. if(StringUtils.isBlank(id)){
  125. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "id"));
  126. return res;
  127. }
  128. /*OrganizationListOut olo=departmentMapper.selectAllById(id);
  129. String superId=olo.getName();*/
  130. int subordinate=departmentMapper.selectCountBySuperId(id);
  131. if(subordinate>0){
  132. res.getError().add(buildError("","存在下级组织不能删除"));
  133. return res;
  134. }
  135. int adminCount=departmentMapper.selectUserById(id);
  136. if(adminCount>0){
  137. res.getError().add(buildError("","部门被用户选定不能删除"));
  138. return res;
  139. }
  140. organizationService.deleteById(id);
  141. return res;
  142. }
  143. }