|
@@ -0,0 +1,184 @@
|
|
|
|
+package org.eco.als.service.impl;
|
|
|
|
+
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
|
+import com.mybatisflex.core.paginate.Page;
|
|
|
|
+import com.mybatisflex.core.query.QueryWrapper;
|
|
|
|
+import jakarta.annotation.Resource;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.eco.als.domain.KGraphEntity;
|
|
|
|
+import org.eco.als.domain.bo.KGraphEntityBo;
|
|
|
|
+import org.eco.als.domain.bo.KGraphTaskBo;
|
|
|
|
+import org.eco.als.domain.vo.KGraphClauseVo;
|
|
|
|
+import org.eco.als.domain.vo.KGraphEntityVo;
|
|
|
|
+import org.eco.als.mapper.KGraphEntityMapper;
|
|
|
|
+import org.eco.als.service.IKGraphClauseService;
|
|
|
|
+import org.eco.als.service.IKGraphEntityService;
|
|
|
|
+import org.eco.als.service.IKGraphTaskService;
|
|
|
|
+import org.eco.common.core.core.page.PageResult;
|
|
|
|
+import org.eco.common.core.utils.MapstructUtils;
|
|
|
|
+import org.eco.common.orm.core.page.PageQuery;
|
|
|
|
+import org.eco.common.orm.core.service.impl.BaseServiceImpl;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Arrays;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+import static org.eco.als.domain.table.KGraphEntityTableDef.K_GRAPH_ENTITY;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 知识图谱实体关系Service业务层处理
|
|
|
|
+ *
|
|
|
|
+ * @author wgk
|
|
|
|
+ * @date 2025-01-03
|
|
|
|
+ */
|
|
|
|
+@Service
|
|
|
|
+@Slf4j
|
|
|
|
+public class KGraphEntityServiceImpl extends BaseServiceImpl<KGraphEntityMapper, KGraphEntity> implements IKGraphEntityService {
|
|
|
|
+ @Resource
|
|
|
|
+ private KGraphEntityMapper kGraphEntityMapper;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private IKGraphTaskService kGraphTaskService;
|
|
|
|
+ @Resource
|
|
|
|
+ private IKGraphClauseService kGraphClauseService;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public QueryWrapper query() {
|
|
|
|
+ return super.query().from(K_GRAPH_ENTITY);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private QueryWrapper buildQueryWrapper(KGraphEntityBo kGraphEntityBo) {
|
|
|
|
+ QueryWrapper queryWrapper = super.buildBaseQueryWrapper();
|
|
|
|
+ queryWrapper.and(K_GRAPH_ENTITY.CLAUSE_ID.eq
|
|
|
|
+ (kGraphEntityBo.getClauseId()));
|
|
|
|
+ queryWrapper.and(K_GRAPH_ENTITY.HEAD_ENTITY.eq
|
|
|
|
+ (kGraphEntityBo.getHeadEntity()));
|
|
|
|
+ queryWrapper.and(K_GRAPH_ENTITY.HEAD_ENTITY_CLASS.eq
|
|
|
|
+ (kGraphEntityBo.getHeadEntityClass()));
|
|
|
|
+ queryWrapper.and(K_GRAPH_ENTITY.RELATION.eq
|
|
|
|
+ (kGraphEntityBo.getRelation()));
|
|
|
|
+ queryWrapper.and(K_GRAPH_ENTITY.TAIL_ENTITY.eq
|
|
|
|
+ (kGraphEntityBo.getTailEntity()));
|
|
|
|
+ queryWrapper.and(K_GRAPH_ENTITY.TAIL_ENTITY_CLASS.eq
|
|
|
|
+ (kGraphEntityBo.getTailEntityClass()));
|
|
|
|
+ queryWrapper.and(K_GRAPH_ENTITY.STATUS.eq
|
|
|
|
+ (kGraphEntityBo.getStatus()));
|
|
|
|
+ queryWrapper.and(K_GRAPH_ENTITY.REMARKS.eq
|
|
|
|
+ (kGraphEntityBo.getRemarks()));
|
|
|
|
+
|
|
|
|
+ return queryWrapper;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 查询知识图谱实体关系
|
|
|
|
+ *
|
|
|
|
+ * @param id 知识图谱实体关系主键
|
|
|
|
+ * @return 知识图谱实体关系
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public KGraphEntityVo selectById(Long id) {
|
|
|
|
+ return this.getOneAs(query().where(K_GRAPH_ENTITY.ID.eq(id)), KGraphEntityVo.class);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 查询知识图谱实体关系列表
|
|
|
|
+ *
|
|
|
|
+ * @param kGraphEntityBo 知识图谱实体关系Bo
|
|
|
|
+ * @return 知识图谱实体关系集合
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public List<KGraphEntityVo> selectList(KGraphEntityBo kGraphEntityBo) {
|
|
|
|
+ QueryWrapper queryWrapper = buildQueryWrapper(kGraphEntityBo);
|
|
|
|
+ return this.listAs(queryWrapper, KGraphEntityVo.class);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 分页查询知识图谱实体关系列表
|
|
|
|
+ *
|
|
|
|
+ * @param kGraphEntityBo 知识图谱实体关系Bo
|
|
|
|
+ * @return 分页知识图谱实体关系集合
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public PageResult<KGraphEntityVo> selectPage(KGraphEntityBo kGraphEntityBo) {
|
|
|
|
+ QueryWrapper queryWrapper = buildQueryWrapper(kGraphEntityBo);
|
|
|
|
+ Page<KGraphEntityVo> page = this.pageAs(PageQuery.build(), queryWrapper, KGraphEntityVo.class);
|
|
|
|
+ return PageResult.build(page);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 新增知识图谱实体关系
|
|
|
|
+ *
|
|
|
|
+ * @param kGraphEntityBo 知识图谱实体关系Bo
|
|
|
|
+ * @return 结果:true 操作成功,false 操作失败
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public boolean insert(KGraphEntityBo kGraphEntityBo) {
|
|
|
|
+ KGraphEntity kGraphEntity = MapstructUtils.convert(kGraphEntityBo, KGraphEntity.class);
|
|
|
|
+
|
|
|
|
+ return this.save(kGraphEntity);//使用全局配置的雪花算法主键生成器生成ID值
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public boolean saveBatch(List<KGraphEntityBo> kGraphEntityBoList) {
|
|
|
|
+ List<KGraphEntity> kGraphEntityList = new ArrayList<>();
|
|
|
|
+ kGraphEntityBoList.forEach(kGraphEntityBo -> {
|
|
|
|
+ kGraphEntityList.add(MapstructUtils.convert(kGraphEntityBo, KGraphEntity.class));
|
|
|
|
+ });
|
|
|
|
+ boolean isSave = this.saveBatch(kGraphEntityList, 100);
|
|
|
|
+ if (isSave) {
|
|
|
|
+ KGraphClauseVo kGraphClauseVo = kGraphClauseService.selectById(kGraphEntityList.getFirst().getClauseId());
|
|
|
|
+ KGraphTaskBo kGraphTaskBo = new KGraphTaskBo();
|
|
|
|
+ kGraphTaskBo.setId(kGraphClauseVo.getTaskId());
|
|
|
|
+ kGraphTaskBo.setStatus("2");
|
|
|
|
+ kGraphTaskService.update(kGraphTaskBo);
|
|
|
|
+ }
|
|
|
|
+ return isSave;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 新增知识图谱实体关系,前台提供主键值,一般用于导入的场合
|
|
|
|
+ *
|
|
|
|
+ * @param kGraphEntityBo 知识图谱实体关系Bo
|
|
|
|
+ * @return 结果:true 操作成功,false 操作失败
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public boolean insertWithPk(KGraphEntityBo kGraphEntityBo) {
|
|
|
|
+ KGraphEntity kGraphEntity = MapstructUtils.convert(kGraphEntityBo, KGraphEntity.class);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ return kGraphEntityMapper.insertWithPk(kGraphEntity) > 0;//前台传来主键值
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 修改知识图谱实体关系
|
|
|
|
+ *
|
|
|
|
+ * @param kGraphEntityBo 知识图谱实体关系Bo
|
|
|
|
+ * @return 结果:true 更新成功,false 更新失败
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public boolean update(KGraphEntityBo kGraphEntityBo) {
|
|
|
|
+ KGraphEntity kGraphEntity = MapstructUtils.convert(kGraphEntityBo, KGraphEntity.class);
|
|
|
|
+ if (ObjectUtil.isNotNull(kGraphEntity) && ObjectUtil.isNotNull(kGraphEntity.getId())) {
|
|
|
|
+ boolean updated = this.updateById(kGraphEntity);
|
|
|
|
+ return updated;
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 批量删除知识图谱实体关系
|
|
|
|
+ *
|
|
|
|
+ * @param ids 需要删除的知识图谱实体关系主键集合
|
|
|
|
+ * @return 结果:true 删除成功,false 删除失败
|
|
|
|
+ */
|
|
|
|
+ @Transactional
|
|
|
|
+ @Override
|
|
|
|
+ public boolean deleteByIds(Long[] ids) {
|
|
|
|
+ return this.removeByIds(Arrays.asList(ids));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|