ludc
2023-05-27 d9fb787c2eb0bc4058087b81bc5f01abbaf2ba65
Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/CodeClassifyServiceImpl.java
@@ -2,6 +2,7 @@
import com.alibaba.nacos.common.utils.StringUtils;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
@@ -33,6 +34,7 @@
import com.vci.ubcs.starter.revision.model.TreeQueryObject;
import com.vci.ubcs.starter.revision.model.TreeWrapperOptions;
import com.vci.ubcs.starter.revision.service.RevisionModelUtil;
import com.vci.ubcs.starter.util.BladeTreeQueryObject;
import com.vci.ubcs.starter.util.LocalFileUtil;
import com.vci.ubcs.starter.web.pagemodel.BaseQueryObject;
import com.vci.ubcs.starter.web.pagemodel.DataGrid;
@@ -48,6 +50,7 @@
import org.springblade.core.mp.support.Condition;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
@@ -73,10 +76,14 @@
   @Resource
   private CodeOsbtmtypeMapper codeOsbtmtypeMapper;
   @Resource
   CodeOsbtmtypeattributeMapper codeOsbtmtypeattributeMapper;
   private CodeOsbtmtypeattributeMapper codeOsbtmtypeattributeMapper;
   @Resource
   ICodeRuleService ICodeRuleService;
   private IBtmTypeClient btmTypeClient;
   /**
    * 日志
@@ -254,7 +261,7 @@
      if(StringUtils.isBlank(oid)){
         throw new ServiceException("oid不能为空!");
      }
      return !codeClassifyMapper.checkHasChild(oid.trim());
      return codeClassifyMapper.checkHasChild(oid.trim());
   }
@@ -469,8 +476,45 @@
      return tree;
   }
   /**
    * 根据树形查询对象来查询数据对象
    *
    * @param treeQueryObject 树形查询对象
    * @return 查询结果,数据对象
    */
   @Override
   public List<CodeClassifyVO> selectCodeClassifyDOByTree(TreeQueryObject treeQueryObject) {
      List<CodeClassify> doList =codeClassifyMapper.selectCodeClassifyVOByTree(treeQueryObject.getParentOid());
      List<CodeClassifyVO> voList = codeClassifyDO2VOs(doList);
      return voList;
   }
   /**
    * 使用编号的路径获取对象
    *
    * @param fieldPath 编号的路径,一定要从最顶层节点开始,格式为xxx/yyy/zz 这样
    * @return 分类的显示对象
    */
   @Override
   public CodeClassifyVO getObjectByClsfNamePath(String fieldPath){
      CodeClassifyVO codeClassifyVO=new CodeClassifyVO();
      List<CodeClassify> classifyList = codeClassifyMapper.selectByFieldNamePath(fieldPath,"name");
      if(classifyList.size()>0){
         codeClassifyVO=codeClassifyDO2VO(classifyList.get(0));
      }
      return codeClassifyVO;
   }
   /***
    * 根据上级节点获取下级节点代号路径和名称路径
    * @param classifyId
    * @param enable
    * @return
    */
   @Override
   public List<CodeClassifyVO> getIdPathToNamePathByParentId(String classifyId, boolean enable) {
      return null;
   }
//   /**
   //   /**
//    * 根据树形查询对象来查询数据对象
//    *
//    * @param treeQueryObject 树形查询对象
@@ -961,7 +1005,7 @@
    * @throws VciBaseException 参数为空,数据不存在时会抛出异常
    */
   @Override
   public  CodeClassifyVO getObjectByOid(String oid) throws VciBaseException{
   public CodeClassifyVO getObjectByOid(String oid) throws VciBaseException{
      return codeClassifyDO2VO(selectByOid(oid));
   }
@@ -982,7 +1026,7 @@
   }
   /**
    * 主题库的树
    * 主题库的树,已经联调业务类型查询
    *
    * @param treeQueryObject 树形查询对象
    * @return 主题库显示树
@@ -993,10 +1037,20 @@
         treeQueryObject = new TreeQueryObject();
      }
      if(treeQueryObject.getConditionMap() == null){
         treeQueryObject.setConditionMap(new HashMap<>());
         treeQueryObject.setConditionMap(new HashMap<String,String>());
      }
      treeQueryObject.getConditionMap().put(PARENT_FIELD_NAME, "=null");
      return treeCodeClassify(treeQueryObject);
      List<Tree> trees = treeCodeClassify(treeQueryObject);
      treeQueryObject.getConditionMap().put("domain", AppConstant.APPLICATION_NAME_CODE);
      BaseQueryObject baseQueryObject = new BaseQueryObject();
      baseQueryObject.setConditionMap(treeQueryObject.getConditionMap());
      List<BtmTypeVO> btmTypeVOS = btmTypeClient.getRef(baseQueryObject).getData();
      if(Func.isEmpty(btmTypeVOS) || Func.isEmpty(trees)){
         return null;
      }
      List<Tree> treeList = trees.stream().filter(tree -> btmTypeVOS.stream().
         anyMatch(btmType -> Objects.equals(tree.getAttributes().get("id"), btmType.getId()))).collect(Collectors.toList());
      return treeList;
   }
   /**
@@ -1050,18 +1104,37 @@
      CodeClassify classifyDO = selectByOid(codeClassifyOid);
      //查询上级
      fullInfo.setCurrentClassifyVO(codeClassifyDO2VO(classifyDO));
      List<Map<String, Object>> maps = codeClassifyMapper.selectAllLevelParentByOid(codeClassifyOid);
      List<CodeClassify> codeClassifyList = new ArrayList<>();
      for (Map<String, Object> map : maps) {
         CodeClassify codeClassify = new CodeClassify();
         codeClassify.setOid(String.valueOf(map.get("OID")));
         codeClassify.setOid(String.valueOf(map.get("LEVEL")));
         codeClassifyList.add(codeClassify);
      }
//      List<Map<String, Object>> maps = codeClassifyMapper.selectAllLevelParentByOid(codeClassifyOid);
//      List<Map<String, Object>> maps = selectAllLevelParentByOid(codeClassifyOid);
      List<CodeClassify> codeClassifyList = selectAllLevelParentByOid(codeClassifyOid);
//      for (Map<String, Object> map : maps) {
//         CodeClassify codeClassify = new CodeClassify();
//         codeClassify.setOid(String.valueOf(map.get("OID")));
//         codeClassify.setDataLevel((Integer) map.get("LEVEL"));
//         codeClassifyList.add(codeClassify);
//      }
      fullInfo.setParentClassifyVOs(codeClassifyDO2VOs(codeClassifyList));
      if(!CollectionUtils.isEmpty(fullInfo.getParentClassifyVOs())){
         fullInfo.setTopClassifyVO(fullInfo.getParentClassifyVOs().stream().filter(s->StringUtils.isBlank(s.getParentcodeclassifyoid())).findFirst().orElseGet(()->null));
      }
      return fullInfo;
   }
   /**
    * 统计子节点的个数
    *
    * @param codeClassifyOid 分类的主键
    * @return 个数
    */
   @Override
   public int countChildrenByClassifyOid(String codeClassifyOid) {
//      Map<String,String> conditionMap = new HashMap<>();
//      conditionMap.put("parentCodeClassifyOid",codeClassifyOid);
      QueryWrapper<CodeClassify> wrapper = new QueryWrapper<>();
      wrapper.eq("parentCodeClassifyOid",codeClassifyOid);
      return codeClassifyMapper.selectCount(wrapper).intValue();
   }
}