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<Long> selectAllResponse(@Param("taskId") Integer taskId);
|
||||
|
||||
List<Long> selectAllRsponseSuccessed(@Param("taskId") Integer taskId);
|
||||
|
||||
int addNewSensorTaskData(@Param("sensor") SensorTask sensorTask);
|
||||
|
||||
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.zjyr.beidouservice.pojo.entry.SensorTask;
|
||||
import com.zjyr.beidouservice.pojo.po.AlarmTaskResult;
|
||||
import com.zjyr.beidouservice.pojo.vo.binary.SensorTaskAck;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -13,8 +14,7 @@ public interface SensorTaskService {
|
|||
|
||||
int getRespSuccessedSensors(int taskId);
|
||||
|
||||
List<Long> getResponseSuccessedItems(int taskId);
|
||||
List<Long> getResponsedItems(int taskId);
|
||||
List<AlarmTaskResult> getSensorTaskResult(int taskId, long timeOut, List<Long> sensorId);
|
||||
|
||||
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.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.pojo.entry.SensorTask;
|
||||
import com.zjyr.beidouservice.pojo.po.AlarmTaskResult;
|
||||
import com.zjyr.beidouservice.pojo.vo.binary.SensorTaskAck;
|
||||
import com.zjyr.beidouservice.service.SensorTaskService;
|
||||
import jakarta.annotation.Resource;
|
||||
|
@ -53,13 +56,57 @@ public class SensorTaskServiceImpl implements SensorTaskService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getResponseSuccessedItems(int taskId) {
|
||||
return null;
|
||||
public List<AlarmTaskResult> getSensorTaskResult(int taskId, long timeOut, List<Long> sensorId) {
|
||||
List<AlarmTaskResult> results = new ArrayList<>(sensorId.size());
|
||||
|
||||
if (sensorId.isEmpty()) {
|
||||
return results;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getResponsedItems(int taskId) {
|
||||
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
|
||||
|
|
|
@ -81,10 +81,4 @@
|
|||
WHERE taskResult = ${@com.zjyr.beidouservice.common.impl.TaskResultName@TASK_RESULT_SUCCESSED.getValue()}
|
||||
AND taskId = #{taskId};
|
||||
</select>
|
||||
|
||||
<select id="selectAllResponse" resultType="java.lang.Long">
|
||||
</select>
|
||||
|
||||
<select id="selectAllRsponseSuccessed" resultType="java.lang.Long">
|
||||
</select>
|
||||
</mapper>
|
|
@ -2,6 +2,7 @@ package com.zjyr.beidouservice.service;
|
|||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.zjyr.beidouservice.pojo.entry.SensorTask;
|
||||
import com.zjyr.beidouservice.pojo.po.AlarmTaskResult;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@Slf4j
|
||||
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
|
||||
|
@ -28,4 +32,17 @@ public class SensorTaskServiceTest {
|
|||
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