中建五局-导出质量问题和整改记录excel

This commit is contained in:
Administrator 2023-04-24 16:12:42 +08:00
parent 2c950de383
commit 0b8ab8bff7
2 changed files with 76 additions and 40 deletions

View File

@ -58,8 +58,8 @@ public class QualityRectifyRecordController {
return Result.ok();
}
@ApiOperation(value = "导出质量问题和整改记录excel", notes = "导出质量问题和整改记录excel", httpMethod = "GET")
@GetMapping(value = "/recordRectify/excel/export")
@ApiOperation(value = "导出质量问题和整改记录excel", notes = "导出质量问题和整改记录excel", httpMethod = "POST")
@PostMapping(value = "/recordRectify/excel/export")
public void qualityInspectionRecordRectifyExportExcel(@RequestBody Map<String, Object> map, HttpServletResponse response) throws IOException {
qualityRectifyRecordService.qualityInspectionRecordRectifyExportExcel(map, response);
}

View File

@ -1,10 +1,15 @@
package com.zhgd.xmgl.modules.quality.service.impl;
import cn.afterturn.easypoi.entity.ImageEntity;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gexin.fastjson.JSON;
import com.gexin.fastjson.JSONArray;
import com.gexin.fastjson.JSONObject;
import com.zhgd.jeecg.common.mybatis.EntityMap;
import com.zhgd.xmgl.call.SanjiangDataCall;
import com.zhgd.xmgl.modules.basicdata.service.INoticeService;
@ -16,10 +21,10 @@ import com.zhgd.xmgl.modules.quality.service.IQualityInspectionRecordService;
import com.zhgd.xmgl.modules.quality.service.IQualityRectifyRecordService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Workbook;
import org.jeecgframework.poi.excel.ExcelExportUtil;
import org.jeecgframework.poi.excel.entity.TemplateExportParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -38,6 +43,8 @@ import java.util.stream.Collectors;
@Service
@Transactional(rollbackFor = Exception.class)
public class QualityRectifyRecordServiceImpl extends ServiceImpl<QualityRectifyRecordMapper, QualityRectifyRecord> implements IQualityRectifyRecordService {
@Value("${basePath}")
private String basePath;
@Autowired
IQualityInspectionRecordService qualityInspectionRecordService;
@Autowired
@ -100,40 +107,10 @@ public class QualityRectifyRecordServiceImpl extends ServiceImpl<QualityRectifyR
String templatePath = "zjwj/template/qualityInspectionRecordRectifyTemplate.xls";
String path = getClass().getClassLoader().getResource(templatePath).getPath();
TemplateExportParams params = new TemplateExportParams(path);
map.put("pageSize", Integer.MAX_VALUE);
Map<String, Object> recordPage = qualityInspectionRecordService.selectQualityInspectionRecordPage(map);
Page page = (Page) recordPage.get("page");
Map<String, Object> rtMap = new HashMap<String, Object>();
rtMap.put("createTime", DateUtil.format(new Date(), "yyyy年MM月dd日"));
List<Map<String, Object>> listMap = new ArrayList<Map<String, Object>>();
List<Map<String, Object>> records = page.getRecords();
List<String> idList = records.stream().map(m -> MapUtils.getString(m, "id")).collect(Collectors.toList());
List<QualityRectifyRecord> qualityRectifyRecords = qualityRectifyRecordMapper.selectList(new LambdaQueryWrapper<QualityRectifyRecord>().eq(QualityRectifyRecord::getType, 1)
.in(QualityRectifyRecord::getQualityId, idList));
Map<Long, List<QualityRectifyRecord>> idQualityRectifyRecordListMap = qualityRectifyRecords.stream().collect(Collectors.groupingBy(QualityRectifyRecord::getQualityId));
int k = 1;
for (int i = 1; i <= page.getTotal(); i++) {
Map<String, Object> rM = records.get(i - 1);
List<QualityRectifyRecord> list = idQualityRectifyRecordListMap.get(MapUtils.getString(rM, "id"));
int j = 0;
do {
QualityRectifyRecord rectifyRecord = list.get(j);
Map<String, Object> lm = new HashMap<String, Object>();
lm.put("no", k);
lm.put("danger", MapUtils.getString(rM, "regionName") + "" + MapUtils.getString(rM, "dangerItemContent"));
lm.put("dangerPic", getImageEntity(MapUtils.getString(rM, "imageUrl")));
lm.put("rectifyCompleteTime", DateUtil.format(DateUtil.parse(rectifyRecord.getRectifyTime()), "yyyy年MM月dd日"));
lm.put("rectifyReply", i);
lm.put("remark", rectifyRecord.getAdditionalRemarks());
listMap.add(lm);
j++;
k++;
} while (j < list.size());
}
rtMap.put("list", listMap);
Workbook workbook = ExcelExportUtil.exportExcel(params, map);
rtMap.put("list", getRecordMapList(map, rtMap));
Workbook workbook = ExcelExportUtil.exportExcel(params, rtMap);
//准备将Excel的输出流通过response输出到页面下载
//八进制输出流
@ -149,11 +126,70 @@ public class QualityRectifyRecordServiceImpl extends ServiceImpl<QualityRectifyR
workbook.write(response.getOutputStream());
}
private ImageEntity getImageEntity(String imageUrl) {
private List<Map<String, Object>> getRecordMapList(Map<String, Object> map, Map<String, Object> rtMap) {
map.put("pageSize", Integer.MAX_VALUE);
Map<String, Object> recordPage = qualityInspectionRecordService.selectQualityInspectionRecordPage(map);
Page page = (Page) recordPage.get("page");
List<Map<String, Object>> listMap = new ArrayList<Map<String, Object>>();
List<Map<String, Object>> records = page.getRecords();
if (CollectionUtils.isEmpty(records)) {
return null;
}
List<String> idList = records.stream().map(m -> MapUtils.getString(m, "id")).collect(Collectors.toList());
List<QualityRectifyRecord> qualityRectifyRecords = qualityRectifyRecordMapper.selectList(new LambdaQueryWrapper<QualityRectifyRecord>().eq(QualityRectifyRecord::getType, 1)
.in(QualityRectifyRecord::getQualityId, idList));
Map<Long, List<QualityRectifyRecord>> idQualityRectifyRecordListMap = qualityRectifyRecords.stream().collect(Collectors.groupingBy(QualityRectifyRecord::getQualityId));
int k = 1;
for (int i = 1; i <= page.getTotal(); i++) {
Map<String, Object> rM = records.get(i - 1);
List<QualityRectifyRecord> list = idQualityRectifyRecordListMap.get(MapUtils.getString(rM, "id"));
int j = 0;
do {
Map<String, Object> lm = new HashMap<String, Object>();
lm.put("no", k);
lm.put("danger", MapUtils.getString(rM, "regionName") + "" + MapUtils.getString(rM, "dangerItemContent"));
lm.put("dangerPic", getImageEntityByQualityInspectionRecordImage(MapUtils.getString(rM, "imageUrl")));
if (CollectionUtils.isNotEmpty(list)) {
QualityRectifyRecord rectifyRecord = list.get(j);
lm.put("rectifyCompleteTime", DateUtil.format(DateUtil.parse(rectifyRecord.getRectifyTime()), "yyyy年MM月dd日"));
lm.put("rectifyReply", getImageEntityByRectifyImg(rectifyRecord.getFileUrl()));
lm.put("remark", rectifyRecord.getAdditionalRemarks());
}
listMap.add(lm);
j++;
k++;
} while (CollectionUtils.isNotEmpty(list) && j < list.size());
}
return listMap;
}
private ImageEntity getImageEntityByQualityInspectionRecordImage(String imageUrl) {
if (StringUtils.isBlank(imageUrl)) {
return null;
}
String[] split = StringUtils.split(imageUrl, "*");
String fileName = split[0];
ImageEntity image = new ImageEntity();
image.setHeight(1000);
image.setWidth(2500);
image.setUrl("image/" + imageUrl);
image.setHeight(100);
image.setWidth(250);
image.setUrl(basePath + fileName);
return image;
}
private ImageEntity getImageEntityByRectifyImg(String imageUrl) {
if (StringUtils.isBlank(imageUrl)) {
return null;
}
JSONArray array = JSON.parseArray(imageUrl);
for (Object o : array) {
JSONObject jsonObject = JSON.parseObject(String.valueOf(o));
String fileName = (String) jsonObject.get("name");
ImageEntity image = new ImageEntity();
image.setHeight(100);
image.setWidth(250);
image.setUrl(basePath + fileName);
return image;
}
return null;
}
}