update 下载导出文件优化

master
yinq 2 months ago
parent d90abe1635
commit 15f0050c84

@ -19,8 +19,8 @@
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/sys-info.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
<!-- 日志最大的历史 30天 -->
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
@ -41,8 +41,8 @@
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/sys-error.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
<!-- 日志最大的历史 30天 -->
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
@ -63,8 +63,8 @@
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 按天回滚 daily -->
<fileNamePattern>${log.path}/sys-user.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
<!-- 日志最大的历史 30天 -->
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>

@ -15,12 +15,16 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.List;
/**
@ -124,6 +128,15 @@ public class KDocsApiController extends BaseController {
}
SysAttachInfo attachInfo = attachInfoList.get(0);
Instant now = Instant.now();
Instant expirationTime = attachInfo.getExpirationTime().toInstant();
if (now.isAfter(expirationTime)) {
DateTimeFormatter formatter = DateTimeFormatter
.ofPattern("yyyy-MM-dd HH:mm:ss")
.withZone(ZoneId.systemDefault());
String formattedTime = formatter.format(expirationTime);
throw new ServletException("此文件已过期(有效期至: " + formattedTime + "");
}
// 检查文件是否存在
File file = new File(attachInfo.getAttachAddress());
if (!file.exists()) {

@ -69,6 +69,27 @@ public class HwTagRecord extends BaseEntity
@Excel(name = "生产人员编号", type = Type.EXPORT)
private String operatorId;
/** 测试结果 */
// @Excel(name = "测试结果")
private String testResult;
/** 测试值 */
// @Excel(name = "测试值")
private String testValue;
/** 参考值 */
// @Excel(name = "参考值")
private String referenceValue;
/** 测试时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
// @Excel(name = "测试时间", width = 30, dateFormat = "yyyy-MM-dd")
private Date testingTime;
/** 导入文件名 */
// @Excel(name = "导入文件名")
private String fileName;
/** 数据状态标记 */
private Integer delFlag;

@ -5,16 +5,13 @@ import hw.tagApi.service.service.IHwTagRecordService;
import hw.tagApi.service.service.IKDocsService;
import hw.tagApi.service.utils.TagExcelUtil;
import hw.tagApi.service.utils.httpClientUtils;
import hw.tagApi.system.service.ISysAttachInfoService;
import java.time.Duration;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.*;
import hw.tagApi.service.constant.ApiConstants;
@ -25,7 +22,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import hw.tagApi.service.domain.ApiResponse;
import hw.tagApi.service.domain.ApiContent;
import org.springframework.util.StringUtils;
import java.util.Collections;
/**
*
@ -68,6 +64,7 @@ public class KDocsServiceImpl implements IKDocsService {
executorService.execute(() -> {
List<ApiContent> resList = new ArrayList<>();
for (ApiContent apiContent : contentList) {
long startTime = System.currentTimeMillis();
ApiContent resContent = new ApiContent();
resContent.setId(apiContent.getId());
try {
@ -82,7 +79,10 @@ public class KDocsServiceImpl implements IKDocsService {
resContent.setFields(errorFields);
}
resList.add(resContent);
long endTime = System.currentTimeMillis();
log.info("数据库导入完成 - ID: {}, 耗时: {}ms", apiContent.getId(), (endTime - startTime));
}
// 发送处理结果到回调接口
httpClientUtils.sendResultToCallback(resList, ApiConstants.IN_CALLBACK_URL);
});
@ -150,6 +150,8 @@ public class KDocsServiceImpl implements IKDocsService {
Map<String, String> orderInfo = (Map<String, String>) excelResult.get("orderInfo");
// 获取标签数据列表
List<Map<String, String>> tagList = (List<Map<String, String>>) excelResult.get("tagList");
// 获取文件名
String fileName = (String) excelResult.get("fileName");
// 批量处理标签数据
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
for (Map<String, String> tagData : tagList) {
@ -165,10 +167,11 @@ public class KDocsServiceImpl implements IKDocsService {
record.setTId(tagData.get("TID"));
record.setEpc(tagData.get("EPC"));
record.setPassword(tagData.get("密码"));
record.setFields1(tagData.get("测试结果"));
record.setFields2(tagData.get("测试值"));
record.setFields3(tagData.get("参考值"));
record.setRemark(tagData.get("测试时间"));
record.setTestResult(tagData.get("测试结果"));
record.setTestValue(tagData.get("测试值"));
record.setReferenceValue(tagData.get("参考值"));
record.setTestingTime(sdf.parse(tagData.get("测试时间")));
record.setFileName(fileName);
// 达到批量大小时执行插入
if ("更新".equals(importMode)) {
@ -395,8 +398,7 @@ public class KDocsServiceImpl implements IKDocsService {
log.info("执行数据导出查询 - ID: {}", condition.getId());
long startTime = System.currentTimeMillis();
List<HwTagRecord> records = tagRecordService.selectHwTagRecordList(queryCondition);
long endTime = System.currentTimeMillis();
log.info("查询完成 - ID: {}, 记录数: {}, 耗时: {}ms", condition.getId(), records.size(), (endTime - startTime));
Map<String, Object> responseFields = new HashMap<>();
@ -404,14 +406,22 @@ public class KDocsServiceImpl implements IKDocsService {
try {
String fileName = String.format("标签数据_%s.xlsx", condition.getId());
String filePath = TagExcelUtil.generateTagExcel(records, fileName);
long endTime = System.currentTimeMillis();
Duration duration = Duration.ofMillis(endTime - startTime);
long minutes = duration.toMinutes();
long seconds = duration.minusMinutes(minutes).getSeconds();
Date futureDate = new Date(endTime + ApiConstants.PASS_TIME);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
log.info("数据库导出完成 - ID: {}, 记录数: {}, 耗时: {}分{}秒", condition.getId(), records.size(), minutes, seconds);
responseFields.put("导出状态", "导出成功");
responseFields.put("情况说明", "耗时: " + minutes + "分" + seconds + "秒");
responseFields.put("文件路径", filePath);
responseFields.put("记录数量", records.size());
responseFields.put("链接有效期", sdf.format(futureDate));
log.info("导出文件生成成功 - ID: {}, 路径: {}", condition.getId(), filePath);
} catch (Exception e) {
log.error("生成导出文件失败 - ID: {}", condition.getId(), e);
responseFields.put("导出状态", "导出失败");
responseFields.put("错误信息", "生成导出文件失败: " + e.getMessage());
responseFields.put("情况说明", "生成导出文件失败: " + e.getMessage());
}
} else {
responseFields.put("导出状态", "未找到记录");
@ -425,7 +435,7 @@ public class KDocsServiceImpl implements IKDocsService {
response.setId(condition.getId());
Map<String, Object> responseFields = new HashMap<>();
responseFields.put("导出状态", "导出失败");
responseFields.put("错误信息", "处理导出任务失败: " + e.getMessage());
responseFields.put("情况说明", "处理导出任务失败: " + e.getMessage());
response.setFields(responseFields);
}

@ -32,7 +32,7 @@ public class TagExcelUtil {
* Excel
*
* @param is Excel
* @return
* @return
*/
public static Map<String, Object> parseTagExcel(InputStream is) {
Map<String, Object> result = new HashMap<>();
@ -47,6 +47,16 @@ public class TagExcelUtil {
List<Map<String, String>> tagList = parseTagList(sheet);
result.put("tagList", tagList);
// 获取文件名
String fileName = sheet.getSheetName();
if (fileName == null || fileName.isEmpty()) {
// 如果没有sheet名称使用默认格式
fileName = String.format("Lot_%s_%s.xlsx",
orderInfo.get("orderNo"),
new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()));
}
result.put("fileName", fileName);
return result;
} catch (Exception e) {
log.error("解析Excel文件失败", e);

@ -1,68 +1,105 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="hw.tagApi.service.mapper.HwTagRecordMapper">
<resultMap type="HwTagRecord" id="HwTagRecordResult">
<result property="rId" column="r_id" />
<result property="tId" column="t_id" />
<result property="epc" column="epc" />
<result property="password" column="password" />
<result property="orderCode" column="order_code" />
<result property="batchNumber" column="batch_number" />
<result property="tagSequence" column="tag_sequence" />
<result property="totalQuantity" column="total_quantity" />
<result property="tagBatch" column="tag_batch" />
<result property="modelCode" column="model_code" />
<result property="processingTime" column="processing_time" />
<result property="operatorId" column="operator_id" />
<result property="delFlag" column="del_flag" />
<result property="fields1" column="fields_1" />
<result property="fields2" column="fields_2" />
<result property="fields3" column="fields_3" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="remark" column="remark" />
<result property="rId" column="r_id"/>
<result property="tId" column="t_id"/>
<result property="epc" column="epc"/>
<result property="password" column="password"/>
<result property="orderCode" column="order_code"/>
<result property="batchNumber" column="batch_number"/>
<result property="tagSequence" column="tag_sequence"/>
<result property="totalQuantity" column="total_quantity"/>
<result property="tagBatch" column="tag_batch"/>
<result property="modelCode" column="model_code"/>
<result property="processingTime" column="processing_time"/>
<result property="operatorId" column="operator_id"/>
<result property="testResult" column="test_result" />
<result property="testValue" column="test_value" />
<result property="referenceValue" column="reference_value" />
<result property="testingTime" column="testing_time" />
<result property="fileName" column="file_name" />
<result property="delFlag" column="del_flag"/>
<result property="fields1" column="fields_1"/>
<result property="fields2" column="fields_2"/>
<result property="fields3" column="fields_3"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/>
<result property="remark" column="remark"/>
</resultMap>
<sql id="selectHwTagRecordVo">
select r_id, t_id, epc, password, order_code, batch_number, tag_sequence, total_quantity, tag_batch, model_code, processing_time, operator_id, del_flag, fields_1, fields_2, fields_3, create_by, create_time, update_by, update_time, remark from hw_tag_record
select r_id,
t_id,
epc,
password,
order_code,
batch_number,
tag_sequence,
total_quantity,
tag_batch,
model_code,
processing_time,
operator_id,
test_result,
test_value,
reference_value,
testing_time,
file_name,
del_flag,
fields_1,
fields_2,
fields_3,
create_by,
create_time,
update_by,
update_time,
remark
from hw_tag_record
</sql>
<select id="selectHwTagRecordList" parameterType="HwTagRecord" resultMap="HwTagRecordResult">
<include refid="selectHwTagRecordVo"/>
<where>
<if test="tId != null and tId != ''"> and t_id = #{tId}</if>
<if test="epc != null and epc != ''"> and epc = #{epc}</if>
<if test="selectTID != null and selectTID != ''"> and t_id like concat('%', #{selectTID}, '%')</if>
<if test="selectEPC != null and selectEPC != ''"> and epc like concat('%', #{selectEPC}, '%')</if>
<if test="password != null and password != ''"> and password = #{password}</if>
<if test="orderCode != null and orderCode != ''"> and order_code = #{orderCode}</if>
<if test="batchNumber != null and batchNumber != ''"> and batch_number = #{batchNumber}</if>
<if test="tagSequence != null and tagSequence != ''"> and tag_sequence = #{tagSequence}</if>
<if test="totalQuantity != null "> and total_quantity = #{totalQuantity}</if>
<if test="tagBatch != null and tagBatch != ''"> and tag_batch = #{tagBatch}</if>
<if test="modelCode != null and modelCode != ''"> and model_code = #{modelCode}</if>
<if test="params.beginProcessingTime != null and params.beginProcessingTime != '' and params.endProcessingTime != null and params.endProcessingTime != ''"> and processing_time between #{params.beginProcessingTime} and #{params.endProcessingTime}</if>
<if test="operatorId != null and operatorId != ''"> and operator_id = #{operatorId}</if>
<if test="fields1 != null and fields1 != ''"> and fields_1 = #{fields1}</if>
<if test="fields2 != null and fields2 != ''"> and fields_2 = #{fields2}</if>
<if test="fields3 != null and fields3 != ''"> and fields_3 = #{fields3}</if>
<if test="startDate != null and startDate != ''"> and DATE_FORMAT(processing_time, '%Y/%m/%d') >= #{startDate}</if>
<if test="endDate != null and endDate != ''"> and #{endDate} >= DATE_FORMAT(processing_time, '%Y/%m/%d')</if>
<where>
<if test="tId != null and tId != ''">and t_id = #{tId}</if>
<if test="epc != null and epc != ''">and epc = #{epc}</if>
<if test="selectTID != null and selectTID != ''">and t_id like concat('%', #{selectTID}, '%')</if>
<if test="selectEPC != null and selectEPC != ''">and epc like concat('%', #{selectEPC}, '%')</if>
<if test="password != null and password != ''">and password = #{password}</if>
<if test="orderCode != null and orderCode != ''">and order_code = #{orderCode}</if>
<if test="batchNumber != null and batchNumber != ''">and batch_number = #{batchNumber}</if>
<if test="tagSequence != null and tagSequence != ''">and tag_sequence = #{tagSequence}</if>
<if test="totalQuantity != null ">and total_quantity = #{totalQuantity}</if>
<if test="tagBatch != null and tagBatch != ''">and tag_batch = #{tagBatch}</if>
<if test="modelCode != null and modelCode != ''">and model_code = #{modelCode}</if>
<if test="params.beginProcessingTime != null and params.beginProcessingTime != '' and params.endProcessingTime != null and params.endProcessingTime != ''">
and processing_time between #{params.beginProcessingTime} and #{params.endProcessingTime}
</if>
<if test="operatorId != null and operatorId != ''">and operator_id = #{operatorId}</if>
<if test="fields1 != null and fields1 != ''">and fields_1 = #{fields1}</if>
<if test="fields2 != null and fields2 != ''">and fields_2 = #{fields2}</if>
<if test="fields3 != null and fields3 != ''">and fields_3 = #{fields3}</if>
<if test="startDate != null and startDate != ''">and DATE_FORMAT(processing_time, '%Y/%m/%d') >=
#{startDate}
</if>
<if test="endDate != null and endDate != ''">and #{endDate} >= DATE_FORMAT(processing_time, '%Y/%m/%d')
</if>
</where>
</select>
<select id="selectHwTagRecordByRId" parameterType="Long" resultMap="HwTagRecordResult">
<include refid="selectHwTagRecordVo"/>
where r_id = #{rId}
</select>
<select id="selectHwTagRecordByTxId" parameterType="String" resultMap="HwTagRecordResult">
select r_id, t_id, epc from hw_tag_record
select r_id, t_id, epc
from hw_tag_record
where t_id = #{tId}
</select>
@ -81,6 +118,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="modelCode != null">model_code,</if>
<if test="processingTime != null">processing_time,</if>
<if test="operatorId != null">operator_id,</if>
<if test="testResult != null">test_result,</if>
<if test="testValue != null">test_value,</if>
<if test="referenceValue != null">reference_value,</if>
<if test="testingTime != null">testing_time,</if>
<if test="fileName != null">file_name,</if>
<if test="delFlag != null">del_flag,</if>
<if test="fields1 != null">fields_1,</if>
<if test="fields2 != null">fields_2,</if>
@ -90,7 +132,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
<if test="remark != null">remark,</if>
</trim>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="rId != null">#{rId},</if>
<if test="tId != null and tId != ''">#{tId},</if>
@ -104,6 +146,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="modelCode != null">#{modelCode},</if>
<if test="processingTime != null">#{processingTime},</if>
<if test="operatorId != null">#{operatorId},</if>
<if test="testResult != null">#{testResult},</if>
<if test="testValue != null">#{testValue},</if>
<if test="referenceValue != null">#{referenceValue},</if>
<if test="testingTime != null">#{testingTime},</if>
<if test="fileName != null">#{fileName},</if>
<if test="delFlag != null">#{delFlag},</if>
<if test="fields1 != null">#{fields1},</if>
<if test="fields2 != null">#{fields2},</if>
@ -113,7 +160,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="remark != null">#{remark},</if>
</trim>
</trim>
</insert>
<update id="updateHwTagRecord" parameterType="HwTagRecord">
@ -130,6 +177,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="modelCode != null">model_code = #{modelCode},</if>
<if test="processingTime != null">processing_time = #{processingTime},</if>
<if test="operatorId != null">operator_id = #{operatorId},</if>
<if test="testResult != null">test_result = #{testResult},</if>
<if test="testValue != null">test_value = #{testValue},</if>
<if test="referenceValue != null">reference_value = #{referenceValue},</if>
<if test="testingTime != null">testing_time = #{testingTime},</if>
<if test="fileName != null">file_name = #{fileName},</if>
<if test="delFlag != null">del_flag = #{delFlag},</if>
<if test="fields1 != null">fields_1 = #{fields1},</if>
<if test="fields2 != null">fields_2 = #{fields2},</if>
@ -146,6 +198,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<update id="updateHwTagRecordByTID" parameterType="HwTagRecord">
update hw_tag_record
<trim prefix="SET" suffixOverrides=",">
<if test="tId != null and tId != ''">t_id = #{tId},</if>
<if test="epc != null and epc != ''">epc = #{epc},</if>
<if test="password != null">password = #{password},</if>
<if test="orderCode != null">order_code = #{orderCode},</if>
@ -156,6 +209,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="modelCode != null">model_code = #{modelCode},</if>
<if test="processingTime != null">processing_time = #{processingTime},</if>
<if test="operatorId != null">operator_id = #{operatorId},</if>
<if test="testResult != null">test_result = #{testResult},</if>
<if test="testValue != null">test_value = #{testValue},</if>
<if test="referenceValue != null">reference_value = #{referenceValue},</if>
<if test="testingTime != null">testing_time = #{testingTime},</if>
<if test="fileName != null">file_name = #{fileName},</if>
<if test="delFlag != null">del_flag = #{delFlag},</if>
<if test="fields1 != null">fields_1 = #{fields1},</if>
<if test="fields2 != null">fields_2 = #{fields2},</if>
@ -170,11 +228,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</update>
<delete id="deleteHwTagRecordByRId" parameterType="Long">
delete from hw_tag_record where r_id = #{rId}
delete
from hw_tag_record
where r_id = #{rId}
</delete>
<delete id="deleteHwTagRecordByRIds" parameterType="String">
delete from hw_tag_record where r_id in
delete from hw_tag_record where r_id in
<foreach item="rId" collection="array" open="(" separator="," close=")">
#{rId}
</foreach>
@ -183,17 +243,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<!-- 批量新增标签记录 -->
<insert id="batchInsertHwTagRecord" parameterType="java.util.List">
insert into hw_tag_record (
r_id, t_id, epc, password, order_code, batch_number,
tag_sequence, total_quantity, tag_batch, model_code,
processing_time, operator_id, fields_1, fields_2, fields_3,
create_by, create_time, update_by, update_time, remark
) values
r_id, t_id, epc, password, order_code, batch_number,
tag_sequence, total_quantity, tag_batch, model_code,
processing_time, operator_id, fields_1, fields_2, fields_3,
create_by, create_time, update_by, update_time, remark,
test_result,test_value,reference_value,testing_time,file_name
) values
<foreach collection="list" item="item" separator=",">
(
#{item.rId}, #{item.tId}, #{item.epc}, #{item.password}, #{item.orderCode}, #{item.batchNumber},
#{item.tagSequence}, #{item.totalQuantity}, #{item.tagBatch}, #{item.modelCode},
#{item.processingTime}, #{item.operatorId}, #{item.fields1}, #{item.fields2}, #{item.fields3},
#{item.createBy}, sysdate(), #{item.updateBy}, sysdate(), #{item.remark}
#{item.rId}, #{item.tId}, #{item.epc}, #{item.password}, #{item.orderCode}, #{item.batchNumber},
#{item.tagSequence}, #{item.totalQuantity}, #{item.tagBatch}, #{item.modelCode},
#{item.processingTime}, #{item.operatorId}, #{item.fields1}, #{item.fields2}, #{item.fields3},
#{item.createBy}, sysdate(), #{item.updateBy}, sysdate(), #{item.remark},
#{item.testResult}, #{item.testValue},#{item.referenceValue}, #{item.testingTime},#{item.fileName}
)
</foreach>
</insert>

Loading…
Cancel
Save