ludc
2023-07-18 ec407e8676f6245d88da3d9f729ad545ae3218c0
Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/CodeClassifyValueServiceImpl.java
@@ -1,12 +1,15 @@
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;
import com.vci.ubcs.code.enumpack.FrameworkDataLCStatus;
import com.vci.ubcs.code.enumpack.*;
import com.vci.ubcs.code.mapper.CodeClassifyValueMapper;
import com.vci.ubcs.code.service.ICodeBasicSecService;
import com.vci.ubcs.code.service.ICodeClassifyValueService;
@@ -16,11 +19,15 @@
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.DefaultAttrAssimtUtil;
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.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;
@@ -30,7 +37,8 @@
import java.util.stream.Collectors;
import static com.vci.ubcs.code.constant.FrameWorkDefaultValueConstant.LC_STATUS;
import static com.vci.ubcs.code.constant.FrameWorkLangCodeConstant.*;
import static com.vci.ubcs.code.constant.FrameWorkLangCodeConstant.DATA_CASCADE_LINKED_NOT_DELETE;
import static com.vci.ubcs.code.constant.FrameWorkLangCodeConstant.DATA_OID_NOT_EXIST;
@Service
public class CodeClassifyValueServiceImpl  extends ServiceImpl<CodeClassifyValueMapper, CodeClassifyValue> implements ICodeClassifyValueService {
@@ -48,7 +56,7 @@
   /**
    * 上级节点的属性名称
    */
   private static  final String PARENT_FIELD_NAME = "parentClassifyValueOid";
   private static final String PARENT_FIELD_NAME = "parentClassifyValueOid";
   /**
    * 查询分类码段的码值 树
@@ -58,8 +66,7 @@
    */
   @Override
   public List<Tree> treeCodeClassifyValue(TreeQueryObject treeQueryObject) throws VciBaseException {
      // List<CodeClassifyValueDO> doList =selectCodeClassifyValueDOByTree(treeQueryObject);
      List<CodeClassifyValue> doList =selectCodeClassifyValueDO4Tree(treeQueryObject);
      List<CodeClassifyValue> doList = selectCodeClassifyValueDO4Tree(treeQueryObject);
      List<CodeClassifyValueVO> voList = CodeClassifyValueWrapper.build().listVO(doList);
      TreeWrapperOptions treeWrapperOptions = new TreeWrapperOptions(PARENT_FIELD_NAME);
      treeWrapperOptions.copyFromTreeQuery(treeQueryObject);
@@ -77,12 +84,13 @@
    * @throws VciBaseException 参数为空,唯一项,必输项不通过时会抛出异常
    */
   @Override
   @Transactional(rollbackFor = Exception.class)
   public boolean addSave(CodeClassifyValueDTO codeClassifyValueDTO) throws VciBaseException{
      VciBaseUtil.alertNotNull(codeClassifyValueDTO,"需要添加的数据对象");
      //添加对码值子父级的判断
      if(StringUtils.isNotBlank(codeClassifyValueDTO.getParentclassifyvalueoid())){
         String parentclassifyvalueoid = codeClassifyValueDTO.getParentclassifyvalueoid();
         String codeclassifysecoid = codeClassifyValueDTO.getCodeclassifysecoid();
      if(StringUtils.isNotBlank(codeClassifyValueDTO.getParentClassifyValueOid())){
         String parentclassifyvalueoid = codeClassifyValueDTO.getParentClassifyValueOid();
         String codeclassifysecoid = codeClassifyValueDTO.getCodeClassifySecOid();
         CodeClassifyValue parentDO = codeClassifyValueMapper.selectById(parentclassifyvalueoid);
         if (parentDO.getCodeClassifySecOid().equalsIgnoreCase(codeclassifysecoid)){
            throw new VciBaseException("不允许在父码值中直接添加子码值");
@@ -91,6 +99,8 @@
      //将DTO转换为DO
      CodeClassifyValue codeClassifyValueDO = new CodeClassifyValue();
      BeanUtilForVCI.copyPropertiesIgnoreCase(codeClassifyValueDTO,codeClassifyValueDO);
      //填充一些默认值
      DefaultAttrAssimtUtil.addDefaultAttrAssimt(codeClassifyValueDO,MdmBtmTypeConstant.CODE_CLASSIFY_VALUE);
      //查询
      List<CodeClassifyValue> existList = codeClassifyValueMapper.selectList(Wrappers.<CodeClassifyValue>query()
         .lambda().eq(CodeClassifyValue::getCodeClassifySecOid, codeClassifyValueDO.getCodeClassifySecOid())
@@ -108,11 +118,14 @@
    * @throws VciBaseException 参数为空,唯一项,必输项不通过时会抛出异常
    */
   @Override
   @Transactional(rollbackFor = Exception.class)
   public boolean editSave(CodeClassifyValueDTO codeClassifyValueDTO) throws VciBaseException{
      VciBaseUtil.alertNotNull(codeClassifyValueDTO,"数据对象",codeClassifyValueDTO.getOid(),"分类码段的码值主键");
      //将DTO转换为DO
      CodeClassifyValue codeClassifyValueDO = selectByOid(codeClassifyValueDTO.getOid());
      revisionModelUtil.copyFromDTOIgnore(codeClassifyValueDTO,codeClassifyValueDO);
      //填充一些默认值
      DefaultAttrAssimtUtil.updateDefaultAttrAssimt(codeClassifyValueDO);
      boolean resBoolean = codeClassifyValueMapper.updateById(codeClassifyValueDO) > 0;
      return resBoolean;
   }
@@ -137,9 +150,7 @@
    * @return success为true为可以删除,false表示有数据引用,obj为true表示有下级
    */
   private R checkIsCanDeleteForDO(CodeClassifyValueDTO codeClassifyValueDTO, CodeClassifyValue codeClassifyValueDO) {
      if (!checkTs(codeClassifyValueDTO)) {
         return R.fail(TS_NOT_PROCESS);
      }
      //boService.checkTs(codeClassifyValueDTO);
      //校验下级是否有引用
      if(checkChildIsLinked(codeClassifyValueDO.getOid())){
         return R.fail(DATA_CASCADE_LINKED_NOT_DELETE);
@@ -204,7 +215,7 @@
      VciBaseUtil.alertNotNull(codeClassifyValueDTO,"分类码段的码值数据对象",codeClassifyValueDTO.getOid(),"分类码段的码值的主键");
      CodeClassifyValue codeClassifyValueDO = selectByOid(codeClassifyValueDTO.getOid());
      R baseResult = checkIsCanDeleteForDO(codeClassifyValueDTO,codeClassifyValueDO);
      if(baseResult.isSuccess()) {
      if(!baseResult.isSuccess()) {
         //找下级的,这个是可以删除的时候R
         List<String> childrenOids = codeClassifyValueMapper.selectAllLevelChildOid(codeClassifyValueDO.getOid().trim());
         if (!CollectionUtils.isEmpty(childrenOids)) {
@@ -273,7 +284,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)
@@ -281,18 +292,21 @@
      List<CodeClassifyValue> updateList = new ArrayList<>();
      dtoList.forEach(dto -> {
         if( StringUtils.isNotBlank( dto.getOid() )){
         if(StringUtils.isNotBlank(dto.getOid())){
            List<CodeClassifyValue> collect = valueDOList.stream().filter(value -> {
               return dto.getOid().equals(value.getOid());
            }).collect(Collectors.toList());
            collect.forEach(ccv -> {
               ccv.setOrderNum(dto.getOrdernum());
               ccv.setOrderNum(dto.getOrderNum());
               ccv.setId(dto.getId());
               ccv.setName(dto.getName());
               updateList.add(ccv);
            });
         }
      });
      if(updateList.isEmpty()){
         return R.fail("该操作有误【待操作集合为空】。");
      }
      boolean resBoolean = this.updateBatchById(updateList);
      return R.status(resBoolean);
   }
@@ -336,24 +350,82 @@
      List<String> oids = codeBasicSecService.getOidByCodeclassifysecOid(conditionMap.get("codeclassifysecoid"));
      LambdaQueryWrapper<CodeClassifyValue> wrapper = Wrappers.<CodeClassifyValue>query()
         .lambda().in(CodeClassifyValue::getCodeClassifySecOid,oids)
         .orderByDesc(CodeClassifyValue::getOrderNum);
         .orderByAsc(CodeClassifyValue::getOrderNum);
      return codeClassifyValueMapper.selectList(wrapper);
   }
   /**
    * 检查ts
    * @param tempDO
    * @return
    * 使用码段的主键获取分类的码值内容
    *
    * @param classifySecOid         码段的主键
    * @param parentClassifyValueOid 上级分类的主键
    * @return 分类码值的内容
    */
   private boolean checkTs(CodeClassifyValueDTO tempDO){
      LambdaQueryWrapper<CodeClassifyValue> wrapper = Wrappers.<CodeClassifyValue>query()
         .lambda().eq(CodeClassifyValue::getOid,tempDO.getOid()).select(CodeClassifyValue::getTs);
      long dbTs = codeClassifyValueMapper.selectById(wrapper).getTs().getTime();
      long currentTs = tempDO.getTs().getTime();
      if(dbTs == currentTs){
         return true;
   @Override
   public List<CodeClassifyValueVO> listCodeClassifyValueBySecOid(String classifySecOid, String parentClassifyValueOid) {
      if(StringUtils.isBlank(classifySecOid)){
         return new ArrayList<>();
      }
      return false;
      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 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;
   }
   /**
    * 数据对象转换为显示对象
    * @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;
   }
}