|
@@ -13,7 +13,6 @@ import com.persagy.proxy.adm.utils.AdmContextUtil;
|
|
|
import com.persagy.proxy.common.entity.InstanceUrlParam;
|
|
|
import com.persagy.proxy.common.entity.RelationDTO;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
@@ -30,10 +29,12 @@ import java.util.List;
|
|
|
@RestController
|
|
|
@RequestMapping("/rel/fl-through-fl")
|
|
|
public class RelationFlThroughFlController {
|
|
|
+
|
|
|
+ private static final String GRAPH_CODE = "ThroughRelationship";
|
|
|
+ private static final String REL_CODE = "Fl2Fl";
|
|
|
+
|
|
|
@Autowired
|
|
|
private IAdmRelationService service;
|
|
|
- @Value("${middleware.group.code}")
|
|
|
- private String groupCode;
|
|
|
/**
|
|
|
* 创建楼层的贯通关系
|
|
|
* @param param
|
|
@@ -49,7 +50,9 @@ public class RelationFlThroughFlController {
|
|
|
}
|
|
|
// 创建关系对象
|
|
|
List<RelationDTO> voList = new ArrayList<>();
|
|
|
- voList.add(new RelationDTO(null, "ThroughRelationship", "Fl2Fl", null, floorId , floorOtherId));
|
|
|
+ RelationDTO relation = RelationDTO.builder().graphCode(GRAPH_CODE)
|
|
|
+ .relCode(REL_CODE).objFrom(floorId).objTo(floorOtherId).build();
|
|
|
+ voList.add(relation);
|
|
|
service.doSave(AdmContextUtil.toDmpContext(), voList);
|
|
|
return AdmResponse.success();
|
|
|
}
|
|
@@ -62,26 +65,44 @@ public class RelationFlThroughFlController {
|
|
|
@PostMapping("/unlink")
|
|
|
public AdmResponse delete(@RequestBody JSONObject param) throws Exception {
|
|
|
if(CollUtil.isEmpty(param)) {
|
|
|
- return AdmResponse.success();
|
|
|
+ return AdmResponse.failure("必填项:FloorId(楼层id)、FloorOtherId(其他楼层id)");
|
|
|
}
|
|
|
- // 组装上下文条件
|
|
|
- InstanceUrlParam context = AdmContextUtil.toDmpContext();
|
|
|
- // 组装条件
|
|
|
- QueryCriteria criteria = new QueryCriteria();
|
|
|
String floorId = param.getString("floorId");
|
|
|
String floorOtherId = param.getString("floorOtherId");
|
|
|
if(!StrUtil.isAllNotEmpty(floorId,floorOtherId)) {
|
|
|
return AdmResponse.failure("必填项:FloorId(楼层id)、FloorOtherId(其他楼层id)");
|
|
|
}
|
|
|
+ deleteById(AdmContextUtil.toDmpContext(), floorId, floorOtherId);
|
|
|
+ return AdmResponse.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过楼层Id删除
|
|
|
+ * @param context
|
|
|
+ * @param fromId
|
|
|
+ * @param toId
|
|
|
+ */
|
|
|
+ private void deleteById(InstanceUrlParam context, String fromId, String toId) {
|
|
|
+ // 都为空不处理
|
|
|
+ if(StrUtil.isAllBlank(fromId, toId)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 关系条件
|
|
|
ObjectNode node = JsonNodeFactory.instance.objectNode();
|
|
|
- node.put("graphCode", "ThroughRelationship");
|
|
|
- node.put("relCode", "Fl2Fl");
|
|
|
- node.put("objFrom", floorId);
|
|
|
- node.put("objTo",floorOtherId);
|
|
|
+ node.put("graphCode", GRAPH_CODE);
|
|
|
+ node.put("relCode", REL_CODE);
|
|
|
+ if(StrUtil.isNotBlank(fromId)) {
|
|
|
+ node.put("objFrom", fromId);
|
|
|
+ }
|
|
|
+ if(StrUtil.isNotBlank(toId)) {
|
|
|
+ node.put("objTo",toId);
|
|
|
+ }
|
|
|
+ // 执行删除
|
|
|
+ QueryCriteria criteria = new QueryCriteria();
|
|
|
criteria.setCriteria(node);
|
|
|
service.doDelete(context, criteria);
|
|
|
- return AdmResponse.success();
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 创建楼层的贯通关系
|
|
|
* 楼层的贯通,楼层一对多
|
|
@@ -93,27 +114,28 @@ public class RelationFlThroughFlController {
|
|
|
public AdmResponse createFloorOtherIdList(@RequestBody JSONObject param) {
|
|
|
String floorId = param.getString("floorId");
|
|
|
JSONArray floorOtherIdList = param.getJSONArray("floorOtherIdList");
|
|
|
- if(StrUtil.isBlank(floorId) || CollUtil.isEmpty(floorOtherIdList)) {
|
|
|
- return AdmResponse.failure("必填项:FloorId(楼层id)、FloorOtherIdList(其他楼层id列表),测方法会覆盖以前的记录");
|
|
|
+ if(StrUtil.isBlank(floorId)) {
|
|
|
+ return AdmResponse.failure("必填项:FloorId(楼层id),此方法会覆盖以前的记录");
|
|
|
}
|
|
|
- // 创建关系对象.先删除,后添加
|
|
|
InstanceUrlParam context = AdmContextUtil.toDmpContext();
|
|
|
+ // 先删除floorId的所有关系
|
|
|
+ deleteById(context, floorId, null);
|
|
|
+ deleteById(context, null, floorId);
|
|
|
+ // 如果没有待添加的,返回
|
|
|
+ if(CollUtil.isEmpty(floorOtherIdList)) {
|
|
|
+ return AdmResponse.success();
|
|
|
+ }
|
|
|
+ // 创建关系对象.先删除,后添加
|
|
|
List<RelationDTO> voList = new ArrayList<>();
|
|
|
for(int i = 0;i < floorOtherIdList.size();i++) {
|
|
|
String floorOtherId = floorOtherIdList.getString(i);
|
|
|
if(StrUtil.isBlank(floorOtherId)) {
|
|
|
continue;
|
|
|
}
|
|
|
- QueryCriteria queryRequest = new QueryCriteria();
|
|
|
- ObjectNode node = JsonNodeFactory.instance.objectNode();
|
|
|
- node.put("graphCode", "ThroughRelationship");
|
|
|
- node.put("relCode", "Fl2Fl");
|
|
|
- node.put("objFrom", floorId);
|
|
|
- node.put("objTo", floorOtherId);
|
|
|
- queryRequest.setCriteria(node);
|
|
|
- service.doDelete(context,queryRequest);
|
|
|
- // 创建关系对象 - 参考(datasyn中DataCenterSync.kt)
|
|
|
- voList.add(new RelationDTO(null, "ThroughRelationship", "Fl2Fl", null, floorId, floorOtherId));
|
|
|
+ // 创建关系对象
|
|
|
+ RelationDTO relation = RelationDTO.builder().graphCode(GRAPH_CODE)
|
|
|
+ .relCode(REL_CODE).objFrom(floorId).objTo(floorOtherId).build();
|
|
|
+ voList.add(relation);
|
|
|
}
|
|
|
// 组装上下文条件
|
|
|
service.doSave(context, voList);
|
|
@@ -130,27 +152,28 @@ public class RelationFlThroughFlController {
|
|
|
public AdmResponse createFloorIdList(@RequestBody JSONObject param) {
|
|
|
String floorOtherId = param.getString("floorOtherId");
|
|
|
JSONArray floorIdList = param.getJSONArray("floorIdList");
|
|
|
- if(StrUtil.isBlank(floorOtherId) || CollUtil.isEmpty(floorIdList)) {
|
|
|
- return AdmResponse.failure("必填项:FloorIdList(楼层id列表)、FloorOtherId(其他楼层id),测方法会覆盖以前的记录");
|
|
|
+ if(StrUtil.isBlank(floorOtherId)) {
|
|
|
+ return AdmResponse.failure("必填项:FloorOtherId(其他楼层id),测方法会覆盖以前的记录");
|
|
|
}
|
|
|
- // 创建关系对象.先删除,后添加
|
|
|
InstanceUrlParam context = AdmContextUtil.toDmpContext();
|
|
|
+ // 先删除floorOtherId的所有关系
|
|
|
+ deleteById(context, floorOtherId, null);
|
|
|
+ deleteById(context, null, floorOtherId);
|
|
|
+ // 如果没有待添加的,返回
|
|
|
+ if(CollUtil.isEmpty(floorIdList)) {
|
|
|
+ return AdmResponse.success();
|
|
|
+ }
|
|
|
+ // 创建关系对象.先删除,后添加
|
|
|
List<RelationDTO> voList = new ArrayList<>();
|
|
|
for(int i = 0;i < floorIdList.size();i++) {
|
|
|
String floorId = floorIdList.getString(i);
|
|
|
if(StrUtil.isBlank(floorId)) {
|
|
|
continue;
|
|
|
}
|
|
|
- QueryCriteria queryRequest = new QueryCriteria();
|
|
|
- ObjectNode node = JsonNodeFactory.instance.objectNode();
|
|
|
- node.put("graphCode", "ThroughRelationship");
|
|
|
- node.put("relCode", "Fl2Fl");
|
|
|
- node.put("objFrom", floorId);
|
|
|
- node.put("objTo", floorOtherId);
|
|
|
- queryRequest.setCriteria(node);
|
|
|
- service.doDelete(context,queryRequest);
|
|
|
- // 创建关系对象 - 参考(datasyn中DataCenterSync.kt)
|
|
|
- voList.add(new RelationDTO(null, "ThroughRelationship", "Fl2Fl", null, floorId, floorOtherId));
|
|
|
+ // 创建关系对象
|
|
|
+ RelationDTO relation = RelationDTO.builder().graphCode(GRAPH_CODE)
|
|
|
+ .relCode(REL_CODE).objFrom(floorId).objTo(floorOtherId).build();
|
|
|
+ voList.add(relation);
|
|
|
}
|
|
|
// 组装上下文条件
|
|
|
service.doSave(context, voList);
|