Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/CodeClassifyValueServiceImpl.java
@@ -1,10 +1,11 @@
package com.vci.ubcs.code.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vci.ubcs.code.constant.MdmBtmTypeConstant;
import com.vci.ubcs.code.dto.CodeClassifyValueDTO;
import com.vci.ubcs.code.entity.CodeBasicSec;
import com.vci.ubcs.code.entity.CodeClassifyValue;
@@ -19,17 +20,22 @@
import com.vci.ubcs.starter.revision.model.TreeWrapperOptions;
import com.vci.ubcs.starter.revision.service.RevisionModelUtil;
import com.vci.ubcs.starter.util.DefaultAttrAssimtUtil;
import com.vci.ubcs.starter.util.MdmBtmTypeConstant;
import com.vci.ubcs.starter.web.pagemodel.Tree;
import com.vci.ubcs.starter.web.util.BeanUtilForVCI;
import com.vci.ubcs.starter.web.util.VciBaseUtil;
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.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.rmi.ServerException;
import java.util.*;
import java.util.stream.Collectors;
@@ -38,7 +44,7 @@
import static com.vci.ubcs.code.constant.FrameWorkLangCodeConstant.DATA_OID_NOT_EXIST;
@Service
public class CodeClassifyValueServiceImpl  extends ServiceImpl<CodeClassifyValueMapper, CodeClassifyValue> implements ICodeClassifyValueService {
public class CodeClassifyValueServiceImpl extends ServiceImpl<CodeClassifyValueMapper, CodeClassifyValue> implements ICodeClassifyValueService {
   @Resource
   private RevisionModelUtil revisionModelUtil;
@@ -56,6 +62,33 @@
   private static final String PARENT_FIELD_NAME = "parentClassifyValueOid";
   /**
    * 克隆分类码值
    * @param codeClassifyValues
    * @return
    */
   @Override
   public boolean cloneCodeClassifyVaue(List<CodeClassifyValue> codeClassifyValues) {
      // 创建Map对象,用于存储原始oid和新oid的映射关系
      Map<String, String> oidMap = new HashMap<>();
      // 遍历对象数组,为每个对象生成新的oid,并将原始oid和新oid的映射关系存储到Map中
      for (CodeClassifyValue obj : codeClassifyValues) {
         String originalOid = obj.getOid();
         String newOid = VciBaseUtil.getPk();
         oidMap.put(originalOid, newOid);
      }
      // 遍历对象数组,更新每个对象的oid和codeClassifySecOid属性值
      for (CodeClassifyValue obj : codeClassifyValues) {
         String originalOid = obj.getOid();
         String newOid = oidMap.get(originalOid);
         obj.setOid(newOid);
         String originalParentClassifyValueOid = obj.getParentClassifyValueOid();
         String newParentClassifyValueOid = oidMap.get(originalParentClassifyValueOid);
         obj.setParentClassifyValueOid(newParentClassifyValueOid);
      }
      return this.saveBatch(codeClassifyValues);
   }
   /**
    * 查询分类码段的码值 树
    * @param treeQueryObject 树查询对象
    * @return 分类码段的码值 显示树
@@ -63,14 +96,13 @@
    */
   @Override
   public List<Tree> treeCodeClassifyValue(TreeQueryObject treeQueryObject) throws VciBaseException {
      // List<CodeClassifyValueDO> doList =selectCodeClassifyValueDOByTree(treeQueryObject);
      List<CodeClassifyValue> doList = selectCodeClassifyValueDO4Tree(treeQueryObject);
      List<CodeClassifyValueVO> voList = CodeClassifyValueWrapper.build().listVO(doList);
      TreeWrapperOptions treeWrapperOptions = new TreeWrapperOptions(PARENT_FIELD_NAME);
      treeWrapperOptions.copyFromTreeQuery(treeQueryObject);
      return revisionModelUtil.doList2Trees(voList,treeWrapperOptions,(CodeClassifyValueVO s) ->{
         //可以在这里处理树节点的显示
         return s.getId() + " " + s.getName() + (FrameworkDataLCStatus.DISABLED.getValue().equalsIgnoreCase(s
         return (Func.isNotEmpty(s.getId()) ? s.getId():"") + " " + (Func.isNotEmpty(s.getName()) ? s.getName():"") + (FrameworkDataLCStatus.DISABLED.getValue().equalsIgnoreCase(s
            .getLcStatus()) ? (" 【停用】 ") : "");
      });
   }
@@ -98,12 +130,16 @@
      CodeClassifyValue codeClassifyValueDO = new CodeClassifyValue();
      BeanUtilForVCI.copyPropertiesIgnoreCase(codeClassifyValueDTO,codeClassifyValueDO);
      //填充一些默认值
      DefaultAttrAssimtUtil.addDefaultAttrAssimt(codeClassifyValueDO,MdmBtmTypeConstant.CODE_CLASSIFY_VALUE);
      DefaultAttrAssimtUtil.addDefaultAttrAssimt(codeClassifyValueDO, MdmBtmTypeConstant.CODE_CLASSIFY_VALUE);
      LambdaQueryWrapper<CodeClassifyValue> wrapper = Wrappers.<CodeClassifyValue>query()
         .lambda().eq(CodeClassifyValue::getCodeClassifySecOid, codeClassifyValueDO.getCodeClassifySecOid());
      if(Func.isEmpty(codeClassifyValueDO.getParentClassifyValueOid())){
         wrapper.isNull(CodeClassifyValue::getParentClassifyValueOid);
      }else{
         wrapper.eq(CodeClassifyValue::getParentClassifyValueOid, codeClassifyValueDO.getParentClassifyValueOid());
      }
      //查询
      List<CodeClassifyValue> existList = codeClassifyValueMapper.selectList(Wrappers.<CodeClassifyValue>query()
         .lambda().eq(CodeClassifyValue::getCodeClassifySecOid, codeClassifyValueDO.getCodeClassifySecOid())
         .eq(CodeClassifyValue::getParentClassifyValueOid, codeClassifyValueDO.getParentClassifyValueOid())
      );
      List<CodeClassifyValue> existList = codeClassifyValueMapper.selectList(wrapper);
      codeClassifyValueDO.setOrderNum(existList.size() + 1);
      boolean resBoolean = codeClassifyValueMapper.insert(codeClassifyValueDO) > 0;
      return resBoolean;
@@ -213,19 +249,17 @@
      VciBaseUtil.alertNotNull(codeClassifyValueDTO,"分类码段的码值数据对象",codeClassifyValueDTO.getOid(),"分类码段的码值的主键");
      CodeClassifyValue codeClassifyValueDO = selectByOid(codeClassifyValueDTO.getOid());
      R baseResult = checkIsCanDeleteForDO(codeClassifyValueDTO,codeClassifyValueDO);
      if(!baseResult.isSuccess()) {
         //找下级的,这个是可以删除的时候R
         List<String> childrenOids = codeClassifyValueMapper.selectAllLevelChildOid(codeClassifyValueDO.getOid().trim());
      if(baseResult.isSuccess()) {
         //先删除下级码值,找下级的,这个是可以删除的时候
         List<String> childrenOids = codeClassifyValueMapper.selectChildOid(codeClassifyValueDO.getOid().trim());
         if (!CollectionUtils.isEmpty(childrenOids)) {
            Collection<Collection<String>> childrenCollections = VciBaseUtil.switchCollectionForOracleIn(childrenOids);
            for(Collection<String> s : childrenCollections){
               codeClassifyValueMapper.delete(Wrappers.<CodeClassifyValue>query().lambda().eq(CodeClassifyValue::getOid,s));
               codeClassifyValueMapper.deleteBatchIds(s);
            }
         }
      }else{
         return baseResult;
      }
      //执行删除操作
      //执行删除操作,再删除父的码值
      boolean resBoolean = codeClassifyValueMapper.deleteById(codeClassifyValueDO.getOid()) > 0;
      return R.status(resBoolean);
   }
@@ -282,7 +316,7 @@
    */
   @Override
   @Transactional(rollbackFor = Exception.class)
   public R batchSave4Order(List<CodeClassifyValueDTO> dtoList, String codeclassifysecoid) {
   public R batchSave4Order(List<CodeClassifyValueDTO> dtoList, String codeclassifysecoid) throws VciBaseException{
      VciBaseUtil.alertNotNull(codeclassifysecoid,"分类码段主键");
      List<CodeClassifyValue> valueDOList = codeClassifyValueMapper.selectList(Wrappers.<CodeClassifyValue>query()
         .lambda().eq(CodeClassifyValue::getCodeClassifySecOid,codeclassifysecoid)
@@ -302,6 +336,9 @@
            });
         }
      });
      if(updateList.isEmpty()){
         return R.fail("该操作有误【待操作集合为空】。");
      }
      boolean resBoolean = this.updateBatchById(updateList);
      return R.status(resBoolean);
   }
@@ -349,4 +386,105 @@
      return codeClassifyValueMapper.selectList(wrapper);
   }
   /**
    * 使用码段的主键获取分类的码值内容
    *
    * @param classifySecOid         码段的主键
    * @param parentClassifyValueOid 上级分类的主键
    * @return 分类码值的内容
    */
   @Override
   public List<CodeClassifyValueVO> listCodeClassifyValueBySecOid(String classifySecOid, String parentClassifyValueOid) {
      if(StringUtils.isBlank(classifySecOid)){
         return new ArrayList<>();
      }
      CodeBasicSec secDO = codeBasicSecService.getById(classifySecOid);
      if(secDO == null || StringUtils.isBlank(secDO.getOid())){
         throw new VciBaseException("码段的内容在系统中不存在");
      }
      if(StringUtils.isNotBlank(secDO.getParentClassifySecOid()) && StringUtils.isBlank(parentClassifyValueOid)){
         return new ArrayList<>();
         //因为有上级分类的时候,必须先选择上级分类的内容
      }
//      Map<String,String> conditionMap = new HashMap<>();
//      conditionMap.put("codeClassifySecOid",classifySecOid);
//      if(StringUtils.isNotBlank(parentClassifyValueOid)){
//         conditionMap.put("parentClassifyValueOid",parentClassifyValueOid);
//      }
//      PageHelper pageHelper = new PageHelper(-1);
//      pageHelper.addDefaultAsc("ordernum");
      QueryWrapper<CodeClassifyValue> wrapper = new QueryWrapper<>();
      wrapper.eq("codeClassifySecOid",classifySecOid);
      if(StringUtils.isNotBlank(parentClassifyValueOid)){
         wrapper.in("parentClassifyValueOid",VciBaseUtil.str2List(parentClassifyValueOid));
      }
      wrapper.orderByAsc("ordernum");
      List<CodeClassifyValue> valueDOList = codeClassifyValueMapper.selectList(wrapper);
      return codeClassifyValueDO2VOs(valueDOList);
   }
   /**
    * 根据主键获取码值字符串
    * @param oid
    * @return
    */
   @Override
   public String getClassifyValueStr(String oid){
      if(Func.isEmpty(oid)){
         return "";
      }
      String classifyValueStr = this.codeClassifyValueMapper.getClassifyValueStr(oid);
      return Func.isEmpty(classifyValueStr) ? "":classifyValueStr;
   }
   /**
    * 批量数据对象转换为显示对象
    * @param codeClassifyValueDOs 数据对象列表
    * @return 显示对象
    * @throws VciBaseException 参数为空或者不存在的时候会抛出异常
    */
   @Override
   public List<CodeClassifyValueVO> codeClassifyValueDO2VOs(Collection<CodeClassifyValue>  codeClassifyValueDOs) throws VciBaseException{
      List<CodeClassifyValueVO> voList = new ArrayList<CodeClassifyValueVO>();
      if(!CollectionUtils.isEmpty(codeClassifyValueDOs)){
         for(CodeClassifyValue s: codeClassifyValueDOs){
            CodeClassifyValueVO vo =  codeClassifyValueDO2VO(s);
            if(vo != null){
               voList.add(vo);
            }
         }
      }
      return voList;
   }
   /**
    * 根据codeClassifySecOid删除码值
    * @param codeClassifySecOid
    * @return
    * @throws ServerException
    */
   @Override
   public Boolean deleteClassifyValueBySecOid(String codeClassifySecOid) throws ServerException {
      LambdaQueryWrapper<CodeClassifyValue> wrapper = Wrappers.<CodeClassifyValue>query()
         .lambda().eq(CodeClassifyValue::getCodeClassifySecOid, codeClassifySecOid);
      return codeClassifyValueMapper.delete(wrapper) > 0;
   }
   /**
    * 数据对象转换为显示对象
    * @param  codeClassifyValueDO 数据对象
    * @return 显示对象
    * @throws VciBaseException 拷贝属性出错的时候会抛出异常
    */
   @Override
   public  CodeClassifyValueVO codeClassifyValueDO2VO(CodeClassifyValue codeClassifyValueDO) throws VciBaseException{
      CodeClassifyValueVO vo = new CodeClassifyValueVO();
      if(codeClassifyValueDO != null){
         BeanUtilForVCI.copyPropertiesIgnoreCase(codeClassifyValueDO,vo);
         //如果有lcstatus的类的话
      }
      return vo;
   }
}