diff --git a/modules/calculation/src/main/java/com/thing/calculation/excel/CalcLogExcel.java b/modules/calculation/src/main/java/com/thing/calculation/excel/CalcLogExcel.java index 3aa5407..3026d42 100644 --- a/modules/calculation/src/main/java/com/thing/calculation/excel/CalcLogExcel.java +++ b/modules/calculation/src/main/java/com/thing/calculation/excel/CalcLogExcel.java @@ -3,19 +3,14 @@ package com.thing.calculation.excel; import cn.afterturn.easypoi.excel.annotation.Excel; import com.thing.calculation.dto.CalcLogDTO; -import com.thing.calculation.dto.CalcSourceConfigDTO; -import com.thing.calculation.dto.CalcTargetConfigDTO; -import com.thing.calculation.enumeration.CalcConfigType; +import com.thing.calculation.enumeration.CalcConfigType; import com.thing.common.core.utils.ConvertUtils; import com.thing.common.core.utils.DateTimeUtils; import lombok.Data; -import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.function.Function; import java.util.stream.Collectors; /** @@ -27,10 +22,10 @@ public class CalcLogExcel { @Excel(name = "计算类型", orderNum = "1") private String calcType; - @Excel(name = "结果物名称", orderNum = "2", width = 18) + @Excel(name = "结果物名称", orderNum = "2", width = 25) private String targetThingName; - @Excel(name = "结果物编码", orderNum = "3", width = 18) + @Excel(name = "结果物编码", orderNum = "3", width = 25) private String targetThingCode; @Excel(name = "结果属性名称", orderNum = "4", width = 18) @@ -39,23 +34,34 @@ public class CalcLogExcel { @Excel(name = "结果属性编码", orderNum = "5", width = 15) private String targetAttrCode; - @Excel(name = "异常信息", orderNum = "6", width = 20) + @Excel(name = "计算结果", orderNum = "7", width = 18) + private String result; + + @Excel(name = "计算公式", orderNum = "8", width = 20) + private String formula; + + @Excel(name = "计算参数", orderNum = "9", width = 65) + private String sourceInfo; + + @Excel(name = "异常信息", orderNum = "10", width = 20) private String errorInfo; - @Excel(name = "计算生成事件", orderNum = "7", width = 18) + @Excel(name = "计算生成时间", orderNum = "11", width = 18) private String createTime; - @Excel(name = "数据异常时间", orderNum = "8", width = 18) + @Excel(name = "数据异常时间", orderNum = "12", width = 18) private String dataTime; - public static List convertFromDTO(List dtoList) { - return dtoList.stream().map(CalcLogExcel::convertFromDTO).collect(Collectors.toList()); + public static List convertFromDTO(List dtoList, Map calcTypeMap) { + return dtoList.stream().map(e -> convertFromDTO(e, calcTypeMap)).collect(Collectors.toList()); } - private static CalcLogExcel convertFromDTO(CalcLogDTO dto) { + private static CalcLogExcel convertFromDTO(CalcLogDTO dto, Map calcTypeMap) { CalcLogExcel excel = ConvertUtils.sourceToTarget(dto, CalcLogExcel.class); + Integer calcType = calcTypeMap.get(dto.getCalcTargetConfigId()); excel.setCreateTime(DateTimeUtils.timestamp2Str(dto.getCreateDate())); excel.setDataTime(DateTimeUtils.timestamp2Str(dto.getTime())); + excel.setCalcType(CalcConfigType.getNameByCode(calcType)); return excel; } } diff --git a/modules/calculation/src/main/java/com/thing/calculation/service/impl/CalcLogServiceImpl.java b/modules/calculation/src/main/java/com/thing/calculation/service/impl/CalcLogServiceImpl.java index 6389dd2..e64bbbd 100644 --- a/modules/calculation/src/main/java/com/thing/calculation/service/impl/CalcLogServiceImpl.java +++ b/modules/calculation/src/main/java/com/thing/calculation/service/impl/CalcLogServiceImpl.java @@ -14,21 +14,23 @@ import com.thing.calculation.enumeration.CalcStatus; import com.thing.calculation.excel.CalcLogExcel; import com.thing.calculation.mapper.CalcLogMapper; import com.thing.calculation.service.CalcLogService; +import com.thing.calculation.service.CalcTargetConfigService; import com.thing.common.core.utils.excel.ExcelUtils; import com.thing.common.core.web.response.PageData; import com.thing.common.orm.service.impl.BaseServiceImpl; import com.thing.sys.security.context.UserContext; +import jakarta.annotation.Resource; import jakarta.servlet.http.HttpServletResponse; -import lombok.RequiredArgsConstructor; - import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import java.util.*; +import java.util.stream.Collectors; /** * 物计算日志表 @@ -37,8 +39,9 @@ import java.util.*; * @since 5.1 2024-02-27 */ @Service -@RequiredArgsConstructor public class CalcLogServiceImpl extends BaseServiceImpl implements CalcLogService { + @Resource @Lazy + private CalcTargetConfigService targetConfigService; /** 日志过期时间跨度 */ private static final Long TIMEOUT_INTERVAL = 1000 * 60 * 60 * 24 * 7L; @@ -153,7 +156,14 @@ public class CalcLogServiceImpl extends BaseServiceImpl params, HttpServletResponse response) { List logs = listAs(getWrapper(params), CalcLogDTO.class); - List excels = CalcLogExcel.convertFromDTO(logs); + List configs = targetConfigService.getAllEnabled(); + Map calcTypeMap = + configs.stream() + .collect( + Collectors.toMap( + CalcTargetConfigDTO::getId, + CalcTargetConfigDTO::getConfigType)); + List excels = CalcLogExcel.convertFromDTO(logs, calcTypeMap); ExcelUtils.exportExcel(excels, null, "物计算异常记录", CalcLogExcel.class, "物计算异常记录.xls", response); }