From bfce748e37a753c729e15dd233600379f504d019 Mon Sep 17 00:00:00 2001
From: zhanzhiqin <895896009@qq.com>
Date: 星期四, 28 四月 2022 13:59:28 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
ximon-admin/src/main/java/com/sandu/ximon/admin/service/PoleBindingService.java | 99 +++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 94 insertions(+), 5 deletions(-)
diff --git a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/PoleBindingService.java b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/PoleBindingService.java
index 8f810d5..d43f65a 100644
--- a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/PoleBindingService.java
+++ b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/PoleBindingService.java
@@ -1,12 +1,19 @@
package com.sandu.ximon.admin.service;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.sandu.common.execption.BusinessException;
import com.sandu.common.service.impl.BaseServiceImpl;
+import com.sandu.common.util.SpringContextHolder;
import com.sandu.ximon.admin.param.PoleBindingParam;
+import com.sandu.ximon.dao.domain.Pole;
import com.sandu.ximon.dao.domain.PoleBinding;
-import com.sandu.ximon.dao.enums.PoleBindingEnums;
import com.sandu.ximon.dao.mapper.PoleBindingMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
+
+import javax.swing.*;
+import java.util.List;
/**
* @author chenjiantian
@@ -18,17 +25,99 @@
private final LightReportDataService lightReportDataService;
+ /**
+ * 鐏潌缁戝畾璁惧
+ *
+ * @param poleId
+ * @param param
+ * @return
+ */
public boolean bindPole(Long poleId, PoleBindingParam param) {
Integer deviceType = param.getDeviceType();
- if (PoleBindingEnums.LIGHT.getCode().equals(deviceType)) {
+// if (PoleBindingEnums.LIGHT.getCode().equals(deviceType)) {
+// }
+ LambdaQueryWrapper<PoleBinding> eq = Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getPoleId, poleId);
+ List<PoleBinding> list = list(eq);
+ if (list.size() != 0) {
+ for (PoleBinding poleBinding : list) {
+ //鍏呯數妗╃殑缁戝畾鏄綉缁滆姹傛槸甯﹁繃鏉ョ殑鐏潌淇℃伅锛岃鍏佽鐩存帴淇敼
+ if (poleBinding.getDeviceType().equals(deviceType) && deviceType != 2) {
+ throw new BusinessException("璇ョ伅鏉嗗凡缁戝畾杩囩浉鍚岀被鍨嬭澶�");
+ }
+ }
+ }
+
+ PoleBinding one = getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, param.getDeviceCode()));
+ if (one == null) {
PoleBinding poleBinding = new PoleBinding();
poleBinding.setPoleId(poleId);
poleBinding.setDeviceType(deviceType);
poleBinding.setDeviceName(param.getDeviceName());
- poleBinding.setDeviceMac(param.getDeviceMac());
+ poleBinding.setDeviceCode(param.getDeviceCode());
return save(poleBinding);
- }
+ } else {
+ //淇敼鍗曠伅鐨勭粦瀹氬叧绯荤殑鏃跺�欒棰濆澶勭悊鐨勪簨鍔�
+ // 鍒犻櫎鐏潌鐨刣evicescode
+ if(param.getDeviceType() == 0){
+ PoleService poleService = SpringContextHolder.getBean(PoleService.class);
+ Pole pole = poleService.getOne(Wrappers.lambdaQuery(Pole.class).eq(Pole::getId, one.getPoleId()));
+ if (pole != null) {
+ pole.setDeviceCode(null);
+ poleService.updateById(pole);
+ }
+ }
- return false;
+ one.setPoleId(poleId);
+ one.setDeviceType(param.getDeviceType());
+ one.setDeviceName(param.getDeviceName());
+ one.setDeviceCode(param.getDeviceCode());
+ return updateById(one);
+ }
+ }
+
+ /**
+ * 鐏潌瑙g粦璁惧锛屽垹闄よ澶囧墠闇�瑕佽В缁�
+ *
+ * @param deviceCode
+ */
+ public boolean unBindPole(Long poleId, String deviceCode) {
+ if (deviceCode == null) {
+ throw new BusinessException("璁惧缂栧彿涓嶈兘涓虹┖");
+ }
+ PoleBinding one;
+ //鐩存帴鍒犻櫎璁惧涓嶉渶瑕佺伅鏉咺D
+ if (poleId == null) {
+ one = getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, deviceCode));
+ } else {
+ one = getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, deviceCode).eq(PoleBinding::getPoleId, poleId));
+ }
+ if (one != null) {
+ return removeById(one.getId());
+ } else {
+ throw new BusinessException("璁惧涓嶅瓨鍦ㄧ粦瀹氭儏鍐垫垨鐏潌ID涓嶆纭�");
+ }
+ }
+
+ /**
+ * 璁惧鍒犻櫎,鐩存帴瑙g粦璁惧鐩稿叧缁戝畾鏁版嵁
+ *
+ * @param deviceCode
+ */
+ public boolean unBindPole(String deviceCode) {
+ if (deviceCode == null) {
+ throw new BusinessException("璁惧缂栧彿涓嶈兘涓虹┖");
+ }
+ //鐩存帴鍒犻櫎璁惧涓嶉渶瑕佺伅鏉咺D
+ PoleBinding one = getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, deviceCode));
+
+ if (one != null) {
+ return removeById(one.getId());
+ } else {
+ return false;
+ }
+ }
+
+ public PoleBinding getPoleIdByMac(String deviceCode) {
+ return getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, deviceCode));
}
}
--
Gitblit v1.9.3