diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/domain/nanrui/NROrderInfo.java b/jsowell-pile/src/main/java/com/jsowell/pile/domain/nanrui/JiangSuOrderInfo.java similarity index 98% rename from jsowell-pile/src/main/java/com/jsowell/pile/domain/nanrui/NROrderInfo.java rename to jsowell-pile/src/main/java/com/jsowell/pile/domain/nanrui/JiangSuOrderInfo.java index cbc8cc3b6..48ef4e7f6 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/domain/nanrui/NROrderInfo.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/domain/nanrui/JiangSuOrderInfo.java @@ -18,7 +18,7 @@ import java.math.BigDecimal; @AllArgsConstructor @NoArgsConstructor @Builder -public class NROrderInfo { +public class JiangSuOrderInfo { /** * 运营商 ID * 统一社会信用代码 diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/mapper/OrderBasicInfoMapper.java b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/OrderBasicInfoMapper.java index 4fad9a584..d4426e0bf 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/mapper/OrderBasicInfoMapper.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/OrderBasicInfoMapper.java @@ -8,7 +8,7 @@ import com.jsowell.pile.dto.ningxiajiaotou.NXJTQueryOrdersInfoDTO; import com.jsowell.pile.vo.SupStationStatsVO; import com.jsowell.pile.vo.base.MerchantOrderInfoVO; import com.jsowell.pile.vo.lianlian.AccumulativeInfoVO; -import com.jsowell.pile.vo.nanrui.NROrderInfoVO; +import com.jsowell.pile.vo.nanrui.JiangSuOrderInfoVO; import com.jsowell.pile.vo.uniapp.OrderVO; import com.jsowell.pile.vo.uniapp.PersonPileConnectorSumInfoVO; import com.jsowell.pile.vo.uniapp.SendMessageVO; @@ -319,7 +319,7 @@ public interface OrderBasicInfoMapper { * @param dto * @return */ - List getNROrderInfoByOrderCode(@Param("dto") NRQueryOrderDTO dto); + List getNROrderInfoByOrderCode(@Param("dto") NRQueryOrderDTO dto); List queryOrderPayDetail(@Param("startTime") String startTime, @Param("endTime") String endTime); diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/OrderBasicInfoService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/OrderBasicInfoService.java index 02b15459b..a779eb6cf 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/OrderBasicInfoService.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/OrderBasicInfoService.java @@ -17,7 +17,7 @@ import com.jsowell.pile.vo.base.MerchantOrderInfoVO; import com.jsowell.pile.vo.base.OrderAmountDetailVO; import com.jsowell.pile.vo.base.OrderPeriodAmountVO; import com.jsowell.pile.vo.lianlian.AccumulativeInfoVO; -import com.jsowell.pile.vo.nanrui.NROrderInfoVO; +import com.jsowell.pile.vo.nanrui.JiangSuOrderInfoVO; import com.jsowell.pile.vo.uniapp.OrderVO; import com.jsowell.pile.vo.uniapp.PersonPileConnectorSumInfoVO; import com.jsowell.pile.vo.uniapp.SendMessageVO; @@ -388,14 +388,14 @@ public interface OrderBasicInfoService{ * @param orderCode * @return */ - NROrderInfoVO getNROrderInfoByOrderCode(String orderCode); + JiangSuOrderInfoVO getNROrderInfoByOrderCode(String orderCode); /** * 通过充电结束时间批量查询 * @param dto * @return */ - List getNROrderInfos(NRQueryOrderDTO dto); + List getNROrderInfos(NRQueryOrderDTO dto); /** * 根据时间端范围查询订单支付单id diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/nanrui/NROrderInfoVO.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/nanrui/JiangSuOrderInfoVO.java similarity index 57% rename from jsowell-pile/src/main/java/com/jsowell/pile/vo/nanrui/NROrderInfoVO.java rename to jsowell-pile/src/main/java/com/jsowell/pile/vo/nanrui/JiangSuOrderInfoVO.java index be65332f9..526056654 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/vo/nanrui/NROrderInfoVO.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/nanrui/JiangSuOrderInfoVO.java @@ -1,6 +1,6 @@ package com.jsowell.pile.vo.nanrui; -import com.jsowell.pile.domain.nanrui.NROrderInfo; +import com.jsowell.pile.domain.nanrui.JiangSuOrderInfo; import lombok.Data; /** @@ -10,6 +10,6 @@ import lombok.Data; * @Date 2023/10/12 15:57 */ @Data -public class NROrderInfoVO extends NROrderInfo { +public class JiangSuOrderInfoVO extends JiangSuOrderInfo { private String stationId; } diff --git a/jsowell-pile/src/main/resources/mapper/pile/OrderBasicInfoMapper.xml b/jsowell-pile/src/main/resources/mapper/pile/OrderBasicInfoMapper.xml index fa76185e4..c5167b05f 100644 --- a/jsowell-pile/src/main/resources/mapper/pile/OrderBasicInfoMapper.xml +++ b/jsowell-pile/src/main/resources/mapper/pile/OrderBasicInfoMapper.xml @@ -2738,7 +2738,7 @@ station_id = #{stationId,jdbcType=BIGINT} - SELECT t1.station_id as stationId, t1.merchant_id, diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/common/CommonService.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/common/CommonService.java index eee4009b1..ca0aa317d 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/common/CommonService.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/common/CommonService.java @@ -705,7 +705,7 @@ public class CommonService { * @param putGunType 是否插枪 * @return 第三方平台枪口状态 */ - private String changeConnectorStatus(String connectorStatus, String putGunType) { + public String changeConnectorStatus(String connectorStatus, String putGunType) { if (StringUtils.equals(connectorStatus, PileConnectorStatusEnum.FREE.getValue())) { // 空闲 return Constants.ONE; diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/nanrui/service/impl/NRServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/nanrui/service/impl/NRServiceImpl.java index b0a9c669e..f8673613a 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/nanrui/service/impl/NRServiceImpl.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/nanrui/service/impl/NRServiceImpl.java @@ -16,7 +16,7 @@ import com.jsowell.common.util.DateUtils; import com.jsowell.common.util.PageUtils; import com.jsowell.common.util.StringUtils; import com.jsowell.pile.domain.*; -import com.jsowell.pile.domain.nanrui.NROrderInfo; +import com.jsowell.pile.domain.nanrui.JiangSuOrderInfo; import com.jsowell.pile.dto.PushStationInfoDTO; import com.jsowell.pile.dto.QueryConnectorListDTO; import com.jsowell.pile.dto.QueryStationInfoDTO; @@ -26,7 +26,7 @@ import com.jsowell.pile.service.*; import com.jsowell.pile.vo.base.MerchantInfoVO; import com.jsowell.pile.vo.base.ThirdPartyStationInfoVO; import com.jsowell.pile.vo.base.ThirdPartyStationRelationVO; -import com.jsowell.pile.vo.nanrui.NROrderInfoVO; +import com.jsowell.pile.vo.nanrui.JiangSuOrderInfoVO; import com.jsowell.pile.vo.uniapp.CurrentTimePriceDetails; import com.jsowell.pile.vo.web.PileConnectorInfoVO; import com.jsowell.pile.vo.web.PileModelInfoVO; @@ -537,11 +537,6 @@ public class NRServiceImpl implements NRService { String url = urlAddress + BusinessInformationExchangeEnum.NOTIFICATION_STATION_STATUS.getValue(); - // 获取令牌 - String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret); - if (StringUtils.isBlank(token)) { - return null; - } Date chargeStartTime = new Date(); if (StringUtils.equals(connectorStatus, "03")) { // 根据交易流水号查询订单信息 @@ -571,6 +566,11 @@ public class NRServiceImpl implements NRService { json.put("ConnectorStatusInfo", nrConnectorStatusInfo); String jsonString = JSON.toJSONString(json); + // 获取令牌 + String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret); + if (StringUtils.isBlank(token)) { + return null; + } String result = HttpRequestUtil.nrSendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret); return result; } @@ -672,12 +672,12 @@ public class NRServiceImpl implements NRService { @Override public String pushOrderInfo(String orderCode) { // 根据订单号查询订单信息 - NROrderInfoVO nrOrderInfoVO = orderBasicInfoService.getNROrderInfoByOrderCode(orderCode); - NROrderInfo nrOrderInfo = formatNROrderInfo((nrOrderInfoVO)); + JiangSuOrderInfoVO nrOrderInfoVO = orderBasicInfoService.getNROrderInfoByOrderCode(orderCode); + JiangSuOrderInfo jiangSuOrderInfo = formatNROrderInfo((nrOrderInfoVO)); // 通过三方平台类型查询相关配置信息 ThirdPartyStationRelation relation = new ThirdPartyStationRelation(); - relation.setThirdPartyType(nrOrderInfo.getThirdPartyType()); + relation.setThirdPartyType(jiangSuOrderInfo.getThirdPartyType()); ThirdPartyStationRelationVO relationInfo = thirdPartyStationRelationService.selectRelationInfo(relation); if (relationInfo == null) { return null; @@ -699,7 +699,7 @@ public class NRServiceImpl implements NRService { // 发送请求 JSONObject jsonObject = new JSONObject(); - jsonObject.put("OrderInfo", nrOrderInfo); + jsonObject.put("OrderInfo", jiangSuOrderInfo); String jsonString = JSON.toJSONString(jsonObject); @@ -715,18 +715,18 @@ public class NRServiceImpl implements NRService { */ @Override public Map query_order_info(NRQueryOrderDTO dto) { - List resultList = new ArrayList<>(); + List resultList = new ArrayList<>(); ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); if (configInfo == null) { return null; } - List nrOrderInfos = orderBasicInfoService.getNROrderInfos(dto); + List nrOrderInfos = orderBasicInfoService.getNROrderInfos(dto); if (CollectionUtils.isEmpty(nrOrderInfos)) { return Maps.newLinkedHashMap(); } - for (NROrderInfoVO nrOrderInfoVO : nrOrderInfos) { - NROrderInfo nrOrderInfo = formatNROrderInfo(nrOrderInfoVO); - resultList.add(nrOrderInfo); + for (JiangSuOrderInfoVO nrOrderInfoVO : nrOrderInfos) { + JiangSuOrderInfo jiangSuOrderInfo = formatNROrderInfo(nrOrderInfoVO); + resultList.add(jiangSuOrderInfo); } // 加密 Map resultMap = Maps.newLinkedHashMap(); @@ -748,7 +748,7 @@ public class NRServiceImpl implements NRService { * @param nrOrderInfoVO * @return */ - private NROrderInfo formatNROrderInfo(NROrderInfoVO nrOrderInfoVO) { + private JiangSuOrderInfo formatNROrderInfo(JiangSuOrderInfoVO nrOrderInfoVO) { // 将组织机构代码截取后九位 // String organizationCode = nrOrderInfoVO.getOperatorId(); // if (StringUtils.isBlank(organizationCode)) { @@ -756,7 +756,7 @@ public class NRServiceImpl implements NRService { // } // String operatorId = StringUtils.substring(organizationCode, organizationCode.length() - 9); - NROrderInfo nrOrderInfo = NROrderInfo.builder() + JiangSuOrderInfo jiangSuOrderInfo = JiangSuOrderInfo.builder() .operatorId(Constants.OPERATORID_JIANG_SU) .connectorId(nrOrderInfoVO.getConnectorId()) .startChargeSeq(nrOrderInfoVO.getStartChargeSeq()) @@ -773,9 +773,9 @@ public class NRServiceImpl implements NRService { // TODO 获取电表总起、止值 // pileMsgRecordService.getPileFeedList() - nrOrderInfo.setMeterValueStart(BigDecimal.ZERO); - nrOrderInfo.setMeterValueEnd(BigDecimal.ZERO); - return nrOrderInfo; + jiangSuOrderInfo.setMeterValueStart(BigDecimal.ZERO); + jiangSuOrderInfo.setMeterValueEnd(BigDecimal.ZERO); + return jiangSuOrderInfo; } public static void main(String[] args) { diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/dto/QueryOrderDTO.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/dto/QueryOrderDTO.java new file mode 100644 index 000000000..c2ee0c7a9 --- /dev/null +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/dto/QueryOrderDTO.java @@ -0,0 +1,29 @@ +package com.jsowell.thirdparty.platform.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +/** + * 查询订单信息DTO + * + * @author Lemon + * @Date 2024/7/9 13:57:44 + */ +@Data +public class QueryOrderDTO { + private String operatorId; + + private String orderCode; + + /** + * yyyy-MM-dd HH:mm:ss 格式,必填,以充电结束时间为准 + */ + @JsonProperty(value = "QueryStartTime") + private String queryStartTime; + + /** + * yyyy-MM-dd HH:mm:ss 格式,必填,以充电结束时间为准 + */ + @JsonProperty(value = "QueryEndTime") + private String queryEndTime; +} diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/ThirdPartyPlatformService.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/ThirdPartyPlatformService.java index 377a4479c..d93c5e056 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/ThirdPartyPlatformService.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/ThirdPartyPlatformService.java @@ -4,15 +4,18 @@ import cn.hutool.http.HttpUtil; import cn.hutool.json.JSONUtil; import com.alibaba.fastjson2.JSON; import com.google.common.collect.Maps; +import com.jsowell.common.core.domain.ykc.RealTimeMonitorData; import com.jsowell.common.util.DateUtils; import com.jsowell.common.util.JWTUtils; import com.jsowell.common.util.StringUtils; import com.jsowell.pile.dto.*; +import com.jsowell.pile.dto.nanrui.PushAlarmInfoDTO; import com.jsowell.pile.dto.ningxiajiaotou.NXJTQueryStationInfoDTO; import com.jsowell.pile.thirdparty.CommonParamsDTO; import com.jsowell.pile.vo.ThirdPartySecretInfoVO; import com.jsowell.thirdparty.lianlian.vo.AccessTokenVO; import com.jsowell.thirdparty.lianlian.vo.LianLianResultVO; +import com.jsowell.thirdparty.platform.dto.QueryOrderDTO; import com.jsowell.thirdparty.platform.util.Cryptos; import com.jsowell.thirdparty.platform.util.Encodes; import com.jsowell.thirdparty.platform.util.GBSignUtils; @@ -99,7 +102,7 @@ public interface ThirdPartyPlatformService extends InitializingBean { * * @throws UnsupportedOperationException 未实现异常 */ - default Map queryOrderInfo(String orderCode) { + default Map queryOrderInfo(QueryOrderDTO dto) { throw new UnsupportedOperationException("This method is not yet implemented"); } @@ -311,7 +314,7 @@ public interface ThirdPartyPlatformService extends InitializingBean { * * @throws UnsupportedOperationException 未实现异常 */ - default String notificationAlarmInfo() { + default String notificationAlarmInfo(PushAlarmInfoDTO dto) { throw new UnsupportedOperationException("This method is not yet implemented"); } diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/JiangSuPlatformServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/JiangSuPlatformServiceImpl.java new file mode 100644 index 000000000..070e608fe --- /dev/null +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/JiangSuPlatformServiceImpl.java @@ -0,0 +1,684 @@ +package com.jsowell.thirdparty.platform.service.impl; + +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.CacheConstants; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.core.domain.ykc.RealTimeMonitorData; +import com.jsowell.common.core.redis.RedisCache; +import com.jsowell.common.enums.thirdparty.BusinessInformationExchangeEnum; +import com.jsowell.common.enums.thirdparty.JiangSuConstructionEnum; +import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum; +import com.jsowell.common.enums.ykc.PileStatusEnum; +import com.jsowell.common.enums.ykc.ReturnCodeEnum; +import com.jsowell.common.exception.BusinessException; +import com.jsowell.common.util.DateUtils; +import com.jsowell.common.util.PageUtils; +import com.jsowell.common.util.StringUtils; +import com.jsowell.pile.domain.*; +import com.jsowell.pile.domain.nanrui.JiangSuOrderInfo; +import com.jsowell.pile.dto.*; +import com.jsowell.pile.dto.nanrui.NRQueryOrderDTO; +import com.jsowell.pile.dto.nanrui.PushAlarmInfoDTO; +import com.jsowell.pile.service.*; +import com.jsowell.pile.vo.ThirdPartySecretInfoVO; +import com.jsowell.pile.vo.base.MerchantInfoVO; +import com.jsowell.pile.vo.base.ThirdPartyStationInfoVO; +import com.jsowell.pile.vo.nanrui.JiangSuOrderInfoVO; +import com.jsowell.pile.vo.uniapp.CurrentTimePriceDetails; +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.common.CommonService; +import com.jsowell.thirdparty.nanrui.domain.*; +import com.jsowell.thirdparty.platform.dto.QueryOrderDTO; +import com.jsowell.thirdparty.platform.factory.ThirdPartyPlatformFactory; +import com.jsowell.thirdparty.platform.service.ThirdPartyPlatformService; +import com.jsowell.thirdparty.platform.util.*; +import com.jsowell.thirdparty.service.ThirdpartySecretInfoService; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.util.*; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; + +/** + * 江苏省平台(原南瑞平台) + * + * @author Lemon + * @Date 2024/7/8 10:35:16 + */ +@Service +public class JiangSuPlatformServiceImpl implements ThirdPartyPlatformService { + + @Autowired + private CommonService commonService; + + @Autowired + private PileStationInfoService pileStationInfoService; + + @Autowired + private ThirdpartySecretInfoService thirdpartySecretInfoService; + + @Autowired + private PileBasicInfoService pileBasicInfoService; + + @Autowired + private PileModelInfoService pileModelInfoService; + + @Autowired + private PileConnectorInfoService pileConnectorInfoService; + + @Autowired + private PileMerchantInfoService pileMerchantInfoService; + + @Autowired + private PileBillingTemplateService pileBillingTemplateService; + + @Autowired + private OrderBasicInfoService orderBasicInfoService; + + @Autowired + private RedisCache redisCache; + + // 平台类型 + private final String thirdPlatformType = ThirdPlatformTypeEnum.JIANG_SU_PLATFORM.getTypeCode(); + + @Override + public void afterPropertiesSet() throws Exception { + ThirdPartyPlatformFactory.register(thirdPlatformType, this); + } + + @Override + public String notificationStationInfo(String stationId) { + PileStationVO stationInfoVO = pileStationInfoService.getStationInfo(stationId); + if (stationInfoVO == null) { + return null; + } + ThirdPartySecretInfoVO jiangSuSecretInfo = getJiangSuSecretInfo(); + + String operatorId = jiangSuSecretInfo.getOurOperatorId(); + String operatorSecret = jiangSuSecretInfo.getTheirOperatorSecret(); + String signSecret = jiangSuSecretInfo.getTheirSigSecret(); + String dataSecret = jiangSuSecretInfo.getTheirDataSecret(); + String dataSecretIv = jiangSuSecretInfo.getTheirDataSecretIv(); + String urlAddress = jiangSuSecretInfo.getTheirUrlPrefix(); + + // 拼装江苏平台所需参数 + NRStationInfo nrStationInfo = NRStationInfo.builder() + .stationId(String.valueOf(stationInfoVO.getId())) + .operatorID(Constants.OPERATORID_JIANG_SU) + // .equipmentOwnerID(Constants.OPERATORID_JIANG_SU) + .stationName(stationInfoVO.getStationName()) + .countryCode(stationInfoVO.getCountryCode()) + // .areaCode() + .address(stationInfoVO.getAddress()) + .serviceTel(stationInfoVO.getStationTel()) + .stationStatus(stationInfoVO.getStationStatus()) + .parkNums(0) + .stationLng(new BigDecimal(stationInfoVO.getStationLng()).setScale(6, BigDecimal.ROUND_HALF_UP)) + .stationLat(new BigDecimal(stationInfoVO.getStationLat()).setScale(6, BigDecimal.ROUND_HALF_UP)) + .openForBusinessDate(DateUtils.convertDateTimeToDate(stationInfoVO.getCreateTime())) + .openAllDay(Integer.parseInt(stationInfoVO.getOpenAllDay())) + .busineHours(stationInfoVO.getBusinessHours()) + .minElectricityPrice(stationInfoVO.getElectricityPrice().add(stationInfoVO.getServicePrice())) + .loungeFlag(0) + .isAloneApply(0) + .printerFlag(0) + .parkFree(0) + .isPublicParkingLot(0) + .payment(1) + .restaurantFlag(0) + .barrierFlag(0) + .serviceFee(stationInfoVO.getServicePrice()) + .parkingLockFlag(0) + .electricityFee(stationInfoVO.getElectricityPrice()) + .storeFlag(0) + .canopyFlag(0) + .toiletFlag(0) + .supportOrder(0) + .parkFeeType(1) + + .build(); + // 截取运营商组织机构代码(去除最后一位后的最后九位) + MerchantInfoVO merchantInfo = pileMerchantInfoService.getMerchantInfoVO(String.valueOf(stationInfoVO.getMerchantId())); + String organizationCode = merchantInfo.getOrganizationCode(); + if (StringUtils.isNotBlank(organizationCode) && organizationCode.length() == 18) { + String equipmentOwnerId = StringUtils.substring(organizationCode, organizationCode.length() - 10, organizationCode.length() - 1); + nrStationInfo.setEquipmentOwnerID(equipmentOwnerId); + } + // 站点地址 + String areaCode = stationInfoVO.getAreaCode(); + // 截取最后一组数据,例如将 320000,320500,320583 截取为 320583 + String[] split = StringUtils.split(areaCode, ","); + String s = split[split.length - 1]; + nrStationInfo.setAreaCode(s); + // 站点图片 + if (CollectionUtils.isNotEmpty(stationInfoVO.getPictureList())) { + nrStationInfo.setPictures(stationInfoVO.getPictureList()); + } + String stationType = stationInfoVO.getStationType(); + if (!StringUtils.equals("1", stationType) && !StringUtils.equals("255", stationType)) { + // 不为1-公共并且不为255-其他,都为专用 + stationType = "2"; + } + nrStationInfo.setStationType(Integer.parseInt(stationType)); + // 获取建设场所 + int jsConstructionCode = JiangSuConstructionEnum.getJSCodeByDataBaseCode(Integer.parseInt(stationInfoVO.getConstruction())); + nrStationInfo.setConstruction(jsConstructionCode); + + List nrEquipmentInfos = getEquipmentInfo(stationId); + nrStationInfo.setEquipmentInfos(nrEquipmentInfos); + + // 推送到平台 + String url = urlAddress + "notification_stationInfo"; + + JSONObject data = new JSONObject(); + data.put("StationInfo", nrStationInfo); + + String jsonString = data.toString(); + System.out.println("jsonString : " + jsonString); + + // 获取令牌 + String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret); + System.out.println(token); + String result = HttpRequestUtil.nrSendPost(token, jsonString, url, dataSecret + , dataSecretIv, operatorId, signSecret); + + // 新增数据库 + PushStationInfoDTO dto = new PushStationInfoDTO(); + dto.setThirdPartyType(thirdPlatformType); + dto.setStationId(Long.parseLong(stationId)); + + commonService.insertInfo2DataBase(dto); + return thirdPlatformType + ":" + result; + } + + + /** + * 获取充电站信息 + * @param dto + * @return + */ + @Override + public Map queryStationsInfo(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.getStationInfosByThirdParty(dto); + if (CollectionUtils.isEmpty(stationInfos)) { + // 未查到数据 + return null; + } + ThirdPartySecretInfoVO jiangSuSecretInfo = getJiangSuSecretInfo(); + + PageInfo pageInfo = new PageInfo<>(stationInfos); + for (ThirdPartyStationInfoVO pileStationInfo : pageInfo.getList()) { + // 拼装参数 + NRStationInfo nrStationInfo = NRStationInfo.builder() + .stationId(String.valueOf(pileStationInfo.getId())) + .operatorID(Constants.OPERATORID_JIANG_SU) + .equipmentOwnerID(Constants.OPERATORID_JIANG_SU) + .stationName(pileStationInfo.getStationName()) + .countryCode(pileStationInfo.getCountryCode()) + .areaCode(pileStationInfo.getAreaCode()) + .address(pileStationInfo.getAddress()) + .serviceTel(pileStationInfo.getStationTel()) + .stationStatus(Integer.parseInt(pileStationInfo.getStationStatus())) + .parkNums(0) + .stationLng(new BigDecimal(pileStationInfo.getStationLng()).setScale(6, BigDecimal.ROUND_HALF_UP)) + .stationLat(new BigDecimal(pileStationInfo.getStationLat()).setScale(6, BigDecimal.ROUND_HALF_UP)) + .openForBusinessDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, pileStationInfo.getCreateTime())) + .openAllDay(Integer.parseInt(pileStationInfo.getOpenAllDay())) + .busineHours(pileStationInfo.getBusinessHours()) + .build(); + // 站点费率 + // 查计费模板 + CurrentTimePriceDetails currentTimePriceDetails = pileBillingTemplateService.getCurrentTimePriceDetails(String.valueOf(pileStationInfo.getId())); + if (currentTimePriceDetails == null) { + // 未设置计费模板 + continue; + } + String electricityPrice = currentTimePriceDetails.getElectricityPrice(); + electricityPrice = StringUtils.isBlank(electricityPrice) ? "0" : electricityPrice; + + String servicePrice = currentTimePriceDetails.getServicePrice(); + servicePrice = StringUtils.isBlank(servicePrice) ? "0" : servicePrice; + + BigDecimal price = new BigDecimal(electricityPrice).add(new BigDecimal(servicePrice)); + nrStationInfo.setMinElectricityPrice(price); + + // 站点图片 + if (StringUtils.isNotBlank(pileStationInfo.getPictures())) { + nrStationInfo.setPictures(Lists.newArrayList(pileStationInfo.getPictures().split(","))); + } + // 站点类型 + String stationType = pileStationInfo.getStationType(); + if (!StringUtils.equals("1", stationType) && !StringUtils.equals("255", stationType)) { + // 不为1-公共并且不为255-其他,都为专用 + stationType = "2"; + } + nrStationInfo.setStationType(Integer.parseInt(stationType)); + nrStationInfo.setConstruction(255); + + List nrEquipmentInfos = getEquipmentInfo(String.valueOf(pileStationInfo.getId())); + nrStationInfo.setEquipmentInfos(nrEquipmentInfos); + + resultList.add(nrStationInfo); + } + Map map = new LinkedHashMap<>(); + map.put("PageNo", pageInfo.getPageNum()); + map.put("PageCount", pageInfo.getPages()); + map.put("ItemSize", resultList.size()); + map.put("StationInfos", resultList); + + Map resultMap = ThirdPartyPlatformUtils.generateResultMap(map, jiangSuSecretInfo); + return resultMap; + } + + @Override + public String notificationAlarmInfo(PushAlarmInfoDTO dto) { + List nrAlarmInfos = new ArrayList<>(); + + ThirdPartySecretInfoVO jiangSuSecretInfo = getJiangSuSecretInfo(); + + String operatorId = jiangSuSecretInfo.getOurOperatorId(); + String operatorSecret = jiangSuSecretInfo.getTheirOperatorSecret(); + String signSecret = jiangSuSecretInfo.getTheirSigSecret(); + String dataSecret = jiangSuSecretInfo.getTheirDataSecret(); + String dataSecretIv = jiangSuSecretInfo.getTheirDataSecretIv(); + String urlAddress = jiangSuSecretInfo.getTheirUrlPrefix(); + + // 从缓存中获取故障原因 + String redisKey = CacheConstants.PILE_HARDWARE_FAULT + dto.getPileConnectorCode(); + String faultReason = redisCache.getCacheObject(redisKey); + int status = 0; + if (StringUtils.equals(dto.getConnectorStatus(), "01")) { + // 故障 + status = 1; + } + // 封装对象 + NRAlarmInfo alarmInfo = NRAlarmInfo.builder() + .connectorId(dto.getPileConnectorCode()) + .alertTime(DateUtils.dateTimeNow(DateUtils.YYYY_MM_DD_HH_MM_SS)) + .alertCode(120) // 120-预留 + .describe(faultReason) + .status(status) + + .build(); + nrAlarmInfos.add(alarmInfo); + + // 发送请求 + String url = urlAddress + "notification_alarmInfo"; + + JSONObject data = new JSONObject(); + data.put("AlarmInfos", nrAlarmInfos); + + String jsonString = JSON.toJSONString(data); + System.out.println("jsonString : " + jsonString); + + // 获取令牌 + String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret); + String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret); + return result; + } + + /** + * 推送站点信息状态 + * @param stationId 站点id + * @param pileConnectorCode 枪口号 + * @param status 枪口状态 + * @param secretInfoVO 第三方平台对应密钥 + * @return + */ + @Override + public String notificationStationStatus(String stationId, String pileConnectorCode, String status, ThirdPartySecretInfoVO secretInfoVO) { + // 查询枪口信息 + PileConnectorInfoVO connectorInfo = pileConnectorInfoService.getPileConnectorInfoByConnectorCode(pileConnectorCode); + if (Objects.isNull(connectorInfo)) { + throw new BusinessException(ReturnCodeEnum.CODE_CONNECTOR_INFO_NULL_ERROR); + } + + // 查询相关配置信息 + ThirdPartySecretInfoVO jiangSuSecretInfo = getJiangSuSecretInfo(); + + String operatorId = jiangSuSecretInfo.getOurOperatorId(); + String operatorSecret = jiangSuSecretInfo.getTheirOperatorSecret(); + String signSecret = jiangSuSecretInfo.getTheirSigSecret(); + String dataSecret = jiangSuSecretInfo.getTheirDataSecret(); + String dataSecretIv = jiangSuSecretInfo.getTheirDataSecretIv(); + String urlAddress = jiangSuSecretInfo.getTheirUrlPrefix(); + + String url = urlAddress + BusinessInformationExchangeEnum.NOTIFICATION_STATION_STATUS.getValue(); + + Date chargeStartTime = new Date(); + RealTimeMonitorData realTimeMonitorData = null; + if (StringUtils.equals(status, "03")) { + // 查询充电中的订单信息 + OrderBasicInfo orderBasicInfo = orderBasicInfoService.queryChargingByPileConnectorCode(pileConnectorCode); + if (orderBasicInfo == null) { + return null; + } + chargeStartTime = orderBasicInfo.getChargeStartTime(); + // 查询实时数据缓存 + String redisKey = CacheConstants.PILE_REAL_TIME_MONITOR_DATA + pileConnectorCode + "_" + orderBasicInfo.getTransactionCode(); + realTimeMonitorData = redisCache.getCacheObject(redisKey); + } + if (realTimeMonitorData == null) { + return null; + } + // 封装对象 + NRConnectorStatusInfo nrConnectorStatusInfo = NRConnectorStatusInfo.builder() + .connectorID(pileConnectorCode) + .status(Integer.parseInt(status)) + .currentA(new BigDecimal(realTimeMonitorData.getOutputCurrent()).intValue()) + .voltageA(new BigDecimal(realTimeMonitorData.getOutputVoltage()).intValue()) + .soc(BigDecimal.ZERO) + .beginTime(DateUtils.formatDateTime(chargeStartTime)) + .currentKwh(new BigDecimal(realTimeMonitorData.getChargingDegree()).setScale(3, BigDecimal.ROUND_HALF_UP)) + .timeStamp((int) (System.currentTimeMillis() / 1000)) + + .build(); + if (StringUtils.isNotBlank(realTimeMonitorData.getSOC())) { + nrConnectorStatusInfo.setSoc(new BigDecimal(realTimeMonitorData.getSOC()).setScale(1, BigDecimal.ROUND_HALF_UP)); + } + + // 发送请求 + JSONObject json = new JSONObject(); + json.put("ConnectorStatusInfo", nrConnectorStatusInfo); + String jsonString = JSON.toJSONString(json); + + // 获取令牌 + String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret); + String result = ""; + // 江苏省平台(充电状态至少一分钟推送一次) + if (StringUtils.equals(status, "03")) { + // 充电状态 + String redisKey = CacheConstants.JIANGSU_PUSH_PILE_STATUS + pileConnectorCode; + Object cacheObject = redisCache.getCacheObject(redisKey); + // 如果缓存有数据,证明上次推送未超过一分钟,不予推送,若缓存中无数据,说明需要推送 + if (cacheObject == null) { + result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret); + // 存缓存 + redisCache.setCacheObject(redisKey, nrConnectorStatusInfo, 1, TimeUnit.MINUTES); + } + } else { + // 如果不是充电状态,直接推送就可以 + result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret); + } + return result; + } + + /** + * 查询设备接口状态 + * 此接口用于批量查询设备实时状态 + * 由充电运营商方实现此接口,省、市两级监管平台调用。 + * @param dto + * @return + */ + @Override + public Map queryStationStatus(QueryStationInfoDTO dto) { + List stationIds = dto.getStationIds(); + List resultList = new ArrayList<>(); + + ThirdPartySecretInfoVO jiangSuSecretInfo = getJiangSuSecretInfo(); + + // 将 stationIdList 转换成 List + List stationLongList = stationIds.stream() + .map(Long::parseLong) + .collect(Collectors.toList()); + + QueryConnectorListDTO queryConnectorListDTO = QueryConnectorListDTO.builder() + .stationIdList(stationLongList) + .build(); + List connectorInfoVOS = pileConnectorInfoService.getConnectorInfoListByParams(queryConnectorListDTO); + if (CollectionUtils.isEmpty(connectorInfoVOS)) { + return new LinkedHashMap<>(); + } + // 根据stationId分组 + Map> collect = connectorInfoVOS.stream() + .collect(Collectors.groupingBy(PileConnectorInfoVO::getStationId)); + // 遍历 map + for (Map.Entry> entry : collect.entrySet()) { + String stationId = entry.getKey(); + List connectorList = entry.getValue(); + List connectorStatusInfoList = new ArrayList<>(); + + for (PileConnectorInfoVO connectorInfoVO : connectorList) { + NRConnectorStatusInfo nrConnectorStatusInfo = NRConnectorStatusInfo.builder() + .connectorID(connectorInfoVO.getPileConnectorCode()) + .status(connectorInfoVO.getStatus()) + .currentA(0) + .voltageA(0) + .soc(BigDecimal.ZERO) + .beginTime(null) + .currentKwh(BigDecimal.ZERO) + .timeStamp((int) (System.currentTimeMillis() / 1000)) + + .build(); + if (StringUtils.equals(String.valueOf(connectorInfoVO.getStatus()), "3")) { + // 充电中 + nrConnectorStatusInfo.setCurrentA(connectorInfoVO.getCurrent().intValue()); + nrConnectorStatusInfo.setVoltageA(connectorInfoVO.getVoltage().intValue()); + nrConnectorStatusInfo.setSoc(new BigDecimal(connectorInfoVO.getSOC())); + String chargingTime = connectorInfoVO.getChargingTime(); + Date beginTime = DateUtils.addMinute(new Date(), -Integer.parseInt(chargingTime)); + nrConnectorStatusInfo.setBeginTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, beginTime)); + } + if (StringUtils.equals(String.valueOf(connectorInfoVO.getStatus()), "255")) { + // 故障 + nrConnectorStatusInfo.setStatus(255); + } + connectorStatusInfoList.add(nrConnectorStatusInfo); + } + // 封装参数 + NRStationStatusInfo stationStatusInfo = NRStationStatusInfo.builder() + .stationId(stationId) + .connectorStatusInfos(connectorStatusInfoList) + .build(); + resultList.add(stationStatusInfo); + } + Map map = new LinkedHashMap<>(); + map.put("StationStatusInfos", resultList); + + Map resultMap = ThirdPartyPlatformUtils.generateResultMap(map, jiangSuSecretInfo); + return resultMap; + } + + /** + * 推送订单信息 + * @param orderCode + * @param secretInfoVO + * @return + */ + @Override + public String notificationChargeOrderInfo(String orderCode, ThirdPartySecretInfoVO secretInfoVO) { + // 根据订单号查询订单信息 + JiangSuOrderInfoVO nrOrderInfoVO = orderBasicInfoService.getNROrderInfoByOrderCode(orderCode); + JiangSuOrderInfo jiangSuOrderInfo = formatJiangSuOrderInfo(nrOrderInfoVO); + + ThirdPartySecretInfoVO jiangSuSecretInfo = getJiangSuSecretInfo(); + + String operatorId = jiangSuSecretInfo.getOurOperatorId(); + String operatorSecret = jiangSuSecretInfo.getTheirOperatorSecret(); + String signSecret = jiangSuSecretInfo.getTheirSigSecret(); + String dataSecret = jiangSuSecretInfo.getTheirDataSecret(); + String dataSecretIv = jiangSuSecretInfo.getTheirDataSecretIv(); + String urlAddress = jiangSuSecretInfo.getTheirUrlPrefix(); + + String url = urlAddress + "notification_orderInfo"; + + // 获取令牌 + String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret); + if (StringUtils.isBlank(token)) { + return null; + } + + // 发送请求 + JSONObject jsonObject = new JSONObject(); + jsonObject.put("OrderInfo", jiangSuOrderInfo); + + String jsonString = JSON.toJSONString(jsonObject); + + String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret); + return result; + } + + /** + * 查询充电电量信息 + * 此接口用于批量查询时间区段内交易记录 + * @param dto + * @return + */ + @Override + public Map queryOrderInfo(QueryOrderDTO dto) { + List resultList = new ArrayList<>(); + ThirdPartySecretInfoVO jiangSuSecretInfo = getJiangSuSecretInfo(); + NRQueryOrderDTO queryOrderDTO = new NRQueryOrderDTO(); + queryOrderDTO.setOrderCode(dto.getOrderCode()); + queryOrderDTO.setQueryStartTime(dto.getQueryStartTime()); + queryOrderDTO.setQueryEndTime(dto.getQueryEndTime()); + List nrOrderInfos = orderBasicInfoService.getNROrderInfos(queryOrderDTO); + if (CollectionUtils.isEmpty(nrOrderInfos)) { + return Maps.newLinkedHashMap(); + } + for (JiangSuOrderInfoVO nrOrderInfoVO : nrOrderInfos) { + JiangSuOrderInfo jiangSuOrderInfo = formatJiangSuOrderInfo(nrOrderInfoVO); + resultList.add(jiangSuOrderInfo); + } + + Map resultMap = ThirdPartyPlatformUtils.generateResultMap(JSONObject.toJSONString(resultList), jiangSuSecretInfo); + return resultMap; + } + + /** + * 格式化江苏平台订单对象 + * @param nrOrderInfoVO + * @return + */ + private JiangSuOrderInfo formatJiangSuOrderInfo(JiangSuOrderInfoVO nrOrderInfoVO) { + JiangSuOrderInfo jiangSuOrderInfo = JiangSuOrderInfo.builder() + .operatorId(Constants.OPERATORID_JIANG_SU) + .connectorId(nrOrderInfoVO.getConnectorId()) + .startChargeSeq(nrOrderInfoVO.getStartChargeSeq()) + .userChargeType(1) + .elect(nrOrderInfoVO.getElect()) + .cuspElect(nrOrderInfoVO.getCuspElect()) + .peakElect(nrOrderInfoVO.getPeakElect()) + .flatElect(nrOrderInfoVO.getFlatElect()) + .valleyElect(nrOrderInfoVO.getValleyElect()) + .startTime(nrOrderInfoVO.getStartTime()) + .endTime(nrOrderInfoVO.getEndTime()) + + .build(); + // TODO 获取电表总起、止值 + // pileMsgRecordService.getPileFeedList() + + jiangSuOrderInfo.setMeterValueStart(BigDecimal.ZERO); + jiangSuOrderInfo.setMeterValueEnd(BigDecimal.ZERO); + return jiangSuOrderInfo; + } + + + /** + * 获取设备信息 + * @param stationId + * @return + */ + private List getEquipmentInfo(String stationId) { + List resultList = new ArrayList<>(); + List list = pileBasicInfoService.getPileListByStationId(stationId); + if (CollectionUtils.isEmpty(list)) { + return resultList; + } + // 封装成江苏平台对象 + for (PileBasicInfo pileBasicInfo : list) { + String pileSn = pileBasicInfo.getSn(); + // 获取桩状态 + Map pileStatusMap = pileConnectorInfoService.getPileStatus(Lists.newArrayList(pileSn)); + String pileStatus = pileStatusMap.get(pileSn); + if (StringUtils.equals(PileStatusEnum.ON_LINE.getValue(), pileStatus)) { + pileStatus = "50"; // 50-正常使用 + } else if (StringUtils.equals(PileStatusEnum.OFF_LINE.getValue(), pileStatus) + || StringUtils.equals(PileStatusEnum.FAULT.getValue(), pileStatus)) { + pileStatus = "6"; // 6-维护中 + } + // 获取桩型号信息 + PileModelInfoVO modelInfo = pileModelInfoService.getPileModelInfoByPileSn(pileSn); + if (modelInfo == null) { + continue; + } + NREquipmentInfo equipmentInfo = NREquipmentInfo.builder() + .equipmentID(pileSn) + .equipmentName(pileSn) + .openForBusinessDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, pileBasicInfo.getCreateTime())) + .equipmentType(Integer.parseInt(modelInfo.getSpeedType())) + .equipmentStatus(Integer.parseInt(pileStatus)) + .power(new BigDecimal(modelInfo.getRatedPower()).setScale(1, BigDecimal.ROUND_HALF_UP)) + + .vinFlag(1) + .equipmentPower(new BigDecimal(modelInfo.getRatedPower()).setScale(1, BigDecimal.ROUND_HALF_UP)) + .newNationalStandard(1) + .constructionTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, pileBasicInfo.getProductionDate())) + .manufacturerID("014406554") + .build(); + // 获取枪口信息 + List connectorInfos = getConnectorInfo(pileSn); + equipmentInfo.setConnectorInfos(connectorInfos); + + resultList.add(equipmentInfo); + } + return resultList; + } + + /** + * 获取枪口信息 + * @param pileSn + * @return + */ + private List getConnectorInfo(String pileSn) { + List resultList = new ArrayList<>(); + List list = pileConnectorInfoService.selectPileConnectorInfoList(pileSn); + if (CollectionUtils.isEmpty(list)) { + return resultList; + } + PileModelInfoVO modelInfo = pileModelInfoService.getPileModelInfoByPileSn(pileSn); + int connectorType = StringUtils.equals("1", modelInfo.getSpeedType()) ? 4 : 3; + // 封装成江苏平台对象 + for (PileConnectorInfo pileConnectorInfo : list) { + NRConnectorInfo connectorInfo = NRConnectorInfo.builder() + .connectorId(pileConnectorInfo.getPileConnectorCode()) + .connectorName(pileConnectorInfo.getPileConnectorCode()) + .connectorType(connectorType) + .voltageUpperLimits(Integer.parseInt(modelInfo.getRatedVoltage())) + .voltageLowerLimits(Integer.parseInt(modelInfo.getRatedVoltage())) + .current(Integer.parseInt(modelInfo.getRatedCurrent())) + .power(new BigDecimal(modelInfo.getRatedPower()).setScale(1, BigDecimal.ROUND_HALF_UP)) + .nationalStandard(2) + + .build(); + resultList.add(connectorInfo); + } + return resultList; + } + + private ThirdPartySecretInfoVO getJiangSuSecretInfo() { + // 通过第三方平台类型查询相关配置信息 + ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(ThirdPlatformTypeEnum.JIANG_SU_PLATFORM.getTypeCode()); + if (thirdPartySecretInfoVO == null) { + throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL); + } + thirdPartySecretInfoVO.setOurOperatorId(Constants.OPERATORID_JIANG_SU); + return thirdPartySecretInfoVO; + } + + +}