package com.product.module.data.controller; import com.alibaba.fastjson.JSONObject; import com.product.common.lang.StringUtils; import com.product.core.config.CoreConst; import com.product.core.controller.support.AbstractBaseController; import com.product.core.entity.FieldSetEntity; import com.product.core.entity.RequestParameterEntity; import com.product.core.exception.BaseException; import com.product.core.spring.context.SpringMVCContextHolder; import com.product.file.config.FileCode; import com.product.module.data.config.CmnCode; import com.product.module.data.config.CmnConst; import com.product.module.data.service.SystemDataUpLoadService; import com.product.module.data.service.idel.ISystemDataUpLoadService; import com.product.module.sys.version.ApiVersion; import com.product.util.BaseUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; @RestController @RequestMapping("/api/data-model") public class SystemDataUploadController extends AbstractBaseController { @Autowired private SystemDataUpLoadService systemDataUpLoadService; /** * 模板上传 * * @return 结果 */ @RequestMapping(value = "/upload-template/{version}", method = RequestMethod.POST) @ApiVersion(1) public String uploadTemplate(HttpServletRequest request) { try { Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); RequestParameterEntity rpe = (RequestParameterEntity) bean; ISystemDataUpLoadService iSystemDataUpLoadService = (ISystemDataUpLoadService) getProxyInstance(systemDataUpLoadService); JSONObject resultObj = iSystemDataUpLoadService.uploadTemplate(rpe); return BaseUtil.success(resultObj); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); e.printStackTrace(); return error(e.getCode(), e.getMessage()); } catch (Exception e) { SpringMVCContextHolder.getSystemLogger().error(e); e.printStackTrace(); return error(FileCode.UPLOAD_FILE_FAIL.getValue(), FileCode.UPLOAD_FILE_FAIL.getText()); } } /** * 根据已经上传的excel文件,解析excel表头 * * @param request * @return * @throws IOException */ @RequestMapping(value = "/analysis-template/{version}", method = RequestMethod.POST) public String analysisTemplate(HttpServletRequest request) { try { FieldSetEntity fse = null; Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); RequestParameterEntity rpe = (RequestParameterEntity) bean; if (null != rpe && null != rpe.getFormData()) { fse = rpe.getFormData(); } if (fse == null) { SpringMVCContextHolder.getSystemLogger().error(CmnCode.SYSTEM_FORM_NODATA.getValue(), CmnCode.SYSTEM_FORM_NODATA.getText()); return this.error(CmnCode.SYSTEM_FORM_NODATA.getValue(), CmnCode.SYSTEM_FORM_NODATA.getText()); } JSONObject dataJson = systemDataUpLoadService.analysisTemplate(fse); return BaseUtil.success(dataJson); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); e.printStackTrace(); return error(e.getCode(), e.getMessage()); } catch (Exception e) { SpringMVCContextHolder.getSystemLogger().error(e); e.printStackTrace(); return error(CmnCode.UPLOAD_TEMPLATE_GET_INFO_FAIL.getValue(), CmnCode.UPLOAD_TEMPLATE_GET_INFO_FAIL.getText()); } } /** * 上传模板新增 * * @param request * @return * @throws BaseException */ @RequestMapping(value = "/save-template/{version}", method = RequestMethod.POST) @ApiVersion(1) public String saveTemplate(HttpServletRequest request) { try { FieldSetEntity fse = null; Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); RequestParameterEntity rpe = (RequestParameterEntity) bean; if (null != rpe && null != rpe.getFormData()) { fse = rpe.getFormData(); } if (fse == null) { SpringMVCContextHolder.getSystemLogger().error(CmnCode.SYSTEM_FORM_NODATA.getValue(), CmnCode.SYSTEM_FORM_NODATA.getText()); return this.error(CmnCode.SYSTEM_FORM_NODATA.getValue(), CmnCode.SYSTEM_FORM_NODATA.getText()); } ISystemDataUpLoadService iSystemDataUpLoadService = (ISystemDataUpLoadService) getProxyInstance(systemDataUpLoadService); iSystemDataUpLoadService.saveTemplate(fse); return OK(); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); e.printStackTrace(); return error(e.getCode(), e.getMessage()); } catch (Exception e) { SpringMVCContextHolder.getSystemLogger().error(e); e.printStackTrace(); return error(CmnCode.UPLOAD_TEMPLATE_SAVE_FAIL.getValue(), CmnCode.UPLOAD_TEMPLATE_SAVE_FAIL.getText()); } } @PostMapping("/get-prompt/{version}") @ApiVersion(1) public String getPromptList() { try { return BaseUtil.success(systemDataUpLoadService.getPrompt()); } catch (BaseException e) { return this.error(e.getCode(), e.getMessageInfo()); } catch (Exception e) { return error(CmnCode.GET_EXPORT_PROMPT_LIST_FINAL.getValue(), CmnCode.GET_EXPORT_PROMPT_LIST_FINAL.getText()); } } /** * 模板台账-左边树结构 * * @return 结果 */ @RequestMapping(value = "/list-template/{version}", method = RequestMethod.POST) @ApiVersion(1) public String listTemplate(HttpServletRequest request) { try { FieldSetEntity fse = null; Object bean = request.getAttribute("requestPara"); if (bean != null) { RequestParameterEntity reqp = (RequestParameterEntity) bean; fse = reqp.getFormData(); } if (bean == null || fse == null) { SpringMVCContextHolder.getSystemLogger().error(CmnCode.SYSTEM_FORM_NODATA.getValue(), CmnCode.SYSTEM_FORM_NODATA.getText()); return this.error(CmnCode.SYSTEM_FORM_NODATA.getValue(), CmnCode.SYSTEM_FORM_NODATA.getText()); } if (StringUtils.isEmpty(fse.getTableName()) || !CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL.equals(fse.getTableName())) { SpringMVCContextHolder.getSystemLogger().error(CmnCode.SYSTEM_TABLE_NODATA.getValue(), CmnCode.SYSTEM_TABLE_NODATA.getText()); return this.error(CmnCode.SYSTEM_TABLE_NODATA.getValue(), CmnCode.SYSTEM_TABLE_NODATA.getText()); } return OK_List(systemDataUpLoadService.listTemplate(fse)); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(e.getCode(), e.getMessageInfo()); } catch (Exception e) { SpringMVCContextHolder.getSystemLogger().error(e); logger.error("", e); return error(CmnCode.UPLOAD_TEMPLATE_GET_LIST_FAIL.getValue(), CmnCode.UPLOAD_TEMPLATE_GET_LIST_FAIL.getText()); } } /** * 查询模板详情 * * @param request * @return * @throws BaseException */ @RequestMapping(value = "/find-template/{version}", method = RequestMethod.POST) @ApiVersion(1) public String findTemplate(HttpServletRequest request) { try { FieldSetEntity fse = null; Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); RequestParameterEntity rpe = (RequestParameterEntity) bean; if (null != rpe && null != rpe.getFormData()) { fse = rpe.getFormData(); } if (fse == null) { SpringMVCContextHolder.getSystemLogger().error(CmnCode.SYSTEM_FORM_NODATA.getValue(), CmnCode.SYSTEM_FORM_NODATA.getText()); return this.error(CmnCode.SYSTEM_FORM_NODATA.getValue(), CmnCode.SYSTEM_FORM_NODATA.getText()); } return OK_List(systemDataUpLoadService.findTemplate(fse)); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); e.printStackTrace(); return error(e.getCode(), e.getMessage()); } catch (Exception e) { SpringMVCContextHolder.getSystemLogger().error(e); e.printStackTrace(); return error(CmnCode.UPLOAD_TEMPLATE_FIND_FAIL.getValue(), CmnCode.UPLOAD_TEMPLATE_FIND_FAIL.getText()); } } /** * 数据上传模板删除接口 * * @param request * @return */ @RequestMapping(value = "/delete-template/{version}", method = RequestMethod.POST) @ApiVersion(1) public String deleteDataModel(HttpServletRequest request) { try { //获取传参数据 FieldSetEntity fse = null; Object bean = request.getAttribute("requestPara"); if (bean != null) { RequestParameterEntity reqp = (RequestParameterEntity) bean; fse = reqp.getFormData(); } if (bean == null || fse == null) { SpringMVCContextHolder.getSystemLogger().error(CmnCode.SYSTEM_FORM_NODATA.getValue(), CmnCode.SYSTEM_FORM_NODATA.getText()); return this.error(CmnCode.SYSTEM_FORM_NODATA.getValue(), CmnCode.SYSTEM_FORM_NODATA.getText()); } if (StringUtils.isEmpty(fse.getTableName()) || !CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL.equals(fse.getTableName())) { SpringMVCContextHolder.getSystemLogger().error(CmnCode.SYSTEM_TABLE_NODATA.getValue(), CmnCode.SYSTEM_TABLE_NODATA.getText()); return this.error(CmnCode.SYSTEM_TABLE_NODATA.getValue(), CmnCode.SYSTEM_TABLE_NODATA.getText()); } ISystemDataUpLoadService iSystemDataUpLoadService = (ISystemDataUpLoadService) getProxyInstance(systemDataUpLoadService); iSystemDataUpLoadService.deleteModel(fse); return OK(); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(e.getCode(), e.getMessageInfo()); } catch (Exception e) { SpringMVCContextHolder.getSystemLogger().error(e); logger.error("", e); return error(CmnCode.UPLOAD_TEMPLATE_DELETE_FAIL.getValue(), CmnCode.UPLOAD_TEMPLATE_DELETE_FAIL.getText()); } } /** * 模板下载 * * @param request * @return * @throws BaseException */ @RequestMapping(value = "/download-template/{version}", method = RequestMethod.POST) @ApiVersion(1) public String downloadTemplate(HttpServletRequest request, HttpServletResponse response) { try { FieldSetEntity fse = null; Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); RequestParameterEntity rpe = (RequestParameterEntity) bean; if (null != rpe && null != rpe.getFormData()) { fse = rpe.getFormData(); } if (fse == null) { SpringMVCContextHolder.getSystemLogger().error(CmnCode.SYSTEM_FORM_NODATA.getValue(), CmnCode.SYSTEM_FORM_NODATA.getText()); return this.error(CmnCode.SYSTEM_FORM_NODATA.getValue(), CmnCode.SYSTEM_FORM_NODATA.getText()); } systemDataUpLoadService.downloadTemplate(fse, response); return OK(); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); e.printStackTrace(); return error(e.getCode(), e.getMessage()); } catch (Exception e) { SpringMVCContextHolder.getSystemLogger().error(e); e.printStackTrace(); return error(CmnCode.UPLOAD_TEMPLATE_DOWNLOAD_FAIL.getValue(), CmnCode.UPLOAD_TEMPLATE_DOWNLOAD_FAIL.getText()); } } /** * 业务功能导入-上传文件 * * @param request * @return * @throws IOException * @throws BaseException */ @RequestMapping(value = "/record-data-import/{version}", method = RequestMethod.POST) @ApiVersion(1) public String recordDataImport(HttpServletRequest request) { try { FieldSetEntity fse = null; Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); RequestParameterEntity rpe = (RequestParameterEntity) bean; if (null != rpe && null != rpe.getFormData()) { fse = rpe.getFormData(); } if (fse == null) { SpringMVCContextHolder.getSystemLogger().error(CmnCode.SYSTEM_FORM_NODATA.getValue(), CmnCode.SYSTEM_FORM_NODATA.getText()); return this.error(CmnCode.SYSTEM_FORM_NODATA.getValue(), CmnCode.SYSTEM_FORM_NODATA.getText()); } if (StringUtils.isEmpty(fse.getTableName()) || !CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_RECORD.equals(fse.getTableName())) { SpringMVCContextHolder.getSystemLogger().error(CmnCode.SYSTEM_TABLE_NODATA.getValue(), CmnCode.SYSTEM_TABLE_NODATA.getText()); return this.error(CmnCode.SYSTEM_TABLE_NODATA.getValue(), CmnCode.SYSTEM_TABLE_NODATA.getText()); } ISystemDataUpLoadService iSystemDataUpLoadService = (ISystemDataUpLoadService) getProxyInstance(systemDataUpLoadService); String uuid = iSystemDataUpLoadService.recordDataImport(rpe); return OK_Add(uuid); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); e.printStackTrace(); return error(e.getCode(), e.getMessage()); } catch (Exception e) { SpringMVCContextHolder.getSystemLogger().error(e); e.printStackTrace(); return error(CmnCode.UPLOAD_TEMPLATE_RECORD_DATA_IMPORT_FILE_FAIL.getValue(), CmnCode.UPLOAD_TEMPLATE_RECORD_DATA_IMPORT_FILE_FAIL.getText()); } } /** * 业务功能导入-解析并保存到数据库 * * @param request * @return * @throws IOException * @throws BaseException */ @RequestMapping(value = "/record-data-save/{version}", method = RequestMethod.POST) @ApiVersion(1) public String recordDataSave(HttpServletRequest request) { try { FieldSetEntity fse = null; Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); RequestParameterEntity rpe = (RequestParameterEntity) bean; if (null != rpe && null != rpe.getFormData()) { fse = rpe.getFormData(); } if (fse == null) { SpringMVCContextHolder.getSystemLogger().error(CmnCode.SYSTEM_FORM_NODATA.getValue(), CmnCode.SYSTEM_FORM_NODATA.getText()); return this.error(CmnCode.SYSTEM_FORM_NODATA.getValue(), CmnCode.SYSTEM_FORM_NODATA.getText()); } if (StringUtils.isEmpty(fse.getTableName()) || !CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_RECORD.equals(fse.getTableName())) { SpringMVCContextHolder.getSystemLogger().error(CmnCode.SYSTEM_TABLE_NODATA.getValue(), CmnCode.SYSTEM_TABLE_NODATA.getText()); return this.error(CmnCode.SYSTEM_TABLE_NODATA.getValue(), CmnCode.SYSTEM_TABLE_NODATA.getText()); } ISystemDataUpLoadService iSystemDataUpLoadService = (ISystemDataUpLoadService) getProxyInstance(systemDataUpLoadService); iSystemDataUpLoadService.recordDataSave(fse); return OK(); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); e.printStackTrace(); return error(e.getCode(), e.getMessage()); } catch (Exception e) { SpringMVCContextHolder.getSystemLogger().error(e); e.printStackTrace(); return error(CmnCode.UPLOAD_TEMPLATE_RECORD_DATA_IMPORT_FILE_FAIL.getValue(), CmnCode.UPLOAD_TEMPLATE_RECORD_DATA_IMPORT_FILE_FAIL.getText()); } } }