From dda268997ca8f8a364f7c19b45d7a43a50a98efe Mon Sep 17 00:00:00 2001
From: liuhaonan <31457034@qq.com>
Date: 星期二, 25 十月 2022 18:00:11 +0800
Subject: [PATCH] changes

---
 ximon-admin/src/main/java/com/sandu/ximon/admin/service/InterphoneHostService.java |  116 ++++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 100 insertions(+), 16 deletions(-)

diff --git a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/InterphoneHostService.java b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/InterphoneHostService.java
index e81e7f7..b0fc52b 100644
--- a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/InterphoneHostService.java
+++ b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/InterphoneHostService.java
@@ -1,68 +1,146 @@
 package com.sandu.ximon.admin.service;
 
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.github.pagehelper.PageHelper;
+import com.sandu.common.execption.BusinessException;
+import com.sandu.common.object.BaseConditionVO;
 import com.sandu.common.service.impl.BaseServiceImpl;
+import com.sandu.common.util.SpringContextHolder;
 import com.sandu.ximon.admin.param.InterphoneHostParam;
+import com.sandu.ximon.admin.security.SecurityUtils;
+import com.sandu.ximon.admin.utils.StoreOperationRecordsUtils;
+import com.sandu.ximon.dao.bo.InterphoneHostBo;
 import com.sandu.ximon.dao.domain.InterphoneHost;
+import com.sandu.ximon.dao.domain.InterphoneHostSubPole;
+import com.sandu.ximon.dao.enums.PoleBindingEnums;
 import com.sandu.ximon.dao.mapper.InterphoneHostMapper;
 import lombok.AllArgsConstructor;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
+import java.util.ArrayList;
 import java.util.List;
 
 @Service
 @AllArgsConstructor
-public class InterphoneHostService extends BaseServiceImpl <InterphoneHostMapper, InterphoneHost>{
+public class InterphoneHostService extends BaseServiceImpl<InterphoneHostMapper, InterphoneHost> {
 
     private final InterphoneHostMapper interphoneHostMapper;
+
+    private final InterphoneHostSubService interphoneHostSubService;
 
 
     /**
      * 娣诲姞涓绘満
-     *
      */
     public boolean addHost(InterphoneHostParam interphoneHostParam) {
+        List<InterphoneHost> list = list(Wrappers.lambdaQuery(InterphoneHost.class).eq(InterphoneHost::getHostMac, interphoneHostParam.getHostMac()));
+        if (list.size() > 0) {
+            throw new BusinessException("璇ヨ澶囧凡瀛樺湪");
+        }
         InterphoneHost interphoneHost = new InterphoneHost();
         BeanUtils.copyProperties(interphoneHostParam, interphoneHost);
-       return save(interphoneHost);
+        boolean save = save(interphoneHost);
+        /**
+         * 娣诲姞涓�閿眰鍔╀富鏈� 鏃ュ織璁板綍寮�濮�
+         */
+        List<String> listCode = new ArrayList<>(1);
+        listCode.add(interphoneHost.getHostMac());
+        String content = "{ 璁惧id:" + interphoneHost.getHostId() + "璁惧code锛�" + interphoneHost.getHostMac() +
+                "}";
+
+        StoreOperationRecordsUtils.storeOperationData(listCode, null, "娣诲姞涓�閿眰鍔╀富鏈�", content);
+        /**
+         * 娣诲姞涓�閿眰鍔╀富鏈� 鏃ュ織璁板綍缁撴潫
+         */
+
+        return save;
     }
 
     /**
      * 淇敼涓绘満
      */
-    public boolean updateHost(Integer id,InterphoneHostParam interphoneHostParam) {
+    @Transactional(rollbackFor = Exception.class)
+    public boolean updateHost(Integer id, InterphoneHostParam interphoneHostParam) {
         InterphoneHost byId = getById(id);
-        if(byId == null){
+        if (byId == null) {
             return false;
+        }
+
+        if (SecurityUtils.getClientId() != null) {
+            boolean belong = SpringContextHolder.getBean(PoleBindingService.class).isBelong(byId.getHostMac(), PoleBindingEnums.FOR_HELP);
+            if (!belong) {
+                throw new BusinessException("璇ヨ澶囦笉灞炰簬鎮�,涓嶈兘淇敼璁惧淇℃伅");
+            }
         }
         InterphoneHost interphoneHost = new InterphoneHost();
         interphoneHost.setHostId(id);
         BeanUtils.copyProperties(interphoneHostParam, interphoneHost);
-        return updateById(interphoneHost);
+
+        /**
+         * 缂栬緫涓�閿眰鍔╀富鏈� 鏃ュ織璁板綍寮�濮�
+         */
+        List<String> listCode = new ArrayList<>(1);
+        listCode.add(interphoneHost.getHostMac());
+        String content = "{ 璁惧id:" + interphoneHost.getHostId() + "璁惧code锛�" + interphoneHost.getHostMac() +
+                "}";
+
+        StoreOperationRecordsUtils.storeOperationData(listCode, null, "缂栬緫涓�閿眰鍔╀富鏈�", content);
+        /**
+         * 缂栬緫涓�閿眰鍔╀富鏈� 鏃ュ織璁板綍缁撴潫
+         */
+        boolean b = updateById(interphoneHost);
+        List<InterphoneHost> list = list(Wrappers.lambdaQuery(InterphoneHost.class).eq(InterphoneHost::getHostMac, interphoneHostParam.getHostMac()));
+        if (list.size() > 1) {
+            throw new BusinessException("璇锋鏌ヨ澶噈ac鏄惁閲嶅");
+        }
+        return b;
     }
 
     /**
      * 鍒犻櫎涓绘満
+     *
      * @param id
      * @return
-     *
-      */
+     */
     public boolean deleteHost(Integer id) {
         InterphoneHost byId = getById(id);
-        if(byId == null){
-            return false;
+
+        if (byId == null) {
+            throw new BusinessException("涓绘満涓嶅瓨鍦紒");
         }
+
+        InterphoneHostSubPole one = interphoneHostSubService.getOne(Wrappers.lambdaQuery(InterphoneHostSubPole.class).eq(InterphoneHostSubPole::getHostId, id));
+        if (one != null) {
+            throw new BusinessException("璇ヤ富鏈哄瓨鍦ㄧ粦瀹氬叧绯伙紝涓嶈兘鍒犻櫎");
+        }
+
+        /**
+         * 鍒犻櫎涓�閿眰鍔╀富鏈� 鏃ュ織璁板綍寮�濮�
+         */
+        List<String> listCode = new ArrayList<>(1);
+        listCode.add(byId.getHostMac());
+        String content = "{ 璁惧id:" + byId.getHostId() + "璁惧code锛�" + byId.getHostMac() +
+                "}";
+
+        StoreOperationRecordsUtils.storeOperationData(listCode, null, "鍒犻櫎涓�閿眰鍔╀富鏈�", content);
+        /**
+         * 鍒犻櫎涓�閿眰鍔╀富鏈� 鏃ュ織璁板綍缁撴潫
+         */
+
         return removeById(id);
     }
 
     /**
      * 鏌ヨ涓绘満
+     *
      * @param id
      * @return
      */
     public InterphoneHost getHost(Integer id) {
         InterphoneHost byId = getById(id);
-        if(byId == null){
+        if (byId == null) {
             return null;
         }
         return byId;
@@ -71,10 +149,16 @@
     /**
      * 鏌ヨ涓绘満鍒楄〃
      */
-    public List<InterphoneHost> getHostList() {
-        List<InterphoneHost> list = list();//TODO
-        return list();
+    public List<InterphoneHostBo> getInterphoneHostList(BaseConditionVO baseConditionVO, String keyword) {
+        if (baseConditionVO != null) {
+            PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize());
+        }
+        List<InterphoneHostBo> list;
+        if (SecurityUtils.getClientId() == null) {
+            list = interphoneHostMapper.getInterphoneHostList(keyword, null);
+        } else {
+            list = interphoneHostMapper.getInterphoneHostList(keyword, SecurityUtils.getUserId());
+        }
+        return list;
     }
-
-
 }

--
Gitblit v1.9.3