whycxzp
2021-09-28 7d64716cb0d406f21cde03976fd273bd07fdc06f
src/main/java/com/whyc/controller/TestConfigController.java
@@ -5,16 +5,20 @@
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.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
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")
@@ -22,24 +26,65 @@
@Api(tags = "试验配置")
public class TestConfigController {
    @Autowired
    @Qualifier("deviceInfService")
    private DeviceInfService deviceInfService;
    @Autowired
    @Resource(name = "deviceTypeService")
    private DeviceTypeService deviceTypeService;
    @Resource(name = "testPlanService")
    private TestPlanService testPlanService;
    @PutMapping
    @ApiOperation("加载默认配置参数")
    public Response setDefautlTestConfig(@RequestParam Integer deviceId){
    @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 deviceInfService.update(deviceInf);
        if (deviceInf.getLoadStartType() == null) {
            deviceInf.setLoadStartType(deviceType.getLoadStartType());
        }
        if (deviceInf.getLoadRuntimeHour() == null) {
            deviceInf.setLoadRuntimeHour(deviceType.getLoadRuntimeHour());
        }
        if (deviceInf.getLoadRuntimeMin() == null) {
            deviceInf.setLoadRuntimeMin(deviceType.getLoadRuntimeMin());
        }
        if (deviceInf.getLoadCurrStd() == null) {
            deviceInf.setLoadCurrStd(deviceType.getLoadCurrStd());
        }
        if (deviceInf.getLoadVolStd() == null) {
            deviceInf.setLoadVolStd(deviceType.getLoadVolStd());
        }
        if (deviceInf.getLoadRpm() == null) {
            deviceInf.setLoadRpm(deviceType.getLoadRpm());
        }
        if (deviceInf.getLoadTorque() == null) {
            deviceInf.setLoadTorque(deviceType.getLoadTorque());
        }
        if (deviceInf.getLoadPropulsionShaft() == null) {
            deviceInf.setLoadPropulsionShaft(deviceType.getLoadPropulsionShaft());
        }
        return deviceInf;
    }