update add导出接口、导出下载接口

master
yinq 2 months ago
parent 0dbdfabe66
commit d90abe1635

@ -3,80 +3,85 @@ package hw.tagApi.common.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
*
*
*
* @author ruoyi
*/
@Component
@ConfigurationProperties(prefix = "ruoyi")
public class RuoYiConfig
{
/** 项目名称 */
public class RuoYiConfig {
/**
*
*/
private String name;
/** 版本 */
/**
*
*/
private String version;
/** 版权年份 */
/**
*
*/
private String copyrightYear;
/** 上传路径 */
/**
*
*/
private static String profile;
/** 获取地址开关 */
/**
*
*/
private static boolean addressEnabled;
/** 验证码类型 */
/**
*
*/
private static String captchaType;
public String getName()
{
public String getName() {
return name;
}
public void setName(String name)
{
public void setName(String name) {
this.name = name;
}
public String getVersion()
{
public String getVersion() {
return version;
}
public void setVersion(String version)
{
public void setVersion(String version) {
this.version = version;
}
public String getCopyrightYear()
{
public String getCopyrightYear() {
return copyrightYear;
}
public void setCopyrightYear(String copyrightYear)
{
public void setCopyrightYear(String copyrightYear) {
this.copyrightYear = copyrightYear;
}
public static String getProfile()
{
public static String getProfile() {
return profile;
}
public void setProfile(String profile)
{
public void setProfile(String profile) {
RuoYiConfig.profile = profile;
}
public static boolean isAddressEnabled()
{
public static boolean isAddressEnabled() {
return addressEnabled;
}
public void setAddressEnabled(boolean addressEnabled)
{
public void setAddressEnabled(boolean addressEnabled) {
RuoYiConfig.addressEnabled = addressEnabled;
}
@ -91,32 +96,30 @@ public class RuoYiConfig
/**
*
*/
public static String getImportPath()
{
public static String getImportPath() {
return getProfile() + "/import";
}
/**
*
*/
public static String getAvatarPath()
{
public static String getAvatarPath() {
return getProfile() + "/avatar";
}
/**
*
*/
public static String getDownloadPath()
{
return getProfile() + "/download/";
public static String getDownloadPath() {
// return getProfile() + "/download/";
String dateFolder = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
return System.getProperty("user.dir") + File.separator + "download" + File.separator + dateFolder + File.separator;
}
/**
*
*/
public static String getUploadPath()
{
public static String getUploadPath() {
return getProfile() + "/upload";
}
}

@ -1457,7 +1457,7 @@ public class ExcelUtil<T>
*
* @param filename
*/
public String getAbsoluteFile(String filename)
public static String getAbsoluteFile(String filename)
{
String downloadPath = RuoYiConfig.getDownloadPath() + filename;
File desc = new File(downloadPath);

@ -115,6 +115,7 @@ public class SecurityConfig
// 静态资源,可匿名访问
.antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
.antMatchers(HttpMethod.POST, "/docs/**").permitAll()
.antMatchers(HttpMethod.GET, "/docs/**").permitAll()
.antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()
// 除上面外的所有请求全部需要鉴权认证
.anyRequest().authenticated();

@ -19,6 +19,15 @@
<groupId>hw.tagApi</groupId>
<artifactId>tagApi-common</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>hw.tagApi</groupId>
<artifactId>tagApi-system</artifactId>
</dependency>
</dependencies>

@ -10,10 +10,25 @@ import com.fasterxml.jackson.databind.ObjectMapper;
*/
public class ApiConstants {
/**
* IP
*/
public static final String BASE_URL = "http://127.0.0.1:9000/docs/export/";
/**
* () 6
*/
public static final Long PASS_TIME = 21600000L;
/**
*
*/
public static final String CALLBACK_URL = "https://www.kdocs.cn/chatflow/api/v2/func/webhook/2uZIRSpxLvtfaoCjRoLg4EvwIc5";
public static final String IN_CALLBACK_URL = "https://www.kdocs.cn/chatflow/api/v2/func/webhook/2uZIRSpxLvtfaoCjRoLg4EvwIc5";
/**
*
*/
public static final String OUT_CALLBACK_URL = "https://www.kdocs.cn/chatflow/api/v2/func/webhook/2uZIRSpxLvtfaoCjRoLg4EvwIc5";
/**
*

@ -2,16 +2,25 @@ package hw.tagApi.service.controller;
import hw.tagApi.common.core.controller.BaseController;
import hw.tagApi.common.core.domain.AjaxResult;
import hw.tagApi.common.utils.poi.ExcelUtil;
import hw.tagApi.service.constant.ApiConstants;
import hw.tagApi.service.domain.ApiContent;
import hw.tagApi.service.domain.ApiRequest;
import hw.tagApi.service.domain.ApiResponse;
import hw.tagApi.service.service.IKDocsService;
import hw.tagApi.system.domain.SysAttachInfo;
import hw.tagApi.system.service.ISysAttachInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
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.util.List;
/**
@ -29,6 +38,9 @@ public class KDocsApiController extends BaseController {
@Autowired
private IKDocsService ikDocsService;
@Autowired
private ISysAttachInfoService attachInfoService;
/**
*
*
@ -75,7 +87,13 @@ public class KDocsApiController extends BaseController {
return apiResponse;
case ApiConstants.DATA_EXPORT:
// 数据导出
log.info("开始导出数据");
if (content == null || content.isEmpty()) {
log.warn("导出条件为空");
return apiResponse;
}
log.info("开始导出数据: {}", content);
List<ApiContent> exportResults = ikDocsService.exportDataList(content);
apiResponse.setResult(exportResults);
return apiResponse;
default:
log.warn("未知的功能代码: {}", caseCode);
@ -87,6 +105,54 @@ public class KDocsApiController extends BaseController {
}
}
/**
*
*
* @param attachUrl ID
* @param response HTTP
*/
@GetMapping("/export/{attachUrl}")
public void downloadExportFile(@PathVariable String attachUrl, HttpServletResponse response) {
try {
// 查询附件信息
SysAttachInfo sysAttachInfo = new SysAttachInfo();
sysAttachInfo.setAttachUrl(ApiConstants.BASE_URL + attachUrl);
List<SysAttachInfo> attachInfoList = attachInfoService.selectSysAttachInfoList(sysAttachInfo);
if (attachInfoList.isEmpty()) {
throw new RuntimeException("附件不存在");
}
SysAttachInfo attachInfo = attachInfoList.get(0);
// 检查文件是否存在
File file = new File(attachInfo.getAttachAddress());
if (!file.exists()) {
throw new RuntimeException("文件不存在");
}
// 设置响应头
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("utf-8");
response.setHeader("Content-Disposition", "attachment;filename=" +
URLEncoder.encode(attachInfo.getAttachName(), "UTF-8"));
// 写入响应流
try (FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis)) {
byte[] buffer = new byte[1024];
OutputStream os = response.getOutputStream();
int i = bis.read(buffer);
while (i != -1) {
os.write(buffer, 0, i);
i = bis.read(buffer);
}
}
} catch (Exception e) {
log.error("下载文件失败", e);
throw new RuntimeException("下载文件失败: " + e.getMessage());
}
}
/**
* API-Key
*

@ -2,10 +2,11 @@ package hw.tagApi.service.domain;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import lombok.EqualsAndHashCode;
import hw.tagApi.common.annotation.Excel;
import hw.tagApi.common.core.domain.BaseEntity;
import hw.tagApi.common.annotation.Excel.Type;
import lombok.Data;
/**
* hw_tag_record
@ -13,71 +14,74 @@ import hw.tagApi.common.core.domain.BaseEntity;
* @author Yinq
* @date 2025-04-15
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class HwTagRecord extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 主键标识,RID */
@Excel(name = "RID", type = Type.EXPORT)
private Long rId;
/** TID */
@Excel(name = "TID")
@Excel(name = "TID", type = Type.EXPORT)
private String tId;
/** EPC */
@Excel(name = "EPC")
@Excel(name = "EPC", type = Type.EXPORT)
private String epc;
/** 密码(预留字段) */
@Excel(name = "密码", readConverterExp = "预=留字段")
@Excel(name = "密码", type = Type.EXPORT)
private String password;
/** 订单号LOT */
@Excel(name = "订单号,LOT")
@Excel(name = "LOT", type = Type.EXPORT)
private String orderCode;
/** 批次编号,卷编号 */
@Excel(name = "批次编号,卷编号")
@Excel(name = "卷编号", type = Type.EXPORT)
private String batchNumber;
/** 标签序号,序号 */
@Excel(name = "标签序号,序号")
@Excel(name = "标签序号", type = Type.EXPORT)
private String tagSequence;
/** 总数量,本卷数量 */
@Excel(name = "总数量,本卷数量")
@Excel(name = "本卷数量", type = Type.EXPORT)
private Long totalQuantity;
/** 标签批次号(预留字段) */
@Excel(name = "标签批次号")
@Excel(name = "标签批次号", type = Type.EXPORT)
private String tagBatch;
/** 型号,导入提供 */
@Excel(name = "型号,导入提供")
@Excel(name = "型号", type = Type.EXPORT)
private String modelCode;
/** 加工时间 */
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "加工时间", width = 30, dateFormat = "yyyy-MM-dd")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "加工时间", type = Type.EXPORT, dateFormat = "yyyy/MM/dd HH:mm:ss")
private Date processingTime;
/** 操作人员编号,生产人员编号 */
@Excel(name = "操作人员编号,生产人员编号")
@Excel(name = "生产人员编号", type = Type.EXPORT)
private String operatorId;
/** 数据状态标记 */
private Integer delFlag;
/** 预留字段1 */
// @Excel(name = "预留字段1")
// @Excel(name = "测试结果", type = Type.EXPORT)
private String fields1;
/** 预留字段2 */
// @Excel(name = "预留字段2")
// @Excel(name = "测试值", type = Type.EXPORT)
private String fields2;
/** 预留字段3 */
// @Excel(name = "预留字段3")
// @Excel(name = "参考值", type = Type.EXPORT)
private String fields3;
/**
@ -89,207 +93,30 @@ public class HwTagRecord extends BaseEntity
*
*/
private String endDate;
public String getStartDate() {
return startDate;
}
public void setStartDate(String startDate) {
this.startDate = startDate;
}
public String getEndDate() {
return endDate;
}
public void setEndDate(String endDate) {
this.endDate = endDate;
}
public void setrId(Long rId)
{
this.rId = rId;
}
public Long getrId()
{
return rId;
}
public void settId(String tId)
{
this.tId = tId;
}
public String gettId()
{
return tId;
}
public void setEpc(String epc)
{
this.epc = epc;
}
public String getEpc()
{
return epc;
}
public void setPassword(String password)
{
this.password = password;
}
public String getPassword()
{
return password;
}
public void setOrderCode(String orderCode)
{
this.orderCode = orderCode;
}
public String getOrderCode()
{
return orderCode;
}
public void setBatchNumber(String batchNumber)
{
this.batchNumber = batchNumber;
}
public String getBatchNumber()
{
return batchNumber;
}
public void setTagSequence(String tagSequence)
{
this.tagSequence = tagSequence;
}
public String getTagSequence()
{
return tagSequence;
}
public void setTotalQuantity(Long totalQuantity)
{
this.totalQuantity = totalQuantity;
}
public Long getTotalQuantity()
{
return totalQuantity;
}
public void setTagBatch(String tagBatch)
{
this.tagBatch = tagBatch;
}
public String getTagBatch()
{
return tagBatch;
}
public void setModelCode(String modelCode)
{
this.modelCode = modelCode;
}
public String getModelCode()
{
return modelCode;
}
public void setProcessingTime(Date processingTime)
{
this.processingTime = processingTime;
}
public Date getProcessingTime()
{
return processingTime;
}
public void setOperatorId(String operatorId)
{
this.operatorId = operatorId;
}
public String getOperatorId()
{
return operatorId;
}
public void setDelFlag(Integer delFlag)
{
this.delFlag = delFlag;
}
public Integer getDelFlag()
{
return delFlag;
}
public void setFields1(String fields1)
{
this.fields1 = fields1;
}
public String getFields1()
{
return fields1;
}
public void setFields2(String fields2)
{
this.fields2 = fields2;
}
public String getFields2()
{
return fields2;
}
public void setFields3(String fields3)
{
this.fields3 = fields3;
}
public String getFields3()
{
return fields3;
}
private String selectTID;
private String selectEPC;
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("rId", getrId())
.append("tId", gettId())
.append("epc", getEpc())
.append("password", getPassword())
.append("orderCode", getOrderCode())
.append("batchNumber", getBatchNumber())
.append("tagSequence", getTagSequence())
.append("totalQuantity", getTotalQuantity())
.append("tagBatch", getTagBatch())
.append("modelCode", getModelCode())
.append("processingTime", getProcessingTime())
.append("operatorId", getOperatorId())
.append("delFlag", getDelFlag())
.append("fields1", getFields1())
.append("fields2", getFields2())
.append("fields3", getFields3())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.append("remark", getRemark())
.toString();
return "HwTagRecord{" +
"rId=" + rId +
", tId='" + tId + '\'' +
", epc='" + epc + '\'' +
", password='" + password + '\'' +
", orderCode='" + orderCode + '\'' +
", batchNumber='" + batchNumber + '\'' +
", tagSequence='" + tagSequence + '\'' +
", totalQuantity=" + totalQuantity +
", tagBatch='" + tagBatch + '\'' +
", modelCode='" + modelCode + '\'' +
", processingTime=" + processingTime +
", operatorId='" + operatorId + '\'' +
", delFlag=" + delFlag +
", fields1='" + fields1 + '\'' +
", fields2='" + fields2 + '\'' +
", fields3='" + fields3 + '\'' +
", startDate='" + startDate + '\'' +
", endDate='" + endDate + '\'' +
'}';
}
}

@ -20,21 +20,13 @@ public interface IKDocsService {
String getSystemStatus();
/**
* List
*
* @param content
* @return
*
*
* @param content
* @return
*/
List<ApiContent> importDataList(List<ApiContent> content);
/**
*
*
* @param query
* @return
*/
String exportData(String query);
/**
*
*
@ -42,4 +34,12 @@ public interface IKDocsService {
* @return
*/
List<ApiContent> queryDataList(List<ApiContent> content);
/**
*
*
* @param content
* @return
*/
List<ApiContent> exportDataList(List<ApiContent> content);
}

@ -141,7 +141,7 @@ public class HwTagRecordServiceImpl implements IHwTagRecordService
* @param hwTagRecord hwTagRecord
*/
public void initTagRecord(HwTagRecord hwTagRecord){
hwTagRecord.setrId(IdGenerator.nextId());
hwTagRecord.setRId(IdGenerator.nextId());
hwTagRecord.setCreateTime(DateUtils.getNowDate());
}
}

@ -3,17 +3,13 @@ package hw.tagApi.service.service.impl;
import hw.tagApi.common.utils.uuid.IdGenerator;
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 org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
@ -22,14 +18,14 @@ import java.util.Map;
import java.util.concurrent.*;
import hw.tagApi.service.constant.ApiConstants;
import hw.tagApi.service.mapper.HwTagRecordMapper;
import hw.tagApi.service.domain.HwTagRecord;
import hw.tagApi.common.utils.poi.TagExcelUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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;
/**
*
@ -44,6 +40,8 @@ public class KDocsServiceImpl implements IKDocsService {
@Autowired
private IHwTagRecordService tagRecordService;
private static final int BATCH_SIZE = 100;
// 创建线程池
@ -86,7 +84,7 @@ public class KDocsServiceImpl implements IKDocsService {
resList.add(resContent);
}
// 发送处理结果到回调接口
httpClientUtils.sendResultToCallback(resList);
httpClientUtils.sendResultToCallback(resList, ApiConstants.IN_CALLBACK_URL);
});
return resApiContentList;
@ -164,7 +162,7 @@ public class KDocsServiceImpl implements IKDocsService {
// 设置标签数据
record.setModelCode(model);
record.setTagSequence(tagData.get("序号"));
record.settId(tagData.get("TID"));
record.setTId(tagData.get("TID"));
record.setEpc(tagData.get("EPC"));
record.setPassword(tagData.get("密码"));
record.setFields1(tagData.get("测试结果"));
@ -178,11 +176,11 @@ public class KDocsServiceImpl implements IKDocsService {
continue;
}
//校验tId唯一
HwTagRecord tagRecord = tagRecordService.selectHwTagRecordByTID(record.gettId());
HwTagRecord tagRecord = tagRecordService.selectHwTagRecordByTID(record.getTId());
if (tagRecord != null) {
continue;
}
record.setrId(IdGenerator.nextId());
record.setRId(IdGenerator.nextId());
// 添加到批处理列表
batchList.add(record);
if (batchList.size() >= BATCH_SIZE) {
@ -227,12 +225,6 @@ public class KDocsServiceImpl implements IKDocsService {
}
}
@Override
public String exportData(String query) {
// TODO: 实现数据导出逻辑
return getSystemStatus();
}
/**
*
*
@ -270,7 +262,7 @@ public class KDocsServiceImpl implements IKDocsService {
// 设置查询条件
if (fields.containsKey("TID")) {
String tid = (String) fields.get("TID");
selectTagRecord.settId(tid);
selectTagRecord.setTId(tid);
}
if (fields.containsKey("EPC")) {
String epc = (String) fields.get("EPC");
@ -294,14 +286,14 @@ public class KDocsServiceImpl implements IKDocsService {
// 处理查询结果
if (data != null) {
log.info("查询成功 - ID: {}, TID: {}, EPC: {}", queryId, data.gettId(), data.getEpc());
log.info("查询成功 - ID: {}, TID: {}, EPC: {}", queryId, data.getTId(), data.getEpc());
// 查询成功
response.getFields().put("搜索状态", "搜索成功");
response.getFields().put("TID", data.gettId());
response.getFields().put("TID", data.getTId());
response.getFields().put("EPC", data.getEpc());
response.getFields().put("标签序号", data.getTagSequence());
response.getFields().put("密码", data.getPassword() != null ? data.getPassword() : "");
response.getFields().put("RID", data.getrId());
response.getFields().put("RID", data.getTId());
response.getFields().put("LOT", data.getOrderCode());
response.getFields().put("卷编号", data.getBatchNumber());
response.getFields().put("本卷数量", data.getTotalQuantity() != null ? data.getTotalQuantity() : "");
@ -330,4 +322,119 @@ public class KDocsServiceImpl implements IKDocsService {
return result;
}
/**
*
*
* @param content
* @return
*/
@Override
public List<ApiContent> exportDataList(List<ApiContent> content) {
List<ApiContent> result = new ArrayList<>();
if (content == null || content.isEmpty()) {
log.warn("导出条件列表为空");
return result;
}
log.info("开始处理导出请求,导出条件数量: {}", content.size());
// 创建初始响应
for (ApiContent condition : content) {
ApiContent response = new ApiContent();
response.setId(condition.getId());
Map<String, Object> responseFields = new HashMap<>();
responseFields.put("导出状态", "导出中");
responseFields.put("情况说明", "预计需要3分钟");
response.setFields(responseFields);
result.add(response);
}
// 异步执行导出任务
executorService.execute(() -> {
List<ApiContent> resApiContentList = new ArrayList<>();
for (ApiContent condition : content) {
ApiContent response = new ApiContent();
response.setId(condition.getId());
try {
Map<String, Object> fields = condition.getFields();
String lot = fields.get("LOT") != null ? (String) fields.get("LOT") : "";
String startDate = fields.get("导出日期起点") != null ? (String) fields.get("导出日期起点") : "";
String endDate = fields.get("导出日期终点") != null ? (String) fields.get("导出日期终点") : "";
String tagBatch = fields.get("标签批次号") != null ? (String) fields.get("标签批次号") : "";
String batchNumber = fields.get("卷编号") != null ? (String) fields.get("卷编号") : "";
String modelCode = fields.get("型号") != null ? (String) fields.get("型号") : "";
String TID = fields.get("TID") != null ? (String) fields.get("TID") : "";
String EPC = fields.get("EPC") != null ? (String) fields.get("EPC") : "";
// 构建查询条件
HwTagRecord queryCondition = new HwTagRecord();
if (StringUtils.hasText(lot)) {
queryCondition.setOrderCode(lot);
}
if (StringUtils.hasText(startDate)) {
queryCondition.setStartDate(startDate);
}
if (StringUtils.hasText(endDate)) {
queryCondition.setEndDate(endDate);
}
if (StringUtils.hasText(tagBatch)) {
queryCondition.setTagBatch(tagBatch);
}
if (StringUtils.hasText(batchNumber)) {
queryCondition.setBatchNumber(batchNumber);
}
if (StringUtils.hasText(modelCode)) {
queryCondition.setModelCode(modelCode);
}
if (StringUtils.hasText(TID)) {
queryCondition.setSelectTID(TID);
}
if (StringUtils.hasText(EPC)) {
queryCondition.setSelectEPC(EPC);
}
// 执行查询
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<>();
if (records != null && !records.isEmpty()) {
try {
String fileName = String.format("标签数据_%s.xlsx", condition.getId());
String filePath = TagExcelUtil.generateTagExcel(records, fileName);
responseFields.put("导出状态", "导出成功");
responseFields.put("文件路径", filePath);
responseFields.put("记录数量", records.size());
log.info("导出文件生成成功 - ID: {}, 路径: {}", condition.getId(), filePath);
} catch (Exception e) {
log.error("生成导出文件失败 - ID: {}", condition.getId(), e);
responseFields.put("导出状态", "导出失败");
responseFields.put("错误信息", "生成导出文件失败: " + e.getMessage());
}
} else {
responseFields.put("导出状态", "未找到记录");
responseFields.put("情况说明", "未找到符合条件的记录");
}
response.setFields(responseFields);
} catch (Exception e) {
log.error("处理导出任务失败 - ID: {}", condition.getId(), e);
response.setId(condition.getId());
Map<String, Object> responseFields = new HashMap<>();
responseFields.put("导出状态", "导出失败");
responseFields.put("错误信息", "处理导出任务失败: " + e.getMessage());
response.setFields(responseFields);
}
resApiContentList.add(response);
}
// 发送处理结果到回调接口
httpClientUtils.sendResultToCallback(resApiContentList, ApiConstants.OUT_CALLBACK_URL);
});
return result;
}
}

@ -1,19 +1,30 @@
package hw.tagApi.common.utils.poi;
package hw.tagApi.service.utils;
import hw.tagApi.common.constant.HttpStatus;
import hw.tagApi.common.core.domain.AjaxResult;
import hw.tagApi.common.utils.poi.ExcelUtil;
import hw.tagApi.common.utils.spring.SpringUtils;
import hw.tagApi.common.utils.uuid.UUID;
import hw.tagApi.service.constant.ApiConstants;
import hw.tagApi.service.domain.HwTagRecord;
import hw.tagApi.system.domain.SysAttachInfo;
import hw.tagApi.system.service.ISysAttachInfoService;
import org.apache.poi.ss.usermodel.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import java.io.File;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* Excel
*
* @author Yinq
* Excel
*/
@Component
public class TagExcelUtil {
private static final Logger log = LoggerFactory.getLogger(TagExcelUtil.class);
@ -27,15 +38,15 @@ public class TagExcelUtil {
Map<String, Object> result = new HashMap<>();
try (Workbook workbook = WorkbookFactory.create(is)) {
Sheet sheet = workbook.getSheetAt(0);
// 解析订单信息
Map<String, String> orderInfo = parseOrderInfo(sheet);
result.put("orderInfo", orderInfo);
// 解析标签数据
List<Map<String, String>> tagList = parseTagList(sheet);
result.put("tagList", tagList);
return result;
} catch (Exception e) {
log.error("解析Excel文件失败", e);
@ -53,17 +64,17 @@ public class TagExcelUtil {
Row orderRow = sheet.getRow(0);
String orderNoCell = getCellStringValue(orderRow.getCell(0));
orderInfo.put("orderNo", orderNoCell.substring(orderNoCell.indexOf("") + 1).trim());
// 批次号 - 格式: 批次号002
Row batchRow = sheet.getRow(1);
String batchNoCell = getCellStringValue(batchRow.getCell(0));
orderInfo.put("batchNo", batchNoCell.substring(batchNoCell.indexOf("") + 1).trim());
// 操作人员号 - 格式: 操作人员号WJL
Row operatorRow = sheet.getRow(2);
String operatorIdCell = getCellStringValue(operatorRow.getCell(0));
orderInfo.put("operatorId", operatorIdCell.substring(operatorIdCell.indexOf("") + 1).trim());
// 加工时间 - 格式: 加工时间2025/1/9 14:00:19
Row timeRow = sheet.getRow(3);
String processTimeCell = getCellStringValue(timeRow.getCell(0));
@ -77,7 +88,7 @@ public class TagExcelUtil {
}
}
orderInfo.put("processTime", processTime);
// 数量信息 - 格式: 合格数量2500不合格数量0总数量2500
Row quantityRow = sheet.getRow(4);
String quantityCell = getCellStringValue(quantityRow.getCell(0));
@ -95,7 +106,7 @@ public class TagExcelUtil {
}
}
}
log.info("解析到的订单信息: {}", orderInfo);
} catch (Exception e) {
log.error("解析订单信息失败", e);
@ -116,14 +127,14 @@ public class TagExcelUtil {
for (Cell cell : headerRow) {
headers.add(getCellStringValue(cell));
}
// 解析数据行
int startRow = 7;
Row row;
while ((row = sheet.getRow(startRow)) != null) {
Map<String, String> tagData = new HashMap<>();
boolean hasData = false;
for (int i = 0; i < headers.size(); i++) {
String value = getCellStringValue(row.getCell(i));
if (StringUtils.hasText(value)) {
@ -131,7 +142,7 @@ public class TagExcelUtil {
tagData.put(headers.get(i), value);
}
}
if (hasData) {
tagList.add(tagData);
} else {
@ -153,7 +164,7 @@ public class TagExcelUtil {
if (cell == null) {
return "";
}
String value = "";
switch (cell.getCellType()) {
case STRING:
@ -175,4 +186,62 @@ public class TagExcelUtil {
}
return value.trim();
}
/**
* Excel
*
* @param records
* @param fileName
* @return
*/
public static String generateTagExcel(List<HwTagRecord> records, String fileName) {
try {
// 使用ExcelUtil导出
ExcelUtil<HwTagRecord> util = new ExcelUtil<>(HwTagRecord.class);
// 导出Excel并获取结果
AjaxResult result = util.exportExcel(records, "标签数据");
if (result != null && HttpStatus.SUCCESS == Integer.parseInt(String.valueOf(result.get(AjaxResult.CODE_TAG)))) {
String exportFileName = (String) result.get(AjaxResult.MSG_TAG);
if (exportFileName == null || exportFileName.isEmpty()) {
throw new RuntimeException("导出文件名不能为空");
}
String fileUrl = ApiConstants.BASE_URL + UUID.randomUUID();
String absoluteFile = ExcelUtil.getAbsoluteFile(exportFileName);
// 存储文件信息
saveFileInfo(fileUrl, fileName, absoluteFile);
log.info("Excel文件生成成功: {}", absoluteFile);
return fileUrl;
} else {
String errorMsg = result != null ? (String) result.get(AjaxResult.MSG_TAG) : "导出失败";
throw new RuntimeException("导出Excel失败: " + errorMsg);
}
} catch (Exception e) {
log.error("生成Excel文件失败", e);
throw new RuntimeException("生成Excel文件失败: " + e.getMessage());
}
}
/**
*
*
* @param filePath
* @param fileName
* @param attachAddress
*/
private static void saveFileInfo(String filePath, String fileName, String attachAddress) {
try {
SysAttachInfo sysAttachInfo = new SysAttachInfo();
sysAttachInfo.setAttachUrl(filePath);
sysAttachInfo.setAttachAddress(attachAddress);
sysAttachInfo.setAttachName(fileName);
sysAttachInfo.setAttachType("1");
Date currentDate = new Date();
sysAttachInfo.setExpirationTime(new Date(currentDate.getTime() + ApiConstants.PASS_TIME));
SpringUtils.getBean(ISysAttachInfoService.class).insertSysAttachInfo(sysAttachInfo);
log.info("文件信息保存成功: {}", filePath);
} catch (Exception e) {
log.error("保存文件信息失败", e);
throw new RuntimeException("保存文件信息失败: " + e.getMessage());
}
}
}

@ -92,7 +92,7 @@ public class httpClientUtils {
*
* @param resList
*/
public static void sendResultToCallback(List<ApiContent> resList) {
public static void sendResultToCallback(List<ApiContent> resList, String url) {
if (resList == null || resList.isEmpty()) {
log.warn("处理结果列表为空,不发送回调请求");
return;
@ -101,7 +101,7 @@ public class httpClientUtils {
HttpPost httpPost = null;
try {
// 创建POST请求
httpPost = new HttpPost(ApiConstants.CALLBACK_URL);
httpPost = new HttpPost(url);
httpPost.setConfig(requestConfig);
// 设置请求头

@ -37,6 +37,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<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>

@ -30,7 +30,7 @@ public class SysAttachInfo extends BaseEntity
/** 附件URL */
@Excel(name = "附件URL")
private String attachRul;
private String attachUrl;
/** 附件地址 */
@Excel(name = "附件地址")
@ -74,17 +74,15 @@ public class SysAttachInfo extends BaseEntity
return attachType;
}
public void setAttachRul(String attachRul)
{
this.attachRul = attachRul;
public String getAttachUrl() {
return attachUrl;
}
public String getAttachRul()
{
return attachRul;
public void setAttachUrl(String attachUrl) {
this.attachUrl = attachUrl;
}
public void setAttachAddress(String attachAddress)
public void setAttachAddress(String attachAddress)
{
this.attachAddress = attachAddress;
}
@ -120,7 +118,7 @@ public class SysAttachInfo extends BaseEntity
.append("attachId", getAttachId())
.append("attachName", getAttachName())
.append("attachType", getAttachType())
.append("attachRul", getAttachRul())
.append("attachRul", getAttachUrl())
.append("attachAddress", getAttachAddress())
.append("expirationTime", getExpirationTime())
.append("delFlag", getDelFlag())

@ -8,7 +8,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="attachId" column="attach_id" />
<result property="attachName" column="attach_name" />
<result property="attachType" column="attach_type" />
<result property="attachRul" column="attach_rul" />
<result property="attachUrl" column="attach_url" />
<result property="attachAddress" column="attach_address" />
<result property="expirationTime" column="expiration_time" />
<result property="delFlag" column="del_flag" />
@ -20,7 +20,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectSysAttachInfoVo">
select attach_id, attach_name, attach_type, attach_rul, attach_address, expiration_time, del_flag, remark, create_by, create_time, update_by, update_time from sys_attach_info
select attach_id, attach_name, attach_type, attach_url, attach_address, expiration_time, del_flag, remark, create_by, create_time, update_by, update_time from sys_attach_info
</sql>
<select id="selectSysAttachInfoList" parameterType="SysAttachInfo" resultMap="SysAttachInfoResult">
@ -28,7 +28,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<where>
<if test="attachName != null and attachName != ''"> and attach_name like concat('%', #{attachName}, '%')</if>
<if test="attachType != null and attachType != ''"> and attach_type = #{attachType}</if>
<if test="attachRul != null and attachRul != ''"> and attach_rul = #{attachRul}</if>
<if test="attachUrl != null and attachUrl != ''"> and attach_url = #{attachUrl}</if>
<if test="attachAddress != null and attachAddress != ''"> and attach_address = #{attachAddress}</if>
<if test="expirationTime != null "> and expiration_time = #{expirationTime}</if>
</where>
@ -44,7 +44,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="attachName != null and attachName != ''">attach_name,</if>
<if test="attachType != null and attachType != ''">attach_type,</if>
<if test="attachRul != null and attachRul != ''">attach_rul,</if>
<if test="attachUrl != null and attachUrl != ''">attach_url,</if>
<if test="attachAddress != null and attachAddress != ''">attach_address,</if>
<if test="expirationTime != null">expiration_time,</if>
<if test="delFlag != null">del_flag,</if>
@ -57,7 +57,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="attachName != null and attachName != ''">#{attachName},</if>
<if test="attachType != null and attachType != ''">#{attachType},</if>
<if test="attachRul != null and attachRul != ''">#{attachRul},</if>
<if test="attachUrl != null and attachUrl != ''">#{attachUrl},</if>
<if test="attachAddress != null and attachAddress != ''">#{attachAddress},</if>
<if test="expirationTime != null">#{expirationTime},</if>
<if test="delFlag != null">#{delFlag},</if>
@ -74,7 +74,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<trim prefix="SET" suffixOverrides=",">
<if test="attachName != null and attachName != ''">attach_name = #{attachName},</if>
<if test="attachType != null and attachType != ''">attach_type = #{attachType},</if>
<if test="attachRul != null and attachRul != ''">attach_rul = #{attachRul},</if>
<if test="attachUrl != null and attachUrl != ''">attach_url = #{attachUrl},</if>
<if test="attachAddress != null and attachAddress != ''">attach_address = #{attachAddress},</if>
<if test="expirationTime != null">expiration_time = #{expirationTime},</if>
<if test="delFlag != null">del_flag = #{delFlag},</if>

@ -0,0 +1,44 @@
import request from '@/utils/request'
// 查询附件信息列表
export function listAttachInfo(query) {
return request({
url: '/system/attachInfo/list',
method: 'get',
params: query
})
}
// 查询附件信息详细
export function getAttachInfo(attachId) {
return request({
url: '/system/attachInfo/' + attachId,
method: 'get'
})
}
// 新增附件信息
export function addAttachInfo(data) {
return request({
url: '/system/attachInfo',
method: 'post',
data: data
})
}
// 修改附件信息
export function updateAttachInfo(data) {
return request({
url: '/system/attachInfo',
method: 'put',
data: data
})
}
// 删除附件信息
export function delAttachInfo(attachId) {
return request({
url: '/system/attachInfo/' + attachId,
method: 'delete'
})
}

@ -1,6 +1,6 @@
<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
<el-form-item label="TID" prop="tId">
<el-input
v-model="queryParams.tId"
@ -33,22 +33,22 @@
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="标签序号" prop="tagSequence">
<!-- <el-form-item label="标签序号" prop="tagSequence">
<el-input
v-model="queryParams.tagSequence"
placeholder="请输入标签序号"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="总数量" prop="totalQuantity">
</el-form-item> -->
<!-- <el-form-item label="总数量" prop="totalQuantity">
<el-input
v-model="queryParams.totalQuantity"
placeholder="请输入总数量"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item>
</el-form-item> -->
<el-form-item label="标签批次号" prop="tagBatch">
<el-input
v-model="queryParams.tagBatch"
@ -76,14 +76,14 @@
end-placeholder="结束日期"
></el-date-picker>
</el-form-item>
<el-form-item label="操作人员编号" prop="operatorId">
<!-- <el-form-item label="操作人员编号" prop="operatorId">
<el-input
v-model="queryParams.operatorId"
placeholder="请输入操作人员编号"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item>
</el-form-item> -->
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery"></el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery"></el-button>
@ -154,9 +154,9 @@
</template>
</el-table-column>
<el-table-column label="操作人员编号" align="center" prop="operatorId" />
<el-table-column label="预览字段1" align="center" prop="fields1" />
<!-- <el-table-column label="预览字段1" align="center" prop="fields1" />
<el-table-column label="预览字段2" align="center" prop="fields2" />
<el-table-column label="预览字段3" align="center" prop="fields3" />
<el-table-column label="预览字段3" align="center" prop="fields3" /> -->
<el-table-column label="备注" align="center" prop="remark" />
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">

@ -9,9 +9,9 @@
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="附件URL" prop="attachRul">
<el-form-item label="附件URL" prop="attachUrl">
<el-input
v-model="queryParams.attachRul"
v-model="queryParams.attachUrl"
placeholder="请输入附件URL"
clearable
@keyup.enter.native="handleQuery"
@ -78,7 +78,7 @@
<dict-tag :options="dict.type.attach_type" :value="scope.row.attachType"/>
</template>
</el-table-column>
<el-table-column label="附件URL" align="center" prop="attachRul" />
<el-table-column label="附件URL" align="center" prop="attachUrl" />
<el-table-column label="附件地址" align="center" prop="attachAddress" />
<el-table-column label="过期时间" align="center" prop="expirationTime" width="180">
<template slot-scope="scope">
@ -130,8 +130,8 @@
></el-option>
</el-select>
</el-form-item>
<el-form-item label="附件URL" prop="attachRul">
<el-input v-model="form.attachRul" placeholder="请输入附件URL" />
<el-form-item label="附件URL" prop="attachUrl">
<el-input v-model="form.attachUrl" placeholder="请输入附件URL" />
</el-form-item>
<el-form-item label="附件地址" prop="attachAddress">
<el-input v-model="form.attachAddress" type="textarea" placeholder="请输入内容" />
@ -191,7 +191,7 @@ export default {
pageSize: 10,
attachName: null,
attachType: null,
attachRul: null,
attachUrl: null,
attachAddress: null,
expirationTime: null,
},
@ -205,7 +205,7 @@ export default {
attachType: [
{ required: true, message: "附件类别不能为空", trigger: "change" }
],
attachRul: [
attachUrl: [
{ required: true, message: "附件URL不能为空", trigger: "blur" }
],
attachAddress: [
@ -238,7 +238,7 @@ export default {
attachId: null,
attachName: null,
attachType: null,
attachRul: null,
attachUrl: null,
attachAddress: null,
expirationTime: null,
delFlag: null,

Loading…
Cancel
Save