diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/domain/ebike/AbsEBikeMessage.java b/jsowell-netty/src/main/java/com/jsowell/netty/domain/ebike/AbsEBikeMessage.java index bcac7aad9..3f161625f 100644 --- a/jsowell-netty/src/main/java/com/jsowell/netty/domain/ebike/AbsEBikeMessage.java +++ b/jsowell-netty/src/main/java/com/jsowell/netty/domain/ebike/AbsEBikeMessage.java @@ -1,7 +1,9 @@ package com.jsowell.netty.domain.ebike; import com.jsowell.common.util.BytesUtil; +import com.jsowell.netty.domain.ebike.deviceupload.DeviceRegister; import com.jsowell.netty.domain.ebike.deviceupload.EBikeMessageCmd03; +import com.jsowell.netty.domain.ebike.deviceupload.EBikeMessageCmd20; import com.jsowell.netty.domain.ebike.deviceupload.SettlementInfo; import com.jsowell.netty.domain.ebike.serversend.EBikeMessageCmd82; import com.jsowell.netty.domain.ebike.serversend.SpecificDataCmd82; @@ -40,6 +42,8 @@ public abstract class AbsEBikeMessage { return new EBikeMessageCmd82(header, length, physicalId, messageId, command, null, checksum, new SpecificDataCmd82(dataBytes)); case "03": return new EBikeMessageCmd03(header, length, physicalId, messageId, command, null, checksum, new SettlementInfo(dataBytes)); + case "20": + return new EBikeMessageCmd20(header, length, physicalId, messageId, command, null, checksum, new DeviceRegister(dataBytes)); default: throw new IllegalArgumentException("Unsupported command: " + command); } diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/domain/ebike/deviceupload/DeviceRegister.java b/jsowell-netty/src/main/java/com/jsowell/netty/domain/ebike/deviceupload/DeviceRegister.java new file mode 100644 index 000000000..65e81e793 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/domain/ebike/deviceupload/DeviceRegister.java @@ -0,0 +1,49 @@ +package com.jsowell.netty.domain.ebike.deviceupload; + +import com.jsowell.common.util.BytesUtil; +import lombok.Data; + +import java.util.Arrays; + +@Data +public class DeviceRegister { + /** + * 固件版本,如100则表示V1.00版本 + */ + private String firmwareVersion; + + /** + * 端口数量 表示设备总共有多少个端口 + */ + private String portNumber; + + /** + * 虚拟ID:需要内部组网的设备的本地地址,如485、LORA系列,如不需组网的设备,默认为00 + */ + private String virtualId; + + /** + * 设备类型: 见01指令中的设备类型表 + */ + private String deviceType; + + /** + * 工作模式:第0位:0=联网,1=刷卡。第1位:0=RN8209,1=BL0939。第2位:0=无短路预检,1=有短路预检。第3位:0=光耦检测模式,1=带灯模式。 + */ + private String workMode; + + /** + * 电源板版本号:电源板的固件版本号,如没有电源板的机型则为0 + */ + private String powerBoardVersion; + + public DeviceRegister(byte[] dataBytes) { + this.firmwareVersion = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, 0, 2)) + ""; + this.portNumber = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, 2, 3)) + ""; + this.virtualId = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, 3, 4)) + ""; + this.deviceType = BytesUtil.bcd2StrLittle(Arrays.copyOfRange(dataBytes, 4, 5)); + this.workMode = BytesUtil.bcd2StrLittle(Arrays.copyOfRange(dataBytes, 5, 6)); + this.powerBoardVersion = BytesUtil.bcd2StrLittle(Arrays.copyOfRange(dataBytes, 6, 8)); + } + +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/domain/ebike/deviceupload/EBikeMessageCmd20.java b/jsowell-netty/src/main/java/com/jsowell/netty/domain/ebike/deviceupload/EBikeMessageCmd20.java new file mode 100644 index 000000000..f7593f616 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/domain/ebike/deviceupload/EBikeMessageCmd20.java @@ -0,0 +1,27 @@ +package com.jsowell.netty.domain.ebike.deviceupload; + +import com.jsowell.netty.domain.ebike.AbsEBikeMessage; +import lombok.Data; + +/** + * 设备注册包(20指令) + */ +@Data +public class EBikeMessageCmd20 extends AbsEBikeMessage { + + private DeviceRegister deviceRegister; + + public EBikeMessageCmd20(String header, int length, int physicalId, int messageId, String command, Object payload, int checksum, DeviceRegister deviceRegister) { + super(header, length, physicalId, messageId, command, payload, checksum); + this.deviceRegister = deviceRegister; + } + + @Override + public void parsePayload(byte[] dataBytes) { + this.deviceRegister = new DeviceRegister(dataBytes); + } + + public DeviceRegister getDeviceRegister() { + return deviceRegister; + } +} \ No newline at end of file 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 4f5e70540..0d787f9f5 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 @@ -1220,7 +1220,6 @@ public class PileBasicInfoServiceImpl implements PileBasicInfoService { dto.setMerchantId(pileConnectorDetailVO.getMerchantId()); dto.setStationId(pileConnectorDetailVO.getStationId()); // 获取处理逻辑 - // String mode = pileMerchantInfoService.getDelayModeByAppIdAndRequestSource(dto.getAppId(), dto.getRequestSource()); String mode = pileMerchantInfoService.getDelayModeByMerchantId(pileConnectorDetailVO.getMerchantId()); AbstractProgramLogic orderLogic = ProgramLogicFactory.getProgramLogic(mode); return orderLogic.startPersonalPileCharging(dto); diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileStationInfoServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileStationInfoServiceImpl.java index a27bef474..bb0432d15 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileStationInfoServiceImpl.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileStationInfoServiceImpl.java @@ -1,5 +1,6 @@ package com.jsowell.pile.service.impl; +import cn.hutool.core.util.CoordinateUtil; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.google.common.collect.Lists; @@ -13,7 +14,10 @@ import com.jsowell.common.core.redis.RedisCache; 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.common.util.DateUtils; +import com.jsowell.common.util.DistanceUtils; +import com.jsowell.common.util.SecurityUtils; +import com.jsowell.common.util.StringUtils; import com.jsowell.common.util.ip.AddressUtils; import com.jsowell.pile.domain.PileBasicInfo; import com.jsowell.pile.domain.PileStationInfo; @@ -26,18 +30,16 @@ import com.jsowell.pile.dto.ningxiajiaotou.NXJTQueryStationInfoDTO; import com.jsowell.pile.mapper.PileStationInfoMapper; import com.jsowell.pile.service.*; import com.jsowell.pile.util.UserUtils; -import com.jsowell.pile.vo.uniapp.business.BusinessOrderDetailInfoVO; -import com.jsowell.pile.vo.uniapp.business.StationBusinessAnalyzeInfoVO; import com.jsowell.pile.vo.base.*; import com.jsowell.pile.vo.ningxiajiaotou.NXJTStationInfoVO; +import com.jsowell.pile.vo.uniapp.business.BusinessOrderDetailInfoVO; +import com.jsowell.pile.vo.uniapp.business.StationBusinessAnalyzeInfoVO; import com.jsowell.pile.vo.uniapp.business.StationOrderQuantityInfoVO; import com.jsowell.pile.vo.uniapp.business.StationStatisticsInfosVO; import com.jsowell.pile.vo.uniapp.customer.CurrentTimePriceDetails; import com.jsowell.pile.vo.web.PileStationVO; import com.jsowell.system.service.SysDeptService; import com.jsowell.system.service.SysUserService; -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.springframework.beans.factory.annotation.Autowired; @@ -63,1112 +65,1138 @@ import java.util.stream.Collectors; @Slf4j @Service public class PileStationInfoServiceImpl implements PileStationInfoService { - @Autowired - private PileStationInfoMapper pileStationInfoMapper; + @Autowired + private PileStationInfoMapper pileStationInfoMapper; - @Autowired - private PileConnectorInfoService pileConnectorInfoService; + @Autowired + private PileConnectorInfoService pileConnectorInfoService; - @Autowired - private PileBillingTemplateService pileBillingTemplateService; + @Autowired + private PileBillingTemplateService pileBillingTemplateService; - @Autowired - private PileMerchantInfoService pileMerchantInfoService; + @Autowired + private PileMerchantInfoService pileMerchantInfoService; - @Autowired - private SysDeptService sysDeptService; + @Autowired + private SysDeptService sysDeptService; - @Autowired - private PileBasicInfoService pileBasicInfoService; + @Autowired + private PileBasicInfoService pileBasicInfoService; - @Autowired - private RedisCache redisCache; + @Autowired + private RedisCache redisCache; - @Autowired - private SysUserService userService; + @Autowired + private SysUserService userService; - @Autowired - private ThirdPartyParkingConfigService parkingConfigService; + @Autowired + private ThirdPartyParkingConfigService parkingConfigService; - @Autowired - private OrderBasicInfoService orderBasicInfoService; + @Autowired + private OrderBasicInfoService orderBasicInfoService; - @Autowired - private SettleOrderReportService settleOrderReportService; + @Autowired + private SettleOrderReportService settleOrderReportService; - /** - * 查询充电站信息 - * - * @param id 充电站信息主键 - * @return 充电站信息 - */ - @Override - public PileStationInfo selectPileStationInfoById(Long id) { - // 加缓存 - String redisKey = CacheConstants.SELECT_PILE_STATION_INFO_BY_ID + id; - PileStationInfo pileStationInfo = redisCache.getCacheObject(redisKey); - if (pileStationInfo == null) { - // 查数据库 - pileStationInfo = pileStationInfoMapper.selectPileStationInfoById(id); - redisCache.setCacheObject(redisKey, pileStationInfo, 15, TimeUnit.MINUTES); - } - return pileStationInfo; - } + /** + * 查询充电站信息 + * + * @param id 充电站信息主键 + * @return 充电站信息 + */ + @Override + public PileStationInfo selectPileStationInfoById(Long id) { + // 加缓存 + String redisKey = CacheConstants.SELECT_PILE_STATION_INFO_BY_ID + id; + PileStationInfo pileStationInfo = redisCache.getCacheObject(redisKey); + if (pileStationInfo == null) { + // 查数据库 + pileStationInfo = pileStationInfoMapper.selectPileStationInfoById(id); + redisCache.setCacheObject(redisKey, pileStationInfo, 15, TimeUnit.MINUTES); + } + return pileStationInfo; + } - /** - * 查询站点基本资料 - * 加缓存 - * @param stationId - * @return - */ - @Override - public PileStationVO getStationInfo(String stationId) { - PileStationVO vo = new PileStationVO(); - PileStationInfo pileStationInfo = selectPileStationInfoById(Long.parseLong(stationId)); - // 查计费模板 - CurrentTimePriceDetails currentTimePriceDetails = pileBillingTemplateService.getCurrentTimePriceDetails(stationId); - if (currentTimePriceDetails != null) { - String electricityPrice = currentTimePriceDetails.getElectricityPrice(); - electricityPrice = StringUtils.isBlank(electricityPrice) ? "0" : electricityPrice; + /** + * 查询站点基本资料 + * 加缓存 + * + * @param stationId + * @return + */ + @Override + public PileStationVO getStationInfo(String stationId) { + PileStationVO vo = new PileStationVO(); + PileStationInfo pileStationInfo = selectPileStationInfoById(Long.parseLong(stationId)); + // 查计费模板 + CurrentTimePriceDetails currentTimePriceDetails = pileBillingTemplateService.getCurrentTimePriceDetails(stationId); + if (currentTimePriceDetails != null) { + String electricityPrice = currentTimePriceDetails.getElectricityPrice(); + electricityPrice = StringUtils.isBlank(electricityPrice) ? "0" : electricityPrice; - String servicePrice = currentTimePriceDetails.getServicePrice(); - servicePrice = StringUtils.isBlank(servicePrice) ? "0" : servicePrice; + String servicePrice = currentTimePriceDetails.getServicePrice(); + servicePrice = StringUtils.isBlank(servicePrice) ? "0" : servicePrice; - vo.setElectricityPrice(new BigDecimal(electricityPrice)); - vo.setServicePrice(new BigDecimal(servicePrice)); + vo.setElectricityPrice(new BigDecimal(electricityPrice)); + vo.setServicePrice(new BigDecimal(servicePrice)); - if (StringUtils.isNotBlank(String.valueOf(currentTimePriceDetails.getFreeTime()))) { - vo.setFreeTime(currentTimePriceDetails.getFreeTime()); - } - if (StringUtils.isNotBlank(String.valueOf(currentTimePriceDetails.getOccupyFee()))) { - vo.setOccupyFee(currentTimePriceDetails.getOccupyFee()); - } - } + if (StringUtils.isNotBlank(String.valueOf(currentTimePriceDetails.getFreeTime()))) { + vo.setFreeTime(currentTimePriceDetails.getFreeTime()); + } + if (StringUtils.isNotBlank(String.valueOf(currentTimePriceDetails.getOccupyFee()))) { + vo.setOccupyFee(currentTimePriceDetails.getOccupyFee()); + } + } - if (pileStationInfo != null) { - vo.setMerchantId(pileStationInfo.getMerchantId().toString()); - vo.setStationName(pileStationInfo.getStationName()); - vo.setId(pileStationInfo.getId().toString()); - vo.setAreaCode(pileStationInfo.getAreaCode()); - vo.setAddress(pileStationInfo.getAddress()); - if (StringUtils.isNotBlank(pileStationInfo.getParkingId())) { - vo.setParkingId(pileStationInfo.getParkingId()); - } - if (StringUtils.isNotBlank(pileStationInfo.getQrcodePrefix())) { - vo.setQrcodePrefix(pileStationInfo.getQrcodePrefix()); - } - if (StringUtils.isNotBlank(pileStationInfo.getParkingNumber())) { - vo.setParkingNumber(pileStationInfo.getParkingNumber()); - } - if (StringUtils.isNotBlank(pileStationInfo.getParkFeeDescribe())) { - vo.setParkFeeDescribe(pileStationInfo.getParkFeeDescribe()); - } - if (StringUtils.isNotBlank(pileStationInfo.getAccountNumber())) { - vo.setAccountNumber(pileStationInfo.getAccountNumber()); - } - if (StringUtils.isNotBlank(String.valueOf(pileStationInfo.getCapacity()))) { - vo.setCapacity(pileStationInfo.getCapacity()); - } - if (StringUtils.isNotBlank(pileStationInfo.getOperatorName())) { - vo.setOperatorName(pileStationInfo.getOperatorName()); - } - if (StringUtils.isNotBlank(pileStationInfo.getAMapStationName())) { - vo.setAMapStationName(pileStationInfo.getAMapStationName()); - } - vo.setMerchantAdminName(pileStationInfo.getStationAdminName()); - vo.setStationStatus(Integer.parseInt(pileStationInfo.getStationStatus())); - vo.setStationType(pileStationInfo.getStationType()); - vo.setCreateTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, pileStationInfo.getCreateTime())); - vo.setStationTel(pileStationInfo.getStationTel()); - vo.setMatchCars(pileStationInfo.getMatchCars()); - if (StringUtils.isNotBlank(pileStationInfo.getMatchCars())) { - vo.setSelectMatchCars(Lists.newArrayList(pileStationInfo.getMatchCars().split(","))); - } - vo.setStationLat(pileStationInfo.getStationLat()); - vo.setStationLng(pileStationInfo.getStationLng()); - vo.setCountryCode(pileStationInfo.getCountryCode()); - vo.setConstruction(pileStationInfo.getConstruction()); - vo.setBusinessHours(pileStationInfo.getBusinessHours()); - // vo.setOrganizationCode(pileStationInfo.getor); - vo.setPublicFlag(pileStationInfo.getPublicFlag()); - vo.setOpenFlag(pileStationInfo.getOpenFlag()); - vo.setOpenAllDay(pileStationInfo.getOpenAllDay()); - vo.setDeptId(pileStationInfo.getDeptId()); - if (StringUtils.isNotBlank(pileStationInfo.getPictures())) { - vo.setPictures(pileStationInfo.getPictures()); - vo.setPictureList(Lists.newArrayList(pileStationInfo.getPictures().split(","))); - } - } - return vo; - } + if (pileStationInfo != null) { + vo.setMerchantId(pileStationInfo.getMerchantId().toString()); + vo.setStationName(pileStationInfo.getStationName()); + vo.setId(pileStationInfo.getId().toString()); + vo.setAreaCode(pileStationInfo.getAreaCode()); + vo.setAddress(pileStationInfo.getAddress()); + if (StringUtils.isNotBlank(pileStationInfo.getParkingId())) { + vo.setParkingId(pileStationInfo.getParkingId()); + } + if (StringUtils.isNotBlank(pileStationInfo.getQrcodePrefix())) { + vo.setQrcodePrefix(pileStationInfo.getQrcodePrefix()); + } + if (StringUtils.isNotBlank(pileStationInfo.getParkingNumber())) { + vo.setParkingNumber(pileStationInfo.getParkingNumber()); + } + if (StringUtils.isNotBlank(pileStationInfo.getParkFeeDescribe())) { + vo.setParkFeeDescribe(pileStationInfo.getParkFeeDescribe()); + } + if (StringUtils.isNotBlank(pileStationInfo.getAccountNumber())) { + vo.setAccountNumber(pileStationInfo.getAccountNumber()); + } + if (StringUtils.isNotBlank(String.valueOf(pileStationInfo.getCapacity()))) { + vo.setCapacity(pileStationInfo.getCapacity()); + } + if (StringUtils.isNotBlank(pileStationInfo.getOperatorName())) { + vo.setOperatorName(pileStationInfo.getOperatorName()); + } + if (StringUtils.isNotBlank(pileStationInfo.getAMapStationName())) { + vo.setAMapStationName(pileStationInfo.getAMapStationName()); + } + vo.setMerchantAdminName(pileStationInfo.getStationAdminName()); + vo.setStationStatus(Integer.parseInt(pileStationInfo.getStationStatus())); + vo.setStationType(pileStationInfo.getStationType()); + vo.setCreateTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, pileStationInfo.getCreateTime())); + vo.setStationTel(pileStationInfo.getStationTel()); + vo.setMatchCars(pileStationInfo.getMatchCars()); + if (StringUtils.isNotBlank(pileStationInfo.getMatchCars())) { + vo.setSelectMatchCars(Lists.newArrayList(pileStationInfo.getMatchCars().split(","))); + } + vo.setStationLat(pileStationInfo.getStationLat()); + vo.setStationLng(pileStationInfo.getStationLng()); + vo.setCountryCode(pileStationInfo.getCountryCode()); + vo.setConstruction(pileStationInfo.getConstruction()); + vo.setBusinessHours(pileStationInfo.getBusinessHours()); + // vo.setOrganizationCode(pileStationInfo.getor); + vo.setPublicFlag(pileStationInfo.getPublicFlag()); + vo.setOpenFlag(pileStationInfo.getOpenFlag()); + vo.setOpenAllDay(pileStationInfo.getOpenAllDay()); + vo.setDeptId(pileStationInfo.getDeptId()); + if (StringUtils.isNotBlank(pileStationInfo.getPictures())) { + vo.setPictures(pileStationInfo.getPictures()); + vo.setPictureList(Lists.newArrayList(pileStationInfo.getPictures().split(","))); + } + } + return vo; + } - /** - * 通过充电桩枪口编号查询充电站信息 - * @param pileConnectorCode 充电桩枪口编号 - * @return 充电站信息 - */ - @Override - public PileStationVO getStationInfoByPileConnectorCode(String pileConnectorCode) { - if (StringUtils.isBlank(pileConnectorCode)) { - return null; - } - String pileSn = StringUtils.substring(pileConnectorCode, 0, 14); - return getStationInfoByPileSn(pileSn); - } + /** + * 通过充电桩枪口编号查询充电站信息 + * + * @param pileConnectorCode 充电桩枪口编号 + * @return 充电站信息 + */ + @Override + public PileStationVO getStationInfoByPileConnectorCode(String pileConnectorCode) { + if (StringUtils.isBlank(pileConnectorCode)) { + return null; + } + String pileSn = StringUtils.substring(pileConnectorCode, 0, 14); + return getStationInfoByPileSn(pileSn); + } - /** - * 通过充电桩sn查询充电站信息 - * @param pileSn 充电桩sn - * @return 充电站信息 - */ - @Override - public PileStationVO getStationInfoByPileSn(String pileSn) { - // 通过pileSn查询充电桩(缓存方法) - PileInfoVO pileInfoVO = pileBasicInfoService.selectPileInfoBySn(pileSn); - if (pileInfoVO == null) { - return null; - } - // 通过stationId查询充电站信息(缓存方法) - PileStationVO stationInfo = getStationInfo(pileInfoVO.getStationId()); - return stationInfo; - } + /** + * 通过充电桩sn查询充电站信息 + * + * @param pileSn 充电桩sn + * @return 充电站信息 + */ + @Override + public PileStationVO getStationInfoByPileSn(String pileSn) { + // 通过pileSn查询充电桩(缓存方法) + PileInfoVO pileInfoVO = pileBasicInfoService.selectPileInfoBySn(pileSn); + if (pileInfoVO == null) { + return null; + } + // 通过stationId查询充电站信息(缓存方法) + PileStationVO stationInfo = getStationInfo(pileInfoVO.getStationId()); + return stationInfo; + } - @Override - public List getStationInfosByThirdParty(QueryStationInfoDTO dto) { - // PageUtils.startPage(pageNum, pageSize); - return pileStationInfoMapper.getStationInfoForThirdParty(dto); - } + @Override + public List getStationInfosByThirdParty(QueryStationInfoDTO dto) { + // PageUtils.startPage(pageNum, pageSize); + return pileStationInfoMapper.getStationInfoForThirdParty(dto); + } - @Override - public List selectStationInfosByThirdParty(QueryStationInfoDTO dto) { - return pileStationInfoMapper.selectStationInfoForThirdParty(dto); - } + @Override + public List selectStationInfosByThirdParty(QueryStationInfoDTO dto) { + return pileStationInfoMapper.selectStationInfoForThirdParty(dto); + } - @Override - public List getStationInfosByAmap(GetStationInfoDTO dto) { - return pileStationInfoMapper.getStationInfoForAmap(dto); - } + @Override + public List getStationInfosByAmap(GetStationInfoDTO dto) { + return pileStationInfoMapper.getStationInfoForAmap(dto); + } - @Override - public List queryByStationDeptIds(List stationIds) { - return pileStationInfoMapper.queryByStationDeptIds(stationIds); - } + @Override + public List queryByStationDeptIds(List stationIds) { + return pileStationInfoMapper.queryByStationDeptIds(stationIds); + } - /** - * 查询充电站信息列表 - * - * @param pileStationInfo 充电站信息 - * @return 充电站信息 - */ - @Override - public List selectPileStationInfoList(PileStationInfo pileStationInfo) { - return pileStationInfoMapper.selectPileStationInfoList(pileStationInfo); - } + /** + * 查询充电站信息列表 + * + * @param pileStationInfo 充电站信息 + * @return 充电站信息 + */ + @Override + public List selectPileStationInfoList(PileStationInfo pileStationInfo) { + return pileStationInfoMapper.selectPileStationInfoList(pileStationInfo); + } - /** - * 通过运营商id查询站点信息 - * - * @param merchantId 运营商id - * @return 站点信息列表 - */ + /** + * 通过运营商id查询站点信息 + * + * @param merchantId 运营商id + * @return 站点信息列表 + */ @Override public List selectStationListByMerchantId(Long merchantId) { return pileStationInfoMapper.selectStationListByMerchantId(merchantId); } - /** - * 通过运营商id查询站点信息(带权限校验) - * - * @param merchantId 运营商id - * @return 站点信息列表 - */ - @Override - public List selectStationListByMerchantIdWithAuth(Long merchantId) { - AuthorizedDeptVO authorizedMap = UserUtils.getAuthorizedMap(); - if (authorizedMap == null) { - return null; - } - List pileStationInfos = pileStationInfoMapper.selectStationListByMerchantId(merchantId); - // 站点管理员 - if (CollectionUtils.isNotEmpty(authorizedMap.getStationDeptIds())) { - List stationDeptIds = authorizedMap.getStationDeptIds(); - // 筛选出来符合deptIds的数据 - pileStationInfos = pileStationInfos.stream() - .filter(pileStationInfo -> stationDeptIds.contains(pileStationInfo.getDeptId())) - .collect(Collectors.toList()); - } - return pileStationInfos; - } + /** + * 通过运营商id查询站点信息(带权限校验) + * + * @param merchantId 运营商id + * @return 站点信息列表 + */ + @Override + public List selectStationListByMerchantIdWithAuth(Long merchantId) { + AuthorizedDeptVO authorizedMap = UserUtils.getAuthorizedMap(); + if (authorizedMap == null) { + return null; + } + List pileStationInfos = pileStationInfoMapper.selectStationListByMerchantId(merchantId); + // 站点管理员 + if (CollectionUtils.isNotEmpty(authorizedMap.getStationDeptIds())) { + List stationDeptIds = authorizedMap.getStationDeptIds(); + // 筛选出来符合deptIds的数据 + pileStationInfos = pileStationInfos.stream() + .filter(pileStationInfo -> stationDeptIds.contains(pileStationInfo.getDeptId())) + .collect(Collectors.toList()); + } + return pileStationInfos; + } /** - * 新增充电站信息 - * - * @param pileStationInfo 充电站信息 - * @return 结果 - */ - @Override + * 新增充电站信息 + * + * @param pileStationInfo 充电站信息 + * @return 结果 + */ + @Override - public int insertPileStationInfo(PileStationInfo pileStationInfo) { - pileStationInfo.setCreateTime(DateUtils.getNowDate()); - pileStationInfo.setCreateBy(SecurityUtils.getUsername()); - return pileStationInfoMapper.insertPileStationInfo(pileStationInfo); - } + public int insertPileStationInfo(PileStationInfo pileStationInfo) { + pileStationInfo.setCreateTime(DateUtils.getNowDate()); + pileStationInfo.setCreateBy(SecurityUtils.getUsername()); + return pileStationInfoMapper.insertPileStationInfo(pileStationInfo); + } - /** - * 快速建站 - * @param dto - * @return - */ - @Override - @Transactional(readOnly = false, propagation = Propagation.REQUIRED) - public int fastCreateStation(FastCreateStationDTO dto) { - MerchantInfoVO merchantInfo = pileMerchantInfoService.getMerchantInfoVO(dto.getMerchantId()); - if (merchantInfo == null) { - return 0; - } + /** + * 快速建站 + * + * @param dto + * @return + */ + @Override + @Transactional(readOnly = false, propagation = Propagation.REQUIRED) + public int fastCreateStation(FastCreateStationDTO dto) { + MerchantInfoVO merchantInfo = pileMerchantInfoService.getMerchantInfoVO(dto.getMerchantId()); + if (merchantInfo == null) { + return 0; + } - // 创建站点对应部门 - SysDept dept = sysDeptService.createStationDept(Long.valueOf(merchantInfo.getDeptId()), dto.getStationName(), dto.getStationAdminName(), dto.getStationTel()); + // 创建站点对应部门 + SysDept dept = sysDeptService.createStationDept(Long.valueOf(merchantInfo.getDeptId()), dto.getStationName(), dto.getStationAdminName(), dto.getStationTel()); - PileStationInfo pileStationInfo = new PileStationInfo(); - pileStationInfo.setDeptId(String.valueOf(dept.getDeptId())); - // 前端输入信息 - pileStationInfo.setMerchantId(Long.valueOf(dto.getMerchantId())); - pileStationInfo.setStationName(StringUtils.trim(dto.getStationName())); - pileStationInfo.setAddress(StringUtils.trim(dto.getAddress())); - pileStationInfo.setAreaCode(StringUtils.trim(dto.getAreaCode())); - pileStationInfo.setCapacity(BigDecimal.ZERO); // 容量 - pileStationInfo.setStationTel(StringUtils.trim(dto.getStationTel())); - pileStationInfo.setStationAdminName(StringUtils.trim(dto.getStationAdminName())); - // 获取经纬度 - Map longitudeAndLatitude = AddressUtils.getLongitudeAndLatitude(dto.getAreaCode(), dto.getAddress()); - if (longitudeAndLatitude != null) { - pileStationInfo.setStationLng(longitudeAndLatitude.get("lng")); - pileStationInfo.setStationLat(longitudeAndLatitude.get("lat")); - } - pileStationInfo.setCreateBy(SecurityUtils.getUsername()); - int i = pileStationInfoMapper.insertPileStationInfo(pileStationInfo); - return i; - } + PileStationInfo pileStationInfo = new PileStationInfo(); + pileStationInfo.setDeptId(String.valueOf(dept.getDeptId())); + // 前端输入信息 + pileStationInfo.setMerchantId(Long.valueOf(dto.getMerchantId())); + pileStationInfo.setStationName(StringUtils.trim(dto.getStationName())); + pileStationInfo.setAddress(StringUtils.trim(dto.getAddress())); + pileStationInfo.setAreaCode(StringUtils.trim(dto.getAreaCode())); + pileStationInfo.setCapacity(BigDecimal.ZERO); // 容量 + pileStationInfo.setStationTel(StringUtils.trim(dto.getStationTel())); + pileStationInfo.setStationAdminName(StringUtils.trim(dto.getStationAdminName())); + // 获取经纬度 + Map longitudeAndLatitude = AddressUtils.getLongitudeAndLatitude(dto.getAreaCode(), dto.getAddress()); + if (longitudeAndLatitude != null) { + pileStationInfo.setStationLng(longitudeAndLatitude.get("lng")); + pileStationInfo.setStationLat(longitudeAndLatitude.get("lat")); + } + pileStationInfo.setCreateBy(SecurityUtils.getUsername()); + int i = pileStationInfoMapper.insertPileStationInfo(pileStationInfo); + return i; + } - /** - * 修改充电站信息 - * - * @param pileStationInfo 充电站信息 - * @return 结果 - */ - @Override - @Transactional(readOnly = false, propagation = Propagation.REQUIRED) - public int updatePileStationInfo(PileStationInfo pileStationInfo) { - // 清缓存 - String redisKey = CacheConstants.SELECT_PILE_STATION_INFO_BY_ID + pileStationInfo.getId(); - redisCache.deleteObject(redisKey); + /** + * 修改充电站信息 + * + * @param pileStationInfo 充电站信息 + * @return 结果 + */ + @Override + @Transactional(readOnly = false, propagation = Propagation.REQUIRED) + public int updatePileStationInfo(PileStationInfo pileStationInfo) { + // 清缓存 + String redisKey = CacheConstants.SELECT_PILE_STATION_INFO_BY_ID + pileStationInfo.getId(); + redisCache.deleteObject(redisKey); - String templateRedisKey = CacheConstants.QUERY_STATION_BILLING_TEMPLATE_LIST + pileStationInfo.getId(); - redisCache.deleteObject(templateRedisKey); + String templateRedisKey = CacheConstants.QUERY_STATION_BILLING_TEMPLATE_LIST + pileStationInfo.getId(); + redisCache.deleteObject(templateRedisKey); - // 先查询一下当前数据库的充电站数据 - PileStationInfo queryStationInfo = selectPileStationInfoById(pileStationInfo.getId()); - String oldMerchantId = String.valueOf(queryStationInfo.getMerchantId()); - String newMerchantId = String.valueOf(pileStationInfo.getMerchantId()); - // 对比一下运营商有没有变化 - if (!StringUtils.equals(oldMerchantId, newMerchantId)) { - // 新旧运营商不一致,执行站点更换运营商逻辑 - stationUpdateMerchant(pileStationInfo, newMerchantId); - } else { - // 查询部门 - SysDept sysDept = sysDeptService.selectDeptById(Long.parseLong(pileStationInfo.getDeptId())); - // 同步组织中的名称,联系人,电话 - if (sysDept != null) { - sysDept.setDeptName(pileStationInfo.getStationName()); - sysDept.setLeader(pileStationInfo.getStationAdminName()); - sysDept.setPhone(pileStationInfo.getStationTel()); - sysDept.setUpdateTime(DateUtils.getNowDate()); - sysDept.setDeptLevel("3"); - // 修改站点对应的部门 - sysDeptService.updateDept(sysDept); - } - } + // 先查询一下当前数据库的充电站数据 + PileStationInfo queryStationInfo = selectPileStationInfoById(pileStationInfo.getId()); + String oldMerchantId = String.valueOf(queryStationInfo.getMerchantId()); + String newMerchantId = String.valueOf(pileStationInfo.getMerchantId()); + // 对比一下运营商有没有变化 + if (!StringUtils.equals(oldMerchantId, newMerchantId)) { + // 新旧运营商不一致,执行站点更换运营商逻辑 + stationUpdateMerchant(pileStationInfo, newMerchantId); + } else { + // 查询部门 + SysDept sysDept = sysDeptService.selectDeptById(Long.parseLong(pileStationInfo.getDeptId())); + // 同步组织中的名称,联系人,电话 + if (sysDept != null) { + sysDept.setDeptName(pileStationInfo.getStationName()); + sysDept.setLeader(pileStationInfo.getStationAdminName()); + sysDept.setPhone(pileStationInfo.getStationTel()); + sysDept.setUpdateTime(DateUtils.getNowDate()); + sysDept.setDeptLevel("3"); + // 修改站点对应的部门 + sysDeptService.updateDept(sysDept); + } + } - pileStationInfo.setUpdateBy(SecurityUtils.getUsername()); - pileStationInfo.setUpdateTime(DateUtils.getNowDate()); - int i = pileStationInfoMapper.updatePileStationInfo(pileStationInfo); + // 2024年8月16日14点15分 天地图坐标转高德坐标 + if (StringUtils.isNotBlank(pileStationInfo.getStationLng()) && StringUtils.isNotBlank(pileStationInfo.getStationLat())) { + // 获取经纬度 + CoordinateUtil.Coordinate coordinate = CoordinateUtil.wgs84ToGcj02(Double.parseDouble(pileStationInfo.getStationLng()), Double.parseDouble(pileStationInfo.getStationLat())); + if (coordinate != null) { + pileStationInfo.setStationLng(String.valueOf(coordinate.getLng())); + pileStationInfo.setStationLat(String.valueOf(coordinate.getLat())); + } + } - // 再次清缓存 - redisCache.deleteObject(redisKey); - return i; - } - /** - * 充电站更换运营商逻辑 - */ - private void stationUpdateMerchant(PileStationInfo pileStationInfo, String newMerchantId) { + pileStationInfo.setUpdateBy(SecurityUtils.getUsername()); + pileStationInfo.setUpdateTime(DateUtils.getNowDate()); + int i = pileStationInfoMapper.updatePileStationInfo(pileStationInfo); + + // 再次清缓存 + redisCache.deleteObject(redisKey); + return i; + } + + /** + * 充电站更换运营商逻辑 + */ + private void stationUpdateMerchant(PileStationInfo pileStationInfo, String newMerchantId) { /* 修改充电桩所属运营商 */ - List pileInfoList = pileBasicInfoService.getPileListByStationId(String.valueOf(pileStationInfo.getId())); - if (CollectionUtils.isNotEmpty(pileInfoList)) { - List pileIdList = pileInfoList.stream().map(PileBasicInfo::getId).collect(Collectors.toList()); - // 修改桩基本信息 - pileBasicInfoService.updatePileMerchantBatch(pileIdList, newMerchantId); - } + List pileInfoList = pileBasicInfoService.getPileListByStationId(String.valueOf(pileStationInfo.getId())); + if (CollectionUtils.isNotEmpty(pileInfoList)) { + List pileIdList = pileInfoList.stream().map(PileBasicInfo::getId).collect(Collectors.toList()); + // 修改桩基本信息 + pileBasicInfoService.updatePileMerchantBatch(pileIdList, newMerchantId); + } /* 修改组织部门 */ - MerchantInfoVO merchantInfo = pileMerchantInfoService.getMerchantInfoVO(newMerchantId); - if (merchantInfo != null) { - // 创建一个新的站点对应部门 - SysDept dept = sysDeptService.createStationDept(Long.valueOf(merchantInfo.getDeptId()), - pileStationInfo.getStationName(), pileStationInfo.getStationAdminName(), pileStationInfo.getStationTel()); - Long newDeptId = dept.getDeptId(); + MerchantInfoVO merchantInfo = pileMerchantInfoService.getMerchantInfoVO(newMerchantId); + if (merchantInfo != null) { + // 创建一个新的站点对应部门 + SysDept dept = sysDeptService.createStationDept(Long.valueOf(merchantInfo.getDeptId()), + pileStationInfo.getStationName(), pileStationInfo.getStationAdminName(), pileStationInfo.getStationTel()); + Long newDeptId = dept.getDeptId(); - // 修改账号归属部门 - SysUser user = new SysUser(); - user.setDeptId(Long.valueOf(pileStationInfo.getDeptId())); - List userList = userService.selectUserList(user); - if (CollectionUtils.isNotEmpty(userList)) { - for (SysUser sysUser : userList) { - sysUser.setDeptId(newDeptId); - userService.updateUser(sysUser); - } - } + // 修改账号归属部门 + SysUser user = new SysUser(); + user.setDeptId(Long.valueOf(pileStationInfo.getDeptId())); + List userList = userService.selectUserList(user); + if (CollectionUtils.isNotEmpty(userList)) { + for (SysUser sysUser : userList) { + sysUser.setDeptId(newDeptId); + userService.updateUser(sysUser); + } + } - // 逻辑删除老的部门 - sysDeptService.deleteDeptById(Long.parseLong(pileStationInfo.getDeptId())); + // 逻辑删除老的部门 + sysDeptService.deleteDeptById(Long.parseLong(pileStationInfo.getDeptId())); - // 设置新部门id - pileStationInfo.setDeptId(String.valueOf(newDeptId)); - } + // 设置新部门id + pileStationInfo.setDeptId(String.valueOf(newDeptId)); + } - /** - * 修改订单中的 merchantId - */ - orderBasicInfoService.updateMerchantByStationId(pileStationInfo.getId(), newMerchantId); + /** + * 修改订单中的 merchantId + */ + orderBasicInfoService.updateMerchantByStationId(pileStationInfo.getId(), newMerchantId); - } + } - /** - * 批量删除充电站信息 - * - * @param ids 需要删除的充电站信息主键 - * @return 结果 - */ - @Override - public int deletePileStationInfoByIds(Long[] ids) { - return pileStationInfoMapper.deletePileStationInfoByIds(ids); - } + /** + * 批量删除充电站信息 + * + * @param ids 需要删除的充电站信息主键 + * @return 结果 + */ + @Override + public int deletePileStationInfoByIds(Long[] ids) { + return pileStationInfoMapper.deletePileStationInfoByIds(ids); + } - /** - * 充电站列表信息 - * @param dto 前台参数 - * @return 充电站对象集合 - */ - @Override - // @DataScope(deptAlias = "t3") - public List queryStationInfos(QueryStationDTO dto) { - AuthorizedDeptVO authorizedMap = UserUtils.getAuthorizedMap(); - if (authorizedMap == null) { - // 为空表示没有权限,返回空数组 - return Lists.newArrayList(); - } - dto.setStationDeptIds(authorizedMap.getStationDeptIds()); - dto.setMerchantDeptIds(authorizedMap.getMerchantDeptIds()); - List list = pileStationInfoMapper.queryStationInfos(dto); - return list; - } + /** + * 充电站列表信息 + * + * @param dto 前台参数 + * @return 充电站对象集合 + */ + @Override + // @DataScope(deptAlias = "t3") + public List queryStationInfos(QueryStationDTO dto) { + AuthorizedDeptVO authorizedMap = UserUtils.getAuthorizedMap(); + if (authorizedMap == null) { + // 为空表示没有权限,返回空数组 + return Lists.newArrayList(); + } + dto.setStationDeptIds(authorizedMap.getStationDeptIds()); + dto.setMerchantDeptIds(authorizedMap.getMerchantDeptIds()); + List list = pileStationInfoMapper.queryStationInfos(dto); + return list; + } - /** - * uniApp查询充电站信息并通过经纬度排序 - * - * @param dto 前台参数 - * @return 充电站对象集合 - */ - @Override - public PageResponse uniAppQueryStationInfoList(QueryStationDTO dto) { - int pageNum = dto.getPageNum() == 0 ? 1 : dto.getPageNum(); - int pageSize = dto.getPageSize() == 0 ? 10 : dto.getPageSize(); + /** + * uniApp查询充电站信息并通过经纬度排序 + * + * @param dto 前台参数 + * @return 充电站对象集合 + */ + @Override + public PageResponse uniAppQueryStationInfoList(QueryStationDTO dto) { + int pageNum = dto.getPageNum() == 0 ? 1 : dto.getPageNum(); + int pageSize = dto.getPageSize() == 0 ? 10 : dto.getPageSize(); - // 小程序站点列表页只展示对外开放的站点 - dto.setPublicFlag(Constants.ONE); - // 根据前台参数分页 - PageHelper.startPage(pageNum, pageSize); - List list = pileStationInfoMapper.queryStationInfos(dto); - PageInfo pageInfo = new PageInfo<>(list); + // 小程序站点列表页只展示对外开放的站点 + dto.setPublicFlag(Constants.ONE); + // 根据前台参数分页 + PageHelper.startPage(pageNum, pageSize); + List list = pileStationInfoMapper.queryStationInfos(dto); + PageInfo pageInfo = new PageInfo<>(list); - List stationVOList = Lists.newArrayList(); - StationInfoVO stationVO; - String stationLng = dto.getStationLng(); - String stationLat = dto.getStationLat(); - double distance = 0d; - for (PileStationVO pileStationVO : pageInfo.getList()) { - stationVO = new StationInfoVO(); - if (StringUtils.isNotEmpty(stationLng) && StringUtils.isNotEmpty(stationLat)) { - try{ - // 计算当前经纬度和站点之间的距离 - distance = DistanceUtils.getDistance(Double.parseDouble(stationLng), Double.parseDouble(stationLat), - Double.parseDouble(pileStationVO.getStationLng()), Double.parseDouble(pileStationVO.getStationLat())); - // 保留两位小数 - stationVO.setDistance(String.format("%.2f", distance)); - }catch (Exception e){ - stationVO.setDistance("0.00"); - } + List stationVOList = Lists.newArrayList(); + StationInfoVO stationVO; + String stationLng = dto.getStationLng(); + String stationLat = dto.getStationLat(); + double distance = 0d; + for (PileStationVO pileStationVO : pageInfo.getList()) { + stationVO = new StationInfoVO(); + if (StringUtils.isNotEmpty(stationLng) && StringUtils.isNotEmpty(stationLat)) { + try { + // 计算当前经纬度和站点之间的距离 + distance = DistanceUtils.getDistance(Double.parseDouble(stationLng), Double.parseDouble(stationLat), + Double.parseDouble(pileStationVO.getStationLng()), Double.parseDouble(pileStationVO.getStationLat())); + // 保留两位小数 + stationVO.setDistance(String.format("%.2f", distance)); + } catch (Exception e) { + stationVO.setDistance("0.00"); + } - } - stationVO.setStationId(pileStationVO.getId()); - stationVO.setStationName(pileStationVO.getStationName()); - stationVO.setStationAddress(pileStationVO.getAddress()); - stationVO.setStationLat(pileStationVO.getStationLat()); - stationVO.setStationLng(pileStationVO.getStationLng()); - if (StringUtils.isNotBlank(pileStationVO.getParkFeeDescribe())) { - stationVO.setParkFeeDescribe(pileStationVO.getParkFeeDescribe()); - } - // 站点联系电话 - if (StringUtils.isNotBlank(pileStationVO.getStationTel())) { - stationVO.setStationTel(pileStationVO.getStationTel()); - } - // 站点图片 - if (StringUtils.isNotBlank(pileStationVO.getPictures())) { - stationVO.setStationImgList(Lists.newArrayList(pileStationVO.getPictures().split(","))); - } + } + stationVO.setStationId(pileStationVO.getId()); + stationVO.setStationName(pileStationVO.getStationName()); + stationVO.setStationAddress(pileStationVO.getAddress()); + stationVO.setStationLat(pileStationVO.getStationLat()); + stationVO.setStationLng(pileStationVO.getStationLng()); + if (StringUtils.isNotBlank(pileStationVO.getParkFeeDescribe())) { + stationVO.setParkFeeDescribe(pileStationVO.getParkFeeDescribe()); + } + // 站点联系电话 + if (StringUtils.isNotBlank(pileStationVO.getStationTel())) { + stationVO.setStationTel(pileStationVO.getStationTel()); + } + // 站点图片 + if (StringUtils.isNotBlank(pileStationVO.getPictures())) { + stationVO.setStationImgList(Lists.newArrayList(pileStationVO.getPictures().split(","))); + } - // 查询快慢充数量 - Map map = pileConnectorInfoService.getPileTypeNum(Long.parseLong(pileStationVO.getId())); - Integer fastFree = map.get("fastFree"); - Integer slowFree = map.get("slowFree"); - stationVO.setFastTotal(map.get("fastTotal")); - stationVO.setFastFree(fastFree); - stationVO.setSlowTotal(map.get("slowTotal")); - stationVO.setSlowFree(map.get("slowFree")); - stationVO.setTotalFree(fastFree + slowFree); + // 查询快慢充数量 + Map map = pileConnectorInfoService.getPileTypeNum(Long.parseLong(pileStationVO.getId())); + Integer fastFree = map.get("fastFree"); + Integer slowFree = map.get("slowFree"); + stationVO.setFastTotal(map.get("fastTotal")); + stationVO.setFastFree(fastFree); + stationVO.setSlowTotal(map.get("slowTotal")); + stationVO.setSlowFree(map.get("slowFree")); + stationVO.setTotalFree(fastFree + slowFree); - // 查询当前时段电费 - CurrentTimePriceDetails currentTimePriceDetails = pileBillingTemplateService.getCurrentTimePriceDetails(stationVO.getStationId()); - if (currentTimePriceDetails != null) { - stationVO.setElectricityPrice(currentTimePriceDetails.getElectricityPrice()); - stationVO.setServicePrice(currentTimePriceDetails.getServicePrice()); - stationVO.setTotalPrice(currentTimePriceDetails.getTotalPrice()); - stationVO.setFreeTime(currentTimePriceDetails.getFreeTime()); - stationVO.setOccupyFee(currentTimePriceDetails.getOccupyFee()); - // vip价 - stationVO.setVipElectricityPrice(currentTimePriceDetails.getVipElectricityPrice()); - stationVO.setVipServicePrice(currentTimePriceDetails.getVipServicePrice()); - stationVO.setVipTotalPrice(currentTimePriceDetails.getVipTotalPrice()); - } - stationVOList.add(stationVO); - } + // 查询当前时段电费 + CurrentTimePriceDetails currentTimePriceDetails = pileBillingTemplateService.getCurrentTimePriceDetails(stationVO.getStationId()); + if (currentTimePriceDetails != null) { + stationVO.setElectricityPrice(currentTimePriceDetails.getElectricityPrice()); + stationVO.setServicePrice(currentTimePriceDetails.getServicePrice()); + stationVO.setTotalPrice(currentTimePriceDetails.getTotalPrice()); + stationVO.setFreeTime(currentTimePriceDetails.getFreeTime()); + stationVO.setOccupyFee(currentTimePriceDetails.getOccupyFee()); + // vip价 + stationVO.setVipElectricityPrice(currentTimePriceDetails.getVipElectricityPrice()); + stationVO.setVipServicePrice(currentTimePriceDetails.getVipServicePrice()); + stationVO.setVipTotalPrice(currentTimePriceDetails.getVipTotalPrice()); + } + stationVOList.add(stationVO); + } - if (distance != 0.00) { - // 对集合按照距离排序,距离小的在前 - stationVOList.sort((o1, o2) -> { - Double a = Double.valueOf(o1.getDistance()); - Double b = Double.valueOf(o2.getDistance()); - return a.compareTo(b); - }); - } + if (distance != 0.00) { + // 对集合按照距离排序,距离小的在前 + stationVOList.sort((o1, o2) -> { + Double a = Double.valueOf(o1.getDistance()); + Double b = Double.valueOf(o2.getDistance()); + return a.compareTo(b); + }); + } - // 返回结果集 - PageResponse pageResponse = PageResponse.builder() - .pageNum(pageInfo.getPageNum()) - .pageSize(pageInfo.getPageSize()) - .list(stationVOList) - .pages(pageInfo.getPages()) - .total(pageInfo.getTotal()) - .build(); - return pageResponse; - } + // 返回结果集 + PageResponse pageResponse = PageResponse.builder() + .pageNum(pageInfo.getPageNum()) + .pageSize(pageInfo.getPageSize()) + .list(stationVOList) + .pages(pageInfo.getPages()) + .total(pageInfo.getTotal()) + .build(); + return pageResponse; + } - /** - * 根据站点id查询运营商配置的汇付会员id - * @param stationId - * @return - */ - @Override - public String selectAdapayMemberId(String stationId) { - return null; - } + /** + * 根据站点id查询运营商配置的汇付会员id + * + * @param stationId + * @return + */ + @Override + public String selectAdapayMemberId(String stationId) { + return null; + } - @Override - public int updateAmapFlag(String stationId, String amapFlag) { - return pileStationInfoMapper.updateAmapFlag(stationId, amapFlag); - } + @Override + public int updateAmapFlag(String stationId, String amapFlag) { + return pileStationInfoMapper.updateAmapFlag(stationId, amapFlag); + } - /** - * 通过站点部门id查询站点id - * @param deptId - * @return - */ + /** + * 通过站点部门id查询站点id + * + * @param deptId + * @return + */ @Override public List getIdsByDeptId(String deptId) { return pileStationInfoMapper.getIdsByDeptId(deptId); } - /** - * 绑定停车系统平台 - * @param dto - */ + /** + * 绑定停车系统平台 + * + * @param dto + */ @Override public int bindParkingPlatform(BindParkingPlatformDTO dto) { - String parkingId = dto.getParkingId(); - String stationId = dto.getStationId(); - // 先根据停车系统平台查询一下是否有数据 - ThirdpartyParkingConfig basicInfo = parkingConfigService.selectByPrimaryKey(Integer.parseInt(parkingId)); - if (basicInfo == null) { - throw new BusinessException(ReturnCodeEnum.CODE_QUERY_PARKING_INFO_IS_NULL); - } - // 先删除缓存 - String redisKey = CacheConstants.SELECT_PILE_STATION_INFO_BY_ID + stationId; - redisCache.deleteObject(redisKey); - // 再将站点信息表中绑定上parkingId + String parkingId = dto.getParkingId(); + String stationId = dto.getStationId(); + // 先根据停车系统平台查询一下是否有数据 + ThirdpartyParkingConfig basicInfo = parkingConfigService.selectByPrimaryKey(Integer.parseInt(parkingId)); + if (basicInfo == null) { + throw new BusinessException(ReturnCodeEnum.CODE_QUERY_PARKING_INFO_IS_NULL); + } + // 先删除缓存 + String redisKey = CacheConstants.SELECT_PILE_STATION_INFO_BY_ID + stationId; + redisCache.deleteObject(redisKey); + // 再将站点信息表中绑定上parkingId return pileStationInfoMapper.updateParkingPlatform(parkingId, stationId); } - /** - * 查询充电站下拉列表 - * @param dto - * @return - */ - @Override - public List getStationSelectList(QueryStationDTO dto) { - AuthorizedDeptVO authorizedMap = UserUtils.getAuthorizedMap(); - if (authorizedMap == null) { - // 为空表示没有权限,返回空数组 - return Lists.newArrayList(); - } - dto.setStationDeptIds(authorizedMap.getStationDeptIds()); - dto.setMerchantDeptIds(authorizedMap.getMerchantDeptIds()); + /** + * 查询充电站下拉列表 + * + * @param dto + * @return + */ + @Override + public List getStationSelectList(QueryStationDTO dto) { + AuthorizedDeptVO authorizedMap = UserUtils.getAuthorizedMap(); + if (authorizedMap == null) { + // 为空表示没有权限,返回空数组 + return Lists.newArrayList(); + } + dto.setStationDeptIds(authorizedMap.getStationDeptIds()); + dto.setMerchantDeptIds(authorizedMap.getMerchantDeptIds()); - return pileStationInfoMapper.getStationSelectList(dto); - } + return pileStationInfoMapper.getStationSelectList(dto); + } - /** - * 宁夏交投查询充电站信息 - * @param dto - * @return - */ - @Override - public List NXJTQueryStationsInfo(NXJTQueryStationInfoDTO dto) { - return pileStationInfoMapper.NXJTQueryStationsInfo(dto); - } + /** + * 宁夏交投查询充电站信息 + * + * @param dto + * @return + */ + @Override + public List NXJTQueryStationsInfo(NXJTQueryStationInfoDTO dto) { + return pileStationInfoMapper.NXJTQueryStationsInfo(dto); + } @Override public PileStationInfo queryInfoByDeptId(String deptId) { - if (StringUtils.isBlank(deptId)) { - return null; - } + if (StringUtils.isBlank(deptId)) { + return null; + } return pileStationInfoMapper.queryInfoByDeptId(deptId); } @Override - public List getStationInfosByMerchantIds(List merchantIds){ - return pileStationInfoMapper.getStationInfosByMerchantIds(merchantIds); - } + public List getStationInfosByMerchantIds(List merchantIds) { + return pileStationInfoMapper.getStationInfosByMerchantIds(merchantIds); + } - /** - * 获取站点统计信息 - * @param dto - */ - @Override - public List getStationStatisticsInfos(StationStatisticsInfoDTO dto) { - String merchantId = dto.getMerchantId(); - List stationIds = dto.getStationIds(); - // 获取当前登录账号的运营商权限 - List merchantInfoVOList = UserUtils.getMerchantInfoVOList(); - List merchantIds = new ArrayList<>(); - List resultList = new ArrayList<>(); - if (StringUtils.isBlank(merchantId)) { - merchantIds = merchantInfoVOList.stream() - .map(MerchantInfoVO::getMerchantId) - .collect(Collectors.toList()); - }else { - merchantIds.add(merchantId); - } - if (CollectionUtils.isEmpty(stationIds)) { - // 根据运营商ids查出所有站点id - List pileStationInfos = getStationInfosByMerchantIds(merchantIds); - if (CollectionUtils.isEmpty(pileStationInfos)) { - // 未查到该运营商下的站点 - throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL); - } - stationIds = pileStationInfos.stream() - .map(x -> String.valueOf(x.getId())) - .collect(Collectors.toList()); - } - // 创建DecimalFormat对象并设置格式 - DecimalFormat df = new DecimalFormat("0.00%"); - // 根据站点ids查询站点营收报表 - List list = settleOrderReportService.queryOrderReport(stationIds, dto.getStartTime(), dto.getEndTime()); - if (CollectionUtils.isEmpty(list)) { - throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL); - } - // 根据站点id分组,将充电度数、充电金额、充电次数进行累加 - Map collect = list.stream() - .sorted(Comparator.comparing(SettleOrderReport::getStationId)) - // .filter(vo -> vo.getChargingTime() != null && vo.getTotalPower() != null) - .collect(Collectors.toMap(SettleOrderReport::getStationId, Function.identity(), - (a, b) -> { - a.setUseElectricity(a.getUseElectricity().add(b.getUseElectricity())); - a.setTotalAmount(a.getTotalAmount().add(b.getTotalAmount())); - a.setChargeNum(String.valueOf(Integer.parseInt(a.getChargeNum()) + Integer.parseInt(b.getChargeNum()))); - return a; - })); + /** + * 获取站点统计信息 + * + * @param dto + */ + @Override + public List getStationStatisticsInfos(StationStatisticsInfoDTO dto) { + String merchantId = dto.getMerchantId(); + List stationIds = dto.getStationIds(); + // 获取当前登录账号的运营商权限 + List merchantInfoVOList = UserUtils.getMerchantInfoVOList(); + List merchantIds = new ArrayList<>(); + List resultList = new ArrayList<>(); + if (StringUtils.isBlank(merchantId)) { + merchantIds = merchantInfoVOList.stream() + .map(MerchantInfoVO::getMerchantId) + .collect(Collectors.toList()); + } else { + merchantIds.add(merchantId); + } + if (CollectionUtils.isEmpty(stationIds)) { + // 根据运营商ids查出所有站点id + List pileStationInfos = getStationInfosByMerchantIds(merchantIds); + if (CollectionUtils.isEmpty(pileStationInfos)) { + // 未查到该运营商下的站点 + throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL); + } + stationIds = pileStationInfos.stream() + .map(x -> String.valueOf(x.getId())) + .collect(Collectors.toList()); + } + // 创建DecimalFormat对象并设置格式 + DecimalFormat df = new DecimalFormat("0.00%"); + // 根据站点ids查询站点营收报表 + List list = settleOrderReportService.queryOrderReport(stationIds, dto.getStartTime(), dto.getEndTime()); + if (CollectionUtils.isEmpty(list)) { + throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL); + } + // 根据站点id分组,将充电度数、充电金额、充电次数进行累加 + Map collect = list.stream() + .sorted(Comparator.comparing(SettleOrderReport::getStationId)) + // .filter(vo -> vo.getChargingTime() != null && vo.getTotalPower() != null) + .collect(Collectors.toMap(SettleOrderReport::getStationId, Function.identity(), + (a, b) -> { + a.setUseElectricity(a.getUseElectricity().add(b.getUseElectricity())); + a.setTotalAmount(a.getTotalAmount().add(b.getTotalAmount())); + a.setChargeNum(String.valueOf(Integer.parseInt(a.getChargeNum()) + Integer.parseInt(b.getChargeNum()))); + return a; + })); - for (Map.Entry entry: collect.entrySet()) { - String stationId = entry.getKey(); - SettleOrderReport report = entry.getValue(); + for (Map.Entry entry : collect.entrySet()) { + String stationId = entry.getKey(); + SettleOrderReport report = entry.getValue(); - // 查询枪口列表 - List uniAppConnectorList = pileConnectorInfoService.getUniAppConnectorList(Long.parseLong(stationId)); + // 查询枪口列表 + List uniAppConnectorList = pileConnectorInfoService.getUniAppConnectorList(Long.parseLong(stationId)); - int chargingConnectorNum = Constants.zero; // 充电中 - int freeConnectorNum = Constants.zero; // 空闲 - int occupiedConnectorNum = Constants.zero; // 占用 - int hangingConnectorNum = Constants.zero; // 挂起 - int offlineConnectorNum = Constants.zero; // 离线 - int faultConnectorNum = Constants.zero; // 故障 + int chargingConnectorNum = Constants.zero; // 充电中 + int freeConnectorNum = Constants.zero; // 空闲 + int occupiedConnectorNum = Constants.zero; // 占用 + int hangingConnectorNum = Constants.zero; // 挂起 + int offlineConnectorNum = Constants.zero; // 离线 + int faultConnectorNum = Constants.zero; // 故障 - for (ConnectorInfoVO connectorInfoVO : uniAppConnectorList) { - String connectorStatus = connectorInfoVO.getConnectorStatus(); - if (StringUtils.equals(PileConnectorDataBaseStatusEnum.FREE.getValue(), connectorStatus)) { - // 空闲 - freeConnectorNum += 1; - }else if (StringUtils.equals(PileConnectorDataBaseStatusEnum.OCCUPIED_NOT_CHARGED.getValue(), connectorStatus)) { - // 占用(未充电) - occupiedConnectorNum += 1; - }else if (StringUtils.equals(PileConnectorDataBaseStatusEnum.OCCUPIED_CHARGING.getValue(), connectorStatus)) { - // 充电中 - chargingConnectorNum += 1; - }else if (StringUtils.equals(PileConnectorDataBaseStatusEnum.OFF_NETWORK.getValue(), connectorStatus)) { - // 离线 - offlineConnectorNum += 1; - }else if(StringUtils.equals(PileConnectorDataBaseStatusEnum.FAULT.getValue(), connectorStatus)) { - // 故障 - faultConnectorNum += 1; - } - } - // 计算枪口可使用率 - int totalConnectorNum = uniAppConnectorList.size(); - double connectorAvailability = (double) freeConnectorNum / totalConnectorNum; - String format = df.format(connectorAvailability); + for (ConnectorInfoVO connectorInfoVO : uniAppConnectorList) { + String connectorStatus = connectorInfoVO.getConnectorStatus(); + if (StringUtils.equals(PileConnectorDataBaseStatusEnum.FREE.getValue(), connectorStatus)) { + // 空闲 + freeConnectorNum += 1; + } else if (StringUtils.equals(PileConnectorDataBaseStatusEnum.OCCUPIED_NOT_CHARGED.getValue(), connectorStatus)) { + // 占用(未充电) + occupiedConnectorNum += 1; + } else if (StringUtils.equals(PileConnectorDataBaseStatusEnum.OCCUPIED_CHARGING.getValue(), connectorStatus)) { + // 充电中 + chargingConnectorNum += 1; + } else if (StringUtils.equals(PileConnectorDataBaseStatusEnum.OFF_NETWORK.getValue(), connectorStatus)) { + // 离线 + offlineConnectorNum += 1; + } else if (StringUtils.equals(PileConnectorDataBaseStatusEnum.FAULT.getValue(), connectorStatus)) { + // 故障 + faultConnectorNum += 1; + } + } + // 计算枪口可使用率 + int totalConnectorNum = uniAppConnectorList.size(); + double connectorAvailability = (double) freeConnectorNum / totalConnectorNum; + String format = df.format(connectorAvailability); - StationStatisticsInfosVO vo = StationStatisticsInfosVO.builder() - .stationId(stationId) - // .stationName(pileStationInfo.getStationName()) - .chargeDegree(report.getUseElectricity()) - .chargeAmount(report.getTotalAmount()) - .orderQuantity(Integer.parseInt(report.getChargeNum())) - .connectorAvailability(format) - .chargingConnectorNum(chargingConnectorNum) - .freeConnectorNum(freeConnectorNum) - .occupiedConnectorNum(occupiedConnectorNum) - .hangingConnectorNum(hangingConnectorNum) - .offlineConnectorNum(offlineConnectorNum) - .faultConnectorNum(faultConnectorNum) - .build(); + StationStatisticsInfosVO vo = StationStatisticsInfosVO.builder() + .stationId(stationId) + // .stationName(pileStationInfo.getStationName()) + .chargeDegree(report.getUseElectricity()) + .chargeAmount(report.getTotalAmount()) + .orderQuantity(Integer.parseInt(report.getChargeNum())) + .connectorAvailability(format) + .chargingConnectorNum(chargingConnectorNum) + .freeConnectorNum(freeConnectorNum) + .occupiedConnectorNum(occupiedConnectorNum) + .hangingConnectorNum(hangingConnectorNum) + .offlineConnectorNum(offlineConnectorNum) + .faultConnectorNum(faultConnectorNum) + .build(); - resultList.add(vo); - } + resultList.add(vo); + } - return resultList; - } + return resultList; + } - /** - * 获取站点运营分析信息(7天、30天) - * @param dto - */ - @Override - public StationBusinessAnalyzeInfoVO getStationBusinessAnalyzeInfo(StationBusinessAnalyzeInfoDTO dto) { - StationBusinessAnalyzeInfoVO vo = new StationBusinessAnalyzeInfoVO(); + /** + * 获取站点运营分析信息(7天、30天) + * + * @param dto + */ + @Override + public StationBusinessAnalyzeInfoVO getStationBusinessAnalyzeInfo(StationBusinessAnalyzeInfoDTO dto) { + StationBusinessAnalyzeInfoVO vo = new StationBusinessAnalyzeInfoVO(); - String dateTime = dto.getDateTime(); - // 获取type类型 - String type = dto.getType(); - // 获取站点id,如果为空,则默认查询该账号下所有站点 - // String stationId = dto.getStationId(); - List stationIds = dto.getStationIds(); - if (CollectionUtils.isNotEmpty(stationIds)) { - List merchantInfoVOList = UserUtils.getMerchantInfoVOList(); - List merchantIds = merchantInfoVOList.stream() - .map(MerchantInfoVO::getMerchantId) - .collect(Collectors.toList()); - // 根据运营商ids查出所有站点id - List pileStationInfos = getStationInfosByMerchantIds(merchantIds); - stationIds = pileStationInfos.stream() - .map(x -> String.valueOf(x.getId())) - .collect(Collectors.toList()); - if (CollectionUtils.isEmpty(pileStationInfos)) { - // 未查到该运营商下的站点 - throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL); - } - } - // 日期区间 - // String startTime = null; - // String endTime = null; - // 用户未选中某天时 - Date date = null; - if (StringUtils.equals(Constants.ONE, type)) { - // 7天 - date = DateUtils.addDays(new Date(), -7); - }else if (StringUtils.equals(Constants.TWO, type)) { - // 30天 - date = DateUtils.addDays(new Date(), -30); - } - String startTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, date); - String endTime = DateUtils.dateTimeNow(DateUtils.YYYY_MM_DD); - // if (dateTime == null) { - // - // - // } else { - // // 用户选中某天的数据时↓ - // startTime = dateTime; - // endTime = dateTime; - // } + String dateTime = dto.getDateTime(); + // 获取type类型 + String type = dto.getType(); + // 获取站点id,如果为空,则默认查询该账号下所有站点 + // String stationId = dto.getStationId(); + List stationIds = dto.getStationIds(); + if (CollectionUtils.isNotEmpty(stationIds)) { + List merchantInfoVOList = UserUtils.getMerchantInfoVOList(); + List merchantIds = merchantInfoVOList.stream() + .map(MerchantInfoVO::getMerchantId) + .collect(Collectors.toList()); + // 根据运营商ids查出所有站点id + List pileStationInfos = getStationInfosByMerchantIds(merchantIds); + stationIds = pileStationInfos.stream() + .map(x -> String.valueOf(x.getId())) + .collect(Collectors.toList()); + if (CollectionUtils.isEmpty(pileStationInfos)) { + // 未查到该运营商下的站点 + throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL); + } + } + // 日期区间 + // String startTime = null; + // String endTime = null; + // 用户未选中某天时 + Date date = null; + if (StringUtils.equals(Constants.ONE, type)) { + // 7天 + date = DateUtils.addDays(new Date(), -7); + } else if (StringUtils.equals(Constants.TWO, type)) { + // 30天 + date = DateUtils.addDays(new Date(), -30); + } + String startTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, date); + String endTime = DateUtils.dateTimeNow(DateUtils.YYYY_MM_DD); + // if (dateTime == null) { + // + // + // } else { + // // 用户选中某天的数据时↓ + // startTime = dateTime; + // endTime = dateTime; + // } - // 根据站点ids和日期区间查询订单详情 - List orderDetails = orderBasicInfoService.getOrderDetailByStationIds(stationIds, startTime, endTime); - if (CollectionUtils.isEmpty(orderDetails)) { - return new StationBusinessAnalyzeInfoVO(); - } - for (BusinessOrderDetailInfoVO orderDetail : orderDetails) { - if (orderDetail.getSharpAmount() == null) { - orderDetail.setSharpAmount(BigDecimal.ZERO); - } - if (orderDetail.getPeakAmount() == null) { - orderDetail.setPeakAmount(BigDecimal.ZERO); - } - if (orderDetail.getFlatAmount() == null) { - orderDetail.setFlatAmount(BigDecimal.ZERO); - } - if (orderDetail.getValleyAmount() == null) { - orderDetail.setValleyAmount(BigDecimal.ZERO); - } - if (orderDetail.getSharpUsedElectricity() == null) { - orderDetail.setSharpUsedElectricity(BigDecimal.ZERO); - } - if (orderDetail.getPeakUsedElectricity() == null) { - orderDetail.setPeakUsedElectricity(BigDecimal.ZERO); - } - if (orderDetail.getFlatUsedElectricity() == null) { - orderDetail.setFlatUsedElectricity(BigDecimal.ZERO); - } - if (orderDetail.getValleyUsedElectricity() == null) { - orderDetail.setValleyUsedElectricity(BigDecimal.ZERO); - } - if (orderDetail.getTotalServiceAmount() == null) { - orderDetail.setTotalServiceAmount(BigDecimal.ZERO); - } - if (orderDetail.getSettleAmount() == null) { - orderDetail.setSettleAmount(BigDecimal.ZERO); - } - } + // 根据站点ids和日期区间查询订单详情 + List orderDetails = orderBasicInfoService.getOrderDetailByStationIds(stationIds, startTime, endTime); + if (CollectionUtils.isEmpty(orderDetails)) { + return new StationBusinessAnalyzeInfoVO(); + } + for (BusinessOrderDetailInfoVO orderDetail : orderDetails) { + if (orderDetail.getSharpAmount() == null) { + orderDetail.setSharpAmount(BigDecimal.ZERO); + } + if (orderDetail.getPeakAmount() == null) { + orderDetail.setPeakAmount(BigDecimal.ZERO); + } + if (orderDetail.getFlatAmount() == null) { + orderDetail.setFlatAmount(BigDecimal.ZERO); + } + if (orderDetail.getValleyAmount() == null) { + orderDetail.setValleyAmount(BigDecimal.ZERO); + } + if (orderDetail.getSharpUsedElectricity() == null) { + orderDetail.setSharpUsedElectricity(BigDecimal.ZERO); + } + if (orderDetail.getPeakUsedElectricity() == null) { + orderDetail.setPeakUsedElectricity(BigDecimal.ZERO); + } + if (orderDetail.getFlatUsedElectricity() == null) { + orderDetail.setFlatUsedElectricity(BigDecimal.ZERO); + } + if (orderDetail.getValleyUsedElectricity() == null) { + orderDetail.setValleyUsedElectricity(BigDecimal.ZERO); + } + if (orderDetail.getTotalServiceAmount() == null) { + orderDetail.setTotalServiceAmount(BigDecimal.ZERO); + } + if (orderDetail.getSettleAmount() == null) { + orderDetail.setSettleAmount(BigDecimal.ZERO); + } + } - // 根据日期进行分组汇总 - Map collect = orderDetails.stream() - .sorted(Comparator.comparing(BusinessOrderDetailInfoVO::getTradeDate)) - .collect(Collectors.toMap(BusinessOrderDetailInfoVO::getTradeDate, Function.identity(), - (a, b) -> { - a.setSharpUsedElectricity(a.getSharpUsedElectricity().add(b.getSharpUsedElectricity())); - a.setSharpAmount(a.getSharpAmount().add(b.getSharpAmount())); - a.setPeakUsedElectricity(a.getPeakUsedElectricity().add(b.getPeakUsedElectricity())); - a.setPeakAmount(a.getPeakAmount().add(b.getPeakAmount())); - a.setFlatUsedElectricity(a.getFlatUsedElectricity().add(b.getFlatUsedElectricity())); - a.setFlatAmount(a.getFlatAmount().add(b.getFlatAmount())); - a.setValleyUsedElectricity(a.getValleyUsedElectricity().add(b.getValleyUsedElectricity())); - a.setValleyAmount(a.getValleyAmount().add(b.getValleyAmount())); - a.setTotalServiceAmount(a.getTotalServiceAmount().add(b.getTotalServiceAmount())); - a.setSettleAmount(a.getSettleAmount().add(b.getSettleAmount())); - a.setTotalUsedElectricity(a.getSharpUsedElectricity().add(a.getPeakUsedElectricity()).add(a.getFlatUsedElectricity()).add(a.getValleyUsedElectricity())); - return a; - })); - // 通过TreeMap排序 - TreeMap map = new TreeMap<>(collect); - List businessOrderDetailInfoVOS = new ArrayList<>(map.values()); + // 根据日期进行分组汇总 + Map collect = orderDetails.stream() + .sorted(Comparator.comparing(BusinessOrderDetailInfoVO::getTradeDate)) + .collect(Collectors.toMap(BusinessOrderDetailInfoVO::getTradeDate, Function.identity(), + (a, b) -> { + a.setSharpUsedElectricity(a.getSharpUsedElectricity().add(b.getSharpUsedElectricity())); + a.setSharpAmount(a.getSharpAmount().add(b.getSharpAmount())); + a.setPeakUsedElectricity(a.getPeakUsedElectricity().add(b.getPeakUsedElectricity())); + a.setPeakAmount(a.getPeakAmount().add(b.getPeakAmount())); + a.setFlatUsedElectricity(a.getFlatUsedElectricity().add(b.getFlatUsedElectricity())); + a.setFlatAmount(a.getFlatAmount().add(b.getFlatAmount())); + a.setValleyUsedElectricity(a.getValleyUsedElectricity().add(b.getValleyUsedElectricity())); + a.setValleyAmount(a.getValleyAmount().add(b.getValleyAmount())); + a.setTotalServiceAmount(a.getTotalServiceAmount().add(b.getTotalServiceAmount())); + a.setSettleAmount(a.getSettleAmount().add(b.getSettleAmount())); + a.setTotalUsedElectricity(a.getSharpUsedElectricity().add(a.getPeakUsedElectricity()).add(a.getFlatUsedElectricity()).add(a.getValleyUsedElectricity())); + return a; + })); + // 通过TreeMap排序 + TreeMap map = new TreeMap<>(collect); + List businessOrderDetailInfoVOS = new ArrayList<>(map.values()); - String usedElectricityRiseRate = "-"; - String orderAmountRiseRate = "-"; - String serviceAmountRiseRate = "-"; - BigDecimal todayUsedElectricity = BigDecimal.ZERO; - BigDecimal yesterdayUsedElectricity = BigDecimal.ZERO; - BigDecimal todaySettleAmount = BigDecimal.ZERO; - BigDecimal yesterdaySettleAmount = BigDecimal.ZERO; - BigDecimal todayServiceAmount = BigDecimal.ZERO; - BigDecimal yesterdayServiceAmount = BigDecimal.ZERO; - if (dateTime != null) { - // 如果指定日期不为空,则将指定日期与指定日期的前一天进行数据对比 - BusinessOrderDetailInfoVO orderDetailToday = map.get(dateTime); // 指定日期 - // 指定日期前一天 - String dateTimeYesterday = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, DateUtils.addDays(DateUtils.parseDate(dateTime), -1)); - BusinessOrderDetailInfoVO orderDetailYesterday = collect.get(dateTimeYesterday); - if (orderDetailYesterday == null) { - // 如果为空,为第一天数据,默认置空 - vo.setElectricityGrowthRate("-"); - vo.setOrderAmountGrowthRate("-"); - vo.setServiceAmountGrowthRate("-"); - // vo.setBusinessOrderDetailInfoVOList(); - }else { - // 充电量增长率 - todayUsedElectricity = orderDetailToday.getTotalUsedElectricity(); - yesterdayUsedElectricity = orderDetailYesterday.getTotalUsedElectricity(); - // 订单金额增长率 - todaySettleAmount = orderDetailToday.getSettleAmount(); - yesterdaySettleAmount = orderDetailYesterday.getSettleAmount(); - // 服务费增长率 - todayServiceAmount = orderDetailToday.getTotalServiceAmount(); - yesterdayServiceAmount = orderDetailYesterday.getTotalServiceAmount(); - } - }else { - // 如果指定日期为空,则默认最后一天(当天)与前一天做对比 - BusinessOrderDetailInfoVO orderDetailToday = businessOrderDetailInfoVOS.get(businessOrderDetailInfoVOS.size() - 1); - BusinessOrderDetailInfoVO orderDetailYesterday = businessOrderDetailInfoVOS.get(businessOrderDetailInfoVOS.size() - 2); - // 充电量增长率 - todayUsedElectricity = orderDetailToday.getTotalUsedElectricity(); - yesterdayUsedElectricity = orderDetailYesterday.getTotalUsedElectricity(); - // 订单金额增长率 - todaySettleAmount = orderDetailToday.getSettleAmount(); - yesterdaySettleAmount = orderDetailYesterday.getSettleAmount(); - // 服务费增长率 - todayServiceAmount = orderDetailToday.getTotalServiceAmount(); - yesterdayServiceAmount = orderDetailYesterday.getTotalServiceAmount(); - } - if (yesterdayUsedElectricity.compareTo(BigDecimal.ZERO) == 0) { - usedElectricityRiseRate = "0%"; - }else { - BigDecimal divideUsedElectricity = todayUsedElectricity.subtract(yesterdayUsedElectricity).divide(yesterdayUsedElectricity, 2, BigDecimal.ROUND_HALF_UP); - usedElectricityRiseRate = divideUsedElectricity.multiply(new BigDecimal("100")) + "%"; - } - if (yesterdaySettleAmount.compareTo(BigDecimal.ZERO) == 0) { - orderAmountRiseRate = "0%"; - }else { - BigDecimal divideSettleAmount = todaySettleAmount.subtract(yesterdaySettleAmount).divide(yesterdaySettleAmount, 2, BigDecimal.ROUND_HALF_UP); - orderAmountRiseRate = divideSettleAmount.multiply(new BigDecimal("100")) + "%"; - } - if (yesterdayServiceAmount.compareTo(BigDecimal.ZERO) == 0) { - serviceAmountRiseRate = "0%"; - }else { - BigDecimal divideServiceAmount = todayServiceAmount.subtract(yesterdayServiceAmount).divide(yesterdayServiceAmount, 2, BigDecimal.ROUND_HALF_UP); - serviceAmountRiseRate = divideServiceAmount.multiply(new BigDecimal("100")) + "%"; - } + String usedElectricityRiseRate = "-"; + String orderAmountRiseRate = "-"; + String serviceAmountRiseRate = "-"; + BigDecimal todayUsedElectricity = BigDecimal.ZERO; + BigDecimal yesterdayUsedElectricity = BigDecimal.ZERO; + BigDecimal todaySettleAmount = BigDecimal.ZERO; + BigDecimal yesterdaySettleAmount = BigDecimal.ZERO; + BigDecimal todayServiceAmount = BigDecimal.ZERO; + BigDecimal yesterdayServiceAmount = BigDecimal.ZERO; + if (dateTime != null) { + // 如果指定日期不为空,则将指定日期与指定日期的前一天进行数据对比 + BusinessOrderDetailInfoVO orderDetailToday = map.get(dateTime); // 指定日期 + // 指定日期前一天 + String dateTimeYesterday = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, DateUtils.addDays(DateUtils.parseDate(dateTime), -1)); + BusinessOrderDetailInfoVO orderDetailYesterday = collect.get(dateTimeYesterday); + if (orderDetailYesterday == null) { + // 如果为空,为第一天数据,默认置空 + vo.setElectricityGrowthRate("-"); + vo.setOrderAmountGrowthRate("-"); + vo.setServiceAmountGrowthRate("-"); + // vo.setBusinessOrderDetailInfoVOList(); + } else { + // 充电量增长率 + todayUsedElectricity = orderDetailToday.getTotalUsedElectricity(); + yesterdayUsedElectricity = orderDetailYesterday.getTotalUsedElectricity(); + // 订单金额增长率 + todaySettleAmount = orderDetailToday.getSettleAmount(); + yesterdaySettleAmount = orderDetailYesterday.getSettleAmount(); + // 服务费增长率 + todayServiceAmount = orderDetailToday.getTotalServiceAmount(); + yesterdayServiceAmount = orderDetailYesterday.getTotalServiceAmount(); + } + } else { + // 如果指定日期为空,则默认最后一天(当天)与前一天做对比 + BusinessOrderDetailInfoVO orderDetailToday = businessOrderDetailInfoVOS.get(businessOrderDetailInfoVOS.size() - 1); + BusinessOrderDetailInfoVO orderDetailYesterday = businessOrderDetailInfoVOS.get(businessOrderDetailInfoVOS.size() - 2); + // 充电量增长率 + todayUsedElectricity = orderDetailToday.getTotalUsedElectricity(); + yesterdayUsedElectricity = orderDetailYesterday.getTotalUsedElectricity(); + // 订单金额增长率 + todaySettleAmount = orderDetailToday.getSettleAmount(); + yesterdaySettleAmount = orderDetailYesterday.getSettleAmount(); + // 服务费增长率 + todayServiceAmount = orderDetailToday.getTotalServiceAmount(); + yesterdayServiceAmount = orderDetailYesterday.getTotalServiceAmount(); + } + if (yesterdayUsedElectricity.compareTo(BigDecimal.ZERO) == 0) { + usedElectricityRiseRate = "0%"; + } else { + BigDecimal divideUsedElectricity = todayUsedElectricity.subtract(yesterdayUsedElectricity).divide(yesterdayUsedElectricity, 2, BigDecimal.ROUND_HALF_UP); + usedElectricityRiseRate = divideUsedElectricity.multiply(new BigDecimal("100")) + "%"; + } + if (yesterdaySettleAmount.compareTo(BigDecimal.ZERO) == 0) { + orderAmountRiseRate = "0%"; + } else { + BigDecimal divideSettleAmount = todaySettleAmount.subtract(yesterdaySettleAmount).divide(yesterdaySettleAmount, 2, BigDecimal.ROUND_HALF_UP); + orderAmountRiseRate = divideSettleAmount.multiply(new BigDecimal("100")) + "%"; + } + if (yesterdayServiceAmount.compareTo(BigDecimal.ZERO) == 0) { + serviceAmountRiseRate = "0%"; + } else { + BigDecimal divideServiceAmount = todayServiceAmount.subtract(yesterdayServiceAmount).divide(yesterdayServiceAmount, 2, BigDecimal.ROUND_HALF_UP); + serviceAmountRiseRate = divideServiceAmount.multiply(new BigDecimal("100")) + "%"; + } - vo.setElectricityGrowthRate(usedElectricityRiseRate); - vo.setServiceAmountGrowthRate(serviceAmountRiseRate); - vo.setOrderAmountGrowthRate(orderAmountRiseRate); - vo.setBusinessOrderDetailInfoVOList(businessOrderDetailInfoVOS); - return vo; - } + vo.setElectricityGrowthRate(usedElectricityRiseRate); + vo.setServiceAmountGrowthRate(serviceAmountRiseRate); + vo.setOrderAmountGrowthRate(orderAmountRiseRate); + vo.setBusinessOrderDetailInfoVOList(businessOrderDetailInfoVOS); + return vo; + } - /** - * 获取站点运营分析信息(12个月) - * @param dto - */ - @Override - public StationBusinessAnalyzeInfoVO getStationMonthlyBusinessAnalyzeInfo(StationBusinessAnalyzeInfoDTO dto) { - // 获取目标日期(年-月) - String dateTime = dto.getDateTime(); - // 设置开始时间、结束时间 - // String stationId = dto.getStationId(); - List stationIds = dto.getStationIds(); - String startTime = DateUtils.getLastDayOfCurrentMonth(); // 去年月份第一天 - String endTime = DateUtils.getFirstDayOfLastYearMonth(); // 当前月份最后一天 + /** + * 获取站点运营分析信息(12个月) + * + * @param dto + */ + @Override + public StationBusinessAnalyzeInfoVO getStationMonthlyBusinessAnalyzeInfo(StationBusinessAnalyzeInfoDTO dto) { + // 获取目标日期(年-月) + String dateTime = dto.getDateTime(); + // 设置开始时间、结束时间 + // String stationId = dto.getStationId(); + List stationIds = dto.getStationIds(); + String startTime = DateUtils.getLastDayOfCurrentMonth(); // 去年月份第一天 + String endTime = DateUtils.getFirstDayOfLastYearMonth(); // 当前月份最后一天 - // 查询订单日报表过去一年的数据 - List list = settleOrderReportService.queryOrderReport(stationIds, startTime, endTime); - if (CollectionUtils.isEmpty(list)) { - throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL); - } - // 按照日期汇总数据 - Map collect = list.stream() - .peek(report -> { - LocalDate date = LocalDate.parse(report.getTradeDate(), DateTimeFormatter.ofPattern("yyyy-MM-dd")); - String formattedDate = date.format(DateTimeFormatter.ofPattern("yyyy-MM")); - report.setTradeDate(formattedDate); - }) - .sorted(Comparator.comparing(SettleOrderReport::getTradeDate)) - .collect(Collectors.toMap(SettleOrderReport::getTradeDate, Function.identity(), - (a, b) -> { - a.setUseElectricity(a.getUseElectricity().add(b.getUseElectricity())); - a.setTotalAmount(a.getTotalAmount().add(b.getTotalAmount())); - a.setElectricityAmount(a.getElectricityAmount().add(b.getElectricityAmount())); - a.setServiceAmount(a.getServiceAmount().add(b.getServiceAmount())); - return a; - })); - // 通过TreeMap排序 - TreeMap map = new TreeMap<>(collect); - List settleOrderReports = new ArrayList<>(map.values()); + // 查询订单日报表过去一年的数据 + List list = settleOrderReportService.queryOrderReport(stationIds, startTime, endTime); + if (CollectionUtils.isEmpty(list)) { + throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL); + } + // 按照日期汇总数据 + Map collect = list.stream() + .peek(report -> { + LocalDate date = LocalDate.parse(report.getTradeDate(), DateTimeFormatter.ofPattern("yyyy-MM-dd")); + String formattedDate = date.format(DateTimeFormatter.ofPattern("yyyy-MM")); + report.setTradeDate(formattedDate); + }) + .sorted(Comparator.comparing(SettleOrderReport::getTradeDate)) + .collect(Collectors.toMap(SettleOrderReport::getTradeDate, Function.identity(), + (a, b) -> { + a.setUseElectricity(a.getUseElectricity().add(b.getUseElectricity())); + a.setTotalAmount(a.getTotalAmount().add(b.getTotalAmount())); + a.setElectricityAmount(a.getElectricityAmount().add(b.getElectricityAmount())); + a.setServiceAmount(a.getServiceAmount().add(b.getServiceAmount())); + return a; + })); + // 通过TreeMap排序 + TreeMap map = new TreeMap<>(collect); + List settleOrderReports = new ArrayList<>(map.values()); - SettleOrderReport nowReportInfo = new SettleOrderReport(); - SettleOrderReport lastMonthReportInfo = new SettleOrderReport(); - if(dateTime == null) { - // 为空默认对比最后一个月和前一个月的数据 - nowReportInfo = settleOrderReports.get(settleOrderReports.size() - 1); - lastMonthReportInfo = settleOrderReports.get(settleOrderReports.size() - 2); - }else { - // 对比目标日期和目标日期前一个月数据 - nowReportInfo = map.get(dateTime); - Date lastMonth = DateUtils.addMonths(DateUtils.parseDate(dateTime), -1); - String lastMonthStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM, lastMonth); - lastMonthReportInfo = map.get(lastMonthStr); - } - String electricityGrowthRate = "-"; - String orderAmountGrowthRate = ""; - String serviceAmountGrowthRate = ""; - // 充电量增长率 - BigDecimal useElectricity = nowReportInfo.getUseElectricity(); - BigDecimal lastMonthUseElectricity = lastMonthReportInfo.getUseElectricity(); - if (lastMonthUseElectricity.compareTo(BigDecimal.ZERO) != 0) { - BigDecimal usedElectricityRate = useElectricity.subtract(lastMonthUseElectricity).divide(lastMonthUseElectricity, 2, BigDecimal.ROUND_HALF_UP); - electricityGrowthRate = usedElectricityRate.multiply(new BigDecimal("100")) + "%"; - } - // 订单金额增长率 - BigDecimal totalAmount = nowReportInfo.getTotalAmount(); - BigDecimal lastTotalAmount = lastMonthReportInfo.getTotalAmount(); - if (lastTotalAmount.compareTo(BigDecimal.ZERO) != 0) { - BigDecimal totalAmountRate = totalAmount.subtract(lastTotalAmount).divide(lastTotalAmount, 2, BigDecimal.ROUND_HALF_UP); - orderAmountGrowthRate = totalAmountRate.multiply(new BigDecimal("100")) + "%"; - } - // 服务费增长率 - BigDecimal serviceAmount = nowReportInfo.getServiceAmount(); - BigDecimal lastMonthServiceAmount = lastMonthReportInfo.getServiceAmount(); - if (lastMonthServiceAmount.compareTo(BigDecimal.ZERO) != 0) { - BigDecimal serviceAmountRate = serviceAmount.subtract(lastMonthServiceAmount).divide(lastMonthServiceAmount, 2, BigDecimal.ROUND_HALF_UP); - serviceAmountGrowthRate = serviceAmountRate.multiply(new BigDecimal("100")) + "%"; - } + SettleOrderReport nowReportInfo = new SettleOrderReport(); + SettleOrderReport lastMonthReportInfo = new SettleOrderReport(); + if (dateTime == null) { + // 为空默认对比最后一个月和前一个月的数据 + nowReportInfo = settleOrderReports.get(settleOrderReports.size() - 1); + lastMonthReportInfo = settleOrderReports.get(settleOrderReports.size() - 2); + } else { + // 对比目标日期和目标日期前一个月数据 + nowReportInfo = map.get(dateTime); + Date lastMonth = DateUtils.addMonths(DateUtils.parseDate(dateTime), -1); + String lastMonthStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM, lastMonth); + lastMonthReportInfo = map.get(lastMonthStr); + } + String electricityGrowthRate = "-"; + String orderAmountGrowthRate = ""; + String serviceAmountGrowthRate = ""; + // 充电量增长率 + BigDecimal useElectricity = nowReportInfo.getUseElectricity(); + BigDecimal lastMonthUseElectricity = lastMonthReportInfo.getUseElectricity(); + if (lastMonthUseElectricity.compareTo(BigDecimal.ZERO) != 0) { + BigDecimal usedElectricityRate = useElectricity.subtract(lastMonthUseElectricity).divide(lastMonthUseElectricity, 2, BigDecimal.ROUND_HALF_UP); + electricityGrowthRate = usedElectricityRate.multiply(new BigDecimal("100")) + "%"; + } + // 订单金额增长率 + BigDecimal totalAmount = nowReportInfo.getTotalAmount(); + BigDecimal lastTotalAmount = lastMonthReportInfo.getTotalAmount(); + if (lastTotalAmount.compareTo(BigDecimal.ZERO) != 0) { + BigDecimal totalAmountRate = totalAmount.subtract(lastTotalAmount).divide(lastTotalAmount, 2, BigDecimal.ROUND_HALF_UP); + orderAmountGrowthRate = totalAmountRate.multiply(new BigDecimal("100")) + "%"; + } + // 服务费增长率 + BigDecimal serviceAmount = nowReportInfo.getServiceAmount(); + BigDecimal lastMonthServiceAmount = lastMonthReportInfo.getServiceAmount(); + if (lastMonthServiceAmount.compareTo(BigDecimal.ZERO) != 0) { + BigDecimal serviceAmountRate = serviceAmount.subtract(lastMonthServiceAmount).divide(lastMonthServiceAmount, 2, BigDecimal.ROUND_HALF_UP); + serviceAmountGrowthRate = serviceAmountRate.multiply(new BigDecimal("100")) + "%"; + } - StationBusinessAnalyzeInfoVO vo = StationBusinessAnalyzeInfoVO.builder() - .electricityGrowthRate(electricityGrowthRate) - .orderAmountGrowthRate(orderAmountGrowthRate) - .serviceAmountGrowthRate(serviceAmountGrowthRate) - .settleOrderReportList(settleOrderReports) - .build(); + StationBusinessAnalyzeInfoVO vo = StationBusinessAnalyzeInfoVO.builder() + .electricityGrowthRate(electricityGrowthRate) + .orderAmountGrowthRate(orderAmountGrowthRate) + .serviceAmountGrowthRate(serviceAmountGrowthRate) + .settleOrderReportList(settleOrderReports) + .build(); - return vo; - } + return vo; + } - /** - * 查询订单数量趋势信息 - * @param dto - * @return - */ - @Override - public StationBusinessAnalyzeInfoVO getStationOrderQuantityInfo(StationBusinessAnalyzeInfoDTO dto) { - StationBusinessAnalyzeInfoVO vo = new StationBusinessAnalyzeInfoVO(); - List stationIds = dto.getStationIds(); - String dateTime = dto.getDateTime(); - String type = dto.getType(); - String startTime = ""; - String endTime = ""; - if (StringUtils.equals(Constants.ONE, type)) { - // 7天 - startTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, DateUtils.addDays(new Date(), -7)); - endTime = DateUtils.dateTimeNow(DateUtils.YYYY_MM_DD); - } else if (StringUtils.equals(Constants.TWO, type)) { - // 30天 - startTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, DateUtils.addDays(new Date(), -30)); - endTime = DateUtils.dateTimeNow(DateUtils.YYYY_MM_DD); - }else if (StringUtils.equals(Constants.THREE, type)) { - // 一年 - startTime = DateUtils.getFirstDayOfLastYearMonth(); - endTime = DateUtils.getLastDayOfCurrentMonth(); - } - // 根据站点id、开始时间、结束时间查询订单日报表 - List settleOrderReports = settleOrderReportService.queryOrderReport(stationIds, startTime, endTime); - if (CollectionUtils.isEmpty(settleOrderReports)) { - return vo; - } - // 根据交易日期汇总订单数量(充电次数) - // key: 交易日期 value: SettleOrderReport - Map collect = new LinkedHashMap<>(); - if (StringUtils.equals(Constants.ONE, type) || StringUtils.equals(Constants.TWO, type)) { - collect = settleOrderReports.stream() - .sorted(Comparator.comparing(SettleOrderReport::getTradeDate)) - .collect(Collectors.toMap(SettleOrderReport::getTradeDate, Function.identity(), - (a, b) -> { - a.setChargeNum(String.valueOf(new BigDecimal(a.getChargeNum()).add(new BigDecimal(b.getChargeNum())))); - return a; - })); - }else { - collect = settleOrderReports.stream() - .peek(report -> { - LocalDate date = LocalDate.parse(report.getTradeDate(), DateTimeFormatter.ofPattern("yyyy-MM-dd")); - String formattedDate = date.format(DateTimeFormatter.ofPattern("yyyy-MM")); - report.setTradeDate(formattedDate); - }) - .collect(Collectors.toMap(SettleOrderReport::getTradeDate, Function.identity(), - (a, b) -> { - a.setChargeNum(String.valueOf(new BigDecimal(a.getChargeNum()).add(new BigDecimal(b.getChargeNum())))); - return a; - })); - } - TreeMap map = new TreeMap<>(collect); - List list = new ArrayList<>(); - for (SettleOrderReport settleOrderReport : map.values()) { - StationOrderQuantityInfoVO orderQuantityInfoVO = new StationOrderQuantityInfoVO(); - orderQuantityInfoVO.setTradeDate(settleOrderReport.getTradeDate()); - orderQuantityInfoVO.setOrderNumber(Integer.parseInt(settleOrderReport.getChargeNum())); + /** + * 查询订单数量趋势信息 + * + * @param dto + * @return + */ + @Override + public StationBusinessAnalyzeInfoVO getStationOrderQuantityInfo(StationBusinessAnalyzeInfoDTO dto) { + StationBusinessAnalyzeInfoVO vo = new StationBusinessAnalyzeInfoVO(); + List stationIds = dto.getStationIds(); + String dateTime = dto.getDateTime(); + String type = dto.getType(); + String startTime = ""; + String endTime = ""; + if (StringUtils.equals(Constants.ONE, type)) { + // 7天 + startTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, DateUtils.addDays(new Date(), -7)); + endTime = DateUtils.dateTimeNow(DateUtils.YYYY_MM_DD); + } else if (StringUtils.equals(Constants.TWO, type)) { + // 30天 + startTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, DateUtils.addDays(new Date(), -30)); + endTime = DateUtils.dateTimeNow(DateUtils.YYYY_MM_DD); + } else if (StringUtils.equals(Constants.THREE, type)) { + // 一年 + startTime = DateUtils.getFirstDayOfLastYearMonth(); + endTime = DateUtils.getLastDayOfCurrentMonth(); + } + // 根据站点id、开始时间、结束时间查询订单日报表 + List settleOrderReports = settleOrderReportService.queryOrderReport(stationIds, startTime, endTime); + if (CollectionUtils.isEmpty(settleOrderReports)) { + return vo; + } + // 根据交易日期汇总订单数量(充电次数) + // key: 交易日期 value: SettleOrderReport + Map collect = new LinkedHashMap<>(); + if (StringUtils.equals(Constants.ONE, type) || StringUtils.equals(Constants.TWO, type)) { + collect = settleOrderReports.stream() + .sorted(Comparator.comparing(SettleOrderReport::getTradeDate)) + .collect(Collectors.toMap(SettleOrderReport::getTradeDate, Function.identity(), + (a, b) -> { + a.setChargeNum(String.valueOf(new BigDecimal(a.getChargeNum()).add(new BigDecimal(b.getChargeNum())))); + return a; + })); + } else { + collect = settleOrderReports.stream() + .peek(report -> { + LocalDate date = LocalDate.parse(report.getTradeDate(), DateTimeFormatter.ofPattern("yyyy-MM-dd")); + String formattedDate = date.format(DateTimeFormatter.ofPattern("yyyy-MM")); + report.setTradeDate(formattedDate); + }) + .collect(Collectors.toMap(SettleOrderReport::getTradeDate, Function.identity(), + (a, b) -> { + a.setChargeNum(String.valueOf(new BigDecimal(a.getChargeNum()).add(new BigDecimal(b.getChargeNum())))); + return a; + })); + } + TreeMap map = new TreeMap<>(collect); + List list = new ArrayList<>(); + for (SettleOrderReport settleOrderReport : map.values()) { + StationOrderQuantityInfoVO orderQuantityInfoVO = new StationOrderQuantityInfoVO(); + orderQuantityInfoVO.setTradeDate(settleOrderReport.getTradeDate()); + orderQuantityInfoVO.setOrderNumber(Integer.parseInt(settleOrderReport.getChargeNum())); - list.add(orderQuantityInfoVO); - } - // 用户选中某日期 - if (dateTime != null) { - String orderNumRateGrowthRate = "0%"; - String format = ""; - if (StringUtils.equals(Constants.ONE, type) || - StringUtils.equals(Constants.TWO, type)) { - // 7天 - format = DateUtils.YYYY_MM_DD; - }else { - format = DateUtils.YYYY_MM; - } - String yesterday = DateUtils.parseDateToStr(format, DateUtils.addDays(DateUtils.parseDate(dateTime), -1)); - SettleOrderReport todayReportInfo = map.get(dateTime); - SettleOrderReport yesterdayReportInfo = map.get(yesterday); + list.add(orderQuantityInfoVO); + } + // 用户选中某日期 + if (dateTime != null) { + String orderNumRateGrowthRate = "0%"; + String format = ""; + if (StringUtils.equals(Constants.ONE, type) || + StringUtils.equals(Constants.TWO, type)) { + // 7天 + format = DateUtils.YYYY_MM_DD; + } else { + format = DateUtils.YYYY_MM; + } + String yesterday = DateUtils.parseDateToStr(format, DateUtils.addDays(DateUtils.parseDate(dateTime), -1)); + SettleOrderReport todayReportInfo = map.get(dateTime); + SettleOrderReport yesterdayReportInfo = map.get(yesterday); - BigDecimal todayOrderNum = new BigDecimal(todayReportInfo.getChargeNum()); - BigDecimal yesterdayOrderNum = new BigDecimal(yesterdayReportInfo.getChargeNum()); + BigDecimal todayOrderNum = new BigDecimal(todayReportInfo.getChargeNum()); + BigDecimal yesterdayOrderNum = new BigDecimal(yesterdayReportInfo.getChargeNum()); - // 计算增长率 - if (yesterdayOrderNum.compareTo(BigDecimal.ZERO) != 0) { - BigDecimal orderNumRate = todayOrderNum.subtract(yesterdayOrderNum).divide(yesterdayOrderNum, 2, BigDecimal.ROUND_HALF_UP); - orderNumRateGrowthRate = orderNumRate.multiply(new BigDecimal("100")) + "%"; - }else { - orderNumRateGrowthRate = todayOrderNum.multiply(new BigDecimal("100")) + "%"; - } - vo.setOrderAmountGrowthRate(orderNumRateGrowthRate); - } - vo.setStationOrderQuantityInfoList(list); - return vo; - } + // 计算增长率 + if (yesterdayOrderNum.compareTo(BigDecimal.ZERO) != 0) { + BigDecimal orderNumRate = todayOrderNum.subtract(yesterdayOrderNum).divide(yesterdayOrderNum, 2, BigDecimal.ROUND_HALF_UP); + orderNumRateGrowthRate = orderNumRate.multiply(new BigDecimal("100")) + "%"; + } else { + orderNumRateGrowthRate = todayOrderNum.multiply(new BigDecimal("100")) + "%"; + } + vo.setOrderAmountGrowthRate(orderNumRateGrowthRate); + } + vo.setStationOrderQuantityInfoList(list); + return vo; + } - /** - * 查询站点枪利用率趋势信息 - * @param dto - * @return - */ - @Override - public StationBusinessAnalyzeInfoVO getStationConnectorUsedInfo(StationBusinessAnalyzeInfoDTO dto) { - List stationIds = dto.getStationIds(); - String type = dto.getType(); - String dateTime = dto.getDateTime(); - String startTime = ""; - String endTime = ""; - if (StringUtils.equals(Constants.ONE, type)) { - // 7天 - startTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, DateUtils.addDays(new Date(), -7)); - endTime = DateUtils.dateTimeNow(DateUtils.YYYY_MM_DD); - } else if (StringUtils.equals(Constants.TWO, type)) { - // 30天 - startTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, DateUtils.addDays(new Date(), -30)); - endTime = DateUtils.dateTimeNow(DateUtils.YYYY_MM_DD); - } - // 根据站点ids和开始、结束日期查询订单表 - List orderDetailByStationIds = orderBasicInfoService.getOrderDetailByStationIds(stationIds, startTime, endTime); - if (CollectionUtils.isEmpty(orderDetailByStationIds)) { - throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL); - } + /** + * 查询站点枪利用率趋势信息 + * + * @param dto + * @return + */ + @Override + public StationBusinessAnalyzeInfoVO getStationConnectorUsedInfo(StationBusinessAnalyzeInfoDTO dto) { + List stationIds = dto.getStationIds(); + String type = dto.getType(); + String dateTime = dto.getDateTime(); + String startTime = ""; + String endTime = ""; + if (StringUtils.equals(Constants.ONE, type)) { + // 7天 + startTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, DateUtils.addDays(new Date(), -7)); + endTime = DateUtils.dateTimeNow(DateUtils.YYYY_MM_DD); + } else if (StringUtils.equals(Constants.TWO, type)) { + // 30天 + startTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, DateUtils.addDays(new Date(), -30)); + endTime = DateUtils.dateTimeNow(DateUtils.YYYY_MM_DD); + } + // 根据站点ids和开始、结束日期查询订单表 + List orderDetailByStationIds = orderBasicInfoService.getOrderDetailByStationIds(stationIds, startTime, endTime); + if (CollectionUtils.isEmpty(orderDetailByStationIds)) { + throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL); + } - // 分组出来key为日期,value为订单信息 - return null; - } + // 分组出来key为日期,value为订单信息 + return null; + } } \ No newline at end of file diff --git a/pom.xml b/pom.xml index 44a95cca9..e70af79f8 100644 --- a/pom.xml +++ b/pom.xml @@ -307,7 +307,7 @@ cn.hutool hutool-all - 5.7.3 + 5.8.30