xiejun
2023-07-18 24e44fc25fc7b502486373589e61791ff5bb5eac
Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmIOServiceImpl.java
@@ -8,7 +8,6 @@
import com.vci.ubcs.code.bo.CodeTemplateAttrSqlBO;
import com.vci.ubcs.code.dto.CodeOrderDTO;
import com.vci.ubcs.code.entity.CodeAllCode;
import com.vci.ubcs.code.entity.CodeClassify;
import com.vci.ubcs.code.enumpack.CodeDefaultLC;
import com.vci.ubcs.code.enumpack.CodeLevelTypeEnum;
import com.vci.ubcs.code.lifecycle.CodeAllCodeLC;
@@ -33,7 +32,6 @@
import com.vci.ubcs.starter.revision.model.BaseModel;
import com.vci.ubcs.starter.util.DefaultAttrAssimtUtil;
import com.vci.ubcs.starter.util.LocalFileUtil;
import com.vci.ubcs.starter.util.MdmBtmTypeConstant;
import com.vci.ubcs.starter.web.constant.QueryOptionConstant;
import com.vci.ubcs.starter.web.enumpck.BooleanEnum;
import com.vci.ubcs.starter.web.enumpck.UserSecretEnum;
@@ -41,7 +39,6 @@
import com.vci.ubcs.starter.web.pagemodel.*;
import com.vci.ubcs.starter.web.toolmodel.DateConverter;
import com.vci.ubcs.starter.web.util.*;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.map.HashedMap;
@@ -51,7 +48,6 @@
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.RichTextString;
import org.apache.poi.ss.usermodel.Workbook;
import org.springblade.core.cache.utils.CacheUtil;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.tool.api.R;
import org.springframework.beans.BeanUtils;
@@ -68,6 +64,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
import static com.alibaba.druid.util.FnvHash.Constants.LIMIT;
@@ -361,16 +358,23 @@
         //参照的自行输入名称
         //分类注入的不用,都是导入后自动处理的
         //编码,状态等字段不导入
         List<CodeClassifyTemplateAttrVO> templateAttrVOS = codeClassifyTemplateVO.getAttributes().stream().filter(s ->
         List<CodeClassifyTemplateAttrVO> codeClassifyTemplateAttrVOList=codeClassifyTemplateVO.getAttributes();
         if(!CollectionUtils.isEmpty(codeClassifyTemplateAttrVOList)) {
            if (CollectionUtils.isEmpty(codeClassifyTemplateAttrVOList)) {
               throw new VciBaseException("模板没有配置属性");
            }
         }
         List<CodeClassifyTemplateAttrVO> templateAttrVOS = codeClassifyTemplateAttrVOList.stream().filter(s ->
            !DEFAULT_ATTR_LIST.contains(s.getId())
               && StringUtils.isBlank(s.getComponentRule())
               && StringUtils.isBlank(s.getClassifyInvokeAttr())
               && (isHistory || VciBaseUtil.getBoolean(s.getFormDisplayFlag()))
         ).collect(Collectors.toList());
         if(CollectionUtils.isEmpty(templateAttrVOS)){
            throw new VciBaseException("模板没有配置任何【表单显示】为【是】的属性");
         }
            if (CollectionUtils.isEmpty(templateAttrVOS)) {
               throw new VciBaseException("模板没有配置任何【表单显示】为【是】的属性");
            }
         List<CodeClassifyTemplateAttrVO> idAttrVOList = codeClassifyTemplateVO.getAttributes().stream().filter(s -> s.getId().equalsIgnoreCase(CODE_FIELD)).collect(Collectors.toList());
         LinkedList<WriteExcelData> excelDataList = new LinkedList<>();
         Workbook workbook = new HSSFWorkbook();
@@ -673,7 +677,7 @@
         //相似校验
         Map<String,String>resembleMap=new HashMap<>();
         List<DataResembleVO> dataResembleVOS=new ArrayList<>();
         String btmtypeid= classifyFullInfo.getTopClassifyVO().getBtmtypeid();
         String btmtypeid= classifyFullInfo.getTopClassifyVO().getBtmTypeId();
         bathcResembleQuery(codeClassifyOid,templateVO,needSaveCboList,resembleMap,btmtypeid,dataResembleVOS);
         if(resembleMap.size()>0) {
            if(!CollectionUtils.isEmpty(dataResembleVOS)) {
@@ -973,7 +977,7 @@
         //相似校验
         Map<String, String> resembleMap = new HashMap<>();
         List<DataResembleVO> dataResembleVOS = new ArrayList<>();
         String btmtypeid = classifyFullInfo.getTopClassifyVO().getBtmtypeid();
         String btmtypeid = classifyFullInfo.getTopClassifyVO().getBtmTypeId();
         bathcResembleQuery(templateVO.getCodeclassifyoid(), templateVO, needSaveCboList, resembleMap, btmtypeid, dataResembleVOS);
         if (resembleMap.size() > 0) {
            if (!CollectionUtils.isEmpty(dataResembleVOS)) {
@@ -1313,7 +1317,7 @@
      //相似校验
      Map<String,String>resembleMap=new HashMap<>();
      List<DataResembleVO> dataResembleVOS=new ArrayList<>();
      String btmtypeid= classifyFullInfo.getTopClassifyVO().getBtmtypeid();
      String btmtypeid= classifyFullInfo.getTopClassifyVO().getBtmTypeId();
      bathcResembleQuery(orderDTO.getCodeClassifyOid(),templateVO,needSaveCboList,resembleMap,btmtypeid,dataResembleVOS);
      if(resembleMap.size()>0) {
         isCreateUUid=true;
@@ -1448,8 +1452,8 @@
   @Override
   public R batchImportData(List<CodeImprotSaveDatVO> codeImprotSaveDatVOList, String classifyAttr, boolean isImprot) {
      boolean success=true;
      WriteExcelOption eo = new WriteExcelOption();
      AtomicBoolean success= new AtomicBoolean(true);
      codeImprotSaveDatVOList.stream().forEach(codeImprotSaveDatVO -> {
         List<SheetRowData> rowDataList = new ArrayList<>();
         List<ClientBusinessObject>cboList=new ArrayList<>();
@@ -1566,7 +1570,7 @@
                     log.error("批量产生编码的时候出错了", e);
                     thisCbos.stream().forEach(cbo -> {
                        String rowIndex = cbo.getAttributeValue(IMPORT_ROW_INDEX);
                        errorMap.put(rowIndex, errorMap.getOrDefault(rowIndex, "") + ";系统错误,存储数据的时候出错了");
                        errorMap.put(rowIndex, errorMap.getOrDefault(rowIndex, "") + ";系统错误,存储数据的时候出错了:"+e.getMessage());
                     });
                  }
               }
@@ -1588,14 +1592,34 @@
               try {
                  productCodeService.productCodeAndSaveData(classifyFullInfo, codeClassifyTemplateVO, ruleVO, orderDTO.getSecDTOList(), dataCBOList);
               } catch (Exception e) {
                  e.printStackTrace();
                  log.error("批量产生编码的时候出错了", e);
                  needSaveCboList.stream().forEach(cbo -> {
                     String rowIndex = cbo.getAttributeValue(IMPORT_ROW_INDEX);
                     errorMap.put(rowIndex, errorMap.getOrDefault(rowIndex, "") + ";系统错误,存储数据的时候出错了:"+e.getMessage());
                  });
               }
               //如果是编码生成失败,则直接就失败了,其他的判断出来有错误的我们都统一返回到excel里面
               engineService.batchSaveSelectChar(codeClassifyTemplateVO, dataCBOList);
            }
         }
         if(errorMap.size()>0) {
            success.set(false);
            LinkedList<WriteExcelData> excelDataList = new LinkedList<>();
            excelDataList.add(new WriteExcelData(0, 0, "错误信息"));
            final int[] index = {1};
            errorMap.forEach((key,v)->{
               excelDataList.add(new WriteExcelData(index[0]++, 0, "第"+(Integer.parseInt(key)+1)+"行数据:"+v));
            });
            eo.addSheetDataList(codeClassifyTemplateVO.getName() + "导入模板", excelDataList);
         }
      });
      return  R.success(isImprot?"批量历史导入成功":"批量申请成功");
      if(!success.get()){
         String excelName = LocalFileUtil.getDefaultTempFolder() + File.separator + (isImprot?"批量历史错误信息.xls":"批量申请错误信息.xls");
         ExcelUtil.writeDataToFile(excelName,eo);
         return  R.fail(excelName);
      }else {
         return R.success(isImprot ? "批量历史导入成功" : "批量申请成功");
      }
   }
   /***
@@ -1825,7 +1849,7 @@
            });
            //关键熟悉更改
            if (!CollectionUtils.isEmpty(editBoList)) {
               engineService.updateBatchByBaseModel(classifyFullInfo.getTopClassifyVO().getBtmtypeid(),editBoList);//保存数据
               engineService.updateBatchByBaseModel(classifyFullInfo.getTopClassifyVO().getBtmTypeId(),editBoList);//保存数据
            }
            errorMap.putAll(errorKeyMap);
         }
@@ -1860,7 +1884,7 @@
            //如果是编码生成失败,则直接就失败了,其他的判断出来有错误的我们都统一返回到excel里面
            engineService.batchSaveSelectChar(templateVO, dataCBOList);
            // if(!isProcess){
            needSaveCboList.stream().forEach(needSaveCbo->{
            dataCBOList.stream().forEach(needSaveCbo->{
               XMLResultDataObjectDetailDO resultDataObjectDetailDO=new XMLResultDataObjectDetailDO();
               resultDataObjectDetailDO.setCode(needSaveCbo.getId());
               String oid=needSaveCbo.getOid();
@@ -2121,7 +2145,7 @@
      }else {
         //存储数据
         try {
            engineService.updateBatchByBaseModel(classifyFullInfo.getTopClassifyVO().getBtmtypeid(),updateList);
            engineService.updateBatchByBaseModel(classifyFullInfo.getTopClassifyVO().getBtmTypeId(),updateList);
            codeAllCodeService.saveBatch(codeAllCodeList);
            if(deleteList.size()>0) {
               commonsMapper.deleteByTaleAndOid(tableName, VciBaseUtil.array2String(deleteList.toArray(new String[]{})));
@@ -2248,7 +2272,7 @@
      //没有限制分类,但是一个模板只可能在一个业务类型里面,所以直接查询这个业务类型即可
      if (!CollectionUtils.isEmpty(conditionMap)) {
         final String[] sql = {"select count(*) from " + VciBaseUtil.getTableName(classifyFullInfo.getTopClassifyVO().getBtmtypeid()) + " where 1 = 1 "};
         final String[] sql = {"select count(*) from " + VciBaseUtil.getTableName(classifyFullInfo.getTopClassifyVO().getBtmTypeId()) + " where 1 = 1 "};
         conditionMap.forEach((key, value) -> {
            sql[0] += " and " + key + " = " + value;
         });
@@ -2588,7 +2612,7 @@
         String oid=rowData.getOid();
         String rowNumber=rowData.getRowIndex();
         ClientBusinessObject cbo = new ClientBusinessObject();
         DefaultAttrAssimtUtil.addDefaultAttrAssimt(cbo, classifyFullInfo.getTopClassifyVO().getBtmtypeid());
         DefaultAttrAssimtUtil.addDefaultAttrAssimt(cbo, classifyFullInfo.getTopClassifyVO().getBtmTypeId());
         rowData.getData().forEach((index,value)->{
            String field = fieldIndexMap.get(index);
            if(StringUtils.isBlank(field)){
@@ -2693,7 +2717,7 @@
      String fullPath = getFullPath(classifyFullInfo);
      codeImprotDataVO.getDatas().stream().forEach(rowData -> {
         ClientBusinessObject cbo=new ClientBusinessObject();
         DefaultAttrAssimtUtil.addDefaultAttrAssimt(cbo, classifyFullInfo.getTopClassifyVO().getBtmtypeid());
         DefaultAttrAssimtUtil.addDefaultAttrAssimt(cbo, classifyFullInfo.getTopClassifyVO().getBtmTypeId());
         rowData.forEach((field,value)->{
            try {
               cbo.setAttributeValueWithNoCheck(field,value);
@@ -2716,6 +2740,7 @@
                  Integer userSecret = VciBaseUtil.getCurrentUserSecret();
                  cbo.setAttributeValue(SECRET_FIELD,String.valueOf((userSecret==null || userSecret ==0)? UserSecretEnum.NONE.getValue():userSecret));
               }
               cbo.setLcStatus(CodeDefaultLC.EDITING.getValue());
            }else{
               //此时还没有转换路径
               //cbo.setAttributeValue(CODE_FULL_PATH_FILED, childOidPathMap.getOrDefault(rowData.getData().getOrDefault(CODE_CLASSIFY_OID_FIELD,""),fullPath));
@@ -2745,7 +2770,7 @@
                     String fullPath,boolean newCode){
      rowDataList.stream().forEach(rowData -> {
         ClientBusinessObject cbo=new ClientBusinessObject();
          DefaultAttrAssimtUtil.addDefaultAttrAssimt(cbo, classifyFullInfo.getTopClassifyVO().getBtmtypeid());
          DefaultAttrAssimtUtil.addDefaultAttrAssimt(cbo, classifyFullInfo.getTopClassifyVO().getBtmTypeId());
         rowData.getData().forEach((index,value)->{
            String field = fieldIndexMap.get(index);
            if (StringUtils.isBlank(field)) {
@@ -2772,6 +2797,7 @@
                  Integer userSecret = VciBaseUtil.getCurrentUserSecret();
                  cbo.setAttributeValue(SECRET_FIELD,String.valueOf((userSecret==null || userSecret ==0)? UserSecretEnum.NONE.getValue():userSecret));
               }
               cbo.setLcStatus(CodeDefaultLC.EDITING.getValue());
            }else{
               //此时还没有转换路径
               //cbo.setAttributeValue(CODE_FULL_PATH_FILED, childOidPathMap.getOrDefault(rowData.getData().getOrDefault(CODE_CLASSIFY_OID_FIELD,""),fullPath));
@@ -3409,7 +3435,7 @@
            engineService.wrapperKeyAttrConditionMap(value, keyRuleVO, attrId, trim, ignoreCase, ignoreWidth, trimAll, conditionMap);
         });
         if (!CollectionUtils.isEmpty(ketAttrMap)) {
            CodeTemplateAttrSqlBO sqlBO = engineService.getSqlByTemplateVO(classifyFullInfo.getTopClassifyVO().getBtmtypeid(), templateVO, conditionMap, null);
            CodeTemplateAttrSqlBO sqlBO = engineService.getSqlByTemplateVO(classifyFullInfo.getTopClassifyVO().getBtmTypeId(), templateVO, conditionMap, null);
            boolean isKeyCheck= commonsMapper.queryCountBySql(sqlBO.getSqlCount()) > 0;
            if(isKeyCheck){
               List<Map<String,String>> newDataList=  commonsMapper.queryByOnlySqlForMap(sqlBO.getSqlUnPage());
@@ -3478,12 +3504,12 @@
                              List<String> unExistRuleClassifyOidList   ){
      if(!CollectionUtils.isEmpty(classifyVOMap)){
         classifyVOMap.values().parallelStream().forEach(classifyVO->{
            if(StringUtils.isNotBlank(classifyVO.getCoderuleoid())){
               ruleOidMap.put(classifyVO.getOid(),classifyVO.getCoderuleoid());
            if(StringUtils.isNotBlank(classifyVO.getCodeRuleOid())){
               ruleOidMap.put(classifyVO.getOid(),classifyVO.getCodeRuleOid());
            }else{
               //递归找上级
               List<String> ruleOidList = new ArrayList<>();
               recursionRule(classifyVOMap,classifyVO.getParentcodeclassifyoid(),ruleOidList);
               recursionRule(classifyVOMap,classifyVO.getParentCodeClassifyOid(),ruleOidList);
               if(!CollectionUtils.isEmpty(ruleOidList)){
                  ruleOidMap.put(classifyVO.getOid(),ruleOidList.get(0));
               }else{
@@ -3503,11 +3529,11 @@
   private void recursionRule(Map<String, CodeClassifyVO> classifyVOMap,String classifyOid,List<String> ruleOidList){
      if(classifyVOMap.containsKey(classifyOid)){
         CodeClassifyVO classifyVO = classifyVOMap.get(classifyOid);
         if(StringUtils.isNotBlank(classifyVO.getCoderuleoid())){
            ruleOidList.add(classifyVO.getCoderuleoid());
         if(StringUtils.isNotBlank(classifyVO.getCodeRuleOid())){
            ruleOidList.add(classifyVO.getCodeRuleOid());
            return;
         }else{
            recursionRule(classifyVOMap,classifyVO.getParentcodeclassifyoid(),ruleOidList);
            recursionRule(classifyVOMap,classifyVO.getParentCodeClassifyOid(),ruleOidList);
         }
      }else{
         Map<String, CodeClassifyVO> parentClassifyVOMap=new HashMap<>();
@@ -3617,13 +3643,15 @@
      }
   }
   private List<ClientBusinessObject> ChangeMapTOClientBusinessObjects(List<Map<String,String>> oldDataMap){
      List<ClientBusinessObject> clientBusinessObjectList=new CopyOnWriteArrayList<>();
      oldDataMap.parallelStream().forEach(dataMap->{
      List<ClientBusinessObject> clientBusinessObjectList=new ArrayList<>();
      oldDataMap.stream().forEach(dataMap->{
         ClientBusinessObject clientBusinessObject=new ClientBusinessObject();
         DefaultAttrAssimtUtil.copplyDefaultAttrAssimt(dataMap,clientBusinessObject);
         dataMap.forEach((key,value)->{
            clientBusinessObject.setAttributeValue(key,value);
         });
         for (String key:dataMap.keySet()){
            Object value= dataMap.getOrDefault(key,"");
            clientBusinessObject.setAttributeValue(key,value.toString());
         }
         clientBusinessObjectList.add(clientBusinessObject);
      });
      return clientBusinessObjectList;
   }