From a5fac95408a43ad43de9d88c30d06c0918c7bc8f Mon Sep 17 00:00:00 2001
From: zhongrj <646384940@qq.com>
Date: Wed, 29 May 2024 11:14:44 +0800
Subject: [PATCH] 配置调整

---
 src/main/java/org/springblade/modules/system/service/impl/UserServiceImpl.java |  263 +++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 226 insertions(+), 37 deletions(-)

diff --git a/src/main/java/org/springblade/modules/system/service/impl/UserServiceImpl.java b/src/main/java/org/springblade/modules/system/service/impl/UserServiceImpl.java
index b9b5b09..77daeaf 100644
--- a/src/main/java/org/springblade/modules/system/service/impl/UserServiceImpl.java
+++ b/src/main/java/org/springblade/modules/system/service/impl/UserServiceImpl.java
@@ -1,27 +1,14 @@
-/*
- *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
- *
- *  Redistribution and use in source and binary forms, with or without
- *  modification, are permitted provided that the following conditions are met:
- *
- *  Redistributions of source code must retain the above copyright notice,
- *  this list of conditions and the following disclaimer.
- *  Redistributions in binary form must reproduce the above copyright
- *  notice, this list of conditions and the following disclaimer in the
- *  documentation and/or other materials provided with the distribution.
- *  Neither the name of the dreamlu.net developer nor the names of its
- *  contributors may be used to endorse or promote products derived from
- *  this software without specific prior written permission.
- *  Author: Chill 庄骞 (smallchill@163.com)
- */
 package org.springblade.modules.system.service.impl;
 
 
+import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import lombok.AllArgsConstructor;
+import org.apache.ibatis.annotations.Param;
 import org.apache.logging.log4j.util.Strings;
 import org.springblade.common.cache.DictCache;
 import org.springblade.common.cache.ParamCache;
@@ -42,23 +29,16 @@
 import org.springblade.core.tool.utils.*;
 import org.springblade.modules.auth.enums.UserEnum;
 import org.springblade.modules.system.entity.*;
+import org.springblade.modules.system.excel.PoliceUserExcel;
 import org.springblade.modules.system.excel.UserExcel;
 import org.springblade.modules.system.mapper.UserMapper;
-import org.springblade.modules.system.service.IRoleService;
-import org.springblade.modules.system.service.IUserDeptService;
-import org.springblade.modules.system.service.IUserOauthService;
-import org.springblade.modules.system.service.IUserService;
+import org.springblade.modules.system.service.*;
 import org.springblade.modules.system.vo.UserDetailVO;
 import org.springblade.modules.system.vo.UserVO;
 import org.springblade.modules.system.wrapper.UserWrapper;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Objects;
-
+import java.util.*;
 import static org.springblade.common.constant.CommonConstant.DEFAULT_PARAM_PASSWORD;
 
 /**
@@ -103,7 +83,11 @@
 		if (userCount > 0L && Func.isEmpty(user.getId())) {
 			throw new ServiceException(StringUtil.format("当前用户 [{}] 已存在!", user.getAccount()));
 		}
-		return save(user) && submitUserDept(user);
+		boolean save = save(user);
+		// 更新警格或网格的绑定
+		updateGridBind(user);
+		// 返回
+		return save && submitUserDept(user);
 	}
 
 	@Override
@@ -126,7 +110,17 @@
 	public boolean updateUserInfo(User user) {
 		user.setPassword(null);
 		boolean b = updateById(user);
+		// 更新警格或网格的绑定
+		updateGridBind(user);
 		return b;
+	}
+
+	/**
+	 * 更新警格或网格的绑定
+	 *
+	 * @param user
+	 */
+	public void updateGridBind(User user) {
 	}
 
 	private boolean submitUserDept(User user) {
@@ -144,9 +138,9 @@
 	}
 
 	@Override
-	public IPage<User> selectUserPage(IPage<User> page, User user, Long deptId, String tenantId) {
-		if (null == deptId && !AuthUtil.isAdministrator()){
-			deptId = Long.parseLong(AuthUtil.getDeptId());
+	public IPage<User> selectUserPage(IPage<User> page, User user, String deptId, String tenantId) {
+		if (Strings.isBlank(deptId) && !AuthUtil.isAdministrator() && !AuthUtil.isAdmin()) {
+			deptId = AuthUtil.getDeptId();
 		}
 		List<Long> deptIdList = SysCache.getDeptChildIds(deptId);
 		return page.setRecords(baseMapper.selectUserPage(page, user, deptIdList, tenantId));
@@ -187,6 +181,12 @@
 	@Override
 	public User userByAccount(String tenantId, String account) {
 		return baseMapper.selectOne(Wrappers.<User>query().lambda().eq(User::getTenantId, tenantId).eq(User::getAccount, account).eq(User::getIsDeleted, BladeConstant.DB_NOT_DELETED));
+	}
+
+	@Override
+	public UserInfo userInfo(String tenantId, String account) {
+		User user = baseMapper.selectOne(Wrappers.<User>query().lambda().eq(User::getTenantId, tenantId).eq(User::getAccount, account).eq(User::getIsDeleted, BladeConstant.DB_NOT_DELETED));
+		return buildUserInfo(user);
 	}
 
 	@Override
@@ -303,7 +303,20 @@
 		if (Func.contains(Func.toLongArray(userIds), AuthUtil.getUserId())) {
 			throw new ServiceException("不能删除本账号!");
 		}
-		return deleteLogic(Func.toLongList(userIds));
+		boolean deleteLogic = deleteLogic(Func.toLongList(userIds));
+		if (deleteLogic) {
+			// 删除警格绑定
+			removePoliceGridBind(userIds);
+		}
+		return deleteLogic;
+	}
+
+	/**
+	 * 删除警格绑定
+	 *
+	 * @param userIds
+	 */
+	public void removePoliceGridBind(String userIds) {
 	}
 
 	@Override
@@ -341,8 +354,12 @@
 	}
 
 	@Override
-	public List<UserExcel> exportUser(Wrapper<User> queryWrapper) {
-		List<UserExcel> userList = baseMapper.exportUser(queryWrapper);
+	public List<UserExcel> exportUser(Wrapper<User> queryWrapper, String deptId) {
+		if (Strings.isBlank(deptId) && !AuthUtil.isAdministrator() && !AuthUtil.isAdmin()) {
+			deptId = AuthUtil.getDeptId();
+		}
+		List<Long> deptIdList = SysCache.getDeptChildIds(deptId);
+		List<UserExcel> userList = baseMapper.exportUser(queryWrapper, deptIdList);
 		userList.forEach(user -> {
 			user.setUserTypeName(DictCache.getValue(DictEnum.USER_TYPE, user.getUserType()));
 			user.setRoleName(StringUtil.join(SysCache.getRoleNames(user.getRoleId())));
@@ -435,12 +452,13 @@
 
 	/**
 	 * 按条件查询用户信息
+	 *
 	 * @param user
 	 * @return
 	 */
 	@Override
 	public List<UserVO> getUserListByParam(UserVO user) {
-		if (!Strings.isBlank(user.getRoleName())){
+		if (!Strings.isBlank(user.getRoleName())) {
 			// 查询对应的角色id
 			String roleIds = roleService.getRoleIds("000000", user.getRoleName());
 			user.setRoleId(roleIds);
@@ -450,36 +468,207 @@
 
 	/**
 	 * 通过小区Id搜索用户
+	 *
 	 * @param districtId
 	 * @return
 	 */
 	@Override
 	public List<User> searchUserByDistrictId(String districtId) {
-		return baseMapper.searchUserByDistrictId( districtId);
+		return baseMapper.searchUserByDistrictId(districtId);
 	}
 
 	/**
 	 * 根据手机号查询对应账号和手机号的用户信息
+	 *
 	 * @param phoneNumber
 	 * @return
 	 */
 	@Override
 	public List<User> getUserListByPhoneOrAccount(String phoneNumber) {
-		return baseMapper.getUserListByPhoneOrAccount( phoneNumber);
+		return baseMapper.getUserListByPhoneOrAccount(phoneNumber);
 	}
 
 	/**
 	 * 获取用户信息
+	 *
 	 * @return
 	 */
 	@Override
 	public UserDetailVO getUserInfo(Long userId) {
 		// 根据用户id 获取用户详情信息
 		UserDetailVO userVO = baseMapper.getUserInfo(userId);
-		if (null!=userVO){
+		if (null != userVO) {
+			// 设置机构
 			userVO.setPassword(null);
 		}
 		// 返回
 		return userVO;
 	}
+
+	@Override
+	public UserVO getuserById(Long id) {
+		return baseMapper.searchUserById(id);
+	}
+
+	/**
+	 * 处理漏绑定的user_dept
+	 */
+	@Override
+	public Object handleUserDept() {
+		// 查询没有匹配的数据
+		List<User> list = baseMapper.getNotBindUserDept();
+		// 遍历处理
+		for (User user : list) {
+			UserDept userDept = new UserDept();
+			userDept.setUserId(user.getId());
+			userDept.setDeptId(Long.parseLong(user.getDeptId()));
+			// 保存
+			userDeptService.save(userDept);
+		}
+		return null;
+	}
+
+	@Override
+	public List<User> getUserInfoByPropertyId(String propertyCompanyId, String roleId) {
+		return null;
+	}
+
+	@Override
+	public Object handleUser() {
+		return null;
+	}
+
+	/**
+	 * 导入民警信息
+	 *
+	 * @param data
+	 */
+	@Override
+	@Transactional(rollbackFor = Exception.class)
+	public void importPoliceUser(List<PoliceUserExcel> data) {
+		for (PoliceUserExcel userExcel : data) {
+			// 查询用户
+			List<User> list = getUserListByPhoneOrAccount(userExcel.getPhone());
+			if (list.size() > 0) {
+				User userInfo = list.get(0);
+				// 判断角色
+				if (!userInfo.getRoleId().contains("1727864411451359233")) {
+					userInfo.setRoleId(userInfo.getRoleId() + ",1727864411451359233");
+				}
+				// 更新机构
+				setDeptId(userInfo, userExcel);
+				// 更新
+				updateById(userInfo);
+				// 更新用户机构绑定
+				submitUserDept(userInfo);
+				// 更新社区民警绑定信息
+				updateGridBind(userInfo);
+			} else {
+				// 插入用户角色
+				User user = new User();
+				user.setTenantId("000000");
+				user.setUserType(1);
+				user.setRoleId("1727864411451359233");
+				user.setName(userExcel.getRealName());
+				user.setRealName(userExcel.getRealName());
+				user.setPhone(userExcel.getPhone());
+				user.setAccount(userExcel.getPhone());
+				// 更新机构
+				setDeptId(user, userExcel);
+				// 设置初始密码
+				user.setPassword("123456");
+				// 保存
+				submit(user);
+				// 更新用户机构绑定
+				submitUserDept(user);
+				// 更新社区民警绑定信息
+				updateGridBind(user);
+			}
+		}
+	}
+
+	/**
+	 * 设置机构
+	 */
+	public void setDeptId(User user, PoliceUserExcel userExcel) {
+	}
+
+	/**
+	 * 机构不为空时处理
+	 *
+	 * @param user
+	 * @param dept
+	 */
+	public void DeptNotHandle(User user, Dept dept) {
+		// 更新设置机构
+		if (!Strings.isBlank(user.getDeptId())) {
+			// 查询对应的派出所(去掉)
+			Dept deptPcs = SpringUtil.getBean(IDeptService.class).getDeptByDeptIds(user.getDeptId());
+			if (null != deptPcs) {
+				// 如果存在需要去掉派出所的机构id
+				List<String> list = new ArrayList<>(Arrays.asList(user.getDeptId().split(",")));
+				// 先删除派出所对应的机构ID
+				if (list.contains(deptPcs.getId().toString())) {
+					list.remove(deptPcs.getId().toString());
+					user.setDeptId(String.join(",", list));
+				}
+				// 删完后可能就没了
+				if (!Strings.isBlank(user.getDeptId())) {
+					if (!user.getDeptId().contains(dept.getId().toString())) {
+						user.setDeptId(user.getDeptId() + "," + dept.getId());
+					}
+				} else {
+					// 删完后的
+					user.setDeptId(dept.getId().toString());
+				}
+			} else {
+				if (!user.getDeptId().contains(dept.getId().toString())) {
+					user.setDeptId(user.getDeptId() + "," + dept.getId());
+				}
+			}
+		}
+	}
+
+	/**
+	 * 更新社区民警绑定信息
+	 *
+	 * @param userExcel
+	 * @param user
+	 */
+	public void updateCommunityInfo(PoliceUserExcel userExcel, User user) {
+
+	}
+
+	@Override
+	public List<User> getUserListByIds(String receiveUser) {
+		return baseMapper.selectBatchIds(Arrays.asList(receiveUser.split(",")));
+	}
+
+	@Override
+	public List<User> getUserListByDeptIds(String receiveDept) {
+		return baseMapper.getUserListByDeptIds(receiveDept);
+	}
+
+	/**
+	 * 通过经纬度查询最近的民警人员
+	 *
+	 * @param longitude
+	 * @param latitude
+	 * @return
+	 */
+	@Override
+	public List<User> getPoliceUser(String longitude, String latitude, String houseCode) {
+		List<User> policeUser = baseMapper.getPoliceUser(longitude, latitude);
+		// 自动生成警单
+//		if (StringUtils.isNotBlank(houseCode)) {
+//			IPoliceAlarmRecordsService policeAlarmRecordsService = SpringUtil.getBean(IPoliceAlarmRecordsService.class);
+//			PoliceAlarmRecordsEntity policeAlarmRecordsEntity = new PoliceAlarmRecordsEntity();
+//			policeAlarmRecordsEntity.setHouseCode(houseCode);
+//			if (policeUser != null && policeUser.size() == 1) {
+//				policeAlarmRecordsEntity.setPoliceId(policeUser.get(0).getId());
+//			}
+//			policeAlarmRecordsService.save(policeAlarmRecordsEntity);
+//		}
+		return policeUser;
+	}
 }

--
Gitblit v1.9.3