下发指令
This commit is contained in:
12
src/main/java/com/sczx/sync/dto/CommandDTO.java
Normal file
12
src/main/java/com/sczx/sync/dto/CommandDTO.java
Normal 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;
|
||||||
|
}
|
||||||
@ -10,5 +10,5 @@ public interface ElectronicFenceMapper extends BaseMapper<BaseUser> {
|
|||||||
|
|
||||||
String selectZcElectronicFenceById(Long id);
|
String selectZcElectronicFenceById(Long id);
|
||||||
|
|
||||||
|
String selectIotBrandById(String id);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,13 @@
|
|||||||
package com.sczx.sync.service.impl;
|
package com.sczx.sync.service.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.sczx.sync.dto.CommandDTO;
|
||||||
import com.sczx.sync.dto.DeviceData;
|
import com.sczx.sync.dto.DeviceData;
|
||||||
import com.sczx.sync.mapper.ElectronicFenceMapper;
|
import com.sczx.sync.mapper.ElectronicFenceMapper;
|
||||||
import com.sczx.sync.service.ElectronicFenceService;
|
import com.sczx.sync.service.ElectronicFenceService;
|
||||||
|
import com.sczx.sync.service.ThirdPartyForwardService;
|
||||||
import com.sczx.sync.utils.Point;
|
import com.sczx.sync.utils.Point;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -13,6 +16,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.sczx.sync.utils.RedisUtil;
|
import com.sczx.sync.utils.RedisUtil;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@ -24,7 +28,13 @@ public class ElectronicFenceServiceImpl implements ElectronicFenceService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private RedisUtil redisUtils;
|
private RedisUtil redisUtils;
|
||||||
@Autowired
|
@Autowired
|
||||||
private ElectronicFenceMapper ElectronicFenceMapper;
|
private ElectronicFenceMapper electronicFenceMapper;
|
||||||
|
|
||||||
|
@Value("${iot-url}")
|
||||||
|
private String URL;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ThirdPartyForwardService thirdPartyForwardService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void checkCarPositionInFence(DeviceData deviceLocation) {
|
public void checkCarPositionInFence(DeviceData deviceLocation) {
|
||||||
@ -39,7 +49,9 @@ public class ElectronicFenceServiceImpl implements ElectronicFenceService {
|
|||||||
}
|
}
|
||||||
String fenceId = redisUtils.get(redisEfenceKey);
|
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) {
|
if (electronicFenceString == null) {
|
||||||
return ;
|
return ;
|
||||||
@ -63,10 +75,10 @@ public class ElectronicFenceServiceImpl implements ElectronicFenceService {
|
|||||||
// 状态发生变化时执行相应操作
|
// 状态发生变化时执行相应操作
|
||||||
if (currentlyInFence && "油路断开".equals(fuleStatus)) {
|
if (currentlyInFence && "油路断开".equals(fuleStatus)) {
|
||||||
// 进入围栏 - 发出放电指令
|
// 进入围栏 - 发出放电指令
|
||||||
sendPowerOnCommand(clientId);
|
sendPowerOnCommand(clientId,iotBrands);
|
||||||
} else if (!currentlyInFence && "油路正常".equals(fuleStatus)) {
|
} else if (!currentlyInFence && "油路正常".equals(fuleStatus)) {
|
||||||
// 超出围栏 - 发出断电指令
|
// 超出围栏 - 发出断电指令
|
||||||
sendPowerOffCommand(clientId);
|
sendPowerOffCommand(clientId,iotBrands);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -136,10 +148,15 @@ public class ElectronicFenceServiceImpl implements ElectronicFenceService {
|
|||||||
*
|
*
|
||||||
* @param clientId 车辆识别号
|
* @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 车辆识别号
|
* @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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,4 +10,8 @@
|
|||||||
where a.id = #{id}
|
where a.id = #{id}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="selectIotBrandById" parameterType="String" resultType="java.lang.String">
|
||||||
|
select lot_brand from zc_car where lot_number = #{id}
|
||||||
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
Reference in New Issue
Block a user