update 电单车协议

This commit is contained in:
Guoqs
2024-08-16 14:16:50 +08:00
parent 7f8ffec164
commit 04b2b5a44f
6 changed files with 1109 additions and 1002 deletions

View File

@@ -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);
}

View File

@@ -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=RN82091=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));
}
}

View File

@@ -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;
}
}

View File

@@ -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);

View File

@@ -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;
@@ -119,6 +121,7 @@ public class PileStationInfoServiceImpl implements PileStationInfoService {
/**
* 查询站点基本资料
* 加缓存
*
* @param stationId
* @return
*/
@@ -205,6 +208,7 @@ public class PileStationInfoServiceImpl implements PileStationInfoService {
/**
* 通过充电桩枪口编号查询充电站信息
*
* @param pileConnectorCode 充电桩枪口编号
* @return 充电站信息
*/
@@ -219,6 +223,7 @@ public class PileStationInfoServiceImpl implements PileStationInfoService {
/**
* 通过充电桩sn查询充电站信息
*
* @param pileSn 充电桩sn
* @return 充电站信息
*/
@@ -317,6 +322,7 @@ public class PileStationInfoServiceImpl implements PileStationInfoService {
/**
* 快速建站
*
* @param dto
* @return
*/
@@ -391,6 +397,17 @@ public class PileStationInfoServiceImpl implements PileStationInfoService {
}
}
// 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()));
}
}
pileStationInfo.setUpdateBy(SecurityUtils.getUsername());
pileStationInfo.setUpdateTime(DateUtils.getNowDate());
int i = pileStationInfoMapper.updatePileStationInfo(pileStationInfo);
@@ -462,6 +479,7 @@ public class PileStationInfoServiceImpl implements PileStationInfoService {
/**
* 充电站列表信息
*
* @param dto 前台参数
* @return 充电站对象集合
*/
@@ -505,13 +523,13 @@ public class PileStationInfoServiceImpl implements PileStationInfoService {
for (PileStationVO pileStationVO : pageInfo.getList()) {
stationVO = new StationInfoVO();
if (StringUtils.isNotEmpty(stationLng) && StringUtils.isNotEmpty(stationLat)) {
try{
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){
} catch (Exception e) {
stationVO.setDistance("0.00");
}
@@ -581,6 +599,7 @@ public class PileStationInfoServiceImpl implements PileStationInfoService {
/**
* 根据站点id查询运营商配置的汇付会员id
*
* @param stationId
* @return
*/
@@ -596,6 +615,7 @@ public class PileStationInfoServiceImpl implements PileStationInfoService {
/**
* 通过站点部门id查询站点id
*
* @param deptId
* @return
*/
@@ -606,6 +626,7 @@ public class PileStationInfoServiceImpl implements PileStationInfoService {
/**
* 绑定停车系统平台
*
* @param dto
*/
@Override
@@ -626,6 +647,7 @@ public class PileStationInfoServiceImpl implements PileStationInfoService {
/**
* 查询充电站下拉列表
*
* @param dto
* @return
*/
@@ -644,6 +666,7 @@ public class PileStationInfoServiceImpl implements PileStationInfoService {
/**
* 宁夏交投查询充电站信息
*
* @param dto
* @return
*/
@@ -661,12 +684,13 @@ public class PileStationInfoServiceImpl implements PileStationInfoService {
}
@Override
public List<PileStationInfo> getStationInfosByMerchantIds(List<String> merchantIds){
public List<PileStationInfo> getStationInfosByMerchantIds(List<String> merchantIds) {
return pileStationInfoMapper.getStationInfosByMerchantIds(merchantIds);
}
/**
* 获取站点统计信息
*
* @param dto
*/
@Override
@@ -681,7 +705,7 @@ public class PileStationInfoServiceImpl implements PileStationInfoService {
merchantIds = merchantInfoVOList.stream()
.map(MerchantInfoVO::getMerchantId)
.collect(Collectors.toList());
}else {
} else {
merchantIds.add(merchantId);
}
if (CollectionUtils.isEmpty(stationIds)) {
@@ -715,7 +739,7 @@ public class PileStationInfoServiceImpl implements PileStationInfoService {
}));
for (Map.Entry<String, SettleOrderReport> entry: collect.entrySet()) {
for (Map.Entry<String, SettleOrderReport> entry : collect.entrySet()) {
String stationId = entry.getKey();
SettleOrderReport report = entry.getValue();
@@ -734,16 +758,16 @@ public class PileStationInfoServiceImpl implements PileStationInfoService {
if (StringUtils.equals(PileConnectorDataBaseStatusEnum.FREE.getValue(), connectorStatus)) {
// 空闲
freeConnectorNum += 1;
}else if (StringUtils.equals(PileConnectorDataBaseStatusEnum.OCCUPIED_NOT_CHARGED.getValue(), connectorStatus)) {
} else if (StringUtils.equals(PileConnectorDataBaseStatusEnum.OCCUPIED_NOT_CHARGED.getValue(), connectorStatus)) {
// 占用(未充电)
occupiedConnectorNum += 1;
}else if (StringUtils.equals(PileConnectorDataBaseStatusEnum.OCCUPIED_CHARGING.getValue(), connectorStatus)) {
} else if (StringUtils.equals(PileConnectorDataBaseStatusEnum.OCCUPIED_CHARGING.getValue(), connectorStatus)) {
// 充电中
chargingConnectorNum += 1;
}else if (StringUtils.equals(PileConnectorDataBaseStatusEnum.OFF_NETWORK.getValue(), connectorStatus)) {
} else if (StringUtils.equals(PileConnectorDataBaseStatusEnum.OFF_NETWORK.getValue(), connectorStatus)) {
// 离线
offlineConnectorNum += 1;
}else if(StringUtils.equals(PileConnectorDataBaseStatusEnum.FAULT.getValue(), connectorStatus)) {
} else if (StringUtils.equals(PileConnectorDataBaseStatusEnum.FAULT.getValue(), connectorStatus)) {
// 故障
faultConnectorNum += 1;
}
@@ -776,6 +800,7 @@ public class PileStationInfoServiceImpl implements PileStationInfoService {
/**
* 获取站点运营分析信息7天、30天
*
* @param dto
*/
@Override
@@ -811,7 +836,7 @@ public class PileStationInfoServiceImpl implements PileStationInfoService {
if (StringUtils.equals(Constants.ONE, type)) {
// 7天
date = DateUtils.addDays(new Date(), -7);
}else if (StringUtils.equals(Constants.TWO, type)) {
} else if (StringUtils.equals(Constants.TWO, type)) {
// 30天
date = DateUtils.addDays(new Date(), -30);
}
@@ -907,7 +932,7 @@ public class PileStationInfoServiceImpl implements PileStationInfoService {
vo.setOrderAmountGrowthRate("-");
vo.setServiceAmountGrowthRate("-");
// vo.setBusinessOrderDetailInfoVOList();
}else {
} else {
// 充电量增长率
todayUsedElectricity = orderDetailToday.getTotalUsedElectricity();
yesterdayUsedElectricity = orderDetailYesterday.getTotalUsedElectricity();
@@ -918,7 +943,7 @@ public class PileStationInfoServiceImpl implements PileStationInfoService {
todayServiceAmount = orderDetailToday.getTotalServiceAmount();
yesterdayServiceAmount = orderDetailYesterday.getTotalServiceAmount();
}
}else {
} else {
// 如果指定日期为空,则默认最后一天(当天)与前一天做对比
BusinessOrderDetailInfoVO orderDetailToday = businessOrderDetailInfoVOS.get(businessOrderDetailInfoVOS.size() - 1);
BusinessOrderDetailInfoVO orderDetailYesterday = businessOrderDetailInfoVOS.get(businessOrderDetailInfoVOS.size() - 2);
@@ -934,19 +959,19 @@ public class PileStationInfoServiceImpl implements PileStationInfoService {
}
if (yesterdayUsedElectricity.compareTo(BigDecimal.ZERO) == 0) {
usedElectricityRiseRate = "0%";
}else {
} 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 {
} 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 {
} else {
BigDecimal divideServiceAmount = todayServiceAmount.subtract(yesterdayServiceAmount).divide(yesterdayServiceAmount, 2, BigDecimal.ROUND_HALF_UP);
serviceAmountRiseRate = divideServiceAmount.multiply(new BigDecimal("100")) + "%";
}
@@ -960,6 +985,7 @@ public class PileStationInfoServiceImpl implements PileStationInfoService {
/**
* 获取站点运营分析信息12个月
*
* @param dto
*/
@Override
@@ -999,11 +1025,11 @@ public class PileStationInfoServiceImpl implements PileStationInfoService {
SettleOrderReport nowReportInfo = new SettleOrderReport();
SettleOrderReport lastMonthReportInfo = new SettleOrderReport();
if(dateTime == null) {
if (dateTime == null) {
// 为空默认对比最后一个月和前一个月的数据
nowReportInfo = settleOrderReports.get(settleOrderReports.size() - 1);
lastMonthReportInfo = settleOrderReports.get(settleOrderReports.size() - 2);
}else {
} else {
// 对比目标日期和目标日期前一个月数据
nowReportInfo = map.get(dateTime);
Date lastMonth = DateUtils.addMonths(DateUtils.parseDate(dateTime), -1);
@@ -1048,6 +1074,7 @@ public class PileStationInfoServiceImpl implements PileStationInfoService {
/**
* 查询订单数量趋势信息
*
* @param dto
* @return
*/
@@ -1067,7 +1094,7 @@ public class PileStationInfoServiceImpl implements PileStationInfoService {
// 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)) {
} else if (StringUtils.equals(Constants.THREE, type)) {
// 一年
startTime = DateUtils.getFirstDayOfLastYearMonth();
endTime = DateUtils.getLastDayOfCurrentMonth();
@@ -1088,7 +1115,7 @@ public class PileStationInfoServiceImpl implements PileStationInfoService {
a.setChargeNum(String.valueOf(new BigDecimal(a.getChargeNum()).add(new BigDecimal(b.getChargeNum()))));
return a;
}));
}else {
} else {
collect = settleOrderReports.stream()
.peek(report -> {
LocalDate date = LocalDate.parse(report.getTradeDate(), DateTimeFormatter.ofPattern("yyyy-MM-dd"));
@@ -1118,7 +1145,7 @@ public class PileStationInfoServiceImpl implements PileStationInfoService {
StringUtils.equals(Constants.TWO, type)) {
// 7天
format = DateUtils.YYYY_MM_DD;
}else {
} else {
format = DateUtils.YYYY_MM;
}
String yesterday = DateUtils.parseDateToStr(format, DateUtils.addDays(DateUtils.parseDate(dateTime), -1));
@@ -1132,7 +1159,7 @@ public class PileStationInfoServiceImpl implements PileStationInfoService {
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 {
} else {
orderNumRateGrowthRate = todayOrderNum.multiply(new BigDecimal("100")) + "%";
}
vo.setOrderAmountGrowthRate(orderNumRateGrowthRate);
@@ -1143,6 +1170,7 @@ public class PileStationInfoServiceImpl implements PileStationInfoService {
/**
* 查询站点枪利用率趋势信息
*
* @param dto
* @return
*/

View File

@@ -307,7 +307,7 @@
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.7.3</version>
<version>5.8.30</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.huifu.adapay.core/adapay-core-sdk -->