This commit is contained in:
van
2026-09-06 21:00:59 +08:00
parent e5da5096c3
commit b46edff651
5 changed files with 91 additions and 17 deletions
@@ -43,8 +43,9 @@ public class InstructionController extends BaseController {
@GetMapping("/history")
public AjaxResult getHistory(@RequestParam(required = false, defaultValue = "request") String type,
@RequestParam(required = false, defaultValue = "100") Integer limit,
@RequestParam(required = false) String keyword) {
java.util.List<String> history = instructionService.getHistory(type, limit, keyword);
@RequestParam(required = false) String keyword,
@RequestParam(required = false) Integer days) {
java.util.List<String> history = instructionService.getHistory(type, limit, keyword, days);
return AjaxResult.success(history);
}
}
@@ -126,6 +126,11 @@ public class JDOrderListController extends BaseController
query.getParams().put("orderSearch", orderSearch.trim());
}
String quickRecordSearch = request.getParameter("quickRecordSearch");
if (quickRecordSearch != null && !quickRecordSearch.trim().isEmpty()) {
query.getParams().put("quickRecordSearch", quickRecordSearch.trim());
}
String rebateRemarkAbnormal = request.getParameter("rebateRemarkHasAbnormal");
if (rebateRemarkAbnormal != null && !rebateRemarkAbnormal.isEmpty()) {
query.setRebateRemarkHasAbnormal(Integer.valueOf(rebateRemarkAbnormal));
@@ -50,6 +50,12 @@ public interface IInstructionService {
* @return 历史消息列表
*/
java.util.List<String> getHistory(String type, Integer limit, String keyword);
/**
* 获取历史消息记录(支持关键词与最近 N 天)
* @param days 仅返回该天数内的记录;空或 &lt;=0 不限制
*/
java.util.List<String> getHistory(String type, Integer limit, String keyword, Integer days);
}
@@ -238,11 +238,16 @@ public class InstructionServiceImpl implements IInstructionService {
@Override
public List<String> getHistory(String type, Integer limit) {
return getHistory(type, limit, null);
return getHistory(type, limit, null, null);
}
@Override
public List<String> getHistory(String type, Integer limit, String keyword) {
return getHistory(type, limit, keyword, null);
}
@Override
public List<String> getHistory(String type, Integer limit, String keyword, Integer days) {
if (stringRedisTemplate == null) {
return Collections.emptyList();
}
@@ -260,28 +265,63 @@ public class InstructionServiceImpl implements IInstructionService {
int maxReturn = (limit != null && limit > 0) ? Math.min(limit, 1000) : 200;
boolean hasKeyword = keyword != null && !keyword.trim().isEmpty();
String kwLower = hasKeyword ? keyword.trim().toLowerCase() : null;
List<String> messages;
if (hasKeyword) {
// 搜索模式:取全部数据后在内存中按关键词过滤
messages = stringRedisTemplate.opsForList().range(key, 0, -1);
if (messages == null) messages = Collections.emptyList();
messages = messages.stream()
.filter(msg -> msg != null && msg.toLowerCase().contains(kwLower))
.limit(maxReturn)
.collect(Collectors.toList());
} else {
// 普通模式:只取最近 N 条
messages = stringRedisTemplate.opsForList().range(key, 0, maxReturn - 1);
long cutoffMs = 0L;
if (days != null && days > 0) {
cutoffMs = System.currentTimeMillis() - days * 24L * 60 * 60 * 1000;
}
return messages != null ? messages : Collections.emptyList();
// 新消息在前;限定天数时扫到早于截止时间即可停止
List<String> source = stringRedisTemplate.opsForList().range(key, 0, hasKeyword || cutoffMs > 0 ? -1 : maxReturn - 1);
if (source == null) {
return Collections.emptyList();
}
List<String> out = new ArrayList<>();
for (String msg : source) {
if (msg == null) {
continue;
}
if (cutoffMs > 0) {
Long ts = parseHistoryTimestampMs(msg);
if (ts != null && ts < cutoffMs) {
break;
}
if (ts == null) {
continue;
}
}
if (hasKeyword && !msg.toLowerCase().contains(kwLower)) {
continue;
}
out.add(msg);
if (out.size() >= maxReturn) {
break;
}
}
return out;
} catch (Exception e) {
System.err.println("获取历史消息失败: " + e.getMessage());
return Collections.emptyList();
}
}
/** 解析「yyyy-MM-dd HH:mm:ss | 正文」前缀时间,无法解析返回 null */
private Long parseHistoryTimestampMs(String message) {
if (message == null) {
return null;
}
int idx = message.indexOf(" | ");
if (idx < 10) {
return null;
}
try {
return new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
.parse(message.substring(0, idx).trim())
.getTime();
} catch (Exception e) {
return null;
}
}
private Set<String> menuKeywords() {
return new HashSet<>(Arrays.asList("菜单", "今日统计", "昨日统计", "三日统计", "七日统计", "一个月统计", "两个月统计", "三个月统计", "这个月统计", "上个月统计", "今日订单", "昨日订单", "七日订单", "总统计"));
}
@@ -67,6 +67,17 @@
or distribution_mark like concat('%', #{params.orderSearch}, '%')
)
</if>
<if test="params.quickRecordSearch != null and params.quickRecordSearch != ''">
and (
model_number like concat('%', #{params.quickRecordSearch}, '%')
or concat(IFNULL(model_number, ''), IFNULL(model_shop, '')) like concat('%', #{params.quickRecordSearch}, '%')
or address like concat('%', #{params.quickRecordSearch}, '%')
or buyer like concat('%', #{params.quickRecordSearch}, '%')
or order_id like concat('%', #{params.quickRecordSearch}, '%')
or third_party_order_no like concat('%', #{params.quickRecordSearch}, '%')
or distribution_mark like concat('%', #{params.quickRecordSearch}, '%')
)
</if>
<if test="distributionMark != null and distributionMark != ''"> and distribution_mark = #{distributionMark}</if>
<if test="modelNumber != null and modelNumber != ''">
and (
@@ -126,6 +137,17 @@
or distribution_mark like concat('%', #{params.orderSearch}, '%')
)
</if>
<if test="params.quickRecordSearch != null and params.quickRecordSearch != ''">
and (
model_number like concat('%', #{params.quickRecordSearch}, '%')
or concat(IFNULL(model_number, ''), IFNULL(model_shop, '')) like concat('%', #{params.quickRecordSearch}, '%')
or address like concat('%', #{params.quickRecordSearch}, '%')
or buyer like concat('%', #{params.quickRecordSearch}, '%')
or order_id like concat('%', #{params.quickRecordSearch}, '%')
or third_party_order_no like concat('%', #{params.quickRecordSearch}, '%')
or distribution_mark like concat('%', #{params.quickRecordSearch}, '%')
)
</if>
<if test="distributionMark != null and distributionMark != ''"> and distribution_mark = #{distributionMark}</if>
<if test="modelNumber != null and modelNumber != ''">
and (