于俊龙 1 week ago
parent
commit
8b6508b44a

+ 33 - 23
farm-crm/src/main/java/jp/yamoto/farm/crm/web/controller/system/SysUserController.java

@@ -10,9 +10,8 @@ import jp.yamoto.farm.common.core.domain.entity.SysRole;
 import jp.yamoto.farm.common.core.domain.entity.SysUser;
 import jp.yamoto.farm.common.core.domain.entity.SysUser;
 import jp.yamoto.farm.common.core.page.TableDataInfo;
 import jp.yamoto.farm.common.core.page.TableDataInfo;
 import jp.yamoto.farm.common.enums.BusinessType;
 import jp.yamoto.farm.common.enums.BusinessType;
-import jp.yamoto.farm.common.utils.ConvertUtils;
-import jp.yamoto.farm.common.utils.SecurityUtils;
-import jp.yamoto.farm.common.utils.StringUtils;
+import jp.yamoto.farm.common.exception.ServiceException;
+import jp.yamoto.farm.common.utils.*;
 import jp.yamoto.farm.common.utils.poi.ExcelUtil;
 import jp.yamoto.farm.common.utils.poi.ExcelUtil;
 import jp.yamoto.farm.common.validator.utils.ValidatorGroup;
 import jp.yamoto.farm.common.validator.utils.ValidatorGroup;
 import jp.yamoto.farm.crm.biz.sys.service.ISysRoleService;
 import jp.yamoto.farm.crm.biz.sys.service.ISysRoleService;
@@ -49,7 +48,7 @@ public class SysUserController extends BaseController
     /**
     /**
      * ユーザーリストの取得
      * ユーザーリストの取得
      */
      */
-    @PreAuthorize("@ss.hasPermi('system:user:list')")
+    @PreAuthorize("@ss.hasPermi('system:user')")
     @GetMapping("/list")
     @GetMapping("/list")
     public TableDataInfo list(SysUser user)
     public TableDataInfo list(SysUser user)
     {
     {
@@ -59,7 +58,7 @@ public class SysUserController extends BaseController
     }
     }
 
 
     @Log(title = "ユーザー管理", businessType = BusinessType.EXPORT)
     @Log(title = "ユーザー管理", businessType = BusinessType.EXPORT)
-    @PreAuthorize("@ss.hasPermi('system:user:export')")
+    @PreAuthorize("@ss.hasPermi('system:user')")
     @PostMapping("/export")
     @PostMapping("/export")
     public void export(HttpServletResponse response, SysUser user)
     public void export(HttpServletResponse response, SysUser user)
     {
     {
@@ -69,7 +68,7 @@ public class SysUserController extends BaseController
     }
     }
 
 
     @Log(title = "ユーザー管理", businessType = BusinessType.IMPORT)
     @Log(title = "ユーザー管理", businessType = BusinessType.IMPORT)
-    @PreAuthorize("@ss.hasPermi('system:user:import')")
+    @PreAuthorize("@ss.hasPermi('system:user')")
     @PostMapping("/importData")
     @PostMapping("/importData")
     public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
     public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
     {
     {
@@ -90,19 +89,22 @@ public class SysUserController extends BaseController
     /**
     /**
      * ユーザー番号による詳細の取得
      * ユーザー番号による詳細の取得
      */
      */
-    @PreAuthorize("@ss.hasPermi('system:user:query')")
-    @GetMapping(value = { "/", "/{userId}" })
+    @PreAuthorize("@ss.hasPermi('system:user')")
+    @GetMapping("/info/{userId}")
     public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId)
     public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId)
     {
     {
         userService.checkUserDataScope(userId);
         userService.checkUserDataScope(userId);
         AjaxResult ajax = AjaxResult.success();
         AjaxResult ajax = AjaxResult.success();
-        List<SysRole> roles = roleService.selectRoleAll();
-        ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
+        List<SysRole> roles = roleService.selectRolesByUserId(userId);
+        //ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
         if (StringUtils.isNotNull(userId))
         if (StringUtils.isNotNull(userId))
         {
         {
             SysUser sysUser = userService.selectUserById(userId);
             SysUser sysUser = userService.selectUserById(userId);
+            if(ValueUtils.isNotEmpty(sysUser.getRoles())) {
+                sysUser.setRoleId(sysUser.getRoles().getFirst().getRoleId());
+            }
             ajax.put(AjaxResult.DATA_TAG, sysUser);
             ajax.put(AjaxResult.DATA_TAG, sysUser);
-            ajax.put("roleIds", sysUser.getRoles().stream().map(SysRole::getRoleId).collect(Collectors.toList()));
+            //ajax.put("roleIds", sysUser.getRoles().stream().map(SysRole::getRoleId).collect(Collectors.toList()));
         }
         }
         return ajax;
         return ajax;
     }
     }
@@ -110,7 +112,7 @@ public class SysUserController extends BaseController
     /**
     /**
      * 新規ユーザー
      * 新規ユーザー
      */
      */
-    @PreAuthorize("@ss.hasPermi('system:user:add')")
+    @PreAuthorize("@ss.hasPermi('system:user')")
     @Log(title = "ユーザー管理", businessType = BusinessType.INSERT)
     @Log(title = "ユーザー管理", businessType = BusinessType.INSERT)
     @PostMapping("/add")
     @PostMapping("/add")
     public AjaxResult add(@RequestBody @Validated({ValidatorGroup.AddGroup.class}) SysUser user)
     public AjaxResult add(@RequestBody @Validated({ValidatorGroup.AddGroup.class}) SysUser user)
@@ -135,14 +137,19 @@ public class SysUserController extends BaseController
     /**
     /**
      * ユーザーの変更
      * ユーザーの変更
      */
      */
-    @PreAuthorize("@ss.hasPermi('system:user:edit')")
+    @PreAuthorize("@ss.hasPermi('system:user')")
     @Log(title = "ユーザー管理", businessType = BusinessType.UPDATE)
     @Log(title = "ユーザー管理", businessType = BusinessType.UPDATE)
     @PostMapping("/update")
     @PostMapping("/update")
     public AjaxResult edit(@Validated @RequestBody SysUser user)
     public AjaxResult edit(@Validated @RequestBody SysUser user)
     {
     {
         userService.checkUserAllowed(user);
         userService.checkUserAllowed(user);
-        userService.checkUserDataScope(user.getUserId());
-        roleService.checkRoleDataScope(user.getRoleIds());
+        //userService.checkUserDataScope(user.getUserId());
+        if(ValueUtils.isNotEmpty(user.getRoleIds())){
+            roleService.checkRoleDataScope(user.getRoleIds());
+        } else {
+            roleService.checkRoleDataScope(user.getRoleId());
+        }
+
         if (!userService.checkUserNameUnique(user))
         if (!userService.checkUserNameUnique(user))
         {
         {
             return error("ユーザーの変更'" + user.getUserName() + "'失敗しました。ログインアカウントは既に存在します");
             return error("ユーザーの変更'" + user.getUserName() + "'失敗しました。ログインアカウントは既に存在します");
@@ -162,7 +169,7 @@ public class SysUserController extends BaseController
     /**
     /**
      * ユーザーの削除
      * ユーザーの削除
      */
      */
-    @PreAuthorize("@ss.hasPermi('system:user:remove')")
+    @PreAuthorize("@ss.hasPermi('system:user')")
     @Log(title = "ユーザー管理", businessType = BusinessType.DELETE)
     @Log(title = "ユーザー管理", businessType = BusinessType.DELETE)
     @DeleteMapping("/{userIds}")
     @DeleteMapping("/{userIds}")
     public AjaxResult remove(@PathVariable Long[] userIds)
     public AjaxResult remove(@PathVariable Long[] userIds)
@@ -177,11 +184,14 @@ public class SysUserController extends BaseController
     /**
     /**
      * パスワードをリセット
      * パスワードをリセット
      */
      */
-    @PreAuthorize("@ss.hasPermi('system:user:resetPwd')")
+    @PreAuthorize("@ss.hasPermi('system:user')")
     @Log(title = "ユーザー管理", businessType = BusinessType.UPDATE)
     @Log(title = "ユーザー管理", businessType = BusinessType.UPDATE)
-    @PutMapping("/resetPwd")
+    @PostMapping("/resetPwd")
     public AjaxResult resetPwd(@RequestBody SysUser user)
     public AjaxResult resetPwd(@RequestBody SysUser user)
     {
     {
+        if(ValueUtils.isEmpty(user.getPassword())){
+            throw new ServiceException(MessageUtils.message("E0003", MessageUtils.message("label.password")));
+        }
         userService.checkUserAllowed(user);
         userService.checkUserAllowed(user);
         userService.checkUserDataScope(user.getUserId());
         userService.checkUserDataScope(user.getUserId());
         user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
         user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
@@ -192,9 +202,9 @@ public class SysUserController extends BaseController
     /**
     /**
      * ステータスの変更
      * ステータスの変更
      */
      */
-    @PreAuthorize("@ss.hasPermi('system:user:edit')")
+    @PreAuthorize("@ss.hasPermi('system:user')")
     @Log(title = "ユーザー管理", businessType = BusinessType.UPDATE)
     @Log(title = "ユーザー管理", businessType = BusinessType.UPDATE)
-    @PutMapping("/changeStatus")
+    @PostMapping("/changeStatus")
     public AjaxResult changeStatus(@RequestBody SysUser user)
     public AjaxResult changeStatus(@RequestBody SysUser user)
     {
     {
         userService.checkUserAllowed(user);
         userService.checkUserAllowed(user);
@@ -206,7 +216,7 @@ public class SysUserController extends BaseController
     /**
     /**
      * ユーザー番号に基づいた権限ロールの取得
      * ユーザー番号に基づいた権限ロールの取得
      */
      */
-    @PreAuthorize("@ss.hasPermi('system:user:query')")
+    @PreAuthorize("@ss.hasPermi('system:user')")
     @GetMapping("/authRole/{userId}")
     @GetMapping("/authRole/{userId}")
     public AjaxResult authRole(@PathVariable("userId") Long userId)
     public AjaxResult authRole(@PathVariable("userId") Long userId)
     {
     {
@@ -221,9 +231,9 @@ public class SysUserController extends BaseController
     /**
     /**
      * ユーザー権限ロール
      * ユーザー権限ロール
      */
      */
-    @PreAuthorize("@ss.hasPermi('system:user:edit')")
+    @PreAuthorize("@ss.hasPermi('system:user')")
     @Log(title = "ユーザー管理", businessType = BusinessType.GRANT)
     @Log(title = "ユーザー管理", businessType = BusinessType.GRANT)
-    @PutMapping("/authRole")
+    @PostMapping("/authRole")
     public AjaxResult insertAuthRole(Long userId, Long[] roleIds) {
     public AjaxResult insertAuthRole(Long userId, Long[] roleIds) {
         userService.checkUserDataScope(userId);
         userService.checkUserDataScope(userId);
         roleService.checkRoleDataScope(roleIds);
         roleService.checkRoleDataScope(roleIds);