From 7db4ffaf37728b4dcf9ad9bccb49897e8d0fe698 Mon Sep 17 00:00:00 2001 From: Guoqs <123@jsowell.com> Date: Thu, 29 Aug 2024 16:58:21 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E7=94=B5=E5=8D=95=E8=BD=A6=E5=8D=8F?= =?UTF-8?q?=E8=AE=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DeviceGetServerTimeHandler.java | 2 +- .../HostGetServerTimeHandler.java | 9 ++ .../electricbicycles/RegistrationHandler.java | 6 + .../jsowell/pile/domain/PileBasicInfo.java | 133 +----------------- .../ebike/deviceupload/EBikeMessageCmd20.java | 4 +- .../pile/service/PileBasicInfoService.java | 7 + .../impl/PileBasicInfoServiceImpl.java | 66 ++++++++- 7 files changed, 93 insertions(+), 134 deletions(-) diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/electricbicycles/DeviceGetServerTimeHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/electricbicycles/DeviceGetServerTimeHandler.java index 2bfbbfa42..2afe0e5ba 100644 --- a/jsowell-netty/src/main/java/com/jsowell/netty/handler/electricbicycles/DeviceGetServerTimeHandler.java +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/electricbicycles/DeviceGetServerTimeHandler.java @@ -41,7 +41,7 @@ public class DeviceGetServerTimeHandler extends AbstractEBikeHandler { // 获取当前服务器10位时间戳 byte[] timeBytes = BytesUtil.getIntBytes((int) (System.currentTimeMillis() / 1000)); - // System.out.println("data: " + BytesUtil.bytesToIntLittle(timeBytes)); + return getResult(dataProtocol, timeBytes); } } diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/electricbicycles/HostGetServerTimeHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/electricbicycles/HostGetServerTimeHandler.java index 53ed54e1b..0d9bf4eee 100644 --- a/jsowell-netty/src/main/java/com/jsowell/netty/handler/electricbicycles/HostGetServerTimeHandler.java +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/electricbicycles/HostGetServerTimeHandler.java @@ -44,4 +44,13 @@ public class HostGetServerTimeHandler extends AbstractEBikeHandler { // System.out.println("data: " + BytesUtil.bytesToIntLittle(timeBytes)); return getResult(dataProtocol, timeBytes); } + + public static void main(String[] args) { + // DE 5C A9 5F,转小端模式,=0x5FA95CDE=1604934878=2020-11-09 23:14:38 + String str = "DE 5C A9 5F".replace(" ", ""); + byte[] bytes = BytesUtil.hexStringToByteArray(str); + System.out.println("data: " + BytesUtil.binary(bytes, 16)); + System.out.println("time: " + BytesUtil.bytesToIntLittle(bytes)); + + } } diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/electricbicycles/RegistrationHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/electricbicycles/RegistrationHandler.java index 8b90effbd..a9a6ebb7c 100644 --- a/jsowell-netty/src/main/java/com/jsowell/netty/handler/electricbicycles/RegistrationHandler.java +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/electricbicycles/RegistrationHandler.java @@ -7,8 +7,10 @@ import com.jsowell.netty.factory.EBikeOperateFactory; import com.jsowell.pile.domain.ebike.AbsEBikeMessage; import com.jsowell.pile.domain.ebike.EBikeCommandEnum; import com.jsowell.pile.domain.ebike.deviceupload.EBikeMessageCmd20; +import com.jsowell.pile.service.PileBasicInfoService; import io.netty.channel.ChannelHandlerContext; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** @@ -19,6 +21,9 @@ import org.springframework.stereotype.Component; public class RegistrationHandler extends AbstractEBikeHandler { private final String type = EBikeCommandEnum.REGISTRATION.getCode(); + @Autowired + private PileBasicInfoService pileBasicInfoService; + @Override public void afterPropertiesSet() throws Exception { EBikeOperateFactory.register(type, this); @@ -39,6 +44,7 @@ public class RegistrationHandler extends AbstractEBikeHandler { saveLastTimeAndCheckChannel(message.getPhysicalId() + "", ctx); EBikeMessageCmd20.DeviceRegister deviceRegister = message.getDeviceRegister(); log.info("设备注册包:{}", JSON.toJSONString(message)); + pileBasicInfoService.registrationEBikePile(message); return getResult(dataProtocol, Constants.zeroByteArray); } } diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/domain/PileBasicInfo.java b/jsowell-pile/src/main/java/com/jsowell/pile/domain/PileBasicInfo.java index d0c548b2d..a38c4877d 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/domain/PileBasicInfo.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/domain/PileBasicInfo.java @@ -3,6 +3,8 @@ package com.jsowell.pile.domain; import com.fasterxml.jackson.annotation.JsonFormat; import com.jsowell.common.annotation.Excel; import com.jsowell.common.core.domain.BaseEntity; +import lombok.Getter; +import lombok.Setter; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; @@ -14,6 +16,8 @@ import java.util.Date; * @author jsowell * @date 2022-08-26 */ +@Getter +@Setter public class PileBasicInfo extends BaseEntity { private static final long serialVersionUID = 1L; @@ -52,9 +56,9 @@ public class PileBasicInfo extends BaseEntity { private String secretKey; /** - * 软件协议(1-云快充;2-永联) + * 软件协议(1-云快充; 2-永联; 3-友电) */ - @Excel(name = "软件协议", readConverterExp = "1=-云快充;2-永联") + @Excel(name = "软件协议", readConverterExp = "1=-云快充; 2-永联; 3-友电") private String softwareProtocol; /** @@ -107,131 +111,6 @@ public class PileBasicInfo extends BaseEntity { */ private String delFlag; - public void setId(Long id) { - this.id = id; - } - - public Long getId() { - return id; - } - - public void setSn(String sn) { - this.sn = sn; - } - - public String getSn() { - return sn; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public void setBusinessType(String businessType) { - this.businessType = businessType; - } - - public String getBusinessType() { - return businessType; - } - - public void setSoftwareProtocol(String softwareProtocol) { - this.softwareProtocol = softwareProtocol; - } - - public String getSoftwareProtocol() { - return softwareProtocol; - } - - public void setProductionDate(Date productionDate) { - this.productionDate = productionDate; - } - - public Date getProductionDate() { - return productionDate; - } - - public void setLicenceId(Long licenceId) { - this.licenceId = licenceId; - } - - public Long getLicenceId() { - return licenceId; - } - - public void setModelId(Long modelId) { - this.modelId = modelId; - } - - public Long getModelId() { - return modelId; - } - - public void setSimId(Long simId) { - this.simId = simId; - } - - public Long getSimId() { - return simId; - } - - public void setMerchantId(Long merchantId) { - this.merchantId = merchantId; - } - - public Long getMerchantId() { - return merchantId; - } - - public void setStationId(Long stationId) { - this.stationId = stationId; - } - - public Long getStationId() { - return stationId; - } - - public void setFaultReason(String faultReason) { - this.faultReason = faultReason; - } - - public String getFaultReason() { - return faultReason; - } - - public void setDelFlag(String delFlag) { - this.delFlag = delFlag; - } - - public String getDelFlag() { - return delFlag; - } - - public String getSecretKey() { - return secretKey; - } - - public void setSecretKey(String secretKey) { - this.secretKey = secretKey; - } - - public static long getSerialVersionUID() { - return serialVersionUID; - } - - @Override - public Date getCreateTime() { - return createTime; - } - - public void setCreateTime(Date createTime) { - this.createTime = createTime; - } - @Override public String toString() { return new ToStringBuilder(this, ToStringStyle.JSON_STYLE) diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/domain/ebike/deviceupload/EBikeMessageCmd20.java b/jsowell-pile/src/main/java/com/jsowell/pile/domain/ebike/deviceupload/EBikeMessageCmd20.java index 5d1d671d8..a1610074a 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/domain/ebike/deviceupload/EBikeMessageCmd20.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/domain/ebike/deviceupload/EBikeMessageCmd20.java @@ -42,7 +42,7 @@ public class EBikeMessageCmd20 extends AbsEBikeMessage { /** * 端口数量 表示设备总共有多少个端口 */ - private String portNumber; + private int portNumber; /** * 虚拟ID:需要内部组网的设备的本地地址,如485、LORA系列,如不需组网的设备,默认为00 @@ -66,7 +66,7 @@ public class EBikeMessageCmd20 extends AbsEBikeMessage { public DeviceRegister(byte[] dataBytes) { this.firmwareVersion = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, 0, 2)) * 0.01 + ""; - this.portNumber = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, 2, 3)) + ""; + this.portNumber = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, 2, 3)); this.virtualId = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, 3, 4)) + ""; this.deviceType = BytesUtil.printHexBinary(Arrays.copyOfRange(dataBytes, 4, 5)); this.workMode = BytesUtil.bcd2StrLittle(Arrays.copyOfRange(dataBytes, 5, 6)); diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/PileBasicInfoService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/PileBasicInfoService.java index d0ff490df..463697708 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/PileBasicInfoService.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/PileBasicInfoService.java @@ -2,6 +2,7 @@ package com.jsowell.pile.service; import com.jsowell.common.core.domain.ykc.RealTimeMonitorData; import com.jsowell.pile.domain.PileBasicInfo; +import com.jsowell.pile.domain.ebike.deviceupload.EBikeMessageCmd20; import com.jsowell.pile.dto.*; import com.jsowell.pile.thirdparty.ConnectorInfo; import com.jsowell.pile.thirdparty.EquipmentInfo; @@ -221,4 +222,10 @@ public interface PileBasicInfoService { String startPersonalPileCharging(StartPersonPileDTO dto); void startupResult(ReservationChargingStartupResult chargingStartupResult); + + /** + * 注册电单车桩 + * @param message + */ + void registrationEBikePile(EBikeMessageCmd20 message); } 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 0d787f9f5..5d7c7c4cb 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 @@ -11,13 +11,11 @@ import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; import com.jsowell.common.core.redis.RedisCache; import com.jsowell.common.enums.DelFlagEnum; import com.jsowell.common.enums.lianlian.LianLianPileStatusEnum; -import com.jsowell.common.enums.ykc.PileConnectorDataBaseStatusEnum; -import com.jsowell.common.enums.ykc.PileConnectorStatusEnum; -import com.jsowell.common.enums.ykc.PileStatusEnum; -import com.jsowell.common.enums.ykc.ReturnCodeEnum; +import com.jsowell.common.enums.ykc.*; import com.jsowell.common.exception.BusinessException; import com.jsowell.common.util.*; import com.jsowell.pile.domain.*; +import com.jsowell.pile.domain.ebike.deviceupload.EBikeMessageCmd20; import com.jsowell.pile.dto.*; import com.jsowell.pile.mapper.PileBasicInfoMapper; import com.jsowell.pile.service.*; @@ -27,6 +25,8 @@ import com.jsowell.pile.thirdparty.ConnectorInfo; import com.jsowell.pile.thirdparty.EquipmentInfo; import com.jsowell.pile.thirdparty.ZDLConnectorInfo; import com.jsowell.pile.thirdparty.ZDLEquipmentInfo; +import com.jsowell.pile.transaction.dto.PileTransactionDTO; +import com.jsowell.pile.transaction.service.TransactionService; import com.jsowell.pile.util.UserUtils; import com.jsowell.pile.vo.base.MerchantInfoVO; import com.jsowell.pile.vo.base.PileInfoVO; @@ -83,6 +83,9 @@ public class PileBasicInfoServiceImpl implements PileBasicInfoService { @Autowired private RedisCache redisCache; + @Autowired + private TransactionService pileTransactionService; + @Value("${baseurl.prefix}") private String BASE_URL_PREFIX; @@ -1249,4 +1252,59 @@ public class PileBasicInfoServiceImpl implements PileBasicInfoService { wxAppletRemoteService.reservationStartupResultSendMsg(memberVO.getOpenId(), startTime, endTime, startUpResult, failReason); } } + + /** + * 注册电单车桩 + * @param message + */ + @Override + public void registrationEBikePile(EBikeMessageCmd20 message) { + // 根据物理id(桩编号)查询桩信息 + PileBasicInfo pileBasicInfo = this.selectPileBasicInfoBySN(message.getPhysicalId() + ""); + if (pileBasicInfo != null) { + return; + } + List basicInfoList = Lists.newArrayList(); + List connectorInfoList = Lists.newArrayList(); + + // 组装pile_basic_info表数据 + PileBasicInfo basicInfo = new PileBasicInfo(); + // 桩编号 + String sn = message.getPhysicalId() + ""; + basicInfo.setSn(sn); + basicInfo.setBusinessType(Constants.ONE); // 经营类型 1-运营桩;2-个人桩 + basicInfo.setSoftwareProtocol(Constants.THREE); // 软件协议 + basicInfo.setMerchantId(Long.valueOf("1")); // 运营商id 默认1 + basicInfo.setStationId(Long.valueOf("2")); // 站点id + basicInfo.setModelId(null); // 型号id + basicInfo.setProductionDate(new Date()); // 生产日期 + basicInfo.setLicenceId(null); // TODO 证书编号 + basicInfo.setSimId(null); // TODO sim卡 + basicInfo.setRemark(null); // 备注 + basicInfo.setCreateBy("system"); // 创建人 + basicInfo.setDelFlag(DelFlagEnum.NORMAL.getValue()); // 删除标识 + basicInfoList.add(basicInfo); + + EBikeMessageCmd20.DeviceRegister deviceRegister = message.getDeviceRegister(); + int portNumber = deviceRegister.getPortNumber(); + PileConnectorInfo connectorInfo; + for (int i = 1; i < portNumber + 1; i++) { + // 组装pile_connector_info表数据 + connectorInfo = new PileConnectorInfo(); + connectorInfo.setPileSn(sn); // sn号 + String connectorCode = String.format("%1$02d", i); + connectorInfo.setPileConnectorCode(sn + connectorCode); // 枪口号 + connectorInfo.setStatus(Constants.ZERO); //状态,默认 0-离网 + connectorInfo.setCreateBy(SecurityUtils.getUsername()); // 创建人 + connectorInfo.setDelFlag(DelFlagEnum.NORMAL.getValue()); // 删除标识 + connectorInfoList.add(connectorInfo); + } + + // 批量入库 + PileTransactionDTO transactionDTO = PileTransactionDTO.builder() + .pileBasicInfoList(basicInfoList) + .pileConnectorInfoList(connectorInfoList) + .build(); + pileTransactionService.doCreatePileTransaction(transactionDTO); + } }