From 2b1a74f4faa5a00a294bdc6a6d956c2e009cf467 Mon Sep 17 00:00:00 2001
From: lin <sbla5888@163.com>
Date: Tue, 16 Apr 2024 15:32:09 +0800
Subject: [PATCH] 管理员过滤文章

---
 src/main/java/org/springblade/modules/place/service/impl/PlaceServiceImpl.java |  290 +++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 239 insertions(+), 51 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 60ea4b0..7c30f48 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.P;
 import liquibase.pro.packaged.W;
 import liquibase.repackaged.org.apache.commons.lang3.StringUtils;
 import org.apache.logging.log4j.util.Strings;
@@ -46,7 +47,9 @@
 import org.springblade.modules.house.entity.HouseholdEntity;
 import org.springblade.modules.house.entity.UserHouseLabelEntity;
 import org.springblade.modules.house.service.IHouseholdService;
+import org.springblade.modules.house.vo.HouseholdVO;
 import org.springblade.modules.label.entity.LabelEntity;
+import org.springblade.modules.partyOrganization.vo.PartyOrganizationVO;
 import org.springblade.modules.place.entity.*;
 import org.springblade.modules.place.excel.NinePlaceExcel;
 import org.springblade.modules.place.excel.PlaceAndRelExcel;
@@ -106,9 +109,6 @@
 
 	@Autowired
 	private IGridRangeService gridRangeService;
-
-	@Autowired
-	private IGridmanService gridmanService;
 
 	@Autowired
 	private GridMapper gridMapper;
@@ -215,8 +215,65 @@
 		gridBind(placeVO);
 		// 警务网格绑定
 		jwGridCodeBind(placeVO);
+		// 保存从业人员
+		savePlacePractitioner(placeVO);
 		// 返回结果
 		return flag;
+	}
+
+
+	/**
+	 * 保存从业人员
+	 *
+	 * @param placeVO
+	 */
+	private void savePlacePractitioner(PlaceVO placeVO) {
+		if (placeVO.getPlacePractitioner() != null) {
+			IPlacePractitionerService practitionerService = SpringUtil.getBean(IPlacePractitionerService.class);
+			// 查询对应已存在的租户
+			QueryWrapper<PlacePractitionerEntity> wrapper = new QueryWrapper<>();
+			wrapper.eq("place_id", placeVO.getId()).eq("is_deleted",0);
+			List<PlacePractitionerEntity> oldList = practitionerService.list(wrapper);
+			// 取出从业人员信息
+			List<PlacePractitionerEntity> placePractitionerList = placeVO.getPlacePractitioner();
+			for (PlacePractitionerEntity placePractitionerEntity : placePractitionerList) {
+				placePractitionerEntity.setPlaceId(placeVO.getId());
+			}
+			// 申明新增,修改,删除集合
+			List<PlacePractitionerEntity> newList = new ArrayList<>();
+			List<PlacePractitionerEntity> addList = new ArrayList<>();
+			List<PlacePractitionerEntity> updateList = new ArrayList<>();
+			List<PlacePractitionerEntity> removeList = new ArrayList<>();
+			// 遍历设置数据
+			for (PlacePractitionerEntity placePractitionerEntity : placePractitionerList) {
+				if (null == placePractitionerEntity.getId()) {
+					// 新增
+					addList.add(placePractitionerEntity);
+				} else {
+					newList.add(placePractitionerEntity);
+				}
+			}
+			// 遍历去差集,判断是新增还是删除还是更新
+			// 取旧数据和新提交数据差集--删除
+			removeList = oldList.stream().filter(vo -> !newList.stream().map(e ->
+				e.getId()).collect(Collectors.toList()).contains(vo.getId())).collect(Collectors.toList());
+			// 取旧数据和新提交数据交集--更新
+			updateList = newList.stream().filter(vo -> oldList.stream().map(e ->
+				e.getId()).collect(Collectors.toList()).contains(vo.getId())).collect(Collectors.toList());
+
+			// 批量新增
+			if (addList.size() > 0) {
+				practitionerService.saveBatch(addList);
+			}
+			// 批量修改
+			if (updateList.size() > 0) {
+				practitionerService.updateBatchById(updateList);
+			}
+			// 批量删除
+			if (removeList.size() > 0) {
+				practitionerService.removeBatchByIds(removeList);
+			}
+		}
 	}
 
 	/**
@@ -245,6 +302,7 @@
 	 *
 	 * @param placeVO
 	 */
+	@Override
 	public void jwGridCodeBind(PlaceVO placeVO) {
 		if (!Strings.isBlank(placeVO.getLng())) {
 			String point = "'POINT(" + placeVO.getLng() + " " + placeVO.getLat() + ")'";
@@ -478,7 +536,8 @@
 	 *
 	 * @param placeVO
 	 */
-	private void policePositionHandle(PlaceVO placeVO) {
+	@Override
+	public void policePositionHandle(PlaceVO placeVO) {
 		// 是民警且位置信息存在
 		if (!Strings.isBlank(placeVO.getLng())) {
 			//点坐标解析
@@ -665,18 +724,9 @@
 			placeVO.setPrincipal(placeVO.getPrincipal());
 			placeVO.setPrincipalPhone(placeVO.getPrincipalPhone());
 			//根据手机号查询库里的数据
-			User userParams = new User();
-			userParams.setPhone(placeVO.getPrincipalPhone());
-			userParams.setIsDeleted(0);
-			User user = userService.getOne(Condition.getQueryWrapper(userParams));
-			if (null == user) {
-				User userParams1 = new User();
-				userParams1.setAccount(placeVO.getPrincipalPhone());
-				userParams1.setIsDeleted(0);
-				user = userService.getOne(Condition.getQueryWrapper(userParams1));
-			}
-
-			if (null != user) {
+			List<User> list = userService.getUserListByPhoneOrAccount(placeVO.getPrincipalPhone());
+			if (list.size()>0) {
+				User user = list.get(0);
 				//如果用户存在,则该用户id绑定场所
 				placeVO.setPrincipalUserId(user.getId());
 				newUser = user;
@@ -718,13 +768,16 @@
 	@Transactional(rollbackFor = Exception.class)
 	public void savePlaceExtAndTaskInfo(PlaceVO placeVO) {
 		PlaceExtEntity placeExtEntity = new PlaceExtEntity();
-		placeExtEntity.setPlaceId(placeVO.getId());
 		// 判断是否已存在,已存在则不新增
 		QueryWrapper<PlaceExtEntity> wrapper = new QueryWrapper<>();
 		wrapper.eq("is_deleted", 0)
 			.eq("place_id", placeVO.getId());
-		PlaceExtEntity one = placeExtService.getOne(wrapper);
-		if (null == one) {
+		PlaceExtEntity extServiceOne = placeExtService.getOne(wrapper);
+		if (null == extServiceOne) {
+			// 判断是否有传
+			if (placeVO.getPlaceExtEntity() != null) {
+				placeExtEntity = placeVO.getPlaceExtEntity();
+			}
 			placeExtEntity.setPlaceId(placeVO.getId());
 			// 默认给待完善状态
 			placeExtEntity.setConfirmFlag(4);
@@ -734,6 +787,10 @@
 			placeExtEntity.setUpdateUser(AuthUtil.getUserId());
 			// 新增场所详情
 			placeExtService.save(placeExtEntity);
+		} else {
+			if (placeVO.getPlaceExtEntity() != null) {
+				placeExtService.updateById(placeVO.getPlaceExtEntity());
+			}
 		}
 	}
 
@@ -852,6 +909,13 @@
 				QueryWrapper<PlaceExtEntity> queryWrapper = new QueryWrapper<>();
 				queryWrapper.eq("is_deleted", 0).eq("place_id", placeVO.getId());
 				placeVO.setPlaceExtEntity(placeExtService.getOne(queryWrapper));
+				// 查询从业人员
+				IPlacePractitionerService placePractitionerService = SpringUtils.getBean(IPlacePractitionerService.class);
+				List<PlacePractitionerEntity> entityList = placePractitionerService.list(Wrappers.<PlacePractitionerEntity>lambdaQuery()
+					.eq(PlacePractitionerEntity::getPlaceId, placeVO.getId()));
+				placeVO.setPlacePractitioner(entityList);
+				// 查询绑定的房屋
+				placeVO.setHouseBindList(baseMapper.getHouseBindMap(placeVO.getHouseCodeBinds()));
 			}
 		} else {
 			// 查询地址编码信息(社区派出所相关信息)
@@ -890,8 +954,10 @@
 			if (null == one) {
 				Long userId = updateUser(placeExcel);
 				// 插入场所
-				PlaceEntity placeEntity = new PlaceEntity();
-				placeEntity.setHouseCode(placeExcel.getHouseCode());
+				PlaceVO placeEntity = new PlaceVO();
+				String[] split = placeExcel.getHouseCode().split(",");
+				placeEntity.setHouseCode(split[0]);
+				placeEntity.setHouseCodeBinds(placeExcel.getHouseCode());
 				placeEntity.setPrincipalUserId(userId);
 				placeEntity.setPrincipal(placeExcel.getName());
 				placeEntity.setPrincipalPhone(placeExcel.getPhoneNumber());
@@ -899,8 +965,103 @@
 				placeEntity.setCreateUser(AuthUtil.getUserId());
 				placeEntity.setUpdateTime(new Date());
 				placeEntity.setUpdateUser(AuthUtil.getUserId());
-				//一个一个插入,防止同一个表中有相同的数据
+				// 默认为未完善
+				placeEntity.setStatus(1);
+				// 是否现场采集  1:是  2:否
+				placeEntity.setIsScene(1);
+				// 来源 1:地址总表  2:国控采集 3:商超
+				if (!Strings.isBlank(placeExcel.getHouseCode())) {
+					placeEntity.setSource(1);
+				}else {
+					placeEntity.setSource(2);
+					// 并生成36位的houseCode
+					placeEntity.setHouseCode(IdUtils.getIdBy36());
+				}
+				// 九小场所类型处理
+				if (!Strings.isBlank(placeExcel.getNineType())) {
+					placeEntity.setIsNine(1);
+					placeEntity.setNineType(Integer.parseInt(placeExcel.getNineType()));
+				}
+				// 网格绑定处理
+				importGridHandle(placeExcel,placeEntity);
+				// 新增
 				save(placeEntity);
+				// 保存详情
+				savePlaceExtAndTaskInfo(placeEntity);
+				// 场所标签信息处理
+				if (!Strings.isBlank(placeExcel.getLabelCode())) {
+					PlaceVO placeVO = new PlaceVO();
+					placeVO.setId(placeEntity.getId());
+					placeVO.setLabel(placeExcel.getLabelCode());
+					// 处理
+					placeLabelBind(placeVO);
+				}
+				// 房屋编号绑定处理
+				houseCodeBindHandle(placeEntity);
+			}else {
+				// 更新
+				Long userId = updateUser(placeExcel);
+				// 插入场所
+				PlaceVO placeEntity = new PlaceVO();
+				placeEntity.setId(one.getId());
+				placeEntity.setHouseCode(placeExcel.getHouseCode());
+				placeEntity.setHouseCodeBinds(placeExcel.getHouseCode());
+				placeEntity.setPrincipalUserId(userId);
+				placeEntity.setPrincipal(placeExcel.getName());
+				placeEntity.setPrincipalPhone(placeExcel.getPhoneNumber());
+				placeEntity.setCreateTime(new Date());
+				placeEntity.setCreateUser(AuthUtil.getUserId());
+				placeEntity.setUpdateTime(new Date());
+				placeEntity.setUpdateUser(AuthUtil.getUserId());
+				// 默认为未完善
+				placeEntity.setStatus(1);
+				// 是否现场采集  1:是  2:否
+				placeEntity.setIsScene(1);
+				// 来源 1:地址总表  2:国控采集 3:商超
+				placeEntity.setSource(1);
+				// 九小场所类型处理
+				if (!Strings.isBlank(placeExcel.getNineType())) {
+					placeEntity.setIsNine(1);
+					placeEntity.setNineType(Integer.parseInt(placeExcel.getNineType()));
+				}
+				// 网格绑定处理
+				importGridHandle(placeExcel,placeEntity);
+				// 更新
+				updateById(placeEntity);
+				// 场所标签信息处理
+				if (!Strings.isBlank(placeExcel.getLabelCode())) {
+					PlaceVO placeVO = new PlaceVO();
+					placeVO.setId(placeEntity.getId());
+					placeVO.setLabel(placeExcel.getLabelCode());
+					// 处理
+					placeLabelBind(placeVO);
+				}
+			}
+		}
+	}
+
+	/**
+	 * 导入是网格数据绑定处理
+	 * @param placeExcel
+	 * @param placeEntity
+	 */
+	private void importGridHandle(PlaceExcel placeExcel, PlaceVO placeEntity) {
+		if (!Strings.isBlank(placeExcel.getCommunityName()) &&
+			!Strings.isBlank(placeExcel.getGridName())){
+			// 查询对应的网格信息
+			GridEntity gridEntity = gridService.getGridInfoByParam(placeExcel.getCommunityName(),placeExcel.getGridName());
+			if (null!=gridEntity){
+				// 设置场所范围
+				placeEntity.setGridId(gridEntity.getId());
+				placeEntity.setGridCode(gridEntity.getGridCode());
+				// 更新网格范围绑定
+				GridRangeEntity gridRangeEntity = new GridRangeEntity();
+				gridRangeEntity.setGridId(gridEntity.getId());
+				gridRangeEntity.setGridCode(gridEntity.getGridCode());
+				gridRangeEntity.setHouseCode(placeEntity.getHouseCode());
+				UpdateWrapper<GridRangeEntity> updateWrapper = new UpdateWrapper<>();
+				updateWrapper.eq("house_code",placeEntity.getHouseCode());
+				gridRangeService.update(gridRangeEntity,updateWrapper);
 			}
 		}
 	}
@@ -915,8 +1076,8 @@
 		if (!Strings.isBlank(placeExcel.getPhoneNumber()) &&
 			!Strings.isBlank(placeExcel.getName())) {
 			PlaceVO placeVO = new PlaceVO();
-			placeVO.setPhone(placeExcel.getPhoneNumber());
-			placeVO.setUsername(placeExcel.getName());
+			placeVO.setPrincipal(placeExcel.getPhoneNumber());
+			placeVO.setPrincipalPhone(placeExcel.getName());
 			// 更新场所负责人
 			User user = bindUserHandle(placeVO);
 			// 返回
@@ -986,9 +1147,9 @@
 				placeRelEntity.setPlaceId(placeEntity.getId());
 				placeRelEntity.setStreetName(placeExcel.getStreetName());
 				QueryWrapper<Region> wrapper = new QueryWrapper<>();
-				wrapper.eq("name",placeExcel.getCommunityName());
+				wrapper.eq("name", placeExcel.getCommunityName());
 				Region region = SpringUtils.getBean(IRegionService.class).getOne(wrapper);
-				if (null!=region){
+				if (null != region) {
 					placeRelEntity.setCommunityCode(region.getCode());
 				}
 				placeRelEntity.setCommunityName(placeExcel.getCommunityName());
@@ -1032,10 +1193,10 @@
 		if (!Strings.isBlank(placeExcel.getLabelCode())) {
 			// 匹配标签
 			QueryWrapper<CategoryEntity> wrapper = new QueryWrapper<>();
-			wrapper.eq("level",3).eq("category_name",placeExcel.getLabelCode()).eq("is_deleted",0);
+			wrapper.eq("level", 3).eq("category_name", placeExcel.getLabelCode()).eq("is_deleted", 0);
 			// 查询
 			List<CategoryEntity> list = SpringUtils.getBean(ICategoryService.class).list(wrapper);
-			if (list.size()>0){
+			if (list.size() > 0) {
 				PlaceVO placeVO = new PlaceVO();
 				CategoryEntity categoryEntity = list.get(0);
 				placeVO.setLabel(categoryEntity.getCategoryNo());
@@ -1367,28 +1528,7 @@
 
 	@Override
 	public List<NinePlaceExcel> export(PlaceVO place) {
-		String roleName = SpringUtils.getRequestParam("roleName");
-		String communityCode = SpringUtils.getRequestParam("communityCode");
-		if (!Strings.isBlank(communityCode)) {
-			// 校验社区编号是否合规
-			if (null != SpringUtils.getBean(IRegionService.class).getById(communityCode)) {
-				place.setCommunityCode(communityCode);
-			}
-		}
-		List<String> regionChildCodesList = SysCache.getRegionChildCodesByDeptId(AuthUtil.getDeptId());
-		Integer isAdministrator = AuthUtil.isAdministrator() == true ? 1 : 2;
-		// 网格编号集合
-		List<String> gridCodeList = new ArrayList<>();
-		// 民警角色
-		if (!Strings.isBlank(roleName)) {
-			place.setRoleName(roleName);
-			if (roleName.equals("mj")) {
-				regionChildCodesList = SpringUtil.getBean(IPoliceAffairsGridService.class).getCommunityCodeListByUserId(AuthUtil.getUserId());
-			}
-			if (roleName.equals("wgy")) {
-				gridCodeList = SpringUtil.getBean(IGridService.class).getGridListByUserId(AuthUtil.getUserId());
-			}
-		}
+		CommonParamSet commonParamSet = new CommonParamSet<>().invoke(PlaceVO.class, place);
 		List<String> strings = new ArrayList<>();
 		if (null != place.getNineType()) {
 			QueryWrapper<DictBiz> queryWrapper = new QueryWrapper<>();
@@ -1403,7 +1543,11 @@
 				strings = list.stream().map(DictBiz::getDictKey).collect(Collectors.toList());
 			}
 		}
-		List<NinePlaceExcel> aa = baseMapper.export(place, gridCodeList, regionChildCodesList, isAdministrator, strings);
+		List<NinePlaceExcel> aa = baseMapper.export(place,
+			commonParamSet.getGridCodeList(),
+			commonParamSet.getRegionChildCodesList(),
+			commonParamSet.getIsAdministrator(),
+			strings);
 		IDictBizService bean = SpringUtils.getBean(IDictBizService.class);
 		List<DictBiz> nineType = bean.list(Wrappers.<DictBiz>lambdaQuery().eq(DictBiz::getCode, "nineType").eq(DictBiz::getIsDeleted, 0));
 		for (NinePlaceExcel ninePlaceExcel : aa) {
@@ -1503,4 +1647,48 @@
 		}
 		return null;
 	}
+
+	/**
+	 * 企业商超列表查询
+	 */
+	@Override
+	public IPage<PlaceVO> selectMallPage(IPage<PlaceVO> page, PlaceVO place) {
+		// 公共参数设置
+		CommonParamSet commonParamSet = new CommonParamSet().invoke(PlaceVO.class, place);
+		List<PlaceVO> placeVOS = baseMapper.selectMallPage(page,
+			place,
+			commonParamSet.getGridCodeList(),
+			commonParamSet.getRegionChildCodesList(),
+			commonParamSet.getIsAdministrator());
+		// 返回
+		return page.setRecords(placeVOS);
+	}
+
+	/**
+	 * 查询所有场所数据
+	 * @return
+	 */
+	@Override
+	public List<PlaceVO> getAllList(int i,int size) {
+		return baseMapper.getAllList(i,size);
+	}
+
+	/**
+	 * 查询所有场所数据总数
+	 * @return
+	 */
+	@Override
+	public int getAllListTotal() {
+		return baseMapper.getAllListTotal();
+	}
+
+	/**
+	 * 查询对应的社区编号
+	 * @param id
+	 * @return
+	 */
+	@Override
+	public String getCommunityCode(Long id) {
+		return baseMapper.getCommunityCode(id);
+	}
 }

--
Gitblit v1.9.3