ソースを参照

获取停车优惠

skyline 1 年間 前
コミット
a8916ca249

+ 14 - 4
car-wash-miniapp/src/main/java/com/kym/miniapp/controller/WashOrderController.java

@@ -1,14 +1,12 @@
 package com.kym.miniapp.controller;
 
+import cn.dev33.satoken.annotation.SaIgnore;
 import com.kym.common.R;
 import com.kym.common.controller.IController;
 import com.kym.entity.common.PageParams;
 import com.kym.entity.queryParams.WashOrderQueryParams;
 import com.kym.service.WashOrderService;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.ModelAttribute;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 /**
  * <p>
@@ -51,4 +49,16 @@ public class WashOrderController extends IController {
         return resp(() -> washOrderService.queryOrder(params));
     }
 
+    /**
+     * 获取停车优惠
+     *
+     * @param unionid
+     * @return
+     */
+    @SaIgnore
+    @GetMapping(value = "/getParkingDiscounts/{unionid}")
+    R<?> getParkingDiscounts(@PathVariable String unionid) {
+        return resp(() -> washOrderService.getParkingDiscounts(unionid));
+    }
+
 }

+ 3 - 0
car-wash-service/src/main/java/com/kym/service/WashOrderService.java

@@ -30,6 +30,9 @@ public interface WashOrderService extends MyBaseService<WashOrder> {
 
     WashOrder queryOrder(WashOrderQueryParams params);
 
+
+    String getParkingDiscounts(String unionid);
+
     PageBean<WashOrderVo> listMyWashOrder(PageParams params);
 
     Object list(WashOrderQueryParams query);

+ 32 - 1
car-wash-service/src/main/java/com/kym/service/impl/WashOrderServiceImpl.java

@@ -12,6 +12,7 @@ import com.kym.common.utils.OrderUtils;
 import com.kym.entity.Account;
 import com.kym.entity.User;
 import com.kym.entity.WashOrder;
+import com.kym.entity.WashStation;
 import com.kym.entity.common.PageBean;
 import com.kym.entity.common.PageParams;
 import com.kym.entity.queryParams.DeviceQueryParams;
@@ -21,7 +22,9 @@ import com.kym.entity.vo.StationTrendVo;
 import com.kym.entity.vo.WashOrderVo;
 import com.kym.mapper.WashOrderMapper;
 import com.kym.service.AccountService;
+import com.kym.service.UserService;
 import com.kym.service.WashOrderService;
+import com.kym.service.WashStationService;
 import com.kym.service.awoara.AwoaraService;
 import com.kym.service.cache.KymCache;
 import com.kym.service.mybatisplus.MyBaseServiceImpl;
@@ -49,10 +52,14 @@ public class WashOrderServiceImpl extends MyBaseServiceImpl<WashOrderMapper, Was
 
     private final AwoaraService awoaraService;
     private final AccountService accountService;
+    private final WashStationService washStationService;
+    private final UserService userService;
 
-    public WashOrderServiceImpl(AwoaraService awoaraService, AccountService accountService) {
+    public WashOrderServiceImpl(AwoaraService awoaraService, AccountService accountService, WashStationService washStationService, UserService userService) {
         this.awoaraService = awoaraService;
         this.accountService = accountService;
+        this.washStationService = washStationService;
+        this.userService = userService;
     }
 
     /**
@@ -146,6 +153,30 @@ public class WashOrderServiceImpl extends MyBaseServiceImpl<WashOrderMapper, Was
         return order;
     }
 
+    /**
+     * 查询停车减免订单
+     *
+     * @param unionid
+     * @return
+     */
+    @Override
+    public String getParkingDiscounts(String unionid) {
+        var user = userService.lambdaQuery().eq(User::getUnionid, unionid).one();
+        CommUtil.asserts(null != user, "用户信息异常:无此用户");
+        // 查询用户24小时内的订单
+        var orders = lambdaQuery()
+                .eq(WashOrder::getUserId, user.getId())
+                .ge(WashOrder::getStartTime, LocalDateTime.now().minusHours(24))
+                .eq(WashOrder::getPayStatus, WashOrder.PAY_STATUS_已支付)
+                .orderByDesc(WashOrder::getId)
+                .list();
+
+        CommUtil.asserts(CommUtil.isEmptyOrNull(orders) && (orders.stream().mapToInt(WashOrder::getAmount).sum() >= 0),
+                "抱歉:无停车场洗车记录");
+
+        return washStationService.lambdaQuery().eq(WashStation::getStationId, orders.get(0).getStationId()).one().getParkingQrCode();
+    }
+
     /**
      * 当前用户订单列表
      *

+ 1 - 3
car-wash-service/src/main/java/com/kym/service/parking/ZongTingParkingApiServiceImpl.java

@@ -5,12 +5,10 @@ import com.kym.common.R;
 import com.kym.common.exception.BusinessException;
 import com.kym.common.utils.HttpUtil;
 import lombok.extern.slf4j.Slf4j;
-import okhttp3.*;
 import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
 
-import java.io.IOException;
 import java.util.Arrays;
 import java.util.Map;
 
@@ -27,7 +25,6 @@ public class ZongTingParkingApiServiceImpl implements ParkingApi {
     private static final String ZONG_TING_URL = "http://shenzhen.gate.4pyun.com:8661";
 
 
-
     /**
      * 【纵停】生成签名
      *
@@ -68,6 +65,7 @@ public class ZongTingParkingApiServiceImpl implements ParkingApi {
         var signParams = Map.of("plateNo", params.getPlateNo(), "merchId", params.getMerchId(), "duration", params.getCouponValue());
         params.setSign(genSign(signParams));
         var res = HttpUtil.post(ZONG_TING_URL, JSONObject.toJSONString(params), R.class);
+        log.info("停车场ID:{},车辆:{}减免停车费用结果:{}", params.getParkId(), params.getParkId(), res);
         return switch (res.getCode()) {
             case 10001 -> R.success();
             case 10002 -> throw new BusinessException("车辆未入场");