ludc
2023-06-13 729db9dd93f8884a8f1f0b32a4462708f858ea9b
Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmEngineServiceImpl.java
@@ -8,6 +8,7 @@
import com.vci.ubcs.code.bo.CodeClassifyFullInfoBO;
import com.vci.ubcs.code.bo.CodeTemplateAttrSqlBO;
import com.vci.ubcs.code.constant.FrameWorkDefaultValueConstant;
import com.vci.ubcs.code.constant.MdmBtmTypeConstant;
import com.vci.ubcs.code.dto.CodeDeleteBatchDTO;
import com.vci.ubcs.code.dto.CodeOrderDTO;
import com.vci.ubcs.code.dto.datapush.BaseModelDTO;
@@ -57,6 +58,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
@@ -327,6 +329,7 @@
    *
    * @param baseModelDTO 数据传输对象
    */
   @Transactional
   @Override
   public void changeStatus(BaseModelDTO baseModelDTO) {
      VciBaseUtil.alertNotNull(baseModelDTO, "数据信息", baseModelDTO.getOid(), "主键", baseModelDTO.getBtmname(), "业务类型", baseModelDTO.getLcStatus(), "目标状态");
@@ -337,6 +340,14 @@
      wrapper.eq("BTMNAME",baseModelDTO.getBtmname());
      wrapper.in("OID",oids);
      // TODO 待完善
      //插个点 业务类型完成后需要修改
//      QueryWrapper<BtmTypeVO> wrapper = new QueryWrapper<>();
      List<BaseModel> baseModels = new ArrayList<>();
      baseModels = selectByTypeAndOid(baseModelDTO.getBtmname(), baseModelDTO.getOid());
      if(baseModels.size() == 0){
         throw new VciBaseException("未查询到相关数据。");
      }
      // 待完善
      List<BtmTypeVO> cboList =  null;  // btmTypeClient.selectList(wrapper);
      //还需要修改allCode的生命周期
//      Map<String, String> conditionMap = new HashMap<>();
@@ -349,6 +360,9 @@
//      List<ClientBusinessObject> codeCbos = boService.queryCBO(MdmBtmTypeConstant.CODE_ALL_CODE, conditionMap);
      // 回收需要业务数据删除
      if (CodeDefaultLC.TASK_BACK.getValue().equals(baseModelDTO.getLcStatus())) {
         R<List<BtmTypeVO>> listR = btmTypeClient.selectByIdCollection(Collections.singletonList(baseModelDTO.getBtmname()));
//         String referTable = listR.getData().get(0).getTableName();
         commonsMapper.deleteByTaleAndOid(listR.getData().get(0).getTableName(),VciBaseUtil.toInSql(baseModelDTO.getOid()));
         // BatchCBO batchCBO = new BatchCBO();
         // batchCBO.getDeleteCbos().addAll(cboList);
@@ -357,8 +371,16 @@
         //boService.persistenceBatch(batchCBO);
      } else {
         for (BaseModel baseModel : baseModels) {
            baseModel.setLcStatus(baseModelDTO.getLcStatus());
         }
         updateBatchByBaseModel(baseModelDTO.getBtmname(),baseModels);
         // lifeCycleService.transCboStatus(cboList, baseModelDTO.getLcStatus());
      }
      for (CodeAllCode codeCbo : codeCbos) {
         codeCbo.setLcStatus(baseModelDTO.getLcStatus());
      }
      codeAllCodeService.updateBatchById(codeCbos);
      // lifeCycleService.transCboStatus(codeCbos, baseModelDTO.getLcStatus());
   }
@@ -625,9 +647,10 @@
      //没有限制分类,但是一个模板只可能在一个业务类型里面,所以直接查询这个业务类型即可
      if (!CollectionUtils.isEmpty(conditionMap)) {
         //表需要改
//         final String[] sql = {"select count(*) from " + VciBaseUtil.getTableName(classifyFullInfo.getTopClassifyVO().getBtmtypeid()) + " t where 1 = 1 "};
         final String[] sql = {"select count(*) from pl_code_wupin t where 1 = 1 "};
         R<List<BtmTypeVO>> listR = btmTypeClient.selectByIdCollection(Collections.singletonList(classifyFullInfo.getTopClassifyVO().getBtmtypeid()));
//            String referTable = VciBaseUtil.getTableName(referVO.getReferType());
         final String[] sql = {"select count(*) from "+ listR.getData().get(0).getTableName() +" t where 1 = 1 "};
         conditionMap.forEach((key, value) -> {
            sql[0] += " and " + key + " = " + value;
         });
@@ -1408,31 +1431,45 @@
      DataGrid<Map<String, String>> dataGrid = new DataGrid<>();
      List<Map<String, String>> dataList = new ArrayList<>();
//      if (!CollectionUtils.isEmpty(maps)) {
//         maps.stream().forEach(map -> {
//            Map<String, String> data = new HashMap<>();
//            map.forEach((key, value) -> {
//               data.put(((String) key).toLowerCase(Locale.ROOT), String.valueOf(value));
//            });
//            dataList.add(data);
//         });
//      }
//      dataGrid.setData(dataList);
      if (!CollectionUtils.isEmpty(maps)) {
         wrapperData(maps, templateVO, sqlBO.getSelectFieldList(), false);
         maps.stream().forEach(map -> {
            Map<String, String> data = new HashMap<>();
            for (String s : map.keySet()) {
               data.put(s.toLowerCase(Locale.ROOT), String.valueOf(map.get(s)));
            }
//            map.forEach((key, value) -> {
//               data.put(((String) key).toLowerCase(Locale.ROOT), String.valueOf(value));
//            });
            for (String s : map.keySet()) {
               data.put(((String) s).toLowerCase(Locale.ROOT), String.valueOf(map.get(s)));
            }
            dataList.add(data);
         });
         dataGrid.setData(dataList);
         dataGrid.setTotal(Long.parseLong(commonsMapper.selectBySql(sqlBO.getSqlCount()).get(0).values().toArray()[0].toString()));
         wrapperData(dataList, templateVO, sqlBO.getSelectFieldList(), false);
//         maps.stream().forEach(map -> {
//            Map<String, String> data = new HashMap<>();
////            map.forEach((key, value) -> {
////               data.put(((String) key).toLowerCase(Locale.ROOT), String.valueOf(value));
////            });
//            for (String s : map.keySet()) {
//               data.put(((String) s).toLowerCase(Locale.ROOT), String.valueOf(map.get(s)));
//            }
//            dataList.add(data);
//         });
      }
//      dataGrid.setData(dataList);
//      if (!CollectionUtils.isEmpty(maps)) {
//         wrapperData(maps, templateVO, sqlBO.getSelectFieldList(), false);
//         maps.stream().forEach(map -> {
//            Map<String, String> data = new HashMap<>();
////            map.forEach((key, value) -> {
////               data.put(((String) key).toLowerCase(Locale.ROOT), String.valueOf(value));
////            });
//            for (String s : map.keySet()) {
//               data.put(((String) s).toLowerCase(Locale.ROOT), String.valueOf(map.get(s)));
//            }
//            dataList.add(data);
//         });
      dataGrid.setData(dataList);
      dataGrid.setTotal(Long.parseLong(commonsMapper.selectBySql(sqlBO.getSqlCount()).get(0).values().toArray()[0].toString()));
//      }
      return dataGrid;
   }
@@ -1708,9 +1745,7 @@
         }
         whereSql += " and ( t.secretGrade <= " + userSecret + ") ";
      }
      //要改,表明获取有问题
//      String tableName = VciBaseUtil.getTableName(btmType);
//      String tableName = "pl_code_wupin";
      R<List<BtmTypeVO>> listR = btmTypeClient.selectByIdCollection(Collections.singletonList(btmType));
//            String referTable = VciBaseUtil.getTableName(referVO.getReferType());
      String tableName = listR.getData().get(0).getTableName();
@@ -2158,15 +2193,18 @@
      //pageHelper.addDefaultDesc("createTime");
      pageHelper.addDefaultDesc("id");
      if (!classifyService.checkHasChild(codeClassifyOid)) {
         conditionMap.put(CODE_CLASSIFY_OID_FIELD, codeClassifyOid);
         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)
         conditionMap.put(CODE_CLASSIFY_OID_FIELD, QueryOptionConstant.IN + "(select oid from pl_code_classify where lcstatus='" + FrameWorkDefaultValueConstant.FRAMEWORK_DATA_ENABLED +
            "' start with parentCodeClassifyOid = '" + codeClassifyOid + "' CONNECT BY PRIOR OID = parentCodeClassifyOid )");
         conditionMap.put("t."+CODE_CLASSIFY_OID_FIELD, QueryOptionConstant.IN + "(select oid from "+
            btmTypeClient.selectByIdCollection(Collections.singletonList(MdmBtmTypeConstant.CODE_CLASSIFY))
               .getData().get(0).getTableName() +" where lcstatus='" + FrameWorkDefaultValueConstant
            .FRAMEWORK_DATA_ENABLED + "' start with parentCodeClassifyOid = '" + codeClassifyOid +
            "' CONNECT BY PRIOR OID = parentCodeClassifyOid )");
      }
      conditionMap.put("lastr", "1");
      conditionMap.put("lastv", "1");
      conditionMap.put("t.lastr", "1");
      conditionMap.put("t.lastv", "1");
      return queryGrid(btmTypeId, templateVO, conditionMap, pageHelper);
//        List<String> selectFieldList = templateVO.getAttributes().stream().map(CodeClassifyTemplateAttrVO::getId).collect(Collectors.toList());
//        //参照让平台直接查询就行
@@ -3002,7 +3040,7 @@
    * @return 处理成功数据条数
    */
   @Override
   public Integer insertBatchByType(String btmType, List<BaseModel> baseModels) throws Exception {
   public Integer insertBatchByType(String btmType, List<BaseModel> baseModels) {
      //使用传入的业务类型查询表
      R<List<BtmTypeVO>> listR = btmTypeClient.selectByIdCollection(Collections.singletonList(btmType));
      if(listR.getData().size() == 0){
@@ -3028,7 +3066,7 @@
    * @return 查询出的数据
    */
   @Override
   public List<BaseModel> selectByTypeAndOid(String btmType, String oids) throws IllegalAccessException, NoSuchFieldException, InstantiationException, InvocationTargetException, IntrospectionException, SQLException {
   public List<BaseModel> selectByTypeAndOid(String btmType, String oids)  {
      //使用传入的业务类型查询表
      R<List<BtmTypeVO>> listR = btmTypeClient.selectByIdCollection(Collections.singletonList(btmType));
@@ -3041,38 +3079,42 @@
      List<BaseModel> baseModels = new ArrayList<>();
      //将查询到的数据转换为basemodel,使用的反射方式来进行创建的
      for (Map map : maps) {
         Object obj = BaseModel.class.newInstance();
         BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass());
         PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
         for (PropertyDescriptor property : propertyDescriptors) {
            Method setter = property.getWriteMethod();
            if (setter != null) {
               //oracle的时间为TIMESTAMP的,需要进行转换成data,否则将报错
               if(map.get(property.getName().toUpperCase()) instanceof TIMESTAMP){
                  LocalDateTime localDateTime = ((TIMESTAMP) map.get(property.getName().toUpperCase())).toLocalDateTime();
                  ZoneId zoneId = ZoneId.systemDefault();
                  ZonedDateTime zdt = localDateTime.atZone(zoneId);
                  Date date = Date.from(zdt.toInstant());
                  setter.invoke(obj,date);
                  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());
               }else if(map.get(property.getName().toUpperCase()) != null){
                  setter.invoke(obj, map.get(property.getName().toUpperCase()));
                  map.remove(property.getName().toUpperCase());
      try{
         for (Map map : maps) {
            Object obj = BaseModel.class.newInstance();
            BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass());
            PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
            for (PropertyDescriptor property : propertyDescriptors) {
               Method setter = property.getWriteMethod();
               if (setter != null) {
                  //oracle的时间为TIMESTAMP的,需要进行转换成data,否则将报错
                  if(map.get(property.getName().toUpperCase()) instanceof TIMESTAMP){
                     LocalDateTime localDateTime = ((TIMESTAMP) map.get(property.getName().toUpperCase())).toLocalDateTime();
                     ZoneId zoneId = ZoneId.systemDefault();
                     ZonedDateTime zdt = localDateTime.atZone(zoneId);
                     Date date = Date.from(zdt.toInstant());
                     setter.invoke(obj,date);
                     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());
                  }else if(map.get(property.getName().toUpperCase()) != null){
                     setter.invoke(obj, map.get(property.getName().toUpperCase()));
                     map.remove(property.getName().toUpperCase());
                  }
               }
            }
         }
         for (Object key : map.keySet()) {
            map.put(key,String.valueOf(map.get(key)));
         }
            for (Object key : map.keySet()) {
               map.put(key,String.valueOf(map.get(key)));
            }
         ((BaseModel) obj).setData(map);
         baseModels.add((BaseModel) obj);
            ((BaseModel) obj).setData(map);
            baseModels.add((BaseModel) obj);
         }
      }catch (Exception e){
         throw new VciBaseException("查询失败:" + e.getMessage());
      }
      return baseModels;
   }
@@ -3148,7 +3190,7 @@
    * @return 处理状态
    */
   @Override
   public R updateBatchByBaseModel(String btmType, List<BaseModel> baseModels) throws Exception {
   public R updateBatchByBaseModel(String btmType, List<BaseModel> baseModels) {
      //使用传入的业务类型查询表
      R<List<BtmTypeVO>> listR = btmTypeClient.selectByIdCollection(Collections.singletonList(btmType));
      if(listR.getData().size() == 0){