From d90abe1635f1db162050e75dc7e6a2f2da52c5b5 Mon Sep 17 00:00:00 2001 From: yinq Date: Tue, 22 Apr 2025 15:46:54 +0800 Subject: [PATCH] =?UTF-8?q?update=20add=E5=AF=BC=E5=87=BA=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E3=80=81=E5=AF=BC=E5=87=BA=E4=B8=8B=E8=BD=BD=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hw/tagApi/common/config/RuoYiConfig.java | 79 +++--- .../hw/tagApi/common/utils/poi/ExcelUtil.java | 2 +- .../framework/config/SecurityConfig.java | 1 + tagApi-service/pom.xml | 9 + .../tagApi/service/constant/ApiConstants.java | 17 +- .../controller/KDocsApiController.java | 68 ++++- .../hw/tagApi/service/domain/HwTagRecord.java | 259 +++--------------- .../tagApi/service/service/IKDocsService.java | 24 +- .../service/impl/HwTagRecordServiceImpl.java | 2 +- .../service/impl/KDocsServiceImpl.java | 151 ++++++++-- .../tagApi/service/utils}/TagExcelUtil.java | 101 +++++-- .../tagApi/service/utils/httpClientUtils.java | 4 +- .../mapper/service/HwTagRecordMapper.xml | 2 + .../tagApi/system/domain/SysAttachInfo.java | 16 +- .../mapper/system/SysAttachInfoMapper.xml | 12 +- tagApi-ui/src/api/system/attachInfo.js | 44 +++ .../src/views/service/tagRecord/index.vue | 18 +- .../src/views/system/attachInfo/index.vue | 16 +- 18 files changed, 483 insertions(+), 342 deletions(-) rename {tagApi-common/src/main/java/hw/tagApi/common/utils/poi => tagApi-service/src/main/java/hw/tagApi/service/utils}/TagExcelUtil.java (66%) create mode 100644 tagApi-ui/src/api/system/attachInfo.js diff --git a/tagApi-common/src/main/java/hw/tagApi/common/config/RuoYiConfig.java b/tagApi-common/src/main/java/hw/tagApi/common/config/RuoYiConfig.java index 9e2982f..890512f 100644 --- a/tagApi-common/src/main/java/hw/tagApi/common/config/RuoYiConfig.java +++ b/tagApi-common/src/main/java/hw/tagApi/common/config/RuoYiConfig.java @@ -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"; } } diff --git a/tagApi-common/src/main/java/hw/tagApi/common/utils/poi/ExcelUtil.java b/tagApi-common/src/main/java/hw/tagApi/common/utils/poi/ExcelUtil.java index 6a522f3..1297885 100644 --- a/tagApi-common/src/main/java/hw/tagApi/common/utils/poi/ExcelUtil.java +++ b/tagApi-common/src/main/java/hw/tagApi/common/utils/poi/ExcelUtil.java @@ -1457,7 +1457,7 @@ public class ExcelUtil * * @param filename 文件名称 */ - public String getAbsoluteFile(String filename) + public static String getAbsoluteFile(String filename) { String downloadPath = RuoYiConfig.getDownloadPath() + filename; File desc = new File(downloadPath); diff --git a/tagApi-framework/src/main/java/hw/tagApi/framework/config/SecurityConfig.java b/tagApi-framework/src/main/java/hw/tagApi/framework/config/SecurityConfig.java index e904a6a..dcebf18 100644 --- a/tagApi-framework/src/main/java/hw/tagApi/framework/config/SecurityConfig.java +++ b/tagApi-framework/src/main/java/hw/tagApi/framework/config/SecurityConfig.java @@ -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(); diff --git a/tagApi-service/pom.xml b/tagApi-service/pom.xml index 6551d5c..d097618 100644 --- a/tagApi-service/pom.xml +++ b/tagApi-service/pom.xml @@ -19,6 +19,15 @@ hw.tagApi tagApi-common + + org.projectlombok + lombok + provided + + + hw.tagApi + tagApi-system + diff --git a/tagApi-service/src/main/java/hw/tagApi/service/constant/ApiConstants.java b/tagApi-service/src/main/java/hw/tagApi/service/constant/ApiConstants.java index 477d366..a0189a4 100644 --- a/tagApi-service/src/main/java/hw/tagApi/service/constant/ApiConstants.java +++ b/tagApi-service/src/main/java/hw/tagApi/service/constant/ApiConstants.java @@ -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"; /** * 数据库状态 diff --git a/tagApi-service/src/main/java/hw/tagApi/service/controller/KDocsApiController.java b/tagApi-service/src/main/java/hw/tagApi/service/controller/KDocsApiController.java index bf50a25..a7c4ad3 100644 --- a/tagApi-service/src/main/java/hw/tagApi/service/controller/KDocsApiController.java +++ b/tagApi-service/src/main/java/hw/tagApi/service/controller/KDocsApiController.java @@ -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 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 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 * diff --git a/tagApi-service/src/main/java/hw/tagApi/service/domain/HwTagRecord.java b/tagApi-service/src/main/java/hw/tagApi/service/domain/HwTagRecord.java index 4b9f961..90c170e 100644 --- a/tagApi-service/src/main/java/hw/tagApi/service/domain/HwTagRecord.java +++ b/tagApi-service/src/main/java/hw/tagApi/service/domain/HwTagRecord.java @@ -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 + '\'' + + '}'; } } diff --git a/tagApi-service/src/main/java/hw/tagApi/service/service/IKDocsService.java b/tagApi-service/src/main/java/hw/tagApi/service/service/IKDocsService.java index 9d21a25..06e2501 100644 --- a/tagApi-service/src/main/java/hw/tagApi/service/service/IKDocsService.java +++ b/tagApi-service/src/main/java/hw/tagApi/service/service/IKDocsService.java @@ -20,21 +20,13 @@ public interface IKDocsService { String getSystemStatus(); /** - * 导入数据List - * - * @param content 待导入的数据 - * @return 导入结果 + * 导入数据 + * + * @param content 数据内容 + * @return 处理结果 */ List importDataList(List content); - /** - * 导出数据 - * - * @param query 导出条件 - * @return 导出结果 - */ - String exportData(String query); - /** * 查询数据 * @@ -42,4 +34,12 @@ public interface IKDocsService { * @return 查询结果列表 */ List queryDataList(List content); + + /** + * 导出数据 + * + * @param content 导出条件列表 + * @return 导出结果列表 + */ + List exportDataList(List content); } diff --git a/tagApi-service/src/main/java/hw/tagApi/service/service/impl/HwTagRecordServiceImpl.java b/tagApi-service/src/main/java/hw/tagApi/service/service/impl/HwTagRecordServiceImpl.java index 0483364..c5003c0 100644 --- a/tagApi-service/src/main/java/hw/tagApi/service/service/impl/HwTagRecordServiceImpl.java +++ b/tagApi-service/src/main/java/hw/tagApi/service/service/impl/HwTagRecordServiceImpl.java @@ -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()); } } diff --git a/tagApi-service/src/main/java/hw/tagApi/service/service/impl/KDocsServiceImpl.java b/tagApi-service/src/main/java/hw/tagApi/service/service/impl/KDocsServiceImpl.java index 7e743c2..2e645f2 100644 --- a/tagApi-service/src/main/java/hw/tagApi/service/service/impl/KDocsServiceImpl.java +++ b/tagApi-service/src/main/java/hw/tagApi/service/service/impl/KDocsServiceImpl.java @@ -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 exportDataList(List content) { + List 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 responseFields = new HashMap<>(); + responseFields.put("导出状态", "导出中"); + responseFields.put("情况说明", "预计需要3分钟"); + response.setFields(responseFields); + result.add(response); + } + + // 异步执行导出任务 + executorService.execute(() -> { + List resApiContentList = new ArrayList<>(); + for (ApiContent condition : content) { + ApiContent response = new ApiContent(); + response.setId(condition.getId()); + try { + Map 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 records = tagRecordService.selectHwTagRecordList(queryCondition); + long endTime = System.currentTimeMillis(); + log.info("查询完成 - ID: {}, 记录数: {}, 耗时: {}ms", condition.getId(), records.size(), (endTime - startTime)); + + Map 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 responseFields = new HashMap<>(); + responseFields.put("导出状态", "导出失败"); + responseFields.put("错误信息", "处理导出任务失败: " + e.getMessage()); + response.setFields(responseFields); + + } + resApiContentList.add(response); + } + // 发送处理结果到回调接口 + httpClientUtils.sendResultToCallback(resApiContentList, ApiConstants.OUT_CALLBACK_URL); + }); + + return result; + } } diff --git a/tagApi-common/src/main/java/hw/tagApi/common/utils/poi/TagExcelUtil.java b/tagApi-service/src/main/java/hw/tagApi/service/utils/TagExcelUtil.java similarity index 66% rename from tagApi-common/src/main/java/hw/tagApi/common/utils/poi/TagExcelUtil.java rename to tagApi-service/src/main/java/hw/tagApi/service/utils/TagExcelUtil.java index afbf8d0..12ddcc3 100644 --- a/tagApi-common/src/main/java/hw/tagApi/common/utils/poi/TagExcelUtil.java +++ b/tagApi-service/src/main/java/hw/tagApi/service/utils/TagExcelUtil.java @@ -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 result = new HashMap<>(); try (Workbook workbook = WorkbookFactory.create(is)) { Sheet sheet = workbook.getSheetAt(0); - + // 解析订单信息 Map orderInfo = parseOrderInfo(sheet); result.put("orderInfo", orderInfo); - + // 解析标签数据 List> 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 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 records, String fileName) { + try { + // 使用ExcelUtil导出 + ExcelUtil 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()); + } + } } \ No newline at end of file diff --git a/tagApi-service/src/main/java/hw/tagApi/service/utils/httpClientUtils.java b/tagApi-service/src/main/java/hw/tagApi/service/utils/httpClientUtils.java index 6cb1f11..a4a45b8 100644 --- a/tagApi-service/src/main/java/hw/tagApi/service/utils/httpClientUtils.java +++ b/tagApi-service/src/main/java/hw/tagApi/service/utils/httpClientUtils.java @@ -92,7 +92,7 @@ public class httpClientUtils { * * @param resList 处理结果列表 */ - public static void sendResultToCallback(List resList) { + public static void sendResultToCallback(List 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); // 设置请求头 diff --git a/tagApi-service/src/main/resources/mapper/service/HwTagRecordMapper.xml b/tagApi-service/src/main/resources/mapper/service/HwTagRecordMapper.xml index 85c2205..d20bbf7 100644 --- a/tagApi-service/src/main/resources/mapper/service/HwTagRecordMapper.xml +++ b/tagApi-service/src/main/resources/mapper/service/HwTagRecordMapper.xml @@ -37,6 +37,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and t_id = #{tId} and epc = #{epc} + and t_id like concat('%', #{selectTID}, '%') + and epc like concat('%', #{selectEPC}, '%') and password = #{password} and order_code = #{orderCode} and batch_number = #{batchNumber} diff --git a/tagApi-system/src/main/java/hw/tagApi/system/domain/SysAttachInfo.java b/tagApi-system/src/main/java/hw/tagApi/system/domain/SysAttachInfo.java index 77712a7..6bc4eee 100644 --- a/tagApi-system/src/main/java/hw/tagApi/system/domain/SysAttachInfo.java +++ b/tagApi-system/src/main/java/hw/tagApi/system/domain/SysAttachInfo.java @@ -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()) diff --git a/tagApi-system/src/main/resources/mapper/system/SysAttachInfoMapper.xml b/tagApi-system/src/main/resources/mapper/system/SysAttachInfoMapper.xml index 05bdd92..84e0ba3 100644 --- a/tagApi-system/src/main/resources/mapper/system/SysAttachInfoMapper.xml +++ b/tagApi-system/src/main/resources/mapper/system/SysAttachInfoMapper.xml @@ -8,7 +8,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - + @@ -20,7 +20,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - 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