|
|
|
|
@ -197,64 +197,94 @@ public class MaintenanceTaskDetailServiceImpl extends BaseServiceImpl<Maintenanc |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void batchMaintenanceOutputService(List<MaintenanceTask> taskList, HttpServletResponse response) throws IOException { |
|
|
|
|
for (MaintenanceTask task : taskList) { |
|
|
|
|
//数据获取
|
|
|
|
|
String templateFile = "MaintenanceTaskReport.xlsx"; |
|
|
|
|
InputStream fileInputStream = this.getClass().getClassLoader().getResourceAsStream("excel" + "/" + templateFile); |
|
|
|
|
FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build(); |
|
|
|
|
Map<String, Object> map0 = new HashMap<>(); |
|
|
|
|
map0.put("taskName", task.getDeptName()); |
|
|
|
|
String period = baseMapper.findPeriod(); |
|
|
|
|
map0.put("period",period + "度报告"); |
|
|
|
|
map0.put("time", DateFormatUtils.format(task.getFinishTime(),"yyyy年MM月dd日")); |
|
|
|
|
map0.put("taskCode", task.getTaskCode()); |
|
|
|
|
|
|
|
|
|
Map<String, Object> map1 = new HashMap<>(); |
|
|
|
|
map1.put("taskName", task.getDeptName()); |
|
|
|
|
map1.put("address", task.getDeptName()); |
|
|
|
|
map1.put("taskContent", task.getTaskContent()); |
|
|
|
|
|
|
|
|
|
Map<String, Object> map2 = new HashMap<>(); |
|
|
|
|
map2.put("taskName", task.getDeptName()); |
|
|
|
|
map2.put("address", task.getDeptName()); |
|
|
|
|
map2.put("inspectionConclusion", task.getInspectionConclusion()); |
|
|
|
|
map2.put("signatureTime",task.getSignatureTime() != null ? DateFormatUtils.format(task.getSignatureTime(),"yyyy年MM月dd日"): ""); |
|
|
|
|
|
|
|
|
|
//获取客户联系人、联系电话
|
|
|
|
|
Map<String,String> cusMap = baseMapper.getDeptContact(task.getDeptId()); |
|
|
|
|
if(CollectionUtils.isNotEmpty(cusMap)){ |
|
|
|
|
map2.put("contact",cusMap.get("name")); //联系人
|
|
|
|
|
map2.put("phone",cusMap.get("phone")); //联系方式
|
|
|
|
|
} |
|
|
|
|
try(ZipOutputStream zos = new ZipOutputStream(response.getOutputStream())){ |
|
|
|
|
for (MaintenanceTask task : taskList) { |
|
|
|
|
//数据获取
|
|
|
|
|
String templateFile = "MaintenanceTaskReport.xlsx"; |
|
|
|
|
InputStream fileInputStream = this.getClass().getClassLoader().getResourceAsStream("excel" + "/" + templateFile); |
|
|
|
|
FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build(); |
|
|
|
|
Map<String, Object> map0 = new HashMap<>(); |
|
|
|
|
map0.put("taskName", task.getDeptName()); |
|
|
|
|
String period = baseMapper.findPeriod(); |
|
|
|
|
map0.put("period",period + "度报告"); |
|
|
|
|
map0.put("time", DateFormatUtils.format(task.getFinishTime(),"yyyy年MM月dd日")); |
|
|
|
|
map0.put("taskCode", task.getTaskCode()); |
|
|
|
|
|
|
|
|
|
Map<String, Object> map1 = new HashMap<>(); |
|
|
|
|
map1.put("taskName", task.getDeptName()); |
|
|
|
|
map1.put("address", task.getDeptName()); |
|
|
|
|
map1.put("taskContent", task.getTaskContent()); |
|
|
|
|
|
|
|
|
|
Map<String, Object> map2 = new HashMap<>(); |
|
|
|
|
map2.put("taskName", task.getDeptName()); |
|
|
|
|
map2.put("address", task.getDeptName()); |
|
|
|
|
map2.put("inspectionConclusion", task.getInspectionConclusion()); |
|
|
|
|
map2.put("signatureTime",task.getSignatureTime() != null ? DateFormatUtils.format(task.getSignatureTime(),"yyyy年MM月dd日"): ""); |
|
|
|
|
|
|
|
|
|
//获取客户联系人、联系电话
|
|
|
|
|
Map<String,String> cusMap = baseMapper.getDeptContact(task.getDeptId()); |
|
|
|
|
if(CollectionUtils.isNotEmpty(cusMap)){ |
|
|
|
|
map2.put("contact",cusMap.get("name")); //联系人
|
|
|
|
|
map2.put("phone",cusMap.get("phone")); //联系方式
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
List<MaintenanceTaskDetail> maintenanceTaskDetailList = baseMapper.selectList(Wrappers.lambdaQuery(MaintenanceTaskDetail.class).eq(MaintenanceTaskDetail::getTaskId, task.getId())); |
|
|
|
|
List<MaintenanceOutputData> maintenanceOutputDataList = new ArrayList<>(); |
|
|
|
|
List<MaintenanceOutputData> maintenanceOutputDataList1 = new ArrayList<>(); |
|
|
|
|
long no = 0; |
|
|
|
|
long no1 = 0; |
|
|
|
|
for (MaintenanceTaskDetail maintenanceTaskDetail : maintenanceTaskDetailList) { |
|
|
|
|
no++; |
|
|
|
|
MaintenanceOutputData maintenanceOutputData = new MaintenanceOutputData(); |
|
|
|
|
maintenanceOutputData.setNo(no); |
|
|
|
|
maintenanceOutputData.setFloor(maintenanceTaskDetail.getFloorName()); |
|
|
|
|
maintenanceOutputData.setDeptName(maintenanceTaskDetail.getDeptName()); |
|
|
|
|
maintenanceOutputData.setMajorName(maintenanceTaskDetail.getMajorName()); |
|
|
|
|
maintenanceOutputData.setCheckContent(maintenanceTaskDetail.getCheckContent()); |
|
|
|
|
Optional<Integer> status = Optional.ofNullable(maintenanceTaskDetail.getStatus()); |
|
|
|
|
if (status.isPresent()) { |
|
|
|
|
if (status.get() == 1) { |
|
|
|
|
maintenanceOutputData.setStatus("异常"); |
|
|
|
|
List<MaintenanceTaskDetail> maintenanceTaskDetailList = baseMapper.selectList(Wrappers.lambdaQuery(MaintenanceTaskDetail.class).eq(MaintenanceTaskDetail::getTaskId, task.getId())); |
|
|
|
|
List<MaintenanceOutputData> maintenanceOutputDataList = new ArrayList<>(); |
|
|
|
|
List<MaintenanceOutputData> maintenanceOutputDataList1 = new ArrayList<>(); |
|
|
|
|
long no = 0; |
|
|
|
|
long no1 = 0; |
|
|
|
|
for (MaintenanceTaskDetail maintenanceTaskDetail : maintenanceTaskDetailList) { |
|
|
|
|
no++; |
|
|
|
|
MaintenanceOutputData maintenanceOutputData = new MaintenanceOutputData(); |
|
|
|
|
maintenanceOutputData.setNo(no); |
|
|
|
|
maintenanceOutputData.setFloor(maintenanceTaskDetail.getFloorName()); |
|
|
|
|
maintenanceOutputData.setDeptName(maintenanceTaskDetail.getDeptName()); |
|
|
|
|
maintenanceOutputData.setMajorName(maintenanceTaskDetail.getMajorName()); |
|
|
|
|
maintenanceOutputData.setCheckContent(maintenanceTaskDetail.getCheckContent()); |
|
|
|
|
Optional<Integer> status = Optional.ofNullable(maintenanceTaskDetail.getStatus()); |
|
|
|
|
if (status.isPresent()) { |
|
|
|
|
if (status.get() == 1) { |
|
|
|
|
maintenanceOutputData.setStatus("异常"); |
|
|
|
|
} |
|
|
|
|
if (status.get() == 0) { |
|
|
|
|
maintenanceOutputData.setStatus("正常"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (status.get() == 0) { |
|
|
|
|
maintenanceOutputData.setStatus("正常"); |
|
|
|
|
maintenanceOutputData.setRemark(maintenanceTaskDetail.getRemark()); |
|
|
|
|
maintenanceOutputData.setSignature(task.getSignUrl()); |
|
|
|
|
if (StringUtils.isNotBlank(maintenanceTaskDetail.getPicUrl())) { |
|
|
|
|
try { |
|
|
|
|
//获取图片
|
|
|
|
|
URL url = new URL(maintenanceTaskDetail.getPicUrl()); |
|
|
|
|
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection(); |
|
|
|
|
httpURLConnection.setRequestMethod("GET"); |
|
|
|
|
httpURLConnection.setDoInput(true); |
|
|
|
|
InputStream inputStream = httpURLConnection.getInputStream(); |
|
|
|
|
BufferedImage image = ImageIO.read(inputStream); |
|
|
|
|
ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream(); |
|
|
|
|
ImageIO.write(image, "png", arrayOutputStream); |
|
|
|
|
byte[] bytes = arrayOutputStream.toByteArray(); |
|
|
|
|
maintenanceOutputData.setImage1(bytes); |
|
|
|
|
arrayOutputStream.close(); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
maintenanceOutputData.setImage1(null); |
|
|
|
|
} |
|
|
|
|
maintenanceOutputDataList.add(maintenanceOutputData); |
|
|
|
|
if(maintenanceTaskDetail.getStatus() == 1){ |
|
|
|
|
no1++; |
|
|
|
|
MaintenanceOutputData maintenanceOutputData1 = BeanUtil.copyProperties(maintenanceOutputData,MaintenanceOutputData.class); |
|
|
|
|
maintenanceOutputData1.setNo(no1); |
|
|
|
|
maintenanceOutputDataList1.add(maintenanceOutputData1); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
maintenanceOutputData.setRemark(maintenanceTaskDetail.getRemark()); |
|
|
|
|
maintenanceOutputData.setSignature(task.getSignUrl()); |
|
|
|
|
if (StringUtils.isNotBlank(maintenanceTaskDetail.getPicUrl())) { |
|
|
|
|
//获取签字图片
|
|
|
|
|
if (StringUtils.isNotBlank(task.getSignatureUrl())) { |
|
|
|
|
try { |
|
|
|
|
//获取图片
|
|
|
|
|
URL url = new URL(maintenanceTaskDetail.getPicUrl()); |
|
|
|
|
URL url = new URL(task.getSignatureUrl()); |
|
|
|
|
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection(); |
|
|
|
|
httpURLConnection.setRequestMethod("GET"); |
|
|
|
|
httpURLConnection.setDoInput(true); |
|
|
|
|
@ -263,67 +293,42 @@ public class MaintenanceTaskDetailServiceImpl extends BaseServiceImpl<Maintenanc |
|
|
|
|
ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream(); |
|
|
|
|
ImageIO.write(image, "png", arrayOutputStream); |
|
|
|
|
byte[] bytes = arrayOutputStream.toByteArray(); |
|
|
|
|
maintenanceOutputData.setImage1(bytes); |
|
|
|
|
Double width = Double.valueOf(image.getWidth()); |
|
|
|
|
Double height = Double.valueOf(image.getHeight()); |
|
|
|
|
WriteCellData<Void> voidWriteCellData = TemplateExcelUtils.imageCells(bytes, width, height, 0.6, 1.9); |
|
|
|
|
map2.put("image", voidWriteCellData); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
maintenanceOutputData.setImage1(null); |
|
|
|
|
} |
|
|
|
|
maintenanceOutputDataList.add(maintenanceOutputData); |
|
|
|
|
if(maintenanceTaskDetail.getStatus() == 1){ |
|
|
|
|
no1++; |
|
|
|
|
MaintenanceOutputData maintenanceOutputData1 = BeanUtil.copyProperties(maintenanceOutputData,MaintenanceOutputData.class); |
|
|
|
|
maintenanceOutputData1.setNo(no1); |
|
|
|
|
maintenanceOutputDataList1.add(maintenanceOutputData1); |
|
|
|
|
map2.put("image",null); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//获取签字图片
|
|
|
|
|
if (StringUtils.isNotBlank(task.getSignatureUrl())) { |
|
|
|
|
try { |
|
|
|
|
//获取图片
|
|
|
|
|
URL url = new URL(task.getSignatureUrl()); |
|
|
|
|
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection(); |
|
|
|
|
httpURLConnection.setRequestMethod("GET"); |
|
|
|
|
httpURLConnection.setDoInput(true); |
|
|
|
|
InputStream inputStream = httpURLConnection.getInputStream(); |
|
|
|
|
BufferedImage image = ImageIO.read(inputStream); |
|
|
|
|
ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream(); |
|
|
|
|
ImageIO.write(image, "png", arrayOutputStream); |
|
|
|
|
byte[] bytes = arrayOutputStream.toByteArray(); |
|
|
|
|
Double width = Double.valueOf(image.getWidth()); |
|
|
|
|
Double height = Double.valueOf(image.getHeight()); |
|
|
|
|
WriteCellData<Void> voidWriteCellData = TemplateExcelUtils.imageCells(bytes, width, height, 0.6, 1.9); |
|
|
|
|
map2.put("image", voidWriteCellData); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
//将数据导出到Excel
|
|
|
|
|
String fileName = task.getTaskCode() + "巡检报告.xlsx"; |
|
|
|
|
zos.putNextEntry(new ZipEntry(fileName)); |
|
|
|
|
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); |
|
|
|
|
try (ExcelWriter excelWriter = EasyExcel.write(byteArrayOutputStream).withTemplate(fileInputStream).build()) { |
|
|
|
|
WriteSheet writeSheet0 = EasyExcel.writerSheet(0).build(); |
|
|
|
|
excelWriter.fill(map0, writeSheet0); |
|
|
|
|
|
|
|
|
|
WriteSheet writeSheet1 = EasyExcel.writerSheet(1).build(); |
|
|
|
|
excelWriter.fill(maintenanceOutputDataList, fillConfig, writeSheet1); |
|
|
|
|
excelWriter.fill(map1, writeSheet1); |
|
|
|
|
|
|
|
|
|
WriteSheet writeSheet2 = EasyExcel.writerSheet(2).build(); |
|
|
|
|
excelWriter.fill(maintenanceOutputDataList1, fillConfig, writeSheet2); |
|
|
|
|
|
|
|
|
|
WriteSheet writeSheet3 = EasyExcel.writerSheet(3).build(); |
|
|
|
|
excelWriter.fill(map2, writeSheet3); |
|
|
|
|
|
|
|
|
|
excelWriter.finish(); |
|
|
|
|
byteArrayOutputStream.writeTo(zos); |
|
|
|
|
zos.closeEntry(); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
map2.put("image",null); |
|
|
|
|
} |
|
|
|
|
//将数据导出到Excel
|
|
|
|
|
ZipOutputStream zos = new ZipOutputStream(response.getOutputStream()); |
|
|
|
|
String fileName = task.getTaskCode() + "巡检报告.xlsx"; |
|
|
|
|
zos.putNextEntry(new ZipEntry(fileName)); |
|
|
|
|
try (ExcelWriter excelWriter = EasyExcel.write(zos).withTemplate(fileInputStream).build()) { |
|
|
|
|
WriteSheet writeSheet0 = EasyExcel.writerSheet(0).build(); |
|
|
|
|
excelWriter.fill(map0, writeSheet0); |
|
|
|
|
|
|
|
|
|
WriteSheet writeSheet1 = EasyExcel.writerSheet(1).build(); |
|
|
|
|
excelWriter.fill(maintenanceOutputDataList, fillConfig, writeSheet1); |
|
|
|
|
excelWriter.fill(map1, writeSheet1); |
|
|
|
|
|
|
|
|
|
WriteSheet writeSheet2 = EasyExcel.writerSheet(2).build(); |
|
|
|
|
excelWriter.fill(maintenanceOutputDataList1, fillConfig, writeSheet2); |
|
|
|
|
|
|
|
|
|
WriteSheet writeSheet3 = EasyExcel.writerSheet(3).build(); |
|
|
|
|
excelWriter.fill(map2, writeSheet3); |
|
|
|
|
|
|
|
|
|
excelWriter.finish(); |
|
|
|
|
zos.flush(); |
|
|
|
|
zos.closeEntry(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|