|
@@ -1,12 +1,16 @@
|
|
|
package com.persagy.proxy.adm.controller;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.persagy.dmp.common.model.entity.BaseEntity;
|
|
|
import com.persagy.proxy.adm.constant.AdmCommonConstant;
|
|
|
-import com.persagy.proxy.adm.model.AdmBuilding;
|
|
|
+import com.persagy.proxy.adm.model.*;
|
|
|
import com.persagy.proxy.adm.request.AdmCreateRequest;
|
|
|
import com.persagy.proxy.adm.request.AdmQueryCriteria;
|
|
|
import com.persagy.proxy.adm.request.AdmResponse;
|
|
|
-import com.persagy.proxy.adm.service.IAdmBuildingService;
|
|
|
+import com.persagy.proxy.adm.service.*;
|
|
|
+import com.persagy.proxy.adm.utils.ObjectNameUtil;
|
|
|
+import com.persagy.proxy.common.entity.DmpResult;
|
|
|
import com.persagy.proxy.common.entity.InstanceUrlParam;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -17,6 +21,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.ws.rs.QueryParam;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* ADM 建筑 API
|
|
@@ -29,6 +34,14 @@ public class AdmBuildingController {
|
|
|
|
|
|
@Autowired
|
|
|
private IAdmBuildingService service;
|
|
|
+ @Autowired
|
|
|
+ private IAdmEquipmentService equipmentService;
|
|
|
+ @Autowired
|
|
|
+ private IAdmFloorService floorService;
|
|
|
+ @Autowired
|
|
|
+ private IAdmISpaceService iAdmISpaceService;
|
|
|
+ @Autowired
|
|
|
+ private IAdmSpaceService spaceService;
|
|
|
@Value("${middleware.group.code}")
|
|
|
private String groupCode;
|
|
|
|
|
@@ -44,6 +57,11 @@ public class AdmBuildingController {
|
|
|
InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
|
|
|
List<AdmBuilding> vos = CollUtil.newArrayList(createRequest.getContent());
|
|
|
vos = service.doInsert(context, AdmBuilding.class, vos);
|
|
|
+ vos.stream().forEach(admBuilding -> {
|
|
|
+ if (StrUtil.isEmpty(admBuilding.getName())){
|
|
|
+ admBuilding.setName(ObjectNameUtil.objectName("建筑-"));
|
|
|
+ }
|
|
|
+ });
|
|
|
return AdmResponse.success(vos);
|
|
|
}
|
|
|
|
|
@@ -57,6 +75,46 @@ public class AdmBuildingController {
|
|
|
public AdmResponse delete(@RequestBody List<AdmBuilding> vos) throws Exception {
|
|
|
// 组装上下文条件
|
|
|
InstanceUrlParam context = new InstanceUrlParam(groupCode, null, null, AdmCommonConstant.APP_ID);
|
|
|
+ if(CollUtil.isEmpty(vos)){
|
|
|
+ return AdmResponse.failure("参数不能为空");
|
|
|
+ }
|
|
|
+ //验证楼层 空间 设备 等信息是否存在,不存在关系可以删除
|
|
|
+ Map<String, AdmBuilding> admBuildingMap = CollUtil.fieldValueMap(vos, BaseEntity.PROP_ID);
|
|
|
+ String msg = "建筑下包含其他对象实例,请解除关系后删除";
|
|
|
+ AdmQueryCriteria admQueryCriteria = new AdmQueryCriteria();
|
|
|
+ StringBuilder stringBuilder = new StringBuilder();
|
|
|
+ stringBuilder.append("buildingId in [");
|
|
|
+ admBuildingMap.keySet().stream().forEach(buildingId -> {
|
|
|
+ stringBuilder.append("'").append(buildingId).append("'").append(",");
|
|
|
+ });
|
|
|
+
|
|
|
+ String filters = StrUtil.sub(stringBuilder.toString(),0, -1);
|
|
|
+ filters+= "]";
|
|
|
+
|
|
|
+ admQueryCriteria.setFilters(filters);
|
|
|
+ admQueryCriteria.setOnlyCount(true);
|
|
|
+
|
|
|
+ admQueryCriteria.setName("floor");
|
|
|
+ AdmResponse admResponseF = floorService.doQuery(context, admQueryCriteria, AdmFloor.class);
|
|
|
+ if(DmpResult.SUCCESS.equals(admResponseF.getResult()) && admResponseF.getTotal() > 0){
|
|
|
+ return AdmResponse.failure(msg);
|
|
|
+ }
|
|
|
+ admQueryCriteria.setName("space");
|
|
|
+ AdmResponse admResponseSpace = spaceService.doQuery(context, admQueryCriteria, AdmSpace.class);
|
|
|
+ if(admResponseSpace.getResult().equals(DmpResult.SUCCESS) && admResponseSpace.getTotal() > 0){
|
|
|
+ return AdmResponse.failure(msg);
|
|
|
+ }
|
|
|
+ admQueryCriteria.setName("ispace");
|
|
|
+ AdmResponse admResponseISpace = iAdmISpaceService.doQuery(context, admQueryCriteria, AdmISpace.class);
|
|
|
+ if(admResponseISpace.getResult().equals(DmpResult.SUCCESS) && admResponseISpace.getTotal() > 0){
|
|
|
+ return AdmResponse.failure(msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ admQueryCriteria.setName("equipment");
|
|
|
+ AdmResponse admResponseEuip = equipmentService.doQuery(context, admQueryCriteria, AdmEquipment.class);
|
|
|
+ if(admResponseEuip.getResult().equals(DmpResult.SUCCESS) && admResponseEuip.getTotal() > 0){
|
|
|
+ return AdmResponse.failure(msg);
|
|
|
+ }
|
|
|
service.doDelete(context, vos);
|
|
|
return AdmResponse.success();
|
|
|
}
|
|
@@ -69,9 +127,7 @@ public class AdmBuildingController {
|
|
|
*/
|
|
|
@PostMapping("/single/delete")
|
|
|
public AdmResponse deleteSingle(@RequestBody List<AdmBuilding> vos) throws Exception {
|
|
|
- // 组装上下文条件
|
|
|
- InstanceUrlParam context = new InstanceUrlParam(groupCode, null, null, AdmCommonConstant.APP_ID);
|
|
|
- service.doDelete(context, vos);
|
|
|
+ delete(vos);
|
|
|
return AdmResponse.success();
|
|
|
}
|
|
|
|
|
@@ -86,6 +142,11 @@ public class AdmBuildingController {
|
|
|
// 组装上下文条件
|
|
|
InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
|
|
|
List<AdmBuilding> vos = CollUtil.newArrayList(createRequest.getContent());
|
|
|
+ vos.forEach(admBuilding -> {
|
|
|
+ if(StrUtil.isEmpty(admBuilding.getName())){
|
|
|
+ admBuilding.setName(ObjectNameUtil.objectName("建筑-"));
|
|
|
+ }
|
|
|
+ });
|
|
|
vos = service.doUpdate(context, AdmBuilding.class, vos);
|
|
|
return AdmResponse.success(vos);
|
|
|
}
|