From 490594a3de6680f30c8a0a74a5129f5475aa558f Mon Sep 17 00:00:00 2001 From: "YAS\\29473" <2947326429@qq.com> Date: Mon, 23 Jun 2025 15:33:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20=E5=9B=9B=E5=B7=9D?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E5=8D=8F=E8=AE=AE=E8=81=94=E8=B0=83=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/thirdparty/SiChuanController.java | 202 +++ .../jsowell/common/constant/Constants.java | 2 + .../thirdparty/ThirdPlatformTypeEnum.java | 1 + .../common/NotificationService.java | 3 + .../platform/domain/SupStationInfo.java | 37 + .../service/ThirdPartyPlatformService.java | 10 + .../impl/SiChuanPlatformServiceImpl.java | 1282 +++++++++++++++++ 7 files changed, 1537 insertions(+) create mode 100644 jsowell-admin/src/main/java/com/jsowell/api/thirdparty/SiChuanController.java create mode 100644 jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/SiChuanPlatformServiceImpl.java diff --git a/jsowell-admin/src/main/java/com/jsowell/api/thirdparty/SiChuanController.java b/jsowell-admin/src/main/java/com/jsowell/api/thirdparty/SiChuanController.java new file mode 100644 index 000000000..67c30c941 --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/api/thirdparty/SiChuanController.java @@ -0,0 +1,202 @@ +package com.jsowell.api.thirdparty; + +import com.alibaba.fastjson2.JSON; +import com.jsowell.common.annotation.Anonymous; +import com.jsowell.common.enums.thirdparty.ThirdPartyReturnCodeEnum; +import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum; +import com.jsowell.pile.dto.*; +import com.jsowell.pile.thirdparty.CommonParamsDTO; +import com.jsowell.thirdparty.lianlian.common.CommonResult; +import com.jsowell.thirdparty.platform.service.ThirdPartyPlatformService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import java.util.Map; + +/** + * 四川对接接口 + */ +@RestController +@Anonymous +@RequestMapping("/sichuan") +public class SiChuanController extends ThirdPartyBaseController { + private final String platformName = ""; + + + private final String platformType = ThirdPlatformTypeEnum.SI_CHUAN_PLATFORM.getTypeCode(); + + + @Autowired + @Qualifier("siChuanPlatformServiceImpl") + private ThirdPartyPlatformService platformLogic; + + + /** + * getToken + */ + @PostMapping("/v1/query_token") + public CommonResult queryToken(@RequestBody CommonParamsDTO dto) { + logger.info("{}-请求令牌 params:{}" , platformName , JSON.toJSONString(dto)); + try { + // Map map = zdlService.generateToken(dto); + Map map = platformLogic.queryToken(dto); + logger.info("{}-请求令牌 result:{}" , platformName , map); + return CommonResult.success(0 , "请求令牌成功!" , map.get("Data") , map.get("Sig")); + } catch (Exception e) { + logger.info("{}-请求令牌 error:" , platformName , e); + return CommonResult.failed("获取token发生异常"); + } + } + + /** + * 查询运营商信息 + * supervise_query_operator_info + */ + @PostMapping("/v1/supervise_query_operator_info") + public CommonResult supervise_query_operator_info(HttpServletRequest request , @RequestBody CommonParamsDTO dto) { + logger.info("{}-查询运营商信息 params:{}" , platformName , JSON.toJSONString(dto)); + try { + // 校验令牌 + if (!verifyToken(request.getHeader("Authorization"))) { + // 校验失败 + return CommonResult.failed(ThirdPartyReturnCodeEnum.TOKEN_ERROR); + } + + // 校验签名 + if (!verifySignature(dto)) { + // 签名错误 + return CommonResult.failed(ThirdPartyReturnCodeEnum.SIGN_ERROR); + } + + // 解析入参 + QueryOperatorInfoDTO queryOperatorInfoDTO = parseParamsDTO(dto , QueryOperatorInfoDTO.class); + + // 执行逻辑 + Map map = platformLogic.queryOperatorInfo(queryOperatorInfoDTO); + logger.info("{}-查询运营商信息 result:{}" , platformName , map); + return CommonResult.success(0 , "查询运营商信息成功!" , map.get("Data") , map.get("Sig")); + } catch (Exception e) { + logger.info("{}-查询运营商信息 error:" , platformName , e); + } + return CommonResult.failed("查询运营商信息发生异常"); + } + + + /** + * 查询充电站信息 + * supervise_query_stations_info + */ + @PostMapping("/v1/supervise_query_stations_info") + public CommonResult supervise_query_stations_info(HttpServletRequest request , @RequestBody CommonParamsDTO dto) { + logger.info("{}-查询充电站信息 params:{}" , platformName , JSON.toJSONString(dto)); + try { + logger.info("{}-携带的token:{}",platformName, request.getHeader("Authorization")); + // 校验令牌 + if (!verifyToken(request.getHeader("Authorization"))) { + // 校验失败 + return CommonResult.failed(ThirdPartyReturnCodeEnum.TOKEN_ERROR); + } + + // 校验签名 + if (!verifySignature(dto)) { + // 签名错误 + return CommonResult.failed(ThirdPartyReturnCodeEnum.SIGN_ERROR); + } + + // 解析入参 + QueryStationInfoDTO queryStationInfoDTO = parseParamsDTO(dto , QueryStationInfoDTO.class); + + // 执行逻辑 + Map map = platformLogic.queryStationsInfo(queryStationInfoDTO); + logger.info("{}-查询充电站信息 result:{}" , platformName , JSON.toJSONString(map)); + return CommonResult.success(0 , "查询充电站信息成功!" , map.get("Data") , map.get("Sig")); + } catch (Exception e) { + logger.info("{}-查询充电站信息 error:" , platformName , e); + } + return CommonResult.failed("查询充电站信息发生异常"); + } + + + + /** + * 设备接口状态查询 query_station_status + * + * @param request + * @param dto + * @return + */ + @PostMapping("/v1/supervise_query_station_status") + public CommonResult query_stations_status(HttpServletRequest request , @RequestBody CommonParamsDTO dto) { + logger.info("{}-设备接口状态查询 params:{}" , platformName , JSON.toJSONString(dto)); + try { + // 校验令牌 + if (!verifyToken(request.getHeader("Authorization"))) { + // 校验失败 + return CommonResult.failed(ThirdPartyReturnCodeEnum.TOKEN_ERROR); + } + + // 校验签名 + if (!verifySignature(dto)) { + // 签名错误 + return CommonResult.failed(ThirdPartyReturnCodeEnum.SIGN_ERROR); + } + + // 解析入参 + QueryStationInfoDTO queryStationInfoDTO = parseParamsDTO(dto , QueryStationInfoDTO.class); + + // 执行逻辑 + Map map = platformLogic.queryStationStatus(queryStationInfoDTO); + logger.info("{}-设备接口状态查询 result:{}" , platformName , map); + return CommonResult.success(0 , "设备接口状态查询成功!" , map.get("Data") , map.get("Sig")); + } catch (Exception e) { + logger.info("{}-设备接口状态查询 error:" , platformName , e); + } + return CommonResult.failed("设备接口状态查询发生异常"); + } + + + /** + * 查询补贴发放信息 + * supervise_query_subsidy_grant_info + * @param request + * @param dto + * @return + */ +/* @PostMapping("/v1/supervise_query_subsidy_grant_info") + public CommonResult supervise_query_subsidy_grant_info(HttpServletRequest request , @RequestBody CommonParamsDTO dto) { + logger.info("{}-查询补贴发放信息 params:{}" , platformName , JSON.toJSONString(dto)); + try { + // 校验令牌 + if (!verifyToken(request.getHeader("Authorization"))) { + // 校验失败 + return CommonResult.failed(ThirdPartyReturnCodeEnum.TOKEN_ERROR); + } + + // 校验签名 + if (!verifySignature(dto)) { + // 签名错误 + return CommonResult.failed(ThirdPartyReturnCodeEnum.SIGN_ERROR); + } + + // 解析入参 + QueryStationInfoDTO querySubsidyGrantInfoDTO = parseParamsDTO(dto , QueryStationInfoDTO.class); + + // 执行逻辑 + Map map = platformLogic.querySubsidyGrantInfo(querySubsidyGrantInfoDTO); + logger.info("{}-查询补贴发放信息 result:{}" , platformName , map); + return CommonResult.success(0 , "查询补贴发放信息成功!" , map.get("Data") , map.get("Sig")); + } catch (Exception e) { + logger.info("{}-查询补贴发放信息 error:" , platformName , e); + } + return CommonResult.failed("查询补贴发放信息发生异常"); + }*/ + + + + + + + +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/constant/Constants.java b/jsowell-common/src/main/java/com/jsowell/common/constant/Constants.java index 0e7d7f020..d363a1024 100644 --- a/jsowell-common/src/main/java/com/jsowell/common/constant/Constants.java +++ b/jsowell-common/src/main/java/com/jsowell/common/constant/Constants.java @@ -103,6 +103,8 @@ public class Constants { // public static final String OPERATORID_GUI_ZHOU = "MAC9K4RRX"; public static final String MANUFACTURER_NAME = "举视(江苏)新能源设备制造有限公司"; + //设备所属公司 + public static final String Equipment_Owner_Name = "举视(上海)新能源科技有限公司"; public static final String OPERATORID_XI_XIAO = "MAC13L2Q9"; diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/thirdparty/ThirdPlatformTypeEnum.java b/jsowell-common/src/main/java/com/jsowell/common/enums/thirdparty/ThirdPlatformTypeEnum.java index c5394243d..41f649ae4 100644 --- a/jsowell-common/src/main/java/com/jsowell/common/enums/thirdparty/ThirdPlatformTypeEnum.java +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/thirdparty/ThirdPlatformTypeEnum.java @@ -36,6 +36,7 @@ public enum ThirdPlatformTypeEnum { WEI_WANG_XIN_DIAN("23", "微网新电", "MA005DBW1"), HU_ZHOU_PLATFORM("24", "湖州市监管平台", "MA27U00HZ"), CHANG_ZHOU_PLATFORM("25", "新运常畅充", "0585PCW57"), + SI_CHUAN_PLATFORM("26", "四川省平台", ""), ; private String typeCode; diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/common/NotificationService.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/common/NotificationService.java index 06adc49be..0f324720a 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/common/NotificationService.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/common/NotificationService.java @@ -173,6 +173,9 @@ public class NotificationService { platformService.notificationChargeOrderInfo(orderCode); //停止充电结果推送 platformService.notificationStopChargeResult(orderCode); + //推送充换电站用能统计信息 + platformService.notificationOperationStatsInfo(stationId); + } catch (Exception e) { logger.error("充电订单信息推送error", e); } diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/domain/SupStationInfo.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/domain/SupStationInfo.java index 7ca37cc27..734d85381 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/domain/SupStationInfo.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/domain/SupStationInfo.java @@ -131,5 +131,42 @@ public class SupStationInfo extends StationInfo { @JSONField(name = "SupportingFacilities") private String supportingFacilities; + /** + * 设备所属方名称 + */ + @JSONField(name = "EquipmentOwnerName") + private String equipmentOwnerName; + + /** + * 供电类型 + * 1:直供电 2:转供电 + */ + @JSONField(name = "SupplyType") + private Integer supplyType; + + /** + * 供电局用户编号 + */ + @JSONField(name = "ResidentNo") + private String residentNo; + + /** + * 表号 + */ + @JSONField(name = "WattHourMeterNo") + private String wattHourMeterNo; + + /** + * 外电功率 + */ + @JSONField(name = "ForwardPower") + private String forwardPower; + + /** + * 充电站全省 唯一备案号 + */ + @JSONField(name = "RecordUniqueNo") + private String recordUniqueNo; + private List PolicyInfos; } 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 845311892..bca65c880 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 @@ -260,6 +260,16 @@ public interface ThirdPartyPlatformService extends InitializingBean { throw new UnsupportedOperationException("This method is not yet implemented"); } + /** + * 查询补贴发放信息 + * supervise_query_subsidy_grant_info + * @param querySubsidyGrantInfoDTO + * @return + */ + default Map querySubsidyGrantInfo(QueryStationInfoDTO querySubsidyGrantInfoDTO){ + throw new UnsupportedOperationException("This method is not yet implemented"); + } + // =================================================================================== // // ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ 由对方平台实现此接口,我方平台调用的通知接口 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ // diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/SiChuanPlatformServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/SiChuanPlatformServiceImpl.java new file mode 100644 index 000000000..55e7933c7 --- /dev/null +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/SiChuanPlatformServiceImpl.java @@ -0,0 +1,1282 @@ +package com.jsowell.thirdparty.platform.service.impl; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; +import com.github.pagehelper.PageHelper; +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.thirdparty.BusinessInformationExchangeEnum; +import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum; +import com.jsowell.common.enums.ykc.BillingTimeTypeEnum; +import com.jsowell.common.enums.ykc.OrderStatusEnum; +import com.jsowell.common.enums.ykc.PileConnectorDataBaseStatusEnum; +import com.jsowell.common.enums.ykc.ReturnCodeEnum; +import com.jsowell.common.exception.BusinessException; +import com.jsowell.common.util.*; +import com.jsowell.pile.domain.*; +import com.jsowell.pile.domain.ykcCommond.StartChargingCommand; +import com.jsowell.pile.dto.*; +import com.jsowell.pile.mapper.OrderMonitorDataMapper; +import com.jsowell.pile.service.*; +import com.jsowell.pile.thirdparty.CommonParamsDTO; +import com.jsowell.pile.thirdparty.ConnectorInfo; +import com.jsowell.pile.thirdparty.EquipmentInfo; +import com.jsowell.pile.util.MerchantUtils; +import com.jsowell.pile.vo.SupStationStatsVO; +import com.jsowell.pile.vo.ThirdPartySecretInfoVO; +import com.jsowell.pile.vo.base.ConnectorInfoVO; +import com.jsowell.pile.vo.base.MerchantInfoVO; +import com.jsowell.pile.vo.base.StationInfoVO; +import com.jsowell.pile.vo.base.ThirdPartyStationInfoVO; +import com.jsowell.pile.vo.uniapp.customer.BillingPriceVO; +import com.jsowell.pile.vo.web.PileConnectorInfoVO; +import com.jsowell.pile.vo.web.PileMerchantInfoVO; +import com.jsowell.pile.vo.web.PileModelInfoVO; +import com.jsowell.pile.vo.web.PileStationVO; +import com.jsowell.pile.vo.zdl.EquipBusinessPolicyVO; +import com.jsowell.thirdparty.lianlian.domain.ConnectorStatusInfo; +import com.jsowell.thirdparty.lianlian.domain.StationStatusInfo; +import com.jsowell.thirdparty.lianlian.vo.*; +import com.jsowell.thirdparty.platform.domain.*; +import com.jsowell.thirdparty.platform.factory.ThirdPartyPlatformFactory; +import com.jsowell.thirdparty.platform.service.ThirdPartyPlatformService; +import com.jsowell.thirdparty.platform.util.Cryptos; +import com.jsowell.thirdparty.platform.util.HttpRequestUtil; +import com.jsowell.thirdparty.platform.util.ThirdPartyPlatformUtils; +import com.jsowell.thirdparty.service.ThirdpartySecretInfoService; +import com.yi.business.geo.GeoCodeInfo; +import com.yi.business.geo.TermRelationTreeCoordinate; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; +import org.bouncycastle.crypto.CryptoException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.spec.InvalidKeySpecException; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; + +@Service +@Slf4j +public class SiChuanPlatformServiceImpl implements ThirdPartyPlatformService { + private final String thirdPlatformType = ThirdPlatformTypeEnum.SI_CHUAN_PLATFORM.getTypeCode(); + + @Autowired + private ThirdpartySecretInfoService thirdpartySecretInfoService; + + @Autowired + private PileStationInfoService pileStationInfoService; + + @Autowired + private PileBasicInfoService pileBasicInfoService; + + @Autowired + private PileModelInfoService pileModelInfoService; + + @Autowired + private PileConnectorInfoService pileConnectorInfoService; + + @Autowired + private OrderBasicInfoService orderBasicInfoService; + + @Autowired + private PileBillingTemplateService pileBillingTemplateService; + + @Autowired + private YKCPushCommandService ykcPushCommandService; + + @Autowired + private PileRemoteService pileRemoteService; + + @Autowired + private ThirdPartyStationRelationService thirdPartyStationRelationService; + + @Autowired + private PileMerchantInfoService pileMerchantInfoService; + + + + + @Override + public void afterPropertiesSet() throws Exception { + ThirdPartyPlatformFactory.register(thirdPlatformType, this); + } + + + /** + * query_token 获取token,提供给第三方平台使用 + * + * @param dto + * @return + */ + @Override + public Map queryToken(CommonParamsDTO dto) { + AccessTokenVO vo = new AccessTokenVO(); + // 0:成功;1:失败 + int succStat = 0; + // 0:无;1:无此对接平台;2:密钥错误; 3~99:自定义 + int failReason = 0; + + String operatorId = StringUtils.isNotBlank(dto.getOperatorID()) ? dto.getOperatorID() : dto.getPlatformID(); + // 通过operatorId 查出 operatorSecret + ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByOperatorId(operatorId); + if (thirdPartySecretInfoVO == null) { + failReason = 1; + succStat = 1; + } else { + String theirOperatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret(); + String dataSecret = thirdPartySecretInfoVO.getOurDataSecret(); + String dataSecretIv = thirdPartySecretInfoVO.getOurDataSecretIv(); + // 解密data 获取参数中的OperatorSecret + String decrypt = Cryptos.decrypt(dto.getData(), dataSecret, dataSecretIv); + String inputOperatorSecret = null; + if (StringUtils.isNotBlank(decrypt)) { + inputOperatorSecret = JSON.parseObject(decrypt).getString("OperatorSecret"); + if (StringUtils.isBlank(inputOperatorSecret)) { + inputOperatorSecret = JSON.parseObject(decrypt).getString("PlatformSecret"); + } + } + // 对比密钥 + List operatorSecretList = Lists.newArrayList(theirOperatorSecret, thirdPartySecretInfoVO.getOurOperatorSecret()); + if (!operatorSecretList.contains(inputOperatorSecret)) { + failReason = 1; + succStat = 1; + } else { + // 生成token + String token = JWTUtils.createToken(operatorId, theirOperatorSecret, JWTUtils.ttlMillis); + vo.setAccessToken(token); + vo.setTokenAvailableTime((int) (JWTUtils.ttlMillis / 1000)); + } + } + // 组装返回参数 + vo.setPlatformId(operatorId); + vo.setFailReason(failReason); + vo.setSuccStat(succStat); + + return ThirdPartyPlatformUtils.generateResultMap(vo, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); + } + + + /** + * 查询运营商信息 query_operator_info + * supervise_query_operator_info + * + * @param dto 查询运营商信息DTO + * @throws UnsupportedOperationException 未实现异常 + */ + @Override + public Map queryOperatorInfo(QueryOperatorInfoDTO dto) { + int pageNo = dto.getPageNo() == 0 ? 1 : dto.getPageNo(); + int pageSize = dto.getPageSize() == 0 ? 50 : dto.getPageSize(); + PageHelper.startPage(pageNo, pageSize); + List merchantList = thirdPartyStationRelationService.selectMerchantList(thirdPlatformType); + PageInfo pageInfo = new PageInfo<>(merchantList); + List operatorInfos = Lists.newArrayList(); + if (CollectionUtils.isNotEmpty(pageInfo.getList())) { + SupOperatorInfo supOperatorInfo; + for (MerchantInfoVO merchantInfoVO : pageInfo.getList()) { + supOperatorInfo = new SupOperatorInfo(); + supOperatorInfo.setOperatorID(MerchantUtils.getOperatorID(merchantInfoVO.getOrganizationCode())); + supOperatorInfo.setOperatorUSCID(merchantInfoVO.getOrganizationCode()); + supOperatorInfo.setOperatorName(merchantInfoVO.getMerchantName()); + supOperatorInfo.setOperatorTel1(merchantInfoVO.getMerchantTel()); + supOperatorInfo.setOperatorRegAddress(merchantInfoVO.getMerchantAddress()); + operatorInfos.add(supOperatorInfo); + } + } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getSiChuanSecretInfo(); + + // 组装结果集 + Map map = Maps.newHashMap(); + map.put("PageNo", pageInfo.getPageNum()); + map.put("PageCount", pageInfo.getPages()); + map.put("ItemSize", pageInfo.getTotal()); + map.put("OperatorInfos", operatorInfos); + + Map resultMap = ThirdPartyPlatformUtils.generateResultMap(map, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); + return resultMap; + } + + + /** + * 查询站点信息 + * @param dto 查询站点信息dto + * @return + */ + @Override + public Map queryStationsInfo(QueryStationInfoDTO dto) { + int pageNo = dto.getPageNo() == null ? 1 : dto.getPageNo(); + int pageSize = dto.getPageSize() == null ? 50 : dto.getPageSize(); + dto.setThirdPlatformType(thirdPlatformType); + PageUtils.startPage(pageNo, pageSize); + List stationInfos = pileStationInfoService.selectStationInfosByThirdParty(dto); + if (CollectionUtils.isEmpty(stationInfos)) { + // 未查到数据 + return null; + } + // ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getSiChuanSecretInfo(); + + PageInfo pageInfo = new PageInfo<>(stationInfos); + List resultList = new ArrayList<>(); + for (ThirdPartyStationInfoVO pileStationInfo : pageInfo.getList()) { + SupStationInfo stationInfo = new SupStationInfo(); + stationInfo.setStationID(String.valueOf(pileStationInfo.getId())); + stationInfo.setOperatorID(Constants.OPERATORID_JIANG_SU); // 组织机构代码 + String organizationCode = pileStationInfo.getOrganizationCode(); + // 充电服务运营商 + stationInfo.setEquipmentOwnerID(ThirdPartyPlatformUtils.extractEquipmentOwnerID(organizationCode)); + stationInfo.setStationName(pileStationInfo.getStationName()); + stationInfo.setCountryCode(pileStationInfo.getCountryCode()); + String areaCode = pileStationInfo.getAreaCode(); // 330000,330200,330213 + // 根据逗号分组 + String[] split = StringUtils.split(areaCode, ","); + // 只取最后一部分 330213 + String subAreaCode = split[split.length - 1]; + // 充换电站省市辖区编码 + stationInfo.setAreaCode(subAreaCode); + // 获取地理位置编码 + GeoCodeInfo geoCode = TermRelationTreeCoordinate.completeGeoCode(pileStationInfo.getAddress()); + if (geoCode != null) { + //充换电站所在县以下行政区划代码 + stationInfo.setAreaCodeCountryside(geoCode.getCounty_code()); + }else{ + stationInfo.setAreaCodeCountryside("12345678901"); + } + stationInfo.setAddress(pileStationInfo.getAddress()); + stationInfo.setServiceTel(pileStationInfo.getStationTel()); + stationInfo.setStationClassification(Constants.one); //站点分类,只填1:充电站 + stationInfo.setStationType(Integer.parseInt(pileStationInfo.getStationType())); + stationInfo.setStationStatus(Integer.parseInt(pileStationInfo.getStationStatus())); + stationInfo.setParkNums(Integer.parseInt(pileStationInfo.getParkNums())); + stationInfo.setStationLng(new BigDecimal(pileStationInfo.getStationLng()).setScale(8, RoundingMode.HALF_UP)); + stationInfo.setStationLat(new BigDecimal(pileStationInfo.getStationLat()).setScale(8, RoundingMode.HALF_UP)); + stationInfo.setConstruction(Integer.parseInt(pileStationInfo.getConstruction())); + stationInfo.setRoundTheClock(Constants.one); + stationInfo.setParkType("255"); + stationInfo.setElectricityType(Constants.one); + stationInfo.setBusinessExpandType(Integer.valueOf(pileStationInfo.getAloneApply())); //是否独立报装 //0,否 1,是 + // 报装电源容量 + if (StringUtils.isNotBlank(String.valueOf(pileStationInfo.getCapacity()))) { + stationInfo.setCapacity(pileStationInfo.getCapacity().setScale(4, RoundingMode.HALF_UP)); + } + // 获取充电桩设备列表 + List pileList = getPileList(pileStationInfo,pileStationInfo.getStationStatus()); + // 站点额定总功率 + BigDecimal stationRatedPower = pileList.stream() + .map(EquipmentInfo::getEquipmentPower) + .reduce(BigDecimal.ZERO, BigDecimal::add); + stationInfo.setRatedPower(stationRatedPower.setScale(4, RoundingMode.HALF_UP)); + + stationInfo.setPeriodFee(Constants.one); + stationInfo.setOfficialRunTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, pileStationInfo.getCreateTime())); + stationInfo.setVideoMonitor(Constants.zero); + + // 停车费率描述 + if (StringUtils.isNotBlank(pileStationInfo.getParkFeeDescribe())) { + stationInfo.setParkFee(pileStationInfo.getParkFeeDescribe()); + } + // 站点图片 + if (StringUtils.isNotBlank(pileStationInfo.getPictures())) { + stationInfo.setPictures(Lists.newArrayList(pileStationInfo.getPictures().split(","))); + } + if (CollectionUtils.isNotEmpty(pileList)) { + stationInfo.setEquipmentInfos(pileList); // 充电设备信息列表 + } + StringBuilder electricityFee = new StringBuilder(); + StringBuilder serviceFee = new StringBuilder(); + // 查询计费模板 + List priceList = pileBillingTemplateService.queryBillingPrice(String.valueOf(pileStationInfo.getId())); + for (BillingPriceVO billingPriceVO : priceList) { + electricityFee.append(billingPriceVO.getStartTime()) + .append("-").append(billingPriceVO.getEndTime()) + .append(":").append(billingPriceVO.getElectricityPrice()) + .append(","); + serviceFee.append(billingPriceVO.getStartTime()) + .append("-").append(billingPriceVO.getEndTime()) + .append(":").append(billingPriceVO.getServicePrice()) + .append(","); + } + // 去除最后一位的分号 + electricityFee.deleteCharAt(electricityFee.length() - 1); + serviceFee.deleteCharAt(serviceFee.length() - 1); + + stationInfo.setElectricityFee(electricityFee.toString()); //充电电费描述 + stationInfo.setServiceFee(serviceFee.toString()); + + stationInfo.setEquipmentOwnerName(Constants.Equipment_Owner_Name); // 设备所属方名称 + + stationInfo.setSupplyType(Constants.one); //供电类型 1:直供电 2:转供电 + if(pileStationInfo.getAccountNumber() != null){ + stationInfo.setResidentNo(pileStationInfo.getAccountNumber());//供电局用户编号 + }else{ + stationInfo.setResidentNo("1234567890123"); + } + stationInfo.setWattHourMeterNo("88888888888"); // 电能表号 + stationInfo.setForwardPower("88.8888"); // 外电功率 + stationInfo.setCountryCode(pileStationInfo.getCountryCode()); + stationInfo.setRecordUniqueNo("88888888"); //充电站全省唯一编号 + + + resultList.add(stationInfo); + } + Map map = new LinkedHashMap<>(); + map.put("ItemSize", resultList.size()); + map.put("PageCount", pageInfo.getPages()); + map.put("PageNo", pageInfo.getPageNum()); + map.put("StationInfos", resultList); + + return ThirdPartyPlatformUtils.generateResultMap(map, thirdPartySecretInfoVO); + } + + + /** + * 推送站点信息 + * @param stationId 充电站id + * @return + */ + @Override + public String notificationStationInfo(String stationId) { + List stationInfos = new ArrayList<>(); + // 通过id查询站点相关信息 + PileStationInfo pileStationInfo = pileStationInfoService.selectPileStationInfoById(Long.parseLong(stationId)); + // 查询相关配置信息 + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getSiChuanSecretInfo(); + + String operatorId = Constants.OPERATORID_JIANG_SU; + String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret(); + String signSecret = thirdPartySecretInfoVO.getTheirSigSecret(); + String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret(); + String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv(); + String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix(); + + + // 组装中电联平台所需要的数据格式 + SupStationInfo info = SupStationInfo.builder() + .stationID(stationId) + .operatorID(Constants.OPERATORID_JIANG_SU) + .stationName(pileStationInfo.getStationName()) + .countryCode(pileStationInfo.getCountryCode()) + .areaCode(pileStationInfo.getAreaCode()) + .address(pileStationInfo.getAddress()) + .serviceTel(pileStationInfo.getStationTel()) + .stationClassification(Constants.one) + .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())) + .roundTheClock(Constants.one)//7*24小时营业 0:否 1:是 + .parkType("255")//0:免费 1:不免费 2:限时免费停车 3:充电限时减免 255:参考场地实际收费标准 + .electricityType(Constants.one) //1:商业用电 2:普通工业用电 3:大工业用电 4:其他用电 + .businessExpandType(Constants.one) + .videoMonitor(Constants.zero) + .equipmentOwnerName(Constants.Equipment_Owner_Name) + .supplyType(Constants.one) + .countryCode(pileStationInfo.getCountryCode()) + .wattHourMeterNo("8") + .forwardPower("88.8888") + .recordUniqueNo("88888888") + .recordUniqueNo("88888888") + .build(); + + // 报装电源容量 + if (StringUtils.isNotBlank(String.valueOf(pileStationInfo.getCapacity()))) { + info.setCapacity(pileStationInfo.getCapacity().setScale(4, RoundingMode.HALF_UP)); + } + + //获取充电桩设备列表 + List pileList = getPileList(pileStationInfo,pileStationInfo.getStationStatus()); + + // 站点额定总功率 + BigDecimal stationRatedPower = pileList.stream() + .map(EquipmentInfo::getEquipmentPower) + .reduce(BigDecimal.ZERO, BigDecimal::add); + info.setRatedPower(stationRatedPower.setScale(4, RoundingMode.HALF_UP)); + info.setPeriodFee(Constants.one); + info.setOfficialRunTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, pileStationInfo.getCreateTime())); + + + StringBuilder electricityFee = new StringBuilder(); + StringBuilder serviceFee = new StringBuilder(); + // 查询计费模板 + List priceList = pileBillingTemplateService.queryBillingPrice(String.valueOf(pileStationInfo.getId())); + for (BillingPriceVO billingPriceVO : priceList) { + electricityFee.append(billingPriceVO.getStartTime()) + .append("-").append(billingPriceVO.getEndTime()) + .append(":").append(billingPriceVO.getElectricityPrice()) + .append(","); + serviceFee.append(billingPriceVO.getStartTime()) + .append("-").append(billingPriceVO.getEndTime()) + .append(":").append(billingPriceVO.getServicePrice()) + .append(","); + } + // 去除最后一位的分号 + electricityFee.deleteCharAt(electricityFee.length() - 1); + serviceFee.deleteCharAt(serviceFee.length() - 1); + + info.setElectricityFee(electricityFee.toString()); //充电电费描述 + info.setServiceFee(serviceFee.toString()); + + + String areaCode = pileStationInfo.getAreaCode(); // 330000,330200,330213 + // 根据逗号分组 + String[] split = StringUtils.split(areaCode, ","); + // 只取最后一部分 330213 + String subAreaCode = split[split.length - 1]; + info.setAreaCode(subAreaCode); + // 获取地理位置编码 + GeoCodeInfo geoCode = TermRelationTreeCoordinate.completeGeoCode(pileStationInfo.getAddress()); + if (geoCode != null) { + //充换电站所在县以下行政区划代码 + info.setAreaCodeCountryside(geoCode.getCounty_code()); + }else{ + info.setAreaCodeCountryside("12345678901"); + } + // 截取运营商组织机构代码(去除最后一位后的最后九位) + MerchantInfoVO merchantInfo = pileMerchantInfoService.getMerchantInfoVO(String.valueOf(pileStationInfo.getMerchantId())); + String organizationCode = merchantInfo.getOrganizationCode(); + + info.setEquipmentOwnerID(ThirdPartyPlatformUtils.extractEquipmentOwnerID(organizationCode)); + + + // 站点图片 + if (StringUtils.isNotBlank(pileStationInfo.getPictures())) { + info.setPictures(Lists.newArrayList(pileStationInfo.getPictures().split(","))); + } + + if (CollectionUtils.isNotEmpty(pileList)) { + info.setEquipmentInfos(pileList); // 充电设备信息列表 + } + stationInfos.add(info); + + // 调用中电联平台接口 + String url = urlAddress + "supervise_notification_station_info"; + + JSONObject data = new JSONObject(); + data.put("SupStationInfos", stationInfos); + + 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; + } + + + /** + * 设备接口状态查询 query_station_status + * @param dto 查询站点信息dto + * @return + */ + @Override + public Map queryStationStatus(QueryStationInfoDTO dto) { + List stationIds = dto.getStationIds(); + List stationStatusInfos = new ArrayList<>(); + List connectorStatusInfos = new ArrayList<>(); + // 查询密钥信息 + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getSiChuanSecretInfo(); + + // 根据站点idList查询枪口列表 + List list = pileConnectorInfoService.batchSelectConnectorList(stationIds); + // 根据站点id分组 + Map> collect = list.stream() + .collect(Collectors.groupingBy(ConnectorInfoVO::getStationId)); + // 封装参数 + for (Map.Entry> entry : collect.entrySet()) { + String stationId = entry.getKey(); + List voList = entry.getValue(); + StationStatusInfo stationStatusInfo = new StationStatusInfo(); + + PileStationVO stationInfo = pileStationInfoService.getStationInfo(stationId); + PileMerchantInfoVO pileMerchantInfoVO = pileMerchantInfoService.queryMerchantInfoByStationId(String.valueOf(stationInfo.getId())); + String organizationCode = pileMerchantInfoVO.getOrganizationCode(); + + stationStatusInfo.setOperatorId(Constants.OPERATORID_JIANG_SU); + stationStatusInfo.setEquipmentOwnerId(ThirdPartyPlatformUtils.extractEquipmentOwnerID(organizationCode)); + stationStatusInfo.setStationId(stationId); + + ConnectorStatusInfo connectorStatusInfo; + for (ConnectorInfoVO connectorInfoVO : voList) { + connectorStatusInfo = ConnectorStatusInfo.builder() + .operatorId(Constants.OPERATORID_JIANG_SU) + .equipmentOwnerId(ThirdPartyPlatformUtils.extractEquipmentOwnerID(organizationCode)) + .stationId(connectorInfoVO.getStationId()) + .equipmentId(connectorInfoVO.getPileSn()) + .connectorID(connectorInfoVO.getPileConnectorCode()) + .equipmentClassification(Constants.one) + .status(Integer.parseInt(connectorInfoVO.getConnectorStatus())) + .updateTime(DateUtils.getDateTime()) + .build(); + connectorStatusInfos.add(connectorStatusInfo); + } + stationStatusInfo.setConnectorStatusInfos(connectorStatusInfos); + + stationStatusInfos.add(stationStatusInfo); + } + Map map = new LinkedHashMap<>(); + map.put("StationStatusInfos", stationStatusInfos); + + Map resultMap = ThirdPartyPlatformUtils.generateResultMap(map, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); + return resultMap; + } + + + /** + * 设备状态推送 + * @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); + } + + String merchantId = connectorInfo.getMerchantId(); + MerchantInfoVO merchantInfoVO = pileMerchantInfoService.getMerchantInfoVO(merchantId); + if (Objects.isNull(merchantInfoVO)) { + throw new BusinessException(ReturnCodeEnum.CODE_CONNECTOR_INFO_NULL_ERROR); + } + + SupConnectorStatusInfo info = SupConnectorStatusInfo.builder() + .operatorID(Constants.OPERATORID_JIANG_SU) + .equipmentOwnerID(MerchantUtils.getOperatorID(merchantInfoVO.getOrganizationCode())) + .stationID(connectorInfo.getStationId()) + .equipmentID(connectorInfo.getPileSn()) + .connectorID(pileConnectorCode) + .status(Integer.parseInt(status)) + .updateTime(DateUtils.getDateTime()) + .equipmentClassification(Constants.ONE) + .build(); + + // 调用联联平台接口 + String operatorId = Constants.OPERATORID_JIANG_SU; + String operatorSecret = secretInfoVO.getTheirOperatorSecret(); + String signSecret = secretInfoVO.getTheirSigSecret(); + String dataSecret = secretInfoVO.getTheirDataSecret(); + String dataSecretIv = secretInfoVO.getTheirDataSecretIv(); + String urlAddress = secretInfoVO.getTheirUrlPrefix(); + String url = urlAddress + "supervise_notification_station_status"; + + String jsonString = JSON.toJSONString(info); + // 获取令牌 + String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret); + String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret); + return result; + } + + + /** + * 推送充电状态 notification_equip_charge_status + * 推送充电状态信息 supervise_notification_equip_charge_status + * + * @param orderCode 订单编号 + * @throws UnsupportedOperationException 未实现异常 + */ + @Override + public String notificationEquipChargeStatus(String orderCode) { + // 根据订单号查询订单信息 + OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); + // 查询相关配置信息 + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getSiChuanSecretInfo(); + + String operatorId = thirdPartySecretInfoVO.getOurOperatorId(); + String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret(); + String signSecret = thirdPartySecretInfoVO.getTheirSigSecret(); + String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret(); + String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv(); + String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix(); + // 查询站点信息 + PileStationVO stationInfo = pileStationInfoService.getStationInfo(orderInfo.getStationId()); + PileMerchantInfoVO pileMerchantInfoVO = pileMerchantInfoService.queryMerchantInfoByStationId(String.valueOf(stationInfo.getId())); + String organizationCode = pileMerchantInfoVO.getOrganizationCode(); + + // 查询枪口实时状态 + List chargingRealTimeData = orderBasicInfoService.getChargingRealTimeData(orderInfo.getTransactionCode()); + RealTimeMonitorData realTimeMonitorData; + if (CollectionUtils.isEmpty(chargingRealTimeData)) { + realTimeMonitorData = RealTimeMonitorData.builder() + .chargingDegree(Constants.ZERO) + .connectorStatus("3") + .build(); + chargingRealTimeData.add(realTimeMonitorData); + } else { + realTimeMonitorData = chargingRealTimeData.get(0); + } + + // 查询枪口状态 + PileConnectorInfoVO info = pileConnectorInfoService.getPileConnectorInfoByConnectorCode(orderInfo.getPileConnectorCode()); + if (Objects.isNull(info)) { + throw new BusinessException(ReturnCodeEnum.CODE_CONNECTOR_INFO_NULL_ERROR); + } + String merchantId = info.getMerchantId(); + MerchantInfoVO merchantInfoVO = pileMerchantInfoService.getMerchantInfoVO(merchantId); + if (Objects.isNull(merchantInfoVO)) { + throw new BusinessException(ReturnCodeEnum.CODE_CONNECTOR_INFO_NULL_ERROR); + } + String orderStatus = orderInfo.getOrderStatus(); + if (StringUtils.equals(OrderStatusEnum.IN_THE_CHARGING.getValue(), orderStatus)) { + // 充电中 + orderStatus = "2"; + } else if (StringUtils.equals(OrderStatusEnum.ORDER_COMPLETE.getValue(), orderStatus)) { + // 充电完成 + orderStatus = "4"; + }else if(StringUtils.equals(OrderStatusEnum.STAY_SETTLEMENT.getValue(), orderStatus) + || StringUtils.equals(OrderStatusEnum.STAY_RETROACTIVE_AMOUNT.getValue(), orderStatus) + ){ + //订单挂起 + orderStatus = "5"; + }else if (StringUtils.equals(OrderStatusEnum.NOT_START.getValue(), orderStatus)){ + //启动失败 + orderStatus = "7"; + }else{ + //充电异常结束 + orderStatus = "6"; + } + BigDecimal current = realTimeMonitorData.getOutputCurrent() == null ? BigDecimal.ZERO : info.getCurrent(); + BigDecimal voltage = realTimeMonitorData.getOutputVoltage() == null ? BigDecimal.ZERO : info.getVoltage(); + String soc = realTimeMonitorData.getSOC() == null ? Constants.ZERO : info.getSOC(); + + String dateTime = DateUtils.getDateTime(); + SupEquipChargeStatusInfo supEquipChargeStatusInfo = SupEquipChargeStatusInfo.builder() + .operatorID(Constants.OPERATORID_JIANG_SU) + .equipmentOwnerID(ThirdPartyPlatformUtils.extractEquipmentOwnerID(organizationCode)) + .stationID(orderInfo.getStationId()) + .equipmentID(orderInfo.getPileSn()) + .connectorID(orderInfo.getPileConnectorCode()) + .orderNo(orderInfo.getOrderCode()) + .orderStatus(Integer.parseInt(orderStatus)) + .equipmentClassification(Constants.one) + .pushTimeStamp(dateTime) + .connectorStatus(Integer.parseInt(realTimeMonitorData.getConnectorStatus())) // 3-充电中 + .currentA(current.setScale(4, RoundingMode.HALF_UP)) + .voltageA(voltage.setScale(4, RoundingMode.HALF_UP)) + .soc(new BigDecimal(soc).setScale(1, RoundingMode.HALF_UP)) + .startTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderInfo.getChargeStartTime())) + .endTime(dateTime) + .totalPower(new BigDecimal(realTimeMonitorData.getChargingDegree()).setScale(4, BigDecimal.ROUND_HALF_UP)) + .build(); + + supEquipChargeStatusInfo.setEquipmentOwnerID(ThirdPartyPlatformUtils.extractEquipmentOwnerID(stationInfo.getOrganizationCode())); + + String url = urlAddress + "supervise_notification_equip_charge_status"; + // 调用平台接口 + String jsonString = JSON.toJSONString(supEquipChargeStatusInfo); + + // 获取令牌 + String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret); + String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret); + return result; + } + + + /** + * 推送充换电站用能统计信息 supervise_notification_operation_stats_info + * + * @param stationId + * @throws UnsupportedOperationException 未实现异常 + */ + @Override + public String notificationOperationStatsInfo(String stationId) { + SupStationStatsInfo.EquipmentStatsInfo equipmentStatsInfo = new SupStationStatsInfo.EquipmentStatsInfo(); + List equipmentStatsInfoList = new ArrayList<>(); + + SupStationStatsInfo.EquipmentStatsInfo.ConnectorStatsInfo connectorStatsInfo = null; + List connectorStatsInfoList = new ArrayList<>(); + + // 根据站点id查询订单记录 (新建Service方法) + List orderVOS = orderBasicInfoService.queryOrderListByStationId(stationId); + // 根据订单信息汇总出站点充电数据 + BigDecimal stationTotalElectricity = BigDecimal.ZERO; // 充电站累计用电量 + int stationChargeTime = Constants.zero; // 充电站累计充电次数 + for (SupStationStatsVO orderVO : orderVOS) { + // 充电站累计用电量 + BigDecimal totalPower = (orderVO.getTotalPower() != null) ? orderVO.getTotalPower() : BigDecimal.ZERO; + int chargingTime = (orderVO.getChargingTime() != null) ? orderVO.getChargingTime() : Constants.zero; + + stationTotalElectricity = stationTotalElectricity.add(totalPower); + // 充电站累计充电时长(分钟) + stationChargeTime += chargingTime; + } + + // 根据枪口排序,分组,将充电时长和充电量累加 + Map collect = orderVOS.stream() + .sorted(Comparator.comparing(SupStationStatsVO::getPileConnectorCode)) + .filter(vo -> vo.getChargingTime() != null && vo.getTotalPower() != null) + .collect(Collectors.toMap(SupStationStatsVO::getPileConnectorCode, Function.identity(), + (a, b) -> { + a.setChargingTime(a.getChargingTime() + b.getChargingTime()); + a.setTotalPower(a.getTotalPower().add(b.getTotalPower())); + return a; + })); + TreeMap sortedMap = new TreeMap<>(collect); + + // 初始化相关数据 + String pileSn = ""; + BigDecimal pileTotalPower = BigDecimal.ZERO; + int pileChargeTime = Constants.zero; + // key : pileConnectorCode + // value: SupStationStatsVO + for (Map.Entry entry : sortedMap.entrySet()) { + String pileConnectorCode = entry.getKey(); + SupStationStatsVO vo = entry.getValue(); + + connectorStatsInfo = new SupStationStatsInfo.EquipmentStatsInfo.ConnectorStatsInfo(); + + // 先封装枪口数据 + connectorStatsInfo.setConnectorId(pileConnectorCode); + + connectorStatsInfo.setEquipmentClassification(1); + connectorStatsInfo.setConnectorElectricity(((vo.getTotalPower() != null) ? vo.getTotalPower() : BigDecimal.ZERO).setScale(4, RoundingMode.HALF_UP)); + connectorStatsInfo.setConnectorTotalChargeTime((vo.getChargingTime() != null) ? vo.getChargingTime() : Constants.zero); + connectorStatsInfo.setConnectorTotalChargeNum(orderVOS.size()); + connectorStatsInfo.setConnectorTotalWarningNum(0); + + // 对比这次循环到的桩编号和上次的桩编号,如果是同一台桩,将数据进行汇总,如果不是,新建桩数据,并将之前的累计数据清0 + String newPileSn = vo.getPileSn(); + if (!StringUtils.equals(pileSn, newPileSn)) { + pileSn = newPileSn; + pileTotalPower = BigDecimal.ZERO; + pileChargeTime = Constants.zero; + + equipmentStatsInfo = new SupStationStatsInfo.EquipmentStatsInfo(); + connectorStatsInfoList = new ArrayList<>(); + + equipmentStatsInfo.setEquipmentId(pileSn); + equipmentStatsInfo.setEquipmentClassification(1); + equipmentStatsInfo.setEquipmentElectricity(((vo.getTotalPower() != null) ? vo.getTotalPower() : BigDecimal.ZERO).setScale(4, RoundingMode.HALF_UP)); + equipmentStatsInfo.setEquipmentTotalChargeTime((vo.getChargingTime() != null) ? vo.getChargingTime() : Constants.zero); + equipmentStatsInfo.setEquipmentTotalChargeNum(orderVOS.size()); + equipmentStatsInfo.setEquipmentTotalWarningNum(0); + + pileTotalPower = pileTotalPower.add((vo.getTotalPower() != null) ? vo.getTotalPower() : BigDecimal.ZERO); + pileChargeTime += (vo.getChargingTime() != null) ? vo.getChargingTime() : Constants.zero; + + connectorStatsInfoList.add(connectorStatsInfo); + equipmentStatsInfo.setConnectorStatsInfos(connectorStatsInfoList); + equipmentStatsInfoList.add(equipmentStatsInfo); + } else { + // 同一台桩,枪口号不同,累加桩数据,将枪口数据新建 + pileTotalPower = pileTotalPower.add((vo.getTotalPower() != null) ? vo.getTotalPower() : BigDecimal.ZERO); + pileChargeTime += (vo.getChargingTime() != null) ? vo.getChargingTime() : Constants.zero; + + equipmentStatsInfo.setEquipmentElectricity(pileTotalPower); // 第一次判断时一定不会进入到这里,所以不用判断 equipmentStatsInfo 是否为 null + equipmentStatsInfo.setEquipmentTotalChargeTime(pileChargeTime); + + connectorStatsInfoList.add(connectorStatsInfo); + equipmentStatsInfo.setConnectorStatsInfos(connectorStatsInfoList); + equipmentStatsInfoList.add(equipmentStatsInfo); + } + } + + PileStationVO stationInfo = pileStationInfoService.getStationInfo(stationId); + PileMerchantInfoVO pileMerchantInfoVO = pileMerchantInfoService.queryMerchantInfoByStationId(String.valueOf(stationInfo.getId())); + String organizationCode = pileMerchantInfoVO.getOrganizationCode(); + + // 创建对象 + String startTime = DateUtils.getYesterdayStr(); + String endTime = DateUtils.getYesterdayStr(); + SupStationStatsInfo supStationStatsInfo = SupStationStatsInfo.builder() + .stationId(stationId) + .operatorId(Constants.OPERATORID_JIANG_SU) + .equipmentOwnerId(ThirdPartyPlatformUtils.extractEquipmentOwnerID(organizationCode)) + .stationClassification(1) + .startTime(startTime) + .endTime(endTime) + .stationElectricity(stationTotalElectricity) + .stationTotalChargeEnergy(stationTotalElectricity) + .stationTotalOtherEnergy(new BigDecimal(Constants.zero).setScale(4, RoundingMode.HALF_UP)) //累计其它电量 + .stationTotalSwapChargeNum(Constants.zero) + .stationTotalChargeNum(orderVOS.size()) + .stationTotalChargeTime(stationChargeTime) + .stationTotalSwapTime(Constants.zero) + .stationTotalWarningNum(0) + .equipmentStatsInfos(equipmentStatsInfoList) + .build(); + + JSONObject json = new JSONObject(); + List supStationStatsInfoList = new ArrayList<>(); + supStationStatsInfoList.add(supStationStatsInfo); + json.put("StationStatsInfos", supStationStatsInfoList); + String jsonString = JSON.toJSONString(json); + + // 发送推送请求 + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getSiChuanSecretInfo(); + + String operatorId = Constants.OPERATORID_JIANG_SU; + + String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret(); + String signSecret = thirdPartySecretInfoVO.getTheirSigSecret(); + String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret(); + String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv(); + String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix(); + String url = urlAddress + "supervise_notification_operation_stats_info"; + // 获取令牌 + String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret); + if (StringUtils.isBlank(token)) { + return null; + } + // 调用平台接口 + String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret); + return result; + } + + + /** + * 推送充电订单信息 + * supervise_notification_charge_order_info + */ + @Override + public String notificationChargeOrderInfo(String orderCode, ThirdPartySecretInfoVO secretInfoVO) { + // 根据订单号查询出信息 + OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); + if (orderBasicInfo == null) { + return null; + } + + String operatorId = Constants.OPERATORID_JIANG_SU; + String operatorSecret = secretInfoVO.getTheirOperatorSecret(); + String signSecret = secretInfoVO.getTheirSigSecret(); + String dataSecret = secretInfoVO.getTheirDataSecret(); + String dataSecretIv = secretInfoVO.getTheirDataSecretIv(); + String urlAddress = secretInfoVO.getTheirUrlPrefix(); + + // 根据订单号查询订单详情 + OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderCode); + if (orderDetail == null) { + return null; + } + + // 推送地址 + String url = urlAddress + "supervise_notification_charge_order_info"; + + ChargeOrderInfo chargeOrderInfo = transformChargeOrderInfo(orderBasicInfo , orderDetail); + + + // 获取令牌 + String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret); + if (StringUtils.isBlank(token)) { + return null; + } + // 调用联联平台接口 + String jsonString = JSON.toJSONString(chargeOrderInfo); + String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret); + return result; + } + + + + + /** + * 推送充电站历史充电订单信息 supervise_notification_charge_order_info_history + * + * @param orderCode + * @throws UnsupportedOperationException 未实现异常 + */ + @Override + public String notificationChargeOrderInfoHistory(String orderCode) { + // 根据订单号查询出信息 + OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); + + OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderCode); + + String operatorId = Constants.OPERATORID_JIANG_SU; + ThirdPartySecretInfoVO guiZhouPlatformSecretInfo = getSiChuanSecretInfo(); + + String operatorSecret = guiZhouPlatformSecretInfo.getTheirOperatorSecret(); + String signSecret = guiZhouPlatformSecretInfo.getTheirSigSecret(); + String dataSecret = guiZhouPlatformSecretInfo.getTheirDataSecret(); + String dataSecretIv = guiZhouPlatformSecretInfo.getTheirDataSecretIv(); + String urlAddress = guiZhouPlatformSecretInfo.getTheirUrlPrefix(); + + String url = urlAddress + "supervise_notification_charge_order_info_history"; + + ChargeOrderInfo orderInfo = transformChargeOrderInfo(orderBasicInfo, orderDetail); + + + // 获取令牌 + String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret); + if (StringUtils.isBlank(token)) { + return null; + } + // 调用联联平台接口 + String jsonString = JSON.toJSONString(orderInfo); + String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret); + return result; + } + + + + /** + * 推送充电站实时功率信息 + * supervise_notification_realtime_power_info + */ + @Override + public String notificationPowerInfo(List stationIds) { + List supStationPowerInfoList = new ArrayList<>(); + stationIds.forEach(stationId -> { + PileMerchantInfoVO pileMerchantInfoVO = pileMerchantInfoService.queryMerchantInfoByStationId(stationId); + String dateTimeNow = DateUtils.getDateTime(); + SupStationPowerInfo supStationPowerInfo = new SupStationPowerInfo(); + // 根据站点id查询桩列表 + List pileList = pileBasicInfoService.getPileListByStationId(stationId); + SupStationPowerInfo.EquipmentPowerInfo equipmentPowerInfo = null; + List equipmentPowerInfoList = new ArrayList<>(); + //充换电站实时功率 初始化,指定精度保留4位小数 + BigDecimal stationInstantPower = BigDecimal.ZERO.setScale(4, RoundingMode.HALF_UP); + + supStationPowerInfo.setOperatorId(Constants.OPERATORID_JIANG_SU); + String equipmentOwnerID = ThirdPartyPlatformUtils.extractEquipmentOwnerID(pileMerchantInfoVO.getOrganizationCode()); + supStationPowerInfo.setEquipmentOwnerID(equipmentOwnerID); + supStationPowerInfo.setStationId(stationId); + supStationPowerInfo.setStationClassification(Constants.one); //站点分类 + supStationPowerInfo.setDataTime(dateTimeNow); + + + for (PileBasicInfo pileBasicInfo : pileList) { + equipmentPowerInfo = new SupStationPowerInfo.EquipmentPowerInfo(); + equipmentPowerInfo.setEquipmentID(pileBasicInfo.getSn()); + equipmentPowerInfo.setEquipmentClassification(Constants.one); + equipmentPowerInfo.setDataTime(dateTimeNow); + + // 根据桩sn查询枪口列表 + List pileConnectorInfos = pileConnectorInfoService.selectPileConnectorInfoList(pileBasicInfo.getSn()); + // 如果枪口状态为充电中,则查询枪口功率等信息 + SupStationPowerInfo.EquipmentPowerInfo.ConnectorPowerInfo connectorPowerInfo = null; + List connectorPowerInfoList = new ArrayList<>(); + // 初始化桩功率 + BigDecimal pileInstantPower = BigDecimal.ZERO.setScale(4, RoundingMode.HALF_UP); + for (PileConnectorInfo pileConnectorInfo : pileConnectorInfos) { + if (StringUtils.equals(PileConnectorDataBaseStatusEnum.OCCUPIED_CHARGING.getValue(), pileConnectorInfo.getStatus())) { + // 查询充电枪口状态 + PileConnectorInfoVO connectorInfo = pileConnectorInfoService.getPileConnectorInfoByConnectorCode(pileConnectorInfo.getPileConnectorCode()); + if (Objects.isNull(connectorInfo)) { + throw new BusinessException(ReturnCodeEnum.CODE_CONNECTOR_INFO_NULL_ERROR); + } + //获取该枪充电中的订单信息 + OrderBasicInfo orderBasicInfo = orderBasicInfoService.queryChargingByPileConnectorCode(pileConnectorInfo.getPileConnectorCode()); + if(Objects.isNull(orderBasicInfo)){ + throw new BusinessException(ReturnCodeEnum.valueOf("枪口订单查询失败")); + } + //获取到实时数据 + List chargingRealTimeData = orderBasicInfoService.getChargingRealTimeData(orderBasicInfo.getTransactionCode()); + if(CollectionUtils.isEmpty(chargingRealTimeData)){ + throw new BusinessException(ReturnCodeEnum.valueOf("枪口实时数据查询失败")); + } + RealTimeMonitorData realTimeMonitorData = chargingRealTimeData.get(0); + //获取到实时功率 + BigDecimal instantPower = realTimeMonitorData.getOutputPower() == null ? BigDecimal.ZERO.setScale(4, RoundingMode.HALF_UP) : + new BigDecimal(realTimeMonitorData.getOutputPower()).setScale(4, RoundingMode.HALF_UP); + + //计算桩的功率 = 枪的功率之和 + pileInstantPower = pileInstantPower.add(instantPower); + + connectorPowerInfo = new SupStationPowerInfo.EquipmentPowerInfo.ConnectorPowerInfo(); + connectorPowerInfo.setConnectorID(connectorInfo.getPileConnectorCode()); + connectorPowerInfo.setEquipmentClassification(Constants.one); + connectorPowerInfo.setDataTime(dateTimeNow); + connectorPowerInfo.setConnectorRealTimePower(instantPower); + + connectorPowerInfoList.add(connectorPowerInfo); + } + // 计算桩的功率(枪口功率之和) + equipmentPowerInfo.setEquipRealTimePower(pileInstantPower); + // 汇总站点功率 + stationInstantPower = stationInstantPower.add(pileInstantPower); + + equipmentPowerInfo.setConnectorPowerInfos(connectorPowerInfoList); + equipmentPowerInfoList.add(equipmentPowerInfo); + } + } + supStationPowerInfo.setStationRealTimePower(stationInstantPower); + supStationPowerInfo.setEquipmentPowerInfos(equipmentPowerInfoList); + supStationPowerInfoList.add(supStationPowerInfo); + }); + // 发送请求 + ThirdPartySecretInfoVO zheJiangPlatformSecretInfo = getSiChuanSecretInfo(); + + String operatorId = zheJiangPlatformSecretInfo.getOurOperatorId(); + String operatorSecret = zheJiangPlatformSecretInfo.getTheirOperatorSecret(); + String signSecret = zheJiangPlatformSecretInfo.getTheirSigSecret(); + String dataSecret = zheJiangPlatformSecretInfo.getTheirDataSecret(); + String dataSecretIv = zheJiangPlatformSecretInfo.getTheirDataSecretIv(); + String urlAddress = zheJiangPlatformSecretInfo.getTheirUrlPrefix(); + String url = urlAddress + "supervise_notification_realtime_power_info"; + // 获取令牌 + String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret); + if (StringUtils.isBlank(token)) { + return null; + } + // 调用平台接口 + JSONObject json = new JSONObject(); + json.put("SupStationPowerInfos", supStationPowerInfoList); + String jsonString = JSON.toJSONString(json); + String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret); + return result; + + } + + + /** + * 查询补贴发放信息 + * supervise_query_subsidy_grant_info + */ +/* @Override + public Map querySubsidyGrantInfo(QueryStationInfoDTO dto) { + // 查询第三方绑定的站点有哪些 + List stationInfoVOS = thirdPartyStationRelationService.selectStationList(thirdPlatformType); + + + + }*/ + + + + + /** + * 订单推送数据封装 + * @param orderBasicInfo + * @param orderDetail + * @return + */ + private ChargeOrderInfo transformChargeOrderInfo(OrderBasicInfo orderBasicInfo , OrderDetail orderDetail) { + PileStationVO stationInfo = pileStationInfoService.getStationInfo(orderBasicInfo.getStationId()); + PileMerchantInfoVO pileMerchantInfoVO = pileMerchantInfoService.queryMerchantInfoByStationId(String.valueOf(stationInfo.getId())); + String organizationCode = pileMerchantInfoVO.getOrganizationCode(); + + ChargeOrderInfo chargeOrderInfo = ChargeOrderInfo.builder() + .operatorID(Constants.OPERATORID_JIANG_SU) + .equipmentOwnerID(ThirdPartyPlatformUtils.extractEquipmentOwnerID(organizationCode)) + .stationID(orderBasicInfo.getStationId()) + .equipmentID(orderBasicInfo.getPileSn()) + .orderNo(orderBasicInfo.getOrderCode()) + .connectorID(orderBasicInfo.getPileConnectorCode()) + .equipmentClassification(1) + .startTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderBasicInfo.getChargeStartTime())) + .endTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderBasicInfo.getChargeEndTime())) + .totalPower(orderDetail.getTotalUsedElectricity().setScale(4, RoundingMode.HALF_UP)) + .pushTimeStamp(DateUtils.getDateTime()) + .totalElecMoney(orderDetail.getTotalElectricityAmount().setScale(4, RoundingMode.HALF_UP)) + .totalServiceMoney(orderDetail.getTotalServiceAmount().setScale(4, RoundingMode.HALF_UP)) + .totalMoney(orderDetail.getTotalOrderAmount()) + .stopReason(2) + .stopDesc(orderBasicInfo.getReason()) + .build(); + if (orderBasicInfo.getPlateNumber() != null) { + chargeOrderInfo.setLicensePlate(orderBasicInfo.getPlateNumber()); + } + if (orderBasicInfo.getVinCode() != null) { + chargeOrderInfo.setVin(orderBasicInfo.getVinCode()); + } + if (orderBasicInfo.getStartSoc() != null) { + chargeOrderInfo.setStartSOC(orderBasicInfo.getStartSoc()); + } + if (orderBasicInfo.getEndSoc() != null) { + chargeOrderInfo.setEndSOC(orderBasicInfo.getEndSoc()); + } + return chargeOrderInfo; + } + + + /** + * 转换时段充电明细 + * + * @param orderDetail + * @param billingList + * @return + */ + private List transformSupChargeDetails(OrderDetail orderDetail, List billingList) { + List resultList = Lists.newArrayList(); + SupChargeDetails detail; + for (BillingPriceVO billingPriceVO : billingList) { + detail = new SupChargeDetails(); + + String startTime = convertTime(billingPriceVO.getStartTime()); + String endTime = convertTime(billingPriceVO.getEndTime()); + + if (StringUtils.equals(billingPriceVO.getTimeType(), BillingTimeTypeEnum.SHARP.getValue())) { + // 尖时段 + detail.setDetailStartTime(startTime); + detail.setDetailEndTime(endTime); + 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(), BillingTimeTypeEnum.PEAK.getValue())) { + // 峰时段 + detail.setDetailStartTime(startTime); + detail.setDetailEndTime(endTime); + 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(), BillingTimeTypeEnum.FLAT.getValue())) { + // 平时段 + detail.setDetailStartTime(startTime); + detail.setDetailEndTime(endTime); + 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(), BillingTimeTypeEnum.VALLEY.getValue())) { + // 谷时段 + detail.setDetailStartTime(startTime); + detail.setDetailEndTime(endTime); + 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()); + } + resultList.add(detail); + } + return resultList; + } + + + public static String convertTime(String timeStr) { + try { + // 1. 解析输入的 HH:mm 为 LocalTime + DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm"); + LocalTime localTime = LocalTime.parse(timeStr, timeFormatter); + + // 2. 获取当前日期(年、月、日) + LocalDate currentDate = LocalDate.now(); + + // 3. 合并日期和时间为 LocalDateTime + LocalDateTime dateTime = LocalDateTime.of(currentDate, localTime); + + // 4. 格式化为目标格式 yyyy-MM-dd HH:mm:ss + DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + return dateTime.format(outputFormatter); + + } catch (Exception e) { + throw new IllegalArgumentException("时间格式错误,应为 HH:mm", e); + } + } + + + + /** + * 获取配置密钥信息 + * + * @return + */ + private ThirdPartySecretInfoVO getSiChuanSecretInfo() { + // 通过第三方平台类型查询相关配置信息 + ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(thirdPlatformType); + if (thirdPartySecretInfoVO == null) { + throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL); + } + thirdPartySecretInfoVO.setOurOperatorId(Constants.OPERATORID_JIANG_SU); + return thirdPartySecretInfoVO; + } + + + + /** + * 获取桩列表信息 + * + * @param pileStationInfo + * @param stationStatus + * @return + */ + private List getPileList(PileStationInfo pileStationInfo , String stationStatus) { + List resultList = new ArrayList<>(); + // 通过站点id查询桩基本信息 + List list = pileBasicInfoService.getPileListByStationId(String.valueOf(pileStationInfo.getId())); + // 封装成中电联平台对象 + for (PileBasicInfo pileBasicInfo : list) { + EquipmentInfo equipmentInfo = new EquipmentInfo(); + String pileSn = pileBasicInfo.getSn(); + + equipmentInfo.setEquipmentID(pileSn); + equipmentInfo.setEquipmentClassification(Constants.one); + PileModelInfoVO modelInfo = pileModelInfoService.getPileModelInfoByPileSn(pileSn); + equipmentInfo.setEquipmentType(Integer.parseInt(modelInfo.getSpeedType())); + equipmentInfo.setPower(new BigDecimal(modelInfo.getRatedPower()).setScale(4, RoundingMode.HALF_UP)); + + List connectorList = getConnectorList(pileBasicInfo,stationStatus); + equipmentInfo.setConnectorInfos(connectorList); + + resultList.add(equipmentInfo); + } + return resultList; + } + + /** + * 获取枪口列表 + * + * @param pileBasicInfo + * @param stationStatus + * @return + */ + private List getConnectorList(PileBasicInfo pileBasicInfo , String stationStatus) { + List resultList = new ArrayList<>(); + + List list = pileConnectorInfoService.selectPileConnectorInfoList(pileBasicInfo.getSn()); + for (PileConnectorInfo pileConnectorInfo : list) { + ConnectorInfo connectorInfo = new ConnectorInfo(); + + connectorInfo.setConnectorID(pileConnectorInfo.getPileConnectorCode()); + connectorInfo.setEquipmentClassification(Constants.one); + String pileSn = pileConnectorInfo.getPileSn(); + PileModelInfoVO modelInfo = pileModelInfoService.getPileModelInfoByPileSn(pileSn); + int connectorType = StringUtils.equals("1", modelInfo.getSpeedType()) ? 4 : 3; + + connectorInfo.setConnectorType(connectorType); + // 车位号 + if (StringUtils.isNotBlank(pileConnectorInfo.getParkNo())) { + connectorInfo.setParkNo(pileConnectorInfo.getParkNo()); + } + connectorInfo.setVoltageUpperLimits(Integer.valueOf(modelInfo.getRatedVoltage())); + connectorInfo.setVoltageLowerLimits(Integer.valueOf(modelInfo.getRatedVoltage())); + connectorInfo.setCurrent(Integer.valueOf(modelInfo.getRatedCurrent())); + connectorInfo.setNationalStandard(2); + // if (!StringUtils.equals(modelInfo.getConnectorNum(), "1")) { + // // 如果不是单枪,则枪口功率需要除以枪口数量 + // String ratedPowerStr = modelInfo.getRatedPower(); + // BigDecimal ratedPower = new BigDecimal(ratedPowerStr); + // connectorInfo.setPower(ratedPower.divide(new BigDecimal(modelInfo.getConnectorNum()), 1, BigDecimal.ROUND_HALF_UP)); + // }else { + // } + connectorInfo.setAuxPower(3); + connectorInfo.setOpreateStatus(Integer.valueOf(stationStatus)); + connectorInfo.setPower(new BigDecimal(modelInfo.getRatedPower()).setScale(1, BigDecimal.ROUND_HALF_UP)); + + resultList.add(connectorInfo); + } + + return resultList; + } + + +}