|
@@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.nokia.common.R;
|
|
|
+import com.nokia.common.exception.BizException;
|
|
|
+import com.nokia.dao.AreaDao;
|
|
|
import com.nokia.dao.UserDao;
|
|
|
import com.nokia.dao.UserFunctionDao;
|
|
|
import com.nokia.dao.UserRoleCityDao;
|
|
@@ -17,10 +19,7 @@ import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import javax.servlet.http.HttpSession;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
@@ -29,12 +28,15 @@ public class UserService {
|
|
|
private final UserDao userDao;
|
|
|
private final UserRoleCityDao userRoleCityDao;
|
|
|
private final UserFunctionDao userFunctionDao;
|
|
|
+ private final AreaDao areaDao;
|
|
|
private final OperationLogService operationLogService;
|
|
|
|
|
|
- public UserService(UserDao userDao, UserRoleCityDao userRoleCityDao, UserFunctionDao userFunctionDao, OperationLogService operationLogService) {
|
|
|
+ public UserService(UserDao userDao, UserRoleCityDao userRoleCityDao, UserFunctionDao userFunctionDao,
|
|
|
+ AreaDao areaDao, OperationLogService operationLogService) {
|
|
|
this.userDao = userDao;
|
|
|
this.userRoleCityDao = userRoleCityDao;
|
|
|
this.userFunctionDao = userFunctionDao;
|
|
|
+ this.areaDao = areaDao;
|
|
|
this.operationLogService = operationLogService;
|
|
|
}
|
|
|
|
|
@@ -54,6 +56,11 @@ public class UserService {
|
|
|
if (role.getCityId() != -1 && !role.getCityId().equals(vo.getCityId())) {
|
|
|
return R.error("非本地市用户");
|
|
|
}
|
|
|
+ if (vo.getCityId() != -1) {
|
|
|
+
|
|
|
+ vo.setAreas(areaDao.getByParentId(vo.getCityId()).stream()
|
|
|
+ .map(t -> new TreeAreaVo(t.getAreaName(), t.getAreaId())).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
return R.ok(vo);
|
|
|
}
|
|
|
|
|
@@ -87,33 +94,36 @@ public class UserService {
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public R<Object> add(AddUserDto dto, HttpSession session) {
|
|
|
+
|
|
|
User user = userDao.selectByLoginName(dto.getLoginName());
|
|
|
if (user != null && user.getDeleted().equals(0)) {
|
|
|
return R.error("用户已存在系统中");
|
|
|
}
|
|
|
- TopUserVo topUser = userDao.getTopUserByLoginName(dto.getLoginName());
|
|
|
- if (topUser == null) {
|
|
|
- return R.error("没有查询到top用户信息");
|
|
|
- }
|
|
|
- if (topUser.getCityId() == null) {
|
|
|
- topUser.setCityId(topUser.getProvinceId());
|
|
|
- }
|
|
|
UserRoleCity role = getUserRoleCity(session);
|
|
|
- if (role.getCityId() != -1 && !role.getCityId().equals(topUser.getCityId())) {
|
|
|
+ if (role.getCityId() != -1 && !role.getCityId().equals(dto.getCityId())) {
|
|
|
return R.error("无法添加非本地市用户");
|
|
|
}
|
|
|
+
|
|
|
+ if (!CollectionUtils.isEmpty(dto.getRoles())) {
|
|
|
+ for (AddUserRoleDto t : dto.getRoles()) {
|
|
|
+
|
|
|
+ if (!t.getRoleId().equals(3) && !t.getCityId().equals(dto.getCityId())) {
|
|
|
+ throw new BizException("权限和地市不匹配");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
if (user == null) {
|
|
|
user = new User();
|
|
|
}
|
|
|
- user.setLoginName(topUser.getLoginName());
|
|
|
- user.setUserName(topUser.getUserName());
|
|
|
- user.setPhone(topUser.getPhone());
|
|
|
+ user.setLoginName(dto.getLoginName());
|
|
|
+ user.setUserName(dto.getUserName());
|
|
|
+ user.setPhone(dto.getPhone());
|
|
|
user.setEmail(dto.getEmail());
|
|
|
- user.setOrg(topUser.getOrgName());
|
|
|
+ user.setOrg(dto.getOrgName());
|
|
|
user.setDeleted(0);
|
|
|
- user.setProvinceId(topUser.getProvinceId());
|
|
|
- user.setCityId(topUser.getCityId());
|
|
|
- user.setAreaId(topUser.getAreaId());
|
|
|
+ user.setProvinceId(dto.getProvinceId());
|
|
|
+ user.setCityId(dto.getCityId());
|
|
|
+ user.setAreaId(dto.getAreaId());
|
|
|
|
|
|
if (user.getUserId() == null) {
|
|
|
userDao.insert(user);
|
|
@@ -122,14 +132,15 @@ public class UserService {
|
|
|
userDao.updateById(user);
|
|
|
}
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
- sb.append("添加用户 ").append(topUser.getLoginName()).append(";")
|
|
|
- .append("用户名:").append(topUser.getUserName()).append(",")
|
|
|
- .append("手机号:").append(topUser.getPhone()).append(",")
|
|
|
+ sb.append("添加用户 ").append(dto.getLoginName()).append(";")
|
|
|
+ .append("用户名:").append(dto.getUserName()).append(",")
|
|
|
+ .append("手机号:").append(dto.getPhone()).append(",")
|
|
|
.append("邮箱:").append(dto.getEmail()).append(",")
|
|
|
- .append("部门:").append(topUser.getOrgName()).append(",")
|
|
|
- .append("省份:").append(topUser.getProvinceName()).append(",")
|
|
|
- .append("地市:").append(topUser.getCityName()).append(",")
|
|
|
- .append("区县:").append(topUser.getAreaName()).append(";");
|
|
|
+ .append("部门:").append(dto.getOrgName()).append(",")
|
|
|
+ .append("省份:").append(dto.getProvinceName()).append(",")
|
|
|
+ .append("地市:").append(dto.getCityName()).append(",")
|
|
|
+ .append("区县:").append(dto.getAreaName()).append(";");
|
|
|
+
|
|
|
if (!CollectionUtils.isEmpty(dto.getRoles())) {
|
|
|
int userId = user.getUserId();
|
|
|
List<UserRoleCity> userRoleCities = new ArrayList<>();
|
|
@@ -160,21 +171,46 @@ public class UserService {
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public R<Object> update(UpdateUserDto dto, HttpSession session) {
|
|
|
- User user = userDao.selectById(dto.getUserId());
|
|
|
+ GetUserDetailVo oldUser = userDao.getUserDetail(dto.getUserId());
|
|
|
UserRoleCity role = getUserRoleCity(session);
|
|
|
- if (role.getCityId() != -1 && !role.getCityId().equals(user.getCityId())) {
|
|
|
+ if (role.getCityId() != -1 && !role.getCityId().equals(oldUser.getCityId())) {
|
|
|
return R.error("无法修改非本地市用户");
|
|
|
}
|
|
|
+
|
|
|
+ if (!CollectionUtils.isEmpty(dto.getRoles())) {
|
|
|
+ for (AddUserRoleDto t : dto.getRoles()) {
|
|
|
+
|
|
|
+ if (!t.getRoleId().equals(3) && !t.getCityId().equals(oldUser.getCityId())) {
|
|
|
+ throw new BizException("权限和地市不匹配");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ User user = new User();
|
|
|
+ user.setUserId(dto.getUserId());
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
- sb.append("修改用户 ").append(user.getLoginName()).append(";");
|
|
|
- if (StringUtils.hasText(dto.getEmail()) && !dto.getEmail().equals(user.getEmail())) {
|
|
|
- sb.append("邮箱旧值:").append(user.getEmail()).append(",")
|
|
|
+ sb.append("修改用户 ").append(oldUser.getLoginName()).append(";");
|
|
|
+ if (StringUtils.hasText(dto.getEmail()) && !dto.getEmail().equals(oldUser.getEmail())) {
|
|
|
+ sb.append("邮箱旧值:").append(oldUser.getEmail()).append(",")
|
|
|
.append("邮箱新值:").append(dto.getEmail()).append(";");
|
|
|
user.setEmail(dto.getEmail());
|
|
|
+ }
|
|
|
+ if (StringUtils.hasText(dto.getPhone()) && !dto.getPhone().equals(oldUser.getPhone())) {
|
|
|
+ sb.append("手机号旧值:").append(oldUser.getPhone()).append(",")
|
|
|
+ .append("手机号新值:").append(dto.getPhone()).append(";");
|
|
|
+ user.setPhone(dto.getPhone());
|
|
|
+ }
|
|
|
+ if (dto.getAreaId() != null && !dto.getAreaId().equals(oldUser.getAreaId())) {
|
|
|
+ sb.append("区县旧值:").append(oldUser.getAreaName()).append(",")
|
|
|
+ .append("区县新值:").append(dto.getAreaName()).append(";");
|
|
|
+ user.setAreaId(dto.getAreaId());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.hasText(user.getEmail()) || StringUtils.hasText(user.getPhone()) || user.getAreaId() != null) {
|
|
|
userDao.updateById(user);
|
|
|
}
|
|
|
+
|
|
|
if (!CollectionUtils.isEmpty(dto.getRoles())) {
|
|
|
- int userId = user.getUserId();
|
|
|
+ int userId = oldUser.getUserId();
|
|
|
List<GetUserDetailRoleVo> oldRoles = userDao.getUserDetailRole(userId);
|
|
|
sb.append("角色旧值:");
|
|
|
for (GetUserDetailRoleVo t : oldRoles) {
|
|
@@ -186,7 +222,7 @@ public class UserService {
|
|
|
for (AddUserRoleDto t : dto.getRoles()) {
|
|
|
sb.append(t.getRoleName()).append("-").append(t.getCityName()).append(",");
|
|
|
UserRoleCity userRoleCity = new UserRoleCity();
|
|
|
- userRoleCity.setUserId(user.getUserId());
|
|
|
+ userRoleCity.setUserId(oldUser.getUserId());
|
|
|
userRoleCity.setRoleId(t.getRoleId());
|
|
|
userRoleCity.setCityId(t.getCityId());
|
|
|
userRoleCities.add(userRoleCity);
|
|
@@ -238,15 +274,34 @@ public class UserService {
|
|
|
GetUserDetailVo vo = userDao.getUserDetail(dto.getUserId());
|
|
|
List<GetUserDetailRoleVo> roles = userDao.getUserDetailRole(dto.getUserId());
|
|
|
vo.setRoles(roles);
|
|
|
+ if (vo.getCityId() != -1) {
|
|
|
+
|
|
|
+ vo.setAreas(areaDao.getByParentId(vo.getCityId()).stream()
|
|
|
+ .map(t -> new TreeAreaVo(t.getAreaName(), t.getAreaId())).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
return R.ok(vo);
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public R<Object> copyRole(CopyRolesDto dto, HttpSession session) {
|
|
|
+ List<Integer> cityIds = userDao.getCityIdsByUserIds(dto.getUserIds());
|
|
|
+ if (cityIds.size() > 1) {
|
|
|
+ return R.error("不能选择不同地市用户");
|
|
|
+ }
|
|
|
+ int cityId = cityIds.get(0);
|
|
|
UserRoleCity role = getUserRoleCity(session);
|
|
|
- if (role.getCityId() != -1 && userDao.exceptCityUser(role.getCityId(), dto.getUserIds()) != null) {
|
|
|
+ if (role.getCityId() != -1 && !role.getCityId().equals(cityId)) {
|
|
|
return R.error("无法修改非本地市用户");
|
|
|
}
|
|
|
+
|
|
|
+ if (!CollectionUtils.isEmpty(dto.getRoles())) {
|
|
|
+ for (AddUserRoleDto t : dto.getRoles()) {
|
|
|
+
|
|
|
+ if (!t.getRoleId().equals(3) && !t.getCityId().equals(cityId)) {
|
|
|
+ throw new BizException("权限和地市不匹配");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
List<User> users = userDao.selectBatchIds(dto.getUserIds());
|
|
|
String loginNames = users.stream().map(User::getLoginName).collect(Collectors.joining("、"));
|