|
@@ -0,0 +1,106 @@
|
|
|
+package com.qs.mp.web.controller.common;
|
|
|
+
|
|
|
+import cn.hutool.core.date.LocalDateTimeUtil;
|
|
|
+import cn.hutool.json.JSON;
|
|
|
+import cn.hutool.json.JSONArray;
|
|
|
+import cn.hutool.json.JSONConfig;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.google.gson.Gson;
|
|
|
+import com.kuaidi100.sdk.api.AutoNum;
|
|
|
+import com.kuaidi100.sdk.core.IBaseClient;
|
|
|
+import com.kuaidi100.sdk.pojo.HttpResult;
|
|
|
+import com.kuaidi100.sdk.request.AutoNumReq;
|
|
|
+import com.qs.mp.common.core.domain.AjaxResult;
|
|
|
+import com.qs.mp.common.domain.DeliveryCompany;
|
|
|
+import com.qs.mp.common.service.IDeliveryCompanyService;
|
|
|
+import io.swagger.annotations.*;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.time.Duration;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author Cup
|
|
|
+ * @date 2022/4/20
|
|
|
+ */
|
|
|
+@RequestMapping("/api/v1/mp/logistics")
|
|
|
+@RestController
|
|
|
+@Api(tags = "物流相关接口")
|
|
|
+public class LogisticsController extends BaseApiController {
|
|
|
+
|
|
|
+
|
|
|
+ @Value("${kuaidi100.key}")
|
|
|
+ public String key;
|
|
|
+
|
|
|
+ @Value("${kuaidi100.customer}")
|
|
|
+ private String customer;
|
|
|
+
|
|
|
+ @Value("${kuaidi100.secret}")
|
|
|
+ private String secret;
|
|
|
+
|
|
|
+ @Value("${kuaidi100.userid}")
|
|
|
+ private String userid;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IDeliveryCompanyService deliveryCompanyService;
|
|
|
+
|
|
|
+ @PostMapping("/autonumber/auto/{number}")
|
|
|
+ @ApiOperation("自动单号识别接口")
|
|
|
+ @ApiImplicitParams(
|
|
|
+ @ApiImplicitParam(name = "number", value = "快递单号", required = true, dataType = "String", paramType = "path")
|
|
|
+ )
|
|
|
+ @ApiResponses(
|
|
|
+ @ApiResponse(code = 200, message = "成功", response = DeliveryCompany.class)
|
|
|
+ )
|
|
|
+ public AjaxResult autonumber(@PathVariable("number") String number) {
|
|
|
+ if (StringUtils.isBlank(number)) {
|
|
|
+ return error("快递单号不能为空");
|
|
|
+ }
|
|
|
+ AutoNumReq autoNumReq = new AutoNumReq();
|
|
|
+ autoNumReq.setKey(key);
|
|
|
+ autoNumReq.setNum(number);
|
|
|
+ IBaseClient baseClient = new AutoNum();
|
|
|
+ try {
|
|
|
+ HttpResult execute = baseClient.execute(autoNumReq);
|
|
|
+ if (Objects.isNull(execute)) {
|
|
|
+ return error("自动单号识别失败");
|
|
|
+ }
|
|
|
+ String body = execute.getBody();
|
|
|
+ if (StringUtils.isBlank(body)) {
|
|
|
+ return error("自动单号识别失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONArray jsonArray = JSONUtil.parseArray(body);
|
|
|
+ if (jsonArray.size() != 1) {
|
|
|
+ return AjaxResult.success();
|
|
|
+ }
|
|
|
+ String name = jsonArray.getJSONObject(0).getStr("name");
|
|
|
+
|
|
|
+ DeliveryCompany deliveryCompany = deliveryCompanyService.getOne(new LambdaQueryWrapper<DeliveryCompany>().eq(DeliveryCompany::getCompanyName, name));
|
|
|
+ return AjaxResult.success(deliveryCompany);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ return AjaxResult.success();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return error(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|