1
This commit is contained in:
@@ -7,6 +7,7 @@ import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.jarvis.config.JarvisGoofishProperties;
|
||||
import com.ruoyi.jarvis.domain.ErpGoofishOrder;
|
||||
import com.ruoyi.jarvis.domain.ErpGoofishOrderEventLog;
|
||||
import com.ruoyi.jarvis.service.IErpGoofishOrderService;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -40,6 +41,13 @@ public class ErpGoofishOrderController extends BaseController {
|
||||
return AjaxResult.success(erpGoofishOrderService.selectById(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('jarvis:erpGoofishOrder:query')")
|
||||
@GetMapping("/{id}/eventLogs")
|
||||
public AjaxResult eventLogs(@PathVariable Long id) {
|
||||
List<ErpGoofishOrderEventLog> list = erpGoofishOrderService.listEventLogsByOrderId(id);
|
||||
return AjaxResult.success(list);
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('jarvis:erpGoofishOrder:edit')")
|
||||
@Log(title = "闲管家拉单", businessType = BusinessType.OTHER)
|
||||
@PostMapping("/pull/{appKey}")
|
||||
|
||||
@@ -65,6 +65,20 @@ CREATE TABLE IF NOT EXISTS erp_goofish_order (
|
||||
KEY idx_modify_time (modify_time)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='闲管家 ERP 订单(全量跟踪)';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS erp_goofish_order_event_log (
|
||||
id bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
order_id bigint(20) NOT NULL COMMENT 'erp_goofish_order.id',
|
||||
app_key varchar(64) DEFAULT NULL,
|
||||
order_no varchar(64) NOT NULL,
|
||||
event_type varchar(32) NOT NULL COMMENT 'ORDER_SYNC/LOGISTICS_SYNC/SHIP',
|
||||
source varchar(64) NULL COMMENT 'NOTIFY/LIST/DETAIL_REFRESH 等',
|
||||
message varchar(1024) NOT NULL,
|
||||
create_time datetime DEFAULT NULL,
|
||||
PRIMARY KEY (id),
|
||||
KEY idx_goofish_evt_order (order_id),
|
||||
KEY idx_goofish_evt_time (create_time)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='闲管家订单状态/物流/发货变更日志';
|
||||
|
||||
-- 可选:从旧枚举迁入两条示例(密钥请上线后立即修改)
|
||||
-- INSERT INTO erp_open_config (app_key,app_secret,xy_user_name,remark,express_code,express_name,status,order_num)
|
||||
-- VALUES ('1016208368633221','***','余生请多关照66','海尔胡歌',NULL,'日日顺','0',1);
|
||||
|
||||
@@ -186,6 +186,23 @@ PREPARE puk FROM @sql_uk;
|
||||
EXECUTE puk;
|
||||
DEALLOCATE PREPARE puk;
|
||||
|
||||
-- -----------------------------------------------------------------------------
|
||||
-- 5.5) 订单变更事件日志表
|
||||
-- -----------------------------------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS erp_goofish_order_event_log (
|
||||
id bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
order_id bigint(20) NOT NULL COMMENT 'erp_goofish_order.id',
|
||||
app_key varchar(64) DEFAULT NULL,
|
||||
order_no varchar(64) NOT NULL,
|
||||
event_type varchar(32) NOT NULL COMMENT 'ORDER_SYNC/LOGISTICS_SYNC/SHIP',
|
||||
source varchar(64) NULL COMMENT 'NOTIFY/LIST/DETAIL_REFRESH 等',
|
||||
message varchar(1024) NOT NULL,
|
||||
create_time datetime DEFAULT NULL,
|
||||
PRIMARY KEY (id),
|
||||
KEY idx_goofish_evt_order (order_id),
|
||||
KEY idx_goofish_evt_time (create_time)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='闲管家订单状态/物流/发货变更日志';
|
||||
|
||||
-- -----------------------------------------------------------------------------
|
||||
-- 6) 清理存储过程
|
||||
-- -----------------------------------------------------------------------------
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.ruoyi.jarvis.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 闲管家订单变更日志:状态刷新、物流变动、发货结果等
|
||||
*/
|
||||
@Data
|
||||
public class ErpGoofishOrderEventLog {
|
||||
|
||||
private Long id;
|
||||
/** erp_goofish_order.id */
|
||||
private Long orderId;
|
||||
private String appKey;
|
||||
private String orderNo;
|
||||
/** ORDER_SYNC / LOGISTICS_SYNC / SHIP */
|
||||
private String eventType;
|
||||
/** NOTIFY、LIST、DETAIL_REFRESH、UPSERT、REDIS_WAYBILL、AUTO_SHIP 等 */
|
||||
private String source;
|
||||
private String message;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date createTime;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.ruoyi.jarvis.mapper;
|
||||
|
||||
import com.ruoyi.jarvis.domain.ErpGoofishOrderEventLog;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ErpGoofishOrderEventLogMapper {
|
||||
|
||||
int insert(ErpGoofishOrderEventLog row);
|
||||
|
||||
List<ErpGoofishOrderEventLog> selectByOrderId(@Param("orderId") Long orderId);
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.ruoyi.jarvis.service;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.ruoyi.jarvis.domain.ErpGoofishOrder;
|
||||
import com.ruoyi.jarvis.domain.ErpGoofishOrderEventLog;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -39,4 +40,7 @@ public interface IErpGoofishOrderService {
|
||||
* 京东单物流扫描已得到运单号并写入 Redis 后调用:同步到闲鱼单并尝试开放平台发货。
|
||||
*/
|
||||
void notifyJdWaybillReady(Long jdOrderId);
|
||||
|
||||
/** 订单状态 / 物流 / 发货 变更日志(新→旧) */
|
||||
List<ErpGoofishOrderEventLog> listEventLogsByOrderId(Long orderId);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
package com.ruoyi.jarvis.service.goofish;
|
||||
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.jarvis.domain.ErpGoofishOrder;
|
||||
import com.ruoyi.jarvis.domain.ErpGoofishOrderEventLog;
|
||||
import com.ruoyi.jarvis.mapper.ErpGoofishOrderEventLogMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 闲管家订单:状态 / 物流 / 发货 变更落库 + SLF4J
|
||||
*/
|
||||
@Component
|
||||
public class GoofishOrderChangeLogger {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(GoofishOrderChangeLogger.class);
|
||||
private static final int MESSAGE_MAX = 1000;
|
||||
|
||||
public static final String TYPE_ORDER = "ORDER_SYNC";
|
||||
public static final String TYPE_LOGISTICS = "LOGISTICS_SYNC";
|
||||
public static final String TYPE_SHIP = "SHIP";
|
||||
|
||||
@Resource
|
||||
private ErpGoofishOrderEventLogMapper erpGoofishOrderEventLogMapper;
|
||||
|
||||
public void append(Long orderId, String appKey, String orderNo, String eventType, String source, String message) {
|
||||
if (orderId == null || StringUtils.isEmpty(message)) {
|
||||
return;
|
||||
}
|
||||
String msg = message.length() > MESSAGE_MAX ? message.substring(0, MESSAGE_MAX - 1) + "…" : message;
|
||||
ErpGoofishOrderEventLog row = new ErpGoofishOrderEventLog();
|
||||
row.setOrderId(orderId);
|
||||
row.setAppKey(appKey);
|
||||
row.setOrderNo(orderNo != null ? orderNo : "");
|
||||
row.setEventType(eventType != null ? eventType : "UNKNOWN");
|
||||
row.setSource(source != null ? source : "");
|
||||
row.setMessage(msg);
|
||||
row.setCreateTime(DateUtils.getNowDate());
|
||||
try {
|
||||
erpGoofishOrderEventLogMapper.insert(row);
|
||||
} catch (Exception e) {
|
||||
log.warn("闲管家订单事件日志写入失败 orderId={} {}", orderId, e.toString());
|
||||
}
|
||||
log.info("[goofish-order-event] orderId={} orderNo={} type={} source={} {}", orderId, orderNo, eventType, source, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 合并摘要前后对比:订单状态/退款状态、平台运单与快递、本地运单。
|
||||
*
|
||||
* @param beforeSnap 合并前从 row 拷贝的跟踪字段快照(可不含 id)
|
||||
* @param afterRow 合并并 apply 后的 row
|
||||
*/
|
||||
public void logSummaryMergeDiff(ErpGoofishOrder beforeSnap, ErpGoofishOrder afterRow, String source) {
|
||||
if (afterRow == null || afterRow.getId() == null) {
|
||||
return;
|
||||
}
|
||||
RowSnap b = RowSnap.from(beforeSnap);
|
||||
RowSnap a = RowSnap.from(afterRow);
|
||||
|
||||
List<String> orderParts = new ArrayList<>();
|
||||
if (!Objects.equals(b.orderStatus, a.orderStatus)) {
|
||||
orderParts.add("order_status " + str(b.orderStatus) + "→" + str(a.orderStatus));
|
||||
}
|
||||
if (!Objects.equals(b.refundStatus, a.refundStatus)) {
|
||||
orderParts.add("refund_status " + str(b.refundStatus) + "→" + str(a.refundStatus));
|
||||
}
|
||||
if (!orderParts.isEmpty()) {
|
||||
append(afterRow.getId(), afterRow.getAppKey(), afterRow.getOrderNo(), TYPE_ORDER, source,
|
||||
String.join(";", orderParts));
|
||||
}
|
||||
|
||||
List<String> logParts = new ArrayList<>();
|
||||
if (!eqStr(b.detailWaybillNo, a.detailWaybillNo)) {
|
||||
logParts.add("平台运单 " + str(b.detailWaybillNo) + "→" + str(a.detailWaybillNo));
|
||||
}
|
||||
if (!eqStr(b.detailExpressCode, a.detailExpressCode)) {
|
||||
logParts.add("express_code " + str(b.detailExpressCode) + "→" + str(a.detailExpressCode));
|
||||
}
|
||||
if (!eqStr(b.detailExpressName, a.detailExpressName)) {
|
||||
logParts.add("express_name " + str(b.detailExpressName) + "→" + str(a.detailExpressName));
|
||||
}
|
||||
if (!eqStr(b.localWaybillNo, a.localWaybillNo)) {
|
||||
logParts.add("本地运单 " + str(b.localWaybillNo) + "→" + str(a.localWaybillNo));
|
||||
}
|
||||
if (!logParts.isEmpty()) {
|
||||
append(afterRow.getId(), afterRow.getAppKey(), afterRow.getOrderNo(), TYPE_LOGISTICS, source,
|
||||
String.join(";", logParts));
|
||||
}
|
||||
}
|
||||
|
||||
private static String str(Object o) {
|
||||
return o == null ? "null" : String.valueOf(o);
|
||||
}
|
||||
|
||||
private static boolean eqStr(String x, String y) {
|
||||
String a = x == null ? "" : x.trim();
|
||||
String b = y == null ? "" : y.trim();
|
||||
return Objects.equals(a, b);
|
||||
}
|
||||
|
||||
private static final class RowSnap {
|
||||
Integer orderStatus;
|
||||
Integer refundStatus;
|
||||
String detailWaybillNo;
|
||||
String detailExpressCode;
|
||||
String detailExpressName;
|
||||
String localWaybillNo;
|
||||
|
||||
static RowSnap from(ErpGoofishOrder r) {
|
||||
RowSnap s = new RowSnap();
|
||||
if (r == null) {
|
||||
return s;
|
||||
}
|
||||
s.orderStatus = r.getOrderStatus();
|
||||
s.refundStatus = r.getRefundStatus();
|
||||
s.detailWaybillNo = r.getDetailWaybillNo();
|
||||
s.detailExpressCode = r.getDetailExpressCode();
|
||||
s.detailExpressName = r.getDetailExpressName();
|
||||
s.localWaybillNo = r.getLocalWaybillNo();
|
||||
return s;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
/**
|
||||
* 闲管家:推送/拉单后的落库、详情、关联京东单、同步运单、发货
|
||||
*/
|
||||
@@ -48,13 +49,15 @@ public class GoofishOrderPipeline {
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
@Resource
|
||||
private JarvisGoofishProperties goofishProperties;
|
||||
@Resource
|
||||
private GoofishOrderChangeLogger goofishOrderChangeLogger;
|
||||
|
||||
public void runFullPipeline(String appid, JSONObject notifyBody) {
|
||||
try {
|
||||
JSONObject shape = sourceForNotifyUpsert(notifyBody);
|
||||
ErpGoofishOrder row = upsertFromNotify(appid, notifyBody, notifyBody.toJSONString());
|
||||
ErpGoofishOrder row = upsertFromNotify(appid, notifyBody, notifyBody.toJSONString(), "NOTIFY_UPSERT");
|
||||
tryLinkJdOrder(row);
|
||||
mergeSummaryFromOrderDetailShape(row, shape);
|
||||
mergeSummaryFromOrderDetailShape(row, shape, "NOTIFY");
|
||||
refreshDetail(row);
|
||||
syncWaybillFromRedis(row);
|
||||
tryAutoShip(row);
|
||||
@@ -67,15 +70,19 @@ public class GoofishOrderPipeline {
|
||||
if (item == null || StringUtils.isEmpty(appKey)) {
|
||||
return;
|
||||
}
|
||||
ErpGoofishOrder row = upsertFromNotify(appKey, item, lastNotifyJson);
|
||||
ErpGoofishOrder row = upsertFromNotify(appKey, item, lastNotifyJson, "LIST_UPSERT");
|
||||
tryLinkJdOrder(row);
|
||||
mergeSummaryFromOrderDetailShape(row, item);
|
||||
mergeSummaryFromOrderDetailShape(row, item, "LIST");
|
||||
refreshDetail(row);
|
||||
syncWaybillFromRedis(row);
|
||||
tryAutoShip(row);
|
||||
}
|
||||
|
||||
public ErpGoofishOrder upsertFromNotify(String appKey, JSONObject rawBody, String lastNotifyJson) {
|
||||
return upsertFromNotify(appKey, rawBody, lastNotifyJson, "NOTIFY_UPSERT");
|
||||
}
|
||||
|
||||
public ErpGoofishOrder upsertFromNotify(String appKey, JSONObject rawBody, String lastNotifyJson, String upsertSource) {
|
||||
JSONObject body = sourceForNotifyUpsert(rawBody);
|
||||
Date now = DateUtils.getNowDate();
|
||||
String orderNo = notifyFirstString(body, "order_no", "orderNo");
|
||||
@@ -106,7 +113,9 @@ public class GoofishOrderPipeline {
|
||||
e.setShipStatus(0);
|
||||
}
|
||||
erpGoofishOrderMapper.insert(e);
|
||||
return erpGoofishOrderMapper.selectByAppKeyAndOrderNo(appKey, orderNo);
|
||||
ErpGoofishOrder inserted = erpGoofishOrderMapper.selectByAppKeyAndOrderNo(appKey, orderNo);
|
||||
logUpsertChange(inserted, null, e, upsertSource);
|
||||
return inserted;
|
||||
}
|
||||
e.setId(existing.getId());
|
||||
e.setDetailJson(existing.getDetailJson());
|
||||
@@ -117,7 +126,29 @@ public class GoofishOrderPipeline {
|
||||
e.setShipError(existing.getShipError());
|
||||
e.setShipExpressCode(existing.getShipExpressCode());
|
||||
erpGoofishOrderMapper.update(e);
|
||||
return erpGoofishOrderMapper.selectByAppKeyAndOrderNo(appKey, orderNo);
|
||||
ErpGoofishOrder updated = erpGoofishOrderMapper.selectByAppKeyAndOrderNo(appKey, orderNo);
|
||||
logUpsertChange(updated, existing, e, upsertSource);
|
||||
return updated;
|
||||
}
|
||||
|
||||
private void logUpsertChange(ErpGoofishOrder loaded, ErpGoofishOrder existingBeforeUpdate, ErpGoofishOrder upsertPayload,
|
||||
String upsertSource) {
|
||||
if (goofishOrderChangeLogger == null || loaded == null || loaded.getId() == null) {
|
||||
return;
|
||||
}
|
||||
if (existingBeforeUpdate == null) {
|
||||
goofishOrderChangeLogger.append(loaded.getId(), loaded.getAppKey(), loaded.getOrderNo(),
|
||||
GoofishOrderChangeLogger.TYPE_ORDER, upsertSource,
|
||||
"新订单入库 order_status=" + loaded.getOrderStatus() + " refund_status=" + loaded.getRefundStatus());
|
||||
return;
|
||||
}
|
||||
if (!Objects.equals(existingBeforeUpdate.getOrderStatus(), upsertPayload.getOrderStatus())
|
||||
|| !Objects.equals(existingBeforeUpdate.getRefundStatus(), upsertPayload.getRefundStatus())) {
|
||||
goofishOrderChangeLogger.append(loaded.getId(), loaded.getAppKey(), loaded.getOrderNo(),
|
||||
GoofishOrderChangeLogger.TYPE_ORDER, upsertSource,
|
||||
"order_status " + existingBeforeUpdate.getOrderStatus() + "→" + upsertPayload.getOrderStatus()
|
||||
+ ";refund_status " + existingBeforeUpdate.getRefundStatus() + "→" + upsertPayload.getRefundStatus());
|
||||
}
|
||||
}
|
||||
|
||||
public void tryLinkJdOrder(ErpGoofishOrder row) {
|
||||
@@ -159,7 +190,7 @@ public class GoofishOrderPipeline {
|
||||
if (jo != null && jo.getIntValue("code") == 0) {
|
||||
JSONObject data = jo.getJSONObject("data");
|
||||
if (data != null) {
|
||||
mergeSummaryFromOrderDetailShape(row, data);
|
||||
mergeSummaryFromOrderDetailShape(row, data, "DETAIL_REFRESH");
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
@@ -171,10 +202,11 @@ public class GoofishOrderPipeline {
|
||||
* 合并「订单详情 / 订单列表 / 推送」等同一 schema(order_detail)上的展示与发货摘要字段。
|
||||
* 列表与推送含 prov_name、city_name、area_name、town_name、address,详情接口常不含明文地址。
|
||||
*/
|
||||
private void mergeSummaryFromOrderDetailShape(ErpGoofishOrder row, JSONObject data) {
|
||||
private void mergeSummaryFromOrderDetailShape(ErpGoofishOrder row, JSONObject data, String logSource) {
|
||||
if (row == null || row.getId() == null || data == null) {
|
||||
return;
|
||||
}
|
||||
ErpGoofishOrder beforeSnap = snapshotForEventLog(row);
|
||||
ErpGoofishOrder patch = new ErpGoofishOrder();
|
||||
patch.setId(row.getId());
|
||||
JSONObject goods = data.getJSONObject("goods");
|
||||
@@ -278,36 +310,26 @@ public class GoofishOrderPipeline {
|
||||
if (mt != null) {
|
||||
patch.setModifyTime(mt);
|
||||
}
|
||||
fillReceiverFromJdOrder(patch, row);
|
||||
patch.setUpdateTime(DateUtils.getNowDate());
|
||||
erpGoofishOrderMapper.update(patch);
|
||||
applySummaryPatchToRow(row, patch);
|
||||
if (goofishOrderChangeLogger != null && logSource != null) {
|
||||
goofishOrderChangeLogger.logSummaryMergeDiff(beforeSnap, row, logSource);
|
||||
}
|
||||
}
|
||||
|
||||
/** 闲鱼详情常不返回明文地址:用已关联的 jd_order.address 兜底;平台已回收货人/分级地址时不覆盖姓名 */
|
||||
private void fillReceiverFromJdOrder(ErpGoofishOrder patch, ErpGoofishOrder row) {
|
||||
if (row.getJdOrderId() == null) {
|
||||
return;
|
||||
}
|
||||
boolean platformCare = StringUtils.isNotEmpty(patch.getReceiverName())
|
||||
|| StringUtils.isNotEmpty(patch.getReceiverMobile())
|
||||
|| StringUtils.isNotEmpty(patch.getRecvProvName())
|
||||
|| StringUtils.isNotEmpty(patch.getRecvCityName())
|
||||
|| StringUtils.isNotEmpty(patch.getRecvAreaName())
|
||||
|| StringUtils.isNotEmpty(patch.getRecvTownName());
|
||||
JDOrder jd = jdOrderService.selectJDOrderById(row.getJdOrderId());
|
||||
if (jd == null) {
|
||||
return;
|
||||
}
|
||||
if (StringUtils.isEmpty(patch.getReceiverAddress()) && StringUtils.isNotEmpty(jd.getAddress())) {
|
||||
patch.setReceiverAddress(jd.getAddress().trim());
|
||||
}
|
||||
if (platformCare) {
|
||||
return;
|
||||
}
|
||||
if (StringUtils.isEmpty(patch.getReceiverName()) && StringUtils.isNotEmpty(jd.getBuyer())) {
|
||||
patch.setReceiverName(jd.getBuyer().trim());
|
||||
private static ErpGoofishOrder snapshotForEventLog(ErpGoofishOrder r) {
|
||||
ErpGoofishOrder s = new ErpGoofishOrder();
|
||||
if (r == null) {
|
||||
return s;
|
||||
}
|
||||
s.setOrderStatus(r.getOrderStatus());
|
||||
s.setRefundStatus(r.getRefundStatus());
|
||||
s.setDetailWaybillNo(r.getDetailWaybillNo());
|
||||
s.setDetailExpressCode(r.getDetailExpressCode());
|
||||
s.setDetailExpressName(r.getDetailExpressName());
|
||||
s.setLocalWaybillNo(r.getLocalWaybillNo());
|
||||
return s;
|
||||
}
|
||||
|
||||
private void applySummaryPatchToRow(ErpGoofishOrder row, ErpGoofishOrder patch) {
|
||||
@@ -388,12 +410,18 @@ public class GoofishOrderPipeline {
|
||||
if (wb.equals(row.getLocalWaybillNo())) {
|
||||
return;
|
||||
}
|
||||
String prev = row.getLocalWaybillNo();
|
||||
ErpGoofishOrder patch = new ErpGoofishOrder();
|
||||
patch.setId(row.getId());
|
||||
patch.setLocalWaybillNo(wb.trim());
|
||||
patch.setUpdateTime(DateUtils.getNowDate());
|
||||
erpGoofishOrderMapper.update(patch);
|
||||
row.setLocalWaybillNo(wb.trim());
|
||||
if (goofishOrderChangeLogger != null) {
|
||||
goofishOrderChangeLogger.append(row.getId(), row.getAppKey(), row.getOrderNo(),
|
||||
GoofishOrderChangeLogger.TYPE_LOGISTICS, "REDIS_WAYBILL",
|
||||
"本地运单 " + (prev == null || prev.isEmpty() ? "null" : prev) + "→" + wb.trim());
|
||||
}
|
||||
}
|
||||
|
||||
public void tryAutoShip(ErpGoofishOrder row) {
|
||||
@@ -454,6 +482,11 @@ public class GoofishOrderPipeline {
|
||||
if (StringUtils.isEmpty(addr.shipName) || StringUtils.isEmpty(addr.shipMobile)
|
||||
|| StringUtils.isEmpty(addr.shipAddress)) {
|
||||
patchShipError(row, "缺少收货人/手机/地址:详情无字段时请关联京东单并维护地址,或等平台返回收货字段");
|
||||
if (goofishOrderChangeLogger != null) {
|
||||
goofishOrderChangeLogger.append(row.getId(), row.getAppKey(), row.getOrderNo(),
|
||||
GoofishOrderChangeLogger.TYPE_SHIP, "AUTO_SHIP",
|
||||
"发货失败(缺地址) " + (row.getShipError() != null ? row.getShipError() : ""));
|
||||
}
|
||||
return;
|
||||
}
|
||||
try {
|
||||
@@ -490,12 +523,27 @@ public class GoofishOrderPipeline {
|
||||
ok.setUpdateTime(DateUtils.getNowDate());
|
||||
erpGoofishOrderMapper.update(ok);
|
||||
row.setShipStatus(1);
|
||||
if (goofishOrderChangeLogger != null) {
|
||||
goofishOrderChangeLogger.append(row.getId(), row.getAppKey(), row.getOrderNo(),
|
||||
GoofishOrderChangeLogger.TYPE_SHIP, "AUTO_SHIP",
|
||||
"发货成功 waybill=" + waybill.trim() + " expressCode=" + expressCode);
|
||||
}
|
||||
} else {
|
||||
String msg = r != null ? r.getString("msg") : "unknown";
|
||||
patchShipError(row, msg != null ? msg : "发货接口返回失败");
|
||||
if (goofishOrderChangeLogger != null) {
|
||||
goofishOrderChangeLogger.append(row.getId(), row.getAppKey(), row.getOrderNo(),
|
||||
GoofishOrderChangeLogger.TYPE_SHIP, "AUTO_SHIP",
|
||||
"发货失败 " + (row.getShipError() != null ? row.getShipError() : msg));
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
patchShipError(row, ex.getMessage());
|
||||
if (goofishOrderChangeLogger != null) {
|
||||
goofishOrderChangeLogger.append(row.getId(), row.getAppKey(), row.getOrderNo(),
|
||||
GoofishOrderChangeLogger.TYPE_SHIP, "AUTO_SHIP",
|
||||
"发货异常 " + (row.getShipError() != null ? row.getShipError() : ex.getMessage()));
|
||||
}
|
||||
log.warn("闲管家发货异常 orderNo={}", row.getOrderNo(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,10 @@ import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.ruoyi.jarvis.config.JarvisGoofishProperties;
|
||||
import com.ruoyi.jarvis.domain.ErpGoofishOrder;
|
||||
import com.ruoyi.jarvis.domain.ErpGoofishOrderEventLog;
|
||||
import com.ruoyi.jarvis.domain.ErpOpenConfig;
|
||||
import com.ruoyi.jarvis.dto.GoofishNotifyMessage;
|
||||
import com.ruoyi.jarvis.mapper.ErpGoofishOrderEventLogMapper;
|
||||
import com.ruoyi.jarvis.mapper.ErpGoofishOrderMapper;
|
||||
import com.ruoyi.jarvis.service.IErpGoofishOrderService;
|
||||
import com.ruoyi.jarvis.service.IErpOpenConfigService;
|
||||
@@ -17,6 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@@ -37,6 +40,9 @@ public class ErpGoofishOrderServiceImpl implements IErpGoofishOrderService {
|
||||
@Resource
|
||||
private ErpGoofishOrderMapper erpGoofishOrderMapper;
|
||||
|
||||
@Resource
|
||||
private ErpGoofishOrderEventLogMapper erpGoofishOrderEventLogMapper;
|
||||
|
||||
@Resource
|
||||
private IErpOpenConfigService erpOpenConfigService;
|
||||
|
||||
@@ -159,4 +165,13 @@ public class ErpGoofishOrderServiceImpl implements IErpGoofishOrderService {
|
||||
goofishOrderPipeline.tryAutoShip(full);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ErpGoofishOrderEventLog> listEventLogsByOrderId(Long orderId) {
|
||||
if (orderId == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<ErpGoofishOrderEventLog> list = erpGoofishOrderEventLogMapper.selectByOrderId(orderId);
|
||||
return list != null ? list : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ruoyi.jarvis.mapper.ErpGoofishOrderEventLogMapper">
|
||||
|
||||
<resultMap id="ErpGoofishOrderEventLogResult" type="com.ruoyi.jarvis.domain.ErpGoofishOrderEventLog">
|
||||
<id property="id" column="id"/>
|
||||
<result property="orderId" column="order_id"/>
|
||||
<result property="appKey" column="app_key"/>
|
||||
<result property="orderNo" column="order_no"/>
|
||||
<result property="eventType" column="event_type"/>
|
||||
<result property="source" column="source"/>
|
||||
<result property="message" column="message"/>
|
||||
<result property="createTime" column="create_time"/>
|
||||
</resultMap>
|
||||
|
||||
<insert id="insert" parameterType="com.ruoyi.jarvis.domain.ErpGoofishOrderEventLog" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into erp_goofish_order_event_log
|
||||
(order_id, app_key, order_no, event_type, source, message, create_time)
|
||||
values
|
||||
(#{orderId}, #{appKey}, #{orderNo}, #{eventType}, #{source}, #{message}, #{createTime})
|
||||
</insert>
|
||||
|
||||
<select id="selectByOrderId" resultMap="ErpGoofishOrderEventLogResult">
|
||||
select id, order_id, app_key, order_no, event_type, source, message, create_time
|
||||
from erp_goofish_order_event_log
|
||||
where order_id = #{orderId}
|
||||
order by id desc
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user