|
|
|
|
package com.project.receive.controller;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.project.receive.domain.dto.SfPodPushRequest;
|
|
|
|
|
import com.project.receive.domain.dto.SfRoutePushRequest;
|
|
|
|
|
import com.project.receive.domain.service.ReceiveService;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/api/sf/callback")
|
|
|
|
|
public class ReceiveController {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ReceiveService receiveService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 1. 路由状态回调 (揽收/签收)
|
|
|
|
|
* 对应接口: PushOrderState
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/route")
|
|
|
|
|
public Map<String, Object> handleRoutePush(@RequestBody SfRoutePushRequest request) {
|
|
|
|
|
log.info(">>> 收到顺丰路由推送,包含节点数: {}",
|
|
|
|
|
(request.getBody() != null && request.getBody().getWaybillRoute() != null) ?
|
|
|
|
|
request.getBody().getWaybillRoute().size() : 0);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// 业务处理逻辑
|
|
|
|
|
receiveService.processRoutePush(request);
|
|
|
|
|
|
|
|
|
|
// 返回顺丰要求的成功格式
|
|
|
|
|
return successResponse();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error(">>> 路由解析处理失败", e);
|
|
|
|
|
return failResponse(e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 2. 费用与重量回调
|
|
|
|
|
* 对应接口: EXP_RECE_WAYBILLS_FEE_PUSH
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/fee")
|
|
|
|
|
public Map<String, Object> handleFeePush(@RequestParam("content") String content) {
|
|
|
|
|
log.info(">>> 收到顺丰【运费重量】推送: {}", content);
|
|
|
|
|
try {
|
|
|
|
|
receiveService.saveFeeLog(content);
|
|
|
|
|
return successResponse();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("运费处理异常", e);
|
|
|
|
|
return failResponse(e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 3. 电子回单图片回调
|
|
|
|
|
* 对应接口: 图片注册及推送接口
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/pod-picture")
|
|
|
|
|
public Map<String, Object> handlePodPicturePush(@RequestBody SfPodPushRequest request) {
|
|
|
|
|
log.info(">>> 收到顺丰【电子回单图片】推送 (内容较长,不完整打印)");
|
|
|
|
|
try {
|
|
|
|
|
receiveService.savePodPictureLog(request);
|
|
|
|
|
return successResponse();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("回单图片处理异常", e);
|
|
|
|
|
return failResponse(e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Map<String, Object> successResponse() {
|
|
|
|
|
Map<String, Object> res = new HashMap<>();
|
|
|
|
|
res.put("success", true);
|
|
|
|
|
res.put("errorCode", "S0000");
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Map<String, Object> failResponse(String msg) {
|
|
|
|
|
Map<String, Object> res = new HashMap<>();
|
|
|
|
|
res.put("success", false);
|
|
|
|
|
res.put("errorMsg", msg);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
}
|