parent
477b9bcaf0
commit
163b7b81ea
|
@ -13,4 +13,8 @@ public interface SensorTaskMapper {
|
|||
int addNewSensorTaskData(@Param("sensor") SensorTask sensorTask);
|
||||
|
||||
int addNewSensorTaskDatas(@Param("taskLists") List<SensorTask> taskLists);
|
||||
|
||||
int countTaskResponseSensor(@Param("taskId") Integer taskId);
|
||||
|
||||
int countTaskResponseSuccessedSensor(@Param("taskId") Integer taskId);
|
||||
}
|
||||
|
|
|
@ -4,4 +4,8 @@ import com.zjyr.beidouservice.pojo.vo.binary.SensorTaskAck;
|
|||
|
||||
public interface SensorTaskService {
|
||||
void addSensorTaskResponse(Long controlId, SensorTaskAck sensorTaskAck);
|
||||
|
||||
int getRespSensors(int taskId);
|
||||
|
||||
int getRespSuccessedSensors(int taskId);
|
||||
}
|
||||
|
|
|
@ -26,12 +26,26 @@ public class SensorTaskServiceImpl implements SensorTaskService {
|
|||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
for (var v : sensorTaskAck.getSensorStatus()) {
|
||||
sensorTasks.add(SensorTask.builder().taskId(sensorTaskAck.getTaskId())
|
||||
sensorTasks.add(SensorTask.builder()
|
||||
.taskId(sensorTaskAck.getTaskId())
|
||||
.deviceId(controlId)
|
||||
.sensorId((long) v.getSensorId()).deviceId(0L).taskResult(
|
||||
v.getTaskResult()).reportTime(sdf.format(timeStamp)).build());
|
||||
.sensorId((long) v.getSensorId())
|
||||
.deviceId(0L)
|
||||
.taskResult(v.getTaskResult())
|
||||
.reportTime(sdf.format(timeStamp))
|
||||
.build());
|
||||
}
|
||||
|
||||
sensorTaskMapper.addNewSensorTaskDatas(sensorTasks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRespSensors(int taskId) {
|
||||
return sensorTaskMapper.countTaskResponseSensor(taskId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRespSuccessedSensors(int taskId) {
|
||||
return sensorTaskMapper.countTaskResponseSuccessedSensor(taskId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,4 +50,17 @@
|
|||
TIMESTAMP(#{itme.reportTime}))
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<select id="countTaskResponseSensor" resultType="int">
|
||||
SELECT COUNT(DISTINCT sensorId) as cnt
|
||||
FROM sensor_task
|
||||
WHERE taskId = #{taskId};
|
||||
</select>
|
||||
|
||||
<select id="countTaskResponseSuccessedSensor" resultType="int">
|
||||
SELECT COUNT(DISTINCT sensorId) as cnt
|
||||
FROM sensor_task
|
||||
WHERE taskResult = ${@com.zjyr.beidouservice.common.impl.TaskResultName@TASK_RESULT_SUCCESSED.getValue()}
|
||||
AND taskId = #{taskId};
|
||||
</select>
|
||||
</mapper>
|
|
@ -8,14 +8,16 @@ import org.junit.jupiter.api.Assertions;
|
|||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.annotation.Rollback;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@Slf4j
|
||||
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
|
||||
//@Transactional
|
||||
//@Rollback
|
||||
@Transactional
|
||||
@Rollback
|
||||
public class ControlDeviceMapperTest {
|
||||
@Resource
|
||||
private ControlDeviceMapper controlDeviceMapper;
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
package com.zjyr.beidouservice.mapper;
|
||||
|
||||
import com.zjyr.beidouservice.pojo.entry.ControlDevice;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.annotation.Rollback;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@Slf4j
|
||||
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
|
||||
@Transactional
|
||||
@Rollback
|
||||
public class SensorTaskMapperTest {
|
||||
@Resource
|
||||
SensorTaskMapper sensorTaskMapper;
|
||||
|
||||
@Test
|
||||
public void a1_countTaskResponseSensor() {
|
||||
int nResponse = sensorTaskMapper.countTaskResponseSensor(0);
|
||||
Assertions.assertNotEquals(nResponse, 0);
|
||||
log.info("Total Response Sensor: {}", nResponse);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void a2_countTaskResponseSuccessedSensor() {
|
||||
int nResponseOK = sensorTaskMapper.countTaskResponseSuccessedSensor(0);
|
||||
Assertions.assertNotEquals(nResponseOK, 0);
|
||||
log.info("Total Response OK Sensor: {}", nResponseOK);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue