From 1fc8c9de17129666afd99d591a694c04aacade10 Mon Sep 17 00:00:00 2001
From: lizijie <lzjiiie@163.com>
Date: Fri, 13 Aug 2021 17:47:25 +0800
Subject: [PATCH] 特殊因子新建接口

---
 screen-manage/src/main/java/com/moral/api/service/SpecialDeviceService.java          |    4 ++
 screen-manage/src/main/java/com/moral/api/service/impl/SpecialDeviceServiceImpl.java |   89 ++++++++++++++++++++++++++++++++++++++++++--
 screen-manage/src/main/java/com/moral/api/controller/SpecialDeviceController.java    |   14 +++++--
 3 files changed, 98 insertions(+), 9 deletions(-)

diff --git a/screen-manage/src/main/java/com/moral/api/controller/SpecialDeviceController.java b/screen-manage/src/main/java/com/moral/api/controller/SpecialDeviceController.java
index d8dad90..c1e2361 100644
--- a/screen-manage/src/main/java/com/moral/api/controller/SpecialDeviceController.java
+++ b/screen-manage/src/main/java/com/moral/api/controller/SpecialDeviceController.java
@@ -1,14 +1,12 @@
 package com.moral.api.controller;
 
+import com.moral.api.entity.SpecialDevice;
 import com.moral.api.service.SpecialDeviceService;
 import com.moral.constant.ResultMessage;
 import com.moral.util.WebUtils;
 import io.swagger.annotations.Api;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.ResponseBody;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
@@ -33,4 +31,12 @@
         }
         return ResultMessage.fail(Integer.parseInt(resultMap.get("code").toString()),resultMap.get("msg").toString());
     }
+
+    @RequestMapping(value = "insert", method = RequestMethod.POST)
+    @ResponseBody
+    public ResultMessage insert(@RequestBody SpecialDevice specialDevice){
+        System.out.println(specialDevice);
+        specialDeviceService.insert(specialDevice);
+        return null;
+    }
 }
diff --git a/screen-manage/src/main/java/com/moral/api/service/SpecialDeviceService.java b/screen-manage/src/main/java/com/moral/api/service/SpecialDeviceService.java
index f52d7c9..43a6968 100644
--- a/screen-manage/src/main/java/com/moral/api/service/SpecialDeviceService.java
+++ b/screen-manage/src/main/java/com/moral/api/service/SpecialDeviceService.java
@@ -2,6 +2,7 @@
 
 import com.moral.api.entity.SpecialDevice;
 import com.baomidou.mybatisplus.extension.service.IService;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.List;
 import java.util.Map;
@@ -17,4 +18,7 @@
 public interface SpecialDeviceService extends IService<SpecialDevice> {
 
     Map<String,Object> getDataByCondition(Map map);
+
+    @Transactional
+    Map<String,Object> insert(SpecialDevice specialDevice);
 }
diff --git a/screen-manage/src/main/java/com/moral/api/service/impl/SpecialDeviceServiceImpl.java b/screen-manage/src/main/java/com/moral/api/service/impl/SpecialDeviceServiceImpl.java
index 5038125..d08d880 100644
--- a/screen-manage/src/main/java/com/moral/api/service/impl/SpecialDeviceServiceImpl.java
+++ b/screen-manage/src/main/java/com/moral/api/service/impl/SpecialDeviceServiceImpl.java
@@ -9,9 +9,13 @@
 import com.moral.api.service.SpecialDeviceService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.moral.constant.Constants;
+import com.moral.constant.RedisConstants;
 import com.moral.constant.ResponseCodeEnum;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
@@ -48,6 +52,30 @@
     @Autowired(required = false)
     private OrganizationMapper organizationMapper;
 
+    @Autowired(required = false)
+    private RedisTemplate redisTemplate;
+
+    /*
+     * ���redis������������������
+     * */
+    private Map<String, Object> getDeviceInfoFromRedis(String mac) {
+        return (Map<String, Object>) redisTemplate.opsForHash().get(RedisConstants.DEVICE, mac);
+    }
+
+    /*
+     * ������������������redis
+     */
+    private void setDeviceInfoToRedis(String mac, Map<String, Object> deviceInfo) {
+        redisTemplate.opsForHash().put(RedisConstants.DEVICE, mac, deviceInfo);
+    }
+
+    /*
+     * ���redis������������������
+     */
+    private void delDeviceInfoFromRedis(String mac) {
+        redisTemplate.opsForHash().delete(RedisConstants.DEVICE, mac);
+    }
+
     @Override
     public Map<String, Object> getDataByCondition(Map map) {
         Map<String,Object> resultMap = new HashMap<>();
@@ -62,13 +90,15 @@
         QueryWrapper<SpecialDevice> wrapper_Condition = new QueryWrapper<>();
         wrapper_Condition.eq("is_delete",Constants.NOT_DELETE);
         if (!ObjectUtils.isEmpty(map.get("organization_id"))){
-            wrapper_Condition.like("organization_id",map.get("organization_id").toString());
+            wrapper_Condition.eq("organization_id",map.get("organization_id").toString());
         }
         if (!ObjectUtils.isEmpty(map.get("keyword"))){
-            wrapper_Condition.like("name",map.get("keyword").toString()).or().like("mac",map.get("keyword").toString());
+            wrapper_Condition.and(wc -> wc.like("name",map.get("keyword").toString()).or().like("mac",map.get("keyword").toString()));
+            //wrapper_Condition.like("name",map.get("keyword").toString()).or().like("mac",map.get("keyword").toString());
         }
         wrapper_Condition.orderByDesc("create_time");
         Page resultPage = specialDeviceMapper.selectPage(page,wrapper_Condition);
+        int totalNumber = specialDeviceMapper.selectCount(wrapper_Condition);
         List<SpecialDevice> specialDevices = resultPage.getRecords();
         SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         List<Map<String,Object>> specialDeviceList = new ArrayList<>();
@@ -112,7 +142,7 @@
                     deviceVersionMap.put("name",version.getName());
                 }
             }
-            specialDeviceMap.put("deviceVersion",deviceVersionMap);
+            specialDeviceMap.put("version",deviceVersionMap);
             Map<String,Object> specialTypeMap = new HashMap<>();
             if (!ObjectUtils.isEmpty(specialDevice.getSpecialType()) && specialDevice.getSpecialType()!=null && !"".equals(specialDevice.getSpecialType())){
                 int specialTypeId = Integer.parseInt(specialDevice.getSpecialType().toString());
@@ -123,6 +153,7 @@
                 SysDictData sysDictData = sysDictDataMapper.selectOne(wapper_sysDictData);
                 if (!ObjectUtils.isEmpty(sysDictData)){
                     specialTypeMap.put("id",sysDictData.getId());
+                    specialTypeMap.put("dataKey",sysDictData.getDataKey());
                     specialTypeMap.put("name",sysDictData.getDataValue());
                 }
             }
@@ -139,7 +170,7 @@
                     organizationMap.put("name",organization.getName());
                 }
             }
-            specialDeviceMap.put("organazation",organizationMap);
+            specialDeviceMap.put("organization",organizationMap);
             List<Map<String,Object>> organizationList = new ArrayList<>();
             QueryWrapper<SpecialDeviceHistory> wapper_specialDeviceHistory = new QueryWrapper<>();
             wapper_specialDeviceHistory.eq("is_delete",Constants.NOT_DELETE);
@@ -165,7 +196,6 @@
             specialDeviceList.add(specialDeviceMap);
         }
         resultMap.put("specialDevices",specialDeviceList);
-        int totalNumber = specialDevices.size();
         resultMap.put("totalNumber",totalNumber);
         resultMap.put("current",current);
         int totalPageNumber = totalNumber/size;
@@ -175,4 +205,53 @@
         resultMap.put("totalPageNumber",totalPageNumber);
         return resultMap;
     }
+
+    @Transactional
+    @Override
+    public Map<String, Object> insert(SpecialDevice specialDevice) {
+        Map<String,Object> resultMap = new HashMap<>();
+        String name = specialDevice.getName();
+        String mac = specialDevice.getMac();
+        int organizationId = specialDevice.getOrganizationId();
+        int deviceVersionId = specialDevice.getDeviceVersionId();
+        String operateIds = specialDevice.getOperateIds();
+        String specialType = specialDevice.getSpecialType();
+        if (ObjectUtils.isEmpty(name) || ObjectUtils.isEmpty(mac) || ObjectUtils.isEmpty(specialType) || ObjectUtils.isEmpty(organizationId) || ObjectUtils.isEmpty(deviceVersionId)){
+            resultMap.put("code",ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode());
+            resultMap.put("msg",ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
+            return resultMap;
+        }
+        if (name.equals("") || mac.equals("") || specialType.equals("")){
+            resultMap.put("code",ResponseCodeEnum.PARAMETERS_NOT_REQUIREMENT.getCode());
+            resultMap.put("msg",ResponseCodeEnum.PARAMETERS_NOT_REQUIREMENT.getMsg());
+            return resultMap;
+        }
+        QueryWrapper<SpecialDevice> wrapper_mac = new QueryWrapper<>();
+        wrapper_mac.eq("is_delete",Constants.NOT_DELETE);
+        wrapper_mac.eq("mac",mac);
+        int macNum = specialDeviceMapper.selectCount(wrapper_mac);
+        if (macNum>0){
+            resultMap.put("code",ResponseCodeEnum.MAC_IS_EXIST.getCode());
+            resultMap.put("msg",ResponseCodeEnum.MAC_IS_EXIST.getMsg());
+            return resultMap;
+        }
+        specialDeviceMapper.insert(specialDevice);
+        QueryWrapper<SpecialDeviceHistory> wrapper_specialDeviceHistory = new QueryWrapper<>();
+        wrapper_specialDeviceHistory.eq("is_delete",Constants.NOT_DELETE);
+        wrapper_specialDeviceHistory.eq("mac",mac);
+        wrapper_specialDeviceHistory.eq("organization_id",organizationId);
+        SpecialDeviceHistory specialDeviceHistory = specialDeviceHistoryMapper.selectOne(wrapper_specialDeviceHistory);
+        SpecialDeviceHistory insertSpecialDeviceHistory = new SpecialDeviceHistory();
+        BeanUtils.copyProperties(specialDevice,insertSpecialDeviceHistory);
+        if (ObjectUtils.isEmpty(specialDeviceHistory)){
+            specialDeviceHistoryMapper.insert(insertSpecialDeviceHistory);
+        }else {
+            /*UpdateWrapper<SpecialDeviceHistory> wrapper_insertSpecialDeviceHistory = new UpdateWrapper<>();
+            wrapper_specialDeviceHistory.eq("is_delete",Constants.NOT_DELETE);
+            wrapper_specialDeviceHistory.eq("mac",mac);
+            wrapper_specialDeviceHistory.eq("organization_id",organizationId);*/
+            specialDeviceHistoryMapper.update(insertSpecialDeviceHistory,wrapper_specialDeviceHistory);
+        }
+        return null;
+    }
 }

--
Gitblit v1.8.0