Przeglądaj źródła

请求停止充电

skyline 2 lat temu
rodzic
commit
901a1e8993

+ 3 - 3
miniapp/src/main/java/com/kym/miniapp/controller/ChargerController.java

@@ -81,9 +81,9 @@ public class ChargerController {
     }
 
     @SysLog("停止充电")
-    @PostMapping("/stopCharge")
-    R stopCharge(@RequestBody String startChargeSeq, @RequestBody String connectorId) {
-        chargeService.queryStopCharge(startChargeSeq, connectorId);
+    @GetMapping("/stopCharge/{connectorId}")
+    R stopCharge(@PathVariable("connectorId") String connectorId) {
+        chargeService.queryStopCharge(connectorId);
         return R.success();
     }
 

+ 1 - 1
service/src/main/java/com/kym/service/miniapp/ChargeService.java

@@ -16,7 +16,7 @@ public interface ChargeService {
 
     ChargeOrder queryEquipChargeStatus(String startChargeSeq);
 
-    void queryStopCharge(String startChargeSeq, String connectorId);
+    void queryStopCharge(String connectorId);
 
     EnBusinessPolicy queryEquipBusinessPolicy(String connectorId);
 }

+ 32 - 34
service/src/main/java/com/kym/service/miniapp/impl/ChargeServiceImpl.java

@@ -3,7 +3,6 @@ package com.kym.service.miniapp.impl;
 import cn.dev33.satoken.stp.StpUtil;
 import com.kym.common.constant.ResponseEnum;
 import com.kym.common.exception.BusinessException;
-import com.kym.common.utils.IDGenerator;
 import com.kym.common.utils.OrderUtils;
 import com.kym.entity.enplus.response.EnBusinessPolicy;
 import com.kym.entity.miniapp.ChargeOrder;
@@ -29,10 +28,6 @@ import java.util.Map;
 public class ChargeServiceImpl implements ChargeService {
     private static final Logger LOGGER = LoggerFactory.getLogger(ChargeServiceImpl.class);
 
-
-    @Autowired
-    private IDGenerator idGenerator;
-
     @Autowired
     private EquipmentRelationService equipmentRelationService;
 
@@ -57,22 +52,7 @@ public class ChargeServiceImpl implements ChargeService {
     @Override
     public Map queryStartCharge(String connectorId, String stationId) {
         var userId = StpUtil.getSession().getLong("userId");
-        if (connectorId.length() == 6) {
-            // 查询EN+设备SN
-            var equipmentRelation = equipmentRelationService.getByShortId(connectorId);
-            connectorId = equipmentRelation.getEquipmentId();
-            if (connectorId.length() == 16) {
-                // 如果是16位,末尾补1作为单枪枪号
-                connectorId = connectorId.concat("1");
-            }
-        }
-        if (connectorId.length() == 16) {
-            connectorId = connectorId.concat("1");
-        } else {
-            // 充电桩编号错误
-            LOGGER.error("用户:{}请求充电,设备编码错误:{}", userId, connectorId);
-            throw new BusinessException(ResponseEnum.EQUIP_CONNECTOR_ID_ERROR);
-        }
+        stationId = getConnectorId(stationId);
 
         // 二维码文本
         var qrCode = "";
@@ -167,29 +147,47 @@ public class ChargeServiceImpl implements ChargeService {
         }
     }
 
+    public String getConnectorId(String connectorId) {
+        if (connectorId.length() == 6) {
+            // 查询EN+设备SN
+            var equipmentRelation = equipmentRelationService.getByShortId(connectorId);
+            connectorId = equipmentRelation.getEquipmentId();
+            if (connectorId.length() == 16) {
+                // 如果是16位,末尾补1作为单枪枪号
+                connectorId = connectorId.concat("1");
+            }
+        }
+        if (connectorId.length() == 16) {
+            connectorId = connectorId.concat("1");
+        } else {
+            // 充电桩编号错误
+            LOGGER.error("设备编码错误:{}", connectorId);
+            throw new BusinessException(ResponseEnum.EQUIP_CONNECTOR_ID_ERROR);
+        }
+        return connectorId;
+    }
+
 
     /**
      * 请求停止充电
      *
-     * @param startChargeSeq
      * @param connectorId
      */
     @Override
-    public void queryStopCharge(String startChargeSeq, String connectorId) {
-        if (connectorId.length() == 6) {
-            var equipmentRelation = equipmentRelationService.getByShortId(connectorId);
-            var equipmentId = equipmentRelation.getEquipmentId();
-            if (equipmentId.length() == 16) {
-                // 如果是16位,末尾补1作为单枪枪号
-                connectorId = equipmentId.concat("1");
-            }
-        } else if (connectorId.length() == 16) {
-            connectorId = connectorId.concat("1");
+    public void queryStopCharge(String connectorId) {
+        var userId = StpUtil.getLoginIdAsLong();
+        connectorId = getConnectorId(connectorId);
+        // 查询充电订单
+        var chargeOrder = chargeOrderService.lambdaQuery().eq(ChargeOrder::getUserId, userId).eq(ChargeOrder::getConnectorId, connectorId).one();
+        if (chargeOrder == null) {
+            // 记录失败原因
+            LOGGER.error("用户:{}请求停止充电异常,设备:{}无进行中的订单", userId, connectorId);
+            throw new BusinessException(ResponseEnum.NO_ORDER_IN_PROGRESS);
         }
-        var data = enPlusService.queryStopCharge(startChargeSeq, connectorId);
+        var data = enPlusService.queryStopCharge(chargeOrder.getStartChargeSeq(), connectorId);
         if (data.containsKey("SuccStat") && data.getIntValue("SuccStat") != 0) {
             // 记录失败原因
-            LOGGER.error("订单:{}停止充电失败,返回结果{}", startChargeSeq, data);
+            LOGGER.error("订单:{}停止充电失败,返回结果:{}", chargeOrder.getStartChargeSeq(), data);
             throw new BusinessException(ResponseEnum.EN_PLUS_EQUIP_STOP_FAIL);
         }
         // 这里不更新订单状态,等待EN+推送停止充电结果信息再处理