|
|
@@ -0,0 +1,78 @@
|
|
|
+package com.fs.kdniao.controller;
|
|
|
+
|
|
|
+import com.fs.common.annotation.Log;
|
|
|
+import com.fs.common.core.controller.BaseController;
|
|
|
+import com.fs.common.core.domain.AjaxResult;
|
|
|
+import com.fs.common.enums.BusinessType;
|
|
|
+import com.fs.kdniao.domain.KdniaoSubmitCommand;
|
|
|
+import com.fs.kdniao.domain.KdniaoUniversalResponse;
|
|
|
+import com.fs.kdniao.domain.KdniaoWaybill;
|
|
|
+import com.fs.kdniao.service.IKdniaoUniversalEOrderService;
|
|
|
+import com.fs.kdniao.service.KdniaoWaybillService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 快递鸟统一电子面单控制器
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/kdniao/universal/eorder")
|
|
|
+public class KdniaoUniversalEOrderController extends BaseController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IKdniaoUniversalEOrderService kdniaoUniversalEOrderService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private KdniaoWaybillService kdniaoWaybillService;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 统一下单
|
|
|
+ */
|
|
|
+ @Log(title = "快递鸟统一电子面单", businessType = BusinessType.INSERT)
|
|
|
+ @PostMapping("/submit")
|
|
|
+ public AjaxResult submit(@RequestBody KdniaoSubmitCommand command) {
|
|
|
+ try {
|
|
|
+ // 1. 先查本地是否已有面单,避免重复下单
|
|
|
+ KdniaoWaybill exist = kdniaoWaybillService.selectByOrderCode(command.getBizOrderNo());
|
|
|
+ if (exist != null) {
|
|
|
+ return AjaxResult.success("该订单已生成面单,返回已保存数据", exist);
|
|
|
+ }
|
|
|
+
|
|
|
+ KdniaoUniversalResponse response = kdniaoUniversalEOrderService.submit(command);
|
|
|
+
|
|
|
+ if (Boolean.TRUE.equals(response.getSuccess()) && "100".equals(response.getResultCode())) {
|
|
|
+ KdniaoWaybill waybill = kdniaoWaybillService.saveWaybill(command, response);
|
|
|
+ return AjaxResult.success("下单成功", waybill);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 订单重复:优先查本地已保存面单
|
|
|
+ if ("106".equals(response.getResultCode())) {
|
|
|
+ KdniaoWaybill dbWaybill = kdniaoWaybillService.selectByOrderCode(command.getBizOrderNo());
|
|
|
+ if (dbWaybill != null) {
|
|
|
+ return AjaxResult.success("该订单号已存在面单,返回本地保存数据", dbWaybill);
|
|
|
+ }
|
|
|
+ return AjaxResult.error("订单号重复,快递鸟返回:该订单号已下单成功,但本地未保存到面单");
|
|
|
+ }
|
|
|
+
|
|
|
+ return AjaxResult.error("下单失败:" + response.getReason(), response);
|
|
|
+ } catch (Exception e) {
|
|
|
+ return AjaxResult.error("下单异常:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查看订单面单信息
|
|
|
+ */
|
|
|
+// @PreAuthorize("@ss.hasPermi('store:storeOrder:query')")
|
|
|
+ @GetMapping("/waybill/{orderCode}")
|
|
|
+ public AjaxResult getWaybillInfo(@PathVariable Long orderCode) {
|
|
|
+ KdniaoWaybill waybill = kdniaoWaybillService.selectByOrderCode(String.valueOf(orderCode));
|
|
|
+ if (waybill == null) {
|
|
|
+ return AjaxResult.error("该订单暂无面单信息");
|
|
|
+ }
|
|
|
+
|
|
|
+ return AjaxResult.success(waybill);
|
|
|
+ }
|
|
|
+}
|