Browse Source

org: 关系实例表中增加字段rel_value

yaoll 4 years ago
parent
commit
08fdf6d13b

+ 1 - 0
dmp-model/src/main/java/com/persagy/dmp/rwd/model/RelationInstanceModel.java

@@ -14,6 +14,7 @@ public class RelationInstanceModel {
 	private String graphId;
 	private String graphCode;
 	private String relCode;
+	private String relValue;
 	private String objFrom;
 	private String objTo;
 	private Integer status;

+ 3 - 0
dmp-rwd/src/main/java/com/persagy/dmp/rwd/entity/RelationInstance.java

@@ -28,6 +28,7 @@ public class RelationInstance {
 	private String graphCode;
 	@Column(updatable = false)
 	private String relCode;
+	private String relValue;
 	@Column(updatable = false)
 	private String objFrom;
 	@Column(updatable = false)
@@ -52,6 +53,7 @@ public class RelationInstance {
 		entity.setGraphId(model.getGraphId());
 		entity.setGraphCode(model.getGraphCode());
 		entity.setRelCode(model.getRelCode());
+		entity.setRelValue(model.getRelValue());
 		entity.setObjFrom(model.getObjFrom());
 		entity.setObjTo(model.getObjTo());
 		entity.setStatus(model.getStatus());
@@ -71,6 +73,7 @@ public class RelationInstance {
 		model.setGraphId(this.getGraphId());
 		model.setGraphCode(this.getGraphCode());
 		model.setRelCode(this.getRelCode());
+		model.setRelValue(this.getRelValue());
 		model.setObjFrom(this.getObjFrom());
 		model.setObjTo(this.getObjTo());
 		model.setStatus(this.getStatus());

+ 1 - 0
dmp-rwd/src/main/java/com/persagy/dmp/rwd/service/InitService.java

@@ -337,6 +337,7 @@ public class InitService extends BaseService {
 		sql.append("   `graph_id` varchar(40) DEFAULT NULL,                                 \n");
 		sql.append("   `graph_code` varchar(40) DEFAULT NULL,                               \n");
 		sql.append("   `rel_code` varchar(40) DEFAULT NULL,                                 \n");
+		sql.append("   `rel_value` varchar(45) DEFAULT NULL,                                \n");
 		sql.append("   `obj_from` varchar(100) DEFAULT NULL,                                \n");
 		sql.append("   `obj_to` varchar(100) DEFAULT NULL,                                  \n");
 		sql.append("   `status` int(11) NOT NULL DEFAULT '1',                               \n");

+ 22 - 2
dmp-rwd/src/main/java/com/persagy/dmp/rwd/service/RelationInstanceService.java

@@ -91,12 +91,12 @@ public class RelationInstanceService extends BaseService {
 				return response;
 			}
 
+			QGraphInstance qt = QGraphInstance.graphInstance;
 			// 优先级: graphId > graphCode
 			if (param.getGraphId() != null) {
 				GraphInstance gi = graphInstanceRepository.getOne(entity.getGraphId());
 				entity.setGraphCode(gi.getGraphCode());
 			} else if (param.getGraphCode() != null) {
-				QGraphInstance qt = QGraphInstance.graphInstance;
 				Sort orders = Sort.by(new Sort.Order(Sort.Direction.ASC, "id"));
 				Iterable<GraphInstance> all = graphInstanceRepository.findAll(qt.groupCode.eq(groupCode).and(qt.projectId.eq(projectId).and(qt.graphCode.eq(entity.getGraphCode()))), orders);
 				GraphInstance next = all.iterator().next();
@@ -106,7 +106,25 @@ public class RelationInstanceService extends BaseService {
 			if (entity.getCreateApp() == null) {
 				entity.setCreateApp(DmpParameterStorage.getAppId());
 			}
-			list.add(entity);
+			// 判断是否已存在
+			QRelationInstance rt = QRelationInstance.relationInstance;
+			BooleanExpression exp = rt.groupCode.eq(entity.getGroupCode())
+					.and(rt.projectId.eq(entity.getProjectId()))
+					.and(rt.graphId.eq(entity.getGraphId()))
+					.and(rt.relCode.eq(entity.getRelCode()))
+					.and(rt.objFrom.eq(entity.getObjFrom()))
+					.and(rt.objTo.eq(entity.getObjTo()));
+			if (entity.getRelValue() != null) {
+				exp = exp.and(rt.relValue.eq(entity.getRelValue()));
+			} else {
+				exp = exp.and(rt.relValue.isNull());
+			}
+
+			long count = relationInstanceRepository.count(exp);
+			if (count == 0) {
+				// 数据不存在, 新增, 已存在时忽略
+				list.add(entity);
+			}
 		}
 		if (list.size() > 0) {
 			relationInstanceRepository.saveAll(list);
@@ -121,6 +139,7 @@ public class RelationInstanceService extends BaseService {
 				message.add("graphId", relation.getGraphId());
 				message.add("graphCode", relation.getGraphCode());
 				message.add("relCode", relation.getRelCode());
+				message.add("relValue", relation.getRelValue());
 				message.add("objFrom", relation.getObjFrom());
 				message.add("objTo", relation.getObjTo());
 				response.add(message);
@@ -210,5 +229,6 @@ public class RelationInstanceService extends BaseService {
 		response.setCount(query.getCount());
 		return response;
 	}
+
 }