From caae13281d16f47029813dbeba35bfce1ba92736 Mon Sep 17 00:00:00 2001 From: "autumn.g@foxmail.com" Date: Fri, 26 May 2023 19:25:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BE=9B=E7=BB=99lianlian=E8=8E=B7?= =?UTF-8?q?=E5=8F=96token?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jsowell/lianlian/LianLianController.java | 13 +- .../test/java/SpringBootTestController.java | 55 +- .../com/jsowell/common/util/JWTUtils.java | 2 +- .../lianlian/dto/QueryTokenDTO.java | 24 + .../lianlian/service/LianLianService.java | 5 + .../service/impl/LianLianServiceImpl.java | 2550 +++++++++-------- .../thirdparty/lianlian/vo/AccessTokenVO.java | 44 + 7 files changed, 1437 insertions(+), 1256 deletions(-) create mode 100644 jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/dto/QueryTokenDTO.java create mode 100644 jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/vo/AccessTokenVO.java 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 ccf2c88af..b09bcab7b 100644 --- a/jsowell-admin/src/main/java/com/jsowell/lianlian/LianLianController.java +++ b/jsowell-admin/src/main/java/com/jsowell/lianlian/LianLianController.java @@ -10,13 +10,16 @@ import com.jsowell.common.util.StringUtils; import com.jsowell.pile.dto.*; import com.jsowell.thirdparty.lianlian.common.CommonResult; import com.jsowell.thirdparty.lianlian.domain.StationStatsInfo; +import com.jsowell.thirdparty.lianlian.dto.QueryTokenDTO; import com.jsowell.thirdparty.lianlian.service.LianLianService; import com.jsowell.thirdparty.lianlian.vo.*; import org.apache.commons.collections4.CollectionUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import java.io.UnsupportedEncodingException; import java.util.ArrayList; +import java.util.Map; /** * 对接联联平台controller @@ -317,7 +320,13 @@ public class LianLianController extends BaseController { * http://localhost:8080/LianLian/v1/query_token */ @PostMapping("/v1/query_token") - public CommonResult queryToken() { - return null; + public CommonResult queryToken(QueryTokenDTO dto) { + try { + Map map = lianLianService.generateToken(dto); + return CommonResult.success(0, "", map.get("data"), map.get("sig")); + } catch (UnsupportedEncodingException e) { + logger.error("获取token接口 异常"); + return CommonResult.failed("获取token发生异常"); + } } } diff --git a/jsowell-admin/src/test/java/SpringBootTestController.java b/jsowell-admin/src/test/java/SpringBootTestController.java index 1ddcfa708..e03679bb7 100644 --- a/jsowell-admin/src/test/java/SpringBootTestController.java +++ b/jsowell-admin/src/test/java/SpringBootTestController.java @@ -1,3 +1,4 @@ +import cn.hutool.json.JSONUtil; import com.alibaba.fastjson2.JSONObject; import com.fasterxml.jackson.core.JsonProcessingException; import com.google.common.collect.ImmutableMap; @@ -18,24 +19,11 @@ import com.jsowell.netty.command.ykc.ProofreadTimeCommand; import com.jsowell.netty.handler.HeartbeatRequestHandler; import com.jsowell.netty.service.yunkuaichong.YKCBusinessService; import com.jsowell.netty.service.yunkuaichong.YKCPushCommandService; -import com.jsowell.pile.domain.OrderBasicInfo; -import com.jsowell.pile.domain.PileAuthCard; -import com.jsowell.pile.domain.PileBillingDetail; -import com.jsowell.pile.domain.PileBillingTemplate; -import com.jsowell.pile.domain.PileStationInfo; -import com.jsowell.pile.domain.WxpayCallbackRecord; +import com.jsowell.pile.domain.*; import com.jsowell.pile.dto.*; import com.jsowell.pile.mapper.MemberBasicInfoMapper; import com.jsowell.pile.mapper.PileBillingTemplateMapper; -import com.jsowell.pile.service.IOrderBasicInfoService; -import com.jsowell.pile.service.IPileAuthCardService; -import com.jsowell.pile.service.IPileBasicInfoService; -import com.jsowell.pile.service.IPileBillingTemplateService; -import com.jsowell.pile.service.IPileMsgRecordService; -import com.jsowell.pile.service.IPileStationInfoService; -import com.jsowell.pile.service.SimCardService; -import com.jsowell.pile.service.WechatPayService; -import com.jsowell.pile.service.WxpayCallbackRecordService; +import com.jsowell.pile.service.*; import com.jsowell.pile.vo.web.BillingTemplateVO; import com.jsowell.pile.vo.web.OrderListVO; import com.jsowell.pile.vo.web.PileDetailVO; @@ -43,7 +31,11 @@ import com.jsowell.service.MemberService; import com.jsowell.service.OrderService; import com.jsowell.service.PileRemoteService; import com.jsowell.service.PileService; +import com.jsowell.thirdparty.lianlian.dto.QueryTokenDTO; import com.jsowell.thirdparty.lianlian.service.LianLianService; +import com.jsowell.thirdparty.lianlian.util.Cryptos; +import com.jsowell.thirdparty.lianlian.util.Encodes; +import com.jsowell.thirdparty.lianlian.util.GBSignUtils; import com.jsowell.wxpay.common.WeChatPayParameter; import com.jsowell.wxpay.dto.AppletTemplateMessageSendDTO; import com.jsowell.wxpay.dto.WeChatRefundDTO; @@ -59,6 +51,7 @@ import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.StopWatch; +import java.io.UnsupportedEncodingException; import java.math.BigDecimal; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -144,6 +137,38 @@ public class SpringBootTestController { static final String ALGORITHM_MAC = "HmacMD5"; + @Test + public void testGenerateLianlianToken() throws UnsupportedEncodingException { + String OperatorID = "425010765"; + String OperatorSecret = "123123123123aaaa"; // 1234567890abcdef + + //请求dataX + Map data = new HashMap<>(); + data.put("OperatorID", OperatorID); + data.put("OperatorSecret", OperatorSecret); + String dataJson = JSONUtil.toJsonStr(data); + + //加密 + byte[] encryptText = Cryptos.aesEncrypt(dataJson.getBytes("UTF-8"), + OperatorSecret.getBytes(), OperatorSecret.getBytes()); + String strData = Encodes.encodeBase64(encryptText); + + Map request = new LinkedHashMap<>(); + request.put("OperatorID", OperatorID); + request.put("Data", strData); + request.put("TimeStamp", System.currentTimeMillis() + ""); + request.put("Seq", "0001"); + + //生成签名 + String sig = GBSignUtils.sign(request, OperatorSecret); + request.put("Sig", sig); + String tokenRequest = JSONUtil.toJsonStr(request); + + QueryTokenDTO dto = JSONObject.parseObject(tokenRequest, QueryTokenDTO.class); + + lianLianService.generateToken(dto); + } + @Test public void testupdateElecAmount() { orderBasicInfoService.updateElecAmount(); diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/JWTUtils.java b/jsowell-common/src/main/java/com/jsowell/common/util/JWTUtils.java index 8a4c33f10..bdb5d600e 100644 --- a/jsowell-common/src/main/java/com/jsowell/common/util/JWTUtils.java +++ b/jsowell-common/src/main/java/com/jsowell/common/util/JWTUtils.java @@ -55,7 +55,7 @@ public class JWTUtils { * @param ttlMillis 过期时间 毫秒 * @return Token String 凭证 */ - private static String createToken(String id, String subject, long ttlMillis) { + public static String createToken(String id, String subject, long ttlMillis) { // 签名方法 HS256 SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256; diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/dto/QueryTokenDTO.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/dto/QueryTokenDTO.java new file mode 100644 index 000000000..e6d023891 --- /dev/null +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/dto/QueryTokenDTO.java @@ -0,0 +1,24 @@ +package com.jsowell.thirdparty.lianlian.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class QueryTokenDTO { + @JsonProperty(value = "OperatorID") + private String operatorID; + + @JsonProperty(value = "Data") + private String data; + + @JsonProperty(value = "TimeStamp") + private String timeStamp; + + @JsonProperty(value = "Seq") + private String seq; + + @JsonProperty(value = "Sig") + private String sig; +} 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 9eb489cef..703173449 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 @@ -2,9 +2,12 @@ package com.jsowell.thirdparty.lianlian.service; import com.jsowell.pile.dto.*; import com.jsowell.thirdparty.lianlian.domain.StationStatsInfo; +import com.jsowell.thirdparty.lianlian.dto.QueryTokenDTO; import com.jsowell.thirdparty.lianlian.vo.*; +import java.io.UnsupportedEncodingException; import java.util.List; +import java.util.Map; public interface LianLianService { @@ -150,4 +153,6 @@ public interface LianLianService { * @return */ String pushPileChargeStatusChange(String orderCode); + + Map generateToken(QueryTokenDTO dto) throws UnsupportedEncodingException; } 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 e639c2ed3..c026b93f5 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 @@ -7,6 +7,7 @@ import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONObject; import com.github.pagehelper.PageInfo; import com.google.common.collect.Lists; +import com.google.common.collect.Maps; import com.jsowell.common.constant.Constants; import com.jsowell.common.core.domain.ykc.RealTimeMonitorData; import com.jsowell.common.enums.lianlian.LianLianPileStatusEnum; @@ -18,6 +19,7 @@ import com.jsowell.common.enums.ykc.PileConnectorDataBaseStatusEnum; import com.jsowell.common.enums.ykc.PileStatusEnum; import com.jsowell.common.exception.BusinessException; import com.jsowell.common.util.DateUtils; +import com.jsowell.common.util.JWTUtils; import com.jsowell.common.util.PageUtils; import com.jsowell.common.util.StringUtils; import com.jsowell.netty.command.ykc.StartChargingCommand; @@ -34,6 +36,7 @@ import com.jsowell.pile.vo.web.PileConnectorInfoVO; import com.jsowell.pile.vo.web.PileModelInfoVO; import com.jsowell.pile.vo.web.PileStationVO; import com.jsowell.thirdparty.lianlian.domain.*; +import com.jsowell.thirdparty.lianlian.dto.QueryTokenDTO; import com.jsowell.thirdparty.lianlian.service.LianLianService; import com.jsowell.thirdparty.lianlian.util.Cryptos; import com.jsowell.thirdparty.lianlian.util.Encodes; @@ -44,1248 +47,1319 @@ import org.apache.commons.collections4.CollectionUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.io.UnsupportedEncodingException; import java.math.BigDecimal; import java.util.*; import java.util.stream.Collectors; @Service public class LianLianServiceImpl implements LianLianService { - // private static final String TEST_URL = "http://testdataexchange.evchargeonline.com:82/shevcs/v1/"; // http://testdataexchange.evchargeonline.com:82/shevcs/v1/ - // private static final String OPERATOR_ID = "MA1JLFUU8"; // MA1JLFUU8 987654321 - // private static final String OPERATOR_SECRET = "fGwLsxW1HdzLw7jp"; // fGwLsxW1HdzLw7jp 1234567890abcdef - // private static final String SIG_SECRET = "TmsdVaFVTtjzZbLi"; // 签名秘钥 TmsdVaFVTtjzZbLi 1234567890abcdef - // private static final String DATA_SECRET = "R1Hdq80mSWswwCzt"; // 消息密钥 R1Hdq80mSWswwCzt 1234567890abcdef - // private static final String DATA_SECRETIV = "LVpz3qHD8sM2PYjl"; // 消息密钥初始化向量 LVpz3qHD8sM2PYjl 1234567890abcdef - - @Autowired - private IPileMerchantInfoService pileMerchantInfoService; - - @Autowired - private IPileStationInfoService pileStationInfoService; - - @Autowired - private IPileBasicInfoService pileBasicInfoService; - - @Autowired - private IPileModelInfoService pileModelInfoService; - - @Autowired - private IPileConnectorInfoService pileConnectorInfoService; - - @Autowired - private IOrderBasicInfoService orderBasicInfoService; - - @Autowired - private YKCPushCommandService ykcPushCommandService; - - @Autowired - private IPileBillingTemplateService pileBillingTemplateService; - - @Autowired - private IThirdPartySettingInfoService thirdPartySettingInfoService; - - @Override - public void pushMerchantInfo(Long merchantId) { - // 通过id查询运营商信息 - MerchantInfoVO merchantInfo = pileMerchantInfoService.getMerchantInfo(String.valueOf(merchantId)); - // 组装联联平台所需要的数据格式 - OperatorInfo operatorInfo = OperatorInfo.builder() - .OperatorID(Constants.OPERATORID_LIANLIAN) // 组织机构代码 - .OperatorName(merchantInfo.getMerchantName()) // 机构全称 - .OperatorTel1(merchantInfo.getMerchantTel()) // 对接平台客服电话1 - .build(); - // 调用联联平台接口 - - - } - - /** - * 根据站点id推送站点信息 notification_stationInfo - * @param dto - */ - @Override - public String pushStationInfo(LianLianPushStationInfoDTO dto){ - // String OperatorID = "987654321"; - // String SigSecret = "1234567890abcdef"; // 签名秘钥 - // String DataSecret = "1234567890abcdef"; // 消息密钥 - // String DataSecretIV = "1234567890abcdef"; // 消息密钥初始化向量 - // String token = "c548f9276c1c4ea8b88b1f7b1eb7cf07"; //QueryToken类查询接口获取到的token - - // 通过id查询站点相关信息 - PileStationInfo pileStationInfo = pileStationInfoService.selectPileStationInfoById(dto.getStationId()); - // 通过站点id查询相关配置信息 - ThirdPartySettingInfo settingInfo = thirdPartySettingInfoService.getInfoByStationId(dto.getStationId()); - if (settingInfo == null) { - throw new BusinessException("", ""); - } - String operatorId = settingInfo.getOperatorId(); - String operatorSecret = settingInfo.getOperatorSecret(); - String signSecret = settingInfo.getSignSecret(); - String dataSecret = settingInfo.getDataSecret(); - String dataSecretIv = settingInfo.getDataSecretIv(); - String urlAddress = settingInfo.getUrlAddress(); - - // 组装联联平台所需要的数据格式 - StationInfo info = StationInfo.builder() - .stationID(String.valueOf(dto.getStationId())) - .operatorID(operatorId) - .equipmentOwnerID(Constants.OPERATORID_LIANLIAN) - .stationName(pileStationInfo.getStationName()) - .isAloneApply(Integer.valueOf(pileStationInfo.getAloneApply())) - .isPublicParkingLot(Integer.valueOf(pileStationInfo.getPublicParking())) - .countryCode(pileStationInfo.getCountryCode()) - .areaCode(pileStationInfo.getAreaCode()) - .address(pileStationInfo.getAddress()) - .serviceTel(pileStationInfo.getStationTel()) - .stationType(Integer.valueOf(pileStationInfo.getStationType())) - .stationStatus(Integer.valueOf(pileStationInfo.getStationStatus())) - .parkNums(Integer.valueOf(pileStationInfo.getParkNums())) - .stationLng(new BigDecimal(pileStationInfo.getStationLng())) - .stationLat(new BigDecimal(pileStationInfo.getStationLat())) - .construction(Integer.valueOf(pileStationInfo.getConstruction())) - .openAllDay(Integer.valueOf(pileStationInfo.getOpenAllDay())) - .minElectricityPrice(new BigDecimal(Constants.ZERO)) - .electricityFee(Constants.ZERO) - .serviceFee(Constants.ZERO) - .parkFree(Integer.valueOf(pileStationInfo.getParkFree())) - // .ParkFee("2") - // .payment("线上") - .supportOrder(Integer.valueOf(pileStationInfo.getSupportOrder())) - // .equipmentInfos() - .parkFeeType(0) - .toiletFlag(Integer.valueOf(pileStationInfo.getToiletFlag())) - .storeFlag(Integer.valueOf(pileStationInfo.getStoreFlag())) - .restaurantFlag(Integer.valueOf(pileStationInfo.getRestaurantFlag())) - .loungeFlag(Integer.valueOf(pileStationInfo.getLoungeFlag())) - .canopyFlag(Integer.valueOf(pileStationInfo.getCanopyFlag())) - .printerFlag(Integer.valueOf(pileStationInfo.getPrinterFlag())) - .barrierFlag(Integer.valueOf(pileStationInfo.getBarrierFlag())) - .parkingLockFlag(Integer.valueOf(pileStationInfo.getParkingLockFlag())) - - .build(); - String payment = StationPaymentEnum.getPaymentByCode(pileStationInfo.getPayment()); - info.setPayment(payment); - List pileList = getPileList(pileStationInfo); - if (CollectionUtils.isNotEmpty(pileList)) { - info.setEquipmentInfos(pileList); // 充电设备信息列表 - } - - // 调用联联平台接口 - String url = urlAddress + "notification_stationInfo"; - - String jsonStr = JSONObject.toJSONString(info); - JSONObject data = new JSONObject(); - data.put("StationInfo", jsonStr); - - String jsonString = JSONObject.toJSONString(data); - System.out.println("jsonString : " + jsonString); - - // 获取令牌 - String token = getToken(urlAddress, operatorId, operatorSecret); - String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret - , dataSecretIv, operatorId, signSecret); - - // System.out.println(result); - return result; - } - - public static void main(String[] args){ - - } - - /** - * 查询充电站信息 - * 对外接口 query_stations_info - * @return - */ - @Override - public LianLianPageResponse query_stations_info(QueryStationInfoDTO dto) { - List resultList = new ArrayList<>(); - int pageNo = dto.getPageNo() == null ? 1 : dto.getPageNo(); - int pageSize = dto.getPageSize() == null ? 10 : dto.getPageSize(); - - PageUtils.startPage(pageNo, pageSize); - List stationInfos = pileStationInfoService.getStationInfoForLianLian(); - if (CollectionUtils.isEmpty(stationInfos)) { - // 未查到数据 - return null; - } - PageInfo pageInfo = new PageInfo<>(stationInfos); - for (PileStationInfo pileStationInfo : pageInfo.getList()) { - StationInfo stationInfo = new StationInfo(); - stationInfo.setStationID(String.valueOf(pileStationInfo.getId())); - // MerchantInfoVO merchantInfo = pileMerchantInfoService.getMerchantInfo(String.valueOf(pileStationInfo.getMerchantId())); - stationInfo.setOperatorID(Constants.OPERATORID_LIANLIAN); // 组织机构代码 - stationInfo.setEquipmentOwnerID(String.valueOf(pileStationInfo.getMerchantId())); - stationInfo.setStationName(pileStationInfo.getStationName()); - stationInfo.setIsAloneApply(Integer.valueOf(pileStationInfo.getAloneApply())); - stationInfo.setIsPublicParkingLot(Integer.valueOf(pileStationInfo.getPublicParking())); - stationInfo.setCountryCode(pileStationInfo.getCountryCode()); - stationInfo.setAreaCode(pileStationInfo.getAreaCode()); - stationInfo.setAddress(pileStationInfo.getAddress()); - stationInfo.setServiceTel(pileStationInfo.getStationTel()); - stationInfo.setStationType(Integer.valueOf(pileStationInfo.getStationType())); - stationInfo.setParkNums(Integer.valueOf(pileStationInfo.getParkNums())); - stationInfo.setStationLng(new BigDecimal(pileStationInfo.getStationLng())); - stationInfo.setStationLat(new BigDecimal(pileStationInfo.getStationLat())); - stationInfo.setConstruction(Integer.valueOf(pileStationInfo.getConstruction())); - stationInfo.setOpenAllDay(Integer.valueOf(pileStationInfo.getOpenAllDay())); - // stationInfo.setMinElectricityPrice(pileStationInfo); // 最低充电电费率 - // stationInfo.setElectricityFee(); // 电费 xx元/度 - // stationInfo.setServiceFee(); // 服务费 xx元/度 - stationInfo.setParkFree(Integer.valueOf(pileStationInfo.getParkFree())); - stationInfo.setPayment(pileStationInfo.getPayment()); - stationInfo.setSupportOrder(Integer.valueOf(pileStationInfo.getSupportOrder())); - // stationInfo.setParkFeeType(pileStationInfo); // 停车收费类型 - stationInfo.setToiletFlag(Integer.valueOf(pileStationInfo.getToiletFlag())); - stationInfo.setStoreFlag(Integer.valueOf(pileStationInfo.getStoreFlag())); - stationInfo.setRestaurantFlag(Integer.valueOf(pileStationInfo.getRestaurantFlag())); - stationInfo.setLoungeFlag(Integer.valueOf(pileStationInfo.getLoungeFlag())); - stationInfo.setCanopyFlag(Integer.valueOf(pileStationInfo.getCanopyFlag())); - stationInfo.setPrinterFlag(Integer.valueOf(pileStationInfo.getPrinterFlag())); - stationInfo.setBarrierFlag(Integer.valueOf(pileStationInfo.getBarrierFlag())); - stationInfo.setParkingLockFlag(Integer.valueOf(pileStationInfo.getParkingLockFlag())); - - List pileList = getPileList(pileStationInfo); - if (CollectionUtils.isNotEmpty(pileList)) { - stationInfo.setEquipmentInfos(pileList); // 充电设备信息列表 - } - - resultList.add(stationInfo); - } - - LianLianPageResponse pageResponse = LianLianPageResponse.builder() - .PageNo(pageInfo.getPageNum()) - .PageCount(pageInfo.getPages()) - .ItemSize(resultList.size()) - .list(resultList) - .build(); - return pageResponse; - } - - /** - * 设备接口状态查询 - * 此接口用于批量查询设备实时状态 - * - * @param StationIDs - * @return - */ - @Override - public LianLianPageResponse query_station_status(List StationIDs) { - List StationStatusInfos = new ArrayList<>(); - List ConnectorStatusInfos = new ArrayList<>(); - - for (String stationId : StationIDs) { - // 根据站点id查询 - List list = pileConnectorInfoService.getConnectorListForLianLian(Long.parseLong(stationId)); - for (ConnectorInfoVO connectorInfoVO : list) { - - String connectorStatus = connectorInfoVO.getConnectorStatus(); - if (StringUtils.equals(connectorStatus, PileConnectorDataBaseStatusEnum.OCCUPIED_CHARGING.getValue())) { - // 充电中 - ConnectorChargeStatusInfo info = new ConnectorChargeStatusInfo(); - OrderBasicInfo orderBasicInfo = orderBasicInfoService.queryChargingByPileConnectorCode(connectorInfoVO.getPileConnectorCode()); - List chargingRealTimeData = orderBasicInfoService.getChargingRealTimeData(orderBasicInfo.getTransactionCode()); - RealTimeMonitorData realTimeMonitorData = chargingRealTimeData.get(0); - - info.setStartChargeSeq(orderBasicInfo.getOrderCode()); - info.setConnectorID(orderBasicInfo.getPileConnectorCode()); - info.setConnectorStatus(Integer.valueOf(connectorInfoVO.getConnectorStatus())); - info.setCurrentA(new BigDecimal(realTimeMonitorData.getOutputCurrent())); - info.setVoltageA(new BigDecimal(realTimeMonitorData.getOutputVoltage())); - info.setSoc(new BigDecimal(realTimeMonitorData.getSOC())); - info.setStartTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderBasicInfo.getChargeStartTime())); - info.setEndTime(DateUtils.getTime()); // 本次采样时间 - info.setTotalPower(new BigDecimal(realTimeMonitorData.getChargingDegree())); // 累计充电量 - // info.setElecMoney(); // 累计电费 - // info.setSeviceMoney(); // 累计服务费 - info.setTotalMoney(new BigDecimal(realTimeMonitorData.getChargingAmount())); - - ConnectorStatusInfos.add(info); - - } else { - // 其他 - ConnectorStatusInfo info = new ConnectorStatusInfo(); - info.setConnectorID(connectorInfoVO.getPileConnectorCode()); - info.setStatus(connectorInfoVO.getConnectorStatus()); - - ConnectorStatusInfos.add(info); - } - StationStatusInfo stationStatusInfo = new StationStatusInfo(); - stationStatusInfo.setStationID(connectorInfoVO.getStationId()); - stationStatusInfo.setConnectorStatusInfos(ConnectorStatusInfos); - - StationStatusInfos.add(stationStatusInfo); - } - } - // 将 StationStatusInfos 分页 - int pageNum = 1; - int pageSize = 10; - List collect = StationStatusInfos.stream() - .skip((pageNum - 1) * pageSize) - .limit(pageSize) - .collect(Collectors.toList()); - - int total = StationStatusInfos.size(); - int pages = PageUtil.totalPage(total, pageSize); - - LianLianPageResponse response = LianLianPageResponse.builder() - .PageCount(pages) - .PageNo(pageNum) - .list(collect) - .ItemSize(total) - .build(); - return response; - } - - /** - * 查询统计信息 - * @param dto - * @return - */ - @Override - public StationStatsInfo query_station_stats(QueryStationInfoDTO dto) { - // 根据站点id 查出这段时间的充电量 - List list = orderBasicInfoService.getAccumulativeInfoForLianLian(dto); - if (CollectionUtils.isEmpty(list)) { - return StationStatsInfo.builder() - .StationID(dto.getStationID()) - .StartTime(dto.getStartTime()) - .EndTime(dto.getEndTime()) - .StationElectricity(BigDecimal.ZERO) - .equipmentStatsInfos(Lists.newArrayList()) // 设备列表 - .build(); - } - - // 根据充电桩编号分组 key=充电桩编号 - Map> pileMap = list.stream() - .collect(Collectors.groupingBy(AccumulativeInfoVO::getPileSn)); - - // 存放所有充电桩设备 - List equipmentStatsInfoList = Lists.newArrayList(); - // 站点用电量 - BigDecimal stationElectricity = BigDecimal.ZERO; - // 用于记录枪口用电量 在循环每个枪口的时候初始化 - BigDecimal pileElec; - for (String pileSn : pileMap.keySet()) { - // 该充电桩下 所有枪口的用电数据 - List accumulativeInfoVOS = pileMap.get(pileSn); - if (CollectionUtils.isEmpty(accumulativeInfoVOS)) { - continue; - } - - // 存放充电桩用电量 - pileElec = BigDecimal.ZERO; - - // key=枪口编号 value 该枪口的用电数据 - Map> collect = accumulativeInfoVOS.stream() - .collect(Collectors.groupingBy(AccumulativeInfoVO::getPileConnectorCode)); - - List connectorStatsInfos = Lists.newArrayList(); - for (Map.Entry> entry : collect.entrySet()) { - String pileConnectorCode = entry.getKey(); - List value = entry.getValue(); - // 枪口用电量求和 - BigDecimal connectorElec = value.stream() - .map(AccumulativeInfoVO::getConnectorElectricity) - .map(BigDecimal::new) - .reduce(BigDecimal.ZERO, BigDecimal::add); - - connectorStatsInfos.add( - ConnectorStatsInfo.builder() - .ConnectorID(pileConnectorCode) - .ConnectorElectricity(connectorElec) - .build() - ); - // 充电桩电量为枪口用电量累计 - pileElec = pileElec.add(connectorElec); - } - - EquipmentStatsInfo build = EquipmentStatsInfo.builder() - .EquipmentID(pileSn) - .EquipmentElectricity(pileElec) - .ConnectorStatsInfos(connectorStatsInfos) - .build(); - equipmentStatsInfoList.add(build); - - // 所有充电桩用电量之和 - stationElectricity = stationElectricity.add(pileElec); - } - - StationStatsInfo stationStatsInfo = StationStatsInfo.builder() - .StationID(dto.getStationID()) - .StartTime(dto.getStartTime()) - .EndTime(dto.getEndTime()) - .StationElectricity(stationElectricity) - .equipmentStatsInfos(equipmentStatsInfoList) // 设备列表 - .build(); - - return stationStatsInfo; - } - - /** - * 请求设备认证 - * @param dto - * @return - */ - @Override - public EquipmentAuthVO query_equip_auth(QueryEquipmentDTO dto) { - EquipmentAuthVO vo = new EquipmentAuthVO(); - - String equipAuthSeq = dto.getEquipAuthSeq(); - String pileConnectorCode = dto.getConnectorID(); - // 通过运营商id + 枪口编码查询数据 - String merchantId = StringUtils.substring(equipAuthSeq, 0, 9); - String pileSn = StringUtils.substring(pileConnectorCode, 0, 14); - // 能查到为成功 - vo.setSuccStat(1); // 1-失败 0-成功 - PileBasicInfo pileBasicInfo = pileBasicInfoService.selectPileBasicInfoBySN(pileSn); - if (pileBasicInfo == null) { - vo.setFailReason(2); // 设备检测失败 - vo.setFailReasonMsg("未查到该桩的数据"); - throw new BusinessException("", ""); - } - if (pileBasicInfo.getMerchantId() == Long.parseLong(merchantId)) { - vo.setSuccStat(0); - // 查询当前数据 - PileConnectorInfoVO connectorInfo = pileConnectorInfoService.getPileConnectorInfoByConnectorCode(pileConnectorCode); - if (StringUtils.equals(PileConnectorDataBaseStatusEnum.OCCUPIED_NOT_CHARGED.getValue(), String.valueOf(connectorInfo.getStatus())) - || StringUtils.equals(PileConnectorDataBaseStatusEnum.OCCUPIED_CHARGING.getValue(), String.valueOf(connectorInfo.getStatus())) - || StringUtils.equals(PileConnectorDataBaseStatusEnum.OCCUPIED_APPOINTMENT_LOCK.getValue(), String.valueOf(connectorInfo.getStatus())) - ) { - vo.setFailReason(0); - } else { - vo.setFailReason(1); // 1- 此设备尚未插枪; - } - vo.setFailReasonMsg(""); - } - - vo.setEquipAuthSeq(equipAuthSeq); - vo.setConnectorID(pileConnectorCode); - - return vo; - } - - - /** - * 请求启动充电 - * @param dto - */ - public QueryStartChargeVO query_start_charge(QueryStartChargeDTO dto) { - // 通过传过来的订单号和枪口号生成订单 - // 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(); - // 推送启动充电结果 - pushStartChargeResult(orderCode); - - return vo; - - - } - - - /** - * 查询充电状态 - * @param startChargeSeq - * @return - */ - public QueryChargingStatusVO query_equip_charge_status(String startChargeSeq) { - // 通过订单号查询订单信息 - OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(startChargeSeq); - // 通过订单号查询实时数据 - 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(); - if (StringUtils.equals(orderStatus, OrderStatusEnum.IN_THE_CHARGING.getValue())) { - // 充电中 - orderStatus = "2"; - }if (StringUtils.equals(orderStatus, OrderStatusEnum.ORDER_COMPLETE.getValue())) { - // 充电完成 - orderStatus = "4"; - }else { - // 直接给 5-未知 - orderStatus = "5"; - } - // 拼装联联平台数据 - QueryChargingStatusVO vo = QueryChargingStatusVO.builder() - .StartChargeSeq(startChargeSeq) // 订单号 - .StartChargeSeqStat(Integer.parseInt(orderStatus)) // 订单状态 - .ConnectorID(orderInfo.getPileConnectorCode()) // 枪口编码 - .ConnectorStatus(Integer.parseInt(data.getConnectorStatus())) // 枪口状态 - .CurrentA(new BigDecimal(data.getOutputCurrent())) // 电流 - .VoltageA(new BigDecimal(data.getOutputVoltage())) // 电压 - .Soc(new BigDecimal(data.getSOC())) - .StartTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderInfo.getChargeStartTime())) // 开始时间 - .EndTime(DateUtils.getTime()) // 本次采样时间 - .TotalPower(new BigDecimal(data.getChargingDegree())) // 累计充电量 - .ElecMoney(orderDetail.getTotalElectricityAmount()) // 累计电费 - .SeviceMoney(orderDetail.getTotalServiceAmount()) // 累计服务费 - .TotalMoney(new BigDecimal(data.getChargingAmount())) // 已充金额 - - .build(); - - - return vo; - } - - - /** - * 请求停止充电 - * @param dto - * @return - */ - public QueryStopChargeVO query_stop_charge(QueryStartChargeDTO dto) { - QueryStopChargeVO vo = new QueryStopChargeVO(); - - String orderCode = dto.getStartChargeSeq(); - - // 根据订单号查询订单信息 - OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); - if (orderInfo == null) { - throw new BusinessException("", ""); - } - // 若状态为充电中,则发送停机指令 - if (StringUtils.equals(OrderStatusEnum.IN_THE_CHARGING.getValue(), orderInfo.getOrderStatus())) { - // 充电中 - StopChargingCommand command = StopChargingCommand.builder() - .pileSn(orderInfo.getPileSn()) - .connectorCode(orderInfo.getConnectorCode()) - .build(); - ykcPushCommandService.pushStopChargingCommand(command); - vo.setStartChargeSeq(orderCode); - vo.setStartChargeSeqStat(3); // 3-停止中 - } - return vo; - } - - /** - * 从联联平台获取令牌 - * @param operatorId - * @param operatorSecret - * @return - */ - @Override - public String getToken(String urlAddress, String operatorId, String operatorSecret) { - // String operatorId = dto.getOperatorId(); - // String operatorSecret = dto.getOperatorSecret(); - String token = ""; - try { - //测试用请求地址 - String requestUrl = urlAddress + "query_token"; - - //请求data - Map data = new HashMap<>(); - data.put("OperatorID", operatorId); - data.put("OperatorSecret", operatorSecret); - String dataJson = JSONUtil.toJsonStr(data); - - //加密 - byte[] encryptText = Cryptos.aesEncrypt(dataJson.getBytes("UTF-8"), - operatorSecret.getBytes(), operatorSecret.getBytes()); - String strData = Encodes.encodeBase64(encryptText); - - Map request = new LinkedHashMap<>(); - request.put("OperatorID", operatorId); - request.put("Data", strData); - request.put("TimeStamp", DateUtils.parseDateToStr(DateUtils.YYYYMMDDHHMMSS, new Date())); - request.put("Seq", "0001"); - - //生成签名 - String sig = GBSignUtils.sign(request, operatorSecret); - request.put("Sig", sig); - - String tokenRequest = JSONUtil.toJsonStr(request); - - String response = HttpUtil.post(requestUrl, tokenRequest); - LianLianResultVO result = JSON.parseObject(response, LianLianResultVO.class); - - if (result.getRet() == 0) { - //解密data - byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64((String) result.getData()), - operatorSecret.getBytes(), operatorSecret.getBytes()); - String dataStr = new String(plainText, "UTF-8"); - Map resultMap = (Map) JSON.parse(dataStr); - token = resultMap.get("AccessToken"); - } - } catch (Exception e) { - return token; - } - return token; - } - - /** - * 联联平台推送 设备状态变化推送 notification_stationStatus - * @param pileConnectorCode - * @param status - * @return - */ - @Override - public String pushConnectorStatus(String pileConnectorCode, String status) { - // 查出该桩所属哪个站点 - String pileSn = StringUtils.substring(pileConnectorCode, 0, 14); - PileStationVO stationVO = pileStationInfoService.getStationInfoByPileSn(pileSn); - // 通过站点id查询相关配置信息 - ThirdPartySettingInfo settingInfo = thirdPartySettingInfoService.getInfoByStationId(Long.parseLong(stationVO.getId())); - if (settingInfo == null) { - return null; - } - String operatorId = settingInfo.getOperatorId(); - String operatorSecret = settingInfo.getOperatorSecret(); - String signSecret = settingInfo.getSignSecret(); - String dataSecret = settingInfo.getDataSecret(); - String dataSecretIv = settingInfo.getDataSecretIv(); - String urlAddress = settingInfo.getUrlAddress(); - - String url = urlAddress + "notification_stationStatus"; - - // 获取令牌 - String token = getToken(urlAddress, operatorId, operatorSecret); - if (StringUtils.isBlank(token)) { - return null; - } - ConnectorStatusInfo info = ConnectorStatusInfo.builder() - .connectorID(pileConnectorCode) - .status(status) - .build(); - // 调用联联平台接口 - JSONObject json = new JSONObject(); - json.put("ConnectorStatusInfo", info); - String jsonString = JSONObject.toJSONString(json); - - String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret); - - return result; - } - - /** - * 推送订单信息 notification_orderInfo - * @param orderCode - * @return - */ - @Override - public String pushOrderInfo(String orderCode) { - List chargeDetails = new ArrayList<>(); - // 根据订单号查询出信息 - OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); - OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderCode); - - // 通过站点id查询相关配置信息 - ThirdPartySettingInfo settingInfo = thirdPartySettingInfoService.getInfoByStationId(Long.parseLong(orderBasicInfo.getStationId())); - if (settingInfo == null) { - return null; - } - String operatorId = settingInfo.getOperatorId(); - String operatorSecret = settingInfo.getOperatorSecret(); - String signSecret = settingInfo.getSignSecret(); - String dataSecret = settingInfo.getDataSecret(); - String dataSecretIv = settingInfo.getDataSecretIv(); - String urlAddress = settingInfo.getUrlAddress(); - - String url = urlAddress + "notification_orderInfo"; - - // 拼装成联联平台所需格式对象 - OrderInfo orderInfo = OrderInfo.builder() - .operatorID(operatorId) - .equipmentOwnerID(Constants.OPERATORID_LIANLIAN) - .stationID(orderBasicInfo.getStationId()) - .equipmentID(orderBasicInfo.getPileSn()) - .connectorID(orderBasicInfo.getPileConnectorCode()) - .startChargeSeq(orderCode) - .userChargeType(Constants.one) - .money(new BigDecimal(String.valueOf(orderBasicInfo.getOrderAmount())).setScale(2, BigDecimal.ROUND_HALF_UP)) - .electMoney(new BigDecimal(String.valueOf(orderDetail.getTotalElectricityAmount())).setScale(2, BigDecimal.ROUND_HALF_UP)) - .serviceMoney(new BigDecimal(String.valueOf(orderDetail.getTotalServiceAmount())).setScale(2, BigDecimal.ROUND_HALF_UP)) - .elect(new BigDecimal(String.valueOf(orderDetail.getTotalUsedElectricity())).setScale(2, BigDecimal.ROUND_HALF_UP)) - .startTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderBasicInfo.getChargeStartTime())) - .endTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderBasicInfo.getChargeEndTime())) - .paymentAmount(orderBasicInfo.getPayAmount()) - // .payChannel() - .stopReason(0) - // .chargeDetails() - .build(); - // 支付方式 - if (StringUtils.equals(orderBasicInfo.getPayMode(), OrderPayModeEnum.PAYMENT_OF_WECHATPAY.getValue())) { - // 微信支付 - orderInfo.setPayChannel(Integer.valueOf(PayChannelEnum.WEXIN_PAY.getCode())); - }else if (StringUtils.equals(orderBasicInfo.getPayMode(), OrderPayModeEnum.PAYMENT_OF_ALIPAY.getValue())) { - // 支付宝支付 - orderInfo.setPayChannel(Integer.valueOf(PayChannelEnum.ALI_PAY.getCode())); - }else { - // 其他 - orderInfo.setPayChannel(Integer.valueOf(PayChannelEnum.OTHER.getCode())); - } - // 订单详情 - ChargeDetail detail; - - List billingList = pileBillingTemplateService.queryBillingPrice(orderBasicInfo.getStationId()); - // 先将list按照 尖、峰、平、谷 时段排序 - // List collect = billingList.stream().sorted(Comparator.comparing(BillingPriceVO::getTimeType)).collect(Collectors.toList()); - // 再循环该list,拼装对应的充电价格、费率 - for (BillingPriceVO billingPriceVO : billingList) { - detail = new ChargeDetail(); - if (StringUtils.equals(billingPriceVO.getTimeType(), "1")) { - // 尖时段 - detail.setDetailStartTime(billingPriceVO.getStartTime()); - detail.setDetailEndTime(billingPriceVO.getEndTime()); - detail.setElecPrice(new BigDecimal(billingPriceVO.getElectricityPrice()).setScale(4, BigDecimal.ROUND_HALF_UP)); - detail.setSevicePrice(new BigDecimal(billingPriceVO.getServicePrice()).setScale(4, BigDecimal.ROUND_HALF_UP)); - detail.setDetailPower(orderDetail.getSharpUsedElectricity()); - detail.setDetailElecMoney(orderDetail.getSharpElectricityPrice()); - detail.setDetailSeviceMoney(orderDetail.getSharpServicePrice()); - }else if (StringUtils.equals(billingPriceVO.getTimeType(), "2")) { - // 峰时段 - detail.setDetailStartTime(billingPriceVO.getStartTime()); - detail.setDetailEndTime(billingPriceVO.getEndTime()); - detail.setElecPrice(new BigDecimal(billingPriceVO.getElectricityPrice()).setScale(4, BigDecimal.ROUND_HALF_UP)); - detail.setSevicePrice(new BigDecimal(billingPriceVO.getServicePrice()).setScale(4, BigDecimal.ROUND_HALF_UP)); - detail.setDetailPower(orderDetail.getPeakUsedElectricity()); - detail.setDetailElecMoney(orderDetail.getPeakElectricityPrice()); - detail.setDetailSeviceMoney(orderDetail.getPeakServicePrice()); - }else if (StringUtils.equals(billingPriceVO.getTimeType(), "3")) { - // 平时段 - detail.setDetailStartTime(billingPriceVO.getStartTime()); - detail.setDetailEndTime(billingPriceVO.getEndTime()); - detail.setElecPrice(new BigDecimal(billingPriceVO.getElectricityPrice()).setScale(4, BigDecimal.ROUND_HALF_UP)); - detail.setSevicePrice(new BigDecimal(billingPriceVO.getServicePrice()).setScale(4, BigDecimal.ROUND_HALF_UP)); - detail.setDetailPower(orderDetail.getFlatUsedElectricity()); - detail.setDetailElecMoney(orderDetail.getFlatElectricityPrice()); - detail.setDetailSeviceMoney(orderDetail.getFlatServicePrice()); - }else if (StringUtils.equals(billingPriceVO.getTimeType(), "4")) { - // 谷时段 - detail.setDetailStartTime(billingPriceVO.getStartTime()); - detail.setDetailEndTime(billingPriceVO.getEndTime()); - detail.setElecPrice(new BigDecimal(billingPriceVO.getElectricityPrice()).setScale(4, BigDecimal.ROUND_HALF_UP)); - detail.setSevicePrice(new BigDecimal(billingPriceVO.getServicePrice()).setScale(4, BigDecimal.ROUND_HALF_UP)); - detail.setDetailPower(orderDetail.getValleyUsedElectricity()); - detail.setDetailElecMoney(orderDetail.getValleyElectricityPrice()); - detail.setDetailSeviceMoney(orderDetail.getValleyServicePrice()); - } - chargeDetails.add(detail); - } - - orderInfo.setChargeDetails(chargeDetails); - - // 获取令牌 - String token = getToken(urlAddress, operatorId, operatorSecret); - if (StringUtils.isBlank(token)) { - return null; - } - // 调用联联平台接口 - JSONObject json = new JSONObject(); - json.put("OrderInfo", orderInfo); - String jsonString = JSONObject.toJSONString(json); - - String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret); - - return result; - } - - /** - * 推送启动充电结果 - * @param orderCode - * @return - */ - @Override - public String pushStartChargeResult(String orderCode) { - // 根据订单号查询订单信息 - OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); - if (orderInfo == null) { - return null; - } - // 通过站点id查询相关配置信息 - ThirdPartySettingInfo settingInfo = thirdPartySettingInfoService.getInfoByStationId(Long.parseLong(orderInfo.getStationId())); - if (settingInfo == null) { - return null; - } - String operatorId = settingInfo.getOperatorId(); - String operatorSecret = settingInfo.getOperatorSecret(); - String signSecret = settingInfo.getSignSecret(); - String dataSecret = settingInfo.getDataSecret(); - String dataSecretIv = settingInfo.getDataSecretIv(); - String urlAddress = settingInfo.getUrlAddress(); - - // 推送启动充电结果(调用接口 notification_start_charge_result) - String url = urlAddress + "notification_start_charge_result"; - // 获取令牌 - String token = getToken(urlAddress, operatorId, operatorSecret); - if (StringUtils.isBlank(token)) { - return null; - } - String orderStatus = orderInfo.getOrderStatus(); - // 订单状态统一 - if (StringUtils.equals(OrderStatusEnum.IN_THE_CHARGING.getValue(), orderStatus)) { - // 充电中 - orderStatus = "2"; - }else if (StringUtils.equals(OrderStatusEnum.NOT_START.getValue(), orderStatus)) { - // 未启动 - orderStatus = "1"; - }else { - // 其他状态都为 未知 - orderStatus = "5"; - } - // 拼装参数 - JSONObject json = new JSONObject(); - json.put("StartChargeSeq", orderCode); - json.put("ConnectorID", orderInfo.getPileConnectorCode()); - json.put("StartChargeSeqStat", Integer.valueOf(orderStatus)); - json.put("StartTime", orderInfo.getChargeStartTime()); - - String jsonString = JSONObject.toJSONString(json); - - String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret); - - return result; - } - - /** - * 推送充电状态(仅桩充电时调) - * @param orderCode - * @return - */ - @Override - public String pushChargeStatus(String orderCode) { - // 根据订单号查询订单信息 - OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); - // 通过站点id查询相关配置信息 - ThirdPartySettingInfo settingInfo = thirdPartySettingInfoService.getInfoByStationId(Long.parseLong(orderInfo.getStationId())); - if (settingInfo == null) { - return null; - } - String operatorId = settingInfo.getOperatorId(); - String operatorSecret = settingInfo.getOperatorSecret(); - String signSecret = settingInfo.getSignSecret(); - String dataSecret = settingInfo.getDataSecret(); - String dataSecretIv = settingInfo.getDataSecretIv(); - String urlAddress = settingInfo.getUrlAddress(); - - // 调用 查询充电状态方法 - QueryChargingStatusVO vo = query_equip_charge_status(orderCode); - // 获取令牌 - String token = getToken(urlAddress, operatorId, operatorSecret); - if (StringUtils.isBlank(token)) { - return null; - } - String url = urlAddress + "notification_equip_charge_status"; - // 调用联联平台接口 - String jsonString = JSONObject.toJSONString(vo); - - String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret); - - return result; - } - - /** - * 推送停止充电结果(仅在 交易记录的帧类型中调用) - * @param orderCode - * @return - */ - @Override - public String pushStopChargeResult(String orderCode) { - - // 根据订单号查询订单信息 - OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); - if (orderInfo == null) { - return null; - } - // 通过站点id查询相关配置信息 - ThirdPartySettingInfo settingInfo = thirdPartySettingInfoService.getInfoByStationId(Long.parseLong(orderInfo.getStationId())); - if (settingInfo == null) { - return null; - } - String operatorId = settingInfo.getOperatorId(); - String operatorSecret = settingInfo.getOperatorSecret(); - String signSecret = settingInfo.getSignSecret(); - String dataSecret = settingInfo.getDataSecret(); - String dataSecretIv = settingInfo.getDataSecretIv(); - String urlAddress = settingInfo.getUrlAddress(); - - String url = urlAddress + "notification_stop_charge_result"; - - String orderStatus = orderInfo.getOrderStatus(); - String successFlag = "1"; - if (StringUtils.equals(orderStatus, OrderStatusEnum.IN_THE_CHARGING.getValue())) { - // 充电中 - orderStatus = "2"; - }else if (StringUtils.equals(orderStatus, OrderStatusEnum.ORDER_COMPLETE.getValue())) { - // 订单完成 - orderStatus = "4"; - successFlag = "0"; - }else { - orderStatus = "5"; - } - // 获取token - String token = getToken(urlAddress, operatorId, operatorSecret); - if (StringUtils.isBlank(token)) { - return null; - } - - // 拼装联联平台参数 - JSONObject json = new JSONObject(); - json.put("StartChargeSeq", orderCode); - json.put("StartChargeSeqStat", Integer.valueOf(orderStatus)); - json.put("ConnectorID", orderInfo.getPileConnectorCode()); - json.put("SuccStat", successFlag); - json.put("FailReason", 0); - - String jsonString = JSONObject.toJSONString(json); - - // 发送请求 - String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret); - - return result; - } - - /** - * 推送充电订单信息 - * @param orderCode - * @return - */ - @Override - public String pushChargeOrderInfo(String orderCode) { - - OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); - OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderCode); - - // 通过站点id查询相关配置信息 - ThirdPartySettingInfo settingInfo = thirdPartySettingInfoService.getInfoByStationId(Long.parseLong(orderBasicInfo.getStationId())); - if (settingInfo == null) { - return null; - } - String operatorId = settingInfo.getOperatorId(); - String operatorSecret = settingInfo.getOperatorSecret(); - String signSecret = settingInfo.getSignSecret(); - String dataSecret = settingInfo.getDataSecret(); - String dataSecretIv = settingInfo.getDataSecretIv(); - String urlAddress = settingInfo.getUrlAddress(); - - String url = urlAddress + "notification_charge_order_info"; - - JSONObject json = new JSONObject(); - json.put("StartChargeSeq", orderCode); - json.put("ConnectorID", orderBasicInfo.getPileConnectorCode()); - json.put("StartTime", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderBasicInfo.getChargeStartTime())); - json.put("EndTime", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderBasicInfo.getChargeEndTime())); - json.put("TotalPower", orderDetail.getTotalUsedElectricity().setScale(2, BigDecimal.ROUND_HALF_UP)); - json.put("TotalElecMoney", orderDetail.getTotalElectricityAmount().setScale(2, BigDecimal.ROUND_HALF_UP)); - json.put("TotalSeviceMoney", orderDetail.getTotalServiceAmount().setScale(2, BigDecimal.ROUND_HALF_UP)); - json.put("TotalMoney", orderDetail.getTotalOrderAmount().setScale(2, BigDecimal.ROUND_HALF_UP)); - json.put("StopReason", 2); // 2:BMS 停止充电 - - String jsonString = JSONObject.toJSONString(json); - String token = getToken(urlAddress, operatorId, operatorSecret); - if (token == null) { - return null; - } - // 发送请求 - String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret); - - return result; - } - - /** - * 推送订单结算信息 - * @param dto - * @return - */ - @Override - public String pushOrderSettlementInfo(PushOrderSettlementDTO dto) { - String orderCode = dto.getStartChargeSeq(); - JSONObject json = new JSONObject(); - json.put("StartChargeSeq", orderCode); - json.put("ConnectorID", dto.getConnectorID()); - int confirmResult = Constants.one; - // 根据订单号查询订单信息 - OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); - OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderCode); - if (orderInfo == null || orderDetail == null) { - return null; - } - // 都不为空,根据传过来的数据进行修改数据库信息 - confirmResult = Constants.zero; - orderDetail.setTotalUsedElectricity(dto.getTotalPower()); // 累计充电量 - orderDetail.setTotalOrderAmount(dto.getTotalMoney()); // 累计总金额 - - orderBasicInfoService.updateOrderDetail(orderDetail); - - json.put("ConfirmResult", confirmResult); - String jsonString = JSONObject.toJSONString(json); - - return jsonString; - } - - /** - * 查询订单结算信息 - * @param orderCode - * @return - */ - @Override - public String queryOrderSettlementInfo(String orderCode) { - - JSONObject json = new JSONObject(); - json.put("StartChargeSeq", orderCode); - String jsonString = JSONObject.toJSONString(json); - - OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); - - // 通过站点id查询相关配置信息 - ThirdPartySettingInfo settingInfo = thirdPartySettingInfoService.getInfoByStationId(Long.parseLong(orderBasicInfo.getStationId())); - if (settingInfo == null) { - return null; - } - String operatorId = settingInfo.getOperatorId(); - String operatorSecret = settingInfo.getOperatorSecret(); - String signSecret = settingInfo.getSignSecret(); - String dataSecret = settingInfo.getDataSecret(); - String dataSecretIv = settingInfo.getDataSecretIv(); - String urlAddress = settingInfo.getUrlAddress(); - - String url = urlAddress + "query_order_settlement_info"; - - // 获取令牌 - String token = getToken(urlAddress, operatorId, operatorSecret); - if (StringUtils.isBlank(token)){ - return null; - } - // 发送请求 - String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret); - - return result; - } - - /** - * 推送订单对账结果信息 - * @param orderCode - * @return - */ - @Override - public String pushOrderReconciliationInfo(String orderCode) { - - List list = new ArrayList<>(); - // 根据订单号查询订单信息 - OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); - OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderCode); - if (orderInfo == null || orderDetail == null) { - return null; - } - - // 通过站点id查询相关配置信息 - ThirdPartySettingInfo settingInfo = thirdPartySettingInfoService.getInfoByStationId(Long.parseLong(orderInfo.getStationId())); - if (settingInfo == null) { - return null; - } - String operatorId = settingInfo.getOperatorId(); - String operatorSecret = settingInfo.getOperatorSecret(); - String signSecret = settingInfo.getSignSecret(); - String dataSecret = settingInfo.getDataSecret(); - String dataSecretIv = settingInfo.getDataSecretIv(); - String urlAddress = settingInfo.getUrlAddress(); - - String url = urlAddress + "check_charge_orders"; - - JSONObject json = new JSONObject(); - json.put("CheckOrderSeq", orderCode); - json.put("StartTime", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderInfo.getChargeStartTime())); - json.put("EndTime", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderInfo.getChargeEndTime())); - json.put("OrderCount", 1); - json.put("TotalOrderPower", orderDetail.getTotalUsedElectricity()); - json.put("TotalOrderMoney", orderDetail.getTotalOrderAmount()); - - ChargeOrder chargeOrder = ChargeOrder.builder() - .startChargeSeq(orderCode) - .totalPower(orderDetail.getTotalUsedElectricity()) - .totalMoney(orderDetail.getTotalOrderAmount()) - .build(); - list.add(chargeOrder); - json.put("ChargeOrders", list); - - // 获取令牌 - String token = getToken(urlAddress, operatorId, operatorSecret); - if (StringUtils.isBlank(token)){ - return null; - } - String jsonString = JSONObject.toJSONString(json); - // 发送请求 - String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret); - - return result; - } - - /** - * 设备充电中状态变化推送 notification_connector_charge_status - * @param orderCode - * @return - */ - @Override - public String pushPileChargeStatusChange(String orderCode) { - // 通过订单号查询信息 - OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); - // 根据枪口号查询充电实时状态 - OrderBasicInfo orderBasicInfo = orderBasicInfoService.queryChargingByPileConnectorCode(orderInfo.getPileConnectorCode()); - List list = orderBasicInfoService.getChargingRealTimeData(orderBasicInfo.getTransactionCode()); - RealTimeMonitorData realTimeMonitorData = list.get(0); - // 拼装联联参数 - ConnectorChargeStatusInfo info = ConnectorChargeStatusInfo.builder() - .startChargeSeq(orderBasicInfo.getOrderCode()) - .connectorID(orderInfo.getPileConnectorCode()) - .connectorStatus(Integer.valueOf(realTimeMonitorData.getConnectorStatus())) - .currentA(new BigDecimal(realTimeMonitorData.getOutputCurrent())) - .voltageA(new BigDecimal(realTimeMonitorData.getOutputVoltage())) - .soc(new BigDecimal(realTimeMonitorData.getSOC())) - .startTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderBasicInfo.getChargeStartTime())) - .endTime(DateUtils.getTime()) - .totalPower(new BigDecimal(realTimeMonitorData.getChargingDegree())) - .elecMoney(new BigDecimal("0")) // TODO - .seviceMoney(new BigDecimal("0")) // TODO - .totalMoney(new BigDecimal(realTimeMonitorData.getChargingAmount()).setScale(2, BigDecimal.ROUND_HALF_UP)) - - .build(); - - // 通过站点id查询相关配置信息 - ThirdPartySettingInfo settingInfo = thirdPartySettingInfoService.getInfoByStationId(Long.parseLong(orderBasicInfo.getStationId())); - if (settingInfo == null) { - return null; - } - String operatorId = settingInfo.getOperatorId(); - String operatorSecret = settingInfo.getOperatorSecret(); - String signSecret = settingInfo.getSignSecret(); - String dataSecret = settingInfo.getDataSecret(); - String dataSecretIv = settingInfo.getDataSecretIv(); - String urlAddress = settingInfo.getUrlAddress(); - - String url = urlAddress + "notification_connector_charge_status"; - - // 获取令牌 - String token = getToken(urlAddress, operatorId, operatorSecret); - if (StringUtils.isBlank(token)){ - return null; - } - JSONObject json = new JSONObject(); - json.put("ConnectorChargeStatusInfo", info); - - String jsonString = JSONObject.toJSONString(json); - // 发送请求 - String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret); - - return result; - } - - /** - * TODO 请求打印充电小票 - */ - public void query_print_parking_ticket() { - - } - - /** - * 获取桩列表信息 - * @param pileStationInfo - * @return - */ - private List getPileList(PileStationInfo pileStationInfo){ - List resultList = new ArrayList<>(); - // 通过站点id查询桩基本信息 - List list = pileBasicInfoService.getPileListByStationId(String.valueOf(pileStationInfo.getId())); - MerchantInfoVO merchantInfo = pileMerchantInfoService.getMerchantInfo(String.valueOf(pileStationInfo.getMerchantId())); - // 封装成联联平台对象 - for (PileBasicInfo pileBasicInfo : list) { - EquipmentInfo equipmentInfo = new EquipmentInfo(); - String pileSn = pileBasicInfo.getSn(); - - equipmentInfo.setEquipmentID(pileSn); - equipmentInfo.setManufacturerID(Constants.OPERATORID_LIANLIAN); - equipmentInfo.setConstructionTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, pileBasicInfo.getCreateTime())); - - PileModelInfoVO modelInfo = pileModelInfoService.getPileModelInfoByPileSn(pileSn); - equipmentInfo.setEquipmentType(Integer.valueOf(modelInfo.getSpeedType())); - - // Map pileStatus = pileConnectorInfoService.getPileStatus(Lists.newArrayList(pileBasicInfo.getSn())); - Map pileStatusMap = pileConnectorInfoService.getPileStatus(Lists.newArrayList(pileSn)); - String pileStatus = pileStatusMap.get(pileSn); - if (StringUtils.equals(PileStatusEnum.ON_LINE.getValue(), pileStatus)) { - // 1-在线 - pileStatus = LianLianPileStatusEnum.NORMAL.getCode(); - } else if (StringUtils.equals(PileStatusEnum.OFF_LINE.getValue(), pileStatus)) { - // 2-离线 - pileStatus = LianLianPileStatusEnum.CLOSE_OFFLINE.getCode(); - } else if (StringUtils.equals(PileStatusEnum.FAULT.getValue(), pileStatus)) { - // 3-故障 - pileStatus = LianLianPileStatusEnum.UNDER_MAINTENANCE.getCode(); - } - equipmentInfo.setEquipmentStatus(Integer.valueOf(pileStatus)); - equipmentInfo.setEquipmentPower(new BigDecimal(modelInfo.getRatedPower()).setScale(1, BigDecimal.ROUND_HALF_UP)); - equipmentInfo.setNewNationalStandard(1); - equipmentInfo.setVinFlag(1); - - List connectorList = getConnectorList(pileBasicInfo); - equipmentInfo.setConnectorInfos(connectorList); - - resultList.add(equipmentInfo); - } - return resultList; - } - - - /** - * 获取枪口列表 - * @param pileBasicInfo - * @return - */ - private List getConnectorList(PileBasicInfo pileBasicInfo){ - List resultList = new ArrayList<>(); - - List list = pileConnectorInfoService.selectPileConnectorInfoList(pileBasicInfo.getSn()); - for (PileConnectorInfo pileConnectorInfo : list) { - ConnectorInfo connectorInfo = new ConnectorInfo(); - - connectorInfo.setConnectorID(pileConnectorInfo.getPileConnectorCode()); - String pileSn = pileConnectorInfo.getPileSn(); - PileModelInfoVO modelInfo = pileModelInfoService.getPileModelInfoByPileSn(pileSn); - int connectorType = StringUtils.equals("1", modelInfo.getSpeedType()) ? 4 : 3; - - connectorInfo.setConnectorType(connectorType); - connectorInfo.setVoltageUpperLimits(Integer.valueOf(modelInfo.getRatedVoltage())); - connectorInfo.setVoltageLowerLimits(Integer.valueOf(modelInfo.getRatedVoltage())); - connectorInfo.setCurrent(Integer.valueOf(modelInfo.getRatedCurrent())); - connectorInfo.setPower(new BigDecimal(modelInfo.getRatedPower()).setScale(1, BigDecimal.ROUND_HALF_UP)); - - resultList.add(connectorInfo); - } - - return resultList; - } + // private static final String TEST_URL = "http://testdataexchange.evchargeonline.com:82/shevcs/v1/"; // http://testdataexchange.evchargeonline.com:82/shevcs/v1/ + // private static final String OPERATOR_ID = "MA1JLFUU8"; // MA1JLFUU8 987654321 + // private static final String OPERATOR_SECRET = "fGwLsxW1HdzLw7jp"; // fGwLsxW1HdzLw7jp 1234567890abcdef + // private static final String SIG_SECRET = "TmsdVaFVTtjzZbLi"; // 签名秘钥 TmsdVaFVTtjzZbLi 1234567890abcdef + // private static final String DATA_SECRET = "R1Hdq80mSWswwCzt"; // 消息密钥 R1Hdq80mSWswwCzt 1234567890abcdef + // private static final String DATA_SECRETIV = "LVpz3qHD8sM2PYjl"; // 消息密钥初始化向量 LVpz3qHD8sM2PYjl 1234567890abcdef + + @Autowired + private IPileMerchantInfoService pileMerchantInfoService; + + @Autowired + private IPileStationInfoService pileStationInfoService; + + @Autowired + private IPileBasicInfoService pileBasicInfoService; + + @Autowired + private IPileModelInfoService pileModelInfoService; + + @Autowired + private IPileConnectorInfoService pileConnectorInfoService; + + @Autowired + private IOrderBasicInfoService orderBasicInfoService; + + @Autowired + private YKCPushCommandService ykcPushCommandService; + + @Autowired + private IPileBillingTemplateService pileBillingTemplateService; + + @Autowired + private IThirdPartySettingInfoService thirdPartySettingInfoService; + + @Override + public void pushMerchantInfo(Long merchantId) { + // 通过id查询运营商信息 + MerchantInfoVO merchantInfo = pileMerchantInfoService.getMerchantInfo(String.valueOf(merchantId)); + // 组装联联平台所需要的数据格式 + OperatorInfo operatorInfo = OperatorInfo.builder() + .OperatorID(Constants.OPERATORID_LIANLIAN) // 组织机构代码 + .OperatorName(merchantInfo.getMerchantName()) // 机构全称 + .OperatorTel1(merchantInfo.getMerchantTel()) // 对接平台客服电话1 + .build(); + // 调用联联平台接口 + + + } + + /** + * 根据站点id推送站点信息 notification_stationInfo + * + * @param dto + */ + @Override + public String pushStationInfo(LianLianPushStationInfoDTO dto) { + // String OperatorID = "987654321"; + // String SigSecret = "1234567890abcdef"; // 签名秘钥 + // String DataSecret = "1234567890abcdef"; // 消息密钥 + // String DataSecretIV = "1234567890abcdef"; // 消息密钥初始化向量 + // String token = "c548f9276c1c4ea8b88b1f7b1eb7cf07"; //QueryToken类查询接口获取到的token + + // 通过id查询站点相关信息 + PileStationInfo pileStationInfo = pileStationInfoService.selectPileStationInfoById(dto.getStationId()); + // 通过站点id查询相关配置信息 + ThirdPartySettingInfo settingInfo = thirdPartySettingInfoService.getInfoByStationId(dto.getStationId()); + if (settingInfo == null) { + throw new BusinessException("", ""); + } + String operatorId = settingInfo.getOperatorId(); + String operatorSecret = settingInfo.getOperatorSecret(); + String signSecret = settingInfo.getSignSecret(); + String dataSecret = settingInfo.getDataSecret(); + String dataSecretIv = settingInfo.getDataSecretIv(); + String urlAddress = settingInfo.getUrlAddress(); + + // 组装联联平台所需要的数据格式 + StationInfo info = StationInfo.builder() + .stationID(String.valueOf(dto.getStationId())) + .operatorID(operatorId) + .equipmentOwnerID(Constants.OPERATORID_LIANLIAN) + .stationName(pileStationInfo.getStationName()) + .isAloneApply(Integer.valueOf(pileStationInfo.getAloneApply())) + .isPublicParkingLot(Integer.valueOf(pileStationInfo.getPublicParking())) + .countryCode(pileStationInfo.getCountryCode()) + .areaCode(pileStationInfo.getAreaCode()) + .address(pileStationInfo.getAddress()) + .serviceTel(pileStationInfo.getStationTel()) + .stationType(Integer.valueOf(pileStationInfo.getStationType())) + .stationStatus(Integer.valueOf(pileStationInfo.getStationStatus())) + .parkNums(Integer.valueOf(pileStationInfo.getParkNums())) + .stationLng(new BigDecimal(pileStationInfo.getStationLng())) + .stationLat(new BigDecimal(pileStationInfo.getStationLat())) + .construction(Integer.valueOf(pileStationInfo.getConstruction())) + .openAllDay(Integer.valueOf(pileStationInfo.getOpenAllDay())) + .minElectricityPrice(new BigDecimal(Constants.ZERO)) + .electricityFee(Constants.ZERO) + .serviceFee(Constants.ZERO) + .parkFree(Integer.valueOf(pileStationInfo.getParkFree())) + // .ParkFee("2") + // .payment("线上") + .supportOrder(Integer.valueOf(pileStationInfo.getSupportOrder())) + // .equipmentInfos() + .parkFeeType(0) + .toiletFlag(Integer.valueOf(pileStationInfo.getToiletFlag())) + .storeFlag(Integer.valueOf(pileStationInfo.getStoreFlag())) + .restaurantFlag(Integer.valueOf(pileStationInfo.getRestaurantFlag())) + .loungeFlag(Integer.valueOf(pileStationInfo.getLoungeFlag())) + .canopyFlag(Integer.valueOf(pileStationInfo.getCanopyFlag())) + .printerFlag(Integer.valueOf(pileStationInfo.getPrinterFlag())) + .barrierFlag(Integer.valueOf(pileStationInfo.getBarrierFlag())) + .parkingLockFlag(Integer.valueOf(pileStationInfo.getParkingLockFlag())) + + .build(); + String payment = StationPaymentEnum.getPaymentByCode(pileStationInfo.getPayment()); + info.setPayment(payment); + List pileList = getPileList(pileStationInfo); + if (CollectionUtils.isNotEmpty(pileList)) { + info.setEquipmentInfos(pileList); // 充电设备信息列表 + } + + // 调用联联平台接口 + String url = urlAddress + "notification_stationInfo"; + + String jsonStr = JSONObject.toJSONString(info); + JSONObject data = new JSONObject(); + data.put("StationInfo", jsonStr); + + String jsonString = JSONObject.toJSONString(data); + System.out.println("jsonString : " + jsonString); + + // 获取令牌 + String token = getToken(urlAddress, operatorId, operatorSecret); + String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret + , dataSecretIv, operatorId, signSecret); + + // System.out.println(result); + return result; + } + + public static void main(String[] args) { + + } + + /** + * 查询充电站信息 + * 对外接口 query_stations_info + * + * @return + */ + @Override + public LianLianPageResponse query_stations_info(QueryStationInfoDTO dto) { + List resultList = new ArrayList<>(); + int pageNo = dto.getPageNo() == null ? 1 : dto.getPageNo(); + int pageSize = dto.getPageSize() == null ? 10 : dto.getPageSize(); + + PageUtils.startPage(pageNo, pageSize); + List stationInfos = pileStationInfoService.getStationInfoForLianLian(); + if (CollectionUtils.isEmpty(stationInfos)) { + // 未查到数据 + return null; + } + PageInfo pageInfo = new PageInfo<>(stationInfos); + for (PileStationInfo pileStationInfo : pageInfo.getList()) { + StationInfo stationInfo = new StationInfo(); + stationInfo.setStationID(String.valueOf(pileStationInfo.getId())); + // MerchantInfoVO merchantInfo = pileMerchantInfoService.getMerchantInfo(String.valueOf(pileStationInfo.getMerchantId())); + stationInfo.setOperatorID(Constants.OPERATORID_LIANLIAN); // 组织机构代码 + stationInfo.setEquipmentOwnerID(String.valueOf(pileStationInfo.getMerchantId())); + stationInfo.setStationName(pileStationInfo.getStationName()); + stationInfo.setIsAloneApply(Integer.valueOf(pileStationInfo.getAloneApply())); + stationInfo.setIsPublicParkingLot(Integer.valueOf(pileStationInfo.getPublicParking())); + stationInfo.setCountryCode(pileStationInfo.getCountryCode()); + stationInfo.setAreaCode(pileStationInfo.getAreaCode()); + stationInfo.setAddress(pileStationInfo.getAddress()); + stationInfo.setServiceTel(pileStationInfo.getStationTel()); + stationInfo.setStationType(Integer.valueOf(pileStationInfo.getStationType())); + stationInfo.setParkNums(Integer.valueOf(pileStationInfo.getParkNums())); + stationInfo.setStationLng(new BigDecimal(pileStationInfo.getStationLng())); + stationInfo.setStationLat(new BigDecimal(pileStationInfo.getStationLat())); + stationInfo.setConstruction(Integer.valueOf(pileStationInfo.getConstruction())); + stationInfo.setOpenAllDay(Integer.valueOf(pileStationInfo.getOpenAllDay())); + // stationInfo.setMinElectricityPrice(pileStationInfo); // 最低充电电费率 + // stationInfo.setElectricityFee(); // 电费 xx元/度 + // stationInfo.setServiceFee(); // 服务费 xx元/度 + stationInfo.setParkFree(Integer.valueOf(pileStationInfo.getParkFree())); + stationInfo.setPayment(pileStationInfo.getPayment()); + stationInfo.setSupportOrder(Integer.valueOf(pileStationInfo.getSupportOrder())); + // stationInfo.setParkFeeType(pileStationInfo); // 停车收费类型 + stationInfo.setToiletFlag(Integer.valueOf(pileStationInfo.getToiletFlag())); + stationInfo.setStoreFlag(Integer.valueOf(pileStationInfo.getStoreFlag())); + stationInfo.setRestaurantFlag(Integer.valueOf(pileStationInfo.getRestaurantFlag())); + stationInfo.setLoungeFlag(Integer.valueOf(pileStationInfo.getLoungeFlag())); + stationInfo.setCanopyFlag(Integer.valueOf(pileStationInfo.getCanopyFlag())); + stationInfo.setPrinterFlag(Integer.valueOf(pileStationInfo.getPrinterFlag())); + stationInfo.setBarrierFlag(Integer.valueOf(pileStationInfo.getBarrierFlag())); + stationInfo.setParkingLockFlag(Integer.valueOf(pileStationInfo.getParkingLockFlag())); + + List pileList = getPileList(pileStationInfo); + if (CollectionUtils.isNotEmpty(pileList)) { + stationInfo.setEquipmentInfos(pileList); // 充电设备信息列表 + } + + resultList.add(stationInfo); + } + + LianLianPageResponse pageResponse = LianLianPageResponse.builder() + .PageNo(pageInfo.getPageNum()) + .PageCount(pageInfo.getPages()) + .ItemSize(resultList.size()) + .list(resultList) + .build(); + return pageResponse; + } + + /** + * 设备接口状态查询 + * 此接口用于批量查询设备实时状态 + * + * @param StationIDs + * @return + */ + @Override + public LianLianPageResponse query_station_status(List StationIDs) { + List StationStatusInfos = new ArrayList<>(); + List ConnectorStatusInfos = new ArrayList<>(); + + for (String stationId : StationIDs) { + // 根据站点id查询 + List list = pileConnectorInfoService.getConnectorListForLianLian(Long.parseLong(stationId)); + for (ConnectorInfoVO connectorInfoVO : list) { + + String connectorStatus = connectorInfoVO.getConnectorStatus(); + if (StringUtils.equals(connectorStatus, PileConnectorDataBaseStatusEnum.OCCUPIED_CHARGING.getValue())) { + // 充电中 + ConnectorChargeStatusInfo info = new ConnectorChargeStatusInfo(); + OrderBasicInfo orderBasicInfo = orderBasicInfoService.queryChargingByPileConnectorCode(connectorInfoVO.getPileConnectorCode()); + List chargingRealTimeData = orderBasicInfoService.getChargingRealTimeData(orderBasicInfo.getTransactionCode()); + RealTimeMonitorData realTimeMonitorData = chargingRealTimeData.get(0); + + info.setStartChargeSeq(orderBasicInfo.getOrderCode()); + info.setConnectorID(orderBasicInfo.getPileConnectorCode()); + info.setConnectorStatus(Integer.valueOf(connectorInfoVO.getConnectorStatus())); + info.setCurrentA(new BigDecimal(realTimeMonitorData.getOutputCurrent())); + info.setVoltageA(new BigDecimal(realTimeMonitorData.getOutputVoltage())); + info.setSoc(new BigDecimal(realTimeMonitorData.getSOC())); + info.setStartTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderBasicInfo.getChargeStartTime())); + info.setEndTime(DateUtils.getTime()); // 本次采样时间 + info.setTotalPower(new BigDecimal(realTimeMonitorData.getChargingDegree())); // 累计充电量 + // info.setElecMoney(); // 累计电费 + // info.setSeviceMoney(); // 累计服务费 + info.setTotalMoney(new BigDecimal(realTimeMonitorData.getChargingAmount())); + + ConnectorStatusInfos.add(info); + + } else { + // 其他 + ConnectorStatusInfo info = new ConnectorStatusInfo(); + info.setConnectorID(connectorInfoVO.getPileConnectorCode()); + info.setStatus(connectorInfoVO.getConnectorStatus()); + + ConnectorStatusInfos.add(info); + } + StationStatusInfo stationStatusInfo = new StationStatusInfo(); + stationStatusInfo.setStationID(connectorInfoVO.getStationId()); + stationStatusInfo.setConnectorStatusInfos(ConnectorStatusInfos); + + StationStatusInfos.add(stationStatusInfo); + } + } + // 将 StationStatusInfos 分页 + int pageNum = 1; + int pageSize = 10; + List collect = StationStatusInfos.stream() + .skip((pageNum - 1) * pageSize) + .limit(pageSize) + .collect(Collectors.toList()); + + int total = StationStatusInfos.size(); + int pages = PageUtil.totalPage(total, pageSize); + + LianLianPageResponse response = LianLianPageResponse.builder() + .PageCount(pages) + .PageNo(pageNum) + .list(collect) + .ItemSize(total) + .build(); + return response; + } + + /** + * 查询统计信息 + * + * @param dto + * @return + */ + @Override + public StationStatsInfo query_station_stats(QueryStationInfoDTO dto) { + // 根据站点id 查出这段时间的充电量 + List list = orderBasicInfoService.getAccumulativeInfoForLianLian(dto); + if (CollectionUtils.isEmpty(list)) { + return StationStatsInfo.builder() + .StationID(dto.getStationID()) + .StartTime(dto.getStartTime()) + .EndTime(dto.getEndTime()) + .StationElectricity(BigDecimal.ZERO) + .equipmentStatsInfos(Lists.newArrayList()) // 设备列表 + .build(); + } + + // 根据充电桩编号分组 key=充电桩编号 + Map> pileMap = list.stream() + .collect(Collectors.groupingBy(AccumulativeInfoVO::getPileSn)); + + // 存放所有充电桩设备 + List equipmentStatsInfoList = Lists.newArrayList(); + // 站点用电量 + BigDecimal stationElectricity = BigDecimal.ZERO; + // 用于记录枪口用电量 在循环每个枪口的时候初始化 + BigDecimal pileElec; + for (String pileSn : pileMap.keySet()) { + // 该充电桩下 所有枪口的用电数据 + List accumulativeInfoVOS = pileMap.get(pileSn); + if (CollectionUtils.isEmpty(accumulativeInfoVOS)) { + continue; + } + + // 存放充电桩用电量 + pileElec = BigDecimal.ZERO; + + // key=枪口编号 value 该枪口的用电数据 + Map> collect = accumulativeInfoVOS.stream() + .collect(Collectors.groupingBy(AccumulativeInfoVO::getPileConnectorCode)); + + List connectorStatsInfos = Lists.newArrayList(); + for (Map.Entry> entry : collect.entrySet()) { + String pileConnectorCode = entry.getKey(); + List value = entry.getValue(); + // 枪口用电量求和 + BigDecimal connectorElec = value.stream() + .map(AccumulativeInfoVO::getConnectorElectricity) + .map(BigDecimal::new) + .reduce(BigDecimal.ZERO, BigDecimal::add); + + connectorStatsInfos.add( + ConnectorStatsInfo.builder() + .ConnectorID(pileConnectorCode) + .ConnectorElectricity(connectorElec) + .build() + ); + // 充电桩电量为枪口用电量累计 + pileElec = pileElec.add(connectorElec); + } + + EquipmentStatsInfo build = EquipmentStatsInfo.builder() + .EquipmentID(pileSn) + .EquipmentElectricity(pileElec) + .ConnectorStatsInfos(connectorStatsInfos) + .build(); + equipmentStatsInfoList.add(build); + + // 所有充电桩用电量之和 + stationElectricity = stationElectricity.add(pileElec); + } + + StationStatsInfo stationStatsInfo = StationStatsInfo.builder() + .StationID(dto.getStationID()) + .StartTime(dto.getStartTime()) + .EndTime(dto.getEndTime()) + .StationElectricity(stationElectricity) + .equipmentStatsInfos(equipmentStatsInfoList) // 设备列表 + .build(); + + return stationStatsInfo; + } + + /** + * 请求设备认证 + * + * @param dto + * @return + */ + @Override + public EquipmentAuthVO query_equip_auth(QueryEquipmentDTO dto) { + EquipmentAuthVO vo = new EquipmentAuthVO(); + + String equipAuthSeq = dto.getEquipAuthSeq(); + String pileConnectorCode = dto.getConnectorID(); + // 通过运营商id + 枪口编码查询数据 + String merchantId = StringUtils.substring(equipAuthSeq, 0, 9); + String pileSn = StringUtils.substring(pileConnectorCode, 0, 14); + // 能查到为成功 + vo.setSuccStat(1); // 1-失败 0-成功 + PileBasicInfo pileBasicInfo = pileBasicInfoService.selectPileBasicInfoBySN(pileSn); + if (pileBasicInfo == null) { + vo.setFailReason(2); // 设备检测失败 + vo.setFailReasonMsg("未查到该桩的数据"); + throw new BusinessException("", ""); + } + if (pileBasicInfo.getMerchantId() == Long.parseLong(merchantId)) { + vo.setSuccStat(0); + // 查询当前数据 + PileConnectorInfoVO connectorInfo = pileConnectorInfoService.getPileConnectorInfoByConnectorCode(pileConnectorCode); + if (StringUtils.equals(PileConnectorDataBaseStatusEnum.OCCUPIED_NOT_CHARGED.getValue(), String.valueOf(connectorInfo.getStatus())) + || StringUtils.equals(PileConnectorDataBaseStatusEnum.OCCUPIED_CHARGING.getValue(), String.valueOf(connectorInfo.getStatus())) + || StringUtils.equals(PileConnectorDataBaseStatusEnum.OCCUPIED_APPOINTMENT_LOCK.getValue(), String.valueOf(connectorInfo.getStatus())) + ) { + vo.setFailReason(0); + } else { + vo.setFailReason(1); // 1- 此设备尚未插枪; + } + vo.setFailReasonMsg(""); + } + + vo.setEquipAuthSeq(equipAuthSeq); + vo.setConnectorID(pileConnectorCode); + + return vo; + } + + + /** + * 请求启动充电 + * + * @param dto + */ + public QueryStartChargeVO query_start_charge(QueryStartChargeDTO dto) { + // 通过传过来的订单号和枪口号生成订单 + // 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(); + // 推送启动充电结果 + pushStartChargeResult(orderCode); + + return vo; + + + } + + + /** + * 查询充电状态 + * + * @param startChargeSeq + * @return + */ + public QueryChargingStatusVO query_equip_charge_status(String startChargeSeq) { + // 通过订单号查询订单信息 + OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(startChargeSeq); + // 通过订单号查询实时数据 + 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(); + if (StringUtils.equals(orderStatus, OrderStatusEnum.IN_THE_CHARGING.getValue())) { + // 充电中 + orderStatus = "2"; + } + if (StringUtils.equals(orderStatus, OrderStatusEnum.ORDER_COMPLETE.getValue())) { + // 充电完成 + orderStatus = "4"; + } else { + // 直接给 5-未知 + orderStatus = "5"; + } + // 拼装联联平台数据 + QueryChargingStatusVO vo = QueryChargingStatusVO.builder() + .StartChargeSeq(startChargeSeq) // 订单号 + .StartChargeSeqStat(Integer.parseInt(orderStatus)) // 订单状态 + .ConnectorID(orderInfo.getPileConnectorCode()) // 枪口编码 + .ConnectorStatus(Integer.parseInt(data.getConnectorStatus())) // 枪口状态 + .CurrentA(new BigDecimal(data.getOutputCurrent())) // 电流 + .VoltageA(new BigDecimal(data.getOutputVoltage())) // 电压 + .Soc(new BigDecimal(data.getSOC())) + .StartTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderInfo.getChargeStartTime())) // 开始时间 + .EndTime(DateUtils.getTime()) // 本次采样时间 + .TotalPower(new BigDecimal(data.getChargingDegree())) // 累计充电量 + .ElecMoney(orderDetail.getTotalElectricityAmount()) // 累计电费 + .SeviceMoney(orderDetail.getTotalServiceAmount()) // 累计服务费 + .TotalMoney(new BigDecimal(data.getChargingAmount())) // 已充金额 + + .build(); + + + return vo; + } + + + /** + * 请求停止充电 + * + * @param dto + * @return + */ + public QueryStopChargeVO query_stop_charge(QueryStartChargeDTO dto) { + QueryStopChargeVO vo = new QueryStopChargeVO(); + + String orderCode = dto.getStartChargeSeq(); + + // 根据订单号查询订单信息 + OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); + if (orderInfo == null) { + throw new BusinessException("", ""); + } + // 若状态为充电中,则发送停机指令 + if (StringUtils.equals(OrderStatusEnum.IN_THE_CHARGING.getValue(), orderInfo.getOrderStatus())) { + // 充电中 + StopChargingCommand command = StopChargingCommand.builder() + .pileSn(orderInfo.getPileSn()) + .connectorCode(orderInfo.getConnectorCode()) + .build(); + ykcPushCommandService.pushStopChargingCommand(command); + vo.setStartChargeSeq(orderCode); + vo.setStartChargeSeqStat(3); // 3-停止中 + } + return vo; + } + + /** + * 从联联平台获取令牌 + * + * @param operatorId + * @param operatorSecret + * @return + */ + @Override + public String getToken(String urlAddress, String operatorId, String operatorSecret) { + // String operatorId = dto.getOperatorId(); + // String operatorSecret = dto.getOperatorSecret(); + String token = ""; + try { + // 测试用请求地址 + String requestUrl = urlAddress + "query_token"; + + // 请求data + Map data = new HashMap<>(); + data.put("OperatorID", operatorId); + data.put("OperatorSecret", operatorSecret); + String dataJson = JSONUtil.toJsonStr(data); + + // 加密 + byte[] encryptText = Cryptos.aesEncrypt(dataJson.getBytes("UTF-8"), + operatorSecret.getBytes(), operatorSecret.getBytes()); + String strData = Encodes.encodeBase64(encryptText); + + Map request = new LinkedHashMap<>(); + request.put("OperatorID", operatorId); + request.put("Data", strData); + request.put("TimeStamp", DateUtils.parseDateToStr(DateUtils.YYYYMMDDHHMMSS, new Date())); + request.put("Seq", "0001"); + + // 生成签名 + String sig = GBSignUtils.sign(request, operatorSecret); + request.put("Sig", sig); + + String tokenRequest = JSONUtil.toJsonStr(request); + + String response = HttpUtil.post(requestUrl, tokenRequest); + LianLianResultVO result = JSON.parseObject(response, LianLianResultVO.class); + + if (result.getRet() == 0) { + // 解密data + byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64((String) result.getData()), + operatorSecret.getBytes(), operatorSecret.getBytes()); + String dataStr = new String(plainText, "UTF-8"); + Map resultMap = (Map) JSON.parse(dataStr); + token = resultMap.get("AccessToken"); + } + } catch (Exception e) { + return token; + } + return token; + } + + /** + * 联联平台推送 设备状态变化推送 notification_stationStatus + * + * @param pileConnectorCode + * @param status + * @return + */ + @Override + public String pushConnectorStatus(String pileConnectorCode, String status) { + // 查出该桩所属哪个站点 + String pileSn = StringUtils.substring(pileConnectorCode, 0, 14); + PileStationVO stationVO = pileStationInfoService.getStationInfoByPileSn(pileSn); + // 通过站点id查询相关配置信息 + ThirdPartySettingInfo settingInfo = thirdPartySettingInfoService.getInfoByStationId(Long.parseLong(stationVO.getId())); + if (settingInfo == null) { + return null; + } + String operatorId = settingInfo.getOperatorId(); + String operatorSecret = settingInfo.getOperatorSecret(); + String signSecret = settingInfo.getSignSecret(); + String dataSecret = settingInfo.getDataSecret(); + String dataSecretIv = settingInfo.getDataSecretIv(); + String urlAddress = settingInfo.getUrlAddress(); + + String url = urlAddress + "notification_stationStatus"; + + // 获取令牌 + String token = getToken(urlAddress, operatorId, operatorSecret); + if (StringUtils.isBlank(token)) { + return null; + } + ConnectorStatusInfo info = ConnectorStatusInfo.builder() + .connectorID(pileConnectorCode) + .status(status) + .build(); + // 调用联联平台接口 + JSONObject json = new JSONObject(); + json.put("ConnectorStatusInfo", info); + String jsonString = JSONObject.toJSONString(json); + + String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret); + + return result; + } + + /** + * 推送订单信息 notification_orderInfo + * + * @param orderCode + * @return + */ + @Override + public String pushOrderInfo(String orderCode) { + List chargeDetails = new ArrayList<>(); + // 根据订单号查询出信息 + OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); + OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderCode); + + // 通过站点id查询相关配置信息 + ThirdPartySettingInfo settingInfo = thirdPartySettingInfoService.getInfoByStationId(Long.parseLong(orderBasicInfo.getStationId())); + if (settingInfo == null) { + return null; + } + String operatorId = settingInfo.getOperatorId(); + String operatorSecret = settingInfo.getOperatorSecret(); + String signSecret = settingInfo.getSignSecret(); + String dataSecret = settingInfo.getDataSecret(); + String dataSecretIv = settingInfo.getDataSecretIv(); + String urlAddress = settingInfo.getUrlAddress(); + + String url = urlAddress + "notification_orderInfo"; + + // 拼装成联联平台所需格式对象 + OrderInfo orderInfo = OrderInfo.builder() + .operatorID(operatorId) + .equipmentOwnerID(Constants.OPERATORID_LIANLIAN) + .stationID(orderBasicInfo.getStationId()) + .equipmentID(orderBasicInfo.getPileSn()) + .connectorID(orderBasicInfo.getPileConnectorCode()) + .startChargeSeq(orderCode) + .userChargeType(Constants.one) + .money(new BigDecimal(String.valueOf(orderBasicInfo.getOrderAmount())).setScale(2, BigDecimal.ROUND_HALF_UP)) + .electMoney(new BigDecimal(String.valueOf(orderDetail.getTotalElectricityAmount())).setScale(2, BigDecimal.ROUND_HALF_UP)) + .serviceMoney(new BigDecimal(String.valueOf(orderDetail.getTotalServiceAmount())).setScale(2, BigDecimal.ROUND_HALF_UP)) + .elect(new BigDecimal(String.valueOf(orderDetail.getTotalUsedElectricity())).setScale(2, BigDecimal.ROUND_HALF_UP)) + .startTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderBasicInfo.getChargeStartTime())) + .endTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderBasicInfo.getChargeEndTime())) + .paymentAmount(orderBasicInfo.getPayAmount()) + // .payChannel() + .stopReason(0) + // .chargeDetails() + .build(); + // 支付方式 + if (StringUtils.equals(orderBasicInfo.getPayMode(), OrderPayModeEnum.PAYMENT_OF_WECHATPAY.getValue())) { + // 微信支付 + orderInfo.setPayChannel(Integer.valueOf(PayChannelEnum.WEXIN_PAY.getCode())); + } else if (StringUtils.equals(orderBasicInfo.getPayMode(), OrderPayModeEnum.PAYMENT_OF_ALIPAY.getValue())) { + // 支付宝支付 + orderInfo.setPayChannel(Integer.valueOf(PayChannelEnum.ALI_PAY.getCode())); + } else { + // 其他 + orderInfo.setPayChannel(Integer.valueOf(PayChannelEnum.OTHER.getCode())); + } + // 订单详情 + ChargeDetail detail; + + List billingList = pileBillingTemplateService.queryBillingPrice(orderBasicInfo.getStationId()); + // 先将list按照 尖、峰、平、谷 时段排序 + // List collect = billingList.stream().sorted(Comparator.comparing(BillingPriceVO::getTimeType)).collect(Collectors.toList()); + // 再循环该list,拼装对应的充电价格、费率 + for (BillingPriceVO billingPriceVO : billingList) { + detail = new ChargeDetail(); + if (StringUtils.equals(billingPriceVO.getTimeType(), "1")) { + // 尖时段 + detail.setDetailStartTime(billingPriceVO.getStartTime()); + detail.setDetailEndTime(billingPriceVO.getEndTime()); + detail.setElecPrice(new BigDecimal(billingPriceVO.getElectricityPrice()).setScale(4, BigDecimal.ROUND_HALF_UP)); + detail.setSevicePrice(new BigDecimal(billingPriceVO.getServicePrice()).setScale(4, BigDecimal.ROUND_HALF_UP)); + detail.setDetailPower(orderDetail.getSharpUsedElectricity()); + detail.setDetailElecMoney(orderDetail.getSharpElectricityPrice()); + detail.setDetailSeviceMoney(orderDetail.getSharpServicePrice()); + } else if (StringUtils.equals(billingPriceVO.getTimeType(), "2")) { + // 峰时段 + detail.setDetailStartTime(billingPriceVO.getStartTime()); + detail.setDetailEndTime(billingPriceVO.getEndTime()); + detail.setElecPrice(new BigDecimal(billingPriceVO.getElectricityPrice()).setScale(4, BigDecimal.ROUND_HALF_UP)); + detail.setSevicePrice(new BigDecimal(billingPriceVO.getServicePrice()).setScale(4, BigDecimal.ROUND_HALF_UP)); + detail.setDetailPower(orderDetail.getPeakUsedElectricity()); + detail.setDetailElecMoney(orderDetail.getPeakElectricityPrice()); + detail.setDetailSeviceMoney(orderDetail.getPeakServicePrice()); + } else if (StringUtils.equals(billingPriceVO.getTimeType(), "3")) { + // 平时段 + detail.setDetailStartTime(billingPriceVO.getStartTime()); + detail.setDetailEndTime(billingPriceVO.getEndTime()); + detail.setElecPrice(new BigDecimal(billingPriceVO.getElectricityPrice()).setScale(4, BigDecimal.ROUND_HALF_UP)); + detail.setSevicePrice(new BigDecimal(billingPriceVO.getServicePrice()).setScale(4, BigDecimal.ROUND_HALF_UP)); + detail.setDetailPower(orderDetail.getFlatUsedElectricity()); + detail.setDetailElecMoney(orderDetail.getFlatElectricityPrice()); + detail.setDetailSeviceMoney(orderDetail.getFlatServicePrice()); + } else if (StringUtils.equals(billingPriceVO.getTimeType(), "4")) { + // 谷时段 + detail.setDetailStartTime(billingPriceVO.getStartTime()); + detail.setDetailEndTime(billingPriceVO.getEndTime()); + detail.setElecPrice(new BigDecimal(billingPriceVO.getElectricityPrice()).setScale(4, BigDecimal.ROUND_HALF_UP)); + detail.setSevicePrice(new BigDecimal(billingPriceVO.getServicePrice()).setScale(4, BigDecimal.ROUND_HALF_UP)); + detail.setDetailPower(orderDetail.getValleyUsedElectricity()); + detail.setDetailElecMoney(orderDetail.getValleyElectricityPrice()); + detail.setDetailSeviceMoney(orderDetail.getValleyServicePrice()); + } + chargeDetails.add(detail); + } + + orderInfo.setChargeDetails(chargeDetails); + + // 获取令牌 + String token = getToken(urlAddress, operatorId, operatorSecret); + if (StringUtils.isBlank(token)) { + return null; + } + // 调用联联平台接口 + JSONObject json = new JSONObject(); + json.put("OrderInfo", orderInfo); + String jsonString = JSONObject.toJSONString(json); + + String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret); + + return result; + } + + /** + * 推送启动充电结果 + * + * @param orderCode + * @return + */ + @Override + public String pushStartChargeResult(String orderCode) { + // 根据订单号查询订单信息 + OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); + if (orderInfo == null) { + return null; + } + // 通过站点id查询相关配置信息 + ThirdPartySettingInfo settingInfo = thirdPartySettingInfoService.getInfoByStationId(Long.parseLong(orderInfo.getStationId())); + if (settingInfo == null) { + return null; + } + String operatorId = settingInfo.getOperatorId(); + String operatorSecret = settingInfo.getOperatorSecret(); + String signSecret = settingInfo.getSignSecret(); + String dataSecret = settingInfo.getDataSecret(); + String dataSecretIv = settingInfo.getDataSecretIv(); + String urlAddress = settingInfo.getUrlAddress(); + + // 推送启动充电结果(调用接口 notification_start_charge_result) + String url = urlAddress + "notification_start_charge_result"; + // 获取令牌 + String token = getToken(urlAddress, operatorId, operatorSecret); + if (StringUtils.isBlank(token)) { + return null; + } + String orderStatus = orderInfo.getOrderStatus(); + // 订单状态统一 + if (StringUtils.equals(OrderStatusEnum.IN_THE_CHARGING.getValue(), orderStatus)) { + // 充电中 + orderStatus = "2"; + } else if (StringUtils.equals(OrderStatusEnum.NOT_START.getValue(), orderStatus)) { + // 未启动 + orderStatus = "1"; + } else { + // 其他状态都为 未知 + orderStatus = "5"; + } + // 拼装参数 + JSONObject json = new JSONObject(); + json.put("StartChargeSeq", orderCode); + json.put("ConnectorID", orderInfo.getPileConnectorCode()); + json.put("StartChargeSeqStat", Integer.valueOf(orderStatus)); + json.put("StartTime", orderInfo.getChargeStartTime()); + + String jsonString = JSONObject.toJSONString(json); + + String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret); + + return result; + } + + /** + * 推送充电状态(仅桩充电时调) + * + * @param orderCode + * @return + */ + @Override + public String pushChargeStatus(String orderCode) { + // 根据订单号查询订单信息 + OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); + // 通过站点id查询相关配置信息 + ThirdPartySettingInfo settingInfo = thirdPartySettingInfoService.getInfoByStationId(Long.parseLong(orderInfo.getStationId())); + if (settingInfo == null) { + return null; + } + String operatorId = settingInfo.getOperatorId(); + String operatorSecret = settingInfo.getOperatorSecret(); + String signSecret = settingInfo.getSignSecret(); + String dataSecret = settingInfo.getDataSecret(); + String dataSecretIv = settingInfo.getDataSecretIv(); + String urlAddress = settingInfo.getUrlAddress(); + + // 调用 查询充电状态方法 + QueryChargingStatusVO vo = query_equip_charge_status(orderCode); + // 获取令牌 + String token = getToken(urlAddress, operatorId, operatorSecret); + if (StringUtils.isBlank(token)) { + return null; + } + String url = urlAddress + "notification_equip_charge_status"; + // 调用联联平台接口 + String jsonString = JSONObject.toJSONString(vo); + + String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret); + + return result; + } + + /** + * 推送停止充电结果(仅在 交易记录的帧类型中调用) + * + * @param orderCode + * @return + */ + @Override + public String pushStopChargeResult(String orderCode) { + + // 根据订单号查询订单信息 + OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); + if (orderInfo == null) { + return null; + } + // 通过站点id查询相关配置信息 + ThirdPartySettingInfo settingInfo = thirdPartySettingInfoService.getInfoByStationId(Long.parseLong(orderInfo.getStationId())); + if (settingInfo == null) { + return null; + } + String operatorId = settingInfo.getOperatorId(); + String operatorSecret = settingInfo.getOperatorSecret(); + String signSecret = settingInfo.getSignSecret(); + String dataSecret = settingInfo.getDataSecret(); + String dataSecretIv = settingInfo.getDataSecretIv(); + String urlAddress = settingInfo.getUrlAddress(); + + String url = urlAddress + "notification_stop_charge_result"; + + String orderStatus = orderInfo.getOrderStatus(); + String successFlag = "1"; + if (StringUtils.equals(orderStatus, OrderStatusEnum.IN_THE_CHARGING.getValue())) { + // 充电中 + orderStatus = "2"; + } else if (StringUtils.equals(orderStatus, OrderStatusEnum.ORDER_COMPLETE.getValue())) { + // 订单完成 + orderStatus = "4"; + successFlag = "0"; + } else { + orderStatus = "5"; + } + // 获取token + String token = getToken(urlAddress, operatorId, operatorSecret); + if (StringUtils.isBlank(token)) { + return null; + } + + // 拼装联联平台参数 + JSONObject json = new JSONObject(); + json.put("StartChargeSeq", orderCode); + json.put("StartChargeSeqStat", Integer.valueOf(orderStatus)); + json.put("ConnectorID", orderInfo.getPileConnectorCode()); + json.put("SuccStat", successFlag); + json.put("FailReason", 0); + + String jsonString = JSONObject.toJSONString(json); + + // 发送请求 + String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret); + + return result; + } + + /** + * 推送充电订单信息 + * + * @param orderCode + * @return + */ + @Override + public String pushChargeOrderInfo(String orderCode) { + + OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); + OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderCode); + + // 通过站点id查询相关配置信息 + ThirdPartySettingInfo settingInfo = thirdPartySettingInfoService.getInfoByStationId(Long.parseLong(orderBasicInfo.getStationId())); + if (settingInfo == null) { + return null; + } + String operatorId = settingInfo.getOperatorId(); + String operatorSecret = settingInfo.getOperatorSecret(); + String signSecret = settingInfo.getSignSecret(); + String dataSecret = settingInfo.getDataSecret(); + String dataSecretIv = settingInfo.getDataSecretIv(); + String urlAddress = settingInfo.getUrlAddress(); + + String url = urlAddress + "notification_charge_order_info"; + + JSONObject json = new JSONObject(); + json.put("StartChargeSeq", orderCode); + json.put("ConnectorID", orderBasicInfo.getPileConnectorCode()); + json.put("StartTime", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderBasicInfo.getChargeStartTime())); + json.put("EndTime", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderBasicInfo.getChargeEndTime())); + json.put("TotalPower", orderDetail.getTotalUsedElectricity().setScale(2, BigDecimal.ROUND_HALF_UP)); + json.put("TotalElecMoney", orderDetail.getTotalElectricityAmount().setScale(2, BigDecimal.ROUND_HALF_UP)); + json.put("TotalSeviceMoney", orderDetail.getTotalServiceAmount().setScale(2, BigDecimal.ROUND_HALF_UP)); + json.put("TotalMoney", orderDetail.getTotalOrderAmount().setScale(2, BigDecimal.ROUND_HALF_UP)); + json.put("StopReason", 2); // 2:BMS 停止充电 + + String jsonString = JSONObject.toJSONString(json); + String token = getToken(urlAddress, operatorId, operatorSecret); + if (token == null) { + return null; + } + // 发送请求 + String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret); + + return result; + } + + /** + * 推送订单结算信息 + * + * @param dto + * @return + */ + @Override + public String pushOrderSettlementInfo(PushOrderSettlementDTO dto) { + String orderCode = dto.getStartChargeSeq(); + JSONObject json = new JSONObject(); + json.put("StartChargeSeq", orderCode); + json.put("ConnectorID", dto.getConnectorID()); + int confirmResult = Constants.one; + // 根据订单号查询订单信息 + OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); + OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderCode); + if (orderInfo == null || orderDetail == null) { + return null; + } + // 都不为空,根据传过来的数据进行修改数据库信息 + confirmResult = Constants.zero; + orderDetail.setTotalUsedElectricity(dto.getTotalPower()); // 累计充电量 + orderDetail.setTotalOrderAmount(dto.getTotalMoney()); // 累计总金额 + + orderBasicInfoService.updateOrderDetail(orderDetail); + + json.put("ConfirmResult", confirmResult); + String jsonString = JSONObject.toJSONString(json); + + return jsonString; + } + + /** + * 查询订单结算信息 + * + * @param orderCode + * @return + */ + @Override + public String queryOrderSettlementInfo(String orderCode) { + + JSONObject json = new JSONObject(); + json.put("StartChargeSeq", orderCode); + String jsonString = JSONObject.toJSONString(json); + + OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); + + // 通过站点id查询相关配置信息 + ThirdPartySettingInfo settingInfo = thirdPartySettingInfoService.getInfoByStationId(Long.parseLong(orderBasicInfo.getStationId())); + if (settingInfo == null) { + return null; + } + String operatorId = settingInfo.getOperatorId(); + String operatorSecret = settingInfo.getOperatorSecret(); + String signSecret = settingInfo.getSignSecret(); + String dataSecret = settingInfo.getDataSecret(); + String dataSecretIv = settingInfo.getDataSecretIv(); + String urlAddress = settingInfo.getUrlAddress(); + + String url = urlAddress + "query_order_settlement_info"; + + // 获取令牌 + String token = getToken(urlAddress, operatorId, operatorSecret); + if (StringUtils.isBlank(token)) { + return null; + } + // 发送请求 + String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret); + + return result; + } + + /** + * 推送订单对账结果信息 + * + * @param orderCode + * @return + */ + @Override + public String pushOrderReconciliationInfo(String orderCode) { + + List list = new ArrayList<>(); + // 根据订单号查询订单信息 + OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); + OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderCode); + if (orderInfo == null || orderDetail == null) { + return null; + } + + // 通过站点id查询相关配置信息 + ThirdPartySettingInfo settingInfo = thirdPartySettingInfoService.getInfoByStationId(Long.parseLong(orderInfo.getStationId())); + if (settingInfo == null) { + return null; + } + String operatorId = settingInfo.getOperatorId(); + String operatorSecret = settingInfo.getOperatorSecret(); + String signSecret = settingInfo.getSignSecret(); + String dataSecret = settingInfo.getDataSecret(); + String dataSecretIv = settingInfo.getDataSecretIv(); + String urlAddress = settingInfo.getUrlAddress(); + + String url = urlAddress + "check_charge_orders"; + + JSONObject json = new JSONObject(); + json.put("CheckOrderSeq", orderCode); + json.put("StartTime", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderInfo.getChargeStartTime())); + json.put("EndTime", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderInfo.getChargeEndTime())); + json.put("OrderCount", 1); + json.put("TotalOrderPower", orderDetail.getTotalUsedElectricity()); + json.put("TotalOrderMoney", orderDetail.getTotalOrderAmount()); + + ChargeOrder chargeOrder = ChargeOrder.builder() + .startChargeSeq(orderCode) + .totalPower(orderDetail.getTotalUsedElectricity()) + .totalMoney(orderDetail.getTotalOrderAmount()) + .build(); + list.add(chargeOrder); + json.put("ChargeOrders", list); + + // 获取令牌 + String token = getToken(urlAddress, operatorId, operatorSecret); + if (StringUtils.isBlank(token)) { + return null; + } + String jsonString = JSONObject.toJSONString(json); + // 发送请求 + String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret); + + return result; + } + + /** + * 设备充电中状态变化推送 notification_connector_charge_status + * + * @param orderCode + * @return + */ + @Override + public String pushPileChargeStatusChange(String orderCode) { + // 通过订单号查询信息 + OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); + // 根据枪口号查询充电实时状态 + OrderBasicInfo orderBasicInfo = orderBasicInfoService.queryChargingByPileConnectorCode(orderInfo.getPileConnectorCode()); + List list = orderBasicInfoService.getChargingRealTimeData(orderBasicInfo.getTransactionCode()); + RealTimeMonitorData realTimeMonitorData = list.get(0); + // 拼装联联参数 + ConnectorChargeStatusInfo info = ConnectorChargeStatusInfo.builder() + .startChargeSeq(orderBasicInfo.getOrderCode()) + .connectorID(orderInfo.getPileConnectorCode()) + .connectorStatus(Integer.valueOf(realTimeMonitorData.getConnectorStatus())) + .currentA(new BigDecimal(realTimeMonitorData.getOutputCurrent())) + .voltageA(new BigDecimal(realTimeMonitorData.getOutputVoltage())) + .soc(new BigDecimal(realTimeMonitorData.getSOC())) + .startTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderBasicInfo.getChargeStartTime())) + .endTime(DateUtils.getTime()) + .totalPower(new BigDecimal(realTimeMonitorData.getChargingDegree())) + .elecMoney(new BigDecimal("0")) // TODO + .seviceMoney(new BigDecimal("0")) // TODO + .totalMoney(new BigDecimal(realTimeMonitorData.getChargingAmount()).setScale(2, BigDecimal.ROUND_HALF_UP)) + + .build(); + + // 通过站点id查询相关配置信息 + ThirdPartySettingInfo settingInfo = thirdPartySettingInfoService.getInfoByStationId(Long.parseLong(orderBasicInfo.getStationId())); + if (settingInfo == null) { + return null; + } + String operatorId = settingInfo.getOperatorId(); + String operatorSecret = settingInfo.getOperatorSecret(); + String signSecret = settingInfo.getSignSecret(); + String dataSecret = settingInfo.getDataSecret(); + String dataSecretIv = settingInfo.getDataSecretIv(); + String urlAddress = settingInfo.getUrlAddress(); + + String url = urlAddress + "notification_connector_charge_status"; + + // 获取令牌 + String token = getToken(urlAddress, operatorId, operatorSecret); + if (StringUtils.isBlank(token)) { + return null; + } + JSONObject json = new JSONObject(); + json.put("ConnectorChargeStatusInfo", info); + + String jsonString = JSONObject.toJSONString(json); + // 发送请求 + String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret); + + return result; + } + + @Override + public Map generateToken(QueryTokenDTO dto) throws UnsupportedEncodingException { + String operatorID = dto.getOperatorID(); + // 通过operatorID 查出 operatorSecret + String operatorSecret = "123123123123aaaa"; + + Map map = Maps.newLinkedHashMap(); + map.put("OperatorID", dto.getOperatorID()); + map.put("Data", dto.getData()); + map.put("TimeStamp", dto.getTimeStamp()); + map.put("Seq", dto.getSeq()); + String sign = GBSignUtils.sign(map, operatorSecret); + System.out.println(sign); + + // 验证签名 得到请求方传过来的签名sig->自己拿到请求体后,再按双方约定的协议生成一个sig->对比两个sig是否一致 + if (!StringUtils.equals(dto.getSig(), sign)) { + System.out.println("签名校验==失败"); + return null; + } + System.out.println("签名校验通过!!!"); + + // 解密data + byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dto.getData()), operatorSecret.getBytes(), operatorSecret.getBytes()); + String dataStr = new String(plainText, "UTF-8"); + Map resMap = (Map) JSON.parse(dataStr); + + // 对比解出来的密钥是否和数据库中保存的一致 + + // 生成token返回 eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI0MjUwMTA3NjUiLCJpYXQiOjE2ODUwOTcxMTYsInN1YiI6IjEyMzEyMzEyMzEyM2FhYWEiLCJleHAiOjY4NjkwOTcxMTZ9.NyxOUIZmgsqtfex7oiMRR2LaWePTA56WHVMXIkWWt2w + long ttlMillis = 60 * 60 * 24 * 1000; + String token = JWTUtils.createToken(operatorID, operatorSecret, ttlMillis); + System.out.println(token); + + // 组装返回参数 + AccessTokenVO vo = new AccessTokenVO(); + vo.setAccessToken(token); + vo.setOperatorID(operatorID); + vo.setTokenAvailableTime(String.valueOf(ttlMillis / 1000)); + vo.setFailReason("0"); + vo.setSuccStat("0"); + + Map resultMap = Maps.newLinkedHashMap(); + // 加密数据 + resultMap.put("data", ""); + // 生成sig + resultMap.put("sig", ""); + return resultMap; + } + + /** + * TODO 请求打印充电小票 + */ + public void query_print_parking_ticket() { + + } + + /** + * 获取桩列表信息 + * + * @param pileStationInfo + * @return + */ + private List getPileList(PileStationInfo pileStationInfo) { + List resultList = new ArrayList<>(); + // 通过站点id查询桩基本信息 + List list = pileBasicInfoService.getPileListByStationId(String.valueOf(pileStationInfo.getId())); + MerchantInfoVO merchantInfo = pileMerchantInfoService.getMerchantInfo(String.valueOf(pileStationInfo.getMerchantId())); + // 封装成联联平台对象 + for (PileBasicInfo pileBasicInfo : list) { + EquipmentInfo equipmentInfo = new EquipmentInfo(); + String pileSn = pileBasicInfo.getSn(); + + equipmentInfo.setEquipmentID(pileSn); + equipmentInfo.setManufacturerID(Constants.OPERATORID_LIANLIAN); + equipmentInfo.setConstructionTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, pileBasicInfo.getCreateTime())); + + PileModelInfoVO modelInfo = pileModelInfoService.getPileModelInfoByPileSn(pileSn); + equipmentInfo.setEquipmentType(Integer.valueOf(modelInfo.getSpeedType())); + + // Map pileStatus = pileConnectorInfoService.getPileStatus(Lists.newArrayList(pileBasicInfo.getSn())); + Map pileStatusMap = pileConnectorInfoService.getPileStatus(Lists.newArrayList(pileSn)); + String pileStatus = pileStatusMap.get(pileSn); + if (StringUtils.equals(PileStatusEnum.ON_LINE.getValue(), pileStatus)) { + // 1-在线 + pileStatus = LianLianPileStatusEnum.NORMAL.getCode(); + } else if (StringUtils.equals(PileStatusEnum.OFF_LINE.getValue(), pileStatus)) { + // 2-离线 + pileStatus = LianLianPileStatusEnum.CLOSE_OFFLINE.getCode(); + } else if (StringUtils.equals(PileStatusEnum.FAULT.getValue(), pileStatus)) { + // 3-故障 + pileStatus = LianLianPileStatusEnum.UNDER_MAINTENANCE.getCode(); + } + equipmentInfo.setEquipmentStatus(Integer.valueOf(pileStatus)); + equipmentInfo.setEquipmentPower(new BigDecimal(modelInfo.getRatedPower()).setScale(1, BigDecimal.ROUND_HALF_UP)); + equipmentInfo.setNewNationalStandard(1); + equipmentInfo.setVinFlag(1); + + List connectorList = getConnectorList(pileBasicInfo); + equipmentInfo.setConnectorInfos(connectorList); + + resultList.add(equipmentInfo); + } + return resultList; + } + + + /** + * 获取枪口列表 + * + * @param pileBasicInfo + * @return + */ + private List getConnectorList(PileBasicInfo pileBasicInfo) { + List resultList = new ArrayList<>(); + + List list = pileConnectorInfoService.selectPileConnectorInfoList(pileBasicInfo.getSn()); + for (PileConnectorInfo pileConnectorInfo : list) { + ConnectorInfo connectorInfo = new ConnectorInfo(); + + connectorInfo.setConnectorID(pileConnectorInfo.getPileConnectorCode()); + String pileSn = pileConnectorInfo.getPileSn(); + PileModelInfoVO modelInfo = pileModelInfoService.getPileModelInfoByPileSn(pileSn); + int connectorType = StringUtils.equals("1", modelInfo.getSpeedType()) ? 4 : 3; + + connectorInfo.setConnectorType(connectorType); + connectorInfo.setVoltageUpperLimits(Integer.valueOf(modelInfo.getRatedVoltage())); + connectorInfo.setVoltageLowerLimits(Integer.valueOf(modelInfo.getRatedVoltage())); + connectorInfo.setCurrent(Integer.valueOf(modelInfo.getRatedCurrent())); + connectorInfo.setPower(new BigDecimal(modelInfo.getRatedPower()).setScale(1, BigDecimal.ROUND_HALF_UP)); + + resultList.add(connectorInfo); + } + + return resultList; + } } diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/vo/AccessTokenVO.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/vo/AccessTokenVO.java new file mode 100644 index 000000000..0cf6ff566 --- /dev/null +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/vo/AccessTokenVO.java @@ -0,0 +1,44 @@ +package com.jsowell.thirdparty.lianlian.vo; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class AccessTokenVO { + /** + * 字符串 对接平台组织机构代码 + */ + @JsonProperty(value = "OperatorID") + private String operatorID; + + /** + * 整型 + * 0:成功; + * 1:失败 + */ + @JsonProperty(value = "SuccStat") + private String succStat; + + /** + * 字符串 全局唯一凭证 + */ + @JsonProperty(value = "AccessToken") + private String accessToken; + + /** + * 整型 凭证有效期,单位秒 + */ + @JsonProperty(value = "TokenAvailableTime") + private String tokenAvailableTime; + + /** + * 整型 + * 0:无; + * 1:无此对接平台; + * 2:密钥错误; 3~99:自定义 + */ + @JsonProperty(value = "FailReason") + private String failReason; +}