diff --git a/jsowell-admin/src/main/java/com/jsowell/lianlian/LianLianController.java b/jsowell-admin/src/main/java/com/jsowell/lianlian/LianLianController.java index b8a9ea8d0..c06e8dae1 100644 --- a/jsowell-admin/src/main/java/com/jsowell/lianlian/LianLianController.java +++ b/jsowell-admin/src/main/java/com/jsowell/lianlian/LianLianController.java @@ -495,6 +495,46 @@ public class LianLianController extends BaseController { } } + /** + * 推送订单结算信息 (联联推给我们) + * @param request + * @param dto + * @return + */ + @PostMapping("/v1/notification_order_settlement_info") + public CommonResult notification_order_settlement_info(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 = lianLianService.checkoutSign(dto); + if (resultMap == null) { + // 签名错误 + return CommonResult.failed("签名校验错误"); + } + String operatorSecret = resultMap.get("OperatorSecret"); + String dataString = resultMap.get("Data"); + // 解密data + byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), operatorSecret.getBytes(), operatorSecret.getBytes()); + String dataStr = new String(plainText, "UTF-8"); + // 转换成相应对象 + PushOrderSettlementDTO pushOrderSettlementDTO = JSONObject.parseObject(dataStr, PushOrderSettlementDTO.class); + pushOrderSettlementDTO.setOperatorId(dto.getOperatorID()); + Map map = lianLianService.pushOrderSettlementInfo(pushOrderSettlementDTO); + + 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/LianLian/query_stations_info diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/TransactionRecordsRequestHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/TransactionRecordsRequestHandler.java index 9c4e893cf..7f70ee422 100644 --- a/jsowell-netty/src/main/java/com/jsowell/netty/handler/TransactionRecordsRequestHandler.java +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/TransactionRecordsRequestHandler.java @@ -19,9 +19,11 @@ import com.jsowell.common.util.id.IdUtils; import com.jsowell.netty.factory.YKCOperateFactory; import com.jsowell.pile.domain.OrderBasicInfo; import com.jsowell.pile.domain.PileAuthCard; +import com.jsowell.pile.domain.ThirdPartySettingInfo; import com.jsowell.pile.service.IOrderBasicInfoService; import com.jsowell.pile.service.IPileAuthCardService; import com.jsowell.pile.service.IPileMsgRecordService; +import com.jsowell.pile.service.IThirdPartySettingInfoService; import io.netty.channel.Channel; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -63,6 +65,9 @@ public class TransactionRecordsRequestHandler extends AbstractHandler { @Autowired private IPileAuthCardService pileAuthCardService; + @Autowired + private IThirdPartySettingInfoService thirdPartySettingInfoService; + public static void main(String[] args) { // 获取消息体 String msg = "000000000000000000000000000000008823000000030601a08c2e0d0404170000380d0404170000000000000000000000000000000000000000000000000000000000000000400d0300ee250000ee250000c84b000000000000000000000000000000000000e0bb040000cee1040000ee250000ee250000c84b00000000000000000000000000000000000000010000380d04041745a511101970000000"; @@ -604,9 +609,14 @@ public class TransactionRecordsRequestHandler extends AbstractHandler { // 结算订单操作 try { orderBasicInfoService.settleOrder(data, orderBasicInfo); - // TODO 推送联联平台 订单信息推送接口 + // 查询该站点是否推送联联平台 - + String stationId = orderBasicInfo.getStationId(); + ThirdPartySettingInfo infoByStationId = thirdPartySettingInfoService.getInfoByStationId(Long.parseLong(stationId)); + if (Objects.nonNull(infoByStationId)) { + // TODO 推送联联平台 订单信息推送接口 + + } // 调用相关接口 } catch (Exception e) { diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/PushOrderSettlementDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/PushOrderSettlementDTO.java index f077ca0f5..cd71c5f96 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/dto/PushOrderSettlementDTO.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/PushOrderSettlementDTO.java @@ -1,6 +1,7 @@ package com.jsowell.pile.dto; import com.alibaba.fastjson2.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; import java.math.BigDecimal; @@ -48,4 +49,7 @@ public class PushOrderSettlementDTO { */ @JSONField(name = "SettlementMoney") private BigDecimal settlementMoney; + + @JsonProperty(value = "OperatorID") + private String OperatorId; } diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/service/LianLianService.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/service/LianLianService.java index aed8ea482..997e4bb66 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/service/LianLianService.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/service/LianLianService.java @@ -127,11 +127,11 @@ public interface LianLianService { String pushChargeOrderInfo(String orderCode); /** - * 推送订单结算信息 + * 推送订单结算信息 (联联推给我们) * @param dto * @return */ - String pushOrderSettlementInfo(PushOrderSettlementDTO dto); + Map pushOrderSettlementInfo(PushOrderSettlementDTO dto); /** * 查询订单结算信息 diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/service/impl/LianLianServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/service/impl/LianLianServiceImpl.java index 793201788..3f68554cb 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/service/impl/LianLianServiceImpl.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/service/impl/LianLianServiceImpl.java @@ -1163,17 +1163,17 @@ public class LianLianServiceImpl implements LianLianService { } /** - * 推送订单结算信息 + * 推送订单结算信息 (联联推给我们) * * @param dto * @return */ @Override - public String pushOrderSettlementInfo(PushOrderSettlementDTO dto) { + public Map pushOrderSettlementInfo(PushOrderSettlementDTO dto) { String orderCode = dto.getStartChargeSeq(); - JSONObject json = new JSONObject(); - json.put("StartChargeSeq", orderCode); - json.put("ConnectorID", dto.getConnectorID()); + Map map = new LinkedHashMap<>(); + map.put("StartChargeSeq", orderCode); + map.put("ConnectorID", dto.getConnectorID()); int confirmResult = Constants.one; // 根据订单号查询订单信息 OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); @@ -1181,17 +1181,32 @@ public class LianLianServiceImpl implements LianLianService { if (orderInfo == null || orderDetail == null) { return null; } - // 都不为空,根据传过来的数据进行修改数据库信息 + // 通过operatorID 查出 operatorSecret + DockingPlatformConfig platformConfig = dockingPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); + if (platformConfig == null) { + return null; + } + // orderInfo 和 orderDetail 都不为空,再根据传过来的数据进行修改数据库信息 confirmResult = Constants.zero; orderDetail.setTotalUsedElectricity(dto.getTotalPower()); // 累计充电量 orderDetail.setTotalOrderAmount(dto.getTotalMoney()); // 累计总金额 orderBasicInfoService.updateOrderDetail(orderDetail); - json.put("ConfirmResult", confirmResult); - String jsonString = JSONObject.toJSONString(json); + map.put("ConfirmResult", confirmResult); - return jsonString; + Map resultMap = Maps.newLinkedHashMap(); + // 加密数据 + byte[] encryptText = Cryptos.aesEncrypt(JSONObject.toJSONString(map).getBytes(), + platformConfig.getOperatorSecret().getBytes(), platformConfig.getDataSecretIv().getBytes()); + String encryptData = Encodes.encodeBase64(encryptText); + + resultMap.put("Data", encryptData); + // 生成sig + String resultSign = GBSignUtils.sign(resultMap, platformConfig.getOperatorSecret()); + resultMap.put("Sig", resultSign); + + return resultMap; } /** diff --git a/jsowell-ui/src/views/homeIndex/homeIndex.vue b/jsowell-ui/src/views/homeIndex/homeIndex.vue index 4b08cfc58..511bef7cc 100644 --- a/jsowell-ui/src/views/homeIndex/homeIndex.vue +++ b/jsowell-ui/src/views/homeIndex/homeIndex.vue @@ -112,8 +112,7 @@ :src="require('@/assets/images/yue.png')" > -
+