下发指令

This commit is contained in:
2025-10-17 15:34:40 +08:00
parent 943aa3e2d0
commit 618d0d4f0a
4 changed files with 48 additions and 9 deletions

View File

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

View File

@ -10,5 +10,5 @@ public interface ElectronicFenceMapper extends BaseMapper<BaseUser> {
String selectZcElectronicFenceById(Long id);
String selectIotBrandById(String id);
}

View File

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

View File

@ -10,4 +10,8 @@
where a.id = #{id}
</select>
<select id="selectIotBrandById" parameterType="String" resultType="java.lang.String">
select lot_brand from zc_car where lot_number = #{id}
</select>
</mapper>