|
@@ -0,0 +1,115 @@
|
|
|
+package com.ruoyi.system.controller;
|
|
|
+
|
|
|
+import com.ruoyi.common.core.domain.R;
|
|
|
+import com.ruoyi.common.core.utils.StringUtils;
|
|
|
+import com.ruoyi.common.core.web.controller.BaseController;
|
|
|
+import com.ruoyi.common.core.web.domain.AjaxResult;
|
|
|
+import com.ruoyi.common.log.annotation.Log;
|
|
|
+import com.ruoyi.common.log.enums.BusinessType;
|
|
|
+import com.ruoyi.common.security.annotation.InnerAuth;
|
|
|
+import com.ruoyi.common.security.utils.SecurityUtils;
|
|
|
+import com.ruoyi.system.api.domain.SysRole;
|
|
|
+import com.ruoyi.system.api.domain.SysUser;
|
|
|
+import com.ruoyi.system.service.ISysDeptService;
|
|
|
+import com.ruoyi.system.service.ISysRoleService;
|
|
|
+import com.ruoyi.system.service.ISysUserService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 用户信息
|
|
|
+ *
|
|
|
+ * @author ruoyi
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/userFeign")
|
|
|
+public class SysUserControllerFeign extends BaseController {
|
|
|
+ @Autowired
|
|
|
+ private ISysUserService userService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysDeptService deptService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 注册用户信息
|
|
|
+ */
|
|
|
+ @InnerAuth
|
|
|
+ @PostMapping("/register")
|
|
|
+ @Log(title = "用户信息修改", businessType = BusinessType.INSERT)
|
|
|
+ public R<Boolean> register(@RequestBody SysUser sysUser) {
|
|
|
+ String username = sysUser.getUserName();
|
|
|
+
|
|
|
+ if (!userService.checkUserNameUnique(sysUser)) {
|
|
|
+ return R.fail("保存用户'" + username + "'失败,注册账号已存在");
|
|
|
+ }
|
|
|
+ sysUser.setDept(deptService.selectDeptById(sysUser.getDeptId()));
|
|
|
+ boolean ret = userService.registerUserWithRole(sysUser);
|
|
|
+ if (!ret) {
|
|
|
+ return R.fail("用户" + username + "注册失败");
|
|
|
+ }
|
|
|
+ return R.ok(true, "用户" + username + "注册成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取用户信息
|
|
|
+ *
|
|
|
+ * @return 用户信息
|
|
|
+ */
|
|
|
+ @InnerAuth
|
|
|
+ @GetMapping("getInfo")
|
|
|
+ public AjaxResult getInfo() {
|
|
|
+ SysUser user = userService.selectUserById(SecurityUtils.getUserId());
|
|
|
+ AjaxResult ajax = AjaxResult.success();
|
|
|
+ ajax.put("user", user);
|
|
|
+ return ajax;
|
|
|
+ }
|
|
|
+
|
|
|
+ @InnerAuth
|
|
|
+ @GetMapping("/{userId}")
|
|
|
+ public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId) {
|
|
|
+ userService.checkUserDataScope(userId);
|
|
|
+ AjaxResult ajax = AjaxResult.success();
|
|
|
+ if (StringUtils.isNotNull(userId)) {
|
|
|
+ SysUser sysUser = userService.selectUserById(userId);
|
|
|
+ ajax.put(AjaxResult.DATA_TAG, sysUser);
|
|
|
+ }
|
|
|
+ return ajax;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改用户
|
|
|
+ */
|
|
|
+ @Log(title = "用户信息修改", businessType = BusinessType.UPDATE)
|
|
|
+ @PutMapping
|
|
|
+ public AjaxResult edit(@Validated @RequestBody SysUser user) {
|
|
|
+ userService.checkUserAllowed(user);
|
|
|
+ userService.checkUserDataScope(user.getUserId());
|
|
|
+ if (user.getDeptId() != null || user.getRoleId() != null) {
|
|
|
+ return error("修改用户'" + user.getUserName() + "'失败,用户类型不可修改");
|
|
|
+ } else if (!userService.checkUserNameUnique(user)) {
|
|
|
+ return error("修改用户'" + user.getUserName() + "'失败,登录账号已存在");
|
|
|
+ } else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) {
|
|
|
+ return error("修改用户'" + user.getUserName() + "'失败,手机号码已存在");
|
|
|
+ } else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) {
|
|
|
+ return error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
|
|
|
+ }
|
|
|
+ user.setUpdateBy(SecurityUtils.getUsername());
|
|
|
+ return toAjax(userService.updateUser(user));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 重置密码
|
|
|
+ */
|
|
|
+ @PutMapping("/resetPwd")
|
|
|
+ public AjaxResult resetPwd(@RequestBody SysUser user) {
|
|
|
+ userService.checkUserAllowed(user);
|
|
|
+ userService.checkUserDataScope(user.getUserId());
|
|
|
+ user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
|
|
|
+ user.setUpdateBy(SecurityUtils.getUsername());
|
|
|
+ return toAjax(userService.resetPwd(user));
|
|
|
+ }
|
|
|
+}
|