录单
This commit is contained in:
@@ -42,6 +42,7 @@ import java.text.DateFormat;
|
|||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.LocalTime;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
@@ -2021,20 +2022,60 @@ public class JDUtil {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LD(String input, String fromWxid) {
|
public LocalDate getDateFromLD(String dateStr) {
|
||||||
if (input.equals("慢单")) {
|
// 定义支持的日期格式
|
||||||
// 获取今天的日期
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||||
LocalDateTime today = LocalDateTime.now();
|
|
||||||
if (today.getHour() < 8) {
|
// 解析日期字符串为 LocalDate 对象
|
||||||
// 如果当前时间在早上8点之前,则获取昨天的日期
|
LocalDate date = LocalDate.parse(dateStr, formatter);
|
||||||
today = today.minusDays(1);
|
|
||||||
}
|
// 成功解析后,可执行后续操作(例如业务逻辑)
|
||||||
LocalDateTime startOfDay = today.withHour(0).withMinute(0).withSecond(0).withNano(0);
|
logger.info("成功解析日期: {}", date);
|
||||||
LocalDateTime endOfDay = today.withHour(23).withMinute(59).withSecond(59).withNano(999999999);
|
return date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LocalDateTime getEffectiveToday() {
|
||||||
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
if (now.getHour() < 8) {
|
||||||
|
return now.minusDays(1);
|
||||||
|
}
|
||||||
|
return now;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 解析用户输入中的日期部分
|
||||||
|
*
|
||||||
|
* @param input 用户输入内容
|
||||||
|
* @return 解析出的 LocalDate 对象,如果没有带日期则返回 null
|
||||||
|
*/
|
||||||
|
private LocalDate parseUserDateIfPresent(String input) {
|
||||||
|
if (input.contains("-")) {
|
||||||
|
String dateStr = input.replace("慢单", "").trim();
|
||||||
|
if (!dateStr.isEmpty()) {
|
||||||
|
return getDateFromLD(dateStr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null; // 没有带日期或格式错误,返回 null
|
||||||
|
}
|
||||||
|
public void LD(String input, String fromWxid) {
|
||||||
|
// 1️⃣ 调用封装好的方法提取日期
|
||||||
|
LocalDate userDate = parseUserDateIfPresent(input);
|
||||||
|
|
||||||
|
// 2️⃣ 获取有效“今天”
|
||||||
|
LocalDateTime today = getEffectiveToday();
|
||||||
|
if (userDate != null) {
|
||||||
|
today = userDate.atStartOfDay(); // ⬅️ 用户指定了日期
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3️⃣ 构造查询时间范围
|
||||||
|
LocalDateTime startOfDay = today.with(LocalTime.MIN);
|
||||||
|
LocalDateTime endOfDay = today.with(LocalTime.MAX);
|
||||||
|
|
||||||
|
Date startDate = Date.from(startOfDay.atZone(ZoneId.systemDefault()).toInstant());
|
||||||
|
Date endDate = Date.from(endOfDay.atZone(ZoneId.systemDefault()).toInstant());
|
||||||
|
|
||||||
|
|
||||||
|
if (input.startsWith("慢单")) {
|
||||||
|
|
||||||
// 将 LocalDateTime 转换为 Date
|
|
||||||
Date startDate = Date.from(startOfDay.atZone(ZoneId.systemDefault()).toInstant());
|
|
||||||
Date endDate = Date.from(endOfDay.atZone(ZoneId.systemDefault()).toInstant());
|
|
||||||
|
|
||||||
List<JDOrder> todayOrders = jdOrderRepository.findByOrderTimeBetween(startDate, endDate);
|
List<JDOrder> todayOrders = jdOrderRepository.findByOrderTimeBetween(startDate, endDate);
|
||||||
|
|
||||||
@@ -2089,19 +2130,7 @@ public class JDUtil {
|
|||||||
// 发送详细订单消息
|
// 发送详细订单消息
|
||||||
wxUtil.sendTextMessage(fromWxid, "分销标记:" + distributionMark + "\n" + summaryBuilder + "\n────────────\n" + detailBuilder, 1, fromWxid, true);
|
wxUtil.sendTextMessage(fromWxid, "分销标记:" + distributionMark + "\n" + summaryBuilder + "\n────────────\n" + detailBuilder, 1, fromWxid, true);
|
||||||
}
|
}
|
||||||
} else if (input.equals("录单")) {
|
} else if (input.startsWith("录单")) {
|
||||||
// 获取今天的日期
|
|
||||||
LocalDateTime today = LocalDateTime.now();
|
|
||||||
if (today.getHour() < 8) {
|
|
||||||
// 如果当前时间在早上8点之前,则获取昨天的日期
|
|
||||||
today = today.minusDays(1);
|
|
||||||
}
|
|
||||||
LocalDateTime startOfDay = today.withHour(0).withMinute(0).withSecond(0).withNano(0);
|
|
||||||
LocalDateTime endOfDay = today.withHour(23).withMinute(59).withSecond(59).withNano(999999999);
|
|
||||||
|
|
||||||
// 将 LocalDateTime 转换为 Date
|
|
||||||
Date startDate = Date.from(startOfDay.atZone(ZoneId.systemDefault()).toInstant());
|
|
||||||
Date endDate = Date.from(endOfDay.atZone(ZoneId.systemDefault()).toInstant());
|
|
||||||
|
|
||||||
List<JDOrder> todayOrders = jdOrderRepository.findByOrderTimeBetween(startDate, endDate);
|
List<JDOrder> todayOrders = jdOrderRepository.findByOrderTimeBetween(startDate, endDate);
|
||||||
|
|
||||||
@@ -2139,8 +2168,7 @@ public class JDUtil {
|
|||||||
wxUtil.sendTextMessage(fromWxid, batchSb.toString(), 1, null, true);
|
wxUtil.sendTextMessage(fromWxid, batchSb.toString(), 1, null, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else if (input.startsWith("单")) {
|
||||||
} else {
|
|
||||||
// 生成当前日期
|
// 生成当前日期
|
||||||
JDOrder jdOrder = parseOrderFromText(input.trim().replace("元", ""));
|
JDOrder jdOrder = parseOrderFromText(input.trim().replace("元", ""));
|
||||||
if (jdOrder.getOrderId() == null) {
|
if (jdOrder.getOrderId() == null) {
|
||||||
|
|||||||
@@ -229,7 +229,8 @@ public class WXUtil {
|
|||||||
|
|
||||||
/*录单群*/
|
/*录单群*/
|
||||||
chatRoom_JD_Order.add("50006079425@chatroom");
|
chatRoom_JD_Order.add("50006079425@chatroom");
|
||||||
chatRoom_JD_Order.add("49533691813@chatroom");
|
// 109|17:07:20|wxid_kr145nk7l0an31|收到群聊|群(48146712436@chatroom)wxid_ytpc72mdoskt22:1
|
||||||
|
chatRoom_JD_Order.add("48146712436@chatroom");
|
||||||
|
|
||||||
String messageContent = "Jarvis 更新完成 [亲亲][亲亲][亲亲] ";
|
String messageContent = "Jarvis 更新完成 [亲亲][亲亲][亲亲] ";
|
||||||
String fromWxid = default_bot_wxid; // 来源为机器人自身
|
String fromWxid = default_bot_wxid; // 来源为机器人自身
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ public class WxMessageConsumer {
|
|||||||
}
|
}
|
||||||
// 录单群
|
// 录单群
|
||||||
if ((chatRoom_JD_Order.contains(fromWxid))){
|
if ((chatRoom_JD_Order.contains(fromWxid))){
|
||||||
if (msg.startsWith("单") || msg.equals("慢单") || msg.equals("录单")) {
|
if (msg.startsWith("单") || msg.startsWith("慢单") || msg.startsWith("录单")) {
|
||||||
//logger.info("录单");
|
//logger.info("录单");
|
||||||
jdUtils.LD(msg, fromWxid);
|
jdUtils.LD(msg, fromWxid);
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user