AdmTenantController.java 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. package com.persagy.proxy.adm.controller;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.util.StrUtil;
  4. import com.persagy.proxy.adm.constant.AdmCommonConstant;
  5. import com.persagy.proxy.adm.model.AdmTenant;
  6. import com.persagy.proxy.adm.request.AdmCreateRequest;
  7. import com.persagy.proxy.adm.request.AdmQueryCriteria;
  8. import com.persagy.proxy.adm.request.AdmResponse;
  9. import com.persagy.proxy.adm.service.IAdmTenantService;
  10. import com.persagy.proxy.adm.utils.ObjectNameUtil;
  11. import com.persagy.proxy.common.entity.InstanceUrlParam;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.beans.factory.annotation.Value;
  14. import org.springframework.web.bind.annotation.PostMapping;
  15. import org.springframework.web.bind.annotation.RequestBody;
  16. import org.springframework.web.bind.annotation.RequestMapping;
  17. import org.springframework.web.bind.annotation.RestController;
  18. import javax.ws.rs.QueryParam;
  19. import java.util.List;
  20. /**
  21. * Adm 楼层 API
  22. * @author lvxy
  23. * @date 2021/8/16
  24. */
  25. @RestController
  26. @RequestMapping("/object/tenant")
  27. public class AdmTenantController {
  28. @Autowired
  29. private IAdmTenantService service;
  30. @Value("${middleware.group.code}")
  31. private String groupCode;
  32. /**
  33. * 统计
  34. * @param projectId
  35. * @param request
  36. * @return
  37. * @throws Exception
  38. */
  39. @PostMapping("/count")
  40. public AdmResponse count(@QueryParam("projectId") String projectId,
  41. @RequestBody AdmQueryCriteria request) throws Exception {
  42. // 组装上下文条件
  43. InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  44. request.setName("virtual");
  45. request.setOnlyCount(true);
  46. return service.doQuery(context, request, AdmTenant.class);
  47. }
  48. /**
  49. * 创建
  50. * @param createRequest
  51. * @return
  52. * @throws Exception
  53. */
  54. @PostMapping("/create")
  55. public AdmResponse create(@RequestBody AdmCreateRequest<AdmTenant> createRequest, @QueryParam("projectId") String projectId) throws Exception {
  56. // 组装上下文条件
  57. InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  58. List<AdmTenant> vos = CollUtil.newArrayList(createRequest.getContent());
  59. vos.stream().forEach(admTenant -> {
  60. if (StrUtil.isEmpty(admTenant.getName())){
  61. admTenant.setName(ObjectNameUtil.objectName("租户-"));
  62. }
  63. });
  64. vos = service.doInsert(context, AdmTenant.class, vos);
  65. return AdmResponse.success(vos);
  66. }
  67. /**
  68. * 根据ID删除
  69. * @param vos
  70. * @return
  71. * @throws Exception
  72. */
  73. @PostMapping("/delete")
  74. public AdmResponse delete(@QueryParam("projectId") String projectId, @RequestBody List<AdmTenant> vos) throws Exception {
  75. // 组装上下文条件
  76. InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  77. service.doDelete(context, vos);
  78. return AdmResponse.success();
  79. }
  80. /**
  81. * 更新
  82. * @param createRequest
  83. * @return
  84. * @throws Exception
  85. */
  86. @PostMapping("/update")
  87. public AdmResponse update(@RequestBody AdmCreateRequest<AdmTenant> createRequest, @QueryParam("projectId") String projectId) throws Exception {
  88. // 组装上下文条件
  89. InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  90. List<AdmTenant> vos = CollUtil.newArrayList(createRequest.getContent());
  91. vos = service.doUpdate(context, AdmTenant.class, vos);
  92. return AdmResponse.success(vos);
  93. }
  94. /**
  95. * 查询
  96. * @param projectId
  97. * @param request
  98. * @return
  99. * @throws Exception
  100. */
  101. @PostMapping("/query")
  102. public AdmResponse query(@QueryParam("projectId") String projectId,
  103. @RequestBody AdmQueryCriteria request) throws Exception {
  104. // 组装上下文条件
  105. InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  106. request.setName("virtual");
  107. return service.doQuery(context, request, AdmTenant.class);
  108. }
  109. /**
  110. * 查询租户-包含统计信息
  111. * 此方法可能会被废弃
  112. * @param projectId
  113. * @param request
  114. * @return
  115. * @throws Exception
  116. */
  117. @PostMapping("/query-with-count")
  118. public AdmResponse queryWithCount(@QueryParam("projectId") String projectId,
  119. @RequestBody AdmQueryCriteria request) throws Exception {
  120. // 组装上下文条件
  121. InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
  122. request.setName("virtual");
  123. return service.doQuery(context, request, AdmTenant.class);
  124. }
  125. }