Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmEngineServiceImpl.java
@@ -38,6 +38,7 @@
import com.vci.ubcs.starter.util.UBCSSqlKeyword;
import com.vci.ubcs.starter.web.constant.QueryOptionConstant;
import com.vci.ubcs.starter.web.constant.RegExpConstant;
import com.vci.ubcs.starter.web.constant.VciSystemVarConstants;
import com.vci.ubcs.starter.web.enumpck.BooleanEnum;
import com.vci.ubcs.starter.web.enumpck.UserSecretEnum;
import com.vci.ubcs.starter.web.enumpck.VciFieldTypeEnum;
@@ -66,6 +67,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.beans.BeanInfo;
import java.beans.Introspector;
@@ -390,6 +392,7 @@
    public String addSaveCode(CodeOrderDTO orderDTO) throws Exception {
        VciBaseUtil.alertNotNull(orderDTO, "编码申请相关的属性和码段的内容都为空", orderDTO.getCodeClassifyOid(), "主题库分类的主键",
                orderDTO.getTemplateOid(), "模板的主键", orderDTO.getCodeRuleOid(), "编码规则的主键");
      VciSystemVarConstants.getSystemVarValueMap();
        CodeClassifyFullInfoBO classifyFullInfo = classifyService.getClassifyFullInfo(orderDTO.getCodeClassifyOid());
        CodeClassifyTemplateVO templateVO = templateService.getObjectHasAttrByOid(orderDTO.getTemplateOid());
        CodeRuleVO ruleVO = ruleService.getObjectHasSecByOid(orderDTO.getCodeRuleOid());
@@ -411,10 +414,15 @@
        switchDateAttrOnOrder(templateVO, orderDTO);
        //9.生成编码的信息
//      ClientBusinessObject cbo = boService.createCBOByBtmName(classifyFullInfo.getTopClassifyVO().getBtmtypeid());
        BaseModel cbo = createCBOByBtmName(classifyFullInfo.getTopClassifyVO().getBtmtypeid());
        BaseModel cbo = createCBOByBtmName(classifyFullInfo.getTopClassifyVO().getBtmTypeId());
//      //默认的属性都不用从前端拷贝
//      //设置编码需要的默认属性的内容
        copyValueToCBO(classifyFullInfo, cbo, orderDTO, templateVO, false);
      cbo.setOid(VciBaseUtil.getPk());
      cbo.setCreateTime(new Date());
      cbo.setLastModifyTime(new Date());
      cbo.setCreator(AuthUtil.getUser().getUserName());
      cbo.setLastModifier(AuthUtil.getUser().getUserName());
//      //TODO:因为默认的属性都不拷贝,目前集团码叫name,并没有从DTO拷贝到cbo里。增加一个单独处理,以后再看要不要调整
        cbo.setName(orderDTO.getName() == null ? "" : orderDTO.getName());
//      //end -- modify by lihang @20220407
@@ -644,7 +652,7 @@
        if (!CollectionUtils.isEmpty(conditionMap)) {
//         final String[] sql = {"select count(*) from " + VciBaseUtil.getTableName(classifyFullInfo.getTopClassifyVO().getBtmtypeid()) + " t where 1 = 1 "};
            R<List<BtmTypeVO>> listR = btmTypeClient.selectByIdCollection(Collections.singletonList(classifyFullInfo.getTopClassifyVO().getBtmtypeid()));
            R<List<BtmTypeVO>> listR = btmTypeClient.selectByIdCollection(Collections.singletonList(classifyFullInfo.getTopClassifyVO().getBtmTypeId()));
//            String referTable = VciBaseUtil.getTableName(referVO.getReferType());
            if (!listR.isSuccess() || listR.getData().size() == 0) {
                throw new VciBaseException("传入业务类型未查询到相应表单,请检查!");
@@ -798,35 +806,27 @@
//      BeanUtils.
//      BeanUtils.copyProperties(orderDTO.getData(),cbo);
//      cbo.setMaterialtype(Short.valueOf("1001"));
//      orderDTO.getData().forEach((key, value) -> {
//         if (!edit || (!checkUnAttrUnEdit(key) &&
//            !VciQueryWrapperForDO.LC_STATUS_FIELD.equalsIgnoreCase(key))) {
//            try {
//               cbo.setAttributeValue(key, value);
//            } catch (Exception e) {
//               logger.error("设置属性的值错误", e);
//            }
//         }
//      });
      orderDTO.getData().forEach((key, value) -> {
         if (!edit || (!checkUnAttrUnEdit(key) &&
            !VciQueryWrapperForDO.LC_STATUS_FIELD.equalsIgnoreCase(key))) {
            try {
               cbo.getData().put(cbo.getData().containsKey(key.toUpperCase())?key.toUpperCase():key, value);
            } catch (Exception e) {
               logger.error("设置属性的值错误", e);
            }
         }
      });
//      BeanMap beanMap = BeanMap.create(cbo);
//      beanMap.putAll(orderDTO.getData());
        try {
            BeanUtilForVCI.copyPropertiesIgnoreNull(BeanUtilForVCI.convertMap(BaseModel.class, orderDTO.getData()), cbo);
            Map<String, String> data = new HashMap<>();
            data.put(CODE_CLASSIFY_OID_FIELD, classifyFullInfo.getCurrentClassifyVO().getOid());
            data.put(CODE_TEMPLATE_OID_FIELD, templateVO.getOid());
            data.put(CODE_FULL_PATH_FILED, fullPath);
            cbo.setData(data);
            cbo.setOid(VciBaseUtil.getPk());
            cbo.setCreateTime(new Date());
         Map<String, String> data = new HashMap<>();
            data.put(cbo.getData().containsKey(CODE_CLASSIFY_OID_FIELD.toUpperCase())?CODE_CLASSIFY_OID_FIELD.toUpperCase():CODE_CLASSIFY_OID_FIELD, classifyFullInfo.getCurrentClassifyVO().getOid());
            data.put(cbo.getData().containsKey(CODE_TEMPLATE_OID_FIELD.toUpperCase())?CODE_TEMPLATE_OID_FIELD.toUpperCase():CODE_TEMPLATE_OID_FIELD, templateVO.getOid());
            data.put(cbo.getData().containsKey(CODE_FULL_PATH_FILED.toUpperCase())?CODE_FULL_PATH_FILED.toUpperCase():CODE_FULL_PATH_FILED, fullPath);
            cbo.getData().putAll(data);
            cbo.setLastModifyTime(new Date());
            cbo.setCreator(AuthUtil.getUser().getUserName());
            cbo.setLastModifier(AuthUtil.getUser().getUserName());
//         cbo.setCodeclsfid(classifyFullInfo.getCurrentClassifyVO().getOid());
//         cbo.setTemplateOid(templateVO.getOid());
//         cbo.setCodeclsfpath(fullPath);
            cbo.setTs(new Date());
            if (!edit && StringUtils.isBlank(orderDTO.getLcStatus())) {
                //TODO 先写固定,后面生命周期好了在编写
@@ -1277,7 +1277,7 @@
            conditionMap.putAll(andConditionMap);
            PageHelper pageHelper = new PageHelper(-1);
            pageHelper.addDefaultDesc("id");
            return queryGrid(fullInfoBO.getTopClassifyVO().getBtmtypeid(), templateVO, conditionMap, pageHelper);
            return queryGrid(fullInfoBO.getTopClassifyVO().getBtmTypeId(), templateVO, conditionMap, pageHelper);
        }
        return new DataGrid<>();
    }
@@ -1298,11 +1298,11 @@
            //说明已经存在
            return resembleRuleService.getObjectByOid(currentClassifyVO.getCodeResembleRuleOid());
        }
        if (StringUtils.isBlank(currentClassifyVO.getParentcodeclassifyoid())) {
        if (StringUtils.isBlank(currentClassifyVO.getParentCodeClassifyOid())) {
            return null;
        }
        Map<String, CodeClassifyVO> classifyVOMap = fullInfoBO.getParentClassifyVOs().stream().collect(Collectors.toMap(s -> s.getOid(), t -> t));
        return getUseResembleRule(fullInfoBO, classifyVOMap.getOrDefault(currentClassifyVO.getParentcodeclassifyoid(), null));
        return getUseResembleRule(fullInfoBO, classifyVOMap.getOrDefault(currentClassifyVO.getParentCodeClassifyOid(), null));
    }
    /**
@@ -2102,22 +2102,15 @@
//      CodeClassifyFullInfoBO classifyFullInfo = classifyService.getClassifyFullInfo(orderDTO.getCodeClassifyOid());
        CodeClassifyFullInfoBO classifyFullInfo = classifyService.getClassifyFullInfo(orderDTO.getCodeClassifyOid());
        //找业务类型,然后使用主键去获取数据库里的数据
        List<BaseModel> cbos = selectByTypeAndOid(classifyFullInfo.getTopClassifyVO().getBtmtypeid(), orderDTO.getOid());
        List<BaseModel> cbos = selectByTypeAndOid(classifyFullInfo.getTopClassifyVO().getBtmTypeId(), orderDTO.getOid());
        if (CollectionUtils.isEmpty(cbos)) {
            throw new VciBaseException(DATA_OID_NOT_EXIST);
        }
//      QueryWrapper<CodeWupin> btmWrapper = new QueryWrapper<>();
//      btmWrapper.eq("OID",orderDTO.getOid());
//      CodeWupin cbo = codeWupinMapper.selectOne(btmWrapper);
        BaseModel cbo = cbos.get(0);
//      CodeClstemplateVO templateVO = templateService.getObjectHasAttrByOid(orderDTO.getTemplateOid());
//      CodeRuleVO ruleVO = ruleService.getObjectHasSecByOid(orderDTO.getCodeRuleOid());
        if (cbo != null) {
        if (cbo == null) {
            throw new VciBaseException(DATA_OID_NOT_EXIST);
        }
//      ClientBusinessObject cbo = cbos.get(0);
        if (!cbo.getTs().toString().contains(VciDateUtil.date2Str(orderDTO.getTs(), VciDateUtil.DateTimeFormat))) {
            throw new VciBaseException("数据不是最新的,可能他人已经修改,请刷新后再试");
        }
@@ -2127,9 +2120,16 @@
        //注意模板不能使用数据存储的时候的模板,因为可能会变化
        //1. 判断必输项
      String codeClassifyOid=cbo.getData().get(CODE_CLASSIFY_OID_FIELD.toUpperCase());
      orderDTO.setCodeClassifyOid(codeClassifyOid);
//      CodeClassifyFullInfoBO classifyFullInfo = classifyService.getClassifyFullInfo(orderDTO.getCodeClassifyOid());
//      CodeClassifyTemplateVO templateVO= this.getUsedTemplateByClassifyOid(orderDTO.getCodeClassifyOid());
        CodeClassifyTemplateVO templateVO = templateService.getObjectHasAttrByOid(orderDTO.getTemplateOid());
        checkRequiredAttrOnOrder(templateVO, orderDTO);
      orderDTO.setTemplateOid(templateVO.getOid());
      //1. 判断必输项
      checkRequiredAttrOnOrder(templateVO, orderDTO);
        //2.先注入,再组合,最后校验
        switchClassifyLevelOnOrder(templateVO, classifyFullInfo, orderDTO);
        //3.处理组合规则。组合规则不能使用编码的属性,因为编码的生成可能是需要属性的
@@ -2146,46 +2146,18 @@
        copyValueToCBO(classifyFullInfo, cbo, orderDTO, templateVO, true);
        //企业码和集团码的不修改
        cbo.setDescription(orderDTO.getDescription());
        cbo.setName(orderDTO.getName());
//        cbo.setName(orderDTO.getName());
        try {
            cbo.setDescription(StringUtils.isBlank(orderDTO.getDescription()) ? "" : orderDTO.getDescription());
            cbo.setName(orderDTO.getName());
////         cbo.setAttributeValueWithNoCheck("description", orderDTO.getDescription());
//         cbo.setAttributeValue("name", orderDTO.getName());
        } catch (Exception e) {
            e.printStackTrace();
        }
//      cbo.getData().putAll(orderDTO.getData());
        cbo.setLastModifyTime(new Date());
        cbo.setLastModifier(String.valueOf(AuthUtil.getUser().getUserId()));
        updateBatchByBaseModel(classifyFullInfo.getTopClassifyVO().getBtmtypeid(), Collections.singletonList(cbo));
//      codeWupinMapper.updateById(cbo);
//
//      List<CodeWupinEntity> cboList = new ArrayList<>();
//
//      //备注
//      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 (CodeWupinEntity wupinEntity : cboList) {
//         charList.add(wupinEntity.getId());
//      }
//      batchSaveSelectChar(templateVO, charList);
//      return codeList.size() > 0 ? codeList.get(0) : "";
        //修改的时候,编码是不变的
//      BatchCBO batchCBO = new BatchCBO();
//      batchCBO.getUpdateCbos().add(cbo);
//      List<ClientBusinessObject> cboList = new ArrayList<>();
//      cboList.add(cbo);
//      boService.persistenceBatch(batchCBO);
        updateBatchByBaseModel(classifyFullInfo.getTopClassifyVO().getBtmTypeId(), Collections.singletonList(cbo));
        batchSaveSelectChar(templateVO, Collections.singletonList(cbo));
//      batchSaveSelectChar(templateVO, Arrays.asList(cbo.getId()));
    }
    /**
@@ -2209,7 +2181,7 @@
        oidCollection.stream().forEach(oids -> {
            Map<String, String> conditionMap = new HashMap<>();
//         conditionMap.put("oid", QueryOptionConstant.IN + "(" + VciBaseUtil.toInSql(oids.toArray(new String[0])) + ")");
            List<BaseModel> cbos = selectByTypeAndOid(classifyFullInfo.getTopClassifyVO().getBtmtypeid(), oids);
            List<BaseModel> cbos = selectByTypeAndOid(classifyFullInfo.getTopClassifyVO().getBtmTypeId(), oids);
//            boService.queryCBO(classifyFullInfo.getTopClassifyVO().getBtmtypeid(), conditionMap);
            cboList.addAll(cbos);
        });
@@ -2235,10 +2207,10 @@
//      batchCBO.getDeleteCbos().addAll(cboList);
//      WebUtil.setPersistence(false);
//      batchCBO.copyFromOther(
        productCodeService.recycleCode(classifyFullInfo.getCurrentClassifyVO().getBtmtypeid(), deleteBatchDTO.getOidList());
        productCodeService.recycleCode(classifyFullInfo.getCurrentClassifyVO().getBtmTypeId(), deleteBatchDTO.getOidList());
//      baseMapper.deleteBatchIds(cboList);
        //使用传入的业务类型查询表
        R<List<BtmTypeVO>> listR = btmTypeClient.selectByIdCollection(Collections.singletonList(classifyFullInfo.getCurrentClassifyVO().getBtmtypeid()));
        R<List<BtmTypeVO>> listR = btmTypeClient.selectByIdCollection(Collections.singletonList(classifyFullInfo.getCurrentClassifyVO().getBtmTypeId()));
        if (!listR.isSuccess() || listR.getData().size() == 0) {
            throw new VciBaseException("传入业务类型未查询到相应表单,请检查!");
        }
@@ -2305,10 +2277,10 @@
        //4. 查询的时候,直接使用codeclsfpath来查询
        CodeClassifyVO topClassifyVO = classifyService.getTopClassifyVO(codeClassifyOid);
        CodeClassifyTemplateVO templateVO = templateService.getObjectHasAttrByOid(templateOid);
        if (topClassifyVO == null || StringUtils.isBlank(topClassifyVO.getBtmtypeid())) {
        if (topClassifyVO == null || StringUtils.isBlank(topClassifyVO.getBtmTypeId())) {
            throw new VciBaseException("当前主题库分类没有顶层分类,或者顶层分类没有设置业务类型");
        }
        String btmTypeId = topClassifyVO.getBtmtypeid();
        String btmTypeId = topClassifyVO.getBtmTypeId();
        if (StringUtils.isBlank(btmTypeId)) {
            return new DataGrid<>("这个分类所属顶层分类没有添加业务类型");
        }
@@ -2375,7 +2347,7 @@
            throw new VciBaseException(DATA_OID_NOT_EXIST);
        }
        List<BaseModel> cboList = selectByTypeAndOid(topClassifyFullInfo.getTopClassifyVO().getBtmtypeid(), VciBaseUtil.array2String(orderDTOMap.keySet().toArray(new String[0])));
        List<BaseModel> cboList = selectByTypeAndOid(topClassifyFullInfo.getTopClassifyVO().getBtmTypeId(), VciBaseUtil.array2String(orderDTOMap.keySet().toArray(new String[0])));
//      cboOidMap.put("oid",QueryOptionConstant.IN + "(" + VciBaseUtil.toInSql(orderDTOMap.keySet().toArray(new String[0])) + ")");
//      List<ClientBusinessObject> cboList = boService.queryCBO(classifyFullInfo.getTopClassifyVO().getBtmtypeid(), cboOidMap);
        if (CollectionUtils.isEmpty(cboList)) {
@@ -2431,7 +2403,7 @@
            batchSaveSelectChar(firstTemplateVO, cboList);
        });
//      boService.persistenceBatch(batchCBO);
        updateBatchByBaseModel(topClassifyFullInfo.getTopClassifyVO().getBtmtypeid(), updateList);
        updateBatchByBaseModel(topClassifyFullInfo.getTopClassifyVO().getBtmTypeId(), updateList);
        return R.success("操作成功!");
    }
@@ -2607,7 +2579,7 @@
    public CodeRuleVO getCodeRuleByClassifyOid(String codeClassifyOid) {
        VciBaseUtil.alertNotNull(codeClassifyOid, "分类的主键");
        CodeClassifyVO classifyVO = classifyService.getObjectByOid(codeClassifyOid);
        String codeRuleOid = classifyVO.getCoderuleoid();
        String codeRuleOid = classifyVO.getCodeRuleOid();
        if (StringUtils.isBlank(codeRuleOid)) {
            //往上找
            CodeClassifyFullInfoBO fullInfo = classifyService.getClassifyFullInfo(codeClassifyOid);
@@ -2627,8 +2599,8 @@
    public CodeRuleVO getCodeRuleByClassifyFullInfo(CodeClassifyFullInfoBO fullInfoBO) {
        //往上找
        String codeRuleOid = "";
        if (StringUtils.isNotBlank(fullInfoBO.getCurrentClassifyVO().getCoderuleoid())) {
            codeRuleOid = fullInfoBO.getCurrentClassifyVO().getCoderuleoid();
        if (StringUtils.isNotBlank(fullInfoBO.getCurrentClassifyVO().getCodeRuleOid())) {
            codeRuleOid = fullInfoBO.getCurrentClassifyVO().getCodeRuleOid();
        } else {
            if (CollectionUtils.isEmpty(fullInfoBO.getParentClassifyVOs())) {
                //说明已经是最高层级,
@@ -2638,8 +2610,8 @@
            //从最高的level开始获取
            for (int i = 0; i < parentClassifyVOList.size(); i++) {
                CodeClassifyVO record = parentClassifyVOList.get(i);
                if (StringUtils.isNotBlank(record.getCoderuleoid())) {
                    codeRuleOid = record.getCoderuleoid();
                if (StringUtils.isNotBlank(record.getCodeRuleOid())) {
                    codeRuleOid = record.getCodeRuleOid();
                    break;
                }
            }
@@ -2662,7 +2634,7 @@
        CodeClassifyTemplateVO templateVO = templateService.getObjectHasAttrByOid(templateOid);
        //为了防止模板上的业务类型与分类上不对应
        CodeClassifyVO topClassifyVO = classifyService.getTopClassifyVO(templateVO.getCodeclassifyoid());
        String btmId = topClassifyVO.getBtmtypeid();
        String btmId = topClassifyVO.getBtmTypeId();
        //查询数据
        Map<String, String> conditionMap = new HashMap<>();
        conditionMap.put("t.oid", oid);
@@ -3104,12 +3076,12 @@
        uiInfoVO.setLeaf(classifyService.countChildrenByClassifyOid(codeClassifyOid) == 0);
        if (StringUtils.isNotBlank(functionId) && !"~".equalsIgnoreCase(functionId)) {
            List<Menu> buttonVOS = iSysClient.getMenuButtonByType(uiInfoVO.getTemplateVO().getBtmTypeId()).getData();
         //         List<SmOperationVO> operationVOS = operationService.listButtonByFunctionId(functionId);
         //         if (operationVOS == null) {
         //            operationVOS = new ArrayList<>();
         //         }
         //         //查询扩展按钮
         //         List<CodeButtonVO> buttonVOS = listButtonInToolbarByClassifyOid(codeClassifyOid);
            //         List<SmOperationVO> operationVOS = operationService.listButtonByFunctionId(functionId);
            //         if (operationVOS == null) {
            //            operationVOS = new ArrayList<>();
            //         }
            //         //查询扩展按钮
            //         List<CodeButtonVO> buttonVOS = listButtonInToolbarByClassifyOid(codeClassifyOid);
            List<SmOperationVO> operationVOS = new ArrayList<>();
            if (!CollectionUtils.isEmpty(buttonVOS)) {
                for (int i = 0; i < buttonVOS.size(); i++) {
@@ -3409,20 +3381,20 @@
        String lcstatusSql = "";
        if (StringUtils.isNotBlank(baseQueryObject.getConditionMap().get("lcstatus"))) {
            lcstatusSql = "lcstatus =" + VciBaseUtil.toInSql(baseQueryObject.getConditionMap().get("lcstatus"));
            lcstatusSql = "and lcstatus =" + VciBaseUtil.toInSql(baseQueryObject.getConditionMap().get("lcstatus"));
        }
        String where = "";
//        String where = "";
        if (StringUtils.isNotBlank(codesql) || StringUtils.isNotBlank(lcstatusSql) || StringUtils.isNotBlank(namesql)) {
             where="where ";
        }
//        if (StringUtils.isNotBlank(codesql) || StringUtils.isNotBlank(lcstatusSql) || StringUtils.isNotBlank(namesql)) {
//            where = "where ";
//        }
        String num1 = baseQueryObject.getPage() * baseQueryObject.getLimit() + "";
        String num2 = ((baseQueryObject.getPage()) - 1) * baseQueryObject.getLimit() + 1 + "";
        List<Map> maps = commonsMapper.selectBySql("select * from ( select rownum rn, t.* from (select * from " + listR.getData().get(0).getTableName() + SPACE
                + (StringUtils.isNotBlank(listR.getData().get(0).getRevisionRuleId()) ? (" where lastr = " + VciBaseUtil.toInSql(baseQueryObject.getConditionMap().get("lastr").toString())
            + " and lastv =" + VciBaseUtil.toInSql(baseQueryObject.getConditionMap().get("lastv").toString())) + " and": where) + SPACE
                + " and lastv =" + VciBaseUtil.toInSql(baseQueryObject.getConditionMap().get("lastv").toString())) + " and" : "where") + SPACE + "1=1 "
                + lcstatusSql + namesql + codesql + ") t where rownum <=" + num1 + ") where rn >=" + num2
        );
        List<BaseModel> baseModels = new ArrayList<>();
@@ -3466,7 +3438,7 @@
        }
        int total = commonsMapper.queryCountBySql("select count(*) from " + listR.getData().get(0).getTableName() + SPACE
                + (StringUtils.isNotBlank(listR.getData().get(0).getRevisionRuleId()) ? (" where lastr = " + VciBaseUtil.toInSql(baseQueryObject.getConditionMap().get("lastr").toString())
                + "and lastv = " + VciBaseUtil.toInSql(baseQueryObject.getConditionMap().get("lastv").toString())) + " and" : where) + SPACE
                + "and lastv = " + VciBaseUtil.toInSql(baseQueryObject.getConditionMap().get("lastv").toString())) + " and" : "where") + SPACE + "1=1 "
                + lcstatusSql + namesql + codesql
        );
        IPage<BaseModel> objectDataGrid = new Page<>();