|
|
@@ -1,5 +1,6 @@
|
|
|
package cn.iocoder.yudao.module.pms.controller.admin.qhse.measure;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
|
|
|
import cn.iocoder.yudao.framework.common.exception.ErrorCode;
|
|
|
import cn.iocoder.yudao.framework.common.exception.ServiceException;
|
|
|
@@ -11,12 +12,15 @@ import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.qhse.measure.vo.IotMeasureBookPageReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.qhse.measure.vo.IotMeasureBookRespVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.qhse.measure.vo.IotMeasureBookSaveReqVO;
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.qhse.measure.vo.QhseMeasureExportVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.stat.DeptUtil;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.qhse.measure.IotMeasureBookDO;
|
|
|
+import cn.iocoder.yudao.module.pms.dal.dataobject.qhse.measure.IotMeasureDetectDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.qhse.measure.IotMeasureBookMapper;
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.qhse.measure.IotMeasureDetectMapper;
|
|
|
import cn.iocoder.yudao.module.pms.service.qhse.ChineseLetterUtil;
|
|
|
import cn.iocoder.yudao.module.pms.service.qhse.measure.IotMeasureBookService;
|
|
|
+import cn.iocoder.yudao.module.pms.service.qhse.measure.IotMeasureDetectService;
|
|
|
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
|
|
|
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
|
|
|
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserImportRespVO;
|
|
|
@@ -41,6 +45,7 @@ import javax.annotation.security.PermitAll;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.validation.Valid;
|
|
|
import java.io.IOException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -70,6 +75,8 @@ public class IotMeasureBookController {
|
|
|
private DeptUtil deptUtil;
|
|
|
@Autowired
|
|
|
private IotMeasureDetectMapper iotMeasureDetectMapper;
|
|
|
+ @Autowired
|
|
|
+ private IotMeasureDetectService iotMeasureDetectService;
|
|
|
|
|
|
@PostMapping("/create")
|
|
|
@Operation(summary = "创建计量器具台账")
|
|
|
@@ -145,13 +152,73 @@ public class IotMeasureBookController {
|
|
|
@Operation(summary = "导出计量器具台账 Excel")
|
|
|
@PreAuthorize("@ss.hasPermission('rq:iot-measure-book:export')")
|
|
|
@ApiAccessLog(operateType = EXPORT)
|
|
|
- public void exportIotMeasureBookExcel(@Valid IotMeasureBookPageReqVO pageReqVO,
|
|
|
- HttpServletResponse response) throws IOException {
|
|
|
+ public void exportIotMeasureBookExcel(@Valid IotMeasureBookPageReqVO pageReqVO, HttpServletResponse response) throws IOException {
|
|
|
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
|
|
List<IotMeasureBookDO> list = iotMeasureBookService.getIotMeasureBookPage(pageReqVO).getList();
|
|
|
+ // 转换VO
|
|
|
+ List<QhseMeasureExportVO> results = BeanUtils.toBean(list, QhseMeasureExportVO.class);
|
|
|
+ // 一次性查询所有检测记录
|
|
|
+ List<IotMeasureDetectDO> allDetectList = iotMeasureDetectMapper.selectList();
|
|
|
+ List<DictDataDO> dictType = dictDataService.getDictDataListByDictType("measure_type");
|
|
|
+ // 优化:按 measureId 分组,避免循环反复filter
|
|
|
+ Map<Long, List<IotMeasureDetectDO>> detectGroupMap = allDetectList.stream()
|
|
|
+ .collect(Collectors.groupingBy(IotMeasureDetectDO::getMeasureId));
|
|
|
+
|
|
|
+ // 统一日期格式化器(提取到循环外)
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ List<DeptRespDTO> deptList = deptApi.getDeptList();
|
|
|
+
|
|
|
+ results.forEach(e -> {
|
|
|
+ dictType.stream().filter(g -> g.getValue().equals(e.getClassify())).findAny().ifPresent(g->{
|
|
|
+ e.setClassify(g.getLabel());
|
|
|
+ });
|
|
|
+ deptList.stream().filter(g ->g.getId().equals(e.getDeptId())).findAny().ifPresent(g->{
|
|
|
+ e.setDeptName(g.getName());
|
|
|
+ });
|
|
|
+ String buyDateStr = null;
|
|
|
+ String buyDate = e.getBuyDate();
|
|
|
+ if (StringUtils.isNotBlank(buyDate)) {
|
|
|
+ try {
|
|
|
+ long timeStamp = Long.parseLong(buyDate);
|
|
|
+ Date date = new Date(timeStamp);
|
|
|
+ buyDate = sdf.format(date);
|
|
|
+ } catch (NumberFormatException ex) {
|
|
|
+ // 时间戳格式非法,忽略
|
|
|
+ }
|
|
|
+ }
|
|
|
+ e.setBuyDate(buyDate);
|
|
|
+ // 根据id获取对应检测记录
|
|
|
+ List<IotMeasureDetectDO> detectDOS = detectGroupMap.get(e.getId());
|
|
|
+ if (CollUtil.isEmpty(detectDOS)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 取创建时间最新一条
|
|
|
+ detectDOS.stream()
|
|
|
+ .max(Comparator.comparing(IotMeasureDetectDO::getCreateTime))
|
|
|
+ .ifPresent(latestDetect -> {
|
|
|
+ String detectDateStr = null;
|
|
|
+ String detectDate = latestDetect.getDetectDate();
|
|
|
+ if (StringUtils.isNotBlank(detectDate)) {
|
|
|
+ try {
|
|
|
+ long timeStamp = Long.parseLong(detectDate);
|
|
|
+ Date date = new Date(timeStamp);
|
|
|
+ detectDateStr = sdf.format(date);
|
|
|
+ } catch (NumberFormatException ex) {
|
|
|
+ // 时间戳格式非法,忽略
|
|
|
+ }
|
|
|
+ }
|
|
|
+ e.setDetectDate(detectDateStr);
|
|
|
+ e.setDetectOrg(latestDetect.getDetectOrg());
|
|
|
+ e.setDetectContent(latestDetect.getDetectContent());
|
|
|
+ e.setValidityPeriod(latestDetect.getValidityPeriod());
|
|
|
+ e.setDetectAmount(latestDetect.getDetectAmount());
|
|
|
+ e.setMeasureCertNo(latestDetect.getMeasureCertNo());
|
|
|
+ e.setDetectStandard(latestDetect.getDetectStandard());
|
|
|
+ });
|
|
|
+ // 删掉原来的 results.add(e); 这一行是报错根源
|
|
|
+ });
|
|
|
// 导出 Excel
|
|
|
- ExcelUtils.write(response, "计量器具台账.xls", "数据", IotMeasureBookRespVO.class,
|
|
|
- BeanUtils.toBean(list, IotMeasureBookRespVO.class));
|
|
|
+ ExcelUtils.write(response, "计量器具台账.xls", "数据", QhseMeasureExportVO.class, results);
|
|
|
}
|
|
|
|
|
|
|