//导入
@PostMapping(value = "importData")
ResultJson importData(@RequestParam MultipartFile file) {
ResultJson resultJson= newResultJson();
List importData = null;try{
importData= ExcelUtil.importExcel(file.getInputStream(), ProjectJson.class);
}catch(IOException e) {
e.printStackTrace();
}if (null ==importData) {
resultJson.setStatus(1);
resultJson.setMessage("导入失败!");returnresultJson;
}int num = 0;for(ProjectJson projectJson : importData) {
ProjectManageEntity projectManageEntity= newProjectManageEntity();
num++;if(CommonUtil.isEmpty(projectJson.getNumber())) {
resultJson.setMessage("导入失败!第" + num + "行的编号不能为空");
resultJson.setStatus(1);returnresultJson;
}if (projectService.findByprojectNumber(projectJson.getNumber()) != null) {
resultJson.setStatus(1);
resultJson.setMessage("导入失败!第" + num + "行的编号重复");
resultJson.setData(null);returnresultJson;
}
projectManageEntity.setCreateDate(newDate());
projectManageEntity.setUpdateDate(newDate());
projectManageEntity.setName(projectJson.getName());
projectManageEntity.setNumber(projectJson.getNumber());
projectManageEntity.setType(projectJson.getType());
projectManageEntity.setDeleteMark(false);
projectManageEntity.setCode("PROJECT_MANAGE" +UUID.randomUUID());
projectService.save(projectManageEntity);
}
resultJson.setStatus(0);
resultJson.setMessage("导入成功!");
resultJson.setData(null);returnresultJson;
}//导出
@PostMapping(value = "exportData")
ResultJson exportData() {
String excelTitle= "项目管理";
String path= "/export/company/excel/" + DateUtil.getEightDateFormat().format(newDate());
String realPath= CommonUtil.createFolderPath(propertyUtil.getUploadPath() +path);return ExcelUtil.exportExcel(excelTitle, realPath, path, ProjectJson.class, projectService.getAll());
}//下载模板
@PostMapping(value = "downloadTemplate")publicResultJson downloadTemplate() {
String excelTitle= "项目管理模板";
String path= "/export/company/excel/" + DateUtil.getEightDateFormat().format(newDate());
String realPath= CommonUtil.createFolderPath(propertyUtil.getUploadPath() +path);return ExcelUtil.exportExcel(excelTitle, realPath, path, ProjectJson.class, projectService.getDownloadTemplate());
}