邮件异常提示优化

EXCEL数据通用导出
yun-zuoyi
汪云昊 6 years ago
parent 01d4c7d70e
commit c2e658bf9f

@ -1,44 +1,10 @@
package cn.estsh.i3plus.core.apiservice.controller.base;
import cn.estsh.i3plus.platform.common.exception.ImppExceptionEnum;
import cn.estsh.i3plus.platform.common.tool.ExcelTool;
import cn.estsh.i3plus.platform.common.tool.FileTool;
import cn.estsh.i3plus.platform.common.tool.ZipTool;
import cn.estsh.i3plus.platform.common.util.PlatformConstWords;
import cn.estsh.i3plus.pojo.base.bean.ListPager;
import cn.estsh.i3plus.pojo.base.common.Pager;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
import cn.estsh.i3plus.pojo.model.common.ExportDataModel;
import cn.estsh.i3plus.pojo.platform.bean.SysOrderNoRule;
import cn.estsh.impp.framework.base.controller.BaseCommonController;
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
import cn.estsh.impp.framework.boot.util.ImppRedis;
import cn.estsh.impp.framework.boot.util.ResultBean;
import cn.estsh.impp.framework.boot.util.ValidatorBean;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import java.io.*;
import java.util.*;
import org.springframework.web.method.HandlerMethod;
import springfox.documentation.spring.web.json.Json;
import javax.annotation.Resource;
import javax.persistence.EntityManager;
import javax.servlet.http.HttpServletResponse;
/**
* @Description :
@ -51,82 +17,4 @@ import javax.servlet.http.HttpServletResponse;
@Api(description = "通用功能服务")
@RequestMapping(PlatformConstWords.BASE_URL +"/common")
public class CoreCommonController extends BaseCommonController {
@Autowired
private EntityManager entityManager;
@Resource(name="redisRes")
private ImppRedis redisRes;
@Autowired
private RequestMappingHandlerMapping requestMappingHandlerMapping;
@PostMapping("/test-mapping")
@ApiOperation("根据路径寻找Controller")
public ResultBean exportData(ExportDataModel exportDataModel, HttpServletResponse response){
try {
ValidatorBean.beginValid(exportDataModel)
.notNull("className",exportDataModel.getClassName())
.notNull("exportData",exportDataModel.getExportData());
ExcelTool excelTool = new ExcelTool(entityManager, redisRes);
Class entityClass = Class.forName(exportDataModel.getClassName());
String[] colName = new String[ExcelTool.getColName(entityClass).size()];
ExcelTool.getColName(entityClass).keySet().toArray(colName);
List dataList = JSONArray.parseArray(exportDataModel.getExportData(), entityClass);
// 数据校验
if (colName == null || colName.length == 0) {
throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.IMPP.getCode())
.setErrorCode(ImppExceptionEnum.BUSINESS_EXCEPTION_DATA_ERROR.getCode())
.setErrorDetail("导出列不能为空")
.build();
}
// 将excel导出至临时文件夹
File excelFile = new File(System.getProperty("java.io.tmpdir") + File.separator + entityClass.getSimpleName()+".xls");
excelFile.createNewFile();
excelTool.exportData(excelFile, dataList, entityClass, colName);
InputStream targetStream = new DataInputStream(new FileInputStream(excelFile));
response.setContentType("application/octet-stream;");
response.setHeader("Content-Disposition", "attachment;fileName=" + excelFile.getName()); // 设置文件名
response.addHeader("Pargam", "no-cache");
response.addHeader("Cache-Control", "no-cache");
BufferedInputStream bis = null;
OutputStream os = null;
try {
bis = new BufferedInputStream(targetStream);
os = response.getOutputStream();
byte[] buffer = new byte[1024];
int i = bis.read(buffer);
while (i != -1) {
os.write(buffer, 0, i);
i = bis.read(buffer);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (bis != null) {
try {
os.close();
bis.close();
targetStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
excelFile.delete();
return ResultBean.success("导出成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
} catch (ImppBusiException busExcep) {
return ResultBean.fail(busExcep);
} catch (Exception e) {
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
}
}
}

@ -301,9 +301,9 @@ public class SysConfigController extends CoreBaseController {
if(mailConfig.getMailSwitch() != CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue()){
throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION_DATA_NOT_EXIT.getCode())
.setErrorDetail("字典不存在")
.setErrorSolution("请重新输入字典id")
.setErrorCode(ImppExceptionEnum.MAIL_SERVER_NOT_OPEN_ERROR.getCode())
.setErrorDetail(ImppExceptionEnum.MAIL_SERVER_NOT_OPEN_ERROR.getDescription())
.setErrorSolution("开启邮件服务")
.build();
}

@ -4,6 +4,7 @@ import cn.estsh.i3plus.core.api.iservice.busi.ISysTaskCycleService;
import cn.estsh.i3plus.core.api.iservice.busi.ISysTaskPlanService;
import cn.estsh.i3plus.core.api.iservice.busi.ISysTaskService;
import cn.estsh.i3plus.icloud.wms.sdk.IWmsScheduleJobCloud;
import cn.estsh.i3plus.platform.common.exception.ImppExceptionEnum;
import cn.estsh.i3plus.platform.common.tool.StringTool;
import cn.estsh.i3plus.platform.common.util.PlatformConstWords;
import cn.estsh.i3plus.pojo.base.bean.ListPager;
@ -17,7 +18,6 @@ import cn.estsh.i3plus.pojo.platform.bean.SysTaskPlan;
import cn.estsh.impp.framework.base.controller.CoreBaseController;
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
import cn.estsh.impp.framework.boot.exception.ImppExceptionEnum;
import cn.estsh.impp.framework.boot.quartz.IQuartzJobService;
import cn.estsh.impp.framework.boot.quartz.ScheduleTool;
import cn.estsh.impp.framework.boot.util.ResultBean;

@ -56,8 +56,8 @@ public class SysTaskCycleService implements ISysTaskCycleService {
throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
.setErrorDetail("存在关联任务计划【" + refExpressionTriggerList.get(0).getTaskPlanName()
+ refExpressionTriggerList.get(0).getTaskPlanGroupName() + "】,无法删除")
.setErrorDetail("存在关联任务计划【 名称:"+refExpressionTriggerList.get(0).getTaskPlanName()
+",组名称:"+ refExpressionTriggerList.get(0).getTaskPlanGroupName() + "】,无法删除")
.setErrorSolution("请重新选择")
.build();
}

Loading…
Cancel
Save