DepartmentController.java 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. package com.xintong.visualinspection.controller;
  2. import java.util.List;
  3. import javax.servlet.http.HttpServletRequest;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.web.bind.annotation.PathVariable;
  6. import org.springframework.web.bind.annotation.RequestBody;
  7. import org.springframework.web.bind.annotation.RequestMapping;
  8. import org.springframework.web.bind.annotation.RequestMethod;
  9. import org.springframework.web.bind.annotation.RestController;
  10. import com.xintong.system.err.BusinessException;
  11. import com.xintong.visualinspection.bean.FeeStation;
  12. import com.xintong.visualinspection.bean.Organ;
  13. import com.xintong.visualinspection.bean.User;
  14. import com.xintong.visualinspection.service.DepartmentService;
  15. import com.xintong.visualinspection.util.CacheUtil;
  16. /**
  17. * 文件名:TestController
  18. * 版本信息:日期:2017/3/30 Copyright 江苏省交通规划设计院 Corporation 2017 版权所有.
  19. */
  20. /**
  21. * @author wenhongquan
  22. *
  23. */
  24. @RestController
  25. @RequestMapping("/dept")
  26. public class DepartmentController extends BaseController {
  27. @Autowired
  28. private DepartmentService departmentService;
  29. /**
  30. * 添加部门
  31. * @return
  32. * String
  33. * @exception
  34. * @since 1.0.0
  35. */
  36. @RequestMapping(value = "/addDept",method=RequestMethod.POST,produces="application/json;charset=UTF-8")
  37. public String addDept(@RequestBody Organ organ) throws Exception{
  38. departmentService.insert(organ);
  39. CacheUtil.refreshDeptMap(departmentService);
  40. return returnResult(0, "添加成功", null);
  41. }
  42. /**
  43. * 修改部门
  44. * @return
  45. * String
  46. * @exception
  47. * @since 1.0.0
  48. */
  49. @RequestMapping(value = "/updateDept/{organid}",method=RequestMethod.PUT,produces="application/json;charset=UTF-8")
  50. public String updateDept(@RequestBody Organ organ,@PathVariable int organid){
  51. try{
  52. organ.setId(organid);
  53. departmentService.update(organ);
  54. CacheUtil.refreshDeptMap(departmentService);
  55. return super.returnResult(0, "修改成功", null);
  56. }catch(Exception e){
  57. throw new BusinessException(20003);
  58. }
  59. }
  60. /**
  61. * 删除部门(软删除)
  62. * @return
  63. * String
  64. * @exception
  65. * @since 1.0.0
  66. */
  67. @RequestMapping(value = "/deleteDept/{organid}",method=RequestMethod.DELETE,produces="application/json;charset=UTF-8")
  68. public String deleteDept(@PathVariable Integer organid){
  69. try{
  70. departmentService.delete((organid));
  71. CacheUtil.refreshDeptMap(departmentService);
  72. return returnResult(0, "删除成功", null);
  73. }catch(Exception e){
  74. throw new BusinessException(20002);
  75. }
  76. }
  77. /**
  78. * 获取所用部门
  79. * @param page
  80. * @param size
  81. * @return
  82. */
  83. @RequestMapping(value = "/get/all",method=RequestMethod.POST,produces="application/json;charset=UTF-8")
  84. public String getAll(){
  85. try{
  86. Organ organ=new Organ();
  87. organ.setStatus(0);
  88. List<Organ> organs= departmentService.getAll();
  89. return returnResult(0, "获取成功", organs);
  90. }catch(Exception e){
  91. throw new BusinessException(20001);
  92. }
  93. }
  94. @RequestMapping(value = "/get/all",method=RequestMethod.GET,produces="application/json;charset=UTF-8")
  95. public String getAllDept(HttpServletRequest request){
  96. try{
  97. User u = getCurrentUser(request);
  98. Organ organ=new Organ();
  99. organ.setStatus(0);
  100. List<Organ> organs= departmentService.getOrgans(organ,u);
  101. return returnResult(0, "获取成功", organs);
  102. }catch(Exception e){
  103. throw new BusinessException(20001);
  104. }
  105. }
  106. @RequestMapping(value = "/getDeptByParent/{pid}",method=RequestMethod.GET,produces="application/json;charset=UTF-8")
  107. public String getDeptByParent(@PathVariable Integer pid){
  108. try{
  109. Organ organ = new Organ();
  110. organ.setParentid(pid);
  111. List<Organ> organs= departmentService.getOrgans(organ,null);
  112. return returnResult(0, "获取成功",(organs));
  113. }catch(Exception e){
  114. throw new BusinessException(20001);
  115. }
  116. }
  117. @RequestMapping(value = "/getDeptById/{organid}",method=RequestMethod.GET,produces="application/json;charset=UTF-8")
  118. public String getDeptById(@PathVariable Integer organid){
  119. try{
  120. Organ organ = new Organ();
  121. organ.setId(organid);
  122. List<Organ> organs = departmentService.getOrgans(organ,null);
  123. if(organs==null||organs.size()<1 ) throw new BusinessException(20001);
  124. return returnResult(0, "获取成功", organs.get(0));
  125. }catch(Exception e){
  126. throw new BusinessException(20001);
  127. }
  128. }
  129. @RequestMapping(value = "/getAllFs",method=RequestMethod.GET,produces="application/json;charset=UTF-8")
  130. public String getAllFs(){
  131. List<FeeStation> organs = departmentService.getAllFS();
  132. return returnResult(0, "获取成功", organs);
  133. }
  134. @RequestMapping(value = "/getAllRM",method=RequestMethod.GET,produces="application/json;charset=UTF-8")
  135. public String getAllRM(){
  136. List<FeeStation> organs = departmentService.getAllRM();
  137. return returnResult(0, "获取成功", organs);
  138. }
  139. @RequestMapping(value = "/getFsByDept",method=RequestMethod.GET,produces="application/json;charset=UTF-8")
  140. public String getAFsByDeptId(HttpServletRequest request){
  141. User u = getCurrentUser(request);
  142. FeeStation feestation = departmentService.getFSByDeptId(u.getOrganid());
  143. return returnResult(0, "获取成功", feestation);
  144. }
  145. @RequestMapping(value = "/getDeptInfosByDeptId",method=RequestMethod.POST,produces="application/json;charset=UTF-8")
  146. public String getDeptInfosByDeptId(HttpServletRequest request,@RequestBody Organ organ){
  147. List<Organ> organs = departmentService.getOrgans(organ);
  148. return returnResult(0, "获取成功", organs);
  149. }
  150. }