AdminOrganizationController.java 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. package com.goafanti.organization.controller;
  2. import javax.annotation.Resource;
  3. import com.goafanti.common.dao.DepartmentMapper;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.web.bind.annotation.RequestMapping;
  6. import org.springframework.web.bind.annotation.RequestMethod;
  7. import org.springframework.web.bind.annotation.RestController;
  8. import com.goafanti.common.bo.Result;
  9. import com.goafanti.common.constant.ErrorConstants;
  10. import com.goafanti.common.controller.BaseApiController;
  11. import com.goafanti.common.utils.StringUtils;
  12. import com.goafanti.organization.bo.OrganizationListOut;
  13. import com.goafanti.organization.service.OrganizationService;
  14. @RestController
  15. @RequestMapping("/api/admin/organization")
  16. public class AdminOrganizationController extends BaseApiController{
  17. @Resource
  18. private OrganizationService organizationService;
  19. @Autowired
  20. private DepartmentMapper departmentMapper;
  21. /**部门组织管理列表 **/
  22. @RequestMapping(value = "/listOrganizationManagement" , method = RequestMethod.POST)
  23. public Result listOrganizationManagement(OrganizationListOut olo, Integer pageNo,
  24. Integer pageSize){
  25. Result res = new Result();
  26. res.setData(organizationService.listOrganizationManagement(olo, pageNo, pageSize));
  27. return res;
  28. }
  29. /**部门组织管理上级组织查询 **/
  30. @RequestMapping(value = "/selectSuperId" , method = RequestMethod.GET)
  31. public Result selectsuperId(Integer hideSign){
  32. Result res = new Result();
  33. res.setData(organizationService.selectSuperId(hideSign));
  34. return res;
  35. }
  36. /**部门组织管理上级组织查询 **/
  37. @RequestMapping(value = "/selectSuperIdS" , method = RequestMethod.GET)
  38. public Result selectsuperIdS(){
  39. Result res = new Result();
  40. res.setData(organizationService.selectSuperId(1));
  41. return res;
  42. }
  43. /**部门组织管理新增**/
  44. @RequestMapping(value = "/addOrganization" , method = RequestMethod.POST)
  45. public Result addOrganization(String name, String managerId, String type, String superId, String remarks,
  46. Integer workingHoursType,Integer hideSign) {
  47. Result res = new Result();
  48. if(StringUtils.isBlank(name) || StringUtils.isBlank(type) || StringUtils.isBlank(superId)){
  49. res.getError().add(buildError("","组织名称、组织类型、上级组织不能为空"));
  50. return res;
  51. }
  52. String olo=departmentMapper.selectDepNoByName(name);
  53. if(olo!=null){
  54. res.getError().add(buildError("","部门已存在"));
  55. return res;
  56. }
  57. String sdepNo=departmentMapper.selectDepNo(superId);
  58. int count=departmentMapper.selectDepNoCount(superId);
  59. if((count+1)>99){
  60. res.getError().add(buildError("","每层最多存在99个子类"));
  61. return res;
  62. }
  63. organizationService.addOrganization(name, managerId, type, superId, remarks,sdepNo,count,workingHoursType,hideSign);
  64. return res;
  65. }
  66. /**负责人自动补全查询**/
  67. @RequestMapping(value = "/selectName" , method = RequestMethod.POST)
  68. public Result selectName(String name){
  69. Result res = new Result();
  70. res.setData(organizationService.selectName(name));
  71. return res;
  72. }
  73. /**编辑页面数据读取**/
  74. @RequestMapping(value = "/selectAllById" , method = RequestMethod.POST)
  75. public Result selectAllById(String id){
  76. Result res = new Result();
  77. res.data(organizationService.selectAllById(id)) ;
  78. return res;
  79. }
  80. /**修改信息**/
  81. @RequestMapping(value = "/updateOrganization" , method = RequestMethod.POST)
  82. public Result updateOrganization(String name, String type, String managerId, String superId, String status,Integer province,
  83. String remarks,String id,String abbreviation,String financeId,Integer workingHoursType,Integer hideSign){
  84. Result res = new Result();
  85. if(StringUtils.isBlank(name) || StringUtils.isBlank(type)
  86. || StringUtils.isBlank(managerId)|| StringUtils.isBlank(superId)
  87. || StringUtils.isBlank(status)|| StringUtils.isBlank(remarks)){
  88. res.getError().add(buildError(ErrorConstants.PARAM_ERROR,"参数"));
  89. return res;
  90. }
  91. String sdepNo=departmentMapper.selectDepNo(superId);//No
  92. int count=departmentMapper.selectDepNoCount(superId);//14
  93. if((count+1)>99){
  94. res.getError().add(buildError("","每层最多存在99个子类"));
  95. return res;
  96. }
  97. int i=organizationService.updateOrganization(name, type, managerId, superId, status, province,remarks,id,
  98. sdepNo,count,abbreviation,financeId,workingHoursType,hideSign);
  99. return res.data(i);
  100. }
  101. /**删除列表信息**/
  102. @RequestMapping(value = "/deleteById" , method = RequestMethod.POST)
  103. public Result deleteById(String id){
  104. Result res = new Result();
  105. if(StringUtils.isBlank(id)){
  106. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "id"));
  107. return res;
  108. }
  109. /*OrganizationListOut olo=departmentMapper.selectAllById(id);
  110. String superId=olo.getName();*/
  111. int subordinate=departmentMapper.selectCountBySuperId(id);
  112. if(subordinate>0){
  113. res.getError().add(buildError("","存在下级组织不能删除"));
  114. return res;
  115. }
  116. int adminCount=departmentMapper.selectUserById(id);
  117. if(adminCount>0){
  118. res.getError().add(buildError("","部门被用户选定不能删除"));
  119. return res;
  120. }
  121. organizationService.deleteById(id);
  122. return res;
  123. }
  124. }