From 5868e3d214310c0dd3fa7632efc6906ce79217de Mon Sep 17 00:00:00 2001
From: whyczh <hzjl@qq.com>
Date: 星期一, 29 三月 2021 17:29:19 +0800
Subject: [PATCH] 更新试验计划接口

---
 src/main/java/com/whyc/controller/TestConfigController.java |   46 +++++++++++++++++++++++++++++++++++++---------
 1 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/src/main/java/com/whyc/controller/TestConfigController.java b/src/main/java/com/whyc/controller/TestConfigController.java
index 9227e34..c5f2956 100644
--- a/src/main/java/com/whyc/controller/TestConfigController.java
+++ b/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,13 +26,37 @@
 @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);
+    }
+    public DeviceInf getDefaultConfig(Integer deviceId){
         DeviceInf deviceInf = deviceInfService.getOneByDeviceId(deviceId);
         DeviceType deviceType = deviceTypeService.getOneByDeviceTypeId(deviceInf.getSystemId());
         deviceInf.setLoadStartType(deviceType.getLoadStartType());
@@ -39,7 +67,7 @@
         deviceInf.setLoadRpm(deviceType.getLoadRpm());
         deviceInf.setLoadTorque(deviceType.getLoadTorque());
         deviceInf.setLoadPropulsionShaft(deviceType.getLoadPropulsionShaft());
-        return deviceInfService.update(deviceInf);
+        return deviceInf;
     }
 
 

--
Gitblit v1.9.1