whyczh
2021-04-02 4ae9710a5a4b6eadb6e65ed74ca68d575605240c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package com.whyc.controller;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.whyc.dto.Response;
import com.whyc.pojo.DeviceInf;
import com.whyc.pojo.DeviceType;
import com.whyc.pojo.TestPlan;
import com.whyc.service.DeviceInfService;
import com.whyc.service.DeviceTypeService;
import com.whyc.service.TestPlanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
 
@RestController
@RequestMapping("testConfig")
@Slf4j
@Api(tags = "试验配置")
public class TestConfigController {
    @Autowired
    @Qualifier("deviceInfService")
    private DeviceInfService deviceInfService;
    @Resource(name = "deviceTypeService")
    private DeviceTypeService deviceTypeService;
    @Resource(name = "testPlanService")
    private TestPlanService testPlanService;
 
    @PutMapping("updateConfig")
    @ApiOperation("更新配置参数")
    public Response setDefautlTestConfig(@RequestBody List<DeviceInf> deviceInfList){
        for (DeviceInf deviceInf: deviceInfList) {
            deviceInfService.update(deviceInf);
        }
        return new Response().setMsg(1,"更新成功");
 
    }
 
    @GetMapping("defaultConfig")
    @ApiOperation("默认参数配置")
    public Response getDefaultTestConfig(@RequestParam Integer num){
        TestPlan testPlan = testPlanService.getOneById(num);
        String devices = testPlan.getDevices();
        String[] deviceIds = devices.split(",");
        List<DeviceInf> deviceInfList = new ArrayList<>();
        for (String deviceId : deviceIds) {
            DeviceInf deviceInf = getDefaultConfig(Integer.valueOf(deviceId));
            deviceInfList.add(deviceInf);
        }
        return new Response().set(1,deviceInfList);
    }
    //设备id获取设备类型id,将设备类型的默认参数复制到设备类返回
    public DeviceInf getDefaultConfig(Integer deviceId){
        DeviceInf deviceInf = deviceInfService.getOneByDeviceId(deviceId);
        DeviceType deviceType = deviceTypeService.getOneByDeviceTypeId(deviceInf.getSystemId());
        deviceInf.setLoadStartType(deviceType.getLoadStartType());
        deviceInf.setLoadRuntimeHour(deviceType.getLoadRuntimeHour());
        deviceInf.setLoadRuntimeMin(deviceType.getLoadRuntimeMin());
        deviceInf.setLoadCurrStd(deviceType.getLoadCurrStd());
        deviceInf.setLoadVolStd(deviceType.getLoadVolStd());
        deviceInf.setLoadRpm(deviceType.getLoadRpm());
        deviceInf.setLoadTorque(deviceType.getLoadTorque());
        deviceInf.setLoadPropulsionShaft(deviceType.getLoadPropulsionShaft());
        return deviceInf;
    }
 
 
}