AdmLocationPointController.java 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. package com.persagy.proxy.adm.controller;
  2. import cn.hutool.core.collection.CollUtil;
  3. import com.persagy.proxy.adm.constant.AdmCommonConstant;
  4. import com.persagy.proxy.adm.model.AdmLocationPoint;
  5. import com.persagy.proxy.adm.model.AdmPointImage;
  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.IAdmLocationPointService;
  10. import com.persagy.proxy.adm.utils.AdmContextUtil;
  11. import com.persagy.proxy.common.entity.DmpResult;
  12. import com.persagy.proxy.common.entity.InstanceUrlParam;
  13. import lombok.extern.slf4j.Slf4j;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.beans.factory.annotation.Value;
  16. import org.springframework.web.bind.annotation.PostMapping;
  17. import org.springframework.web.bind.annotation.RequestBody;
  18. import org.springframework.web.bind.annotation.RequestMapping;
  19. import org.springframework.web.bind.annotation.RestController;
  20. import javax.ws.rs.QueryParam;
  21. import java.util.ArrayList;
  22. import java.util.List;
  23. /**
  24. * @ClassName AdmLocationPointController
  25. * @Description: 点位标签
  26. * @Author linhuili
  27. * @Date 2021/8/31 09:44
  28. * @Version V1.0
  29. **/
  30. @RestController
  31. @RequestMapping("/object/location-point")
  32. @Slf4j
  33. public class AdmLocationPointController {
  34. @Value("${middleware.group.code}")
  35. private String groupCode;
  36. @Autowired
  37. private IAdmLocationPointService service;
  38. /**
  39. * 统计点位标签
  40. * @param projectId
  41. * @param request
  42. * @return
  43. * @throws Exception
  44. */
  45. @PostMapping("/count")
  46. public AdmResponse count(@QueryParam("projectId") String projectId,
  47. @RequestBody AdmQueryCriteria request) throws Exception {
  48. // 组装上下文条件
  49. InstanceUrlParam context = AdmContextUtil.toDmpContext();
  50. request.setName("point");
  51. request.setOnlyCount(true);
  52. return service.doQuery(context, request, AdmLocationPoint.class);
  53. }
  54. /**
  55. * 查询信息点标签
  56. * @param projectId
  57. * @param request
  58. * @return
  59. * @throws Exception
  60. */
  61. @PostMapping("/query")
  62. public AdmResponse query(@QueryParam("projectId") String projectId,
  63. @RequestBody AdmQueryCriteria request) throws Exception {
  64. // 组装上下文条件
  65. InstanceUrlParam context = AdmContextUtil.toDmpContext();
  66. request.setName("point");
  67. // 查询信息点标签
  68. AdmResponse admResponse = service.doQuery(context, request, AdmLocationPoint.class);
  69. // 查询结果处理
  70. handleQueryLocationPointResult(admResponse);
  71. return admResponse;
  72. }
  73. /**
  74. * 创建点位标签信息
  75. * @param createRequest
  76. * @return
  77. * @throws Exception
  78. */
  79. @PostMapping("/create")
  80. public AdmResponse create(@RequestBody AdmCreateRequest<AdmLocationPoint> createRequest, @QueryParam("projectId") String projectId) throws Exception {
  81. // 组装上下文条件
  82. InstanceUrlParam context = AdmContextUtil.toDmpContext();
  83. List<AdmLocationPoint> vos = CollUtil.newArrayList(createRequest.getContent());
  84. log.info("创建条件"+vos.toString());
  85. vos = service.doInsert(context, AdmLocationPoint.class, vos);
  86. return AdmResponse.success(vos);
  87. }
  88. /**
  89. * 更新点位标签信息
  90. * @param createRequest
  91. * @return
  92. * @throws Exception
  93. */
  94. @PostMapping("/update")
  95. public AdmResponse update(@RequestBody AdmCreateRequest<AdmLocationPoint> createRequest, @QueryParam("projectId") String projectId) throws Exception {
  96. // 组装上下文条件
  97. InstanceUrlParam context = AdmContextUtil.toDmpContext();
  98. List<AdmLocationPoint> vos = CollUtil.newArrayList(createRequest.getContent());
  99. vos = service.doUpdate(context, AdmLocationPoint.class, vos);
  100. return AdmResponse.success(vos);
  101. }
  102. /**
  103. * 删除点位标签
  104. * @param vos
  105. * @return
  106. * @throws Exception
  107. */
  108. @PostMapping("/delete")
  109. public AdmResponse delete(@QueryParam("projectId") String projectId, @RequestBody List<AdmLocationPoint> vos) throws Exception {
  110. // 组装上下文条件
  111. InstanceUrlParam context = AdmContextUtil.toDmpContext();
  112. service.doDelete(context, vos);
  113. return AdmResponse.success();
  114. }
  115. /**
  116. * 删除点位图片
  117. * @param vos
  118. * @return
  119. * @throws Exception
  120. */
  121. @PostMapping("/delete-image")
  122. public AdmResponse deleteImage(@QueryParam("projectId") String projectId, @RequestBody List<AdmPointImage> vos) throws Exception {
  123. // 组装上下文条件
  124. InstanceUrlParam context = AdmContextUtil.toDmpContext();
  125. // 删除图片参数转换
  126. List<AdmLocationPoint> points = deleteImageParamRevert(vos);
  127. service.doUpdate(context,AdmLocationPoint.class, points);
  128. return AdmResponse.success();
  129. }
  130. /**
  131. * 删除图片参数转换
  132. * @param vos
  133. * @return
  134. */
  135. private List<AdmLocationPoint> deleteImageParamRevert(List<AdmPointImage> vos){
  136. if(CollUtil.isEmpty(vos)){
  137. return new ArrayList<>();
  138. }
  139. ArrayList<AdmLocationPoint> points = new ArrayList<>();
  140. for (AdmPointImage vo : vos) {
  141. AdmLocationPoint point = new AdmLocationPoint();
  142. point.setId(vo.getObjectId());
  143. point.setImageList(new ArrayList<>());
  144. points.add(point);
  145. }
  146. return points;
  147. }
  148. /**
  149. * 查询标签信息结果处理
  150. * @param admResponse
  151. */
  152. private void handleQueryLocationPointResult(AdmResponse admResponse){
  153. if(!DmpResult.SUCCESS.equals(admResponse.getResult())){
  154. return;
  155. }
  156. List<AdmLocationPoint> points = (List<AdmLocationPoint>) admResponse.getContent();
  157. if(CollUtil.isEmpty(points)){
  158. return;
  159. }
  160. for (AdmLocationPoint point : points) {
  161. ArrayList<AdmPointImage> imageList = point.getImageList();
  162. if(CollUtil.isEmpty(imageList)){
  163. continue;
  164. }
  165. imageList.forEach(item->{
  166. item.setObjectId(point.getId());
  167. });
  168. }
  169. }
  170. }