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 42be0aa5f..e0236ff4a 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 @@ -95,6 +95,8 @@ public class Constants { public static final String OPERATORID_LIANLIAN = "MA1JLFUU8"; public static final String OPERATORID_JIANG_SU = "MA1X78KH5"; + public static final String MANUFACTURER_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 42d96d496..a837c7532 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 @@ -25,6 +25,7 @@ public enum ThirdPlatformTypeEnum { SHEN_ZHEN_PLATFORM("14", "深圳平台", ""), ZHE_JIANG_PLATFORM("15", "浙江省平台", "002485048"), SU_ZHOU_PLATFORM("16", "苏州市平台", "MAC1MFJ1X"), + GAN_SU_PLATFORM("17", "甘肃省平台", ""), ; private String typeCode; diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileBasicInfoServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileBasicInfoServiceImpl.java index 0903a1aad..2287b319a 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileBasicInfoServiceImpl.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileBasicInfoServiceImpl.java @@ -1111,10 +1111,12 @@ public class PileBasicInfoServiceImpl implements PileBasicInfoService { equipmentInfo.setEquipmentID(pileSn); equipmentInfo.setManufacturerID(Constants.OPERATORID_LIANLIAN); + equipmentInfo.setManufacturerName(Constants.MANUFACTURER_NAME); equipmentInfo.setConstructionTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, pileBasicInfo.getCreateTime())); PileModelInfoVO modelInfo = pileModelInfoService.getPileModelInfoByPileSn(pileSn); equipmentInfo.setEquipmentType(Integer.valueOf(modelInfo.getSpeedType())); + equipmentInfo.setEquipmentModel(modelInfo.getModelName()); // Map pileStatus = pileConnectorInfoService.getPileStatus(Lists.newArrayList(pileBasicInfo.getSn())); Map pileStatusMap = pileConnectorInfoService.getPileStatus(Lists.newArrayList(pileSn)); diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/thirdparty/EquipmentInfo.java b/jsowell-pile/src/main/java/com/jsowell/pile/thirdparty/EquipmentInfo.java index 4509ad0c5..f1cc24ad5 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/thirdparty/EquipmentInfo.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/thirdparty/EquipmentInfo.java @@ -30,6 +30,12 @@ public class EquipmentInfo { @JSONField(name = "ManufacturerID") private String manufacturerID; + /** + * 设备生产商名称 + */ + @JSONField(name = "ManufacturerName") + private String manufacturerName; + /** * 设备型号 N * 由设备生厂商定义的设备型号 diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/GanSuPlatformServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/GanSuPlatformServiceImpl.java new file mode 100644 index 000000000..3fac00429 --- /dev/null +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/GanSuPlatformServiceImpl.java @@ -0,0 +1,230 @@ +package com.jsowell.thirdparty.platform.service.impl; + +import com.alibaba.fastjson2.JSON; +import com.github.pagehelper.PageInfo; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.core.redis.RedisCache; +import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum; +import com.jsowell.common.enums.ykc.ReturnCodeEnum; +import com.jsowell.common.exception.BusinessException; +import com.jsowell.common.util.JWTUtils; +import com.jsowell.common.util.PageUtils; +import com.jsowell.common.util.StringUtils; +import com.jsowell.pile.dto.QueryStationInfoDTO; +import com.jsowell.pile.service.*; +import com.jsowell.pile.thirdparty.CommonParamsDTO; +import com.jsowell.pile.thirdparty.EquipmentInfo; +import com.jsowell.pile.vo.ThirdPartySecretInfoVO; +import com.jsowell.pile.vo.base.ThirdPartyStationInfoVO; +import com.jsowell.thirdparty.lianlian.vo.AccessTokenVO; +import com.jsowell.thirdparty.platform.domain.SupStationInfo; +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.ThirdPartyPlatformUtils; +import com.jsowell.thirdparty.service.ThirdpartySecretInfoService; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +/** + * 甘肃省平台 + * + * @author Lemon + * @Date 2024/11/5 13:31:06 + */ +public class GanSuPlatformServiceImpl implements ThirdPartyPlatformService { + + @Autowired + private ThirdpartySecretInfoService thirdpartySecretInfoService; + + @Autowired + private PileBasicInfoService pileBasicInfoService; + + @Autowired + private PileMerchantInfoService pileMerchantInfoService; + + @Autowired + private PileConnectorInfoService pileConnectorInfoService; + + @Autowired + private OrderBasicInfoService orderBasicInfoService; + + @Autowired + private PileStationInfoService pileStationInfoService; + + @Autowired + private RedisCache redisCache; + + // 平台类型 + private final String thirdPlatformType = ThirdPlatformTypeEnum.GAN_SU_PLATFORM.getTypeCode(); + + @Override + public void afterPropertiesSet() throws Exception { + ThirdPartyPlatformFactory.register(thirdPlatformType, this); + } + + /** + * 请求令牌 query_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 = dto.getOperatorID(); + // token缓存key值 + String redisKey = operatorId + "_token:"; + // 通过operatorId 查出 operatorSecret + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getGanSuSecretInfo(); + if (thirdPartySecretInfoVO == null) { + failReason = 1; + succStat = 1; + } else { + String ourOperatorSecret = thirdPartySecretInfoVO.getOurOperatorSecret(); + 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.equals(ourOperatorSecret, inputOperatorSecret)) { + failReason = 1; + succStat = 1; + } else { + // 先查缓存中是否有已生成的token + String token = redisCache.getCacheObject(redisKey); + int expiredTime = (int) redisCache.getExpire(redisKey); + if (StringUtils.isBlank(token)){ + // 生成token + token = JWTUtils.createToken(operatorId, ourOperatorSecret, JWTUtils.ttlMillis); + expiredTime = (int) (JWTUtils.ttlMillis / 1000); + } + vo.setAccessToken(token); + vo.setTokenAvailableTime(expiredTime); + // 设置缓存 + redisCache.setCacheObject(redisKey, token, expiredTime, TimeUnit.SECONDS); + } + } + // 组装返回参数 + vo.setOperatorID(operatorId); + vo.setFailReason(failReason); + vo.setSuccStat(succStat); + + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret() + , thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getOurSigSecret()); + return resultMap; + } + + /** + * 查询站点信息 query_stations_info + * @param dto 查询站点信息dto + * @return + */ + @Override + public Map queryStationsInfo(QueryStationInfoDTO dto) { + 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 thirdPartySecretInfoVO = getGanSuSecretInfo(); + + PageInfo pageInfo = new PageInfo<>(stationInfos); + List resultList = new ArrayList<>(); + for (ThirdPartyStationInfoVO pileStationInfo : pageInfo.getList()) { + String stationId = String.valueOf(pileStationInfo.getId()); + SupStationInfo stationInfo = SupStationInfo.builder() + .stationID(stationId) + .operatorID(Constants.OPERATORID_JIANG_SU) + .stationName(pileStationInfo.getStationName()) + .countryCode(pileStationInfo.getCountryCode()) + .address(pileStationInfo.getAddress()) + .stationType(Integer.parseInt(pileStationInfo.getStationType())) + .stationStatus(Integer.parseInt(pileStationInfo.getStationStatus())) + .stationLng(new BigDecimal(pileStationInfo.getStationLng())) + .stationLat(new BigDecimal(pileStationInfo.getStationLat())) + .construction(Integer.parseInt(pileStationInfo.getConstruction())) + .parkNums(Integer.parseInt(pileStationInfo.getParkNums())) + // todo .electricityFee() + // todo .serviceFee() + + .build(); + // busineHours + String busineHours = getBusineHours(); + stationInfo.setBusineHours(busineHours); + + // areaCode + String[] split = StringUtils.split(pileStationInfo.getAreaCode(), ","); + // 只取最后一部分 330213 + String subAreaCode = split[split.length - 1]; + stationInfo.setAreaCode(subAreaCode); + + // EquipmentOwnerID + String organizationCode = pileStationInfo.getOrganizationCode(); + if (StringUtils.isNotBlank(organizationCode) && organizationCode.length() == 18) { + String equipmentOwnerId = StringUtils.substring(organizationCode, organizationCode.length() - 10, organizationCode.length() - 1); + stationInfo.setEquipmentOwnerID(equipmentOwnerId); + } else { + stationInfo.setEquipmentOwnerID(Constants.OPERATORID_JIANG_SU); + } + + List pileList = pileBasicInfoService.getPileListForLianLian(stationId); + if (CollectionUtils.isNotEmpty(pileList)) { + stationInfo.setEquipmentInfos(pileList); // 充电设备信息列表 + } + resultList.add(stationInfo); + } + Map map = new LinkedHashMap<>(); + map.put("PageNo", pageInfo.getPageNum()); + map.put("PageCount", pageInfo.getPages()); + map.put("ItemSize", pageInfo.getTotal()); + map.put("StationInfos", resultList); + return ThirdPartyPlatformUtils.generateResultMap(map, thirdPartySecretInfoVO); + } + + /** + * 获取甘肃平台密钥 + * @return + */ + private ThirdPartySecretInfoVO getGanSuSecretInfo() { + String thirdPartyType = ThirdPlatformTypeEnum.GAN_SU_PLATFORM.getTypeCode(); + ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(thirdPartyType); + if (thirdPartySecretInfoVO == null) { + throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL); + } + thirdPartySecretInfoVO.setOurOperatorId(Constants.OPERATORID_JIANG_SU); + return thirdPartySecretInfoVO; + } + + private String getBusineHours() { + Map map = new LinkedHashMap<>(); + map.put("1", "[\"00:00-24:00\"]"); + map.put("2", "[\"00:00-24:00\"]"); + map.put("3", "[\"00:00-24:00\"]"); + map.put("4", "[\"00:00-24:00\"]"); + map.put("5", "[\"00:00-24:00\"]"); + map.put("6", "[\"00:00-24:00\"]"); + map.put("7", "[\"00:00-24:00\"]"); + + return map.toString(); + } +} diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/SuZhouPlatformServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/SuZhouPlatformServiceImpl.java index 54382fb50..ad1a4b7ca 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/SuZhouPlatformServiceImpl.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/SuZhouPlatformServiceImpl.java @@ -233,10 +233,8 @@ public class SuZhouPlatformServiceImpl implements ThirdPartyPlatformService { return null; } // ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); - ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(thirdPlatformType); - if (thirdPartySecretInfoVO == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getSuZhouSecretInfo(); + PageInfo pageInfo = new PageInfo<>(stationInfos); List resultList = new ArrayList<>(); for (ThirdPartyStationInfoVO pileStationInfo : pageInfo.getList()) {