1. 增加获取警报任务执行状态查询服务
This commit is contained in:
parent
45e1305ed6
commit
2c07aad6cb
|
@ -0,0 +1,32 @@
|
||||||
|
package com.zjyr.beidouservice.common.impl;
|
||||||
|
|
||||||
|
import com.zjyr.beidouservice.common.EnumerationBase;
|
||||||
|
|
||||||
|
public enum TaskStatusName implements EnumerationBase {
|
||||||
|
TASK_OK(0, "TASK_OK"),
|
||||||
|
|
||||||
|
TASK_ERROR(1, "TASK_ERROR"),
|
||||||
|
|
||||||
|
TASK_TIMEOUT(2, "TASK_TIMEOUT"),
|
||||||
|
|
||||||
|
TASK_UNRESPONSE(3, "TASK_UNRESPONSE"),
|
||||||
|
;
|
||||||
|
|
||||||
|
private final Integer code;
|
||||||
|
private final String desc;
|
||||||
|
|
||||||
|
TaskStatusName(int val, String desc) {
|
||||||
|
this.code = val;
|
||||||
|
this.desc = desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer getValue() {
|
||||||
|
return this.code;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return this.desc;
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,10 +12,6 @@ public interface SensorTaskMapper {
|
||||||
|
|
||||||
List<SensorTask> selectAllByTaskId(@Param("taskId") Integer taskId);
|
List<SensorTask> selectAllByTaskId(@Param("taskId") Integer taskId);
|
||||||
|
|
||||||
List<Long> selectAllResponse(@Param("taskId") Integer taskId);
|
|
||||||
|
|
||||||
List<Long> selectAllRsponseSuccessed(@Param("taskId") Integer taskId);
|
|
||||||
|
|
||||||
int addNewSensorTaskData(@Param("sensor") SensorTask sensorTask);
|
int addNewSensorTaskData(@Param("sensor") SensorTask sensorTask);
|
||||||
|
|
||||||
int addNewSensorTaskDatas(@Param("taskLists") List<SensorTask> taskLists);
|
int addNewSensorTaskDatas(@Param("taskLists") List<SensorTask> taskLists);
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.zjyr.beidouservice.pojo.po;
|
||||||
|
|
||||||
|
import com.zjyr.beidouservice.common.impl.TaskStatusName;
|
||||||
|
import com.zjyr.beidouservice.pojo.entry.SensorTask;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
@Data
|
||||||
|
public class AlarmTaskResult {
|
||||||
|
private Long sensorId;
|
||||||
|
private TaskStatusName taskStatus;
|
||||||
|
private SensorTask taskInfo;
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ package com.zjyr.beidouservice.service;
|
||||||
|
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
import com.zjyr.beidouservice.pojo.entry.SensorTask;
|
import com.zjyr.beidouservice.pojo.entry.SensorTask;
|
||||||
|
import com.zjyr.beidouservice.pojo.po.AlarmTaskResult;
|
||||||
import com.zjyr.beidouservice.pojo.vo.binary.SensorTaskAck;
|
import com.zjyr.beidouservice.pojo.vo.binary.SensorTaskAck;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -13,8 +14,7 @@ public interface SensorTaskService {
|
||||||
|
|
||||||
int getRespSuccessedSensors(int taskId);
|
int getRespSuccessedSensors(int taskId);
|
||||||
|
|
||||||
List<Long> getResponseSuccessedItems(int taskId);
|
List<AlarmTaskResult> getSensorTaskResult(int taskId, long timeOut, List<Long> sensorId);
|
||||||
List<Long> getResponsedItems(int taskId);
|
|
||||||
|
|
||||||
PageInfo<SensorTask> querySensorTaskData(int taskId, int page, int nItems);
|
PageInfo<SensorTask> querySensorTaskData(int taskId, int page, int nItems);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,11 @@ package com.zjyr.beidouservice.service.impl;
|
||||||
|
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
|
import com.zjyr.beidouservice.common.impl.TaskResultName;
|
||||||
|
import com.zjyr.beidouservice.common.impl.TaskStatusName;
|
||||||
import com.zjyr.beidouservice.mapper.SensorTaskMapper;
|
import com.zjyr.beidouservice.mapper.SensorTaskMapper;
|
||||||
import com.zjyr.beidouservice.pojo.entry.SensorTask;
|
import com.zjyr.beidouservice.pojo.entry.SensorTask;
|
||||||
|
import com.zjyr.beidouservice.pojo.po.AlarmTaskResult;
|
||||||
import com.zjyr.beidouservice.pojo.vo.binary.SensorTaskAck;
|
import com.zjyr.beidouservice.pojo.vo.binary.SensorTaskAck;
|
||||||
import com.zjyr.beidouservice.service.SensorTaskService;
|
import com.zjyr.beidouservice.service.SensorTaskService;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
@ -24,19 +27,19 @@ public class SensorTaskServiceImpl implements SensorTaskService {
|
||||||
@Override
|
@Override
|
||||||
public void addSensorTaskResponse(Long controlId, SensorTaskAck sensorTaskAck) {
|
public void addSensorTaskResponse(Long controlId, SensorTaskAck sensorTaskAck) {
|
||||||
List<SensorTask> sensorTasks = new ArrayList<>();
|
List<SensorTask> sensorTasks = new ArrayList<>();
|
||||||
Date timeStamp = new Date(sensorTaskAck.getAckTimestamp() * 1000L);
|
Date timeStamp = new Date(sensorTaskAck.getAckTimestamp() * 1000L);
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
|
||||||
for (var v : sensorTaskAck.getSensorStatus()) {
|
for (var v : sensorTaskAck.getSensorStatus()) {
|
||||||
sensorTasks.add(SensorTask.builder()
|
sensorTasks.add(SensorTask.builder()
|
||||||
.taskId(sensorTaskAck.getTaskId())
|
.taskId(sensorTaskAck.getTaskId())
|
||||||
.deviceId(controlId)
|
.deviceId(controlId)
|
||||||
.sensorId((long) v.getSensorId())
|
.sensorId((long) v.getSensorId())
|
||||||
.deviceId(0L)
|
.deviceId(0L)
|
||||||
.taskResult(v.getTaskResult())
|
.taskResult(v.getTaskResult())
|
||||||
.channel(v.getTunnelName())
|
.channel(v.getTunnelName())
|
||||||
.reportTime(sdf.format(timeStamp))
|
.reportTime(sdf.format(timeStamp))
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
sensorTaskMapper.addNewSensorTaskDatas(sensorTasks);
|
sensorTaskMapper.addNewSensorTaskDatas(sensorTasks);
|
||||||
|
@ -53,20 +56,64 @@ public class SensorTaskServiceImpl implements SensorTaskService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Long> getResponseSuccessedItems(int taskId) {
|
public List<AlarmTaskResult> getSensorTaskResult(int taskId, long timeOut, List<Long> sensorId) {
|
||||||
return null;
|
List<AlarmTaskResult> results = new ArrayList<>(sensorId.size());
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
if (sensorId.isEmpty()) {
|
||||||
public List<Long> getResponsedItems(int taskId) {
|
return results;
|
||||||
return null;
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TaskStatusName respStatus = System.currentTimeMillis() > timeOut ? TaskStatusName.TASK_TIMEOUT :
|
||||||
|
TaskStatusName.TASK_UNRESPONSE;
|
||||||
|
|
||||||
|
List<SensorTask> allTask = sensorTaskMapper.selectAllByTaskId(taskId);
|
||||||
|
List<SensorTask> successedTask =
|
||||||
|
allTask.stream().filter(k -> k.getTaskResult() == TaskResultName.TASK_RESULT_SUCCESSED).toList();
|
||||||
|
List<SensorTask> failedTask =
|
||||||
|
allTask.stream().filter(k -> !successedTask.stream().map(SensorTask::getSensorId).toList().contains(k.getSensorId())).toList();
|
||||||
|
List<Long> unResponse =
|
||||||
|
sensorId.stream().filter(k -> !allTask.stream().map(SensorTask::getSensorId).toList().contains(k)).toList();
|
||||||
|
|
||||||
|
for (var v : unResponse) {
|
||||||
|
AlarmTaskResult result = AlarmTaskResult.builder()
|
||||||
|
.sensorId(v)
|
||||||
|
.taskStatus(respStatus)
|
||||||
|
.taskInfo(null)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
results.add(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var v : failedTask) {
|
||||||
|
AlarmTaskResult result = AlarmTaskResult.builder()
|
||||||
|
.sensorId(v.getSensorId())
|
||||||
|
.taskStatus(TaskStatusName.TASK_ERROR)
|
||||||
|
.taskInfo(v)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
results.add(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var v : successedTask) {
|
||||||
|
AlarmTaskResult result = AlarmTaskResult.builder()
|
||||||
|
.sensorId(v.getSensorId())
|
||||||
|
.taskStatus(TaskStatusName.TASK_OK)
|
||||||
|
.taskInfo(v)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
results.add(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageInfo<SensorTask> querySensorTaskData(int taskId, int page, int nItems) {
|
public PageInfo<SensorTask> querySensorTaskData(int taskId, int page, int nItems) {
|
||||||
PageHelper.startPage(page, nItems);
|
PageHelper.startPage(page, nItems);
|
||||||
List<SensorTask> sensorTasks = sensorTaskMapper.selectAllByTaskId(taskId);
|
List<SensorTask> sensorTasks = sensorTaskMapper.selectAllByTaskId(taskId);
|
||||||
PageInfo<SensorTask> pgInfo = new PageInfo<>(sensorTasks);
|
PageInfo<SensorTask> pgInfo = new PageInfo<>(sensorTasks);
|
||||||
PageHelper.clearPage();
|
PageHelper.clearPage();
|
||||||
return pgInfo;
|
return pgInfo;
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,10 +81,4 @@
|
||||||
WHERE taskResult = ${@com.zjyr.beidouservice.common.impl.TaskResultName@TASK_RESULT_SUCCESSED.getValue()}
|
WHERE taskResult = ${@com.zjyr.beidouservice.common.impl.TaskResultName@TASK_RESULT_SUCCESSED.getValue()}
|
||||||
AND taskId = #{taskId};
|
AND taskId = #{taskId};
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectAllResponse" resultType="java.lang.Long">
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<select id="selectAllRsponseSuccessed" resultType="java.lang.Long">
|
|
||||||
</select>
|
|
||||||
</mapper>
|
</mapper>
|
|
@ -2,6 +2,7 @@ package com.zjyr.beidouservice.service;
|
||||||
|
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
import com.zjyr.beidouservice.pojo.entry.SensorTask;
|
import com.zjyr.beidouservice.pojo.entry.SensorTask;
|
||||||
|
import com.zjyr.beidouservice.pojo.po.AlarmTaskResult;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
@ -10,6 +11,9 @@ import org.springframework.test.annotation.DirtiesContext;
|
||||||
import org.springframework.test.annotation.Rollback;
|
import org.springframework.test.annotation.Rollback;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
|
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
|
||||||
|
@ -28,4 +32,17 @@ public class SensorTaskServiceTest {
|
||||||
log.info("Item ID: {}", c.getId());
|
log.info("Item ID: {}", c.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getSensorTaskResult() {
|
||||||
|
List<Long> sensorId = new ArrayList<>();
|
||||||
|
for(long i = 0; i < 10; i++) {
|
||||||
|
sensorId.add(i);
|
||||||
|
}
|
||||||
|
List<AlarmTaskResult> task = sensorTaskService.getSensorTaskResult(0, System.currentTimeMillis(), sensorId);
|
||||||
|
|
||||||
|
for (var c : task) {
|
||||||
|
log.info("Item: {}, {}", c.getSensorId(), c.getTaskStatus());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue