From 618d0d4f0a7ba915445d912cd02288ab932fdb48 Mon Sep 17 00:00:00 2001 From: eric <465889110@qq.com> Date: Fri, 17 Oct 2025 15:34:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8B=E5=8F=91=E6=8C=87=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/sczx/sync/dto/CommandDTO.java | 12 ++++++ .../sync/mapper/ElectronicFenceMapper.java | 2 +- .../impl/ElectronicFenceServiceImpl.java | 39 +++++++++++++++---- .../mapper/ElectronicFenceMapper.xml | 4 ++ 4 files changed, 48 insertions(+), 9 deletions(-) create mode 100644 src/main/java/com/sczx/sync/dto/CommandDTO.java diff --git a/src/main/java/com/sczx/sync/dto/CommandDTO.java b/src/main/java/com/sczx/sync/dto/CommandDTO.java new file mode 100644 index 0000000..b6eeea7 --- /dev/null +++ b/src/main/java/com/sczx/sync/dto/CommandDTO.java @@ -0,0 +1,12 @@ +package com.sczx.sync.dto; + + +import lombok.Data; + +@Data +public class CommandDTO { + + private String clientld; + private Integer command; + private Integer providerld; +} diff --git a/src/main/java/com/sczx/sync/mapper/ElectronicFenceMapper.java b/src/main/java/com/sczx/sync/mapper/ElectronicFenceMapper.java index 9465eba..254592d 100644 --- a/src/main/java/com/sczx/sync/mapper/ElectronicFenceMapper.java +++ b/src/main/java/com/sczx/sync/mapper/ElectronicFenceMapper.java @@ -10,5 +10,5 @@ public interface ElectronicFenceMapper extends BaseMapper { String selectZcElectronicFenceById(Long id); - + String selectIotBrandById(String id); } diff --git a/src/main/java/com/sczx/sync/service/impl/ElectronicFenceServiceImpl.java b/src/main/java/com/sczx/sync/service/impl/ElectronicFenceServiceImpl.java index c5b972d..d32322b 100644 --- a/src/main/java/com/sczx/sync/service/impl/ElectronicFenceServiceImpl.java +++ b/src/main/java/com/sczx/sync/service/impl/ElectronicFenceServiceImpl.java @@ -1,10 +1,13 @@ package com.sczx.sync.service.impl; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.sczx.sync.dto.CommandDTO; import com.sczx.sync.dto.DeviceData; import com.sczx.sync.mapper.ElectronicFenceMapper; import com.sczx.sync.service.ElectronicFenceService; +import com.sczx.sync.service.ThirdPartyForwardService; import com.sczx.sync.utils.Point; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -13,6 +16,7 @@ import java.util.ArrayList; import java.util.List; import com.sczx.sync.utils.RedisUtil; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; @@ -24,7 +28,13 @@ public class ElectronicFenceServiceImpl implements ElectronicFenceService { @Autowired private RedisUtil redisUtils; @Autowired - private ElectronicFenceMapper ElectronicFenceMapper; + private ElectronicFenceMapper electronicFenceMapper; + + @Value("${iot-url}") + private String URL; + + @Autowired + private ThirdPartyForwardService thirdPartyForwardService; @Override public void checkCarPositionInFence(DeviceData deviceLocation) { @@ -39,7 +49,9 @@ public class ElectronicFenceServiceImpl implements ElectronicFenceService { } String fenceId = redisUtils.get(redisEfenceKey); // 查询电子围栏 - String electronicFenceString = ElectronicFenceMapper.selectZcElectronicFenceById(Long.parseLong(fenceId)); + String electronicFenceString = electronicFenceMapper.selectZcElectronicFenceById(Long.parseLong(fenceId)); + + String iotBrands = electronicFenceMapper.selectIotBrandById(clientId); if (electronicFenceString == null) { return ; @@ -63,10 +75,10 @@ public class ElectronicFenceServiceImpl implements ElectronicFenceService { // 状态发生变化时执行相应操作 if (currentlyInFence && "油路断开".equals(fuleStatus)) { // 进入围栏 - 发出放电指令 - sendPowerOnCommand(clientId); + sendPowerOnCommand(clientId,iotBrands); } else if (!currentlyInFence && "油路正常".equals(fuleStatus)) { // 超出围栏 - 发出断电指令 - sendPowerOffCommand(clientId); + sendPowerOffCommand(clientId,iotBrands); } @@ -136,10 +148,15 @@ public class ElectronicFenceServiceImpl implements ElectronicFenceService { * * @param clientId 车辆识别号 */ - private void sendPowerOnCommand(String clientId) { + private void sendPowerOnCommand(String clientId,String iotBrands) { // 实际实现发送通电指令到设备 + CommandDTO commandDTO = new CommandDTO(); - log.info("发送通电指令给车辆: " + clientId); + commandDTO.setClientld(clientId); + commandDTO.setCommand(3); + commandDTO.setProviderld(Integer.parseInt(iotBrands)); + String response = thirdPartyForwardService.forwardData(URL+"/device/8304", JSON.toJSONString(commandDTO)); + log.info("发送通电指令给车辆: {} , 响应: {}" + clientId ,response); } /** @@ -147,9 +164,15 @@ public class ElectronicFenceServiceImpl implements ElectronicFenceService { * * @param clientId 车辆识别号 */ - private void sendPowerOffCommand(String clientId) { + private void sendPowerOffCommand(String clientId,String iotBrands) { // 实际实现发送断电指令到设备 + CommandDTO commandDTO = new CommandDTO(); + commandDTO.setClientld(clientId); + commandDTO.setCommand(2); + commandDTO.setProviderld(Integer.parseInt(iotBrands)); - log.info("发送断电指令给车辆: " + clientId); + + String response = thirdPartyForwardService.forwardData(URL+"/device/8304", JSON.toJSONString(commandDTO)); + log.info("发送断电指令给车辆: {} , 响应: {}" + clientId ,response); } } diff --git a/src/main/resources/mapper/ElectronicFenceMapper.xml b/src/main/resources/mapper/ElectronicFenceMapper.xml index 6b8c945..1d1e7bf 100644 --- a/src/main/resources/mapper/ElectronicFenceMapper.xml +++ b/src/main/resources/mapper/ElectronicFenceMapper.xml @@ -10,4 +10,8 @@ where a.id = #{id} + +