xiejun
2023-06-14 ffb3d0f1af7e5a93b9a509b0838d9b58a1449bdc
批量申请接口提交
已修改7个文件
已添加4个文件
1575 ■■■■■ 文件已修改
Source/UBCS/ubcs-service-api/ubcs-code-api/src/main/java/com/vci/ubcs/code/bo/AttributeValue.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/UBCS/ubcs-service-api/ubcs-code-api/src/main/java/com/vci/ubcs/code/vo/pagemodel/CodeImportTemplateVO.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/UBCS/ubcs-service-api/ubcs-omd-api/src/main/java/com/vci/ubcs/omd/util/Tool.java 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/UBCS/ubcs-service-api/ubcs-util-api/src/main/java/com/vci/ubcs/starter/poi/util/ExcelUtil.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/UBCS/ubcs-service-api/ubcs-util-api/src/main/java/com/vci/ubcs/starter/util/DefaultAttrAssimtUtil.java 71 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/UBCS/ubcs-service-api/ubcs-util-api/src/main/java/com/vci/ubcs/starter/web/util/VciBaseUtil.java 33 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/UBCS/ubcs-service-api/ubcs-util-api/src/main/java/com/vci/ubcs/starter/web/util/WebUtil.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/mapper/CommonsMapper.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmIOServiceImpl.java 1159 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/util/AttributeChecker.java 115 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/util/ClientBusinessObject.java 111 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/UBCS/ubcs-service-api/ubcs-code-api/src/main/java/com/vci/ubcs/code/bo/AttributeValue.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,16 @@
package com.vci.ubcs.code.bo;
import org.omg.CORBA.portable.IDLEntity;
public class AttributeValue implements IDLEntity {
    public String attrName = "";
    public String attrVal = "";
    public AttributeValue() {
    }
    public AttributeValue(String attrName, String attrVal) {
        this.attrName = attrName;
        this.attrVal = attrVal;
    }
}
Source/UBCS/ubcs-service-api/ubcs-code-api/src/main/java/com/vci/ubcs/code/vo/pagemodel/CodeImportTemplateVO.java
@@ -1,13 +1,22 @@
package com.vci.ubcs.code.vo.pagemodel;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
/****
 * æ‰¹é‡ç”³è¯·redis缓存对象
 * @author xiejun
 * @date 2023-06-14
 */
@Data
public class CodeImportTemplateVO {
    private List<ColumnVO> cloNamesList=new ArrayList<>();
    private CodeClassifyTemplateVO codeClstemplateVO;
    private CodeClassifyTemplateVO codeClassifyTemplateVO;
    private CodeClassifyVO codeClassifyVO;
}
Source/UBCS/ubcs-service-api/ubcs-omd-api/src/main/java/com/vci/ubcs/omd/util/Tool.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,39 @@
package com.vci.ubcs.omd.util;
import java.util.ArrayList;
public class Tool {
    public static final String ALLOWNULL = "allowNull";
    public static final String BTM = "btm";
    public static final String ISFIXLEN = "isFixLen";
    public static final String LENGTH = "length";
    public static final String ENUMNAME = "enumName";
    public static final String ACCURACY = "accuracy";
    public static final String LINKTYPENAME = "linkTypeName";
    public static final String VERSION = "version";
    public static ArrayList<String> convertArrayToList(String[] array) {
        ArrayList<String> list = new ArrayList();
        for(int i = 0; i < array.length; ++i) {
            list.add(array[i]);
        }
        return list;
    }
    public static String getOtherValueByType(String other, String type) {
        String[] otherArray = other.split(";");
        for(int i = 0; i < otherArray.length; ++i) {
            String otherValue = otherArray[i];
            if (otherValue.contains(type)) {
                return otherValue.substring(otherValue.indexOf("=") + 2, otherValue.length());
            }
        }
        return null;
    }
}
Source/UBCS/ubcs-service-api/ubcs-util-api/src/main/java/com/vci/ubcs/starter/poi/util/ExcelUtil.java
@@ -61,6 +61,10 @@
    private static Logger logger = LoggerFactory.getLogger(ExcelUtil.class);
    public static final String KEY_ATTR_CHAR = "☆";
    public static final String REQUIRED_CHAR = "*";
    /**
     * æ›¿æ¢å­—符
     */
    public static final String SPECIAL_CHAR  = "VCI";
    public ExcelUtil() {
    }
Source/UBCS/ubcs-service-api/ubcs-util-api/src/main/java/com/vci/ubcs/starter/util/DefaultAttrAssimtUtil.java
@@ -1,6 +1,6 @@
package com.vci.ubcs.starter.util;
import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.vci.ubcs.starter.exception.VciBaseException;
import com.vci.ubcs.starter.revision.model.BaseModel;
import com.vci.ubcs.starter.web.util.VciBaseUtil;
@@ -9,8 +9,11 @@
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Map;
/**
 * æ–°å¢žæ—¶é»˜è®¤å€¼å±žæ€§èµ‹å€¼
@@ -50,7 +53,7 @@
            baseModel.setVersionSeq(1);
            baseModel.setVersionRule("0");
            baseModel.setVersionValue("1");
            baseModel.setNameOid(VciBaseUtil.getPk());
            baseModel.setRevisionOid(VciBaseUtil.getPk());
            baseModel.setLastModifier(userId);
        }catch (VciBaseException e){
            e.printStackTrace();
@@ -79,4 +82,68 @@
        return (T)baseModel;
    }
    /**
     * æ–°å¢žæ—¶å¡«å……默认值
     * @param object ç»§æ‰¿äº†BaseModel的实体对象
     * @param <T>   è¿”回值的类型
     * @return
     * @throws VciBaseException
     */
    public static <T extends BaseModel> T copplyDefaultAttrAssimt(Map<String,String> dataMap, T object) throws VciBaseException {
        BaseModel baseModel = object;
        try {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            baseModel.setOid(dataMap.getOrDefault("OID",""));
            String createTime=dataMap.getOrDefault("CREATETIME","");
            baseModel.setCreateTime(chageStringToDate(createTime));
            baseModel.setNameOid(dataMap.getOrDefault("NAMEOID",""));
            String lastModifyTime=dataMap.getOrDefault("LASTMODIFYTIME","");
            baseModel.setLastModifyTime(chageStringToDate(lastModifyTime));
            String ts=dataMap.getOrDefault("TS","");
            baseModel.setTs(chageStringToDate(ts));
            baseModel.setRevisionOid(dataMap.getOrDefault("REVISIONOID",""));
            //用户id
            String userId = AuthUtil.getUserId().toString();
            baseModel.setBtmname(dataMap.getOrDefault("BTMNAME",""));
            baseModel.setCreator(dataMap.getOrDefault("CREATOR",""));
            baseModel.setFirstR(dataMap.getOrDefault("FIRSTR",""));
            baseModel.setFirstV(dataMap.getOrDefault("FIRSTV",""));
            baseModel.setLastR(dataMap.getOrDefault("LASTR",""));
            baseModel.setLastV(dataMap.getOrDefault("LASTV",""));
            baseModel.setRevisionSeq(chageStringToInt(dataMap.getOrDefault("REVISIONSEQ","")));
            baseModel.setOwner(dataMap.getOrDefault("OWNER",""));
            baseModel.setVersionSeq(chageStringToInt(dataMap.getOrDefault("VERSIONSEQ","")));
            baseModel.setVersionRule(dataMap.getOrDefault("VERSIONRULE",""));
            baseModel.setVersionValue(dataMap.getOrDefault("VERSIONVALUE",""));
            baseModel.setRevisionOid(dataMap.getOrDefault("REVISIONOID",""));
            baseModel.setLastModifier(userId);
        }catch (VciBaseException e){
            e.printStackTrace();
        }
        return (T)baseModel;
    }
    private static int chageStringToInt(String value){
        int newValue=0;
        if(StringUtils.isNotBlank(value)){
            newValue = Integer.parseInt(value);
        }
        return newValue;
    }
    private static Date chageStringToDate(String value){
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date=new Date();
        if(StringUtils.isNotBlank(value)){
            try {
                date = format.parse(value);
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        return date;
    }
}
Source/UBCS/ubcs-service-api/ubcs-util-api/src/main/java/com/vci/ubcs/starter/web/util/VciBaseUtil.java
@@ -1143,7 +1143,38 @@
    public static <T> Collection<Collection<T>> switchCollectionForOracleIn(Collection<T> list) {
        return switchCollectionForOracleIn(list, 500);
    }
    /**
     * oracle in æŸ¥è¯¢ä¸èƒ½è¶…过1000,转换一下集合
     * ç”±äºŽSQL语句1000个可能很长,超过oracle10g,所以牺牲性能分配为500个数组
     * @param list éœ€è¦è½¬æ¢çš„列表内容
     * @return åˆ†ç»„后的list
     */
    public static <T> List<List<T>> switchListForOracleIn(List<T> list) {
        List<List<T>> listHasList = new ArrayList<List<T>>();
        if(list == null){
            return listHasList;
        }
        List<T> newList = new ArrayList<T>();
        for(Object obj : list){
            //为了让list还可以添加内容,因为使用sublist后,list不能再Add了
            newList.add((T)obj);
        }
        int muti = 1;
        if(newList.size() >500){
            int balance = newList.size()%500;
            muti = (newList.size() - balance)/500 + (balance == 0?0:1);
        }
        for(int i = 0 ; i < muti; i ++){
            int start = i*500;
            int end = start + 500;
            if(i == muti-1 || end >newList.size() ){
                end = newList.size();
            }
            List subList = newList.subList(start,end);
            listHasList.add(subList);
        }
        return listHasList;
    }
    public static <T> Collection<Collection<T>> switchCollectionForOracleIn(Collection<T> collection, int preSize) {
        Collection<Collection<T>> listHasList = new ArrayList();
        if (collection == null) {
Source/UBCS/ubcs-service-api/ubcs-util-api/src/main/java/com/vci/ubcs/starter/web/util/WebUtil.java
@@ -724,5 +724,18 @@
        }
        return listHasList;
    }
    /**
     * æ˜¯å¦é»˜è®¤çš„属性
     * @param fieldNames å±žæ€§çš„名字
     * @return true为默认
     */
    public static boolean isDefaultField(String fieldNames){
        if(VciQueryWrapperForDO.BASIC_FIELD_MAP.containsKey(fieldNames) || VciQueryWrapperForDO.LIFECYCLE_MANAGE_FIELD_MAP.containsKey(fieldNames)
            || VciQueryWrapperForDO.REVISION_MANAGE_FIELD_MAP.containsKey(fieldNames) ) {
            return true;
        }
        return false;
    }
}
Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/mapper/CommonsMapper.java
@@ -20,6 +20,9 @@
    List<String> selectById(@Param("inSql") String inSql);
    int  queryCountBySql(@Param("inSql") String inSql);
    List<Map> selectBySql(@Param("inSql") String inSql);
    List<Map<String,String>> queryByOnlySqlForMap(@Param("inSql") String inSql);
Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmIOServiceImpl.java
@@ -1,11 +1,17 @@
package com.vci.ubcs.code.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.common.utils.StringUtils;
import com.vci.ubcs.code.bo.AttributeValue;
import com.vci.ubcs.code.bo.CodeClassifyFullInfoBO;
import com.vci.ubcs.code.bo.CodeTemplateAttrSqlBO;
import com.vci.ubcs.code.dto.CodeOrderDTO;
import com.vci.ubcs.code.service.ICodeClassifyService;
import com.vci.ubcs.code.service.MdmEngineService;
import com.vci.ubcs.code.service.MdmIOService;
import com.vci.ubcs.code.enumpack.CodeDefaultLC;
import com.vci.ubcs.code.enumpack.CodeLevelTypeEnum;
import com.vci.ubcs.code.mapper.CommonsMapper;
import com.vci.ubcs.code.service.*;
import com.vci.ubcs.code.util.ClientBusinessObject;
import com.vci.ubcs.code.vo.CodeKeyAttrRepeatVO;
import com.vci.ubcs.code.vo.pagemodel.*;
import com.vci.ubcs.code.vo.webserviceModel.attrmap.DataObjectVO;
import com.vci.ubcs.code.vo.webserviceModel.attrmap.RowDatas;
@@ -17,14 +23,19 @@
import com.vci.ubcs.starter.poi.bo.SheetRowData;
import com.vci.ubcs.starter.poi.bo.WriteExcelOption;
import com.vci.ubcs.starter.poi.util.ExcelUtil;
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.web.enumpck.BooleanEnum;
import com.vci.ubcs.starter.web.enumpck.VciFieldTypeEnum;
import com.vci.ubcs.starter.web.pagemodel.DataGrid;
import com.vci.ubcs.starter.web.pagemodel.KeyValue;
import com.vci.ubcs.starter.web.util.LangBaseUtil;
import com.vci.ubcs.starter.web.util.VciBaseUtil;
import com.vci.ubcs.starter.web.util.VciDateUtil;
import com.vci.ubcs.starter.web.pagemodel.PageHelper;
import com.vci.ubcs.starter.web.pagemodel.UIFormReferVO;
import com.vci.ubcs.starter.web.toolmodel.DateConverter;
import com.vci.ubcs.starter.web.util.*;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
@@ -33,6 +44,9 @@
import org.apache.poi.ss.usermodel.Workbook;
import org.springblade.core.redis.cache.BladeRedis;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
@@ -40,23 +54,31 @@
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.stream.Collectors;
import static com.alibaba.druid.util.FnvHash.Constants.LIMIT;
import static com.vci.ubcs.code.constant.MdmEngineConstant.*;
import static com.vci.ubcs.starter.poi.util.ExcelUtil.KEY_ATTR_CHAR;
import static com.vci.ubcs.starter.poi.util.ExcelUtil.REQUIRED_CHAR;
import static com.vci.ubcs.starter.poi.util.ExcelUtil.*;
@AllArgsConstructor
@Service
@Slf4j
public class MdmIOServiceImpl implements MdmIOService {
    @Value("${batchadd.redis.time:6000000}")
    public int BATCHADD_REDIS_TIME;
    /**
     * ä¸»é¢˜åº“分类的服务
     */
    @Resource
    private ICodeClassifyService classifyService;
    /**
     * é€šç”¨æŸ¥è¯¢
     */
    @Resource
    CommonsMapper commonsMapper;
    /**
     * æ¨¡æ¿çš„æœåŠ¡
@@ -69,9 +91,26 @@
     */
    @Resource
    private MdmEngineService engineService;
    /***
     * resdis缓存服务
     */
    private final BladeRedis bladeRedis;
    /**
     * ç”Ÿæˆç¼–码的服务
     */
    @Resource
    private MdmProductCodeService productCodeService;
    /**
     * å…³é”®å±žæ€§çš„配置
     */
    @Autowired
    private ICodeKeyAttrRepeatService keyRuleService;
    /**
     * å…¬å¼çš„æœåŠ¡
     */
    @Autowired
    private FormulaServiceImpl formulaService;
    /**
     * ç”Ÿæˆå¯¼å…¥çš„æ–‡ä»¶
     *
@@ -350,125 +389,140 @@
     */
    private String batchImportCodes(CodeOrderDTO orderDTO,CodeClassifyTemplateVO templateVO,SheetDataSet dataSet,Map<String,String> errorMap,boolean isEnumType){
        List<String> codeList=new ArrayList<>();
//        CodeClassifyFullInfoBO classifyFullInfo = classifyService.getClassifyFullInfo(orderDTO.getCodeClassifyOid());
        CodeClassifyFullInfoBO classifyFullInfo = classifyService.getClassifyFullInfo(orderDTO.getCodeClassifyOid());
        //规则的主键需要去获取
//        CodeRuleVO ruleVO = engineService.getCodeRuleByClassifyFullInfo(classifyFullInfo);
//        //1.判断规则中除了流水码段,是否有其他码段
//        engineService.checkSecValueOnOrder(ruleVO,orderDTO);
//        List<SheetRowData> rowDataList = dataSet.getRowData();
//
//        //除去默认的属性.还有只有表单显示的字段才导入
//        List<CodeClassifyTemplateAttrVO> attrVOS = templateVO.getAttributes().stream().filter(s ->
//            !DEFAULT_ATTR_LIST.contains(s.getId()) && VciBaseUtil.getBoolean(s.getFormdisplayflag())
//        ).collect(Collectors.toList());
//        Map<Integer/**列号**/,String/**字段的名称**/> fieldIndexMap = new HashMap<>();
//        List<String> titleRowData = dataSet.getColName();
//        Map<String/**中文名称**/, String/**英文名称**/> attrNameIdMap = attrVOS.stream().collect(Collectors.toMap(s -> s.getName(), t -> t.getId().toLowerCase(Locale.ROOT),(o1, o2)->o2));
//        getFieldIndexMap(titleRowData,attrNameIdMap,fieldIndexMap);
//
//        //需要判断是否所有的属性都在模板上了
//        List<CodeClassifyTemplateAttrVO> unExistAttrVOs = attrVOS.stream().filter(s -> !fieldIndexMap.containsValue(s.getId().toLowerCase(Locale.ROOT))
//            && StringUtils.isBlank(s.getComponentrule()) && StringUtils.isBlank(s.getClassifyinvokeattr())//组合规则和分类注入确实没给用户导出去
//        ).collect(Collectors.toList());
//        if(!CollectionUtils.isEmpty(unExistAttrVOs)){
//            throw new VciBaseException("【" + unExistAttrVOs.stream().map(CodeClassifyTemplateAttrVO::getName) + "】这些属性在列表中没有找到");
//        }
//        List<ClientBusinessObject> cboList = new ArrayList<>();
//        String fullPath = getFullPath(classifyFullInfo);
//        excelToCbo(classifyFullInfo,fieldIndexMap,rowDataList,templateVO,cboList,fullPath,true);
//
//        //都转换完了。需要批量检查
//        //如果出错了,我们依然执行有效的数据,无效的数据写回到excel中
//        //2.判断必输项。。需要全部的属性,如果是必输,但是表单里面不显示的,只能是分类注入或者组合规则
//        batchCheckRequiredAttrOnOrder(templateVO,cboList,errorMap);
//        //3.判断关键属性
//        CodeImportResultVO keyResultVO = batchCheckKeyAttrOnOrder(classifyFullInfo, templateVO, cboList);
//        Set<String> selfRepeatRowIndexList = keyResultVO.getSelfRepeatRowIndexList();
//        Set<String> keyAttrRepeatRowIndexList = keyResultVO.getKeyAttrRepeatRowIndexList();
//        if(!CollectionUtils.isEmpty(selfRepeatRowIndexList)){
//            selfRepeatRowIndexList.stream().forEach(rowIndex->{
//                errorMap.put(rowIndex,errorMap.getOrDefault(rowIndex,"") + ";在当前处理的数据文件中关键属性重复" );
//            });
//        }
//        if(!CollectionUtils.isEmpty(keyAttrRepeatRowIndexList)){
//            keyAttrRepeatRowIndexList.stream().forEach(rowIndex->{
//                errorMap.put(rowIndex,errorMap.getOrDefault(rowIndex,"") + ";关键属性与系统中的重复" );
//            });
//        }
//        //分类注入
//        batchSwitchClassifyAttrOnOrder(attrVOS,cboList,classifyFullInfo,false);
//        //boolean
//        reSwitchBooleanAttrOnOrder(attrVOS,cboList);
//        //4.校验规则
//        batchCheckVerifyOnOrder(attrVOS, cboList,errorMap);
//        if(isEnumType) {//是否需要校验枚举/参照
//            //5.校验枚举是否正确
//            batchSwitchEnumAttrOnOrder(attrVOS, cboList, errorMap);
//            //7.处理参照的情况
//            batchSwitchReferAttrOnOrder(attrVOS,cboList,errorMap);
//        }
//        //6.时间格式的验证
//        //6.时间的,必须统一为yyyy-MM-dd HH:mm:ss
//        batchSwitchDateAttrOnOrder(attrVOS,cboList,errorMap);
//        //最后弄组合规则
//        batchSwitchComponentAttrOnOrder(attrVOS,cboList);
//        String uuid=redisService.getUUIDEveryDay();
//        Map<String, ClientBusinessObject> rowIndexCboMap = cboList.stream().filter(cbo -> cbo != null).collect(Collectors.toList()).stream().collect(Collectors.toMap(s -> s.getAttributeValue((IMPORT_ROW_INDEX)), t -> t));
//
//        if(errorMap.size()>0) {
//            createRedisDatas(uuid + "-error",templateVO, rowIndexCboMap, dataSet, fieldIndexMap, errorMap,false);
//        }
//        boolean isCreateUUid=false;
//        List<ClientBusinessObject> needSaveCboList = cboList.stream().filter(cbo -> {
//            String rowIndex = cbo.getAttributeValue(IMPORT_ROW_INDEX);
//            return !errorMap.containsKey(rowIndex);
//        }).collect(Collectors.toList());
//        //相似校验
//        Map<String,String>resembleMap=new HashMap<>();
//        List<DataResembleVO> dataResembleVOS=new ArrayList<>();
//        String btmtypeid= classifyFullInfo.getTopClassifyVO().getBtmtypeid();
//        bathcResembleQuery(orderDTO.getCodeClassifyOid(),templateVO,needSaveCboList,resembleMap,btmtypeid,dataResembleVOS);
//        if(resembleMap.size()>0) {
//            isCreateUUid=true;
//            if(!CollectionUtils.isEmpty(dataResembleVOS)) {
//                redisService.setCacheList(uuid + "-resemble-data", dataResembleVOS);
//                createRedisDatas(uuid + "-resemble",templateVO, rowIndexCboMap, dataSet, fieldIndexMap, resembleMap, false);
//            }
//        }
//        //排除错误的,剩下正确的
//        Map<String,String> newErrorMap=new HashMap<>();
//        newErrorMap.putAll(resembleMap);
//        newErrorMap.putAll(errorMap);
//        needSaveCboList = cboList.stream().filter(cbo -> {
//            String rowIndex = cbo.getAttributeValue(IMPORT_ROW_INDEX);
//            return !newErrorMap.containsKey(rowIndex);
//        }).collect(Collectors.toList());
//        if((errorMap.size()>0&&needSaveCboList.size()>0)||resembleMap.size()>0){
//            isCreateUUid=true;
//        }
//        createRedisByCodeClassify(uuid + "-class",templateVO,dataSet,fieldIndexMap,false);
//        if(newErrorMap.size()>0) {
//            createRedisDatas(uuid + "-ok",templateVO, rowIndexCboMap, dataSet, fieldIndexMap, newErrorMap,true);
//        }else {
//            uuid="";
//            //要把以上的错误的都抛出后,再继续处理时间和组合规则
//            needSaveCboList = cboList.stream().filter(cbo -> {
//                String rowIndex = cbo.getAttributeValue(IMPORT_ROW_INDEX);
//                return !newErrorMap.containsKey(rowIndex);
//            }).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(needSaveCboList)) {
//                //9.我们处理业务数据
//                //生成编码的内容
//                codeList = productCodeService.productCodeAndSaveData(classifyFullInfo, templateVO, ruleVO, orderDTO.getSecDTOList(), needSaveCboList);
//                //如果是编码生成失败,则直接就失败了,其他的判断出来有错误的我们都统一返回到excel里面
//                engineService.batchSaveSelectChar(templateVO, needSaveCboList);
//            }
//        }
//        if(!isCreateUUid){
//            return uuid="";
//        }
//        return uuid;
        return null;
        CodeRuleVO ruleVO = engineService.getCodeRuleByClassifyFullInfo(classifyFullInfo);
        //1.判断规则中除了流水码段,是否有其他码段
        engineService.checkSecValueOnOrder(ruleVO,orderDTO);
        List<SheetRowData> rowDataList = dataSet.getRowData();
        //除去默认的属性.还有只有表单显示的字段才导入
        List<CodeClassifyTemplateAttrVO> attrVOS = templateVO.getAttributes().stream().filter(s ->
            !DEFAULT_ATTR_LIST.contains(s.getId()) && VciBaseUtil.getBoolean(s.getFormDisplayFlag())
        ).collect(Collectors.toList());
        Map<Integer/**列号**/,String/**字段的名称**/> fieldIndexMap = new HashMap<>();
        List<String> titleRowData = dataSet.getColName();
        Map<String/**中文名称**/, String/**英文名称**/> attrNameIdMap = attrVOS.stream().collect(Collectors.toMap(s -> s.getName(), t -> t.getId().toLowerCase(Locale.ROOT),(o1, o2)->o2));
        getFieldIndexMap(titleRowData,attrNameIdMap,fieldIndexMap);
        //需要判断是否所有的属性都在模板上了
        List<CodeClassifyTemplateAttrVO> unExistAttrVOs = attrVOS.stream().filter(s -> !fieldIndexMap.containsValue(s.getId().toLowerCase(Locale.ROOT))
            && StringUtils.isBlank(s.getComponentRule()) && StringUtils.isBlank(s.getClassifyInvokeAttr())//组合规则和分类注入确实没给用户导出去
        ).collect(Collectors.toList());
        if(!CollectionUtils.isEmpty(unExistAttrVOs)){
            throw new VciBaseException("【" + unExistAttrVOs.stream().map(CodeClassifyTemplateAttrVO::getName) + "】这些属性在列表中没有找到");
        }
        List<ClientBusinessObject> cboList = new ArrayList<>();
        String fullPath = getFullPath(classifyFullInfo);
        excelToCbo(classifyFullInfo,fieldIndexMap,rowDataList,templateVO,cboList,fullPath,true);
        //都转换完了。需要批量检查
        //如果出错了,我们依然执行有效的数据,无效的数据写回到excel中
        //2.判断必输项。。需要全部的属性,如果是必输,但是表单里面不显示的,只能是分类注入或者组合规则
        batchCheckRequiredAttrOnOrder(templateVO,cboList,errorMap);
        //3.判断关键属性
        CodeImportResultVO keyResultVO = batchCheckKeyAttrOnOrder(classifyFullInfo, templateVO, cboList);
        Set<String> selfRepeatRowIndexList = keyResultVO.getSelfRepeatRowIndexList();
        Set<String> keyAttrRepeatRowIndexList = keyResultVO.getKeyAttrRepeatRowIndexList();
        if(!CollectionUtils.isEmpty(selfRepeatRowIndexList)){
            selfRepeatRowIndexList.stream().forEach(rowIndex->{
                errorMap.put(rowIndex,errorMap.getOrDefault(rowIndex,"") + ";在当前处理的数据文件中关键属性重复" );
            });
        }
        if(!CollectionUtils.isEmpty(keyAttrRepeatRowIndexList)){
            keyAttrRepeatRowIndexList.stream().forEach(rowIndex->{
                errorMap.put(rowIndex,errorMap.getOrDefault(rowIndex,"") + ";关键属性与系统中的重复" );
            });
        }
        //分类注入
        batchSwitchClassifyAttrOnOrder(attrVOS,cboList,classifyFullInfo,false);
        //boolean
        reSwitchBooleanAttrOnOrder(attrVOS,cboList);
        //4.校验规则
        batchCheckVerifyOnOrder(attrVOS, cboList,errorMap);
        if(isEnumType) {//是否需要校验枚举/参照
            //5.校验枚举是否正确
            batchSwitchEnumAttrOnOrder(attrVOS, cboList, errorMap);
            //7.处理参照的情况
            batchSwitchReferAttrOnOrder(attrVOS,cboList,errorMap);
        }
        //6.时间格式的验证
        //6.时间的,必须统一为yyyy-MM-dd HH:mm:ss
        batchSwitchDateAttrOnOrder(attrVOS,cboList,errorMap);
        //最后弄组合规则
        batchSwitchComponentAttrOnOrder(attrVOS,cboList);
        String uuid=VciBaseUtil.getPk();
        Map<String, ClientBusinessObject> rowIndexCboMap = cboList.stream().filter(cbo -> cbo != null).collect(Collectors.toList()).stream().collect(Collectors.toMap(s -> s.getAttributeValue((IMPORT_ROW_INDEX)), t -> t));
        if(errorMap.size()>0) {
            createRedisDatas(uuid + "-error",templateVO, rowIndexCboMap, dataSet, fieldIndexMap, errorMap,false);
        }
        boolean isCreateUUid=false;
        List<ClientBusinessObject> needSaveCboList = cboList.stream().filter(cbo -> {
            String rowIndex = cbo.getAttributeValue(IMPORT_ROW_INDEX);
            return !errorMap.containsKey(rowIndex);
        }).collect(Collectors.toList());
        //相似校验
        Map<String,String>resembleMap=new HashMap<>();
        List<DataResembleVO> dataResembleVOS=new ArrayList<>();
        String btmtypeid= classifyFullInfo.getTopClassifyVO().getBtmtypeid();
        bathcResembleQuery(orderDTO.getCodeClassifyOid(),templateVO,needSaveCboList,resembleMap,btmtypeid,dataResembleVOS);
        if(resembleMap.size()>0) {
            isCreateUUid=true;
            if(!CollectionUtils.isEmpty(dataResembleVOS)) {
                bladeRedis.set(uuid + "-resemble-data", dataResembleVOS);
                createRedisDatas(uuid + "-resemble",templateVO, rowIndexCboMap, dataSet, fieldIndexMap, resembleMap, false);
            }
        }
        //排除错误的,剩下正确的
        Map<String,String> newErrorMap=new HashMap<>();
        newErrorMap.putAll(resembleMap);
        newErrorMap.putAll(errorMap);
        needSaveCboList = cboList.stream().filter(cbo -> {
            String rowIndex = cbo.getAttributeValue(IMPORT_ROW_INDEX);
            return !newErrorMap.containsKey(rowIndex);
        }).collect(Collectors.toList());
        if((errorMap.size()>0&&needSaveCboList.size()>0)||resembleMap.size()>0){
            isCreateUUid=true;
        }
        createRedisByCodeClassify(uuid + "-class",templateVO,dataSet,fieldIndexMap,false);
        if(newErrorMap.size()>0) {
            createRedisDatas(uuid + "-ok",templateVO, rowIndexCboMap, dataSet, fieldIndexMap, newErrorMap,true);
        }else {
            uuid="";
            //要把以上的错误的都抛出后,再继续处理时间和组合规则
            /*dataCBOList = cboList.stream().filter(cbo -> {
                String rowIndex = cbo.getAttributeValue(IMPORT_ROW_INDEX);
                return !newErrorMap.containsKey(rowIndex);
            }).collect(Collectors.toList());
*/            List<String> dataCBOIdList=new ArrayList<>();
            List<BaseModel> dataCBOList=new ArrayList<>();
            cboList.stream().forEach(clientBusinessObject -> {
                BaseModel baseModel=new BaseModel();
                BeanUtil.convert(clientBusinessObject,baseModel);
                baseModel.setData(VciBaseUtil.objectToMapString(clientBusinessObject));
                dataCBOList.add(baseModel);
                dataCBOIdList.add(baseModel.getOid());
            });
            if (!CollectionUtils.isEmpty(needSaveCboList)) {
                //9.我们处理业务数据
                //生成编码的内容
                try {
                    codeList = productCodeService.productCodeAndSaveData(classifyFullInfo,templateVO,ruleVO, orderDTO.getSecDTOList(),dataCBOList);
                    //如果是编码生成失败,则直接就失败了,其他的判断出来有错误的我们都统一返回到excel里面
                    engineService.batchSaveSelectChar(templateVO, dataCBOIdList);
                } catch (Exception e) {
                    e.printStackTrace();
                    log.error("批了申请时失败");
                }
            }
        }
        if(!isCreateUUid){
            return uuid="";
        }
        return uuid;
    }
    @Override
@@ -629,6 +683,587 @@
    }
    /**
     * excel转换为cbo的对象
     * @param classifyFullInfo åˆ†ç±»çš„全部信息
     * @param fieldIndexMap å­—段的位置
     * @param rowDataList excel里的行数据
     * @param templateVO æ¨¡æ¿çš„æ˜¾ç¤ºå¯¹è±¡
     * @param cboList æ•°æ®çš„列表
     * @param fullPath å…¨è·¯å¾„
     * @param newCode æ˜¯å¦ä¸ºæ‰¹é‡ç”³è¯·
     */
    private void excelToCbo(CodeClassifyFullInfoBO classifyFullInfo,Map<Integer,String> fieldIndexMap,List<SheetRowData> rowDataList,
                            CodeClassifyTemplateVO templateVO,List<ClientBusinessObject> cboList,
                            String fullPath,boolean newCode){
        rowDataList.stream().forEach(rowData -> {
            ClientBusinessObject cbo=new ClientBusinessObject();
             DefaultAttrAssimtUtil.addDefaultAttrAssimt(cbo, classifyFullInfo.getTopClassifyVO().getBtmtypeid());
            rowData.getData().forEach((index,value)->{
                String field = fieldIndexMap.get(index);
                if (StringUtils.isBlank(field)) {
                    throw new VciBaseException("第" + (index + 1) + "列的标题在系统中不存在");
                }
                try {
                    cbo.setAttributeValueWithNoCheck(field, value);
                    if (WebUtil.isDefaultField(field)) {
                        WebUtil.setValueToField(field, cbo, value);
                    }
                } catch (VciBaseException e) {
                    log.error("设置属性的值错误", e);
                }
            });
            try {
                cbo.setAttributeValue(CODE_TEMPLATE_OID_FIELD,templateVO.getOid());
                cbo.setAttributeValue(IMPORT_ROW_INDEX,rowData.getRowIndex());
                if(newCode){
                    cbo.setAttributeValue(CODE_CLASSIFY_OID_FIELD,classifyFullInfo.getCurrentClassifyVO().getOid());
                    cbo.setAttributeValue(CODE_FULL_PATH_FILED,fullPath);
                    //cbo.setLcStatus(CodeDefaultLC.EDITING.getValue());
                    int secret = VciBaseUtil.getInt(cbo.getAttributeValue(SECRET_FIELD));
                    /*if(secret == 0 || !secretService.checkDataSecret(secret) ){
                        Integer userSecret = VciBaseUtil.getCurrentUserSecret();
                        cbo.setAttributeValue(SECRET_FIELD,String.valueOf((userSecret==null || userSecret ==0)? UserSecretEnum.NONE.getValue():userSecret));
                    }*/
                }else{
                    //此时还没有转换路径
                    //cbo.setAttributeValue(CODE_FULL_PATH_FILED, childOidPathMap.getOrDefault(rowData.getData().getOrDefault(CODE_CLASSIFY_OID_FIELD,""),fullPath));
                    cbo.setLcStatus(CodeDefaultLC.RELEASED.getValue());
                }
            }catch (Throwable e){
                log.error("设置默认的属性的值错误",e);
            }
            cboList.add(cbo);
        });
    }
    /**
     * æ£€æŸ¥æ ¡éªŒè§„则没有通过的内容
     * @param attrVOS éœ€è¦æ ¡éªŒçš„属性
     * @param dataList æ•°æ®çš„列表
     * @param errorMap é”™è¯¯çš„信息映射
     * @return æ ¡éªŒä¸é€šè¿‡çš„行数
     */
    private void batchCheckVerifyOnOrder(Collection<CodeClassifyTemplateAttrVO> attrVOS, List<ClientBusinessObject> dataList,Map<String,String> errorMap) {
        Map<String, CodeClassifyTemplateAttrVO> verifyAttrVOMap = attrVOS.stream().filter(s -> StringUtils.isNotBlank(s.getVerifyRule()) && StringUtils.isBlank(s.getComponentRule())
            &&StringUtils.isBlank(s.getClassifyInvokeAttr())
        ).collect(Collectors.toMap(s -> s.getId().toLowerCase(Locale.ROOT), t -> t));
        if(!CollectionUtils.isEmpty(verifyAttrVOMap)){
            Map<String/**行号**/,List<String>/**校验不通过的属性**/> unPassCheckMap = new HashMap<>();
            verifyAttrVOMap.forEach((attrId,attrVO)->{
                dataList.stream().forEach(cbo -> {
                    String value = cbo.getAttributeValue(attrId);
                    if(StringUtils.isNotBlank(value) && !value.matches(attrVO.getVerifyRule())){
                        String rowIndex = cbo.getAttributeValue(IMPORT_ROW_INDEX);
                        List<String> unPassAttrs = unPassCheckMap.getOrDefault(rowIndex, new ArrayList<>());
                        unPassAttrs.add(attrVO.getName());
                        unPassCheckMap.put(rowIndex,unPassAttrs);
                    }
                });
            });
            if(!CollectionUtils.isEmpty(unPassCheckMap)){
                unPassCheckMap.forEach((rowIndex,unPassAttrs)->{
                    errorMap.put(rowIndex,";属性[" + unPassAttrs.stream().collect(Collectors.joining(",")) + "]内容不符合校验规则的要求");
                });
            }
        }
    }
    /**
     * æ‰¹é‡è½¬æ¢æ—¶é—´éƒ½ä¸ºæŒ‡å®šçš„æ ¼å¼
     * @param attrVOS æ¨¡æ¿å±žæ€§
     * @param cboList æ•°æ®çš„列表
     * @param errorMap é”™è¯¯çš„信息
     */
    private void batchSwitchDateAttrOnOrder(Collection<CodeClassifyTemplateAttrVO> attrVOS,List<ClientBusinessObject> cboList,Map<String,String> errorMap){
        Map<String, CodeClassifyTemplateAttrVO> dateAttrVOMap =attrVOS.stream().filter(s ->
            StringUtils.isNotBlank(s.getCodeDateFormat()) && VciBaseUtil.getBoolean(s.getCodeDateFormat()) && StringUtils.isBlank(s.getComponentRule())
                && StringUtils.isBlank(s.getClassifyInvokeAttr())
        ).collect(Collectors.toMap(s -> s.getId().toLowerCase(Locale.ROOT), t -> t));
        if(!CollectionUtils.isEmpty(dateAttrVOMap)) {
            dateAttrVOMap.forEach((attrId, attrVO) -> {
                cboList.stream().forEach(cbo -> {
                    String value = cbo.getAttributeValue(attrId);
                    if (value == null) {
                        value = "";
                    }
                    if (StringUtils.isNotBlank(value)) {
                        boolean formated = false;
                        if(StringUtils.isNotBlank(attrVO.getCodeDateFormat())){
                            try {
                                Date date = VciDateUtil.str2Date(value, attrVO.getCodeDateFormat());
                                if(date!=null){
                                    cbo.setAttributeValue(attrId,value);
                                    formated = true;
                                }
                            } catch (Exception e) {
                                //说明不是这个格式
                            }
                        }
                        if(!formated) {
                            try {
                                DateConverter dateConverter = new DateConverter();
                                dateConverter.setAsText(value);
                                value = VciDateUtil.date2Str(dateConverter.getValue(), VciDateUtil.DateTimeMillFormat);
                                cbo.setAttributeValue(attrId,value);
                            }catch (Throwable e){
                                //转换不了
                                String rowIndex = cbo.getAttributeValue(IMPORT_ROW_INDEX);
                                errorMap.put(rowIndex,errorMap.getOrDefault(rowIndex,"") + ";属性[" + attrVO.getName() + "]时间格式不正确" );
                            }
                        }
                    }
                });
            });
        }
    }
    /**
     * è½¬ç§»boolean型的属性
     * @param attrVOS å±žæ€§çš„对象
     * @param dataList æ•°æ®
     */
    private void reSwitchBooleanAttrOnOrder(Collection<CodeClassifyTemplateAttrVO> attrVOS,List<ClientBusinessObject> dataList){
        Map<String, CodeClassifyTemplateAttrVO> booleanAttrMap = attrVOS.stream().filter(
            s -> VciFieldTypeEnum.VTBoolean.name().equalsIgnoreCase(s.getAttributeDataType())
        ).collect(Collectors.toMap(s -> s.getId().toLowerCase(Locale.ROOT), t -> t));
        if (!CollectionUtils.isEmpty(booleanAttrMap)) {
            booleanAttrMap.forEach((attrId, attrVO) -> {
                dataList.stream().forEach(cbo -> {
                    String text = cbo.getAttributeValue(attrId);
                    try {
                        if (BooleanEnum.TRUE.getValue().equalsIgnoreCase(text) || "是".equalsIgnoreCase(text)) {
                            cbo.setAttributeValue(attrId, BooleanEnum.TRUE.getValue());
                        } else {
                            cbo.setAttributeValue(attrId, BooleanEnum.FASLE.getValue());
                        }
                    }catch (Throwable e){
                    }
                });
            });
        }
    }
    /**
     * å¤„理组合规则
     * @param attrVOS æ¨¡æ¿å±žæ€§
     * @param dataList excel的数据内容
     */
    private void batchSwitchComponentAttrOnOrder(Collection<CodeClassifyTemplateAttrVO> attrVOS,List<ClientBusinessObject> dataList) {
        Map<String, CodeClassifyTemplateAttrVO> dateAttrVOMap = attrVOS.stream().filter(s -> StringUtils.isNotBlank(s.getComponentRule())).collect(Collectors.toMap(s -> s.getId().toLowerCase(Locale.ROOT), t -> t));
        if(!CollectionUtils.isEmpty(dateAttrVOMap)) {
            dateAttrVOMap.forEach((attrId, attrVO) -> {
                dataList.stream().forEach(cbo -> {
                    //从excel上把属性转换为map
                    Map<String,String> thisRowDataMap = new HashMap<>();
                    copyValueToMapFromCbos(cbo,thisRowDataMap);
                    //组合内容
                    String value = formulaService.getValueByFormula(thisRowDataMap,attrVO.getComponentRule());
                    if(value == null){
                        value = "";
                    }
                    try {
                        cbo.setAttributeValue(attrId, value);
                    }catch (Throwable e){
                        log.error("设置属性的错误",e);
                    }
                });
            });
        }
    }
    /**
     * è½¬æ¢å‚照的值
     * @param attrVOS å±žæ€§çš„æ˜¾ç¤ºå¯¹è±¡
     * @param dataList æ•°æ®åˆ—表
     * @param errorMap é”™è¯¯çš„信息
     */
    private void batchSwitchReferAttrOnOrder(Collection<CodeClassifyTemplateAttrVO> attrVOS,List<ClientBusinessObject> dataList,Map<String,String> errorMap){
        Map<String, CodeClassifyTemplateAttrVO> referAttrVOMap = attrVOS.stream().filter(
            s -> (StringUtils.isNotBlank(s.getReferBtmId()) || StringUtils.isNotBlank(s.getReferConfig()))
        ).collect(Collectors.toMap(s -> s.getId().toLowerCase(Locale.ROOT), t -> t));
        if(!CollectionUtils.isEmpty(referAttrVOMap)){
            Map<String/**表格和值的属性**/,Map<String/**显示属性的值**/,List<String>/**表格里的值**/>> linkValueMap = new HashMap<>();
            referAttrVOMap.forEach((attrId,attrVO)->{
                dataList.stream().forEach(cbo -> {
                    String text = cbo.getAttributeValue(attrId);
                    if(StringUtils.isNotBlank(text)){
                        UIFormReferVO referVO = getReferVO(attrVO);
                        String valueField = getValueField(referVO);
                        String showText = getTextField(referVO);
                        String tableAndAttr = VciBaseUtil.getTableName(referVO.getReferType()) + "#" + valueField;
                        Map<String, List<String>> showTextMap = linkValueMap.getOrDefault(tableAndAttr, new HashMap<>());
                        List<String> textList = showTextMap.getOrDefault(showText, new ArrayList<>());
                        if(!textList.contains(text)) {
                            textList.add(text);
                        }
                        showTextMap.put(showText,textList);
                        linkValueMap.put(tableAndAttr,showTextMap);
                    }
                });
            });
            if(!CollectionUtils.isEmpty(linkValueMap)){
                //需要逐个表的值字段,逐个查询
                Map<String/**表格和值属性**/,Map<String/**显示属性**/, Map<String/**值**/,String/**显示的值**/>>> linkCboMap = new HashMap<>();
                linkValueMap.forEach((tableAndAttr,showValueMap)->{
                    String[] split = tableAndAttr.split("#");
                    String table = split[0];
                    String valueField = split[1].toLowerCase(Locale.ROOT);
                    Map<String,Map<String,String>> dataMap = new HashMap<>();
                    showValueMap.forEach((showText,valueList)->{
                        Map<String,String> valueOidTextMap = new HashMap<>();
                        List<List<String>> valueCollections = VciBaseUtil.switchListForOracleIn(valueList);
                        String sql = "select " + valueField + "," + showText.toLowerCase(Locale.ROOT) +" from " + table + "  where " + showText + " in (%s)";
                        valueCollections.stream().forEach(values->{
                            List<Map<String,String>> dataMapList = commonsMapper.queryByOnlySqlForMap(String.format(sql, VciBaseUtil.toInSql(values.toArray(new String[0]))));
                            List<ClientBusinessObject> cbos=    ChangeMapTOClientBusinessObjects(dataMapList);
                            if(!CollectionUtils.isEmpty(cbos)){
                                valueOidTextMap.putAll(cbos.stream().collect(Collectors.toMap(s->s.getAttributeValue(valueField),t->t.getAttributeValue(showText))));
                            }
                        });
                        dataMap.put(showText,valueOidTextMap);
                    });
                    linkCboMap.put(tableAndAttr,dataMap);
                });
                referAttrVOMap.forEach((attrId,attrVO)->{
                    dataList.stream().forEach(cbo -> {
                        String text = cbo.getAttributeValue(attrId);
                        if (StringUtils.isNotBlank(text)) {
                            UIFormReferVO referVO = getReferVO(attrVO);
                            String valueField = getValueField(referVO);
                            String showText = getTextField(referVO);
                            String tableAndAttr = VciBaseUtil.getTableName(referVO.getReferType()) + "#" + valueField;
                            if(!linkCboMap.containsKey(tableAndAttr)){
                                String rowIndex = cbo.getAttributeValue(IMPORT_ROW_INDEX);
                                errorMap.put(rowIndex,errorMap.getOrDefault(rowIndex,"") + ";参数属性[" + attrVO.getName() + "]的值在系统中不存在" );
                            }else{
                                Map<String, Map<String, String>> dataMap = linkCboMap.get(tableAndAttr);
                                if(!dataMap.containsKey(showText)){
                                    String rowIndex = cbo.getAttributeValue(IMPORT_ROW_INDEX);
                                    errorMap.put(rowIndex,errorMap.getOrDefault(rowIndex,"") + ";参数属性[" + attrVO.getName() + "]的值在系统中不存在" );
                                }else{
                                    Map<String, String> data = dataMap.get(showText);
                                    final boolean[] fined = {false};
                                    data.forEach((key,value)->{
                                        if(value.equalsIgnoreCase(text)){
                                            fined[0] = true;
                                            try {
                                                cbo.setAttributeValue(attrId, key);
                                            }catch (Throwable e){
                                            }
                                        }
                                    });
                                    if(!fined[0]){
                                        String rowIndex = cbo.getAttributeValue(IMPORT_ROW_INDEX);
                                        errorMap.put(rowIndex,errorMap.getOrDefault(rowIndex,"") + ";参数属性[" + attrVO.getName() + "]的值在系统中不存在" );
                                    }
                                }
                            }
                        }
                    });
                });
            }
        }
    }
    /**
     * ä»Žå±žæ€§ä¸ŠèŽ·å–å‚ç…§çš„å†…å®¹
     * @param attrVO å±žæ€§çš„信息
     * @return å‚照的内容
     */
    private UIFormReferVO getReferVO(CodeClassifyTemplateAttrVO attrVO){
        UIFormReferVO referVO = null;
        if(StringUtils.isNotBlank(attrVO.getReferConfig())){
            referVO = JSONObject.parseObject(attrVO.getReferConfig(),UIFormReferVO.class);
        }else{
            referVO = new UIFormReferVO();
            referVO.setReferType(attrVO.getReferBtmId());
            referVO.setValueField(VciQueryWrapperForDO.OID_FIELD);
            referVO.setTextField("name");
        }
        return referVO;
    }
    /**
     * èŽ·å–å‚ç…§ä¸­çš„å€¼çš„å­—æ®µ
     * @param referVO å‚照的对象
     * @return é»˜è®¤ä¸ºOid,有多个的时候,获取第一个
     */
    private String getValueField(UIFormReferVO referVO){
        String showText = referVO.getValueField();
        if(StringUtils.isBlank(showText)){
            return "oid";
        }
        if(showText.contains(",")){
            //防止万一有多个,看看有没有oid
            List<String> strings = VciBaseUtil.str2List(showText);
            if(strings.contains("oid")){
                showText = "oid";
            }else{
                showText = strings.get(0);
            }
        }
        return showText;
    }
    /**
     * èŽ·å–å‚ç…§ä¸­çš„æ˜¾ç¤ºå†…å®¹çš„å­—æ®µ
     * @param referVO å‚照的对象
     * @return é»˜è®¤ä¸ºname,有多个的时候,获取第一个
     */
    private String getTextField(UIFormReferVO referVO){
        String showText = referVO.getTextField();
        if(StringUtils.isBlank(showText)){
            return "name";
        }
        if(showText.contains(",")){
            //防止万一有多个,看看有没有name
            List<String> strings = VciBaseUtil.str2List(showText);
            if(strings.contains("name")){
                showText = "name";
            }else{
                showText = strings.get(0);
            }
        }
        return showText;
    }
    /**
     * å¤„理枚举的显示对象
     * @param attrVOS æ¨¡æ¿å±žæ€§
     * @param dataList excel的数据内容
     * @param errorMap é”™è¯¯ä¿¡æ¯çš„æ˜ å°„
     */
    private void batchSwitchEnumAttrOnOrder(Collection<CodeClassifyTemplateAttrVO> attrVOS,List<ClientBusinessObject> dataList,
                                            Map<String,String> errorMap ) {
        Map<String, CodeClassifyTemplateAttrVO> dateAttrVOMap = attrVOS.stream().filter(
            s -> (StringUtils.isNotBlank(s.getEnumString()) || StringUtils.isNotBlank(s.getEnumId()))
        ).collect(Collectors.toMap(s -> s.getId().toLowerCase(Locale.ROOT), t -> t));
        if (!CollectionUtils.isEmpty(dateAttrVOMap)) {
            dateAttrVOMap.forEach((attrId, attrVO) -> {
                dataList.stream().forEach(cbo -> {
                    String text = cbo.getAttributeValue(attrId);
                    if(StringUtils.isNotBlank(text)){
                        List<KeyValue> valueList = engineService.listComboboxItems(attrVO);
                        boolean fined = false;
                        for (int i = 0; i < valueList.size(); i++) {
                            KeyValue keyValue = valueList.get(i);
                            //if(keyValue.getValue().equalsIgnoreCase(text)){
                            if(keyValue.getValue().equalsIgnoreCase(text)||keyValue.getKey().equalsIgnoreCase(text)){
                                try {
                                    cbo.setAttributeValue(attrId, keyValue.getKey());
                                }catch (Throwable e){
                                    log.error("设置属性出错");
                                }
                                fined = true;
                                break;
                            }
                        }
                        if(!fined){
                            String rowIndex = cbo.getAttributeValue(IMPORT_ROW_INDEX);
                            errorMap.put(rowIndex,errorMap.getOrDefault(rowIndex,"") + ";属性[" + attrVO.getName() + "]的值不符合下拉的要求");
                        }
                    }
                });
            });
        }
    }
    /**
     * æ‰¹é‡æ ¡éªŒæ•°æ®çš„信息
     * @param templateVO æ¨¡æ¿çš„æ˜¾ç¤ºå¯¹è±¡
     * @param cboList æ•°æ®çš„内容
     */
    private void batchCheckRequiredAttrOnOrder(CodeClassifyTemplateVO templateVO,List<ClientBusinessObject> cboList,Map<String,String> errorMap){
        Map<String, CodeClassifyTemplateAttrVO> requiredAttrMap = templateVO.getAttributes().stream().filter(s ->
            VciBaseUtil.getBoolean(s.getRequireFlag()) && StringUtils.isBlank(s.getComponentRule()) && StringUtils.isBlank(s.getClassifyInvokeLevel())//不能是组合的和分类注入的
        ).collect(Collectors.toMap(s -> s.getId().toLowerCase(Locale.ROOT), t -> t));
        //与MdmEngineServiceImpl里面的checkRequiredAttrOnOrder é€»è¾‘应该相似
        if(!CollectionUtils.isEmpty(requiredAttrMap)) {
            Set<String> nullRowIndex = cboList.stream().filter(cbo -> requiredAttrMap.keySet().stream().anyMatch(attrId -> StringUtils.isBlank(cbo.getAttributeValue(attrId)))).map(cbo -> cbo.getAttributeValue(IMPORT_ROW_INDEX)).collect(Collectors.toSet());
            if(!CollectionUtils.isEmpty(nullRowIndex)){
                String checkAttr = requiredAttrMap.values().stream().map(CodeClassifyTemplateAttrVO::getName).collect(Collectors.joining(","));
                nullRowIndex.stream().forEach(rowIndex->{
                    errorMap.put(rowIndex,errorMap.getOrDefault(rowIndex,"") + ";校验规则不通过,有校验的属性为" + checkAttr);
                });
            }
        }
    }
    /**
     * å¤„理分类注入
     * @param attrVOS æ¨¡æ¿å±žæ€§
     * @param dataList excel的数据内容
     * @param classifyFullInfo åˆ†ç±»çš„全路径
     */
    private void batchSwitchClassifyAttrOnOrder(Collection<CodeClassifyTemplateAttrVO> attrVOS,List<ClientBusinessObject> dataList,
                                                CodeClassifyFullInfoBO classifyFullInfo,boolean isImPort) {
        Map<String, CodeClassifyTemplateAttrVO> dateAttrVOMap = attrVOS.stream().filter(
            s -> StringUtils.isNotBlank(s.getClassifyInvokeAttr()) && StringUtils.isNotBlank(s.getClassifyInvokeAttr())
        ).collect(Collectors.toMap(s -> s.getId().toLowerCase(Locale.ROOT), t -> t));
        Map<String,CodeClassifyFullInfoBO> classifyFullInfoMap=new HashMap<>();
        classifyFullInfoMap.put(classifyFullInfo.getCurrentClassifyVO().getOid(),classifyFullInfo);
        if (!CollectionUtils.isEmpty(dateAttrVOMap)) {
            dataList.stream().forEach(cbo -> {
                dateAttrVOMap.forEach((attrId, attrVO) -> {
                    //分类注入的编号或者名称,
                    //层级包含指定层和最小层
                    CodeClassifyVO classifyVO = null;
                    if(!CodeLevelTypeEnum.MIN.getValue().equalsIgnoreCase(attrVO.getClassifyInvokeLevel()) && !"min".equalsIgnoreCase(attrVO.getClassifyInvokeLevel())) {
                        //指定了层级的
                        //注意,因为查询上级分类出来的层级是倒序的,即顶层节点是最大的值
                        if(isImPort){
                            if(!classifyFullInfoMap.containsKey(cbo.getAttributeValue(CODE_CLASSIFY_OID_FIELD))) {
                                CodeClassifyFullInfoBO currentClassifyFullInfo = classifyService.getClassifyFullInfo(cbo.getAttributeValue(CODE_CLASSIFY_OID_FIELD));
                                classifyFullInfoMap.put(currentClassifyFullInfo.getCurrentClassifyVO().getOid(), currentClassifyFullInfo);
                            }
                        }
                        CodeClassifyFullInfoBO newClassifyFullInfo= classifyFullInfoMap.get(cbo.getAttributeValue(CODE_CLASSIFY_OID_FIELD));
                        List<CodeClassifyVO> classifyVOS = newClassifyFullInfo.getParentClassifyVOs().stream().sorted(((o1, o2) -> o2.getDataLevel().compareTo(o1.getDataLevel()))).collect(Collectors.toList());
                        int level = VciBaseUtil.getInt(attrVO.getClassifyInvokeLevel());
                        if (classifyVOS.size()>=level && level > 0 ) {
                            classifyVO = classifyVOS.get(level-1);
                        }
                    }else{
                        //当前的分类
                        classifyVO = classifyFullInfo.getCurrentClassifyVO();
                    }
                    try {
                        if (classifyVO == null) {
                            //说明层级有误
                            cbo.setAttributeValue(attrId, "分类树上没有层级[" + attrVO.getClassifyInvokeLevel() + "]");
                        } else {
                            Map<String, String> classifyDataMap = VciBaseUtil.objectToMapString(classifyVO);
                            String value = classifyDataMap.getOrDefault(attrVO.getClassifyInvokeAttr(), "");
                            cbo.setAttributeValue(attrId, value);
                        }
                    } catch (Throwable e) {
                        log.error("设置属性错误", e);
                    }
                });
            });
        }
    }
    /**
     * æ ¡éªŒå…³é”®å±žæ€§
     * @param classifyFullInfo åˆ†ç±»çš„全部信息
     * @param templateVO æ¨¡æ¿çš„内容,必须包含模板属性
     * @param cboList æ‰¹é‡çš„æ•°æ®
     */
    private CodeImportResultVO batchCheckKeyAttrOnOrder(CodeClassifyFullInfoBO classifyFullInfo, CodeClassifyTemplateVO templateVO,
                                                        List<ClientBusinessObject> cboList) {
        //与MdmEngineServiceImpl里的checkKeyAttrOnOrder相似
        //先获取关键属性的规则,也利用继承的方式
        CodeKeyAttrRepeatVO keyRuleVO = keyRuleService.getRuleByClassifyFullInfo(classifyFullInfo);
        //注意的是keyRuleVO可能为空,表示不使用规则控制
        //获取所有的关键属性
        Map<String/**属性的编号**/, CodeClassifyTemplateAttrVO> ketAttrMap = templateVO.getAttributes().stream().filter(s -> VciBaseUtil.getBoolean(s.getKeyAttrFlag())).collect(Collectors.toMap(s -> s.getId().toLowerCase(Locale.ROOT), t -> t));
        boolean trimAll =keyRuleVO ==null?false: VciBaseUtil.getBoolean(keyRuleVO.getIgnoreallspaceflag());
        //全部去空的优先级大于去空
        boolean trim =keyRuleVO ==null?false:  VciBaseUtil.getBoolean(keyRuleVO.getIgnorespaceflag());
        boolean ignoreCase = keyRuleVO ==null?false: VciBaseUtil.getBoolean(keyRuleVO.getIgnorecaseflag());
        boolean ignoreWidth = keyRuleVO ==null?false: VciBaseUtil.getBoolean(keyRuleVO.getIgnorewidthflag());
        //1. æˆ‘们需要先判断excel导入的内容是否正确
        CodeImportResultVO resultVO = new CodeImportResultVO();
        resultVO.setKeyAttrRuleInfo(String.format(keyRuleVO ==null?"":"查询规则:去除空格--{0},忽略大小写--{1},忽略全半角--{2},忽略全部空格--{3}",
            new String[]{trim?"是":"否",ignoreCase?"是":"否",ignoreWidth?"是":"否",trimAll?"是":"否"}));
        resultVO.setSelfRepeatRowIndexList(getSelfRepeatRowIndex(ketAttrMap,cboList,keyRuleVO));
        if(!CollectionUtils.isEmpty(resultVO.getSelfRepeatRowIndexList())){
            //我们移除本身重复的数据
            cboList = cboList.stream().filter(s->!resultVO.getSelfRepeatRowIndexList().contains(s.getAttributeValue(IMPORT_ROW_INDEX))).collect(Collectors.toList());
        }
        //2.判断关键属性在系统里是否重复
        //因为数据量很大,所以得想办法并行
        //SessionInfo sessionInfo = VciBaseUtil.getCurrentUserSessionInfo();
        Map<String,List<ClientBusinessObject>> indexTODataMap=new HashMap<>();
        List<ClientBusinessObject> repeatDataMap = cboList.parallelStream().filter(cbo -> {
            //每行都得查询.如果其中出现了错误,我们就直接抛出异常,其余的显示
            //VciBaseUtil.setCurrentUserSessionInfo(sessionInfo);
            Map<String, String> conditionMap = new HashMap<>();
            ketAttrMap.forEach((attrId, attrVO) -> {
                String value =cbo.getAttributeValue(attrId.toLowerCase(Locale.ROOT));
                if (value == null) {
                    value = "";
                }
                value= value.replace(REQUIRED_CHAR,SPECIAL_CHAR);
                engineService.wrapperKeyAttrConditionMap(value, keyRuleVO, attrId, trim, ignoreCase, ignoreWidth, trimAll, conditionMap);
            });
            if (!CollectionUtils.isEmpty(ketAttrMap)) {
                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());
                    List<ClientBusinessObject> newCboList=    ChangeMapTOClientBusinessObjects(newDataList);
                    indexTODataMap.put(cbo.getAttributeValue(IMPORT_ROW_INDEX),newCboList);
                }
                return isKeyCheck;
            }else{
                return false;
            }
        }).collect(Collectors.toList());
        if(!CollectionUtils.isEmpty(repeatDataMap)){
            resultVO.setKeyAttrRepeatRowIndexList(repeatDataMap.stream().map(s->s.getAttributeValue(IMPORT_ROW_INDEX)).collect(Collectors.toSet()));
        }
        //resultVO.setIndexTODataMap(indexTODataMap);
        //resultVO.setSuccess(true);
        return resultVO;
    }
    /**
     * èŽ·å–å¯¼å…¥çš„å†…å®¹ä¸­å…³é”®å±žæ€§é‡å¤çš„è¡Œå·
     * @param ketAttrMap å…³é”®å±žæ€§çš„æ˜ å°„
     * @param dataList å¯¼å…¥çš„æ•°æ®
     * @param keyRuleVO å…³é”®å±žæ€§æŽ§åˆ¶è§„则
     * @return é‡å¤çš„行号
     */
    private Set<String> getSelfRepeatRowIndex(Map<String/**属性的编号**/, CodeClassifyTemplateAttrVO> ketAttrMap,
                                              List<ClientBusinessObject> dataList,CodeKeyAttrRepeatVO keyRuleVO){
        Set<String> selfRepeatRowIndexList = new CopyOnWriteArraySet<>();
        boolean trimAll =keyRuleVO ==null?false: VciBaseUtil.getBoolean(keyRuleVO.getIgnoreallspaceflag());
        //全部去空的优先级大于去空
        boolean trim =keyRuleVO ==null?false:  VciBaseUtil.getBoolean(keyRuleVO.getIgnorespaceflag());
        boolean ignoreCase = keyRuleVO ==null?false: VciBaseUtil.getBoolean(keyRuleVO.getIgnorecaseflag());
        boolean ignoreWidth = keyRuleVO ==null?false: VciBaseUtil.getBoolean(keyRuleVO.getIgnorewidthflag());
        //必须将属性按照顺序排序好
        List<CodeClassifyTemplateAttrVO> attrVOList = ketAttrMap.values().stream().sorted(((o1, o2) -> o1.getOrderNum().compareTo(o2.getOrderNum()))).collect(Collectors.toList());
        Map<String/**行号**/,String/**关键属性的组合内容**/> rowIndexKeyStringMap = new HashMap<>();
        dataList.parallelStream().forEach(cbo-> {
            String rowIndex = cbo.getAttributeValue(IMPORT_ROW_INDEX);
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < attrVOList.size(); i++) {
                CodeClassifyTemplateAttrVO attrVO = attrVOList.get(i);
                String attrId = attrVO.getId().toLowerCase(Locale.ROOT);
                String value = cbo.getAttributeValue( attrId);
                if (value == null) {
                    value = "";
                }
                if(trim){
                    value = value.trim();
                }
                if(trimAll){
                    value = value.replace(" ","");
                }
                if(ignoreCase){
                    value = value.toLowerCase(Locale.ROOT);
                }
                if(ignoreWidth){
                    value = VciBaseUtil.toDBC(value);
                }
                sb.append(value).append("${ks}");
            }
            String keyString = sb.toString();
            if(rowIndexKeyStringMap.containsValue(keyString) && StringUtils.isNotBlank(keyString)){
                selfRepeatRowIndexList.add(rowIndex);
            }else {
                rowIndexKeyStringMap.put(rowIndex, sb.toString());
            }
        });
        //因为只是关键属性重复,所以我们不能重复的多条选一条来报错
        return selfRepeatRowIndexList;
    }
    /**
     * excel的标题上获取字段所在的位置
     * @param titleRowData æ ‡é¢˜çš„内容
     * @param attrNameIdMap æ¨¡æ¿ä¸­å±žæ€§åç§°å’Œè‹±æ–‡çš„æ˜ å°„
@@ -653,6 +1288,272 @@
            }
        }
    }
    private List<ClientBusinessObject> ChangeMapTOClientBusinessObjects(List<Map<String,String>> oldDataMap){
        List<ClientBusinessObject> clientBusinessObjectList=new CopyOnWriteArrayList<>();
        oldDataMap.parallelStream().forEach(dataMap->{
            ClientBusinessObject clientBusinessObject=new ClientBusinessObject();
            DefaultAttrAssimtUtil.copplyDefaultAttrAssimt(dataMap,clientBusinessObject);
            dataMap.forEach((key,value)->{
                clientBusinessObject.setAttributeValue(key,value);
            });
        });
        return clientBusinessObjectList;
    }
    /***
     * æ­£ç¡®é”™è¯¯æ•°æ®redis缓存
     * @param uuid
     * @param templateVO
     * @param rowIndexCbo
     * @param dataSet
     * @param fieldIndexMap
     * @param errorMap
     * @param isok
     */
    private void createRedisDatas(String uuid,CodeClassifyTemplateVO templateVO,Map<String,ClientBusinessObject> rowIndexCbo, SheetDataSet dataSet, Map<Integer/**列号**/,String/**字段的名称**/> fieldIndexMap,Map<String,String> errorMap,boolean isok){
        List<SheetRowData>  needsheetRowDataList =new ArrayList<>();
        if(errorMap.size()>0) {
            //要把以上的错误的都抛出后,再继续处理时间和组合规则
            needsheetRowDataList = dataSet.getRowData().stream().filter(cbo -> {
                String rowIndex=cbo.getRowIndex();
                return  isok? !errorMap.containsKey(rowIndex):errorMap.containsKey(rowIndex);
            }).collect(Collectors.toList());
        }else{
            needsheetRowDataList= dataSet.getRowData();
        }
        Map<String/**中文名称**/, SheetRowData/**英文名称**/> rowIdexDataMap = needsheetRowDataList.stream().collect(Collectors.toMap(s -> s.getRowIndex(), t -> t,(o1, o2)->o2));
        Map<String,CodeImprotDataVO> clsfDataMap=new HashMap<>();
        rowIndexCbo .forEach((rowIndex, cbo) -> {
            CodeImprotDataVO codeImprotDataVO = new CodeImprotDataVO();
            codeImprotDataVO.setTemplateOid(templateVO.getOid());
            List<Map<String, String>> dataList = new ArrayList<>();
            if(rowIdexDataMap.containsKey(rowIndex)){
                SheetRowData sheetRowData=rowIdexDataMap.get(rowIndex);
                Map<String, String> dataMap = new HashMap<>();
                Map<Integer, String> data = sheetRowData.getData();
                fieldIndexMap.forEach((integer, s) -> {
                    String field = fieldIndexMap.get(integer);
                    if (data.containsKey(integer)) {
                        String vlues = data.get(integer);
                        dataMap.put(field, vlues);
                    }
                });
                dataMap.put("oid",cbo.getOid());
                dataList.add(dataMap);
            }
            if(clsfDataMap.containsKey(templateVO.getOid())){
                codeImprotDataVO=clsfDataMap.get(templateVO.getOid());
                dataList.addAll(codeImprotDataVO.getDatas());
            }
            codeImprotDataVO.setColNames(dataSet.getColName());
            codeImprotDataVO.setDatas(dataList);
            clsfDataMap.put(templateVO.getOid(),codeImprotDataVO);
        });
        if(!CollectionUtils.isEmpty(clsfDataMap)) {
            Collection codeImprotDataVOS=clsfDataMap.values();
            List<CodeImprotDataVO> codeImprotDataVOList=new ArrayList<>();
            codeImprotDataVOList.addAll(codeImprotDataVOS);
            bladeRedis.set(uuid+"-"+templateVO.getOid(), codeImprotDataVOList);
            bladeRedis.expire(uuid+"-"+templateVO.getOid(),BATCHADD_REDIS_TIME);//redis过期时间
        }
    }
    /****
     * æ•°æ®ç›¸ä¼¼é¡¹æ•°æ®æ ¡éªŒredis缓存
     * @param codeClassifyOid
     * @param templateVO
     * @param cboList
     * @param resembleMap
     * @param btmtypeid
     * @param dataResembleVOS
     */
    private void bathcResembleQuery(String codeClassifyOid, CodeClassifyTemplateVO templateVO, List<ClientBusinessObject> cboList,Map<String,String>resembleMap,String btmtypeid,List<DataResembleVO> dataResembleVOS){
        CodeClassifyFullInfoBO fullInfoBO = classifyService.getClassifyFullInfo(codeClassifyOid);
        Map<String, String> conditionMap = new HashMap<>();
        CodeResembleRuleVO resembleRuleVO = Optional.ofNullable(engineService.getUseResembleRule(fullInfoBO, fullInfoBO.getCurrentClassifyVO())).orElseGet(() -> new CodeResembleRuleVO());
        //需要获取是否有相似查询属性
        Map<String, CodeClassifyTemplateAttrVO> attrVOs = templateVO.getAttributes().stream().filter(s -> VciBaseUtil.getBoolean(s.getSameRepeatAttrFlag())).collect(Collectors.toMap(s -> s.getId(), t -> t));
        if (CollectionUtils.isEmpty(attrVOs)) {
            return;
        }
        Map<String,CodeImprotResembleVO> codeImprotResembleVOMap=new HashMap<>();
        List<CodeImprotResembleVO> codeImprotResembleVOList=new ArrayList<>();
        Map<String,String> rowIndePathMap=new HashMap<>();
        cboList.stream().forEach(clientBusinessObject -> {
            CodeImprotResembleVO codeImprotResembleVO=new CodeImprotResembleVO();
            final String[] path = {""};
            List<String> fieldList=new ArrayList<>();
            List<String> rowIndeList=new ArrayList<>();
            String rowIndex = clientBusinessObject.getAttributeValue(IMPORT_ROW_INDEX);
            attrVOs.forEach((attrId, attrVO) -> {
                String value="";
                /*if (VciQueryWrapperForDO.BASIC_FIELD_MAP.containsKey(attrId)) {
                    value = WebUtil.getStringValueFromObject(WebUtil.getValueFromField(WebUtil.getFieldForObject(attrId, orderDTO.getClass()).getName(), orderDTO));
                }else {*/
                value= clientBusinessObject.getAttributeValue(attrId);
                // }
                fieldList.add(attrId);
                value=StringUtils.isBlank(value)?"":value;
                path[0] +=value+"#";
                engineService.wrapperResembleConditionMap(value, resembleRuleVO, attrId, conditionMap);
            });
            List<Map<String,String>> dataMap=new ArrayList<>();
            if(codeImprotResembleVOMap.containsKey(path[0])) {
                codeImprotResembleVO=codeImprotResembleVOMap.get(path[0]);
                rowIndeList=codeImprotResembleVO.getRownIndex();
                dataMap=  codeImprotResembleVO.getDataList();
                resembleMap.put(rowIndex, "存在相似数据");
            }else{
                if (!CollectionUtils.isEmpty(conditionMap)) {
                    Map<String, String> andConditionMap = new HashMap<>();
                    andConditionMap.put("islastr", "1");
                    andConditionMap.put("islastv", "1");
                    conditionMap.putAll(andConditionMap);
                    PageHelper pageHelper = new PageHelper(-1);
                    pageHelper.addDefaultDesc("id");
                    CodeTemplateAttrSqlBO sqlBO = engineService.getSqlByTemplateVO(btmtypeid, templateVO, conditionMap, pageHelper);
                    List<Map<String,String>> dataMapList=commonsMapper.queryByOnlySqlForMap(sqlBO.getSqlUnPage());
                    List<ClientBusinessObject> resembleCboList=    ChangeMapTOClientBusinessObjects(dataMapList);
                    if(!CollectionUtils.isEmpty(resembleCboList)) {
                        List<Map<String, String>> finalDataMap = dataMap;
                        resembleCboList.stream().forEach(cbo->{
                            Map<String,String> resembDataMap=new HashMap<>();
                            fieldList.stream().forEach(field->{
                                String value=cbo.getAttributeValue(field);
                                value=StringUtils.isBlank(value)?"":value;
                                resembDataMap.put(field,value);
                            });
                            resembDataMap.put("codetemplateoid",templateVO.getOid());
                            resembDataMap.put("id",StringUtils.isBlank(cbo.getAttributeValue("id"))?"":cbo.getAttributeValue("id"));
                            resembDataMap.put("rowIndex","");
                            resembDataMap.put("oid",cbo.getOid());
                            finalDataMap.add(resembDataMap);
                        });
                        resembleMap.put(rowIndex, "存在相似数据");
                    }
                }
            }
            rowIndePathMap.put(rowIndex,path[0]);
            rowIndeList.add(rowIndex);
            codeImprotResembleVO.setPath(path[0]);
            codeImprotResembleVO.setRownIndex(rowIndeList);
            codeImprotResembleVO.setConditionMap(conditionMap);
            codeImprotResembleVO.setFields(fieldList);
            codeImprotResembleVO.setDataList(dataMap);
            codeImprotResembleVOMap.put(path[0],codeImprotResembleVO);
        });
        Map<String, ClientBusinessObject> cboMap = cboList.stream().filter(cbo -> cbo != null).collect(Collectors.toList()).stream().collect(Collectors.toMap(s -> s.getAttributeValue((IMPORT_ROW_INDEX)), t -> t));
        if(!CollectionUtils.isEmpty(rowIndePathMap)){
            rowIndePathMap.forEach((rowIndex, path) -> {
                if(codeImprotResembleVOMap.containsKey(path)){
                    CodeImprotResembleVO codeImprotResembleVO=  codeImprotResembleVOMap.get(path);
                    List<String> fieldList=codeImprotResembleVO.getFields();
                    List<String> rownIndexList= codeImprotResembleVO.getRownIndex();
                    List<String> newRownIndexList = rownIndexList.stream().filter(cbo -> {
                        return rowIndex!=cbo;
                    }).collect(Collectors.toList());
                    newRownIndexList.stream().forEach(s -> {
                        resembleMap.put(s, "存在相似数据");
                    });
                    List<Map<String, String>>newDataList=new ArrayList<>();
                    DataResembleVO dataResembleVO=new DataResembleVO();
                    dataResembleVO.setOid(cboMap.get(rowIndex).getOid());
                    List<ClientBusinessObject> needSaveCboList = cboList.stream().filter(cbo -> {
                        String newRowIndex = cbo.getAttributeValue(IMPORT_ROW_INDEX);
                        return rownIndexList.contains(newRowIndex)&&(!newRowIndex.equalsIgnoreCase(rowIndex));
                    }).collect(Collectors.toList());
                    if(!CollectionUtils.isEmpty(needSaveCboList)) {
                        needSaveCboList.stream().forEach(cbo -> {
                            String newRowIndex = cbo.getAttributeValue(IMPORT_ROW_INDEX);
                            Map<String, String> resembDataMap = new HashMap<>();
                            fieldList.stream().forEach(field -> {
                                String value = cbo.getAttributeValue(field);
                                value = StringUtils.isBlank(value) ? "" : value;
                                resembDataMap.put(field, value);
                            });
                            resembDataMap.put("codetemplateoid",templateVO.getOid());
                            resembDataMap.put("id",StringUtils.isBlank(cbo.getAttributeValue("id"))?"":cbo.getAttributeValue("id"));
                            resembDataMap.put("rowIndex", newRowIndex);
                            resembDataMap.put("oid",cbo.getOid());
                            newDataList.add(resembDataMap);
                        });
                    }
                    List<Map<String, String>>dataList=codeImprotResembleVO.getDataList();
                    newDataList.addAll(dataList);
                    dataResembleVO.setDataList(newDataList);
                    dataResembleVOS.add(dataResembleVO);
                }
            });
        }
    }
    /***
     * å­˜å‚¨åˆ†ç±»å¯¹è±¡åŠå…¶åˆ—名
     * @param uuid
     * @param templateVOList
     * @param dataSet
     * @param fieldIndexMap
     * @param iscContain
     */
    private  void createRedisByCodeClassify(String uuid,CodeClassifyTemplateVO templateVOList,SheetDataSet dataSet, Map<Integer/**列号**/,String/**字段的名称**/> fieldIndexMap,boolean iscContain){
        List<ColumnVO> columnVOList = new ArrayList<>();
        List<String> outNameList = dataSet.getColName();
        fieldIndexMap.forEach((integer, s) -> {
            ColumnVO columnVOS = new ColumnVO();
            String field = fieldIndexMap.get(integer);
            String outName = outNameList.get(integer);
            columnVOS.setField(field);
            columnVOS.setTitle(outName);
            columnVOList.add(columnVOS);
        });
        CodeImportTemplateVO codeImportTemplateVO=new CodeImportTemplateVO();
        codeImportTemplateVO.setCodeClassifyTemplateVO(templateVOList);
        codeImportTemplateVO.setCloNamesList(columnVOList);
        List<CodeImportTemplateVO> codeImportTemplateVOs= new ArrayList<>();
        codeImportTemplateVOs.add(codeImportTemplateVO);
        if(codeImportTemplateVOs.size()>0) {
            bladeRedis.set(uuid, codeImportTemplateVOs);
            bladeRedis.expire(uuid, BATCHADD_REDIS_TIME);//redis过期时间
        }
    }
    /**
     * æ‹·è´ä¸šåŠ¡ç±»åž‹åˆ°map
     * @param cbo ä¸šåŠ¡æ•°æ®
     * @param map map
     */
    public static void copyValueToMapFromCbos(ClientBusinessObject cbo,Map<String,String> map){
        if(cbo!=null){
            copyValueToMapFromBos(cbo,map);
        }
    }
    /**
     * æ‹·è´ä¸šåŠ¡ç±»åž‹åˆ°map
     * @param bo ä¸šåŠ¡æ•°æ®
     * @param map map
     */
    public static void copyValueToMapFromBos(ClientBusinessObject bo,Map<String,String> map){
        if(bo!=null ){
            //先把所有的字段映射找到
            AttributeValue[] newAList = bo.newAttrValList;
            AttributeValue[] hisAList = bo.hisAttrValList;
            if(hisAList!=null&&hisAList.length>0){//
                for(int i = 0 ; i < hisAList.length;i++){
                    AttributeValue av = hisAList[i];
                    String attrName = av.attrName.toLowerCase();
                    map.put(attrName, av.attrVal);
                }
            }
            if(newAList!=null&&newAList.length>0){//NEW的优先级高些
                for(int i = 0 ; i < newAList.length;i++){
                    AttributeValue av = newAList[i];
                    String attrName = av.attrName.toLowerCase();
                    map.put(attrName, av.attrVal);
                }
            }
        }
    }
}
Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/util/AttributeChecker.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,115 @@
package com.vci.ubcs.code.util;
import com.vci.ubcs.omd.feign.IAttributeClient;
import com.vci.ubcs.omd.util.Tool;
import com.vci.ubcs.omd.vo.AttributeVO;
import org.springblade.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class AttributeChecker {
    @Autowired(required = false)
    private  IAttributeClient attributeClient;
    public static HashMap<String, AttributeVO> attrItemMap = new HashMap();
    public static List<AttributeVO> attrItems = new ArrayList<AttributeVO>();
    public void getAllAttribute() {
        if (attrItems == null) {
            R<List<AttributeVO>> R = attributeClient.getAll();
            attrItems=R.getData();
            List<AttributeVO> var4;
            int var3 = (var4 = attrItems).size();
            for(int var2 = 0; var2 < var3; ++var2) {
                AttributeVO attrItem = var4.get(var2);
                attrItemMap.put(attrItem.getName(), attrItem);
            }
        }
    }
    public int isAttrValValid(String attrName, String attrVal) {
//        if (!BusinessConstants.BO_CONSTANTS.containsKey(attrName.toUpperCase())) {
            if (attrVal != null && !attrVal.trim().equals("")) {
                this.getAllAttribute();
                AttributeVO attributeVO = (AttributeVO)attrItemMap.get(attrName);
                if (attributeVO == null) {
                    return 0;
                } else {
                    String attrType = attributeVO.getTypeKey();
                    int rs;
                    if (attrType.equals("VTString")) {
                    //    rs = this.checkVTStringValValid(attributeVO, attrName, attrVal);
                        rs = 0;
                    } else if (attrType.equals("VTInteger")) {
                    //    rs = this.checkVTIntegerValValid(attributeVO, attrName, attrVal);
                        rs = 0;
                    } else if (attrType.equals("VTLong")) {
                    //    rs = this.checkVTLongValValid(attributeVO, attrName, attrVal);
                        rs = 0;
                    } else if (attrType.equals("VTDouble")) {
                    //    rs = this.checkVTDoubleValValid(attributeVO, attrName, attrVal);
                        rs = 0;
                    } else if (attrType.equals("VTBoolean")) {
                        rs = 0;
                    } else if (attrType.equals("VTImage")) {
                        rs = 0;
                    } else if (attrType.equals("VTDate")) {
                        rs = 0;
                    } else if (attrType.equals("VTTime")) {
                        rs = 0;
                    } else if (attrType.equals("VTDateTime")) {
                        rs = 0;
                    } else if (attrType.equals("VTNote")) {
                        rs = 0;
                    } else if (attrType.equals("VTFilePath")) {
                        rs = 0;
                    } else {
                        rs = 0;
                    }
                    return rs;
                }
            } else {
                return 0;
            }
//        } else {
//            return 0;
//        }
    }
    /*private int checkVTStringValValid(AttributeVO attributeVO, String attrName, String attrVal) {
        String other ="";
        int maxLength = Integer.valueOf(Tool.getOtherValueByType(other, "length"));
        int length = attrVal.length();
        return length > maxLength ? 1 : 0;
    }
    private int checkVTIntegerValValid(AttributeVO attributeVO, String attrName, String attrVal) {
        VTInteger obj = new VTInteger(Integer.valueOf(attrVal));
        return !obj.checkRageValueByRage(attributeVO.rage) ? 2 : 0;
    }
    private int checkVTLongValValid(AttributeVO attributeVO, String attrName, String attrVal) {
        VTLong obj = new VTLong(Long.valueOf(attrVal));
        return !obj.checkRageValueByRage(attributeVO.rage) ? 2 : 0;
    }
    private int checkVTDoubleValValid(AttributeVO attributeVO, String attrName, String attrVal) {
        VTDouble obj = new VTDouble(Double.valueOf(attrVal));
        String other = attributeVO.other;
        int maxLength = Integer.valueOf(Tool.getOtherValueByType(other, "length"));
        int length = String.valueOf(attrVal).length() - 1;
        if (length >= maxLength && !obj.checkRageValueByRage(attributeVO.rage)) {
            return 3;
        } else if (!obj.checkRageValueByRage(attributeVO.rage)) {
            return 2;
        } else {
            return length >= maxLength ? 1 : 0;
        }
    }*/
}
Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/util/ClientBusinessObject.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,111 @@
package com.vci.ubcs.code.util;
import com.vci.ubcs.code.bo.AttributeValue;
import com.vci.ubcs.code.vo.pagemodel.BaseModelVO;
import com.vci.ubcs.starter.exception.VciBaseException;
import com.vci.ubcs.starter.revision.model.BaseModel;
import lombok.Data;
import java.util.ArrayList;
@Data
public class ClientBusinessObject extends BaseModel {
    public AttributeValue[] newAttrValList;
    public AttributeValue[] hisAttrValList;
    public void setAttributeValue(String attributeName, String attributeValue) throws VciBaseException {
        this.setAttributeValue(attributeName, attributeValue, false);
    }
    public void setAttributeValue(String attributeName, String attributeValue, boolean isCreate) throws VciBaseException {
        int isValid = (new AttributeChecker()).isAttrValValid(attributeName, attributeValue);
        if (isValid == 1) {
            throw getLocalError("P0010SOF-00017", new String[]{attributeName, attributeValue});
        } else if (isValid == 2) {
            throw this.getLocalError("P0010SOF-00018", new String[]{attributeName, attributeValue});
        } else if (isValid == 3) {
            throw this.getLocalError("P0010SOF-00019", new String[]{attributeName, attributeValue});
        } else {
            this.setAttributeValueWithNoCheck(attributeName, attributeValue, isCreate);
        }
    }
    public void setAttributeValueWithNoCheck(String attributeName, String attributeValue) throws VciBaseException {
        this.setAttributeValueWithNoCheck(attributeName, attributeValue, false);
    }
    public void setAttributeValueWithNoCheck(String attributeName, String attributeValue, boolean isCreate) throws VciBaseException {
        /*if (isCreate) {//&& BusinessConstants.BO_CONSTANTS.containsKey(attributeName.toUpperCase())
            this.setConstantsAttrVal(attributeName, attributeValue);
        } else {*/
            AttributeValue[] attrValues = this.newAttrValList;
            ArrayList<AttributeValue> attrValList = new ArrayList();
            AttributeValue attrVal;
            int i;
            if (attrValues != null && attrValues.length > 0) {
                AttributeValue[] var9 = attrValues;
                i = attrValues.length;
                for(int var7 = 0; var7 < i; ++var7) {
                    attrVal = var9[var7];
                    attrValList.add(attrVal);
                }
            }
            attrVal = null;
            boolean isExist = false;
            for(i = 0; i < attrValList.size(); ++i) {
                attrVal = (AttributeValue)attrValList.get(i);
                if (attrVal.attrName.toUpperCase().equals(attributeName.toUpperCase())) {
                    attrVal.attrVal = attributeValue;
                    isExist = true;
                    break;
                }
            }
            if (!isExist) {
                attrVal = new AttributeValue();
                attrVal.attrName = attributeName.toUpperCase();
                attrVal.attrVal = attributeValue;
                attrValList.add(attrVal);
            }
            this.newAttrValList = (AttributeValue[])attrValList.toArray(new AttributeValue[attrValList.size()]);
    //    }
    }
    public String getAttributeValue(String attrName) {
        String res = "";
        boolean existInNewAttr = false;
        int i;
        if (this.newAttrValList != null) {
            for(i = 0; i < this.newAttrValList.length; ++i) {
                if (this.newAttrValList[i].attrName.toUpperCase().equals(attrName.toUpperCase())) {
                    existInNewAttr = true;
                    res = this.newAttrValList[i].attrVal;
                }
            }
        }
        if (existInNewAttr) {
            return res;
        } else if (this.hisAttrValList == null) {
            return "";
        } else {
            for(i = 0; i < this.hisAttrValList.length; ++i) {
                if (this.hisAttrValList[i].attrName.toUpperCase().equals(attrName.toUpperCase())) {
                    res = this.hisAttrValList[i].attrVal;
                }
            }
            return res;
        }
    }
    public VciBaseException getLocalError(String error_code ,String[] error_messages) {
        return new VciBaseException(error_code, error_messages);
    }
}