Browse Source

物计算日志导出内容调整

thing_master
siyang 1 year ago
parent
commit
1ec966a028
  1. 34
      modules/calculation/src/main/java/com/thing/calculation/excel/CalcLogExcel.java
  2. 18
      modules/calculation/src/main/java/com/thing/calculation/service/impl/CalcLogServiceImpl.java

34
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 cn.afterturn.easypoi.excel.annotation.Excel;
import com.thing.calculation.dto.CalcLogDTO; 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.ConvertUtils;
import com.thing.common.core.utils.DateTimeUtils; import com.thing.common.core.utils.DateTimeUtils;
import lombok.Data; import lombok.Data;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -27,10 +22,10 @@ public class CalcLogExcel {
@Excel(name = "计算类型", orderNum = "1") @Excel(name = "计算类型", orderNum = "1")
private String calcType; private String calcType;
@Excel(name = "结果物名称", orderNum = "2", width = 18)
@Excel(name = "结果物名称", orderNum = "2", width = 25)
private String targetThingName; private String targetThingName;
@Excel(name = "结果物编码", orderNum = "3", width = 18)
@Excel(name = "结果物编码", orderNum = "3", width = 25)
private String targetThingCode; private String targetThingCode;
@Excel(name = "结果属性名称", orderNum = "4", width = 18) @Excel(name = "结果属性名称", orderNum = "4", width = 18)
@ -39,23 +34,34 @@ public class CalcLogExcel {
@Excel(name = "结果属性编码", orderNum = "5", width = 15) @Excel(name = "结果属性编码", orderNum = "5", width = 15)
private String targetAttrCode; 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; private String errorInfo;
@Excel(name = "计算生成事件", orderNum = "7", width = 18)
@Excel(name = "计算生成时间", orderNum = "11", width = 18)
private String createTime; private String createTime;
@Excel(name = "数据异常时间", orderNum = "8", width = 18)
@Excel(name = "数据异常时间", orderNum = "12", width = 18)
private String dataTime; private String dataTime;
public static List<CalcLogExcel> convertFromDTO(List<CalcLogDTO> dtoList) {
return dtoList.stream().map(CalcLogExcel::convertFromDTO).collect(Collectors.toList());
public static List<CalcLogExcel> convertFromDTO(List<CalcLogDTO> dtoList, Map<Long, Integer> 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<Long, Integer> calcTypeMap) {
CalcLogExcel excel = ConvertUtils.sourceToTarget(dto, CalcLogExcel.class); CalcLogExcel excel = ConvertUtils.sourceToTarget(dto, CalcLogExcel.class);
Integer calcType = calcTypeMap.get(dto.getCalcTargetConfigId());
excel.setCreateTime(DateTimeUtils.timestamp2Str(dto.getCreateDate())); excel.setCreateTime(DateTimeUtils.timestamp2Str(dto.getCreateDate()));
excel.setDataTime(DateTimeUtils.timestamp2Str(dto.getTime())); excel.setDataTime(DateTimeUtils.timestamp2Str(dto.getTime()));
excel.setCalcType(CalcConfigType.getNameByCode(calcType));
return excel; return excel;
} }
} }

18
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.excel.CalcLogExcel;
import com.thing.calculation.mapper.CalcLogMapper; import com.thing.calculation.mapper.CalcLogMapper;
import com.thing.calculation.service.CalcLogService; 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.utils.excel.ExcelUtils;
import com.thing.common.core.web.response.PageData; import com.thing.common.core.web.response.PageData;
import com.thing.common.orm.service.impl.BaseServiceImpl; import com.thing.common.orm.service.impl.BaseServiceImpl;
import com.thing.sys.security.context.UserContext; import com.thing.sys.security.context.UserContext;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections4.MapUtils; import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
/** /**
* 物计算日志表 * 物计算日志表
@ -37,8 +39,9 @@ import java.util.*;
* @since 5.1 2024-02-27 * @since 5.1 2024-02-27
*/ */
@Service @Service
@RequiredArgsConstructor
public class CalcLogServiceImpl extends BaseServiceImpl<CalcLogMapper, CalcLogEntity> implements CalcLogService { public class CalcLogServiceImpl extends BaseServiceImpl<CalcLogMapper, CalcLogEntity> implements CalcLogService {
@Resource @Lazy
private CalcTargetConfigService targetConfigService;
/** 日志过期时间跨度 */ /** 日志过期时间跨度 */
private static final Long TIMEOUT_INTERVAL = 1000 * 60 * 60 * 24 * 7L; private static final Long TIMEOUT_INTERVAL = 1000 * 60 * 60 * 24 * 7L;
@ -153,7 +156,14 @@ public class CalcLogServiceImpl extends BaseServiceImpl<CalcLogMapper, CalcLogEn
@Override @Override
public void exportExcel(Map<String, Object> params, HttpServletResponse response) { public void exportExcel(Map<String, Object> params, HttpServletResponse response) {
List<CalcLogDTO> logs = listAs(getWrapper(params), CalcLogDTO.class); List<CalcLogDTO> logs = listAs(getWrapper(params), CalcLogDTO.class);
List<CalcLogExcel> excels = CalcLogExcel.convertFromDTO(logs);
List<CalcTargetConfigDTO> configs = targetConfigService.getAllEnabled();
Map<Long, Integer> calcTypeMap =
configs.stream()
.collect(
Collectors.toMap(
CalcTargetConfigDTO::getId,
CalcTargetConfigDTO::getConfigType));
List<CalcLogExcel> excels = CalcLogExcel.convertFromDTO(logs, calcTypeMap);
ExcelUtils.exportExcel(excels, null, "物计算异常记录", CalcLogExcel.class, "物计算异常记录.xls", response); ExcelUtils.exportExcel(excels, null, "物计算异常记录", CalcLogExcel.class, "物计算异常记录.xls", response);
} }

Loading…
Cancel
Save