AdmISpaceController.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package com.persagy.proxy.object.controller;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.util.StrUtil;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.persagy.dmp.common.utils.JsonHelper;
  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.utils.AdmContextUtil;
  10. import com.persagy.proxy.object.model.AdmISpace;
  11. import com.persagy.proxy.object.service.IAdmISpaceService;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.web.bind.annotation.PostMapping;
  14. import org.springframework.web.bind.annotation.RequestBody;
  15. import org.springframework.web.bind.annotation.RequestMapping;
  16. import org.springframework.web.bind.annotation.RestController;
  17. import java.util.List;
  18. /**
  19. * Adm 模型空间 API
  20. * @author lvxy
  21. * @date 2021/8/16
  22. */
  23. @RestController
  24. @RequestMapping("/object/ispace")
  25. public class AdmISpaceController {
  26. @Autowired
  27. private IAdmISpaceService service;
  28. /**
  29. * 统计
  30. *
  31. * @param request
  32. * @return
  33. * @throws Exception
  34. */
  35. @PostMapping("/count")
  36. public AdmResponse count(@RequestBody AdmQueryCriteria request) throws Exception {
  37. request.setName(AdmISpace.OBJ_TYPE);
  38. request.setOnlyCount(true);
  39. return service.doQuery(AdmContextUtil.toDmpContext(), request, AdmISpace.class);
  40. }
  41. /**
  42. * 创建
  43. * @param AdmISpace
  44. * @return
  45. * @throws Exception
  46. */
  47. @PostMapping("/create")
  48. public AdmResponse create(@RequestBody AdmCreateRequest<AdmISpace> AdmISpace) throws Exception {
  49. List<AdmISpace> vos = CollUtil.newArrayList(AdmISpace.getContent());
  50. ensureDataInfos(vos);
  51. vos = service.doInsert(AdmContextUtil.toDmpContext(), AdmISpace.class, vos);
  52. return AdmResponse.success(vos);
  53. }
  54. /**
  55. * 根据ID删除
  56. * @param vos
  57. * @return
  58. * @throws Exception
  59. */
  60. @PostMapping("/delete")
  61. public AdmResponse delete( @RequestBody List<AdmISpace> vos) throws Exception {
  62. service.doDelete(AdmContextUtil.toDmpContext(), vos);
  63. return AdmResponse.success();
  64. }
  65. /**
  66. * 更新分区对象信息
  67. * @param AdmISpace
  68. * @return
  69. * @throws Exception
  70. */
  71. @PostMapping("/update")
  72. public AdmResponse update(@RequestBody AdmCreateRequest<AdmISpace> AdmISpace) throws Exception {
  73. List<AdmISpace> vos = CollUtil.newArrayList(AdmISpace.getContent());
  74. ensureDataInfos(vos);
  75. vos = service.doUpdate(AdmContextUtil.toDmpContext(), AdmISpace.class, vos);
  76. return AdmResponse.success(vos);
  77. }
  78. /**
  79. * 补偿处理对象属性
  80. * @param vos
  81. */
  82. private void ensureDataInfos(List<AdmISpace> vos) {
  83. if(CollUtil.isEmpty(vos)) {
  84. return;
  85. }
  86. for(AdmISpace vo:vos) {
  87. if(StrUtil.isBlank(vo.getName())) {
  88. vo.setName(vo.getLocalName());
  89. }
  90. vo.setClassCode(AdmISpace.OBJ_TYPE);
  91. }
  92. }
  93. /**
  94. * 根据楼层id查询元空间数据
  95. * @param param:请求参数
  96. */
  97. @PostMapping("/query")
  98. public AdmResponse query(@RequestBody JSONObject param) throws Exception {
  99. AdmQueryCriteria request = JsonHelper.toSingleEntity(param, AdmQueryCriteria.class);
  100. request.setName(AdmISpace.OBJ_TYPE);
  101. if (StrUtil.isNotBlank(param.getString("floorId"))){
  102. String filters = " floorId = '"+param.getString("floorId")+"' ";
  103. request.addFilters(filters);
  104. }
  105. AdmResponse admResponse = service.doQuery(AdmContextUtil.toDmpContext(), request, AdmISpace.class);
  106. admResponse.setMessage(param.getString("floorId"));
  107. return admResponse;
  108. }
  109. }