From 6a54b2b44e4ae62b5f2a884c19e8d81bd5391a12 Mon Sep 17 00:00:00 2001
From: jinpengyong <jpy123456>
Date: Thu, 27 May 2021 17:42:38 +0800
Subject: [PATCH] 根据组织,站点获取设备

---
 screen-manage/src/main/java/com/moral/api/controller/DeviceController.java |  229 +++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 191 insertions(+), 38 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 16691cf..8b0f88e 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
@@ -14,16 +14,18 @@
 import java.util.List;
 import java.util.Map;
 
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import javax.servlet.http.HttpServletRequest;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.moral.api.entity.Device;
-import com.moral.api.entity.ManageAccount;
-import com.moral.api.entity.Organization;
-import com.moral.api.entity.User;
-import com.moral.api.pojo.vo.device.DeviceVO;
+
+import com.moral.api.entity.Version;
 import com.moral.api.service.DeviceService;
-import com.moral.api.service.OrganizationService;
+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 = {"������������"})
@@ -35,7 +37,7 @@
     private DeviceService deviceService;
 
     @Autowired
-    private OrganizationService organizationService;
+    private VersionService versionService;
 
     @ApiOperation(value = "������������", notes = "������������")
     @ApiImplicitParams({
@@ -43,8 +45,157 @@
     })
     @RequestMapping(value = "insert", method = RequestMethod.POST)
     public ResultMessage insert(@RequestBody Device device) {
+        String name = device.getName();
+        String mac = device.getMac();
+        Integer monitorPointId = device.getMonitorPointId();
+        Integer versionId = device.getDeviceVersionId();
+        if (name == null || mac == null || monitorPointId == null || versionId == null) {
+            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(),
+                    ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
+        }
+        //������mac���������������
+        QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("mac", device.getMac());
+        if (deviceService.getOne(queryWrapper) != null) {
+            return ResultMessage.fail(ResponseCodeEnum.MAC_IS_EXIST.getCode(), ResponseCodeEnum.MAC_IS_EXIST.getMsg());
+        }
         deviceService.insert(device);
         return ResultMessage.ok();
+    }
+
+    @ApiOperation(value = "������������", notes = "������������")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
+    })
+    @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();
+    }
+
+    @ApiOperation(value = "������������", notes = "������������")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
+    })
+    @RequestMapping(value = "update", method = RequestMethod.POST)
+    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());
+            if (deviceService.getOne(queryWrapper) != 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 = "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.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);
+    }
+
+    @ApiOperation(value = "������������", notes = "������������")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
+    })
+    @RequestMapping(value = "allOrganization", method = RequestMethod.GET)
+    public ResultMessage selectAllOrganization() {
+        List<Map<String, Object>> organizations = deviceService.selectAllOrganization();
+        return ResultMessage.ok(organizations);
+    }
+
+    @ApiOperation(value = "������������", notes = "������������")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
+    })
+    @RequestMapping(value = "allMonitorPoint", method = RequestMethod.GET)
+    public ResultMessage selectAllMonitorPoint() {
+        List<Map<String, Object>> organizations = deviceService.selectAllMonitorPoint();
+        return ResultMessage.ok(organizations);
+    }
+
+    @ApiOperation(value = "���������������������", notes = "���������������������")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
+    })
+    @RequestMapping(value = "monitorPoints", method = RequestMethod.GET)
+    public ResultMessage selectMonitorPoints(Integer orgId) {
+        List<Map<String, Object>> monitorPoints = deviceService.selectMonitorsByOrgId(orgId);
+        return ResultMessage.ok(monitorPoints);
+    }
+
+    @ApiOperation(value = "���������������������", notes = "���������������������")
+    @ApiImplicitParams({
+            @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(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 = "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(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() {
+        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 = "���������������")
@@ -53,44 +204,46 @@
     })
     @RequestMapping(value = "operators", method = RequestMethod.GET)
     public ResultMessage selectOperators() {
-        List<ManageAccount> operators = deviceService.selectAllOperator();
-        return ResultMessage.ok(operators);
+        return ResultMessage.ok(deviceService.selectAllOperators());
     }
 
-    @ApiOperation(value = "������������", notes = "������������")
-    @RequestMapping(value = "versions", method = RequestMethod.GET)
-    public ResultMessage selectVersions() {
-        return null;
-    }
-
-    @ApiOperation(value = "������������", notes = "������������")
+    @ApiOperation(value = "������������", notes = "������������")
     @ApiImplicitParams({
             @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
     })
-    @RequestMapping(value = "organizations", method = RequestMethod.GET)
-    public ResultMessage selectOrganizations() {
-        List<Organization> organizations = deviceService.selectAllOrganization();
-        return ResultMessage.ok(organizations);
+    @RequestMapping(value = "professions", method = RequestMethod.GET)
+    public ResultMessage selectProfessions() {
+        List<Map<String, Object>> professions = deviceService.selectDeviceDictData(Constants.SYSTEM_DICT_TYPE_PROFESSION);
+        return ResultMessage.ok(professions);
     }
 
-    @ApiOperation(value = "������������������", notes = "������������������")
+    @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 = "order", value = "������������", required = false, paramType = "query", dataType = "String"),
-            @ApiImplicitParam(name = "orderType", value = "������������������������0������������1", defaultValue = "0", required = false, paramType = "query", dataType = "String"),
-            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
-            @ApiImplicitParam(name = "organizationName", value = "������������������", required = false, paramType = "query", dataType = "String"),
-            @ApiImplicitParam(name = "monitorPointName", value = "������������������", required = false, paramType = "query", dataType = "String"),
-            @ApiImplicitParam(name = "deviceName", value = "������������������������", required = false, paramType = "query", dataType = "String"),
-            @ApiImplicitParam(name = "mac", value = "mac������������", required = false, paramType = "query", dataType = "String"),
+            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
     })
-    @RequestMapping(value = "select", method = RequestMethod.POST)
-    public ResultMessage select(@RequestBody Map<String, Object> parameters) {
-        Page<DeviceVO> userPage = deviceService.selectDevices(parameters);
-        PageResult<DeviceVO> pageResult = new PageResult<>(
-                userPage.getTotal(), userPage.getPages(), userPage.getRecords()
-        );
-        return ResultMessage.ok(pageResult);
+    @RequestMapping(value = "techs", method = RequestMethod.GET)
+    public ResultMessage selectTechs() {
+        List<Map<String, Object>> professions = deviceService.selectDeviceDictData(Constants.SYSTEM_DICT_TYPE_TECH);
+        return ResultMessage.ok(professions);
+    }
+
+    @ApiOperation(value = "���������������������", notes = "���������������������")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
+    })
+    @RequestMapping(value = "detectors", method = RequestMethod.GET)
+    public ResultMessage selectDetectors() {
+        List<Map<String, Object>> professions = deviceService.selectDeviceDictData(Constants.SYSTEM_DICT_TYPE_DETECTOR);
+        return ResultMessage.ok(professions);
+    }
+
+    @ApiOperation(value = "���������������", notes = "���������������")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
+    })
+    @RequestMapping(value = "purchasers", method = RequestMethod.GET)
+    public ResultMessage selectPurchasers() {
+        List<Map<String, Object>> professions = deviceService.selectDeviceDictData(Constants.SYSTEM_DICT_TYPE_PURCHASER);
+        return ResultMessage.ok(professions);
     }
 }

--
Gitblit v1.8.0