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 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 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()); 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; } }