ludc
2024-12-26 8267d62b7d89e101669e20e66d6b94420fb82c85
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("操作成功!");
@@ -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);
   }
@@ -778,17 +840,71 @@
    */
   @GetMapping("/exportGroupCodeExcel")
   @VciBusinessLog(operateName = "导出集团码")
   public void exportGroupCodeExcel(String codeClassifyOid, HttpServletResponse response) throws IOException{
   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 = "未知错误";
         }
         ControllerUtil.writeDataToResponse(response,msg.getBytes(StandardCharsets.UTF_8),null);
         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);
   }
}