Pārlūkot izejas kodu

feat(charging): 新增设备状态变化推送接口

- 在ChargingReceptionService中新增stationStatus方法定义
- 在ChargingReceptionServiceImpl中实现设备状态变化推送逻辑
- 新增设备状态变化推送的控制器接口
- 优化JwtAuthenticationEntryPoint返回字段命名
- 清理第三方认证过滤器中的无用导入和代码
- 更新LinkDataController注解引入方式并添加新接口映射
wzq 3 nedēļas atpakaļ
vecāks
revīzija
d35d398bc6

+ 1 - 1
src/main/java/com/zsElectric/boot/auth/controller/ThirdPartyAuthController.java

@@ -65,7 +65,7 @@ public class ThirdPartyAuthController {
                         ConnectivityConstants.SIG_SECRET));
             }
 
-            //todo redis获取token,不存在则创建
+            //redis获取token,不存在则创建
             String accessToken = jwtTokenUtil.generateToken(queryTokenRequestParms.getOperatorID());
             Integer remainingTTL = jwtTokenUtil.getRemainingTTL(accessToken).intValue();
             //构建Data(token信息)

+ 9 - 4
src/main/java/com/zsElectric/boot/charging/controller/LinkDataController.java

@@ -7,10 +7,7 @@ import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 @Slf4j
 @RestController
@@ -60,4 +57,12 @@ public class LinkDataController {
         return chargingReceptionService.chargeOrderResponse(requestDTO);
     }
 
+    /**
+     * 3.2 设备状态变化推送
+     * */
+    @Operation(summary = "设备状态变化推送")
+    @PostMapping("/notification_stationStatus")
+    public ResponseParmsEntity stationStatus(@RequestBody RequestParmsEntity requestDTO){
+        return chargingReceptionService.stationStatus(requestDTO);
+    }
 }

+ 5 - 0
src/main/java/com/zsElectric/boot/charging/service/ChargingReceptionService.java

@@ -31,4 +31,9 @@ public interface ChargingReceptionService {
      * 2.9 推送充电订单信息
      * */
     ResponseParmsEntity chargeOrderResponse(RequestParmsEntity requestDTO);
+
+    /**
+     * 3.2 设备状态变化推送
+     * */
+    ResponseParmsEntity stationStatus(RequestParmsEntity requestDTO);
 }

+ 41 - 0
src/main/java/com/zsElectric/boot/charging/service/impl/ChargingReceptionServiceImpl.java

@@ -12,6 +12,9 @@ import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
+import java.util.HashMap;
+import java.util.Map;
+
 import static com.zsElectric.boot.common.constant.ConnectivityConstants.FAIL_REASON_NONE;
 import static com.zsElectric.boot.common.constant.ConnectivityConstants.STATUS_OK;
 import static com.zsElectric.boot.common.util.HmacMD5Util.genSign;
@@ -170,4 +173,42 @@ public class ChargingReceptionServiceImpl implements ChargingReceptionService {
                 .setSig(genSign);
     }
 
+    @Override
+    public ResponseParmsEntity stationStatus(RequestParmsEntity requestDTO) {
+        log.info("接收设备状态变化推送请求参数:{}", requestDTO);
+        String encryptData = "";
+        String genSign = "";
+        ResponseParmsEntity responseParmsEntity = new ResponseParmsEntity();
+
+        try {
+            String data = requestDTO.getOperatorID() + requestDTO.getData() + requestDTO.getTimeStamp() + requestDTO.getSeq();
+            if (verify(data, ConnectivityConstants.SIG_SECRET, requestDTO.getSig())) {
+                String decryptData = chargingUtil.decryptData(requestDTO.getData());
+                log.info("解密后的数据:{}", decryptData);
+
+                // todo 业务代码待处理
+
+                Map<String, Integer> statusMap = new HashMap<>();
+                statusMap.put("Status", 0);
+                encryptData = chargingUtil.encryptData(new Gson().toJson(statusMap));
+                genSign = genSign(STATUS_OK, "", encryptData, ConnectivityConstants.SIG_SECRET);
+
+                responseParmsEntity
+                        .setRet(STATUS_OK)
+                        .setMsg("")
+                        .setData(encryptData)
+                        .setSig(genSign);
+            } else {
+                log.error("数据验签失败");
+                throw new BusinessException("数据验签失败");
+            }
+        } catch (Exception e) {
+            log.error("数据解密失败:{}", e.getMessage());
+            throw new BusinessException("数据解密失败:" + e.getMessage(), e);
+        }
+
+        return responseParmsEntity;
+
+    }
+
 }

+ 2 - 2
src/main/java/com/zsElectric/boot/common/util/electric/queryToken/JwtAuthenticationEntryPoint.java

@@ -21,8 +21,8 @@ public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint {
         response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
         response.setContentType(MediaType.APPLICATION_JSON_VALUE);
         Map<String, Object> error = new HashMap<>();
-        error.put("status", 401);
-        error.put("message", authException.getMessage());
+        error.put("ret", 401);
+        error.put("msg", authException.getMessage());
         error.put("path", request.getRequestURI());
         new ObjectMapper().writeValue(response.getWriter(), error);
     }

+ 0 - 7
src/main/java/com/zsElectric/boot/common/util/electric/queryToken/ThirdPartyJwtAuthFilter.java

@@ -1,18 +1,13 @@
 package com.zsElectric.boot.common.util.electric.queryToken;
 
-import com.zsElectric.boot.common.constant.ConnectivityConstants;
 import jakarta.annotation.Resource;
 import jakarta.servlet.FilterChain;
 import jakarta.servlet.ServletException;
 import jakarta.servlet.http.HttpServletRequest;
 import jakarta.servlet.http.HttpServletResponse;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.authentication.AuthenticationServiceException;
 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
-import org.springframework.security.core.GrantedAuthority;
 import org.springframework.security.core.context.SecurityContextHolder;
-import org.springframework.security.core.userdetails.UserDetails;
-import org.springframework.security.web.AuthenticationEntryPoint;
 import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
 import org.springframework.stereotype.Component;
 import org.springframework.util.AntPathMatcher;
@@ -21,8 +16,6 @@ import org.springframework.web.filter.OncePerRequestFilter;
 
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
 
 @Component
 public class ThirdPartyJwtAuthFilter extends OncePerRequestFilter {