feat:生成账号

pg_adapter
wangxy 8 months ago
parent b6409a775e
commit 601c2b5bad

@ -1,13 +1,10 @@
package com.ruoyi.web.controller.system.system;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.exception.file.InvalidExtensionException;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.common.utils.file.MimeTypeUtils;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.extra.pinyin.PinyinUtil;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
@ -40,13 +37,12 @@ import com.ruoyi.system.service.ISysUserService;
/**
*
*
*
* @author ruoyi
*/
@Controller
@RequestMapping("/system/user")
public class SysUserController extends BaseController
{
public class SysUserController extends BaseController {
private static final Logger log = LoggerFactory.getLogger(SysUserController.class);
private String prefix = "system/user";
@ -55,7 +51,7 @@ public class SysUserController extends BaseController
@Autowired
private ISysRoleService roleService;
@Autowired
private ISysDeptService deptService;
@ -67,16 +63,14 @@ public class SysUserController extends BaseController
@RequiresPermissions("system:user:view")
@GetMapping()
public String user()
{
public String user() {
return prefix + "/user";
}
@RequiresPermissions("system:user:list")
@PostMapping("/list")
@ResponseBody
public TableDataInfo list(SysUser user)
{
public TableDataInfo list(SysUser user) {
startPage();
List<SysUser> list = userService.selectUserList(user);
return getDataTable(list);
@ -86,8 +80,7 @@ public class SysUserController extends BaseController
@RequiresPermissions("system:user:export")
@PostMapping("/export")
@ResponseBody
public AjaxResult export(SysUser user)
{
public AjaxResult export(SysUser user) {
List<SysUser> list = userService.selectUserList(user);
ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
return util.exportExcel(list, "用户数据");
@ -97,8 +90,7 @@ public class SysUserController extends BaseController
@RequiresPermissions("system:user:import")
@PostMapping("/importData")
@ResponseBody
public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
{
public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
List<SysUser> userList = util.importExcel(file.getInputStream());
String message = userService.importUser(userList, updateSupport, getLoginName());
@ -108,8 +100,7 @@ public class SysUserController extends BaseController
@RequiresPermissions("system:user:view")
@GetMapping("/importTemplate")
@ResponseBody
public AjaxResult importTemplate()
{
public AjaxResult importTemplate() {
ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
return util.importTemplateExcel("用户数据");
}
@ -118,8 +109,7 @@ public class SysUserController extends BaseController
*
*/
@GetMapping("/add")
public String add(ModelMap mmap)
{
public String add(ModelMap mmap) {
mmap.put("roles", roleService.selectRoleAll().stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
mmap.put("posts", postService.selectPostAll());
return prefix + "/add";
@ -132,17 +122,12 @@ public class SysUserController extends BaseController
@Log(title = "用户管理", businessType = BusinessType.INSERT)
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(@Validated SysUser user) {
if (!userService.checkLoginNameUnique(user))
{
public AjaxResult addSave(@Validated SysUser user) {
if (!userService.checkLoginNameUnique(user)) {
return error("新增用户'" + user.getLoginName() + "'失败,登录账号已存在");
}
else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user))
{
} else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) {
return error("新增用户'" + user.getLoginName() + "'失败,手机号码已存在");
}
else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user))
{
} else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) {
return error("新增用户'" + user.getLoginName() + "'失败,邮箱账号已存在");
}
user.setSalt(ShiroUtils.randomSalt());
@ -156,8 +141,7 @@ public class SysUserController extends BaseController
*/
@RequiresPermissions("system:user:edit")
@GetMapping("/edit/{userId}")
public String edit(@PathVariable("userId") Long userId, ModelMap mmap)
{
public String edit(@PathVariable("userId") Long userId, ModelMap mmap) {
userService.checkUserDataScope(userId);
List<SysRole> roles = roleService.selectRolesByUserId(userId);
mmap.put("user", userService.selectUserById(userId));
@ -173,20 +157,14 @@ public class SysUserController extends BaseController
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(@Validated SysUser user)
{
public AjaxResult editSave(@Validated SysUser user) {
userService.checkUserAllowed(user);
userService.checkUserDataScope(user.getUserId());
if (!userService.checkLoginNameUnique(user))
{
if (!userService.checkLoginNameUnique(user)) {
return error("修改用户'" + user.getLoginName() + "'失败,登录账号已存在");
}
else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user))
{
} else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) {
return error("修改用户'" + user.getLoginName() + "'失败,手机号码已存在");
}
else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user))
{
} else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) {
return error("修改用户'" + user.getLoginName() + "'失败,邮箱账号已存在");
}
user.setUpdateBy(getLoginName());
@ -196,8 +174,7 @@ public class SysUserController extends BaseController
@RequiresPermissions("system:user:resetPwd")
@GetMapping("/resetPwd/{userId}")
public String resetPwd(@PathVariable("userId") Long userId, ModelMap mmap)
{
public String resetPwd(@PathVariable("userId") Long userId, ModelMap mmap) {
mmap.put("user", userService.selectUserById(userId));
return prefix + "/resetPwd";
}
@ -206,16 +183,13 @@ public class SysUserController extends BaseController
@Log(title = "重置密码", businessType = BusinessType.RESET)
@PostMapping("/resetPwd")
@ResponseBody
public AjaxResult resetPwdSave(SysUser user)
{
public AjaxResult resetPwdSave(SysUser user) {
userService.checkUserAllowed(user);
userService.checkUserDataScope(user.getUserId());
user.setSalt(ShiroUtils.randomSalt());
user.setPassword(passwordService.encryptPassword(user.getLoginName(), user.getPassword(), user.getSalt()));
if (userService.resetUserPwd(user) > 0)
{
if (ShiroUtils.getUserId().longValue() == user.getUserId().longValue())
{
if (userService.resetUserPwd(user) > 0) {
if (ShiroUtils.getUserId().longValue() == user.getUserId().longValue()) {
setSysUser(userService.selectUserById(user.getUserId()));
}
return success();
@ -227,8 +201,7 @@ public class SysUserController extends BaseController
*
*/
@GetMapping("/authRole/{userId}")
public String authRole(@PathVariable("userId") Long userId, ModelMap mmap)
{
public String authRole(@PathVariable("userId") Long userId, ModelMap mmap) {
SysUser user = userService.selectUserById(userId);
// 获取用户所属的角色列表
List<SysRole> roles = roleService.selectRolesByUserId(userId);
@ -244,8 +217,7 @@ public class SysUserController extends BaseController
@Log(title = "用户管理", businessType = BusinessType.GRANT)
@PostMapping("/authRole/insertAuthRole")
@ResponseBody
public AjaxResult insertAuthRole(Long userId, Long[] roleIds)
{
public AjaxResult insertAuthRole(Long userId, Long[] roleIds) {
userService.checkUserDataScope(userId);
userService.insertUserAuth(userId, roleIds);
AuthorizationUtils.clearAllCachedAuthorizationInfo();
@ -256,10 +228,8 @@ public class SysUserController extends BaseController
@Log(title = "用户管理", businessType = BusinessType.DELETE)
@PostMapping("/remove")
@ResponseBody
public AjaxResult remove(String ids)
{
if (ArrayUtils.contains(Convert.toLongArray(ids), getUserId()))
{
public AjaxResult remove(String ids) {
if (ArrayUtils.contains(Convert.toLongArray(ids), getUserId())) {
return error("当前用户不能删除");
}
return toAjax(userService.deleteUserByIds(ids));
@ -270,8 +240,7 @@ public class SysUserController extends BaseController
*/
@PostMapping("/checkLoginNameUnique")
@ResponseBody
public boolean checkLoginNameUnique(SysUser user)
{
public boolean checkLoginNameUnique(SysUser user) {
return userService.checkLoginNameUnique(user);
}
@ -280,8 +249,7 @@ public class SysUserController extends BaseController
*/
@PostMapping("/checkPhoneUnique")
@ResponseBody
public boolean checkPhoneUnique(SysUser user)
{
public boolean checkPhoneUnique(SysUser user) {
return userService.checkPhoneUnique(user);
}
@ -290,8 +258,7 @@ public class SysUserController extends BaseController
*/
@PostMapping("/checkEmailUnique")
@ResponseBody
public boolean checkEmailUnique(SysUser user)
{
public boolean checkEmailUnique(SysUser user) {
return userService.checkEmailUnique(user);
}
@ -302,8 +269,7 @@ public class SysUserController extends BaseController
@RequiresPermissions("system:user:edit")
@PostMapping("/changeStatus")
@ResponseBody
public AjaxResult changeStatus(SysUser user)
{
public AjaxResult changeStatus(SysUser user) {
userService.checkUserAllowed(user);
userService.checkUserDataScope(user.getUserId());
return toAjax(userService.changeStatus(user));
@ -315,25 +281,38 @@ public class SysUserController extends BaseController
@RequiresPermissions("system:user:list")
@GetMapping("/deptTreeData")
@ResponseBody
public List<Ztree> deptTreeData()
{
public List<Ztree> deptTreeData() {
List<Ztree> ztrees = deptService.selectDeptTree(new SysDept());
return ztrees;
}
/**
*
*
*
* @param deptId ID
*/
@RequiresPermissions("system:user:list")
@GetMapping("/selectDeptTree/{deptId}")
public String selectDeptTree(@PathVariable("deptId") Long deptId, ModelMap mmap)
{
public String selectDeptTree(@PathVariable("deptId") Long deptId, ModelMap mmap) {
mmap.put("dept", deptService.selectDeptById(deptId));
return prefix + "/deptTree";
}
@GetMapping("/getPinyin")
@ResponseBody
public AjaxResult getPinyin(@RequestParam String name) {
return AjaxResult.success(getFirstLetter(name));
}
/**
*
*
* @param columnName
* @return java.lang.String
*/
public String getFirstLetter(String columnName) {
return PinyinUtil.getFirstLetter(columnName, "") + RandomUtil.randomNumbers(4);
}
}

@ -122,6 +122,12 @@
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>com.belerweb</groupId>
<artifactId>pinyin4j</artifactId>
<version>2.5.1</version>
</dependency>
</dependencies>

Loading…
Cancel
Save