xiejun
2023-09-18 7db3ee6e84714a868e0b57a61a033d050b1a61fc
Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmEngineServiceImpl.java
@@ -5,6 +5,7 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.vci.ubcs.code.applyjtcodeservice.vo.BaseModelVO;
import com.vci.ubcs.code.bo.CodeClassifyFullInfoBO;
import com.vci.ubcs.code.bo.CodeTemplateAttrSqlBO;
import com.vci.ubcs.code.constant.FrameWorkDefaultValueConstant;
@@ -15,11 +16,13 @@
import com.vci.ubcs.code.enumpack.*;
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.CodeReferConfigVO;
import com.vci.ubcs.code.vo.pagemodel.UITableFieldVO;
import com.vci.ubcs.code.vo.pagemodel.UITablePageVO;
import com.vci.ubcs.code.vo.pagemodel.*;
import com.vci.ubcs.code.wrapper.BaseMdodelWrapper;
import com.vci.ubcs.flow.core.dto.FlowStatusDTO;
import com.vci.ubcs.flow.core.feign.IMDMIFlowAttrClient;
import com.vci.ubcs.flow.core.vo.ProcessStageAttrVO;
@@ -36,6 +39,7 @@
import com.vci.ubcs.starter.revision.model.TreeQueryObject;
import com.vci.ubcs.starter.revision.model.TreeWrapperOptions;
import com.vci.ubcs.starter.revision.service.RevisionModelUtil;
import com.vci.ubcs.starter.util.MdmBtmTypeConstant;
import com.vci.ubcs.starter.util.UBCSSqlKeyword;
import com.vci.ubcs.starter.web.constant.QueryOptionConstant;
import com.vci.ubcs.starter.web.constant.RegExpConstant;
@@ -53,6 +57,7 @@
import com.vci.ubcs.system.user.feign.IUserClient;
import net.logstash.logback.encoder.org.apache.commons.lang3.StringUtils;
import oracle.sql.TIMESTAMP;
import org.aspectj.apache.bcel.classfile.Code;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springblade.core.cache.utils.CacheUtil;
@@ -434,18 +439,11 @@
        //备注
        cbo.setDescription(orderDTO.getDescription());
        cboList.add(cbo);
//
//      cboList.add(cbo);
        List<String> codeList = productCodeService.productCodeAndSaveData(classifyFullInfo, templateVO, ruleVO, orderDTO.getSecDTOList(), cboList);
//      List<String> charList = new ArrayList<>();
//      for (BaseModel baseModel : cboList) {
//         charList.add(baseModel.getId());
//      }
        batchSaveSelectChar(templateVO, cboList);
        return codeList.size() > 0 ? codeList.get(0) : "";
//      return null;
    }
    /**
@@ -470,7 +468,7 @@
                if (!CodeLevelTypeEnum.MIN.getValue().equalsIgnoreCase(attrVO.getClassifyInvokeLevel()) && !"min".equalsIgnoreCase(attrVO.getClassifyInvokeLevel())) {
                    //指定了层级的
                    //注意,因为查询上级分类出来的层级是倒序的,即顶层节点是最大的值
                    List<CodeClassifyVO> classifyVOS = classifyFullInfoBO.getParentClassifyVOs().stream().sorted(((o1, o2) -> o2.getDataLevel().compareTo(o1.getDataLevel()))).collect(Collectors.toList());
                    List<CodeClassifyVO> classifyVOS = classifyFullInfoBO.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);
@@ -559,7 +557,9 @@
      } else {
            //说明是自行配置的
            //前端必须要传递小写的属性
            value = orderDTO.getData().getOrDefault(attrId, "");
         String orDefault = orderDTO.getData().getOrDefault(attrId, "");
         value = Func.isBlank(orDefault) ? orderDTO.getData()
            .getOrDefault(attrId.toUpperCase(Locale.ROOT), ""):orDefault;
        }
        return value;
    }
@@ -665,7 +665,11 @@
            }
            final String[] sql = {"select count(*) from " + listR.getData().get(0).getTableName() + " t where 1 = 1 "};
            conditionMap.forEach((key, value) -> {
                sql[0] += " and " + key + " = " + value;
            if(StringUtils.isBlank(value)||value.equals(QueryOptionConstant.ISNULL)) {
               sql[0] += " and " + key + " is null";
            }else{
               sql[0] += " and " + key + " = " + value;
            }
            });
            if (StringUtils.isNotBlank(orderDTO.getOid())) {
                //修改的时候,需要排除自己
@@ -686,10 +690,9 @@
   /**
    * 校验关键属性
    *
    * @param classifyFullInfo 分类的全部信息
    * @param templateVO       模板的内容,必须包含模板属性
    * @param orderDTO         编码申请的相关的信息
    */
   @Override
   public List<Map> checkKeyAttrOnOrderFordatas(CodeOrderDTO orderDTO) {
      List<Map>dataList=new ArrayList<>();
      CodeClassifyFullInfoBO classifyFullInfo = classifyService.getClassifyFullInfo(orderDTO.getCodeClassifyOid());
@@ -745,7 +748,29 @@
      return dataList;
   }
    /**
   /**
    * 根据当前申请编码的分类,逐层往上校验是否符合属于配置的中的分类子节点的分
    * 类,如果符合,则该分类申请的编码为集团码返回true,反之则为企业编码返回false
    * @param parameter 传入数据,classifyGroupCode:配置的中的分类顶节点,oid:选择节点的oid
    */
   @Override
   public R checkGroupCode(Map<String, String> parameter) {
      List<CodeClassify> codeClassifyList = classifyService.selectAllLevelParentByOid(parameter.get("oid"));
      Set<String> configGroupCode = Arrays.stream(parameter.get("classifyGroupCode").split("#")).collect(Collectors.toSet());
//      Boolean checkGroupFlag = false;//是否查询到配置的顶层分类中
      for (int i = codeClassifyList.size()-1; i >= 0; i--) {
         if(configGroupCode.contains(codeClassifyList.get(i).getId())){
//            checkGroupFlag = true;
            return R.data("true");
         }
//         if(checkGroupFlag && parameter.get("nowApplyCode").equals(codeClassifyList.get(i).getId())){
//            return R.data(true);
//         }
      }
      return R.data("false");
   }
   /**
     * 封装关键属性的查询语句
     *
     * @param value        当前的值
@@ -945,7 +970,7 @@
            return (BaseModel) valueWrapper.get();
        } catch (Exception e) {
            logger.error("创建业务类型对象", e);
            throw new VciBaseException("initBtmError", new String[]{btmName});
            throw new ServiceException("initBtmError:"+"业务类型:"+btmName+":"+e.getMessage());
        }
    }
@@ -1323,6 +1348,7 @@
        }
        fieldVO.setOptionJsMap(eventJsMap);
        fieldVO.setStyle(attrVO.getTableDisplayStyle());
        fieldVO.setTableDisplayFlag(attrVO.getTableDisplayFlag());
        //列表里不允许直接编辑
        fieldVO.setDateFormate(attrVO.getCodeDateFormat());
        return fieldVO;
@@ -1363,6 +1389,9 @@
      uiTableConfigVO.setQueryColumns(queryColumns);
      //set给表格配置属性
      uiFormReferVO.setTableConfig(uiTableConfigVO);
      //字段名不一致,需要手动set
      uiFormReferVO.setMuti(Func.toBoolean(codeReferConfig.getIsMuti()));
      uiFormReferVO.setInitSort(new UIFieldSortVO(codeReferConfig.getSortField(),codeReferConfig.getSortType()));
      // 筛选条件
      HashMap<String, String> whereMap = new HashMap<>();
      if(!CollectionUtils.isEmpty(codeReferConfig.getCodeSrchCondConfigVOS())){
@@ -2406,7 +2435,6 @@
        return phaseAttrService.listAttrByTemplateOidAndPhaseId(templateVO.getOid(), phase);
    }
    /**
     * 路径上包含当前分类的所有分类信息
     *
@@ -2464,10 +2492,12 @@
            conditionMap.put("t." + CODE_CLASSIFY_OID_FIELD, codeClassifyOid);
        } else {
//         conditionMap.put(CODE_CLASSIFY_OID_FIELD, QueryOptionConstant.IN + "(select oid from " + VciBaseUtil.getTableName(MdmBtmTypeConstant.CODE_CLASSIFY)
         List<BtmTypeVO> classifyData = btmTypeClient.selectByIdCollection(Collections.singletonList(MdmBtmTypeConstant.CODE_CLASSIFY)).getData();
         if(Func.isEmpty(classifyData)){
            throw new ServiceException("业务类型中英文名称和查询条件配置不一致,请修改业务类型中分类表英文名称为"+MdmBtmTypeConstant.CODE_CLASSIFY);
         }
            conditionMap.put("t." + CODE_CLASSIFY_OID_FIELD, QueryOptionConstant.IN + "(select oid from " +
                    btmTypeClient.selectByIdCollection(Collections.singletonList("classify"))
                            .getData().get(0).getTableName() + " where lcstatus='" + FrameWorkDefaultValueConstant
            classifyData.get(0).getTableName() + " where lcstatus='" + FrameWorkDefaultValueConstant
                    .FRAMEWORK_DATA_ENABLED + "' start with parentCodeClassifyOid = '" + codeClassifyOid +
                    "' CONNECT BY PRIOR OID = parentCodeClassifyOid )");
        }
@@ -2730,12 +2760,102 @@
        String codeRuleOid = classifyVO.getCodeRuleOid();
        if (StringUtils.isBlank(codeRuleOid)) {
            //往上找
            CodeClassifyFullInfoBO fullInfo = classifyService.getClassifyFullInfo(codeClassifyOid);
            return getCodeRuleByClassifyFullInfo(fullInfo);
         CodeRuleVO classifyFullInfoCodeRule = getCodeRuleByClassifyFullInfo(classifyService.getClassifyFullInfo(codeClassifyOid));
         return toCodeValueApplyStatus(classifyFullInfoCodeRule);
        }
        //我们查询编码规则
        return ruleService.getObjectHasSecByOid(codeRuleOid);
        //查询编码规则
      CodeRuleVO objectHasSecByOid = ruleService.getObjectHasSecByOid(codeRuleOid);
      return toCodeValueApplyStatus(objectHasSecByOid);
    }
   /**
    * 编码申请表单,隐藏、可输、只读转换
    * @param codeRuleVO
    * @return
    */
   private CodeRuleVO toCodeValueApplyStatus(CodeRuleVO codeRuleVO){
      if(codeRuleVO.getSecVOList().isEmpty()){
         return codeRuleVO;
      }
      // 可输码段类型
      List<String> inputTypes = Arrays.asList(
         CodeSecTypeEnum.CODE_FIXED_SEC.getValue(),
         CodeSecTypeEnum.CODE_VARIABLE_SEC.getValue(),
         CodeSecTypeEnum.CODE_CLASSIFY_SEC.getValue(),
         CodeSecTypeEnum.CODE_REFER_SEC.getValue(),
         CodeSecTypeEnum.CODE_DATE_SEC.getValue()
      );
      // 只读码段类型
      List<String> readOnlyTypes = Arrays.asList(
         CodeSecTypeEnum.CODE_LEVEL_SEC.getValue(),
         CodeSecTypeEnum.CODE_ATTR_SEC.getValue()
      );
      // 隐藏码段类型
      /*List<String> hideType = Arrays.asList(
         CodeSecTypeEnum.CODE_SERIAL_SEC.getValue()
      );*/
      // 当前规则的所有类型码段
      List<String> secTypeList = codeRuleVO.getSecVOList().stream().map(CodeBasicSecVO::getSecType).collect(Collectors.toList());
      // 情况一 全部是只读的码段类型
      boolean hasAllReadOnlyType =secTypeList.stream().allMatch(item -> readOnlyTypes.stream().anyMatch(item1-> item.equals(item1)));
      // 全部是只读的码段类型
      if(hasAllReadOnlyType){
         List<CodeBasicSecVO> basicSecVOS = codeRuleVO.getSecVOList().stream().map(secVO -> {
            secVO.setCodeValueApplyStatus(3);
            // 日期码段设置默认值
            if (secVO.getSecType().equals(CodeSecTypeEnum.CODE_DATE_SEC.getValue())) {
               try {
                  secVO.setCodeDateValue(Func.format(new Date(),secVO.getCodeDateFormatStr()));
               }catch (Exception e){
                  throw new ServiceException("日期码段日期格式配置有误,导致转换出错:"+e.getMessage());
               }
            }
            return secVO;
         }).collect(Collectors.toList());
         codeRuleVO.setSecVOList(basicSecVOS);
         return codeRuleVO;
      }
      // 情况二 全部都是可输入类型的
      boolean hasAllInputType = secTypeList.stream().allMatch(item -> inputTypes.stream().anyMatch(item1-> item.equals(item1)));
      if(hasAllInputType){
         List<CodeBasicSecVO> basicSecVOS = codeRuleVO.getSecVOList().stream().map(secVO -> {
            secVO.setCodeValueApplyStatus(1);
            // 日期码段设置默认值
            if (secVO.getSecType().equals(CodeSecTypeEnum.CODE_DATE_SEC.getValue())) {
               try {
                  secVO.setCodeDateValue(Func.format(new Date(),secVO.getCodeDateFormatStr()));
               }catch (Exception e){
                  throw new ServiceException("日期码段日期格式配置有误,导致转换出错:"+e.getMessage());
               }
            }
            return secVO;
         }).collect(Collectors.toList());
         codeRuleVO.setSecVOList(basicSecVOS);
         return codeRuleVO;
      }
      // 情况三包含人为选择的码段,又有只读类型码段的,所有码段都要显示出来,可输设置为1,只读设置为2,隐藏设置为3
      List<CodeBasicSecVO> basicSecVOS = codeRuleVO.getSecVOList().stream().map(secVO -> {
         if(inputTypes.contains(secVO.getSecType())){
            secVO.setCodeValueApplyStatus(1);
         }else if(readOnlyTypes.contains(secVO.getSecType())){
            secVO.setCodeValueApplyStatus(2);
         }else{
            secVO.setCodeValueApplyStatus(3);
         }
         // 日期码段设置默认值
         if (secVO.getSecType().equals(CodeSecTypeEnum.CODE_DATE_SEC.getValue())) {
            try {
               secVO.setCodeDateValue(Func.format(new Date(),secVO.getCodeDateFormatStr()));
            }catch (Exception e){
               throw new ServiceException("日期码段日期格式配置有误,导致转换出错:"+e.getMessage());
            }
         }
         return secVO;
      }).collect(Collectors.toList());
      codeRuleVO.setSecVOList(basicSecVOS);
      codeRuleVO.setIsShowHideStatus(hasAllReadOnlyType ? "readOnly":(hasAllInputType ? "input":"readAndInput"));
      return codeRuleVO;
   }
    /**
     * 使用分类的全部信息获取编码规则
@@ -2752,7 +2872,7 @@
        } else {
            if (CollectionUtils.isEmpty(fullInfoBO.getParentClassifyVOs())) {
                //说明已经是最高层级,
                throw new VciBaseException("当前主题库分类,以及它的所有的上级分类都没有设置编码规则");
                throw new ServiceException("当前主题库分类,以及它的所有的上级分类都没有设置编码规则");
            }
            List<CodeClassifyVO> parentClassifyVOList = fullInfoBO.getParentClassifyVOs().stream().sorted((o1, o2) -> o1.getDataLevel().compareTo(o2.getDataLevel())).collect(Collectors.toList());
            //从最高的level开始获取
@@ -2764,7 +2884,7 @@
                }
            }
            if (StringUtils.isBlank(codeRuleOid)) {
                throw new VciBaseException("当前主题库分类,以及它的所有的上级分类都没有设置编码规则");
                throw new ServiceException("当前主题库分类,以及它的所有的上级分类都没有设置编码规则");
            }
        }
        return ruleService.getObjectHasSecByOid(codeRuleOid);
@@ -3461,7 +3581,6 @@
        return baseModels;
    }
    /**
     * 根据业务类型名称创建业务数据源对象
     *
@@ -3570,20 +3689,79 @@
        return R.success("更新成功!");
    }
   /**
    * 更新业务数据同时对码值表数据操作接口
    *
    * @param btmType 业务类型
    * @param baseModels      处理数据
    * @return 处理状态
    */
   @Transactional(rollbackFor = VciBaseException.class)
   @Override
   public R<Integer> updateBatchBtypeDatas(String btmType, List<BaseModel> baseModels) {
    /**
      //使用传入的业务类型查询表
      R<List<BtmTypeVO>> listR = btmTypeClient.selectByIdCollection(Collections.singletonList(btmType));
      if (!listR.isSuccess() || listR.getData().size() == 0) {
         throw new VciBaseException("传入业务类型未查询到相应表单,请检查!");
      }
      //获取当前业务类型所有字段用来做对比
      R<BtmTypeVO> allAttributeByBtmId = btmTypeClient.getAllAttributeByBtmId(btmType);
      if (!allAttributeByBtmId.isSuccess() || allAttributeByBtmId.getData().getAttributes().size() == 0) {
         throw new VciBaseException("传入业务类型未查询到相应字段信息,请检查!");
      }
      Set<String> existFild = allAttributeByBtmId.getData().getAttributes().stream().map(btmTypeAttributeVO -> {
         return btmTypeAttributeVO.getId();
      }).collect(Collectors.toSet());
      if(!CollectionUtils.isEmpty(baseModels)){
         List<String> oidList=baseModels.stream().filter(data-> com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotBlank(data.getOid())).map(BaseModel::getOid).distinct().collect(Collectors.toList());
         LambdaQueryWrapper<CodeAllCode> lqw = new LambdaQueryWrapper<>();
         lqw.in(CodeAllCode::getCreateCodeOid,oidList);
         List<CodeAllCode> codeAllCodeList= codeAllCodeService.selectByWrapper(lqw);
         Map<String, CodeAllCode> cboMap = codeAllCodeList.stream().filter(cbo -> cbo != null).collect(Collectors.toList()).stream().collect(Collectors.toMap(s -> s.getCreateCodeOid(), t -> t));
         List<CodeAllCode> newCodeAllCodeList=new ArrayList<>();
         //将bean转为map,mybatis统一处理
         List<Map<String, String>> maps = new ArrayList<>();
         try {
            baseModels.stream().forEach(baseModel->{
               String oid=baseModel.getOid();
               try {
                  maps.add(VciBaseUtil.convertBean2Map(baseModel,existFild));
               } catch (Exception e) {
                  throw new VciBaseException("类型转换错误:" + e.getMessage());
               }
               if(cboMap.containsKey(oid)){
                  CodeAllCode codeAllCode=   cboMap.get(oid);
                  codeAllCode.setId(baseModel.getId());
                  codeAllCode.setLastModifier(AuthUtil.getUser().getUserName());
                  codeAllCode.setLastModifyTime(new Date());
                  codeAllCode.setLcStatus(baseModel.getLcStatus());
                  newCodeAllCodeList.add(codeAllCode);
               }
            });
            commonsMapper.updateBatchByBaseModel(listR.getData().get(0).getTableName(), maps);
            codeAllCodeService.saveOrUpdateBatch(newCodeAllCodeList);
         } catch (Exception e) {
            throw new VciBaseException("类型转换错误:" + e.getMessage());
         }
      }
      return R.success("更新成功!");
   }
   /**
     * 获取参照的信息
     *
     * @param referConfigVO 参照的配置
     * @return 列表数据
     */
    @Override
    public IPage<BaseModel> referDataGrid(UIFormReferVO referConfigVO, BaseQueryObject baseQueryObject) throws VciBaseException {
    public IPage<BaseModelVO> referDataGrid(UIFormReferVO referConfigVO, BaseQueryObject baseQueryObject) throws VciBaseException {
        //checkReferConfig(referConfigVO);
        //使用业务类型查询
        R<BtmTypeVO> allAttributeByBtmId = btmTypeClient.getAllAttributeByBtmId(referConfigVO.getReferType());
        if (!allAttributeByBtmId.isSuccess()) {
            throw new ServiceException("业务类型feign接口调用错误!");
            throw new ServiceException("业务类型feign接口调用错误;"+allAttributeByBtmId.getMsg());
        }
        if (Func.isEmpty(allAttributeByBtmId.getData())) {
            throw new VciBaseException("传入业务类型未查询到相应表单,请检查!");
@@ -3610,6 +3788,7 @@
        if (listR.getData().isEmpty()) {
            throw new VciBaseException("传入业务类型未查询到相应表单,请检查!");
        }
      // TODO:参照配置的模糊查询过滤条件暂未处理
        String namesql = "";
        if (StringUtils.isNotBlank(baseQueryObject.getConditionMap().get("name"))) {
            String s = baseQueryObject.getConditionMap().get("name");
@@ -3659,27 +3838,28 @@
                            ZonedDateTime zdt = localDateTime.atZone(zoneId);
                            Date date = Date.from(zdt.toInstant());
                            setter.invoke(obj, date);
                            map.remove(property.getName().toUpperCase());
                            //map.remove(property.getName().toUpperCase());
                        } //oracle的数字为BigDecimal的,需要进行转换成Integer,否则将报错
                        else if (map.get(property.getName().toUpperCase()) instanceof BigDecimal
                                && ("Integer").equals(setter.getParameterTypes()[0].getSimpleName())) {
                            setter.invoke(obj, ((BigDecimal) map.get(property.getName().toUpperCase())).intValue());
                            map.remove(property.getName().toUpperCase());
                            //map.remove(property.getName().toUpperCase());
                        } else if (map.get(property.getName().toUpperCase()) != null) {
                     if(setter.getParameterTypes()[0].getSimpleName().equals("String")){
                        setter.invoke(obj, map.get(property.getName().toUpperCase()) == null ? null:String.valueOf(map.get(property.getName().toUpperCase())));
                     }else{
                        setter.invoke(obj, map.get(property.getName().toUpperCase()));
                     }
                            map.remove(property.getName().toUpperCase());
                            //map.remove(property.getName().toUpperCase());
                        }
                    }
                }
                for (Object key : map.keySet()) {
                    map.put(key, String.valueOf(map.get(key)));
                }
                ((BaseModel) obj).setData(map);
            Map<String, String> newMap = new HashMap<>();
            map.forEach((key, value) -> newMap.put(String.valueOf(key).toLowerCase(), String.valueOf(value)));
            ((BaseModel) obj).setData(newMap);
                baseModels.add((BaseModel) obj);
            }
        } catch (Exception e) {
@@ -3690,10 +3870,10 @@
                + "and lastv = " + VciBaseUtil.toInSql(baseQueryObject.getConditionMap().get("lastv").toString())) + " and" : "where") + SPACE + "1=1 "
                + lcstatusSql + namesql + codesql
        );
        IPage<BaseModel> objectDataGrid = new Page<>();
        IPage<BaseModelVO> objectDataGrid = new Page<>();
        objectDataGrid.setPages(baseQueryObject.getPage());
        objectDataGrid.setCurrent(baseQueryObject.getPage());
        objectDataGrid.setRecords(baseModels);
        objectDataGrid.setRecords(BaseMdodelWrapper.build().listVO(baseModels));
        objectDataGrid.setSize(baseQueryObject.getLimit());
        objectDataGrid.setTotal(total);
        return objectDataGrid;
@@ -3818,7 +3998,6 @@
        treeWrapperOptions.setParentOid(queryObject.getParentOid());
        return revisionModelUtil.doList2Trees(codeClassifies, treeWrapperOptions, null);
    }
    @Override
    public boolean checkUnAttrUnEdit(String attrName) {