ludc
2023-08-02 744171debef6aee198be296520f0b86dc1586723
Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/controller/MdmEngineController.java
@@ -3,7 +3,10 @@
import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.common.utils.StringUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.vci.ubcs.code.dto.CodeDeleteBatchDTO;
import com.vci.ubcs.code.dto.CodeExportAttrDTO;
import com.vci.ubcs.code.dto.CodeOrderDTO;
import com.vci.ubcs.code.dto.CodeOrderSecDTO;
import com.vci.ubcs.code.dto.datapush.BaseModelDTO;
@@ -38,9 +41,9 @@
@Api(value = "编码数据管理", tags = "编码数据管理")
public class MdmEngineController {
//   /**
//    * 日志
//    */
   /**
    * 日志
    */
   private Logger logger = LoggerFactory.getLogger(getClass());
   /**
    * 主数据引擎服务
@@ -52,6 +55,7 @@
    */
   @Autowired
   private MdmIOService mdmIOService;
   /**
    * 下载批量申请的导入模板
@@ -74,7 +78,71 @@
         ControllerUtil.writeDataToResponse(response,msg.getBytes(StandardCharsets.UTF_8),null);
      }
   }
   /**
    * 下载批量申请的导入模板
    * @param codeClassifyOid 分类的主键
    * @param response 响应对象
    * @throws IOException 抛出异常
    */
   @GetMapping("/downloadTopImportExcel")
   @VciBusinessLog(operateName = "下载批量申请编码的导入模板")
   public void downloadTopImportExcel(String codeClassifyOid,HttpServletResponse response) throws IOException{
      String excelName = mdmIOService.downloadTopImportExcel(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 exportAttrDTO 导出的相关配置
    */
   @VciBusinessLog(operateName = "导出主题库的数据")
   @PostMapping("/exportCode")
   public void exportCode(CodeExportAttrDTO exportAttrDTO, HttpServletResponse response) throws IOException {
      String excelName = mdmIOService.exportCode(exportAttrDTO);
      try {
         ControllerUtil.writeFileToResponse(response,excelName);
      } catch (Throwable e) {
         //如果出错,把错误信息写到text
         String msg = LangBaseUtil.getErrorMsg(e);
         String errorFile = LocalFileUtil.getDefaultTempFolder() + File.separator + "错误.txt";
         LocalFileUtil.writeContentToFile(msg,errorFile);
         ControllerUtil.writeFileToResponse(response,errorFile);
      }
   }
   /**
    * 下载历史数据导入模板
    * @param codeClassifyOid 分类的主键
    * @param response 响应对象
    * @throws IOException 抛出异常
    */
   @GetMapping("/downloadImportExcelHistory")
   @VciBusinessLog(operateName = "下载历史数据导入模板")
   public void downloadImportExcelHistory(String codeClassifyOid,HttpServletResponse response) throws IOException{
      String excelName = mdmIOService.createImportExcel(codeClassifyOid,true);
      //String excelName = mdmIOService.downloadTopImportExcel(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);
      }
   }
   /**
    * 批量申请编码的信息
@@ -126,6 +194,95 @@
//      return null;
   }
   /**
    * 导入历史数据
    * @param codeClassifyOid 分类的主键
    * @param classifyAttr 分类路径使用的属性
    * @param file 文件的内容
    */
   @VciBusinessLog(operateName = "导入编码的历史数据")
   @PostMapping("/batchImportHistoryData")
   public R batchImportHistoryData(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.batchImportHistoryData(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 classifyAttr 分类路径使用的属性
    * @param file 文件的内容
    */
   @VciBusinessLog(operateName = "批量申请编码的信息")
   @PostMapping("/batchTopImportCode")
   public R batchTopImportCode(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.batchTopImportCode(codeClassifyOid, classifyAttr,file1);
         if(StringUtils.isNotBlank(codeImProtRusultVO.getFilePath())||StringUtils.isNotBlank(codeImProtRusultVO.getRedisUuid())){
            //放到map里
            R r = R.fail("导入失败!");
            if(StringUtils.isNotBlank(codeImProtRusultVO.getFilePath())) {
               String filedUUid = ControllerUtil.putErrorFile(codeImProtRusultVO.getFilePath());
               codeImProtRusultVO.setFileOid(filedUUid);
               r = R.success("导入成功!");
            }
            r.setData(codeImProtRusultVO);
            return r;
         }else {
            return R.success("导入成功!");
         }
      }catch (Throwable e) {
         e.printStackTrace();
         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();
      }
   }
   /**
    * 修改状态
@@ -133,7 +290,7 @@
    * @return 执行结果
    */
   @PostMapping("changeStatus")
   public R changeStatus(BaseModelDTO baseModelDTO) {
   public R changeStatus(@RequestBody BaseModelDTO baseModelDTO) {
      engineService.changeStatus(baseModelDTO);
      return R.success("操作成功!");
   }
@@ -256,7 +413,7 @@
   }
   /***
    * 从redis缓存里获取到导入正确的数据
    * 从redis缓存里获取到导入行相似项的数据
    * @param dataOid
    * @param redisOid
    * @return
@@ -276,7 +433,27 @@
   public DataGrid<Map<String,String>> gridResemble(String codeClassifyOid,String redisOid){
      return mdmIOService.gridDatas(codeClassifyOid,redisOid);
   }
   /***
    * 导入数据
    * @param codeImprotSaveDatVO//数据对象
    * @return
    */
   @PostMapping("/batchImportData")
   public R batchImportData(@RequestBody CodeImprotParmaDatVO codeImprotSaveDatVO){
      return  mdmIOService.batchImportData(codeImprotSaveDatVO.getCodeImprotSaveDatVOList(),codeImprotSaveDatVO.getClassifyAttr(),codeImprotSaveDatVO.getImprot());
   }
   /***
    *根据数据oid从缓存中移除数据
    * @param redisOid redisid
    * @param codeClassifyOid 存储规则的oid
    * @param dataOids  所需删除的数据
    * @return
    */
   @GetMapping("/deleteDatas")
   public  R deleteDatas(String redisOid,String codeClassifyOid,String dataOids){
      return mdmIOService.deleteDatas(redisOid,codeClassifyOid,dataOids);
   }
   /**
    * 批量保存流程执行页面修改的内容
    * @param orderDTOList 编码相关的信息,不需要码段的信息
@@ -351,12 +528,12 @@
    * @return 分类码值的内容
    */
   @GetMapping("/listCodeClassifyValueBySecOid")
   public DataGrid<CodeClassifyValueVO> listCodeClassifyValueBySecOid(String classifySecOid, String parentClassifyValueOid){
   public IPage<CodeClassifyValueVO> listCodeClassifyValueBySecOid(String classifySecOid, String parentClassifyValueOid){
      List<CodeClassifyValueVO> valueVOS = engineService.listCodeClassifyValueBySecOid(classifySecOid, parentClassifyValueOid);
      DataGrid<CodeClassifyValueVO> dataGrid = new DataGrid<>();
      dataGrid.setData(valueVOS);
      dataGrid.setTotal(valueVOS==null?0:valueVOS.size());
      return dataGrid;
      IPage<CodeClassifyValueVO> valueVOIPage = new Page<>();
      valueVOIPage.setRecords(valueVOS);
      valueVOIPage.setTotal(valueVOS==null?0:valueVOS.size());
      return valueVOIPage;
   }
   /**
@@ -365,7 +542,7 @@
    * @return 编码规则的内容
    */
   @GetMapping("/getCodeRuleByClassifyOid")
//   @VciUnCheckRight
   //   @VciUnCheckRight
   public R<CodeRuleVO> getCodeRuleByClassifyOid(String codeClassifyOid){
      return R.data(engineService.getCodeRuleByClassifyOid(codeClassifyOid));
   }
@@ -468,6 +645,17 @@
      return engineService.getUIInfoByClassifyOid(codeClassifyOid,functionId);
   }
   /**
    * 使用分类获取表格的定义
    * @param codeClassifyOid 分类主键
    * @param functionId 功能的编号
    * @return UI相关的信息(仅包含表格)
    */
   @GetMapping("/getFlowdUIInfoByClassifyOid")
   public MdmUIInfoVO getUIInfoByClassifyOid(String codeClassifyOid,String functionId,String templateId,String taskId,String modelKey){
      return engineService.getFlowUIInfoByClassifyOid(codeClassifyOid,functionId,templateId,taskId,modelKey);
   }
   @GetMapping("/thisistest")
   @ResponseBody
@@ -537,8 +725,8 @@
    * @return 执行的结果
    */
   @GetMapping("/defaultReferDataGrid")
   public DataGrid defaultReferDataGrid(UIFormReferVO referConfigVO, PageHelper pageHelper){
      return engineService.referDataGrid(referConfigVO,pageHelper);
   public IPage<BaseModel> defaultReferDataGrid(UIFormReferVO referConfigVO, BaseQueryObject baseQueryObject){
      return engineService.referDataGrid(referConfigVO,baseQueryObject);
   }
   /**