ludc
2023-09-08 008c8cb7d9f55341374e37310ee399143d33e902
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;
@@ -20,6 +21,7 @@
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 +38,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;
@@ -423,6 +426,9 @@
      cbo.setCreator(String.valueOf(AuthUtil.getUser().getUserId()));
      cbo.setLastModifier(String.valueOf(AuthUtil.getUser().getUserId()));
      cbo.setTenantId(AuthUtil.getTenantId());
      if(StringUtils.isNotBlank(orderDTO.getLcStatus())||StringUtils.isNotBlank(orderDTO.getData().get("lcStatus"))){
         cbo.setLcStatus(StringUtils.isNotBlank(orderDTO.getLcStatus())?orderDTO.getLcStatus():orderDTO.getData().get("lcStatus"));
      }
//      //TODO:因为默认的属性都不拷贝,目前集团码叫name,并没有从DTO拷贝到cbo里。增加一个单独处理,以后再看要不要调整
        cbo.setName(orderDTO.getName() == null ? "" : orderDTO.getName());
//      //end -- modify by lihang @20220407
@@ -550,10 +556,15 @@
        String value = null;
        if (VciQueryWrapperForDO.BASIC_FIELD_MAP.containsKey(attrId)) {
            value = WebUtil.getStringValueFromObject(WebUtil.getValueFromField(WebUtil.getFieldForObject(attrId, orderDTO.getClass()).getName(), orderDTO));
        } else {
           if(StringUtils.isBlank(value)){
            value = orderDTO.getData().getOrDefault(attrId, "");
         }
      } 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;
    }
@@ -659,7 +670,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())) {
                //修改的时候,需要排除自己
@@ -680,10 +695,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());
@@ -758,7 +772,7 @@
        boolean ignoreSpace = trim || trimAll;
        if (StringUtils.isBlank(value)) {
            //为空的时候,不能用QueryOperation.ISNULL,平台不知道啥时候不处理这种了
            conditionMap.put("t." + attrId, "null");
         conditionMap.put("t." + attrId, QueryOptionConstant.ISNULL);
        } else {
            if (keyRuleVO != null) {
                String queryKey = "";
@@ -794,8 +808,12 @@
                queryValue = String.format(temp, "'" + (trim ? value.trim() : value) + "'");
                conditionMap.put(queryKey, queryValue);
            } else {
                //为空的时候不代表不校验,只是不去除相关的信息
                conditionMap.put("t." + attrId, "'" +value+ "'");
            if(StringUtils.isNotBlank(value)) {
               //为空的时候不代表不校验,只是不去除相关的信息
               conditionMap.put("t." + attrId, "'" + value + "'");
            }else{
               conditionMap.put("t." + attrId, QueryOptionConstant.ISNULL);
            }
            }
        }
    }
@@ -935,7 +953,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());
        }
    }
@@ -1313,6 +1331,7 @@
        }
        fieldVO.setOptionJsMap(eventJsMap);
        fieldVO.setStyle(attrVO.getTableDisplayStyle());
        fieldVO.setTableDisplayFlag(attrVO.getTableDisplayFlag());
        //列表里不允许直接编辑
        fieldVO.setDateFormate(attrVO.getCodeDateFormat());
        return fieldVO;
@@ -1355,7 +1374,7 @@
      uiFormReferVO.setTableConfig(uiTableConfigVO);
      // 筛选条件
      HashMap<String, String> whereMap = new HashMap<>();
      if(!codeReferConfig.getCodeSrchCondConfigVOS().isEmpty()){
      if(!CollectionUtils.isEmpty(codeReferConfig.getCodeSrchCondConfigVOS())){
         codeReferConfig.getCodeSrchCondConfigVOS().stream().forEach(srch->{
            whereMap.put(srch.getFilterField()+srch.getFilterType(),srch.getFilterValue());
         });
@@ -2454,10 +2473,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 )");
        }
@@ -2720,12 +2741,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()
      );
      // 只读码段类型
      List<String> readOnlyTypes = Arrays.asList(
         CodeSecTypeEnum.CODE_LEVEL_SEC.getValue(),
         CodeSecTypeEnum.CODE_ATTR_SEC.getValue(),
         CodeSecTypeEnum.CODE_DATE_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.setCodeDateFormatStr(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.setCodeDateFormatStr(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.setCodeDateFormatStr(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;
   }
    /**
     * 使用分类的全部信息获取编码规则
@@ -3451,7 +3562,6 @@
        return baseModels;
    }
    /**
     * 根据业务类型名称创建业务数据源对象
     *
@@ -3568,7 +3678,7 @@
     * @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());
@@ -3649,27 +3759,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) {
@@ -3680,10 +3791,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;
@@ -3808,7 +3919,6 @@
        treeWrapperOptions.setParentOid(queryObject.getParentOid());
        return revisionModelUtil.doList2Trees(codeClassifies, treeWrapperOptions, null);
    }
    @Override
    public boolean checkUnAttrUnEdit(String attrName) {