TenantInfoController.java 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package com.keao.edu.user.controller;
  2. import com.keao.edu.auth.api.client.SysUserFeignService;
  3. import com.keao.edu.auth.api.entity.SysUser;
  4. import com.keao.edu.common.controller.BaseController;
  5. import com.keao.edu.common.entity.HttpResponseResult;
  6. import com.keao.edu.common.page.PageInfo;
  7. import com.keao.edu.common.page.QueryInfo;
  8. import com.keao.edu.common.tenant.TenantContextHolder;
  9. import com.keao.edu.user.dto.TenantInfoDto;
  10. import com.keao.edu.user.entity.TenantInfo;
  11. import com.keao.edu.user.service.TenantInfoService;
  12. import io.swagger.annotations.Api;
  13. import io.swagger.annotations.ApiOperation;
  14. import org.apache.commons.lang3.StringUtils;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.web.bind.annotation.*;
  17. import java.util.Date;
  18. @RestController
  19. @RequestMapping("tenantInfo")
  20. @Api(tags = "机构服务")
  21. public class TenantInfoController extends BaseController {
  22. @Autowired
  23. private TenantInfoService tenantInfoService;
  24. @Autowired
  25. private SysUserFeignService sysUserFeignService;
  26. @ApiOperation("机构服务分页查询")
  27. @GetMapping(value = "/list")
  28. public HttpResponseResult<PageInfo<TenantInfoDto>> getList(QueryInfo queryInfo) {
  29. return succeed(tenantInfoService.queryTenants(queryInfo));
  30. }
  31. @ApiOperation("查询机构详情")
  32. @GetMapping(value = "/query")
  33. public HttpResponseResult<TenantInfo> query() {
  34. String tenantId = TenantContextHolder.getTenantId();
  35. if(StringUtils.isNotEmpty(tenantId)){
  36. return succeed(tenantInfoService.get(Integer.parseInt(tenantId)));
  37. }else {
  38. return succeed(new TenantInfo());
  39. }
  40. }
  41. @ApiOperation("新增机构")
  42. @PostMapping(value = "/add")
  43. public HttpResponseResult add(@RequestBody TenantInfoDto tenantInfo) {
  44. tenantInfoService.addTenant(tenantInfo);
  45. return succeed();
  46. }
  47. @ApiOperation("更新机构")
  48. @PostMapping(value = "/update")
  49. public HttpResponseResult update(@RequestBody TenantInfoDto tenantInfo) {
  50. SysUser sysUser = sysUserFeignService.queryUserInfo();
  51. if(!sysUser.getIsSuperAdmin()){
  52. String tenantId = TenantContextHolder.getTenantId();
  53. if(StringUtils.isNotEmpty(tenantId)){
  54. tenantInfo.setId(Integer.parseInt(tenantId));
  55. }
  56. }
  57. tenantInfo.setUpdateTime(new Date());
  58. tenantInfoService.updateTenant(tenantInfo);
  59. return succeed();
  60. }
  61. @ApiOperation("删除")
  62. @PostMapping(value = "/del")
  63. public HttpResponseResult add(Integer id) {
  64. return succeed(tenantInfoService.delete(id));
  65. }
  66. }