From db2b30bbe239427a89521cd858b2b191d56086ef Mon Sep 17 00:00:00 2001
From: jinpengyong <jpy123456>
Date: Tue, 14 Sep 2021 09:41:06 +0800
Subject: [PATCH] 获取有走航车数据日期,device修改,绑定国控站

---
 screen-manage/src/main/java/com/moral/api/service/impl/SpecialDeviceServiceImpl.java |  206 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 206 insertions(+), 0 deletions(-)

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 2a00d2a..c25c945 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
@@ -2,6 +2,7 @@
 
 import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.moral.api.entity.*;
@@ -24,6 +25,9 @@
 import org.springframework.web.context.request.ServletRequestAttributes;
 
 import javax.servlet.http.HttpServletRequest;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
 import java.text.SimpleDateFormat;
 import java.util.*;
 
@@ -64,6 +68,9 @@
 
     @Autowired(required = false)
     private VersionSensorUnitMapper versionSensorUnitMapper;
+
+    @Autowired(required = false)
+    private GovMonitorPointMapper govMonitorPointMapper;
 
     @Autowired
     private LogUtils logUtils;
@@ -121,6 +128,20 @@
             String updateTime = SDF.format(specialDevice.getUpdateTime());
             specialDeviceMap.put("createTime",createTime);
             specialDeviceMap.put("updateTime",updateTime);
+            Map<String,Object> govMonitorPointMap = new HashMap<>();
+            if (!ObjectUtils.isEmpty(specialDevice.getGuid()) && specialDevice.getGuid()!=null && !"".equals(specialDevice.getGuid())){
+                String  guid = specialDevice.getGuid().toString();
+                QueryWrapper<GovMonitorPoint> wapper_govMonitorPoint = new QueryWrapper<>();
+                wapper_govMonitorPoint.eq("is_delete",Constants.NOT_DELETE);
+                wapper_govMonitorPoint.eq("guid",guid);
+                GovMonitorPoint govMonitorPoint = govMonitorPointMapper.selectOne(wapper_govMonitorPoint);
+                if (!ObjectUtils.isEmpty(govMonitorPoint)){
+                    govMonitorPointMap.put("id",govMonitorPoint.getId());
+                    govMonitorPointMap.put("guid",govMonitorPoint.getGuid());
+                    govMonitorPointMap.put("name",govMonitorPoint.getName());
+                }
+            }
+            specialDeviceMap.put("govMonitorPoint",govMonitorPointMap);
             List<Map<String,Object>> operateList = new ArrayList<>();
             if (!ObjectUtils.isEmpty(specialDevice.getOperateIds()) && specialDevice.getOperateIds()!=null){
                 String operateIds = specialDevice.getOperateIds();
@@ -133,6 +154,7 @@
                     QueryWrapper<ManageAccount> wapper_manageAccount = new QueryWrapper<>();
                     wapper_manageAccount.eq("is_delete",Constants.NOT_DELETE);
                     wapper_manageAccount.in("id",operateIdList);
+                    wapper_manageAccount.select("id", "user_name");
                     List<ManageAccount> manageAccounts = manageAccountMapper.selectList(wapper_manageAccount);
                     for (ManageAccount manageAccount:manageAccounts) {
                         Map<String,Object> operateMap = new HashMap<>();
@@ -258,12 +280,46 @@
         BeanUtils.copyProperties(specialDevice,insertSpecialDeviceHistory);
         if (ObjectUtils.isEmpty(specialDeviceHistory)){
             specialDeviceHistoryMapper.insert(insertSpecialDeviceHistory);
+            //������������������
+            HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
+            StringBuilder content = new StringBuilder();
+            content.append("������������������������������������").append(insertSpecialDeviceHistory.getName()).append(":").append("mac���").append(insertSpecialDeviceHistory.getMac());
+            logUtils.saveOperationForManage(request, content.toString(), Constants.INSERT_OPERATE_TYPE);
         }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);
+            //������������������
+            HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
+            StringBuilder content = new StringBuilder();
+            content.append("������������������������").append(specialDeviceHistory.getId()).append("���");
+            Field[] fields = SpecialDevice.class.getDeclaredFields();
+            for (Field field : fields) {
+                if (field.getName().equals("id")) {
+                    continue;
+                }
+                if ("serialVersionUID".equals(field.getName())) {
+                    continue;
+                }
+                String fieldName = field.getName();
+                PropertyDescriptor pd = null;
+                try {
+                    pd = new PropertyDescriptor(fieldName, SpecialDeviceHistory.class);
+                    Method method = pd.getReadMethod();
+                    Object o1 = method.invoke(specialDeviceHistory);
+                    Object o2 = method.invoke(insertSpecialDeviceHistory);
+                    if (o2 != null) {
+                        content.append(fieldName).append("���").append(o1).append("-->").append(o2).append(":");
+                    }
+
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+
+            }
+            logUtils.saveOperationForManage(request, content.toString(), Constants.UPDATE_OPERATE_TYPE);
         }
         Map<String, Object> deviceInfo = selectDeviceInfoById(specialDevice.getId());
         //���������������������������
@@ -286,6 +342,136 @@
         return resultMap;
     }
 
+    @Transactional
+    @Override
+    public void update(SpecialDevice specialDevice) {
+        Integer specialDeviceId = specialDevice.getId();
+        SpecialDevice oldSpecialDevice = specialDeviceMapper.selectById(specialDeviceId);
+        specialDeviceMapper.updateById(specialDevice);
+        SpecialDevice updateSpecialDevice = specialDeviceMapper.selectById(specialDeviceId);
+        String oleMac = oldSpecialDevice.getMac();
+        //���������������������������
+        Integer oldOrgId = oldSpecialDevice.getOrganizationId();
+        Integer newOrgId = updateSpecialDevice.getOrganizationId();
+        Integer oldVersionId = oldSpecialDevice.getDeviceVersionId();
+        Integer newVersionId = updateSpecialDevice.getDeviceVersionId();
+        if (!oldOrgId.equals(newOrgId) || !oldVersionId.equals(newVersionId)) {
+            deleteOrganizationUnitAlarm(oldOrgId, oldVersionId);
+            insertOrganizationUnitAlarm(newOrgId, newVersionId);
+        }
+        //���redis���������������������
+        delDeviceInfoFromRedis(oleMac);
+        Map<String, Object> deviceInfo = selectDeviceInfoById(specialDeviceId);
+        //������������������redis
+        setDeviceInfoToRedis(updateSpecialDevice.getMac(), deviceInfo);
+        //������deviceInfo������
+        CacheUtils.refreshSpecialDeviceAlarmInfo();
+        QueryWrapper<SpecialDeviceHistory> wrapper_specialDeviceHistory = new QueryWrapper<>();
+        wrapper_specialDeviceHistory.eq("is_delete",Constants.NOT_DELETE);
+        wrapper_specialDeviceHistory.eq("mac",updateSpecialDevice.getMac());
+        wrapper_specialDeviceHistory.eq("organization_id",updateSpecialDevice.getOrganizationId());
+        SpecialDeviceHistory specialDeviceHistory = specialDeviceHistoryMapper.selectOne(wrapper_specialDeviceHistory);
+        SpecialDeviceHistory updateSpecialDeviceHistory = new SpecialDeviceHistory();
+        BeanUtils.copyProperties(updateSpecialDevice,updateSpecialDeviceHistory);
+        updateSpecialDeviceHistory.setCreateTime(null);
+        updateSpecialDeviceHistory.setUpdateTime(null);
+        updateSpecialDeviceHistory.setIsDelete(null);
+        if (ObjectUtils.isEmpty(specialDeviceHistory)){
+            specialDeviceHistoryMapper.insert(updateSpecialDeviceHistory);
+            //������������������
+            HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
+            StringBuilder content = new StringBuilder();
+            content.append("������������������������������������").append(updateSpecialDeviceHistory.getName()).append(":").append("mac���").append(updateSpecialDeviceHistory.getMac());
+            logUtils.saveOperationForManage(request, content.toString(), Constants.INSERT_OPERATE_TYPE);
+        }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(updateSpecialDeviceHistory,wrapper_specialDeviceHistory);
+            //������������������
+            HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
+            StringBuilder content = new StringBuilder();
+            content.append("������������������������").append(specialDeviceHistory.getId()).append("���");
+            Field[] fields = SpecialDevice.class.getDeclaredFields();
+            for (Field field : fields) {
+                if (field.getName().equals("id")) {
+                    continue;
+                }
+                if ("serialVersionUID".equals(field.getName())) {
+                    continue;
+                }
+                String fieldName = field.getName();
+                PropertyDescriptor pd = null;
+                try {
+                    pd = new PropertyDescriptor(fieldName, SpecialDeviceHistory.class);
+                    Method method = pd.getReadMethod();
+                    Object o1 = method.invoke(specialDeviceHistory);
+                    Object o2 = method.invoke(updateSpecialDeviceHistory);
+                    if (o2 != null) {
+                        content.append(fieldName).append("���").append(o1).append("-->").append(o2).append(":");
+                    }
+
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+
+            }
+            logUtils.saveOperationForManage(request, content.toString(), Constants.UPDATE_OPERATE_TYPE);
+        }
+        //������������������
+        HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
+        StringBuilder content = new StringBuilder();
+        content.append("������������������������").append(specialDeviceId).append("���");
+        Field[] fields = SpecialDevice.class.getDeclaredFields();
+        for (Field field : fields) {
+            if (field.getName().equals("id")) {
+                continue;
+            }
+            if ("serialVersionUID".equals(field.getName())) {
+                continue;
+            }
+            String fieldName = field.getName();
+            PropertyDescriptor pd = null;
+            try {
+                pd = new PropertyDescriptor(fieldName, SpecialDevice.class);
+                Method method = pd.getReadMethod();
+                Object o1 = method.invoke(oldSpecialDevice);
+                Object o2 = method.invoke(specialDevice);
+                if (o2 != null) {
+                    content.append(fieldName).append("���").append(o1).append("-->").append(o2).append(":");
+                }
+
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+
+        }
+        logUtils.saveOperationForManage(request, content.toString(), Constants.UPDATE_OPERATE_TYPE);
+    }
+
+    @Override
+    public void delete(Integer specialDeviceId) {
+        SpecialDevice specialDevice = specialDeviceMapper.selectById(specialDeviceId);
+        UpdateWrapper<SpecialDevice> updateWrapper = new UpdateWrapper<>();
+        updateWrapper.eq("id",specialDeviceId).set("is_delete",Constants.DELETE);
+        specialDeviceMapper.update(null,updateWrapper);
+        String mac = specialDevice.getMac();
+        //���redis���������������������
+        delDeviceInfoFromRedis(mac);
+        //���������������������������
+        Integer versionId = specialDevice.getDeviceVersionId();
+        Integer orgId = specialDevice.getOrganizationId();
+        deleteOrganizationUnitAlarm(orgId, versionId);
+        //������deviceInfo������
+        CacheUtils.refreshSpecialDeviceAlarmInfo();
+        //������������������
+        HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
+        StringBuilder content = new StringBuilder();
+        content.append("������������������").append(specialDevice.getName()).append(";").append("mac���").append(mac);
+        logUtils.saveOperationForManage(request, content.toString(), Constants.DELETE_OPERATE_TYPE);
+    }
+
     @Override
     public Map<String, Object> selectDeviceInfoById(Integer deviceId) {
         String mac = specialDeviceMapper.selectById(deviceId).getMac();
@@ -302,6 +488,7 @@
         specialDeviceInfo.put("name", specialDevice.getName());
         specialDeviceInfo.put("mac", specialDevice.getMac());
         specialDeviceInfo.put("createTime", DateUtils.dateToDateString(specialDevice.getCreateTime()));
+        specialDeviceInfo.put("guid", specialDevice.getGuid());
 
         //������������
         //specialDeviceInfo.put("extend", device.getExtend());
@@ -342,6 +529,9 @@
         Organization organization = organizationMapper.selectById(specialDevice.getOrganizationId());
         orgInfo.put("id", organization.getId());
         orgInfo.put("name", organization.getName());
+        orgInfo.put("areaCode", organization.getAreaCode());
+        orgInfo.put("cityCode", organization.getCityCode());
+        orgInfo.put("provinceCode", organization.getProvinceCode());
         specialDeviceInfo.put("organization", orgInfo);
 
         setDeviceInfoToRedis(mac, specialDeviceInfo);
@@ -372,4 +562,20 @@
             }
         }
     }
+
+    private void deleteOrganizationUnitAlarm(Integer orgId, Integer versionId) {
+        QueryWrapper<SpecialDevice> queryOrganizationVersionWrapper = new QueryWrapper<>();
+        queryOrganizationVersionWrapper.eq("organization_id", orgId);
+        queryOrganizationVersionWrapper.eq("device_version_id", versionId);
+        queryOrganizationVersionWrapper.eq("is_delete", Constants.NOT_DELETE);
+        List<SpecialDevice> specialDevices = specialDeviceMapper.selectList(queryOrganizationVersionWrapper);
+        if (org.springframework.util.ObjectUtils.isEmpty(specialDevices)) {//������������������������������������������������������
+            UpdateWrapper deleteWrapper = new UpdateWrapper();
+            deleteWrapper.eq("organization_id", orgId);
+            deleteWrapper.eq("version_id", versionId);
+            deleteWrapper.eq("is_delete", Constants.NOT_DELETE);
+            deleteWrapper.set("is_delete", Constants.DELETE);
+            organizationUnitAlarmMapper.update(null, deleteWrapper);
+        }
+    }
 }

--
Gitblit v1.8.0