From bb23575b30f92471f5e92fc65cf1250fdb9d2560 Mon Sep 17 00:00:00 2001
From: zhongrj <646384940@qq.com>
Date: Wed, 28 Feb 2024 11:12:32 +0800
Subject: [PATCH] 地址绑定修改

---
 src/main/java/org/springblade/modules/place/service/impl/PlaceServiceImpl.java |  100 ++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 76 insertions(+), 24 deletions(-)

diff --git a/src/main/java/org/springblade/modules/place/service/impl/PlaceServiceImpl.java b/src/main/java/org/springblade/modules/place/service/impl/PlaceServiceImpl.java
index 910effd..af67476 100644
--- a/src/main/java/org/springblade/modules/place/service/impl/PlaceServiceImpl.java
+++ b/src/main/java/org/springblade/modules/place/service/impl/PlaceServiceImpl.java
@@ -20,6 +20,7 @@
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import liquibase.pro.packaged.W;
 import liquibase.repackaged.org.apache.commons.lang3.StringUtils;
 import org.apache.logging.log4j.util.Strings;
 import org.springblade.common.cache.SysCache;
@@ -27,6 +28,7 @@
 import org.springblade.common.param.CommonParamSet;
 import org.springblade.common.utils.IdUtils;
 import org.springblade.common.utils.SpringUtils;
+import org.springblade.core.log.exception.ServiceException;
 import org.springblade.core.mp.support.Condition;
 import org.springblade.core.secure.utils.AuthUtil;
 import org.springblade.core.tool.utils.SpringUtil;
@@ -46,14 +48,11 @@
 import org.springblade.modules.place.excel.NinePlaceExcel;
 import org.springblade.modules.place.excel.PlaceAndRelExcel;
 import org.springblade.modules.place.excel.PlaceExcel;
-import org.springblade.modules.place.service.IPlaceExtService;
-import org.springblade.modules.place.service.IPlacePoiLabelService;
-import org.springblade.modules.place.service.IPlaceRelService;
+import org.springblade.modules.place.service.*;
 import org.springblade.modules.place.vo.PlaceCheckVO;
 import org.springblade.modules.place.vo.PlacePoiLabelVO;
 import org.springblade.modules.place.vo.PlaceVO;
 import org.springblade.modules.place.mapper.PlaceMapper;
-import org.springblade.modules.place.service.IPlaceService;
 import org.springblade.modules.police.entity.PoliceAffairsGridEntity;
 import org.springblade.modules.police.service.IPoliceAffairsGridService;
 import org.springblade.modules.system.entity.Dept;
@@ -90,6 +89,9 @@
 
 	@Autowired
 	private IPlaceRelService placeRelService;
+
+	@Autowired
+	private IPlaceDoorService placeDoorService;
 
 	@Autowired
 	private IDoorplateAddressService doorplateAddressService;
@@ -174,6 +176,8 @@
 			bindUserHandle(placeVO);
 			// 设置完善状态
 			setPlaceStatus(placeVO);
+			// 房屋编号绑定处理
+//			houseCodeBindHandle(placeVO);
 			// 更新场所信息
 			flag = updateById(placeVO);
 		} else {
@@ -203,8 +207,6 @@
 		gridCodeBind(placeVO);
 		// 警务网格绑定
 		jwGridCodeBind(placeVO);
-		// 房屋编号绑定
-//		houseCodeBind(placeVO);
 		// 返回结果
 		return flag;
 	}
@@ -282,18 +284,54 @@
 	}
 
 	/**
-	 * 房屋绑定
+	 * 房屋绑定处理
 	 *
 	 * @param placeVO
 	 */
-	public void houseCodeBind(PlaceVO placeVO) {
-		String houseCode = placeVO.getHouseCode();
-		List<String> list = Arrays.asList(houseCode.split(","));
-		if (list.size() > 1) {
-			// 处理对应的绑定房屋数据
-			List<Long> longs = new ArrayList<>();
-			// 把其他单个的场所数据删除
-			for (String code : list) {
+	public void houseCodeBindHandle(PlaceVO placeVO) {
+		List<String> list = Arrays.asList(placeVO.getHouseCodeBinds().split(","));
+		// 先删除原有的绑定
+		QueryWrapper<PlaceDoorEntity> removeQw = new QueryWrapper<>();
+		removeQw.eq("place_id",placeVO.getId());
+		// 删除
+		placeDoorService.remove(removeQw);
+		// 遍历更新
+		for (String houseCode : list) {
+			// 查询是否已存在关联关系
+			QueryWrapper<PlaceDoorEntity> wrapper = new QueryWrapper<>();
+			wrapper.eq("house_code",houseCode);
+			// 查询
+			List<PlaceDoorEntity> placeDoorEntityList = placeDoorService.list(wrapper);
+			if (placeDoorEntityList.size()>0){
+				// 该houseCode 已被绑定
+//				errorList.add(houseCode);
+				for (PlaceDoorEntity placeDoorEntity : placeDoorEntityList) {
+					placeDoorEntity.setPlaceId(placeVO.getId());
+					// 更新
+					placeDoorService.updateById(placeDoorEntity);
+				}
+			}else {
+				PlaceDoorEntity placeDoorEntity = new PlaceDoorEntity();
+				placeDoorEntity.setHouseCode(houseCode);
+				placeDoorEntity.setPlaceId(placeVO.getId());
+				// 对应插入到关联关系表中
+				placeDoorService.save(placeDoorEntity);
+			}
+		}
+		// 处理原场所表houseCode 绑定数据
+		handlePlaceOne(list,placeVO);
+	}
+
+	/**
+	 * 处理对应的绑定房屋数据
+	 * @param list
+	 */
+	public void handlePlaceOne(List<String> list,PlaceVO place) {
+		// 处理对应的绑定房屋数据
+		List<Long> longs = new ArrayList<>();
+		// 把其他单个的场所数据删除
+		for (String code : list) {
+			if (!code.equals(place.getHouseCode())) {
 				// 先查询对应的场所id
 				QueryWrapper<PlaceEntity> wrapper = new QueryWrapper<>();
 				wrapper.eq("house_code", code).eq("is_deleted", 0);
@@ -304,15 +342,14 @@
 					removeById(one.getId());
 				}
 			}
-			if (longs.size() > 0) {
-				// 删除对应的详情
-				removePlaceExt(longs);
-				// 删除对应的标签绑定信息
-				removePlaceLabel(longs);
-			}
-		} else {
-			// 一对一,暂时不处理,后续考虑需加绑定关系表
-
+		}
+		if (longs.size() > 0) {
+			// 删除对应的详情
+			removePlaceExt(longs);
+			// 删除对应的标签绑定信息
+			removePlaceLabel(longs);
+			// 删除对应的场所门牌绑定关系信息
+			removePlaceDoor(longs);
 		}
 	}
 
@@ -1131,6 +1168,8 @@
 		removePlaceExt(longs);
 		// 删除对应的标签绑定信息
 		removePlaceLabel(longs);
+		// 删除对应的门牌绑定信息
+		removePlaceDoor(longs);
 		// 返回
 		return removeByIds;
 	}
@@ -1211,6 +1250,19 @@
 	}
 
 	/**
+	 * 删除对应的门牌绑定信息
+	 *
+	 * @param longs
+	 */
+	public void removePlaceDoor(List<Long> longs) {
+		for (Long id : longs) {
+			QueryWrapper<PlaceDoorEntity> wrapper = new QueryWrapper<>();
+			wrapper.eq("place_id", id);
+			placeDoorService.remove(wrapper);
+		}
+	}
+
+	/**
 	 * 九小场所档案
 	 *
 	 * @param page

--
Gitblit v1.9.3