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 d4b48c8db..9a83703ab 100644 --- a/jsowell-admin/src/main/java/com/jsowell/lianlian/LianLianController.java +++ b/jsowell-admin/src/main/java/com/jsowell/lianlian/LianLianController.java @@ -3,16 +3,14 @@ package com.jsowell.lianlian; import com.alibaba.fastjson2.JSONObject; import com.jsowell.common.annotation.Anonymous; import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.exception.BusinessException; import com.jsowell.common.response.RestApiResponse; import com.jsowell.pile.dto.QueryEquipmentDTO; import com.jsowell.pile.dto.QueryStartChargeDTO; import com.jsowell.pile.dto.QueryStationInfoDTO; import com.jsowell.thirdparty.domain.StationStatsInfo; import com.jsowell.thirdparty.service.LianLianService; -import com.jsowell.thirdparty.vo.EquipmentAuthVO; -import com.jsowell.thirdparty.vo.LianLianPageResponse; -import com.jsowell.thirdparty.vo.QueryChargingStatusVO; -import com.jsowell.thirdparty.vo.QueryStopChargeVO; +import com.jsowell.thirdparty.vo.*; import org.apache.commons.collections4.CollectionUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -118,6 +116,28 @@ public class LianLianController extends BaseController { return response; } + /** + * 请求启动充电 + * @param dto + * @return + */ + @PostMapping("/query_start_charge") + public RestApiResponse query_start_charge(@RequestBody QueryStartChargeDTO dto) { + logger.info("联联平台请求启动充电 params :{}", JSONObject.toJSONString(dto)); + RestApiResponse response; + try { + QueryStartChargeVO queryStartChargeVO = lianLianService.query_start_charge(dto); + response = new RestApiResponse<>(queryStartChargeVO); + }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; + } /** * 查询充电状态 diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/StartModeEnum.java b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/StartModeEnum.java index 9fc42e1f0..f21a6d1e5 100644 --- a/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/StartModeEnum.java +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/StartModeEnum.java @@ -8,6 +8,7 @@ public enum StartModeEnum { APP("1","用户app启动"), CARD("2", "卡启动"), OFFLINE_CARD("3", "离线卡启动"), + LIAN_LIAN("4", "联联平台启动"), ; private String value; diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/IOrderBasicInfoService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/IOrderBasicInfoService.java index 932706d90..473b8554c 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/IOrderBasicInfoService.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/IOrderBasicInfoService.java @@ -222,4 +222,11 @@ public interface IOrderBasicInfoService { * @return */ List getAccumulativeInfoForLianLian(QueryStationInfoDTO dto); + + /** + * 联联平台生成订单 + * @param dto + * @return + */ + Map generateOrderForLianLian(QueryStartChargeDTO dto); } diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/OrderBasicInfoServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/OrderBasicInfoServiceImpl.java index 50cb0093b..c5998c20e 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/OrderBasicInfoServiceImpl.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/OrderBasicInfoServiceImpl.java @@ -1401,4 +1401,76 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService { public List getAccumulativeInfoForLianLian(QueryStationInfoDTO dto) { return orderBasicInfoMapper.getAccumulativeInfoForLianLian(dto); } + + /** + * 联联平台生成订单 + * @param dto + * @return + */ + @Override + public Map generateOrderForLianLian(QueryStartChargeDTO dto) { + // 联联平台生成订单 + String orderCode = dto.getStartChargeSeq(); + String pileConnectorCode = dto.getConnectorID(); + String pileSn = StringUtils.substring(pileConnectorCode, 0, 14); + String connectorCode = StringUtils.substring(pileConnectorCode, 14, 16); + + + String transactionCode = IdUtils.generateTransactionCode(pileSn, connectorCode); + + // 通过桩号查询所属站点 + PileBasicInfo pileBasicInfo = pileBasicInfoService.selectPileBasicInfoBySN(pileSn); + Long stationId = pileBasicInfo.getStationId(); + + + // 将此订单信息存入订单表 + // 订单基本信息 + OrderBasicInfo orderBasicInfo = OrderBasicInfo.builder() + .orderCode(orderCode) + .transactionCode(transactionCode) + .orderStatus(OrderStatusEnum.NOT_START.getValue()) + // .memberId(memberVO.getMemberId()) // 会员memberId + .stationId(String.valueOf(stationId)) + .pileSn(pileSn) + .connectorCode(connectorCode) + .pileConnectorCode(pileConnectorCode) + // .logicCard(pileAuthCardInfo.getLogicCard()) // 卡号 + .startMode(StartModeEnum.LIAN_LIAN.getValue()) + .payStatus(Constants.ONE) + // .payAmount(totalAccountAmount) // 支付金额 + .payTime(new Date()) + // .payMode(PayModeEnum.PAYMENT_OF_BALANCE.getValue()) // 支付方式 + .orderAmount(BigDecimal.ZERO) + .build(); + // 根据桩编码查询当前计费模板 + BillingTemplateVO billingTemplateVO = pileBillingTemplateService.selectBillingTemplateDetailByPileSn(pileSn); + // 订单详情 + OrderDetail orderDetail = OrderDetail.builder() + .orderCode(orderCode) + .sharpElectricityPrice(billingTemplateVO.getSharpElectricityPrice()) + .sharpServicePrice(billingTemplateVO.getSharpServicePrice()) + .peakElectricityPrice(billingTemplateVO.getPeakElectricityPrice()) + .peakServicePrice(billingTemplateVO.getPeakServicePrice()) + .flatElectricityPrice(billingTemplateVO.getFlatElectricityPrice()) + .flatServicePrice(billingTemplateVO.getFlatServicePrice()) + .valleyElectricityPrice(billingTemplateVO.getValleyElectricityPrice()) + .valleyServicePrice(billingTemplateVO.getValleyServicePrice()) + .build(); + + OrderTransactionDTO createOrderTransactionDTO = OrderTransactionDTO.builder() + .orderBasicInfo(orderBasicInfo) + .orderDetail(orderDetail) + .build(); + pileTransactionService.doCreateOrder(createOrderTransactionDTO); + + // 组装结果集 + Map resultMap = Maps.newHashMap(); + resultMap.put("orderCode", orderBasicInfo.getOrderCode()); + resultMap.put("transactionCode", orderBasicInfo.getTransactionCode()); + resultMap.put("orderBasicInfo", orderBasicInfo); + resultMap.put("orderDetail", orderDetail); + // resultMap.put("accountBalance", totalAccountAmount); + + return resultMap; + } } diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/service/LianLianService.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/service/LianLianService.java index ac0ed895f..d616513a2 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/service/LianLianService.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/service/LianLianService.java @@ -4,10 +4,7 @@ import com.jsowell.pile.dto.QueryEquipmentDTO; import com.jsowell.pile.dto.QueryStartChargeDTO; import com.jsowell.thirdparty.domain.StationStatsInfo; import com.jsowell.pile.dto.QueryStationInfoDTO; -import com.jsowell.thirdparty.vo.EquipmentAuthVO; -import com.jsowell.thirdparty.vo.LianLianPageResponse; -import com.jsowell.thirdparty.vo.QueryChargingStatusVO; -import com.jsowell.thirdparty.vo.QueryStopChargeVO; +import com.jsowell.thirdparty.vo.*; import java.util.List; @@ -51,6 +48,13 @@ public interface LianLianService { */ EquipmentAuthVO query_equip_auth(QueryEquipmentDTO dto); + /** + * 请求开始充电 + * @param dto + * @return + */ + QueryStartChargeVO query_start_charge(QueryStartChargeDTO dto); + /** * 查询充电状态 * @param startChargeSeq diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/service/impl/LianLianServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/service/impl/LianLianServiceImpl.java index c6f7b30af..e4cbda691 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/service/impl/LianLianServiceImpl.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/service/impl/LianLianServiceImpl.java @@ -11,6 +11,7 @@ import com.jsowell.common.exception.BusinessException; import com.jsowell.common.util.DateUtils; import com.jsowell.common.util.PageUtils; import com.jsowell.common.util.StringUtils; +import com.jsowell.netty.command.ykc.StartChargingCommand; import com.jsowell.netty.command.ykc.StopChargingCommand; import com.jsowell.netty.service.yunkuaichong.YKCPushCommandService; import com.jsowell.pile.domain.*; @@ -26,6 +27,7 @@ import com.jsowell.pile.service.IPileStationInfoService; import com.jsowell.pile.vo.base.ConnectorInfoVO; import com.jsowell.pile.vo.base.MerchantInfoVO; import com.jsowell.pile.vo.lianlian.AccumulativeInfoVO; +import com.jsowell.pile.vo.uniapp.SendMessageVO; import com.jsowell.pile.vo.web.PileConnectorInfoVO; import com.jsowell.pile.vo.web.PileModelInfoVO; import com.jsowell.thirdparty.domain.ConnectorChargeStatusInfo; @@ -39,10 +41,7 @@ import com.jsowell.thirdparty.domain.StationInfo; import com.jsowell.thirdparty.domain.StationStatsInfo; import com.jsowell.thirdparty.domain.StationStatusInfo; import com.jsowell.thirdparty.service.LianLianService; -import com.jsowell.thirdparty.vo.EquipmentAuthVO; -import com.jsowell.thirdparty.vo.LianLianPageResponse; -import com.jsowell.thirdparty.vo.QueryChargingStatusVO; -import com.jsowell.thirdparty.vo.QueryStopChargeVO; +import com.jsowell.thirdparty.vo.*; import org.apache.commons.collections4.CollectionUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -210,7 +209,7 @@ public class LianLianServiceImpl implements LianLianService { StationStatusInfos.add(stationStatusInfo); } } - // TODO 将 StationStatusInfos 分页 + // 将 StationStatusInfos 分页 int pageNum = 1; int pageSize = 10; List collect = StationStatusInfos.stream() @@ -363,13 +362,42 @@ public class LianLianServiceImpl implements LianLianService { * 请求启动充电 * @param dto */ - public void query_start_charge(QueryStartChargeDTO dto) { + public QueryStartChargeVO query_start_charge(QueryStartChargeDTO dto) { // 通过传过来的订单号和枪口号生成订单 - String orderCode = dto.getStartChargeSeq(); + // String orderCode = dto.getStartChargeSeq(); String pileConnectorCode = dto.getConnectorID(); + OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(dto.getStartChargeSeq()); + if (orderInfo != null) { + // 平台已存在订单 + throw new BusinessException("", "平台已存在订单"); + } + Map map = orderBasicInfoService.generateOrderForLianLian(dto); + String orderCode = (String) map.get("orderCode"); + String transactionCode = (String) map.get("transactionCode"); + OrderBasicInfo orderBasicInfo = (OrderBasicInfo) map.get("orderBasicInfo"); + + + StartChargingCommand command = StartChargingCommand.builder() + .pileSn(orderBasicInfo.getPileSn()) + .connectorCode(orderBasicInfo.getConnectorCode()) + .transactionCode(transactionCode) + .chargeAmount(orderBasicInfo.getPayAmount()) + .logicCardNum(null) + .physicsCardNum(null) + .build(); + ykcPushCommandService.pushStartChargingCommand(command); // 拼装对应的数据并返回 + QueryStartChargeVO vo = QueryStartChargeVO.builder() + .StartChargeSeq(orderCode) + .StartChargeSeqStat(1) // 1-启动中 + .ConnectorID(pileConnectorCode) + .SuccStat(0) + .FailReason(0) + + .build(); + return vo; // TODO 推送启动充电结果(调用接口 notification_start_charge_result) } @@ -383,11 +411,11 @@ public class LianLianServiceImpl implements LianLianService { public QueryChargingStatusVO query_equip_charge_status(String startChargeSeq) { // 通过订单号查询订单信息 OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(startChargeSeq); - OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(startChargeSeq); // 通过订单号查询实时数据 - if (orderInfo == null || orderDetail == null) { + if (orderInfo == null) { throw new BusinessException("", ""); } + // OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderInfo.getOrderCode()); List realTimeData = orderBasicInfoService.getChargingRealTimeData(orderInfo.getTransactionCode()); RealTimeMonitorData data = realTimeData.get(0); String orderStatus = orderInfo.getOrderStatus(); diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/vo/QueryStartChargeVO.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/vo/QueryStartChargeVO.java new file mode 100644 index 000000000..531087f8b --- /dev/null +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/vo/QueryStartChargeVO.java @@ -0,0 +1,43 @@ +package com.jsowell.thirdparty.vo; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 请求启动充电VO + * + * @author JS-ZZA + * @date 2023/4/28 14:33 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class QueryStartChargeVO { + /** + * 充电订单号 + */ + private String StartChargeSeq; + + /** + * 充电订单状态 + */ + private int StartChargeSeqStat; + + /** + * 充电设备接口编码 + */ + private String ConnectorID; + + /** + * 成功状态 + */ + private int SuccStat; + + /** + * 失败原因 + */ + private int FailReason; +}