|
@@ -28,6 +28,7 @@ import com.pavis.backend.slim.project.system.domain.SysRelation;
|
|
|
import com.pavis.backend.slim.project.system.domain.algorithm.AlgSpO;
|
|
|
import com.pavis.backend.slim.project.system.domain.annotation.ExportSchemaData;
|
|
|
import com.pavis.backend.slim.project.system.domain.annotation.ExportSysEntity;
|
|
|
+import com.pavis.backend.slim.project.system.domain.front.ClutterReturn;
|
|
|
import com.pavis.backend.slim.project.system.domain.front.FileKey;
|
|
|
import com.pavis.backend.slim.project.system.domain.front.InKgParameter;
|
|
|
import com.pavis.backend.slim.project.system.domain.front.KgReturn;
|
|
@@ -195,6 +196,8 @@ public class SysKgServiceImpl extends ServiceImpl<SysKgMapper, SysKg> implements
|
|
|
public void algorithm(AlgSpO algSpO) {
|
|
|
log.info("算法传参map:{}", JSON.toJSONString(algSpO));
|
|
|
// todo 先这么做,以后还需改动
|
|
|
+ sysEntityInstanceMapper.delete(new QueryWrapper<SysEntityInstance>().eq("kg_id", algSpO.getKgId()));
|
|
|
+ sysEntityRelationMapper.delete(new QueryWrapper<SysEntityRelation>().eq("kg_id", algSpO.getKgId()));
|
|
|
Integer integer = 0;
|
|
|
String oCopy = "";
|
|
|
String sCopy = "";
|
|
@@ -202,7 +205,7 @@ public class SysKgServiceImpl extends ServiceImpl<SysKgMapper, SysKg> implements
|
|
|
for (Map map : algSpO.getSpo()) {
|
|
|
if (map.get("s") != null) {
|
|
|
// check库里是否存在此值
|
|
|
- String s = md5Check(MD5.create().digestHex16((String) map.get("s")));
|
|
|
+ String s = md5Check(MD5.create().digestHex16((String) map.get("s")), algSpO.getKgId());
|
|
|
// 临时变量,将起点id赋值给sCopy,最后用于实例关系插入时使用
|
|
|
if (s.equals("false")) {
|
|
|
// 插入起始点实例
|
|
@@ -222,7 +225,7 @@ public class SysKgServiceImpl extends ServiceImpl<SysKgMapper, SysKg> implements
|
|
|
}
|
|
|
}
|
|
|
if (map.get("o") != null) {
|
|
|
- String o = md5Check(MD5.create().digestHex16((String) map.get("o")));
|
|
|
+ String o = md5Check(MD5.create().digestHex16((String) map.get("o")), algSpO.getKgId());
|
|
|
if (o.equals("false")) {
|
|
|
// 插入终点实例
|
|
|
SysEntityInstance sysEntityInstanceO = new SysEntityInstance();
|
|
@@ -245,7 +248,8 @@ public class SysKgServiceImpl extends ServiceImpl<SysKgMapper, SysKg> implements
|
|
|
List<SysEntityRelation> list = sysEntityRelationMapper.selectList(new QueryWrapper<SysEntityRelation>()
|
|
|
.eq("kg_id", algSpO.getKgId())
|
|
|
.eq("start_id", sCopy)
|
|
|
- .eq("end_id", oCopy));
|
|
|
+ .eq("end_id", oCopy)
|
|
|
+ );
|
|
|
if (list.size() == Hodgepodge.NUMBER) {
|
|
|
// 插入实例关系
|
|
|
SysEntityRelation sysEntityRelation = new SysEntityRelation();
|
|
@@ -272,9 +276,11 @@ public class SysKgServiceImpl extends ServiceImpl<SysKgMapper, SysKg> implements
|
|
|
* @param instanceId 唯一id
|
|
|
* @return 如果库里有值,直接将库里的值返回;如果没有,则返回false
|
|
|
*/
|
|
|
- public String md5Check(String instanceId) {
|
|
|
+ public String md5Check(String instanceId, String kgId) {
|
|
|
List<SysEntityInstance> listEIM = sysEntityInstanceMapper.selectList(new QueryWrapper<SysEntityInstance>()
|
|
|
- .eq("instance_id", instanceId));
|
|
|
+ .eq("instance_id", instanceId)
|
|
|
+ .eq("kg_id", kgId)
|
|
|
+ );
|
|
|
if (listEIM.size() > 0) {
|
|
|
return listEIM.get(0).getInstanceId();
|
|
|
} else {
|
|
@@ -627,7 +633,7 @@ public class SysKgServiceImpl extends ServiceImpl<SysKgMapper, SysKg> implements
|
|
|
.like("end", keyEntityRelation.getKeyWord())
|
|
|
;
|
|
|
}
|
|
|
- // zez 根据实体名字查询实例关系
|
|
|
+ // zez 根据实体名字模糊查询实例关系
|
|
|
if (Hodgepodge.ZERO_STR.equals(keyEntityRelation.getEntOrRel())) {
|
|
|
if (keyEntityRelation.getEntityName() != null && !"".equals(keyEntityRelation.getEntityName())) {
|
|
|
queryWrap
|
|
@@ -641,11 +647,11 @@ public class SysKgServiceImpl extends ServiceImpl<SysKgMapper, SysKg> implements
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // zez 根据实体关系查询关系
|
|
|
+ // zez 根据实体关系模糊查询关系
|
|
|
if (Hodgepodge.ONE_STR.equals(keyEntityRelation.getEntOrRel())) {
|
|
|
if (keyEntityRelation.getEntityRelation() != null && !"".equals(keyEntityRelation.getEntityRelation())) {
|
|
|
queryWrap
|
|
|
- .eq("entity_relation", "-" + keyEntityRelation.getEntityRelation() + "-")
|
|
|
+ .like("entity_relation", "-" + keyEntityRelation.getEntityRelation() + "-")
|
|
|
.eq("kg_id", keyEntityRelation.getKgId());
|
|
|
PageHelper.startPage(keyEntityRelation.getPageNum(), keyEntityRelation.getPageSize());
|
|
|
List<SysEntityRelation> sysEntityRelations = sysEntityRelationMapper.selectList(queryWrap);
|
|
@@ -770,4 +776,112 @@ public class SysKgServiceImpl extends ServiceImpl<SysKgMapper, SysKg> implements
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
+ public SysEntityInstance insOrUpdEnIce(SysEntityInstance sysEntityInstance) {
|
|
|
+ log.info("******接口(insOrUpdEnIce)--->入参(sysEntityInstance):{}", JSON.toJSONString(sysEntityInstance));
|
|
|
+ String s = md5Check(MD5.create().digestHex16(sysEntityInstance.getName()), sysEntityInstance.getKgId());
|
|
|
+ Long userId = SecurityUtils.getUserId();
|
|
|
+ if ("false".equals(s)) {
|
|
|
+ sysEntityInstance.setUserId(userId);
|
|
|
+ sysEntityInstance.setCreateBy(String.valueOf(userId));
|
|
|
+ sysEntityInstance.setCreateTime(new Date());
|
|
|
+ sysEntityInstance.setInstanceId(MD5.create().digestHex16(sysEntityInstance.getName()));
|
|
|
+ sysEntityInstanceMapper.insert(sysEntityInstance);
|
|
|
+ } else {
|
|
|
+ sysEntityInstance.setUpdateBy(String.valueOf(userId));
|
|
|
+ sysEntityInstance.setUpdateTime(new Date());
|
|
|
+ sysEntityInstanceMapper.update(sysEntityInstance, new UpdateWrapper<SysEntityInstance>()
|
|
|
+ .eq("instance_id", sysEntityInstance.getInstanceId())
|
|
|
+ .eq("kg_id", sysEntityInstance.getKgId())
|
|
|
+ );
|
|
|
+ }
|
|
|
+ return sysEntityInstance;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void delEnIce(FileKey fileKey) {
|
|
|
+ log.info("*****接口(delEnIce)--->入参(fileKey):{}", JSON.toJSONString(fileKey));
|
|
|
+ if (fileKey.getEnIceIds().size() > 0 && fileKey.getKgId() != null) {
|
|
|
+ for (String id : fileKey.getEnIceIds()) {
|
|
|
+ //删除关于此点的所有关系 根据起点和终点去进行删除
|
|
|
+ sysEntityRelationMapper.delete(new QueryWrapper<SysEntityRelation>()
|
|
|
+ .eq("kg_id", fileKey.getKgId())
|
|
|
+ .eq("start_id", id)
|
|
|
+ );
|
|
|
+
|
|
|
+ sysEntityRelationMapper.delete(new QueryWrapper<SysEntityRelation>()
|
|
|
+ .eq("kg_id", fileKey.getKgId())
|
|
|
+ .eq("end_id", id)
|
|
|
+ );
|
|
|
+
|
|
|
+ sysEntityInstanceMapper.delete(new QueryWrapper<SysEntityInstance>()
|
|
|
+ .eq("instance_id", id)
|
|
|
+ .eq("kg_id", fileKey.getKgId())
|
|
|
+ );
|
|
|
+ }
|
|
|
+ log.info("******实体-删除成功******");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void delEntRlation(FileKey fileKey) {
|
|
|
+ log.info("*****接口(delEntRlation)--->入参(fileKey):{}", JSON.toJSONString(fileKey));
|
|
|
+ if (fileKey.getEnRelationIds().size() > 0 && fileKey.getKgId() != null && !"".equals(fileKey.getKgId())) {
|
|
|
+ for (String id : fileKey.getEnRelationIds()) {
|
|
|
+ sysEntityRelationMapper.delete(new QueryWrapper<SysEntityRelation>()
|
|
|
+ .eq("id", id)
|
|
|
+ .eq("kg_id", fileKey.getKgId())
|
|
|
+ );
|
|
|
+ }
|
|
|
+ log.info("******实体关系-删除成功******");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ClutterReturn selEntAndEntRela(FileKey fileKey) {
|
|
|
+ log.info("*****接口(selEntAndEntRela)--->入参(fileKey):{}", JSON.toJSONString(fileKey));
|
|
|
+ ClutterReturn clutterReturn = new ClutterReturn();
|
|
|
+ if (fileKey.getStart() != null && fileKey.getEnd() != null && !"".equals(fileKey.getStart()) && !"".equals(fileKey.getEnd()) && fileKey.getKgId() != null && !"".equals(fileKey.getKgId())) {
|
|
|
+ List<SysEntityInstance> startList = sysEntityInstanceMapper.selectList(new QueryWrapper<SysEntityInstance>()
|
|
|
+ .eq("entity_name", fileKey.getStart())
|
|
|
+ .eq("kg_id", fileKey.getKgId())
|
|
|
+ );
|
|
|
+ List<SysEntityInstance> endList = sysEntityInstanceMapper.selectList(new QueryWrapper<SysEntityInstance>()
|
|
|
+ .eq("entity_name", fileKey.getEnd())
|
|
|
+ .eq("kg_id", fileKey.getKgId())
|
|
|
+ );
|
|
|
+ clutterReturn.setEntList(endList);
|
|
|
+ clutterReturn.setStartList(startList);
|
|
|
+ }
|
|
|
+ log.info("*****接口(selEntAndEntRela)--->出参(clutterReturn):{}", JSON.toJSONString(clutterReturn));
|
|
|
+ return clutterReturn;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void insOrUpdRelation(SysEntityRelation sysEntityRelation) {
|
|
|
+ log.info("*****接口(insOrUpdRelation)--->入参(sysEntityRelation):{}", JSON.toJSONString(sysEntityRelation));
|
|
|
+ // zez 获取登录人id
|
|
|
+ Long userId = SecurityUtils.getUserId();
|
|
|
+ // 效验一下,数据库中,是否存在。如果存在,则进行提醒,如果不存在,则新增
|
|
|
+ List<SysEntityRelation> sysEntityRelations = sysEntityRelationMapper.selectList(new QueryWrapper<SysEntityRelation>()
|
|
|
+ .eq("start", sysEntityRelation.getStart())
|
|
|
+ .eq("end", sysEntityRelation.getEnd())
|
|
|
+ .eq("relation",sysEntityRelation.getRelation())
|
|
|
+ .eq("kg_id",sysEntityRelation.getKgId())
|
|
|
+ );
|
|
|
+ if (sysEntityRelations.size() == 0) {
|
|
|
+ if (sysEntityRelation.getId() != null && !"".equals(sysEntityRelation.getId())) {
|
|
|
+ sysEntityRelation.setUpdateBy(String.valueOf(userId));
|
|
|
+ sysEntityRelation.setUpdateTime(new Date());
|
|
|
+ sysEntityRelationMapper.updateById(sysEntityRelation);
|
|
|
+ } else {
|
|
|
+ sysEntityRelation.setCreateBy(String.valueOf(userId));
|
|
|
+ sysEntityRelation.setCreateTime(new Date());
|
|
|
+ sysEntityRelation.setUserId(userId);
|
|
|
+ sysEntityRelationMapper.insert(sysEntityRelation);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("数据库中已存在该关系,请重新填写!");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|