|
|
|
@ -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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|