OrgController.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package com.huaxu.controller;
  2. import com.baomidou.mybatisplus.core.metadata.IPage;
  3. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  4. import com.huaxu.dto.OrgTree;
  5. import com.huaxu.entity.Org;
  6. import com.huaxu.model.AjaxMessage;
  7. import com.huaxu.model.Pagination;
  8. import com.huaxu.model.ResultStatus;
  9. import com.huaxu.service.OrgService;
  10. import io.swagger.annotations.Api;
  11. import io.swagger.annotations.ApiOperation;
  12. import io.swagger.annotations.ApiParam;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.web.bind.annotation.*;
  15. import java.util.List;
  16. /**
  17. * 组织(Org)控制层
  18. *
  19. * @author makejava
  20. * @since 2020-10-26 14:55:43
  21. */
  22. @RestController
  23. @RequestMapping("/org")
  24. @Api(tags = "组织机构")
  25. public class OrgController {
  26. /**
  27. * 服务对象
  28. */
  29. @Autowired
  30. private OrgService orgService;
  31. /**
  32. * 通过主键查询单条数据
  33. *
  34. * @param id 参数对象
  35. * @return 单条数据
  36. */
  37. @RequestMapping(value = "get", method = RequestMethod.POST)
  38. @ApiOperation(value = "查询机构列表")
  39. public AjaxMessage<Org> selectOne(
  40. @ApiParam(value = "设置配置", required = true)@RequestParam Integer id) {
  41. Org org=new Org();
  42. org.setId(id);
  43. Org result = orgService.selectById(org.getId());
  44. return new AjaxMessage<>(ResultStatus.OK, result);
  45. }
  46. /**
  47. * 新增一条数据
  48. *
  49. * @param org 实体类
  50. * @return Response对象
  51. */
  52. @RequestMapping(value = "insert", method = RequestMethod.POST)
  53. @ApiOperation(value = "插入机构",notes = "orgType 为company或department")
  54. public AjaxMessage<Integer> insert(@ApiParam(value = "设置配置", required = true) @RequestBody Org org) {
  55. int result = orgService.insert(org);
  56. return new AjaxMessage<>(ResultStatus.OK, result);
  57. }
  58. /**
  59. * 修改一条数据
  60. *
  61. * @param org 实体类
  62. * @return Response对象
  63. */
  64. @RequestMapping(value = "update", method = RequestMethod.POST)
  65. @ApiOperation(value = "更改机构",notes = "orgType 为company或department")
  66. public AjaxMessage<Integer> update(@ApiParam(value = "设置配置", required = true) @RequestBody Org org) {
  67. int result = orgService.update(org);
  68. if(result==-1){
  69. return new AjaxMessage<>(ResultStatus.ORG_HAS_USER);
  70. }else if(result==-2){
  71. return new AjaxMessage<>(ResultStatus.ORG_CHIRDTYPE_ERROR);
  72. }else if(result==-3){
  73. return new AjaxMessage<>(ResultStatus.ORG_PARENT_ERROR);
  74. }else{
  75. return new AjaxMessage<>(ResultStatus.OK, result);
  76. }
  77. }
  78. /**
  79. * 获取机构树
  80. *
  81. * @param
  82. * @param
  83. * @return Response对象
  84. */
  85. @RequestMapping(value = "getOrgTree", method = RequestMethod.POST)
  86. @ApiOperation(value = "获取机构树")
  87. public AjaxMessage<List<OrgTree>> getOrgTree(@ApiParam(value = "机构类型", required = true)String orgType) {
  88. Org org=new Org();
  89. org.setOrgType(orgType);
  90. ;
  91. return new AjaxMessage<>(ResultStatus.OK, orgService.getTrees(org));
  92. }
  93. @RequestMapping(value = "deleteAll", method = RequestMethod.POST)
  94. @ApiOperation(value = "删除机构")
  95. AjaxMessage<List<String>> deleteAll(@ApiParam(value = "机构id", required = true)@RequestBody List<Integer> ids){
  96. return new AjaxMessage<>(ResultStatus.OK,
  97. orgService.deleteAll(ids));
  98. }
  99. }