diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/thirdparty/hainan/HaiNanPlatformController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/thirdparty/hainan/HaiNanPlatformController.java index 338c78aed..d34422824 100644 --- a/jsowell-admin/src/main/java/com/jsowell/web/controller/thirdparty/hainan/HaiNanPlatformController.java +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/thirdparty/hainan/HaiNanPlatformController.java @@ -4,7 +4,12 @@ import com.alibaba.fastjson2.JSONObject; import com.jsowell.common.annotation.Anonymous; import com.jsowell.common.core.controller.BaseController; import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum; +import com.jsowell.common.exception.BusinessException; +import com.jsowell.common.response.RestApiResponse; import com.jsowell.common.util.JWTUtils; +import com.jsowell.pile.dto.QueryEquipChargeStatusDTO; +import com.jsowell.pile.dto.QueryEquipmentDTO; +import com.jsowell.pile.dto.QueryStartChargeDTO; import com.jsowell.pile.dto.QueryStationInfoDTO; import com.jsowell.thirdparty.platform.hainan.service.HaiNanPlatformLogic; import com.jsowell.thirdparty.lianlian.common.CommonResult; @@ -12,10 +17,7 @@ import com.jsowell.thirdparty.lianlian.dto.CommonParamsDTO; import com.jsowell.thirdparty.lianlian.util.Cryptos; import com.jsowell.thirdparty.lianlian.util.Encodes; import com.jsowell.thirdparty.platform.AbsInterfaceWithPlatformLogic; -import org.springframework.web.bind.annotation.PostMapping; -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.*; import javax.servlet.http.HttpServletRequest; import java.nio.charset.StandardCharsets; @@ -171,8 +173,288 @@ public class HaiNanPlatformController extends BaseController { return CommonResult.success(0, "设备接口状态查询成功!", map.get("Data"), map.get("Sig")); } catch (Exception e) { logger.info("海南平台设备接口状态查询 error:", e); - // e.printStackTrace(); } return CommonResult.failed("设备接口状态查询发生异常"); } + + /** + * 请求设备认证 + * @param request + * @param dto + * @return + */ + @PostMapping("/v1/query_equip_auth") + public CommonResult queryEquipAuth(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { + logger.info("请求设备认证 param:{}", JSONObject.toJSONString(dto)); + try { + // 校验令牌 + String token = request.getHeader("Authorization"); + if (!JWTUtils.checkThirdPartyToken(token)) { + // 校验失败 + return CommonResult.failed("令牌校验错误"); + } + // 校验签名 + Map resultMap = platformLogic.checkoutSign(dto); + if (resultMap == null) { + // 签名错误 + return CommonResult.failed("签名校验错误"); + } + String operatorSecret = resultMap.get("OperatorSecret"); + String dataString = resultMap.get("Data"); + String dataSecret = resultMap.get("DataSecret"); + String dataSecretIV = resultMap.get("DataSecretIV"); + // 解密data + byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), dataSecret.getBytes(), dataSecretIV.getBytes()); + String dataStr = new String(plainText, StandardCharsets.UTF_8); + // 转换成相应对象 + QueryEquipmentDTO queryEquipmentDTO = JSONObject.parseObject(dataStr, QueryEquipmentDTO.class); + queryEquipmentDTO.setOperatorID(dto.getOperatorID()); + Map map = platformLogic.queryEquipAuth(queryEquipmentDTO); + logger.info("请求设备认证 result:{}", JSONObject.toJSONString(map)); + return CommonResult.success(0, "请求设备认证成功!", map.get("Data"), map.get("Sig")); + } catch (Exception e) { + logger.info("请求设备认证 error:", e); + e.printStackTrace(); + } + return CommonResult.failed("请求设备认证发生异常"); + } + + /** + * 查询业务策略信息结果 + * http://localhost:8080/hainan/v1/query_equip_business_policy + * @param dto + * @return + */ + @PostMapping("/v1/query_equip_business_policy") + public CommonResult queryEquipBusinessPolicy(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { + logger.info("查询业务策略信息 params:{}", JSONObject.toJSONString(dto)); + try { + // 校验令牌 + String token = request.getHeader("Authorization"); + if (!JWTUtils.checkThirdPartyToken(token)) { + // 校验失败 + return CommonResult.failed("令牌校验错误"); + } + // 校验签名 + Map resultMap = platformLogic.checkoutSign(dto); + if (resultMap == null) { + // 签名错误 + return CommonResult.failed("签名校验错误"); + } + String operatorSecret = resultMap.get("OperatorSecret"); + String dataString = resultMap.get("Data"); + String dataSecret = resultMap.get("DataSecret"); + String dataSecretIV = resultMap.get("DataSecretIV"); + + // 解密data + byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), dataSecret.getBytes(), dataSecretIV.getBytes()); + String dataStr = new String(plainText, StandardCharsets.UTF_8); + // 转换成相应对象 + QueryStartChargeDTO queryStartChargeDTO = JSONObject.parseObject(dataStr, QueryStartChargeDTO.class); + queryStartChargeDTO.setOperatorId(dto.getOperatorID()); + Map map = platformLogic.queryEquipBusinessPolicy(queryStartChargeDTO); + logger.info("查询业务策略信息 result:{}", JSONObject.toJSONString(map)); + + return CommonResult.success(0, "查询业务策略信息成功!", map.get("Data"), map.get("Sig")); + } catch (Exception e) { + logger.info("查询业务策略信息 error:", e); + e.printStackTrace(); + } + return CommonResult.failed("查询业务策略信息发生异常"); + } + + /** + * 请求启动充电 + * @param request + * @param dto + * @return + */ + @PostMapping("/v1/query_start_charge") + public CommonResult query_start_charge(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { + logger.info("海南平台请求启动充电 params :{}", JSONObject.toJSONString(dto)); + try { + // 校验令牌 + String token = request.getHeader("Authorization"); + if (!JWTUtils.checkThirdPartyToken(token)) { + // 校验失败 + return CommonResult.failed("令牌校验错误"); + } + // 校验签名 + Map resultMap = platformLogic.checkoutSign(dto); + if (resultMap == null) { + // 签名错误 + return CommonResult.failed("签名校验错误"); + } + String operatorSecret = resultMap.get("OperatorSecret"); + String dataString = resultMap.get("Data"); + String dataSecret = resultMap.get("DataSecret"); + String dataSecretIV = resultMap.get("DataSecretIV"); + // 解密data + byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), dataSecret.getBytes(), dataSecretIV.getBytes()); + String dataStr = new String(plainText, StandardCharsets.UTF_8); + // 转换成相应对象 + QueryStartChargeDTO queryStartChargeDTO = JSONObject.parseObject(dataStr, QueryStartChargeDTO.class); + queryStartChargeDTO.setOperatorId(dto.getOperatorID()); + Map map = platformLogic.queryStartCharge(queryStartChargeDTO); + logger.info("海南平台请求启动充电 result:{}", JSONObject.toJSONString(map)); + return CommonResult.success(0, "请求启动充电成功!", map.get("Data"), map.get("Sig")); + } catch (Exception e) { + logger.error("海南平台请求启动充电 error", e); + } + return CommonResult.failed("请求启动充电发生异常"); + } + + /** + * 推送启动充电结果 + * http://localhost:8080/hainan/notificationStartChargeResult/{orderCode} + * @param orderCode + * @return + */ + @GetMapping("/notificationStartChargeResult/{orderCode}") + public RestApiResponse notificationStartChargeResult(@PathVariable("orderCode") String orderCode) { + logger.info("【{}】推送启动充电结果 params:{}", this.getClass().getSimpleName(), orderCode); + RestApiResponse response = null; + try { + String result = platformLogic.notificationStartChargeResult(orderCode); + response = new RestApiResponse<>(result); + }catch (BusinessException e) { + logger.error("【{}】推送启动充电结果 error",this.getClass().getSimpleName(), e); + response = new RestApiResponse<>(e.getCode(), e.getMessage()); + }catch (Exception e) { + logger.error("【{}】推送启动充电结果 error", this.getClass().getSimpleName(), e); + response = new RestApiResponse<>(e); + } + logger.info("【{}】推送启动充电结果 result:{}", this.getClass().getSimpleName(), response); + return response; + } + + /** + * 查询充电状态 + * http://localhost:8080/xindiantu/query_equip_charge_status/{startChargeSeq} + * @param dto + * @return + */ + @PostMapping("/v1/query_equip_charge_status") + public CommonResult queryEquipChargeStatus(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { + logger.info("【{}】查询充电状态 params :{}", this.getClass().getSimpleName(), JSONObject.toJSONString(dto)); + try { + // 校验令牌 + String token = request.getHeader("Authorization"); + if (!JWTUtils.checkThirdPartyToken(token)) { + // 校验失败 + return CommonResult.failed("令牌校验错误"); + } + // 校验签名 + Map resultMap = platformLogic.checkoutSign(dto); + if (resultMap == null) { + // 签名错误 + return CommonResult.failed("签名校验错误"); + } + String operatorSecret = resultMap.get("OperatorSecret"); + String dataString = resultMap.get("Data"); + String dataSecret = resultMap.get("DataSecret"); + String dataSecretIV = resultMap.get("DataSecretIV"); + // 解密data + byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), dataSecret.getBytes(), dataSecretIV.getBytes()); + String dataStr = new String(plainText, StandardCharsets.UTF_8); + // 转换成相应对象 + QueryEquipChargeStatusDTO queryEquipChargeStatusDTO = JSONObject.parseObject(dataStr, QueryEquipChargeStatusDTO.class); + queryEquipChargeStatusDTO.setOperatorID(dto.getOperatorID()); + Map map = platformLogic.queryEquipChargeStatus(queryEquipChargeStatusDTO); + logger.info("【{}】查询充电状态 result:{}", this.getClass().getSimpleName(), JSONObject.toJSONString(map)); + return CommonResult.success(0, "查询充电状态成功!", map.get("Data"), map.get("Sig")); + } catch (Exception e) { + logger.error("【{}】平台查询充电状态 error", this.getClass().getSimpleName(), e); + } + return CommonResult.failed("新电途平台查询充电状态发生异常"); + } + + /** + * 推送充电状态 + * http://localhost:8080/hainan/notificationEquipChargeStatus + * @param orderCode + * @return + */ + @GetMapping("/notificationEquipChargeStatus/{orderCode}") + public RestApiResponse notificationEquipChargeStatus(@PathVariable("orderCode") String orderCode) { + logger.info("推送充电状态 params:{}", orderCode); + RestApiResponse response = null; + try { + String result = platformLogic.notificationEquipChargeStatus(orderCode); + response = new RestApiResponse<>(result); + }catch (BusinessException e) { + logger.error("推送充电状态 error",e); + response = new RestApiResponse<>(e.getCode(), e.getMessage()); + }catch (Exception e) { + logger.error("推送充电状态 error", e); + response = new RestApiResponse<>(e); + } + logger.info("推送充电状态 result:{}", response); + return response; + } + + /** + * 请求停止充电 + * @param request + * @param dto + * @return + */ + @PostMapping("/v1/query_stop_charge") + public CommonResult queryStopCharge(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { + logger.info("请求停止充电 params :{}", JSONObject.toJSONString(dto)); + try { + // 校验令牌 + String token = request.getHeader("Authorization"); + if (!JWTUtils.checkThirdPartyToken(token)) { + // 校验失败 + return CommonResult.failed("令牌校验错误"); + } + // 校验签名 + Map resultMap = platformLogic.checkoutSign(dto); + if (resultMap == null) { + // 签名错误 + return CommonResult.failed("签名校验错误"); + } + String operatorSecret = resultMap.get("OperatorSecret"); + String dataString = resultMap.get("Data"); + String dataSecret = resultMap.get("DataSecret"); + String dataSecretIV = resultMap.get("DataSecretIV"); + // 解密data + byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), dataSecret.getBytes(), dataSecretIV.getBytes()); + String dataStr = new String(plainText, StandardCharsets.UTF_8); + // 转换成相应对象 + QueryStartChargeDTO queryStartChargeDTO = JSONObject.parseObject(dataStr, QueryStartChargeDTO.class); + queryStartChargeDTO.setOperatorId(dto.getOperatorID()); + Map map = platformLogic.queryStopCharge(queryStartChargeDTO); + logger.info("请求停止充电 result:{}", JSONObject.toJSONString(map)); + return CommonResult.success(0, "请求停止充电成功!", map.get("Data"), map.get("Sig")); + } catch (Exception e) { + logger.error("请求停止充电 error", e); + } + return CommonResult.failed("请求停止充电发生异常"); + } + + /** + * 新电途推送停止充电结果 + * http://localhost:8080/hainan/notificationStopChargeResult + * @param orderCode + * @return + */ + @GetMapping("/notificationStopChargeResult/{orderCode}") + public RestApiResponse notificationStopChargeResult(@PathVariable("orderCode") String orderCode) { + logger.info("推送停止充电结果 params:{}", orderCode); + RestApiResponse response = null; + try { + String result = platformLogic.notificationStopChargeResult(orderCode); + response = new RestApiResponse<>(result); + }catch (BusinessException e) { + logger.error("推送停止充电结果 error",e); + response = new RestApiResponse<>(e.getCode(), e.getMessage()); + }catch (Exception e) { + logger.error("推送停止充电结果 error", e); + response = new RestApiResponse<>(e); + } + logger.info("推送停止充电结果 result:{}", response); + return response; + } }