diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/AdapayUtil.java b/jsowell-common/src/main/java/com/jsowell/common/util/AdapayUtil.java index a0da8848c..b7c7afc98 100644 --- a/jsowell-common/src/main/java/com/jsowell/common/util/AdapayUtil.java +++ b/jsowell-common/src/main/java/com/jsowell/common/util/AdapayUtil.java @@ -3,6 +3,7 @@ package com.jsowell.common.util; import lombok.extern.slf4j.Slf4j; import java.math.BigDecimal; +import java.math.RoundingMode; import java.nio.charset.StandardCharsets; import java.security.KeyFactory; import java.security.PrivateKey; @@ -19,27 +20,13 @@ import java.util.Base64; @Slf4j public class AdapayUtil { - public static void main(String[] args) { - String amount = "1110.5309"; - String s = formatAmount(amount); - System.out.println(s); - - BigDecimal bigDecimal = new BigDecimal(amount); - String s2 = formatAmount(bigDecimal); - System.out.println(s2); - } - /** * 格式化数字 保留两位小数,不足补0 * @param amount * @return */ public static String formatAmount(String amount) { - //保留2位小数 - double d = new BigDecimal(amount).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - //不足两位则补0 - DecimalFormat decimalFormat = new DecimalFormat("0.00#"); - return decimalFormat.format(d); + return formatAmount(new BigDecimal(amount)); } /** @@ -48,7 +35,34 @@ public class AdapayUtil { * @return */ public static String formatAmount(BigDecimal amount) { - return formatAmount(amount.toString()); + return formatAmount(amount, 2); + } + + /** + * 格式化数字 保留n位小数,不足补0 + * @param amount + * @return + */ + public static String formatAmount(BigDecimal amount, int n) { + //保留2位小数 + double d = amount.setScale(n, RoundingMode.DOWN).doubleValue(); + //不足则补0 + StringBuilder pattern = new StringBuilder("0"); + for (int i = 0; i < n; i++) { + if (i == 0) { + pattern.append("."); + } + pattern.append("0"); + } + DecimalFormat decimalFormat = new DecimalFormat(pattern.toString()); + return decimalFormat.format(d); + } + + public static void main(String[] args) { + BigDecimal bigDecimal = new BigDecimal("1236.8369"); + System.out.println(formatAmount(bigDecimal, 0)); + System.out.println(formatAmount(bigDecimal, 2)); + System.out.println(formatAmount(bigDecimal, 4)); } /** diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/hainan/domain/HNStationInfo.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/hainan/domain/HNStationInfo.java index e8c7fe930..5a679c684 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/hainan/domain/HNStationInfo.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/hainan/domain/HNStationInfo.java @@ -3,12 +3,9 @@ package com.jsowell.thirdparty.platform.hainan.domain; import com.alibaba.fastjson2.annotation.JSONField; import com.jsowell.thirdparty.zhongdianlian.domain.ZDLStationInfo; import lombok.AllArgsConstructor; -import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; -import java.util.List; - /** * TODO * @@ -20,12 +17,6 @@ import java.util.List; @AllArgsConstructor public class HNStationInfo extends ZDLStationInfo { - /** - * 站点照片 - */ - @JSONField(name = "Pictures") - private List pictures; - /** * 电费描述 */ @@ -38,10 +29,4 @@ public class HNStationInfo extends ZDLStationInfo { @JSONField(name = "ServiceFee") private String serviceFee; - /** - * 停车费描述 - */ - @JSONField(name = "ParkFee") - private String parkFee; - } diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/hainan/service/HaiNanPlatformLogic.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/hainan/service/HaiNanPlatformLogic.java index 052b31cd6..739448a37 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/hainan/service/HaiNanPlatformLogic.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/hainan/service/HaiNanPlatformLogic.java @@ -12,21 +12,21 @@ import com.jsowell.common.enums.thirdparty.ThirdPartyOperatorIdEnum; import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum; import com.jsowell.common.enums.ykc.OrderStatusEnum; import com.jsowell.common.enums.ykc.PileConnectorDataBaseStatusEnum; +import com.jsowell.common.util.AdapayUtil; 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.ykcCommond.StartChargingCommand; import com.jsowell.pile.domain.ykcCommond.StopChargingCommand; -import com.jsowell.pile.dto.QueryEquipChargeStatusDTO; -import com.jsowell.pile.dto.QueryEquipmentDTO; -import com.jsowell.pile.dto.QueryStartChargeDTO; -import com.jsowell.pile.dto.QueryStationInfoDTO; +import com.jsowell.pile.dto.*; import com.jsowell.pile.vo.base.ConnectorInfoVO; import com.jsowell.pile.vo.base.ThirdPartyStationInfoVO; import com.jsowell.pile.vo.base.ThirdPartyStationRelationVO; import com.jsowell.pile.vo.lianlian.AccumulativeInfoVO; import com.jsowell.pile.vo.uniapp.BillingPriceVO; +import com.jsowell.pile.vo.web.BillingTemplateVO; +import com.jsowell.pile.vo.web.EchoBillingTemplateVO; import com.jsowell.pile.vo.web.PileConnectorInfoVO; import com.jsowell.pile.vo.web.PileStationVO; import com.jsowell.pile.vo.zdl.EquipBusinessPolicyVO; @@ -41,8 +41,8 @@ import com.jsowell.thirdparty.lianlian.vo.QueryStartChargeVO; import com.jsowell.thirdparty.lianlian.vo.QueryStopChargeVO; import com.jsowell.thirdparty.platform.AbsInterfaceWithPlatformLogic; import com.jsowell.thirdparty.platform.InterfaceWithPlatformLogicFactory; +import com.jsowell.thirdparty.platform.hainan.domain.HNStationInfo; import com.jsowell.thirdparty.zhongdianlian.domain.ZDLEquipmentInfo; -import com.jsowell.thirdparty.zhongdianlian.domain.ZDLStationInfo; import org.apache.commons.collections4.CollectionUtils; import org.springframework.stereotype.Service; @@ -83,7 +83,6 @@ public class HaiNanPlatformLogic extends AbsInterfaceWithPlatformLogic { } } - List resultList = new ArrayList<>(); int pageNo = dto.getPageNo() == null ? 1 : dto.getPageNo(); int pageSize = dto.getPageSize() == null ? 10 : dto.getPageSize(); @@ -98,15 +97,18 @@ public class HaiNanPlatformLogic extends AbsInterfaceWithPlatformLogic { return null; } PageInfo pageInfo = new PageInfo<>(stationInfos); + List resultList = new ArrayList<>(); + HNStationInfo stationInfo = null; for (ThirdPartyStationInfoVO pileStationInfo : pageInfo.getList()) { - ZDLStationInfo stationInfo = new ZDLStationInfo(); - stationInfo.setStationId(String.valueOf(pileStationInfo.getId())); + stationInfo = new HNStationInfo(); + String stationId = String.valueOf(pileStationInfo.getId()); + stationInfo.setStationId(stationId); stationInfo.setOperatorId(Constants.OPERATORID_JIANG_SU); // 组织机构代码 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 { + } else { stationInfo.setEquipmentOwnerId(Constants.OPERATORID_JIANG_SU); } stationInfo.setStationName(pileStationInfo.getStationName()); @@ -138,6 +140,13 @@ public class HaiNanPlatformLogic extends AbsInterfaceWithPlatformLogic { if (CollectionUtils.isNotEmpty(pileList)) { stationInfo.setEquipmentInfos(pileList); // 充电设备信息列表 } + + Map priceDescription = getPriceDescription(stationId); + // 充电费描述 + stationInfo.setElectricityFee(priceDescription.get("electricityFee")); + // 服务费描述 + stationInfo.setServiceFee(priceDescription.get("serviceFee")); + resultList.add(stationInfo); } Map map = new LinkedHashMap<>(); @@ -160,6 +169,59 @@ public class HaiNanPlatformLogic extends AbsInterfaceWithPlatformLogic { return resultMap; } + private Map getPriceDescription(String stationId) { + Map resultMap = Maps.newHashMap(); + StringBuilder electricityFee = new StringBuilder("电费:"); + StringBuilder serviceFee = new StringBuilder("服务费:"); + + // 查询站点当前使用的计费模板 + BillingTemplateVO billingTemplate = pileBillingTemplateService.queryUsedBillingTemplate(stationId); + if (billingTemplate == null) { + resultMap.put("electricityFee", electricityFee.toString()); + resultMap.put("serviceFee", serviceFee.toString()); + return resultMap; + } + EchoBillingTemplateVO echoBillingTemplateVO = pileBillingTemplateService.queryPileBillingTemplateById(Long.parseLong(billingTemplate.getTemplateId())); + if (echoBillingTemplateVO == null) { + resultMap.put("electricityFee", electricityFee.toString()); + resultMap.put("serviceFee", serviceFee.toString()); + return resultMap; + } + + List timeArray = echoBillingTemplateVO.getTimeArray(); + for (BillingTimeDTO billingTimeDTO : timeArray) { + String type = billingTimeDTO.getType(); + String startTime = billingTimeDTO.getStartTime(); + String endTime = billingTimeDTO.getEndTime(); + + BigDecimal electricityPrice; + BigDecimal servicePrice; + if (StringUtils.equals(type, "1")) { + electricityPrice = echoBillingTemplateVO.getElectricityPriceA(); + servicePrice = echoBillingTemplateVO.getServicePriceA(); + } else if (StringUtils.equals(type, "2")) { + electricityPrice = echoBillingTemplateVO.getElectricityPriceB(); + servicePrice = echoBillingTemplateVO.getServicePriceB(); + } else if (StringUtils.equals(type, "3")) { + electricityPrice = echoBillingTemplateVO.getElectricityPriceC(); + servicePrice = echoBillingTemplateVO.getServicePriceC(); + } else { + electricityPrice = echoBillingTemplateVO.getElectricityPriceD(); + servicePrice = echoBillingTemplateVO.getServicePriceD(); + } + + electricityFee.append(startTime).append("~").append(endTime).append(":").append(AdapayUtil.formatAmount(electricityPrice, 4)).append(","); + serviceFee.append(startTime).append("~").append(endTime).append(":").append(AdapayUtil.formatAmount(servicePrice, 4)).append(","); + } + + electricityFee.deleteCharAt(electricityFee.length() - 1); + serviceFee.deleteCharAt(serviceFee.length() - 1); + + resultMap.put("electricityFee", electricityFee.toString()); + resultMap.put("serviceFee", serviceFee.toString()); + return resultMap; + } + /** * 6.3 设备状态变化推送 * @@ -261,7 +323,7 @@ public class HaiNanPlatformLogic extends AbsInterfaceWithPlatformLogic { } ConnectorStatusInfo connectorStatusInfo; for (String stationId : stationIds) { - StationStatusInfo stationStatusInfo= new StationStatusInfo(); + StationStatusInfo stationStatusInfo = new StationStatusInfo(); stationStatusInfo.setStationId(stationId); // 根据站点id查询 List list = pileConnectorInfoService.getConnectorListForLianLian(Long.parseLong(stationId)); @@ -276,7 +338,7 @@ public class HaiNanPlatformLogic extends AbsInterfaceWithPlatformLogic { continue; } List chargingRealTimeData = orderBasicInfoService.getChargingRealTimeData(orderBasicInfo.getTransactionCode()); - if(CollectionUtils.isNotEmpty(chargingRealTimeData)) { + if (CollectionUtils.isNotEmpty(chargingRealTimeData)) { RealTimeMonitorData realTimeMonitorData = chargingRealTimeData.get(0); info.setStartChargeSeq(orderBasicInfo.getOrderCode()); @@ -612,6 +674,7 @@ public class HaiNanPlatformLogic extends AbsInterfaceWithPlatformLogic { /** * 请求开始充电 + * * @param dto * @return */ @@ -707,7 +770,7 @@ public class HaiNanPlatformLogic extends AbsInterfaceWithPlatformLogic { if (StringUtils.equals(orderStatus, OrderStatusEnum.IN_THE_CHARGING.getValue())) { // 充电中 orderStatus = "2"; - }else if (StringUtils.equals(orderStatus, OrderStatusEnum.ORDER_COMPLETE.getValue())) { + } else if (StringUtils.equals(orderStatus, OrderStatusEnum.ORDER_COMPLETE.getValue())) { // 充电完成 orderStatus = "4"; } else { @@ -720,7 +783,7 @@ public class HaiNanPlatformLogic extends AbsInterfaceWithPlatformLogic { // 查询当前枪口状态 PileConnectorInfoVO connectorInfoVO = pileConnectorInfoService.getPileConnectorInfoByConnectorCode(orderInfo.getPileConnectorCode()); connectorStatus = connectorInfoVO.getStatus(); - }else { + } else { connectorStatus = Integer.parseInt(status); } BigDecimal totalElectricityAmount = orderDetail.getTotalElectricityAmount() == null ? BigDecimal.ZERO : orderDetail.getTotalElectricityAmount(); @@ -957,7 +1020,6 @@ public class HaiNanPlatformLogic extends AbsInterfaceWithPlatformLogic { /** * 推送充电订单对账信息 - * */ @Override public Map checkChargeOrders() {