Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/controller/MdmEngineController.java
@@ -1,6 +1,5 @@
package com.vci.ubcs.code.controller;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.common.utils.StringUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -33,11 +32,9 @@
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.rmi.ServerException;
import java.util.*;
@RestController
//@AllArgsConstructor
@RequestMapping("/mdmEngineController")
@Api(value = "编码数据管理", tags = "编码数据管理")
public class MdmEngineController {
@@ -90,6 +87,71 @@
    * @param response 响应对象
    * @throws IOException 抛出异常
    */
   @GetMapping("/downloadExcelBatchEdit")
   @VciBusinessLog(operateName = "下载批量申请编码的导入模板")
   public void downloadImportExcelBatchEdit(String codeClassifyOid, HttpServletResponse response) throws IOException{
      String excelName = mdmIOService.downloadImportExcelBatchEdit(codeClassifyOid);
      try {
         ControllerUtil.writeFileToResponse(response,excelName);
      } catch (Throwable e) {
         //如果出错,把错误信息写到text
         String msg = LangBaseUtil.getErrorMsg(e);
         if(StringUtils.isBlank(msg)){
            msg = "未知错误";
         }
         ControllerUtil.writeDataToResponse(response,msg.getBytes(StandardCharsets.UTF_8),null);
      }
   }
   /**
    * 导入批量编辑数据
    * @param codeClassifyOid 分类的主键
    * @param classifyAttr 分类路径使用的属性
    * @param file 文件的内容
    */
   @VciBusinessLog(operateName = "导入批量编辑数据")
   @PostMapping("/batchImportEdit")
   public R batchImportEdit(String codeClassifyOid, String classifyAttr,MultipartFile file,HttpServletResponse response) throws Throwable {
      String excelFileName = LocalFileUtil.getDefaultTempFolder() + File.separator + file.getOriginalFilename();
      File file1 = new File(excelFileName);
      try {
         file.transferTo(new File(excelFileName));
         CodeImProtRusultVO codeImProtRusultVO =mdmIOService.batchImportEdit(codeClassifyOid, classifyAttr,file1);
         if(StringUtils.isNotBlank(codeImProtRusultVO.getFilePath())||StringUtils.isNotBlank(codeImProtRusultVO.getRedisUuid())){
            //放到map里
            R result = R.fail("导入失败");
            if(StringUtils.isNotBlank(codeImProtRusultVO.getFilePath())) {
               String filedUUid = ControllerUtil.putErrorFile(codeImProtRusultVO.getFilePath());
               codeImProtRusultVO.setFileOid(filedUUid);
            }
            result.setData(codeImProtRusultVO);
            return result;
         }else {
            return R.success("操作成功!");
         }
      }catch (Throwable e) {
         logger.error("导入错误",e);
         String errorFile = LocalFileUtil.getDefaultTempFolder() + File.separator + "错误.txt";
         LocalFileUtil.writeContentToFile(LangBaseUtil.getErrorMsg(e),errorFile);
         String uuid=ControllerUtil.putErrorFile(errorFile);
         CodeImProtRusultVO codeImProtRusultVO =new CodeImProtRusultVO();
         codeImProtRusultVO.setRedisUuid("");
         codeImProtRusultVO.setFileOid(uuid);
         codeImProtRusultVO.setFilePath(errorFile);
         R r = R.fail("导入失败");
         r.setData(codeImProtRusultVO);
         return r;
      }finally {
         file1.delete();
      }
   }
   /**
    * 下载批量申请的导入模板
    * @param codeClassifyOid 分类的主键
    * @param response 响应对象
    * @throws IOException 抛出异常
    */
   @GetMapping("/downloadTopImportExcel")
   @VciBusinessLog(operateName = "下载批量申请编码的导入模板")
   public void downloadTopImportExcel(String codeClassifyOid,HttpServletResponse response) throws IOException{
@@ -113,8 +175,8 @@
   @VciBusinessLog(operateName = "导出主题库的数据")
   @PostMapping("/exportCode")
   public void exportCode(CodeExportAttrDTO exportAttrDTO, HttpServletResponse response) throws IOException {
      String excelName = mdmIOService.exportCode(exportAttrDTO);
      try {
         String excelName = mdmIOService.exportCode(exportAttrDTO);
         ControllerUtil.writeFileToResponse(response,excelName);
      } catch (Throwable e) {
         //如果出错,把错误信息写到text
@@ -293,7 +355,7 @@
    * @param baseModelDTO 数据传输对象
    * @return 执行结果
    */
   @PostMapping("changeStatus")
   @PostMapping("/changeStatus")
   public R changeStatus(@RequestBody BaseModelDTO baseModelDTO) {
      engineService.changeStatus(baseModelDTO);
      return R.success("操作成功!");
@@ -312,7 +374,7 @@
         s = engineService.addSaveCode(orderDTO);
         saveLogUtil.operateLog("编码申请",false,orderDTO.toString());
      }catch (Exception e){
         saveLogUtil.operateLog("编码申请",true,e.getMessage());
         saveLogUtil.operateLog("编码申请",true,e.toString());
         throw e;
      }
      return R.success(s);
@@ -399,7 +461,7 @@
      return engineService.gridTableDataByClassifyOid(codeClassifyOid,templateOid,queryObject.getConditionMap(),queryObject.getPageHelper());
   }
   /***
   /**
    * 获取分类对象
    * @param redisOid
    * @return
@@ -410,7 +472,7 @@
      return R.data(codeImportTemplateVOs);
   }
   /***
   /**
    * 从redis缓存里获取到导入正确的数据
    * @param codeClassifyOid
    * @param redisOid
@@ -421,7 +483,7 @@
      return mdmIOService.gridDatas(codeClassifyOid,redisOid);
   }
   /***
   /**
    * 从redis缓存里获取到导入行相似项的数据
    * @param dataOid
    * @param redisOid
@@ -432,7 +494,7 @@
      return mdmIOService.gridRowResemble(dataOid,redisOid);
   }
   /***
   /**
    * 从redis缓存里获取到导入具有相似项的数据
    * @param codeClassifyOid
    * @param redisOid
@@ -443,7 +505,7 @@
      return mdmIOService.gridDatas(codeClassifyOid,redisOid);
   }
   /***
   /**
    * 导入数据
    * @param codeImprotSaveDatVO//数据对象
    * @return
@@ -453,7 +515,7 @@
      return mdmIOService.batchImportData(codeImprotSaveDatVO.getCodeImprotSaveDatVOList(),codeImprotSaveDatVO.getClassifyAttr(),codeImprotSaveDatVO.getImprot());
   }
   /***
   /**
    * 根据数据oid从缓存中移除数据
    * @param redisOid redisid
    * @param codeClassifyOid 存储规则的oid
@@ -608,7 +670,7 @@
    * @param idPath 编号的路径
    * @return UI相关的信息(仅包含表单)
    */
//   @VciUnCheckRight
   //   @VciUnCheckRight
   @GetMapping("/getFormDefineByClassifyIdPath")
   public MdmUIInfoVO getFormDefineByClassifyIdPath(String idPath){
      return engineService.getFormDefineByClassifyIdPath(idPath);
@@ -663,7 +725,7 @@
    * @return UI相关的信息(仅包含表格)
    */
   @GetMapping("/getFlowdUIInfoByClassifyOid")
   public MdmUIInfoVO getUIInfoByClassifyOid(String codeClassifyOid,String functionId,String templateId,String taskId,String modelKey){
   public MdmUIInfoVO getFlowUIInfoByClassifyOid(String codeClassifyOid,String functionId,String templateId,String taskId,String modelKey){
      return engineService.getFlowUIInfoByClassifyOid(codeClassifyOid,functionId,templateId,taskId,modelKey);
   }
@@ -769,4 +831,80 @@
   public R addSaveBZ (@RequestBody CodeBZApplyDTO codeBZApplyDTO) throws Exception {
      return R.success(engineService.addSaveBZ(codeBZApplyDTO));
   }
   /**
    * 下载批量申请的导入模板
    * @param codeClassifyOid 分类的主键
    * @param response 响应对象
    * @throws IOException 抛出异常
    */
   @GetMapping("/exportGroupCodeExcel")
   @VciBusinessLog(operateName = "导出集团码")
   public void exportGroupCodeExcel(String codeClassifyOid, HttpServletResponse response) throws IOException {
      try {
         String excelName = mdmIOService.exportGroupCodeExcel(codeClassifyOid);
         ControllerUtil.writeFileToResponse(response,excelName);
      } catch (Throwable e) {
         //如果出错,把错误信息写到text
         String msg = LangBaseUtil.getErrorMsg(e);
         if(StringUtils.isBlank(msg)){
            msg = "未知错误";
         }
         String errorFile = LocalFileUtil.getDefaultTempFolder() + File.separator + "错误.txt";
         LocalFileUtil.writeContentToFile(msg,errorFile);
         ControllerUtil.writeFileToResponse(response,errorFile);
      //   return R.fail(msg);
      }
   //   return R.status(true);
   }
   /**
    * 集团码导入
    * @param codeClassifyOid
    * @param file
    * @param response
    * @return
    */
   @PostMapping("/importGroupCode")
   public R  importGroupCode(String codeClassifyOid,MultipartFile file,HttpServletResponse response){
      String excelFileName = LocalFileUtil.getDefaultTempFolder() + File.separator + file.getOriginalFilename();
      File file1 = new File(excelFileName);
      try {
         file.transferTo(new File(excelFileName));
         String excelName=mdmIOService.importGroupCode(codeClassifyOid,file1);
         if(StringUtils.isNotBlank(excelName)) {
            ControllerUtil.writeFileToResponse(response,excelName);
            return   R.fail("集团码导入出现问题,请查看文件");
         }else{
            return R.status(true);
         }
      }catch (Throwable e) {
         logger.error("导入错误",e);
         String errorFile = LocalFileUtil.getDefaultTempFolder() + File.separator + "错误.txt";
         LocalFileUtil.writeContentToFile(LangBaseUtil.getErrorMsg(e),errorFile);
         String uuid=ControllerUtil.putErrorFile(errorFile);
         CodeImProtRusultVO codeImProtRusultVO =new CodeImProtRusultVO();
         codeImProtRusultVO.setRedisUuid("");
         codeImProtRusultVO.setFileOid(uuid);
         codeImProtRusultVO.setFilePath(errorFile);
         R r = R.fail("集团码导入失败");
         r.setData(codeImProtRusultVO);
         return r;
      }finally {
         file1.delete();
      }
   }
   /**
    * 获取统计分析数据
    * @param btmNames 业务类型
    * @return
    */
   @GetMapping("/getStatisticAnalysis")
   @VciBusinessLog(operateName = "获取统计分析数据")
   public R getStatisticAnalysis(String btmNames) {
      return engineService.getStatisticAnalysis(btmNames);
   }
}