forked from BaoKaiWms/202501-Wms-Kate-Wuxi
1. 定期清理数据,并备份文件。
This commit is contained in:
parent
8153741de8
commit
4ee8d8a187
|
|
@ -16,7 +16,10 @@ public enum AppConfigKeyEnums {
|
||||||
STAND_CAPACITY("StandCapacity", "站台容量"),
|
STAND_CAPACITY("StandCapacity", "站台容量"),
|
||||||
IMAGE_IP("ImageIp", "图片存放ip"),
|
IMAGE_IP("ImageIp", "图片存放ip"),
|
||||||
EMPTY_BACK("EmptyBack", "空载具是否回库"),
|
EMPTY_BACK("EmptyBack", "空载具是否回库"),
|
||||||
STOCK_WARNING_QTY("StockWarningQty", "库存预警数量");
|
STOCK_WARNING_QTY("StockWarningQty", "库存预警数量"),
|
||||||
|
LOG_CLEAR_INTERVAL("LogClearInterval", "日志清理间隔"),
|
||||||
|
NORMAL_DATA_CLEAR_INTERVAL("NormalDataClearInterval", "正常数据清理间隔"),
|
||||||
|
IMPORTANT_DATA_CLEAR_INTERVAL("ImportantDataClearInterval", "重要数据清理间隔");
|
||||||
private final String key;
|
private final String key;
|
||||||
private final String desc;
|
private final String desc;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,62 @@
|
||||||
|
package com.wms_main.excel.easypoi.excelTemplate;
|
||||||
|
|
||||||
|
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 接收日志模版
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class ApiReceiveLogExcelTemplate {
|
||||||
|
/**
|
||||||
|
* 日志Id
|
||||||
|
*/
|
||||||
|
@Excel(name = "log_id")
|
||||||
|
private String logId;
|
||||||
|
/**
|
||||||
|
* 请求方式
|
||||||
|
*/
|
||||||
|
@Excel(name = "method")
|
||||||
|
private String method;
|
||||||
|
/**
|
||||||
|
* 请求地址
|
||||||
|
*/
|
||||||
|
@Excel(name = "uri")
|
||||||
|
private String uri;
|
||||||
|
/**
|
||||||
|
* 客户端主机
|
||||||
|
*/
|
||||||
|
@Excel(name = "remote_host")
|
||||||
|
private String remoteHost;
|
||||||
|
/**
|
||||||
|
* 客户端地址
|
||||||
|
*/
|
||||||
|
@Excel(name = "remote_addr")
|
||||||
|
private String remoteAddr;
|
||||||
|
/**
|
||||||
|
* 请求数据
|
||||||
|
*/
|
||||||
|
@Excel(name = "request_content")
|
||||||
|
private String requestContent;
|
||||||
|
/**
|
||||||
|
* 响应状态
|
||||||
|
*/
|
||||||
|
@Excel(name = "status")
|
||||||
|
private String status;
|
||||||
|
/**
|
||||||
|
* 响应数据
|
||||||
|
*/
|
||||||
|
@Excel(name = "response_content")
|
||||||
|
private String responseContent;
|
||||||
|
/**
|
||||||
|
* 日志记录时间
|
||||||
|
*/
|
||||||
|
@Excel(name = "log_time")
|
||||||
|
private LocalDateTime logTime;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,102 @@
|
||||||
|
package com.wms_main.excel.easypoi.excelTemplate;
|
||||||
|
|
||||||
|
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送日志模版
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class ApiSendLogExcelTemplate {
|
||||||
|
/**
|
||||||
|
* id
|
||||||
|
*/
|
||||||
|
@Excel(name = "log_id")
|
||||||
|
private String logId;
|
||||||
|
/**
|
||||||
|
* url
|
||||||
|
*/
|
||||||
|
@Excel(name = "url")
|
||||||
|
private String url;
|
||||||
|
/**
|
||||||
|
* 超时时长
|
||||||
|
*/
|
||||||
|
@Excel(name = "timeout")
|
||||||
|
private Integer timeout;
|
||||||
|
/**
|
||||||
|
* 请求方式
|
||||||
|
*/
|
||||||
|
@Excel(name = "method")
|
||||||
|
private String method;
|
||||||
|
/**
|
||||||
|
* 请求头
|
||||||
|
*/
|
||||||
|
@Excel(name = "content_type")
|
||||||
|
private String contentType;
|
||||||
|
/**
|
||||||
|
* 数据
|
||||||
|
*/
|
||||||
|
@Excel(name = "data")
|
||||||
|
private String data;
|
||||||
|
/**
|
||||||
|
* token
|
||||||
|
*/
|
||||||
|
@Excel(name = "token")
|
||||||
|
private String token;
|
||||||
|
/**
|
||||||
|
* 请求是否成功
|
||||||
|
*/
|
||||||
|
@Excel(name = "success")
|
||||||
|
private String success;
|
||||||
|
/**
|
||||||
|
* 响应码
|
||||||
|
*/
|
||||||
|
@Excel(name = "response_code")
|
||||||
|
private int responseCode;
|
||||||
|
/**
|
||||||
|
* 请求信息
|
||||||
|
*/
|
||||||
|
@Excel(name = "request_message")
|
||||||
|
private String requestMessage;
|
||||||
|
/**
|
||||||
|
* 响应信息
|
||||||
|
*/
|
||||||
|
@Excel(name = "response_message")
|
||||||
|
private String responseMessage;
|
||||||
|
/**
|
||||||
|
* 请求时间
|
||||||
|
*/
|
||||||
|
@Excel(name = "request_time")
|
||||||
|
private LocalDateTime requestTime;
|
||||||
|
/**
|
||||||
|
* 响应时间
|
||||||
|
*/
|
||||||
|
@Excel(name = "response_time")
|
||||||
|
private LocalDateTime responseTime;
|
||||||
|
/**
|
||||||
|
* 请求地址
|
||||||
|
*/
|
||||||
|
@Excel(name = "request_url")
|
||||||
|
private String requestUrl;
|
||||||
|
/**
|
||||||
|
* 请求耗时
|
||||||
|
*/
|
||||||
|
@Excel(name = "use_time")
|
||||||
|
private long useTime;
|
||||||
|
/**
|
||||||
|
* 异常
|
||||||
|
*/
|
||||||
|
@Excel(name = "exception_message")
|
||||||
|
private String exceptionMessage;
|
||||||
|
/**
|
||||||
|
* 记录时间
|
||||||
|
*/
|
||||||
|
@Excel(name = "log_time")
|
||||||
|
private LocalDateTime logTime;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,57 @@
|
||||||
|
package com.wms_main.excel.easypoi.excelTemplate;
|
||||||
|
|
||||||
|
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 拣选任务记录模版
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class PickTaskBakExcelTemplate {
|
||||||
|
/**
|
||||||
|
* 任务id
|
||||||
|
*/
|
||||||
|
@Excel(name = "pick_id")
|
||||||
|
private String pickId;
|
||||||
|
/**
|
||||||
|
* 拣选站台
|
||||||
|
*/
|
||||||
|
@Excel(name = "pick_stand")
|
||||||
|
private String pickStand;
|
||||||
|
/**
|
||||||
|
* 载具号
|
||||||
|
*/
|
||||||
|
@Excel(name = "vehicle_id")
|
||||||
|
private String vehicleId;
|
||||||
|
/**
|
||||||
|
* 任务状态
|
||||||
|
*/
|
||||||
|
@Excel(name = "pick_status")
|
||||||
|
private Integer pickStatus;
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
@Excel(name = "create_time")
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
/**
|
||||||
|
* 发送时间
|
||||||
|
*/
|
||||||
|
@Excel(name = "send_time")
|
||||||
|
private LocalDateTime sendTime;
|
||||||
|
/**
|
||||||
|
* 到达时间
|
||||||
|
*/
|
||||||
|
@Excel(name = "arrive_time")
|
||||||
|
private LocalDateTime arriveTime;
|
||||||
|
/**
|
||||||
|
* 离开时间
|
||||||
|
*/
|
||||||
|
@Excel(name = "leave_time")
|
||||||
|
private LocalDateTime leaveTime;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,72 @@
|
||||||
|
package com.wms_main.excel.easypoi.excelTemplate;
|
||||||
|
|
||||||
|
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wcs任务记录模板
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class WcsTaskBakExcelTemplate {
|
||||||
|
/**
|
||||||
|
* wcs任务id
|
||||||
|
*/
|
||||||
|
@Excel(name = "wcs_task_id")
|
||||||
|
private String wcsTaskId;
|
||||||
|
/**
|
||||||
|
* wcs任务状态
|
||||||
|
*/
|
||||||
|
@Excel(name = "wcs_task_status")
|
||||||
|
private Integer wcsTaskStatus;
|
||||||
|
/**
|
||||||
|
* wcs任务类型
|
||||||
|
*/
|
||||||
|
@Excel(name = "wcs_task_type")
|
||||||
|
private Integer wcsTaskType;
|
||||||
|
/**
|
||||||
|
* wcs任务优先级
|
||||||
|
*/
|
||||||
|
@Excel(name = "task_priority")
|
||||||
|
private Integer taskPriority;
|
||||||
|
/**
|
||||||
|
* 载具号
|
||||||
|
*/
|
||||||
|
@Excel(name = "vehicle_id")
|
||||||
|
private String vehicleId;
|
||||||
|
/**
|
||||||
|
* 起点
|
||||||
|
*/
|
||||||
|
@Excel(name = "origin")
|
||||||
|
private String origin;
|
||||||
|
/**
|
||||||
|
* 终点
|
||||||
|
*/
|
||||||
|
@Excel(name = "destination")
|
||||||
|
private String destination;
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
@Excel(name = "create_time")
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
/**
|
||||||
|
* 发送时间
|
||||||
|
*/
|
||||||
|
@Excel(name = "send_time")
|
||||||
|
private LocalDateTime sendTime;
|
||||||
|
/**
|
||||||
|
* 完成时间
|
||||||
|
*/
|
||||||
|
@Excel(name = "finish_time")
|
||||||
|
private LocalDateTime finishTime;
|
||||||
|
/**
|
||||||
|
* 备注
|
||||||
|
*/
|
||||||
|
@Excel(name = "remark")
|
||||||
|
private String remark;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,102 @@
|
||||||
|
package com.wms_main.excel.easypoi.excelTemplate;
|
||||||
|
|
||||||
|
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wms任务记录模版
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class WmsTaskBakExcelTemplate {
|
||||||
|
/**
|
||||||
|
* 任务ID
|
||||||
|
*/
|
||||||
|
@Excel(name = "task_id")
|
||||||
|
private String taskId;
|
||||||
|
/**
|
||||||
|
* 任务类型
|
||||||
|
*/
|
||||||
|
@Excel(name = "task_type")
|
||||||
|
private Integer taskType;
|
||||||
|
/**
|
||||||
|
* 任务状态
|
||||||
|
*/
|
||||||
|
@Excel(name = "task_status")
|
||||||
|
private Integer taskStatus;
|
||||||
|
/**
|
||||||
|
* 任务优先级
|
||||||
|
*/
|
||||||
|
@Excel(name = "task_priority")
|
||||||
|
private Integer taskPriority;
|
||||||
|
/**
|
||||||
|
* 载具号
|
||||||
|
*/
|
||||||
|
@Excel(name = "vehicle_id")
|
||||||
|
private String vehicleId;
|
||||||
|
/**
|
||||||
|
* 起点
|
||||||
|
*/
|
||||||
|
@Excel(name = "origin")
|
||||||
|
private String origin;
|
||||||
|
/**
|
||||||
|
* 终点
|
||||||
|
*/
|
||||||
|
@Excel(name = "destination")
|
||||||
|
private String destination;
|
||||||
|
/**
|
||||||
|
* wcs任务id
|
||||||
|
*/
|
||||||
|
@Excel(name = "wcs_task_id")
|
||||||
|
private String wcsTaskId;
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
@Excel(name = "create_time")
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
/**
|
||||||
|
* 完成时间
|
||||||
|
*/
|
||||||
|
@Excel(name = "finish_time")
|
||||||
|
private LocalDateTime finishTime;
|
||||||
|
/**
|
||||||
|
* 料号
|
||||||
|
*/
|
||||||
|
@Excel(name = "goods_id")
|
||||||
|
private String goodsId;
|
||||||
|
/**
|
||||||
|
* 操作数量
|
||||||
|
*/
|
||||||
|
@Excel(name = "op_num")
|
||||||
|
private Integer opNum;
|
||||||
|
/**
|
||||||
|
* 库存数量
|
||||||
|
*/
|
||||||
|
@Excel(name = "stock_num")
|
||||||
|
private Integer stockNum;
|
||||||
|
/**
|
||||||
|
* 操纵用户
|
||||||
|
*/
|
||||||
|
@Excel(name = "op_user")
|
||||||
|
private String opUser;
|
||||||
|
/**
|
||||||
|
* 备注
|
||||||
|
*/
|
||||||
|
@Excel(name = "remark")
|
||||||
|
private String remark;
|
||||||
|
/**
|
||||||
|
* 申请出库的站台
|
||||||
|
*/
|
||||||
|
@Excel(name = "call_stand")
|
||||||
|
private String callStand;
|
||||||
|
/**
|
||||||
|
* 物料描述
|
||||||
|
*/
|
||||||
|
@Excel(name = "goods_desc")
|
||||||
|
private String goodsDesc;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.wms_main.excel.easypoi.service;
|
||||||
|
|
||||||
|
import com.wms_main.model.po.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存数据服务接口
|
||||||
|
*/
|
||||||
|
public interface ISaveExcelEasyPoi {
|
||||||
|
void saveApiReceiveLogs(String fileSuffix, List<TSysLog> logList);
|
||||||
|
void saveApiSendLogs(String fileSuffix, List<TSysApi> apiLogList);
|
||||||
|
void saveWmsTaskBak(String fileSuffix, List<TAppTaskBak> wmsTaskBakList);
|
||||||
|
void saveWcsTaskBak(String fileSuffix, List<TAppWcsTaskBak> wcsTaskBakList);
|
||||||
|
void savePickTaskBak(String fileSuffix, List<TAppPickTaskBak> pickTaskBakList);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,252 @@
|
||||||
|
package com.wms_main.excel.easypoi.service.serviceImpl;
|
||||||
|
|
||||||
|
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
||||||
|
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||||
|
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
|
||||||
|
import com.wms_main.excel.easypoi.excelTemplate.*;
|
||||||
|
import com.wms_main.excel.easypoi.service.ISaveExcelEasyPoi;
|
||||||
|
import com.wms_main.model.po.*;
|
||||||
|
import com.wms_main.repository.utils.StringUtils;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存数据服务实现
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class SaveExcelEasyPoi implements ISaveExcelEasyPoi {
|
||||||
|
private final String ROOT_PATH = "./file";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 写入excel
|
||||||
|
* @param fileDesc 文件描述,不需要文件类型的后缀
|
||||||
|
* @param filePath 文件路径,最后一位不需要添加文件分割符
|
||||||
|
* @param sheetName 页名
|
||||||
|
* @param list 数据列表
|
||||||
|
* @param clazz 泛型类
|
||||||
|
* @param <T> 泛型
|
||||||
|
* @throws IOException 异常
|
||||||
|
*/
|
||||||
|
public <T> void doWriteExcel(String fileDesc, String filePath, String sheetName, List<T> list, Class<T> clazz) throws IOException {
|
||||||
|
ExportParams exportParams = new ExportParams();
|
||||||
|
exportParams.setSheetName(sheetName);
|
||||||
|
exportParams.setType(ExcelType.XSSF);
|
||||||
|
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, clazz, list);
|
||||||
|
File file = new File(filePath + File.separator + fileDesc + ".xlsx");
|
||||||
|
createFile(file);// 新建文件
|
||||||
|
FileOutputStream fos = new FileOutputStream(file);
|
||||||
|
workbook.write(fos);
|
||||||
|
fos.close();
|
||||||
|
workbook.close();
|
||||||
|
log.info("保存文件成功:{}。", fileDesc);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建文件
|
||||||
|
* @param file 目标文件
|
||||||
|
*/
|
||||||
|
public void createFile(File file) {
|
||||||
|
if (!file.exists()) {
|
||||||
|
// 文件不存在
|
||||||
|
if (!file.getParentFile().exists()) {
|
||||||
|
// 目录不存在,创建上级目录
|
||||||
|
boolean createDirectSuccessFlag = file.getParentFile().mkdirs();
|
||||||
|
if (!createDirectSuccessFlag) {
|
||||||
|
log.error("创建目录失败。");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
// 在上级目录里创建文件
|
||||||
|
boolean createFileSuccessFlag = file.createNewFile();
|
||||||
|
if (!createFileSuccessFlag) {
|
||||||
|
log.error("创建文件失败。");
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("创建文件异常。{}", StringUtils.objectToString(e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存api接收日志
|
||||||
|
* @param fileSuffix 文件后缀
|
||||||
|
* @param logList 数据列表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void saveApiReceiveLogs(String fileSuffix, List<TSysLog> logList) {
|
||||||
|
if (logList == null || logList.isEmpty()) {
|
||||||
|
// 空数据体,不做处理
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 将数据转化为excel Template
|
||||||
|
List<ApiReceiveLogExcelTemplate> logExcelTemplateList = new ArrayList<>(logList.stream().map(log -> new ApiReceiveLogExcelTemplate(
|
||||||
|
log.getLogId(),
|
||||||
|
log.getMethod(),
|
||||||
|
log.getUri(),
|
||||||
|
log.getRemoteHost(),
|
||||||
|
log.getRemoteAddr(),
|
||||||
|
log.getRequestContent(),
|
||||||
|
log.getStatus(),
|
||||||
|
log.getResponseContent(),
|
||||||
|
log.getLogTime()
|
||||||
|
)).toList());
|
||||||
|
try {
|
||||||
|
// 写入excel
|
||||||
|
doWriteExcel("t_sys_log_" + fileSuffix, ROOT_PATH + "/t_sys_log", "t_sys_log", logExcelTemplateList, ApiReceiveLogExcelTemplate.class);
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("缓存过期接口接收日志异常。");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存api发送日志
|
||||||
|
* @param fileSuffix 文件后缀
|
||||||
|
* @param apiLogList 数据列表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void saveApiSendLogs(String fileSuffix, List<TSysApi> apiLogList) {
|
||||||
|
if (apiLogList == null || apiLogList.isEmpty()) {
|
||||||
|
// 空数据体,不做处理
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 将数据转化为excel Template
|
||||||
|
List<ApiSendLogExcelTemplate> logExcelTemplateList = new ArrayList<>(apiLogList.stream().map(log -> new ApiSendLogExcelTemplate(
|
||||||
|
log.getLogId(),
|
||||||
|
log.getUrl(),
|
||||||
|
log.getTimeout(),
|
||||||
|
log.getMethod(),
|
||||||
|
log.getContentType(),
|
||||||
|
log.getData(),
|
||||||
|
log.getToken(),
|
||||||
|
log.getSuccess(),
|
||||||
|
log.getResponseCode(),
|
||||||
|
log.getRequestMessage(),
|
||||||
|
log.getResponseMessage(),
|
||||||
|
log.getRequestTime(),
|
||||||
|
log.getResponseTime(),
|
||||||
|
log.getRequestUrl(),
|
||||||
|
log.getUseTime(),
|
||||||
|
log.getExceptionMessage(),
|
||||||
|
log.getLogTime()
|
||||||
|
)).toList());
|
||||||
|
try {
|
||||||
|
// 写入excel
|
||||||
|
doWriteExcel("t_sys_api_" + fileSuffix, ROOT_PATH + "/t_sys_api", "t_sys_api", logExcelTemplateList, ApiSendLogExcelTemplate.class);
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("缓存过期接口发送日志异常。");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存Wms任务记录
|
||||||
|
* @param fileSuffix 文件后缀
|
||||||
|
* @param wmsTaskBakList 数据列表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void saveWmsTaskBak(String fileSuffix, List<TAppTaskBak> wmsTaskBakList) {
|
||||||
|
if (wmsTaskBakList == null || wmsTaskBakList.isEmpty()) {
|
||||||
|
// 空数据体,不做处理
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 将数据转化为excel Template
|
||||||
|
List<WmsTaskBakExcelTemplate> wmsTaskBakExcelTemplateList = new ArrayList<>(wmsTaskBakList.stream().map(wmsTaskBak -> new WmsTaskBakExcelTemplate(
|
||||||
|
wmsTaskBak.getTaskId(),
|
||||||
|
wmsTaskBak.getTaskType(),
|
||||||
|
wmsTaskBak.getTaskStatus(),
|
||||||
|
wmsTaskBak.getTaskPriority(),
|
||||||
|
wmsTaskBak.getVehicleId(),
|
||||||
|
wmsTaskBak.getOrigin(),
|
||||||
|
wmsTaskBak.getDestination(),
|
||||||
|
wmsTaskBak.getWcsTaskId(),
|
||||||
|
wmsTaskBak.getCreateTime(),
|
||||||
|
wmsTaskBak.getFinishTime(),
|
||||||
|
wmsTaskBak.getGoodsId(),
|
||||||
|
wmsTaskBak.getOpNum(),
|
||||||
|
wmsTaskBak.getStockNum(),
|
||||||
|
wmsTaskBak.getOpUser(),
|
||||||
|
wmsTaskBak.getRemark(),
|
||||||
|
wmsTaskBak.getCallStand(),
|
||||||
|
wmsTaskBak.getGoodsDesc()
|
||||||
|
)).toList());
|
||||||
|
try {
|
||||||
|
// 写入excel
|
||||||
|
doWriteExcel("t_app_task_bak_" + fileSuffix, ROOT_PATH + "/t_app_task_bak", "t_app_task_bak", wmsTaskBakExcelTemplateList, WmsTaskBakExcelTemplate.class);
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("缓存过期Wms任务记录异常。");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存wcs任务记录
|
||||||
|
* @param fileSuffix 文件后缀
|
||||||
|
* @param wcsTaskBakList 数据记录
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void saveWcsTaskBak(String fileSuffix, List<TAppWcsTaskBak> wcsTaskBakList) {
|
||||||
|
if (wcsTaskBakList == null || wcsTaskBakList.isEmpty()) {
|
||||||
|
// 空数据体,不做处理
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 将数据转化为excel Template
|
||||||
|
List<WcsTaskBakExcelTemplate> wcsTaskBakExcelTemplateList = new ArrayList<>(wcsTaskBakList.stream().map(wcsTaskBak -> new WcsTaskBakExcelTemplate(
|
||||||
|
wcsTaskBak.getWcsTaskId(),
|
||||||
|
wcsTaskBak.getWcsTaskStatus(),
|
||||||
|
wcsTaskBak.getWcsTaskType(),
|
||||||
|
wcsTaskBak.getTaskPriority(),
|
||||||
|
wcsTaskBak.getVehicleId(),
|
||||||
|
wcsTaskBak.getOrigin(),
|
||||||
|
wcsTaskBak.getDestination(),
|
||||||
|
wcsTaskBak.getCreateTime(),
|
||||||
|
wcsTaskBak.getSendTime(),
|
||||||
|
wcsTaskBak.getFinishTime(),
|
||||||
|
wcsTaskBak.getRemark()
|
||||||
|
)).toList());
|
||||||
|
try {
|
||||||
|
// 写入excel
|
||||||
|
doWriteExcel("t_app_wcs_task_bak_" + fileSuffix, ROOT_PATH + "/t_app_wcs_task_bak", "t_app_wcs_task_bak", wcsTaskBakExcelTemplateList, WcsTaskBakExcelTemplate.class);
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("缓存过期Wcs任务记录异常。");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存拣选任务记录
|
||||||
|
* @param fileSuffix 文件后缀
|
||||||
|
* @param pickTaskBakList 数据记录
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void savePickTaskBak(String fileSuffix, List<TAppPickTaskBak> pickTaskBakList) {
|
||||||
|
if (pickTaskBakList == null || pickTaskBakList.isEmpty()) {
|
||||||
|
// 空数据体,不做处理
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 将数据转化为excel Template
|
||||||
|
List<PickTaskBakExcelTemplate> pickTaskExcelTemplateList = new ArrayList<>(pickTaskBakList.stream().map(log -> new PickTaskBakExcelTemplate(
|
||||||
|
log.getPickId(),
|
||||||
|
log.getPickStand(),
|
||||||
|
log.getVehicleId(),
|
||||||
|
log.getPickStatus(),
|
||||||
|
log.getCreateTime(),
|
||||||
|
log.getSendTime(),
|
||||||
|
log.getArriveTime(),
|
||||||
|
log.getLeaveTime()
|
||||||
|
)).toList());
|
||||||
|
try {
|
||||||
|
// 写入excel
|
||||||
|
doWriteExcel("t_app_pick_task_bak_" + fileSuffix, ROOT_PATH + "/t_app_pick_task_bak", "t_app_pick_task_bak", pickTaskExcelTemplateList, PickTaskBakExcelTemplate.class);
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("缓存过期拣选任务记录异常。");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,21 @@
|
||||||
package com.wms_main.service.quartz_job;
|
package com.wms_main.service.quartz_job;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据处理类 服务接口
|
||||||
|
*/
|
||||||
public interface IDataSolverService {
|
public interface IDataSolverService {
|
||||||
|
/**
|
||||||
|
* 清理日志数据
|
||||||
|
*/
|
||||||
|
void clearLogData();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清理普通记录
|
||||||
|
*/
|
||||||
|
void clearNormalRecord();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清理重要记录
|
||||||
|
*/
|
||||||
|
void clearImportantRecord();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package com.wms_main.service.quartz_job.job_executor;
|
package com.wms_main.service.quartz_job.job_executor;
|
||||||
|
|
||||||
|
import com.wms_main.repository.utils.StringUtils;
|
||||||
|
import com.wms_main.service.quartz_job.IDataSolverService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.quartz.*;
|
import org.quartz.*;
|
||||||
|
|
@ -12,6 +14,8 @@ import org.quartz.*;
|
||||||
@DisallowConcurrentExecution
|
@DisallowConcurrentExecution
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class DataSolver implements Job {
|
public class DataSolver implements Job {
|
||||||
|
private final IDataSolverService dataSolverService;// 数据处理服务
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 运行定时任务
|
* 运行定时任务
|
||||||
*
|
*
|
||||||
|
|
@ -19,8 +23,20 @@ public class DataSolver implements Job {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void execute(JobExecutionContext jobExecutionContext) {
|
public void execute(JobExecutionContext jobExecutionContext) {
|
||||||
// 获取
|
try {
|
||||||
// 获取各种需要处理的数据
|
dataSolverService.clearLogData();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("清除日志数据失败{}", StringUtils.objectToString(e));
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
dataSolverService.clearNormalRecord();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("清除普通记录失败{}", StringUtils.objectToString(e));
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
dataSolverService.clearImportantRecord();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("清除重要记录失败{}", StringUtils.objectToString(e));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,151 @@
|
||||||
|
package com.wms_main.service.quartz_job.serviceImpl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.wms_main.app.AppCommon;
|
||||||
|
import com.wms_main.constant.enums.wms.AppConfigKeyEnums;
|
||||||
|
import com.wms_main.dao.*;
|
||||||
|
import com.wms_main.excel.easypoi.service.ISaveExcelEasyPoi;
|
||||||
|
import com.wms_main.model.po.*;
|
||||||
|
import com.wms_main.service.quartz_job.IDataSolverService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据处理类 服务实现
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Slf4j
|
||||||
|
public class DataSolverServiceImpl implements IDataSolverService {
|
||||||
|
private final AppCommon appCommon;// 应用共同数据
|
||||||
|
private final ITSysApiService sysApiService;// 接口发送日志服务
|
||||||
|
private final ITSysLogService sysLogService;// 接口接收日志服务
|
||||||
|
private final ITAppTaskBakService appTaskBakService;// Wms任务记录服务
|
||||||
|
private final ITAppWcsTaskBakService appWcsTaskBakService;// Wcs任务记录服务
|
||||||
|
private final ITAppPickTaskBakService appPickTaskBakService;// 拣选任务记录服务
|
||||||
|
private final ISaveExcelEasyPoi saveExcelEasyPoi;// 记录保存excel服务
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清理日志文件 实现
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void clearLogData() {
|
||||||
|
// 日志清理间隔,默认7天
|
||||||
|
int logClearInterval = 7;
|
||||||
|
// 获取日志清理间隔
|
||||||
|
String logClearIntervalStr = appCommon.getConfigByKey(AppConfigKeyEnums.LOG_CLEAR_INTERVAL.getKey());
|
||||||
|
try {
|
||||||
|
logClearInterval = Integer.parseInt(logClearIntervalStr);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("获取日志清理间隔失败,使用默认值7天。");
|
||||||
|
}
|
||||||
|
// 获取删除时间
|
||||||
|
LocalDateTime deleteTime = LocalDateTime.now().minusDays(logClearInterval);
|
||||||
|
|
||||||
|
// 获取过期接口接收日志
|
||||||
|
List<TSysLog> logList = sysLogService.list(new LambdaQueryWrapper<TSysLog>().lt(TSysLog::getLogTime, deleteTime));
|
||||||
|
if (logList != null && !logList.isEmpty()) {
|
||||||
|
// 缓存接收记录
|
||||||
|
saveExcelEasyPoi.saveApiReceiveLogs(getSuffixFromDate(deleteTime, logClearInterval), logList);
|
||||||
|
// 删除接收记录
|
||||||
|
sysLogService.removeBatchByIds(logList);
|
||||||
|
log.info("清理日志文件成功,清理了{}条接口接收日志。", logList.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取过期接口发送日志
|
||||||
|
List<TSysApi> apiList = sysApiService.list(new LambdaQueryWrapper<TSysApi>().lt(TSysApi::getLogTime, deleteTime));
|
||||||
|
if (apiList != null && !apiList.isEmpty()) {
|
||||||
|
// 缓存发送记录
|
||||||
|
saveExcelEasyPoi.saveApiSendLogs(getSuffixFromDate(deleteTime, logClearInterval), apiList);
|
||||||
|
// 删除发送记录
|
||||||
|
sysApiService.removeBatchByIds(apiList);
|
||||||
|
log.info("清理日志文件成功,清理了{}条接口发送日志。", apiList.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清理普通记录文件 实现
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void clearNormalRecord() {
|
||||||
|
// 普通记录清理间隔,默认180天
|
||||||
|
int normalRecordClearInterval = 180;
|
||||||
|
// 获取普通记录清理间隔
|
||||||
|
String normalRecordClearIntervalStr = appCommon.getConfigByKey(AppConfigKeyEnums.NORMAL_DATA_CLEAR_INTERVAL.getKey());
|
||||||
|
try {
|
||||||
|
normalRecordClearInterval = Integer.parseInt(normalRecordClearIntervalStr);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("获取普通记录清理间隔失败,使用默认值180天。");
|
||||||
|
}
|
||||||
|
// 获取删除时间
|
||||||
|
LocalDateTime deleteTime = LocalDateTime.now().minusDays(normalRecordClearInterval);
|
||||||
|
|
||||||
|
// 查询Wms任务记录
|
||||||
|
List<TAppTaskBak> wmsTaskBakList = appTaskBakService.list(new LambdaQueryWrapper<TAppTaskBak>().lt(TAppTaskBak::getCreateTime, deleteTime));
|
||||||
|
if (wmsTaskBakList != null && !wmsTaskBakList.isEmpty()) {
|
||||||
|
// 备份数据
|
||||||
|
saveExcelEasyPoi.saveWmsTaskBak(getSuffixFromDate(deleteTime, normalRecordClearInterval), wmsTaskBakList);
|
||||||
|
// 删除记录
|
||||||
|
appTaskBakService.removeBatchByIds(wmsTaskBakList);
|
||||||
|
log.info("清理普通记录文件成功,清理了{}条Wms任务记录。", wmsTaskBakList.size());
|
||||||
|
}
|
||||||
|
// 查询Wcs任务记录
|
||||||
|
List<TAppWcsTaskBak> wcsTaskBakList = appWcsTaskBakService.list(new LambdaQueryWrapper<TAppWcsTaskBak>().lt(TAppWcsTaskBak::getCreateTime, deleteTime));
|
||||||
|
if (wcsTaskBakList != null && !wcsTaskBakList.isEmpty()) {
|
||||||
|
// 备份数据
|
||||||
|
saveExcelEasyPoi.saveWcsTaskBak(getSuffixFromDate(deleteTime, normalRecordClearInterval), wcsTaskBakList);
|
||||||
|
// 删除记录
|
||||||
|
appWcsTaskBakService.removeBatchByIds(wcsTaskBakList);
|
||||||
|
log.info("清理普通记录文件成功,清理了{}条Wcs任务记录。", wcsTaskBakList.size());
|
||||||
|
}
|
||||||
|
// 查询拣选任务记录
|
||||||
|
List<TAppPickTaskBak> pickTaskBakList = appPickTaskBakService.list(new LambdaQueryWrapper<TAppPickTaskBak>().lt(TAppPickTaskBak::getCreateTime, deleteTime));
|
||||||
|
if (pickTaskBakList != null && !pickTaskBakList.isEmpty()) {
|
||||||
|
// 备份数据
|
||||||
|
saveExcelEasyPoi.savePickTaskBak(getSuffixFromDate(deleteTime, normalRecordClearInterval), pickTaskBakList);
|
||||||
|
// 删除记录
|
||||||
|
appPickTaskBakService.removeBatchByIds(pickTaskBakList);
|
||||||
|
log.info("清理普通记录文件成功,清理了{}条拣选任务记录。", pickTaskBakList.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清理重要记录文件 实现
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void clearImportantRecord() {
|
||||||
|
// 重要记录清理间隔,默认365天
|
||||||
|
int importantRecordClearInterval = 365;
|
||||||
|
// 获取重要记录清理间隔
|
||||||
|
String importantRecordClearIntervalStr = appCommon.getConfigByKey(AppConfigKeyEnums.IMPORTANT_DATA_CLEAR_INTERVAL.getKey());
|
||||||
|
try {
|
||||||
|
importantRecordClearInterval = Integer.parseInt(importantRecordClearIntervalStr);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("获取重要记录清理间隔失败,使用默认值365天。");
|
||||||
|
}
|
||||||
|
// 获取删除时间
|
||||||
|
LocalDateTime deleteTime = LocalDateTime.now().minusDays(importantRecordClearInterval);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取到文件的时间后缀
|
||||||
|
* @param deleteTime 删除临界时间
|
||||||
|
* @return 后缀字符串
|
||||||
|
*/
|
||||||
|
private String getSuffixFromDate(LocalDateTime deleteTime, int clearInterval) {
|
||||||
|
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyyMMdd");
|
||||||
|
String fromDateStr = dateFormat.format(deleteTime.minusDays(clearInterval));
|
||||||
|
String toDateStr = dateFormat.format(deleteTime);
|
||||||
|
return fromDateStr + "~" + toDateStr;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user