Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmEngineServiceImpl.java
@@ -1,5 +1,6 @@
package com.vci.ubcs.code.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -56,8 +57,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springblade.core.cache.utils.CacheUtil;
import org.springblade.core.launch.constant.AppConstant;
import org.springblade.core.log.exception.ServiceException;
import com.vci.ubcs.core.log.exception.ServiceException;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.DateUtil;
@@ -365,7 +365,10 @@
        // 回收需要业务数据删除
        if (CodeDefaultLC.TASK_BACK.getValue().equals(baseModelDTO.getLcStatus())) {
            R<List<BtmTypeVO>> listR = btmTypeClient.selectByIdCollection(Collections.singletonList(baseModelDTO.getBtmname()));
            commonsMapper.deleteByTaleAndOid(listR.getData().get(0).getTableName(), VciBaseUtil.toInSql(baseModelDTO.getOid()));
         if (!listR.isSuccess() || listR.getData().size() == 0) {
            throw new VciBaseException("传入业务类型未查询到相应表单,请检查!");
         }
         commonsMapper.deleteByTaleAndOid(listR.getData().get(0).getTableName(), VciBaseUtil.toInSql(baseModelDTO.getOid()));
        } else {
            for (BaseModel baseModel : baseModels) {
                baseModel.setLcStatus(baseModelDTO.getLcStatus());
@@ -646,6 +649,9 @@
//         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()));
//            String referTable = VciBaseUtil.getTableName(referVO.getReferType());
         if (!listR.isSuccess() || listR.getData().size() == 0) {
            throw new VciBaseException("传入业务类型未查询到相应表单,请检查!");
         }
            final String[] sql = {"select count(*) from " + listR.getData().get(0).getTableName() + " t where 1 = 1 "};
            conditionMap.forEach((key, value) -> {
                sql[0] += " and " + key + " = " + value;
@@ -826,7 +832,7 @@
//         cbo.setCodeclsfpath(fullPath);
            cbo.setTs(new Date());
            if (!edit && StringUtils.isBlank(orderDTO.getLcStatus())) {
                //先写固定,后面生命周期好了在编写
                //TODO 先写固定,后面生命周期好了在编写
                if (StringUtils.isNotBlank(cbo.getLctid())) {
//               OsLifeCycleVO lifeCycleVO = lifeCycleService.getLifeCycleById(cbo.getLctid());
//               if (lifeCycleVO != null) {
@@ -1221,7 +1227,8 @@
            fieldVO.setTemplet(attrVO.getTableDisplayJs());
        }
        if (StringUtils.isBlank(fieldVO.getTemplet()) && VciFieldTypeEnum.VTBoolean.name().equalsIgnoreCase(attrVO.getAttributeDataType())) {
            fieldVO.setTemplet("function(d){return $webUtil.formateBoolean(d." + fieldVO.getField() + ");}");
            fieldVO.setTemplet("function(row,column){return row[column.property]=='true' || row[column.property]=='1'?'是':'否'}");
//            fieldVO.setTemplet("function(d){return $webUtil.formateBoolean(d." + fieldVO.getField() + ");}");
        }
        fieldVO.setOptionJsMap(eventJsMap);
        fieldVO.setStyle(attrVO.getTableDisplayStyle());
@@ -1580,7 +1587,7 @@
        List<CodeClassifyTemplateAttrVO> referAttrVOs = templateVO.getAttributes().stream().filter(
                s -> StringUtils.isNotBlank(s.getReferBtmId()) || StringUtils.isNotBlank(s.getReferConfig())
        ).collect(Collectors.toList());
        Map<String/**参照的属性**/, String/**实际的字段**/> referFieldMap = new HashMap<>();
        Map<String/**参照的属性**/, String/**实际的字段**/> referFieldMap = new ConcurrentHashMap<>();
        if (!CollectionUtils.isEmpty(referAttrVOs)) {
            referAttrVOs.parallelStream().forEach(attrVO -> {
                UIFormReferVO referVO = null;
@@ -1595,6 +1602,9 @@
                //使用传入的业务类型查询表
                R<List<BtmTypeVO>> listR = btmTypeClient.selectByIdCollection(Collections.singletonList(referVO.getReferType()));
//            String referTable = VciBaseUtil.getTableName(referVO.getReferType());
            if (!listR.isSuccess() || listR.getData().size() == 0) {
               throw new VciBaseException("传入业务类型未查询到相应表单,请检查!");
            }
                String referTable = listR.getData().get(0).getTableName();
//            String referTable = "pl_code_classify";
                String referTableNick = attrVO.getId() + "0";
@@ -1613,11 +1623,7 @@
            });
        }
        R<BtmTypeVO> allAttributeByBtmId = btmTypeClient.getDefaultAttrByBtmId(btmType);
//      Optional.ofNullable(allAttributeByBtmId.getData()).orElseGet(allAttributeByBtmId.getData().getAttributes()).stream().forEach(attrId -> {
//         if (!selectFieldList.contains(attrId.getOid()) && !"secretgrade".equalsIgnoreCase(attrId.getOid())) {
//            selectFieldList.add(attrId.getOid());
//         }
//      });
        if (allAttributeByBtmId.getData() != null) {
            for (BtmTypeAttributeVO attribute : allAttributeByBtmId.getData().getAttributes()) {
                if (!selectFieldList.contains(attribute.getId()) && !"secretgrade".equalsIgnoreCase(attribute.getId())) {
@@ -1695,6 +1701,9 @@
        }
//      String tableName = VciBaseUtil.getTableName(btmType);
        R<List<BtmTypeVO>> listR = btmTypeClient.selectByIdCollection(Collections.singletonList(btmType));
      if (!listR.isSuccess() || listR.getData().size() == 0) {
         throw new VciBaseException("传入业务类型未查询到相应表单,请检查!");
      }
//            String referTable = VciBaseUtil.getTableName(referVO.getReferType());
        String tableName = listR.getData().get(0).getTableName();
        String sql = "select " + selectFieldList.stream().map(s -> (s.contains(".") ? s : ("t." + s))).collect(Collectors.joining(","))
@@ -1864,13 +1873,13 @@
                    return (field.contains(".") ? "" : "t.") + field + SPACE + "= '" + getStringValueInWhere(field, value, attrVOMap) + "'" + SPACE;
                }
            } else {
                if (referFieldMap.containsKey(key)) {
                    //说明是参照的,我们参照的查询都认为是字符串,如果是时间格式的查询肯定有问题,
                    String selectKey = referFieldMap.get(key);
                    return getSqlByValue(selectKey, value, null, btmType);
                } else {
//                if (referFieldMap.containsKey(key)) {
//                    //说明是参照的,我们参照的查询都认为是字符串,如果是时间格式的查询肯定有问题,
//                    String selectKey = referFieldMap.get(key);
//                    return getSqlByValue(selectKey, value, null, btmType);
//                } else {
                    return getSqlByValue(key, value, attrVOMap, btmType);
                }
//                }
            }
        }
        return "";
@@ -1924,7 +1933,7 @@
            }
            if (field.contains(".") && attrVOMap != null && attrVOMap.containsKey(field.split("\\.")[0].toLowerCase(Locale.ROOT))) {
                //是参照
                return value;
            return "'" + value + "'";
            } else {
                return value;
            }
@@ -1948,13 +1957,13 @@
                        || VciFieldTypeEnum.VTInteger.equals(fieldTypeEnum)) {
                    return value;
                } else {
                    return value;
               return "'" + value + "'";
                }
            } else {
                if ((value.startsWith("(") && value.endsWith(")")) || (value.startsWith("'") && value.endsWith("'"))) {
                    return value;
                }
                return value;
            return "'" + value + "'";
            }
        }
@@ -2233,9 +2242,9 @@
//      baseMapper.deleteBatchIds(cboList);
        //使用传入的业务类型查询表
        R<List<BtmTypeVO>> listR = btmTypeClient.selectByIdCollection(Collections.singletonList(classifyFullInfo.getCurrentClassifyVO().getBtmtypeid()));
        if (listR.getData().size() == 0) {
            throw new VciBaseException("传入业务类型未查询到相应表单,请检查!");
        }
      if (!listR.isSuccess() || listR.getData().size() == 0) {
         throw new VciBaseException("传入业务类型未查询到相应表单,请检查!");
      }
        commonsMapper.deleteByTaleAndOid(listR.getData().get(0).getTableName(),
                "'" + (StringUtils.join(cboList.stream().map(BaseModel::getOid).collect(Collectors.toSet()), "','")) + "'");
        //      );
@@ -2439,28 +2448,27 @@
     */
    @Override
    public R markDataPassing(String oid, String btmName, Boolean pass) {
        VciBaseUtil.alertNotNull(oid, "业务数据主键", btmName, "业务类型", pass, "标记类型");
        boolean flag = false;
        try {
//         QueryWrapper<CodeWupinEntity> wrapper = new QueryWrapper<>();
//         wrapper.eq("oid",oid);
            CodeWupin data = baseMapper.selectById(oid);
            //         ClientBusinessObjectOperation operation = new ClientBusinessObjectOperation();
//         ClientBusinessObject data = operation.readBusinessObjectById(oid, btmName);
            if (data == null || StringUtils.isBlank(data.getOid())) {
                return R.fail(DATA_OID_NOT_EXIST);
            }
            data.setPassing(String.valueOf(pass));
            flag = SqlHelper.retBool(baseMapper.updateById(data));
//         flag = operation.updateBuinessObject(data);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (flag) {
            return R.success("标记成功!");
        } else {
            return R.fail("标记失败!");
        }
      VciBaseUtil.alertNotNull(oid, "业务数据主键", btmName, "业务类型", pass, "标记类型");
      boolean flag = true;
      try {
         List<BaseModel> datas = selectByTypeAndOid(btmName, oid);
         if (datas.size() == 0) {
            return R.fail(DATA_OID_NOT_EXIST);
         }
         datas.stream().forEach(data->data.getData().put("PASSING",String.valueOf(pass)));
         R r = updateBatchByBaseModel(btmName, datas);
         if(!r.isSuccess()){
            flag = false;
         }
      } catch (Exception e) {
         flag = false;
         e.printStackTrace();
      }
      if (flag) {
         return R.success("标记成功!");
      } else {
         return R.fail("标记失败!");
      }
    }
    /**
@@ -2738,7 +2746,7 @@
            executionId = executionId.substring(0, executionId.lastIndexOf("."));
        }
        String sql = "select wm_concat(distinct (t.codetempattrOidArr)) codetempattroidarr\n" +
                "from pl_code_wupin t\n" +
                "from pl_code_clsflowtemp t\n" +
                "join PLFLOWINSTANCE plfi on t.ID = plfi.PLTEMPLATEPUID\n" +
                "where plfi.PLEXECUTIONID = '" + executionId + "' and t.CLASSIFYTEMPLATEOID = '" + templateOid + "' and t.CODEPROCESSUSE = '" + processUse + "'";
//      List<ClientBusinessObject> tempAttrOidArr = boService.queryByOnlySql(sql);
@@ -2746,7 +2754,7 @@
        if (CollectionUtils.isEmpty(tempAttrOidArr) || StringUtils.isBlank((CharSequence) tempAttrOidArr.get(0).get("codetempattroidarr"))) {
            return new ArrayList<>();
        }
        return VciBaseUtil.str2List(tempAttrOidArr.get(0).get("codetempattroidarr").toString());
        return VciBaseUtil.str2List(tempAttrOidArr.get(0).get("CODETEMPATTROIDARR").toString());
    }
    /**
@@ -2771,39 +2779,23 @@
            throw new VciBaseException("业务数据主键不能为空");
        }
        List<String> oidList = VciBaseUtil.str2List(conditionMap.get("oid"));
        Map<String, String> oidMap = new HashMap<>();
        QueryWrapper<CodeWupin> wrapper = new QueryWrapper();
        if (conditionMap.get("oid").contains(",")) {
//         oidMap.put("oid", QueryOptionConstant.IN +"("+ VciBaseUtil.toInSql(oidList.toArray(new String[0])) + ")");
            wrapper.in("oid", oidList);
        } else {
//         oidMap.put("oid", conditionMap.get("oid"));
            wrapper.in("oid", conditionMap.get("oid"));
        }
        if (CollectionUtils.isEmpty(oidMap)) {
            throw new VciBaseException("业务数据主键不能为空");
        }
//      List<ClientBusinessObject> cbos = boService.queryCBO(btmType, oidMap);
        List<CodeWupin> cbos = baseMapper.selectList(wrapper);
        List<BaseModel> cbos = selectByTypeAndOid(btmType,conditionMap.get("oid"));
        if (CollectionUtils.isEmpty(cbos)) {
            throw new VciBaseException("未找到业务数据");
        }
        CodeWupin cbo = cbos.get(0);
        String templateOid = cbo.getCodetemplateoid();
//      Map<String, String> templateOidMap = new HashMap<>();
//      templateOidMap.put("oid", templateOid);
      BaseModel cbo = cbos.get(0);
        String templateOid = cbo.getData().get("CODETEMPLATEOID");
        QueryWrapper<CodeClassifyTemplate> codeClassifyTemplateWrapper = new QueryWrapper<>();
        codeClassifyTemplateWrapper.eq("oid", templateOid);
        List<CodeClassifyTemplate> templateDOList = templateService.list(codeClassifyTemplateWrapper);
//      List<CodeClassifyTemplate> templateDOList = boService.queryObject(CodeClassifyTemplate.class, templateOidMap);
        QueryWrapper<CodeClassifyTemplateAttr> codeClassifyTemplateAttrWrapper = new QueryWrapper<>();
      QueryWrapper<CodeClassifyTemplateAttr> codeClassifyTemplateAttrWrapper = new QueryWrapper<>();
        codeClassifyTemplateAttrWrapper.eq("CLASSIFYTEMPLATEOID", templateOid);
//      templateOidMap.clear();
//      templateOidMap.put("CLASSIFYTEMPLATEOID",templateOid);
        List<CodeClassifyTemplateAttr> attrDOList = codeClassifyTemplateAttrService.list(codeClassifyTemplateAttrWrapper);
//         boService.queryObject(CodeClassifyTemplateAttr.class, templateOidMap);
        if (CollectionUtils.isEmpty(templateDOList)) {
            logger.error("找不到业务数据关联的模板,模板主键:" + templateOid);
            throw new VciBaseException("找不到业务数据关联的模板");
@@ -3187,9 +3179,9 @@
    public Integer insertBatchByType(String btmType, List<BaseModel> baseModels) {
        //使用传入的业务类型查询表
        R<List<BtmTypeVO>> listR = btmTypeClient.selectByIdCollection(Collections.singletonList(btmType));
        if (listR.getData().size() == 0) {
            throw new VciBaseException("传入业务类型未查询到相应表单,请检查!");
        }
      if (!listR.isSuccess() || listR.getData().size() == 0) {
         throw new VciBaseException("传入业务类型未查询到相应表单,请检查!");
      }
        //将bean转为map,mybatis统一处理
        List<Map<String, String>> maps = new ArrayList<>();
        baseModels.stream().forEach(model -> {
@@ -3214,9 +3206,9 @@
        //使用传入的业务类型查询表
        R<List<BtmTypeVO>> listR = btmTypeClient.selectByIdCollection(Collections.singletonList(btmType));
        if (listR.getData().size() == 0) {
            throw new VciBaseException("传入业务类型未查询到相应表单,请检查!");
        }
      if (!listR.isSuccess() || listR.getData().size() == 0) {
         throw new VciBaseException("传入业务类型未查询到相应表单,请检查!");
      }
        //查询数据
        List<Map> maps = commonsMapper.selectBySql("select * from " + listR.getData().get(0).getTableName() + " where oid in ("
                + VciBaseUtil.toInSql(oids.toString()) + ")");
@@ -3272,7 +3264,10 @@
     */
    public BaseModel createBaseModel(String boName) {
        R<List<BtmTypeVO>> listR = btmTypeClient.selectByIdCollection(Collections.singletonList(boName));
        String userName = AuthUtil.getUser().getUserName();
      if (!listR.isSuccess() || listR.getData().size() == 0) {
         throw new VciBaseException("传入业务类型未查询到相应表单,请检查!");
      }
        String userName = String.valueOf(AuthUtil.getUser().getUserId());
        BaseModel bo = new BaseModel();
//      bo.setOid(VciBaseUtil.getPk());
//      bo.setRevisionid(VciBaseUtil.getPk());
@@ -3339,9 +3334,9 @@
    public R updateBatchByBaseModel(String btmType, List<BaseModel> baseModels) {
        //使用传入的业务类型查询表
        R<List<BtmTypeVO>> listR = btmTypeClient.selectByIdCollection(Collections.singletonList(btmType));
        if (listR.getData().size() == 0) {
            throw new VciBaseException("传入业务类型未查询到相应表单,请检查!");
        }
      if (!listR.isSuccess() || listR.getData().size() == 0) {
         throw new VciBaseException("传入业务类型未查询到相应表单,请检查!");
      }
        //将bean转为map,mybatis统一处理
        List<Map<String, String>> maps = new ArrayList<>();
@@ -3369,8 +3364,8 @@
     * @return 列表数据
     */
    @Override
    public IPage<BaseModel> referDataGrid(UIFormReferVO referConfigVO, BaseQueryObject baseQueryObject) {
//      checkReferConfig(referConfigVO);
    public IPage<BaseModel> referDataGrid(UIFormReferVO referConfigVO, BaseQueryObject baseQueryObject) throws VciBaseException{
      //checkReferConfig(referConfigVO);
        //使用业务类型查询
        R<BtmTypeVO> allAttributeByBtmId = btmTypeClient.getAllAttributeByBtmId(referConfigVO.getReferType());
        BtmTypeVO btmTypeVO = allAttributeByBtmId.getData();
@@ -3390,10 +3385,10 @@
        R<List<BtmTypeVO>> listR = btmTypeClient.selectByIdCollection(Collections.singletonList(referConfigVO.getReferType()));
        if (listR.getCode() != 200) {
            throw new ServiceException("业务类型feign接口调用错误");
            throw new ServiceException(Func.isNotBlank(listR.getMsg()) ? listR.getMsg():"业务类型feign接口调用错误!");
        }
        if (listR.getData().size() == 0) {
            throw new VciBaseException("传入业务类型未查询到相应表单,请检查!");
        if (listR.getData().isEmpty()) {
            throw new VciBaseException(Func.isNotBlank(listR.getMsg()) ? listR.getMsg():"传入业务类型未查询到相应表单,请检查!");
        }
        String namesql = "";
        if (StringUtils.isNotBlank(baseQueryObject.getConditionMap().get("name"))) {
@@ -3411,15 +3406,15 @@
        String lcstatusSql = "";
        if (StringUtils.isNotBlank(baseQueryObject.getConditionMap().get("lcstatus"))) {
            lcstatusSql = "and lcstatus =" + VciBaseUtil.toInSql(baseQueryObject.getConditionMap().get("lcstatus"));
            lcstatusSql = "lcstatus =" + VciBaseUtil.toInSql(baseQueryObject.getConditionMap().get("lcstatus"));
        }
        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()
        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 lastv =" + VciBaseUtil.toInSql(baseQueryObject.getConditionMap().get("lastv").toString())) + " and":" where") + SPACE
                + lcstatusSql + namesql + codesql + ") t where rownum <=" + num1 + ") where rn >=" + num2
        );
        List<BaseModel> baseModels = new ArrayList<>();
@@ -3461,12 +3456,11 @@
        } catch (Exception e) {
            throw new VciBaseException("查询失败:" + e.getMessage());
        }
        int total = commonsMapper.queryCountBySql("select count(*) from " + listR.getData().get(0).getTableName()
        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 lastv = " + VciBaseUtil.toInSql(baseQueryObject.getConditionMap().get("lastv").toString())) + " and":" where") + SPACE
                + lcstatusSql + namesql + codesql
        );
      IPage<BaseModel> objectDataGrid = new Page<>();
        objectDataGrid.setPages(baseQueryObject.getPage());
      objectDataGrid.setCurrent(baseQueryObject.getPage());
@@ -3601,7 +3595,10 @@
        toBo.setVersionRule(fromBo.getVersionRule());
//      RevisionValueObject rvObj = this.getNextRevision(fromBo.getBtmName(), fromBo.getNameoid(), item.revRuleName, item.revInput, revisionVal);
        R<List<BtmTypeVO>> listR = btmTypeClient.selectByIdCollection(Collections.singletonList(fromBo.getBtmname()));
        Map<String, Object> nextRevision = commonsMapper.getNextRevision(listR.getData().get(0).getTableName(), fromBo.getNameOid());
      if (!listR.isSuccess() || listR.getData().size() == 0) {
         throw new VciBaseException("传入业务类型未查询到相应表单,请检查!");
      }
      Map<String, Object> nextRevision = commonsMapper.getNextRevision(listR.getData().get(0).getTableName(), fromBo.getNameOid());
        toBo.setRevisionSeq(Integer.parseInt(nextRevision.get("REVISIONSEQ").toString()));
        toBo.setRevisionValue(nextRevision.get("REVISIONVAL").toString());
//      VersionValueObject versionObj = this.getVersionValue(item.verRuleName);