From 4e48dd4711cab4528fba7f2ee01a6191c08b34aa Mon Sep 17 00:00:00 2001
From: jinpengyong <jpy123456>
Date: Thu, 03 Aug 2023 11:38:10 +0800
Subject: [PATCH] chore:批量修改校准值

---
 screen-manage/src/main/java/com/moral/api/controller/DeviceController.java |  132 ++++++++++++++++++++++++++++++++++---------
 1 files changed, 104 insertions(+), 28 deletions(-)

diff --git a/screen-manage/src/main/java/com/moral/api/controller/DeviceController.java b/screen-manage/src/main/java/com/moral/api/controller/DeviceController.java
index 780deaa..c4e303c 100644
--- a/screen-manage/src/main/java/com/moral/api/controller/DeviceController.java
+++ b/screen-manage/src/main/java/com/moral/api/controller/DeviceController.java
@@ -6,6 +6,7 @@
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.ObjectUtils;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
@@ -14,13 +15,20 @@
 import java.util.List;
 import java.util.Map;
 
-import com.baomidou.mybatisplus.core.metadata.IPage;
+import javax.servlet.http.HttpServletRequest;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.moral.api.entity.Device;
 
+import com.moral.api.entity.SpecialDevice;
+import com.moral.api.entity.Version;
 import com.moral.api.service.DeviceService;
+import com.moral.api.service.SpecialDeviceService;
+import com.moral.api.service.VersionService;
 import com.moral.constant.Constants;
+import com.moral.constant.ResponseCodeEnum;
 import com.moral.constant.ResultMessage;
-import com.moral.util.PageResult;
+import com.moral.util.WebUtils;
 
 @Slf4j
 @Api(tags = {"������������"})
@@ -31,12 +39,36 @@
     @Autowired
     private DeviceService deviceService;
 
+    @Autowired
+    private VersionService versionService;
+
+    @Autowired
+    private SpecialDeviceService specialDeviceService;
+
     @ApiOperation(value = "������������", notes = "������������")
     @ApiImplicitParams({
             @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
     })
     @RequestMapping(value = "insert", method = RequestMethod.POST)
-    public ResultMessage insert(Device device) {
+    public ResultMessage insert(@RequestBody Device device) {
+        String name = device.getName();
+        String mac = device.getMac();
+        Integer monitorPointId = device.getMonitorPointId();
+        Integer versionId = device.getDeviceVersionId();
+        if (ObjectUtils.isEmpty(name) || ObjectUtils.isEmpty(mac) || ObjectUtils.isEmpty(monitorPointId) || ObjectUtils.isEmpty(versionId)) {
+            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(),
+                    ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
+        }
+        //������mac���������������,���������������������������������������������
+        QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("mac", device.getMac()).eq("is_delete", Constants.NOT_DELETE);
+
+        QueryWrapper<SpecialDevice> specialDeviceQueryWrapper = new QueryWrapper<>();
+        specialDeviceQueryWrapper.eq("mac", device.getMac()).eq("is_delete", Constants.NOT_DELETE);
+
+        if (deviceService.getOne(queryWrapper) != null || specialDeviceService.getOne(specialDeviceQueryWrapper) != null) {
+            return ResultMessage.fail(ResponseCodeEnum.MAC_IS_EXIST.getCode(), ResponseCodeEnum.MAC_IS_EXIST.getMsg());
+        }
         deviceService.insert(device);
         return ResultMessage.ok();
     }
@@ -47,6 +79,10 @@
     })
     @RequestMapping(value = "delete", method = RequestMethod.GET)
     public ResultMessage delete(Integer deviceId) {
+        if (deviceId == null) {
+            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(),
+                    ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
+        }
         deviceService.delete(deviceId);
         return ResultMessage.ok();
     }
@@ -56,37 +92,43 @@
             @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
     })
     @RequestMapping(value = "update", method = RequestMethod.POST)
-    public ResultMessage update(Device device) {
+    public ResultMessage update(@RequestBody Device device) {
+        if (device.getId() == null) {
+            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(),
+                    ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
+        }
+        if (device.getMac() != null) {
+            //������mac���������������,���������������������������������������������
+            QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
+            queryWrapper.eq("mac", device.getMac()).eq("is_delete", Constants.NOT_DELETE);
+
+            QueryWrapper<SpecialDevice> specialDeviceQueryWrapper = new QueryWrapper<>();
+            specialDeviceQueryWrapper.eq("mac", device.getMac()).eq("is_delete", Constants.NOT_DELETE);
+            if (deviceService.getOne(queryWrapper) != null || specialDeviceService.getOne(specialDeviceQueryWrapper) != null) {
+                return ResultMessage.fail(ResponseCodeEnum.MAC_IS_EXIST.getCode(), ResponseCodeEnum.MAC_IS_EXIST.getMsg());
+            }
+        }
         deviceService.update(device);
         return ResultMessage.ok();
     }
 
     @ApiOperation(value = "������������������", notes = "������������������")
     @ApiImplicitParams({
-            @ApiImplicitParam(name = "page", value = "���������", required = false, paramType = "query", dataType = "Integer"),
-            @ApiImplicitParam(name = "size", value = "������������", required = false, paramType = "query", dataType = "Integer"),
+            @ApiImplicitParam(name = "page", value = "���������", required = false, paramType = "query", dataType = "int"),
+            @ApiImplicitParam(name = "size", value = "������������", required = false, paramType = "query", dataType = "int"),
             @ApiImplicitParam(name = "order", value = "������������", required = false, paramType = "query", dataType = "String"),
             @ApiImplicitParam(name = "orderType", value = "������������������������0������������1", required = false, paramType = "query", dataType = "String"),
             @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
             @ApiImplicitParam(name = "name", value = "������������������������", required = false, paramType = "query", dataType = "String"),
             @ApiImplicitParam(name = "mac", value = "mac������������", required = false, paramType = "query", dataType = "String"),
-    })
-    @RequestMapping(value = "select", method = RequestMethod.POST)
-    public ResultMessage select(@RequestBody Map<String, Object> parameters) {
-        IPage<Device> page = deviceService.selectDevices(parameters);
-        PageResult<Device> pageResult = new PageResult<>(
-                page.getTotal(), page.getPages(), page.getRecords()
-        );
-        return ResultMessage.ok(pageResult);
-    }
+            @ApiImplicitParam(name = "organizationId", value = "������������������", required = false, paramType = "query", dataType = "String"),
+            @ApiImplicitParam(name = "monitorPointId", value = "������id", required = false, paramType = "query", dataType = "String")
 
-    @ApiOperation(value = "������������������", notes = "������������������")
-    @ApiImplicitParams({
-            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
     })
-    @RequestMapping(value = "deviceInfo", method = RequestMethod.GET)
-    public ResultMessage selectDeviceInfoById(Integer deviceId) {
-        Map<String, Object> result = deviceService.selectDeviceInfoById(deviceId);
+    @RequestMapping(value = "select", method = RequestMethod.GET)
+    public ResultMessage select(HttpServletRequest request) {
+        Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
+        Map<String, Object> result = deviceService.selectDevices(parameters);
         return ResultMessage.ok(result);
     }
 
@@ -122,28 +164,54 @@
 
     @ApiOperation(value = "���������������������", notes = "���������������������")
     @ApiImplicitParams({
-            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
+            @ApiImplicitParam(name = "page", value = "���������", required = false, paramType = "query", dataType = "int"),
+            @ApiImplicitParam(name = "size", value = "������������", required = false, paramType = "query", dataType = "int"),
+            @ApiImplicitParam(name = "order", value = "������������", required = false, paramType = "query", dataType = "String"),
+            @ApiImplicitParam(name = "orderType", value = "������������������������0������������1", required = false, paramType = "query", dataType = "String"),
+            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
+            @ApiImplicitParam(name = "organizationId", value = "������id", required = false, paramType = "query", dataType = "int"),
     })
     @RequestMapping(value = "devicesByOrgId", method = RequestMethod.GET)
-    public ResultMessage selectDevicesByOrg(Integer orgId) {
-        List<Map<String, Object>> devices = deviceService.selectDevicesByOrgId(orgId);
+    public ResultMessage selectDevicesByOrg(HttpServletRequest request) {
+        Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
+        if (parameters.get("organizationId") == null) {
+            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(),
+                    ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
+        }
+        Map<String, Object> devices = deviceService.selectDevicesByOrgId(parameters);
         return ResultMessage.ok(devices);
     }
 
     @ApiOperation(value = "���������������������", notes = "���������������������")
     @ApiImplicitParams({
-            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
+            @ApiImplicitParam(name = "page", value = "���������", required = false, paramType = "query", dataType = "int"),
+            @ApiImplicitParam(name = "size", value = "������������", required = false, paramType = "query", dataType = "int"),
+            @ApiImplicitParam(name = "order", value = "������������", required = false, paramType = "query", dataType = "String"),
+            @ApiImplicitParam(name = "orderType", value = "������������������������0������������1", required = false, paramType = "query", dataType = "String"),
+            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
+            @ApiImplicitParam(name = "monitorPointId", value = "������id", required = false, paramType = "query", dataType = "int"),
     })
     @RequestMapping(value = "devicesByMpId", method = RequestMethod.GET)
-    public ResultMessage selectDevicesByMp(Integer mpId) {
-        List<Map<String, Object>> devices = deviceService.selectDevicesByMpId(mpId);
+    public ResultMessage selectDevicesByMp(HttpServletRequest request) {
+        Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
+        if (parameters.get("monitorPointId") == null) {
+            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(),
+                    ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
+        }
+        Map<String, Object> devices = deviceService.selectDevicesByMpId(parameters);
         return ResultMessage.ok(devices);
     }
 
     @ApiOperation(value = "������������", notes = "������������")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
+    })
     @RequestMapping(value = "versions", method = RequestMethod.GET)
     public ResultMessage selectVersions() {
-        return null;
+        QueryWrapper<Version> queryWrapper = new QueryWrapper<>();
+        queryWrapper.select("id", "name").eq("is_delete", Constants.NOT_DELETE);
+        List<Map<String, Object>> maps = versionService.listMaps(queryWrapper);
+        return ResultMessage.ok(maps);
     }
 
     @ApiOperation(value = "���������������", notes = "���������������")
@@ -194,4 +262,12 @@
         List<Map<String, Object>> professions = deviceService.selectDeviceDictData(Constants.SYSTEM_DICT_TYPE_PURCHASER);
         return ResultMessage.ok(professions);
     }
+
+    @RequestMapping(value = "selectMonitorPiontAndDeviceByOrgId", method = RequestMethod.GET)
+    public ResultMessage selectMonitorPiontAndDeviceByOrgId(HttpServletRequest request){
+        Map parames = WebUtils.getParametersStartingWith(request,null);
+        int id = Integer.parseInt(parames.get("organization_id").toString());
+        List<Map<String, Object>> maps = deviceService.selectMonitorPiontAndDeviceByOrgId(id);
+        return ResultMessage.ok(maps);
+    }
 }

--
Gitblit v1.8.0