|
@@ -0,0 +1,204 @@
|
|
|
+package org.eco.vip.reliability.ser.service.construct;
|
|
|
+
|
|
|
+import cn.hutool.core.lang.tree.Tree;
|
|
|
+import cn.hutool.core.lang.tree.TreeNode;
|
|
|
+import com.mybatisflex.core.paginate.Page;
|
|
|
+import com.mybatisflex.core.query.QueryWrapper;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.eco.vip.core.pojo.PageResult;
|
|
|
+import org.eco.vip.core.utils.*;
|
|
|
+import org.eco.vip.orm.domain.PageQuery;
|
|
|
+import org.eco.vip.orm.service.BaseService;
|
|
|
+import org.eco.vip.reliability.ser.domain.construct.ConstructPO;
|
|
|
+import org.eco.vip.reliability.ser.domain.construct.pojo.ConstructBO;
|
|
|
+import org.eco.vip.reliability.ser.domain.construct.pojo.ConstructVO;
|
|
|
+import org.eco.vip.reliability.ser.mapper.ConstructMapper;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import static org.eco.vip.reliability.ser.domain.construct.table.ConstructPOTableDef.CONSTRUCT_PO;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Author: wyj
|
|
|
+ * @CreateTime: 2025-08-04
|
|
|
+ * @Belongpackage org.eco.vip.reliability.ser.service.construct
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class ConstructImpl extends BaseService<ConstructMapper, ConstructPO> implements IConstruct {
|
|
|
+
|
|
|
+
|
|
|
+ private QueryWrapper buidQueryWapper(ConstructBO bo) {
|
|
|
+ return buildBaseQueryWrapper().and(CONSTRUCT_PO.ID.eq(bo.getId()))
|
|
|
+ .and(CONSTRUCT_PO.PARENT_ID.eq(bo.getParentId()))
|
|
|
+ .and(CONSTRUCT_PO.CONFIG_NAME.eq(bo.getConfigName()));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询凡所有父节点信息
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<ConstructVO> selectOne(String id) {
|
|
|
+ ArrayList<ConstructVO> treeList = new ArrayList<>();
|
|
|
+ String parentId = id;
|
|
|
+ while (true){
|
|
|
+ ConstructVO constructVO = selectTreeNode(parentId);
|
|
|
+ if(ObjUtils.isEmpty(constructVO)){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ String parent = constructVO.getParentId();
|
|
|
+ if (parent == null) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ ConstructVO treeNode = selectTreeNode(parent);
|
|
|
+ if(ObjUtils.isEmpty(treeNode)){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ treeList.add(treeNode);
|
|
|
+ parentId = parent;
|
|
|
+ }
|
|
|
+ return treeList;
|
|
|
+ }
|
|
|
+
|
|
|
+ public ConstructVO selectTreeNode(String id){
|
|
|
+ QueryWrapper where = query().where(CONSTRUCT_PO.ID.eq(id));
|
|
|
+ ConstructVO oneAs = this.getOneAs(where, ConstructVO.class);
|
|
|
+ return oneAs;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询数据库
|
|
|
+ *
|
|
|
+ * @param constructBO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public PageResult<ConstructVO> selectPage(ConstructBO constructBO) {
|
|
|
+ QueryWrapper wrapper = buidQueryWapper(constructBO);
|
|
|
+ Page<ConstructVO> page = mapper.paginateWithRelationsAs(PageQuery.build(), wrapper, ConstructVO.class);
|
|
|
+ return PageResult.build(page);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除
|
|
|
+ *
|
|
|
+ * @param ids
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public boolean delete(List<String> ids) {
|
|
|
+ return this.removeByIds(ids);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询构型是否存在
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public boolean hasKeyByKey(String id) {
|
|
|
+ ConstructVO constructVO = this.selectById(id);
|
|
|
+ return !ObjUtils.isNotEmpty(constructVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询树结构(按机型->系统->部件层级展示,不进行分页)
|
|
|
+ *
|
|
|
+ * @param constructBO 包含查询条件的BO对象
|
|
|
+ * @return 完整的树结构数据
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<Tree<String>> selectTree(ConstructBO constructBO) {
|
|
|
+ QueryWrapper wrapper = QueryWrapper.create()
|
|
|
+ .eq(ConstructPO::getDelFlag, 0)
|
|
|
+ .eq(ConstructPO::getStatus, 1);
|
|
|
+ List<ConstructPO> aircraftList = this.list(wrapper);
|
|
|
+ return TreeUtils.build(
|
|
|
+ aircraftList.stream().map(aircraft ->
|
|
|
+ new TreeNode<>(aircraft.getId(),aircraft.getParentId(),aircraft.getConfigName(),aircraft.getCountNum()
|
|
|
+ ).setExtra(JsonUtils.parseObj(aircraft))
|
|
|
+ ).collect(Collectors.toList()),
|
|
|
+ null
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 递归构建树形结构(保持不变)
|
|
|
+ *
|
|
|
+ * @param allNodes 所有节点列表
|
|
|
+ * @param parentId 父节点ID(顶级节点为null)
|
|
|
+ * @return 组装好的树形节点列表
|
|
|
+ */
|
|
|
+ private List<ConstructVO> buildTree(List<ConstructVO> allNodes, Long parentId) {
|
|
|
+ return allNodes.stream()
|
|
|
+ .filter(node -> Objects.equals(node.getParentId(), parentId))
|
|
|
+ .peek(node -> node.setChildren(buildTree(allNodes, node.getId())))
|
|
|
+ .sorted(Comparator.comparing(ConstructVO::getConfigName))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取List
|
|
|
+ *
|
|
|
+ * @param configBO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<ConstructVO> selectList(ConstructBO configBO) {
|
|
|
+ QueryWrapper wrapper = buidQueryWapper(configBO);
|
|
|
+ List<ConstructVO> constructPOS = mapper.selectListWithRelationsByQueryAs(wrapper, ConstructVO.class);
|
|
|
+ return constructPOS;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * ‘
|
|
|
+ * 查询一条数据
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ConstructVO selectById(String id) {
|
|
|
+ ConstructBO bo = new ConstructBO();
|
|
|
+ bo.setId(id);
|
|
|
+ QueryWrapper wrapper = buidQueryWapper(bo);
|
|
|
+ ConstructVO constructVO = mapper.selectOneByQueryAs(wrapper, ConstructVO.class);
|
|
|
+ return constructVO;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增
|
|
|
+ *
|
|
|
+ * @param configBO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public boolean insert(ConstructBO configBO) {
|
|
|
+ ConstructPO convert = MapstructUtils.convert(configBO, ConstructPO.class);
|
|
|
+ return this.save(convert);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改信息
|
|
|
+ *
|
|
|
+ * @param configBO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public boolean update(ConstructBO configBO) {
|
|
|
+ ConstructPO po = new ConstructPO();
|
|
|
+ po.setCountNum(configBO.getCountNum());
|
|
|
+ po.setId(configBO.getId());
|
|
|
+ po.setVersion(1);
|
|
|
+ return this.updateById(po);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|