whycxzp
2021-09-28 7d64716cb0d406f21cde03976fd273bd07fdc06f
src/main/java/com/whyc/controller/TestDataController.java
@@ -1,8 +1,11 @@
package com.whyc.controller;
import com.google.gson.JsonObject;
import com.whyc.dto.Response;
import com.whyc.dto.TestDataDTO;
import com.whyc.pojo.MotorState;
import com.whyc.pojo.TestPlan;
import com.whyc.service.DeviceInfService;
import com.whyc.service.MotorStateService;
import com.whyc.service.TestPlanService;
import io.swagger.annotations.Api;
@@ -16,19 +19,26 @@
import javax.annotation.Resource;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
@RestController
@RequestMapping("testData")
@Api(tags = "实验数据")
@Api(tags = "试验数据")
@Slf4j
public class TestDataController {
    @Autowired
    private TestPlanService testPlanService;
    @Resource
    private MotorStateService motorStateService;
    @Autowired
    private DeviceInfService deviceInfService;
    @GetMapping("ws")
    @ApiOperation(value="查询webSocket",protocols = "ws",notes = "接口:ws://localhost:8090/testData,发送消息为testPlanId")
    public Response doc(){
        return new Response().setMsg(1,"查看接口描述");
    }
    @GetMapping()
    @ApiOperation("获取历史数据")
@@ -42,11 +52,16 @@
        String startTime = dateFormat.format(testPlan.getStartTime());
        String endTime = dateFormat.format(testPlan.getEndTime());
        //通过设备和开始结束时间来获取对应的数据
        Map<String,List<MotorState>> map = new HashMap<>();
        List<TestDataDTO> list = new ArrayList<TestDataDTO>();
        for (String deviceId: devIds) {
            List<MotorState> historyData =  motorStateService.getHistoryData(deviceId,startTime,endTime);
            map.put(deviceId,historyData);
            String deviceName = deviceInfService.getOneByDeviceId(Integer.valueOf(deviceId)).getDeviceName();
            TestDataDTO testDataDTO = new TestDataDTO();
            testDataDTO.setDeviceId(deviceId);
            testDataDTO.setDeviceName(deviceName);
            testDataDTO.setData(historyData);
            list.add(testDataDTO);
        }
        return new Response().set(1,map);
        return new Response().set(1,list);
    }
}