瀏覽代碼

Merge branch 'wanjing' into develop

tags/v1.0.0^2
wanjing 1 年之前
父節點
當前提交
b26464a1f4
共有 6 個檔案被更改,包括 199 行新增2 行删除
  1. +11
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/controller/UserController.java
  2. +25
    -1
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/dept/add/AddDeptService.java
  3. +1
    -1
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/dept/update/UpdateDeptService.java
  4. +5
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/user/IUserService.java
  5. +12
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/user/UserServiceImpl.java
  6. +145
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/user/init/SystemUserInitService.java

+ 11
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/controller/UserController.java 查看文件

@@ -114,4 +114,15 @@ public class UserController {
return userService.getListByDeptId(deptId);
}

/**
* 初始化系统超级管理员用户
*
* @param username
* @return
*/
@PostMapping("/init/{username}")
public JsonResult init(@PathVariable("username") String username) {
return userService.init(username);
}

}

+ 25
- 1
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/dept/add/AddDeptService.java 查看文件

@@ -1,11 +1,13 @@
package com.tuoheng.admin.service.dept.add;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tuoheng.admin.entity.*;
import com.tuoheng.admin.enums.code.dept.AddDeptCodeEnum;
import com.tuoheng.admin.mapper.DeptMapper;
import com.tuoheng.admin.mapper.RoadDeptMapper;
import com.tuoheng.admin.mapper.SectionDeptMapper;
import com.tuoheng.admin.mapper.UserMapper;
import com.tuoheng.admin.request.dept.AddDeptRequest;
import com.tuoheng.admin.dto.RoadSectionDto;
import com.tuoheng.admin.utils.CurrentUserUtil;
@@ -37,6 +39,9 @@ public class AddDeptService {
@Autowired
private DeptMapper deptMapper;

@Autowired
private UserMapper userMapper;

@Autowired
private RoadDeptMapper roadDeptMapper;

@@ -61,7 +66,7 @@ public class AddDeptService {
dept.setTenantId(tenantId);
dept.setName(addDeptRequest.getName());
dept.setPid(addDeptRequest.getPid());
// dept.setCreateUser(ShiroUtils.getUserId());
dept.setCreateUser(CurrentUserUtil.getUserId());
dept.setCreateTime(DateUtils.now());
Integer rowId = deptMapper.insert(dept);
log.info("新增部门, 返回结果: deptId={}", dept.getId());
@@ -71,6 +76,8 @@ public class AddDeptService {
return JsonResult.error(AddDeptCodeEnum.ADD_DEPT_IS_FAILED.getCode(), AddDeptCodeEnum.ADD_DEPT_IS_FAILED.getMsg());
}

this.updateSuperAdminUser(dept);

// 新增公路/路段与部门数据
addRoadAndSectionToDept(tenantId, dept.getId(), addDeptRequest.getRoadSectionDtoList());

@@ -236,4 +243,21 @@ public class AddDeptService {
}
}

/**
* 如果创建的是顶级部门,将该部门与超级管理员关联
*/
private void updateSuperAdminUser(Dept dept) {
if (!"0".equals(dept.getPid())) {
return;
}
User user = userMapper.selectOne(new LambdaQueryWrapper<User>()
.eq(User::getRoleId, 1)
.eq(User::getMark, 1));
if (ObjectUtil.isNull(user)) {
return;
}
user.setDeptId(dept.getId());
userMapper.updateById(user);
}

}

+ 1
- 1
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/dept/update/UpdateDeptService.java 查看文件

@@ -169,7 +169,7 @@ public class UpdateDeptService {
dept.setTenantId(tenantId);
dept.setName(newEditDeptRequest.getName());
dept.setFullname(newEditDeptRequest.getName());
// dept.setUpdateUser(ShiroUtils.getUserId());
dept.setUpdateUser(CurrentUserUtil.getUserId());
dept.setUpdateTime(DateUtils.now());

Integer rowId = deptMapper.update(dept);

+ 5
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/user/IUserService.java 查看文件

@@ -82,4 +82,9 @@ public interface IUserService {
*/
JsonResult getListByDeptId(String deptId);

/**
* 初始化系统超级管理员用户
*/
JsonResult init(String username);

}

+ 12
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/user/UserServiceImpl.java 查看文件

@@ -5,6 +5,7 @@ import com.tuoheng.admin.request.user.QueryUserPageListRequest;
import com.tuoheng.admin.request.user.UserResetPwdRequest;
import com.tuoheng.admin.service.user.add.AddUserService;
import com.tuoheng.admin.service.user.delete.DeleteUserService;
import com.tuoheng.admin.service.user.init.SystemUserInitService;
import com.tuoheng.admin.service.user.query.QueryUserInfoByIdService;
import com.tuoheng.admin.service.user.query.QueryUserListByDeptIdService;
import com.tuoheng.admin.service.user.query.QueryUserPageListService;
@@ -57,6 +58,9 @@ public class UserServiceImpl implements IUserService {
@Autowired
private QueryUserInfoByIdService queryUserInfoByIdService;

@Autowired
private SystemUserInitService systemUserInitService;

/**
* 获取用户分页列表
*
@@ -145,4 +149,12 @@ public class UserServiceImpl implements IUserService {
return queryUserListByDeptIdService.getListByDeptId(deptId);
}

/**
* 初始化系统超级管理员用户
*/
@Override
public JsonResult init(String username) {
return systemUserInitService.init(username);
}

}

+ 145
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/user/init/SystemUserInitService.java 查看文件

@@ -0,0 +1,145 @@
package com.tuoheng.admin.service.user.init;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tuoheng.admin.constant.SystemConstant;
import com.tuoheng.admin.entity.Dept;
import com.tuoheng.admin.entity.Role;
import com.tuoheng.admin.entity.Tenant;
import com.tuoheng.admin.entity.User;
import com.tuoheng.admin.enums.code.user.AddUserCodeEnum;
import com.tuoheng.admin.mapper.DeptMapper;
import com.tuoheng.admin.mapper.RoleMapper;
import com.tuoheng.admin.mapper.TenantMapper;
import com.tuoheng.admin.mapper.UserMapper;
import com.tuoheng.admin.service.third.oidc.OidcService;
import com.tuoheng.admin.utils.CurrentUserUtil;
import com.tuoheng.common.core.config.common.CommonConfig;
import com.tuoheng.common.core.utils.CommonUtils;
import com.tuoheng.common.core.utils.DateUtils;
import com.tuoheng.common.core.utils.JsonResult;
import com.tuoheng.common.core.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* 初始化系统用户业务层处理
*
* @author wanjing
* @team tuoheng
* @date 2022-12-29
*/
@Slf4j
@Service
public class SystemUserInitService {

@Autowired
private UserMapper userMapper;

@Autowired
private RoleMapper roleMapper;

@Autowired
private TenantMapper tenantMapper;

@Autowired
private OidcService oidcService;

/**
* 添加用户数据
*
* @return
*/
public JsonResult init(String username) {
log.info("进入添加用户业务接口");

Tenant tenant = tenantMapper.selectOne(new LambdaQueryWrapper<Tenant>()
.eq(Tenant::getMark, 1));
String tenantId = "";
if (ObjectUtil.isNotNull(tenant)) {
tenantId = tenant.getId();
}

User user = this.buildUser(username, tenantId);
JsonResult result = this.check(user, tenantId);
if (0 != result.getCode()) {
log.info("初始化系统用户业务接口:校验失败:{}", result.getMsg());
return result;
}

// 添加oidc
result = oidcService.addUser(user, tenant);
if (0 != result.getCode()) {
log.info("初始化系统用户业务接口:添加oidc数据失败:{}", result.getMsg());
return result;
}

Integer rowCount = userMapper.insert(user);
if (rowCount <= 0) {
return JsonResult.error(400, "初始化系统用户失败");
}

return JsonResult.success();
}

/**
*
* 构建实体字段数据
*
*/
private User buildUser(String username, String tenantId) {
if (StringUtils.isEmpty(username)) {
username = "gs";
}
User user = new User();
user.setCode("gs");
user.setUsername(username);
user.setRealname("超级管理员");
user.setNickname("超级管理员");
user.setCityName("");
user.setPassword(CommonUtils.password(SystemConstant.INIT_PASSWORD));
user.setAvatar("imagedir/n1o1j9ndau_1670488066287.png");
user.setClientId("1,2");
user.setRoleId(1);
user.setDeptId("");
user.setStatus(1);
user.setTenantId(tenantId);
user.setCreateUser(CurrentUserUtil.getUserId());
user.setCreateTime(DateUtils.now());
return user;
}

/**
* 检查参数
*
* @param user
* @return
*/
private JsonResult check(User user, String tenantId) {
Integer count = userMapper.selectCount(new LambdaQueryWrapper<User>()
.eq(User::getTenantId, tenantId)
.eq(User::getRoleId, 1)
.eq(User::getMark, 1));
if (count > 0) {
return JsonResult.error(400, "系统中已经存在超级管理员");
}

count = userMapper.selectCount(new LambdaQueryWrapper<User>()
.eq(User::getTenantId, tenantId)
.eq(User::getUsername, user.getUsername())
.eq(User::getMark, 1));
if (count > 0) {
return JsonResult.error(400, "系统中已经存在该用户名");
}
count = roleMapper.selectCount(new LambdaQueryWrapper<Role>()
.eq(Role::getTenantId, tenantId)
.eq(Role::getId, 1)
.eq(Role::getMark, 1));
if (count <= 0) {
return JsonResult.error(400, "该角色不存在");
}
return JsonResult.success();
}

}

Loading…
取消
儲存