DepartmentController.java 5.1 KB

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