Browse Source

修改商户无法创建人员
修改创建人员角色回显问题

gaohp 6 months ago
parent
commit
1a32247a20

+ 3 - 1
feifan-module-system/feifan-module-system-biz/src/main/java/cn/newfeifan/mall/module/system/controller/admin/user/UserController.java

@@ -34,6 +34,7 @@ import java.util.Map;
 import static cn.newfeifan.mall.framework.common.pojo.CommonResult.success;
 import static cn.newfeifan.mall.framework.common.util.collection.CollectionUtils.convertList;
 import static cn.newfeifan.mall.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
+import static cn.newfeifan.mall.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
 
 @Tag(name = "管理后台 - 用户")
 @RestController
@@ -50,7 +51,8 @@ public class UserController {
     @Operation(summary = "新增用户")
     @PreAuthorize("@ss.hasPermission('system:user:create')")
     public CommonResult<Long> createUser(@Valid @RequestBody UserSaveReqVO reqVO) {
-        Long id = userService.createUser(reqVO);
+        Long loginUserId = getLoginUserId();
+        Long id = userService.createUser(reqVO,loginUserId);
         return success(id);
     }
 

+ 1 - 1
feifan-module-system/feifan-module-system-biz/src/main/java/cn/newfeifan/mall/module/system/service/tenant/TenantServiceImpl.java

@@ -121,7 +121,7 @@ public class TenantServiceImpl implements TenantService {
 
     private Long createUser(Long roleId, TenantSaveReqVO createReqVO) {
         // 创建用户
-        Long userId = userService.createUser(TenantConvert.INSTANCE.convert02(createReqVO));
+        Long userId = userService.createUser(TenantConvert.INSTANCE.convert02(createReqVO), null);
         // 分配角色
         permissionService.assignUserRole(userId, singleton(roleId));
         return userId;

+ 1 - 1
feifan-module-system/feifan-module-system-biz/src/main/java/cn/newfeifan/mall/module/system/service/user/AdminUserService.java

@@ -25,7 +25,7 @@ public interface AdminUserService {
      * @param createReqVO 用户信息
      * @return 用户编号
      */
-    Long createUser(@Valid UserSaveReqVO createReqVO);
+    Long createUser(@Valid UserSaveReqVO createReqVO, Long loginUserId);
 
     /**
      * 修改用户

+ 16 - 5
feifan-module-system/feifan-module-system-biz/src/main/java/cn/newfeifan/mall/module/system/service/user/AdminUserServiceImpl.java

@@ -8,6 +8,7 @@ import cn.newfeifan.mall.framework.common.enums.CommonStatusEnum;
 import cn.newfeifan.mall.framework.common.exception.ServiceException;
 import cn.newfeifan.mall.framework.common.pojo.PageResult;
 import cn.newfeifan.mall.framework.common.util.collection.CollectionUtils;
+import cn.newfeifan.mall.framework.common.util.json.JsonUtils;
 import cn.newfeifan.mall.framework.common.util.object.BeanUtils;
 import cn.newfeifan.mall.framework.datapermission.core.util.DataPermissionUtils;
 import cn.newfeifan.mall.module.infra.api.file.FileApi;
@@ -91,10 +92,9 @@ public class AdminUserServiceImpl implements AdminUserService {
     private StringRedisTemplate stringRedisTemplate;
 
 
-
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public Long createUser(UserSaveReqVO createReqVO) {
+    public Long createUser(UserSaveReqVO createReqVO, Long loginUserId) {
         // 校验账户配合
         tenantService.handleTenantInfo(tenant -> {
             long count = userMapper.selectCount();
@@ -105,10 +105,21 @@ public class AdminUserServiceImpl implements AdminUserService {
         // 校验正确性
         validateUserForCreateOrUpdate(null, createReqVO.getUsername(),
                 createReqVO.getMobile(), createReqVO.getEmail(), createReqVO.getDeptId(), createReqVO.getPostIds());
+
+        if (createReqVO.getMerchantId() == null || createReqVO.getShopId() == null && loginUserId != null) {
+            Map shopMessage = JsonUtils.parseObject(stringRedisTemplate.opsForValue().get("shop:" + loginUserId), Map.class);
+            if (shopMessage != null) {
+                createReqVO.setShopId(Long.valueOf(String.valueOf(shopMessage.get("shopId"))));
+                createReqVO.setMerchantId(Long.valueOf(String.valueOf(shopMessage.get("merId"))));
+            }
+        }
+
+
         // 插入用户
         AdminUserDO user = BeanUtils.toBean(createReqVO, AdminUserDO.class);
         user.setStatus(CommonStatusEnum.ENABLE.getStatus()); // 默认开启
         user.setPassword(encodePassword(createReqVO.getPassword())); // 加密密码
+
         userMapper.insert(user);
         // 插入关联岗位
         if (CollectionUtil.isNotEmpty(user.getPostIds())) {
@@ -503,7 +514,7 @@ public class AdminUserServiceImpl implements AdminUserService {
                 .shopId(shopId)
                 .merchantId(merId)
                 .build();
-        createUser(build);
+        createUser(build, null);
     }
 
     @Override
@@ -521,10 +532,10 @@ public class AdminUserServiceImpl implements AdminUserService {
             UserShopDetailsVO userShopDetailsVO = new UserShopDetailsVO();
             userShopDetailsVO.setShopId(adminUserDO.getShopId());
             userShopDetailsVO.setMerchantId(adminUserDO.getMerchantId());
-            log.info("====userShopDetailsVO:{}",userShopDetailsVO);
+            log.info("====userShopDetailsVO:{}", userShopDetailsVO);
             return userShopDetailsVO;
         } else {
-            log.info("====userShopDetailsVO:{}",s);
+            log.info("====userShopDetailsVO:{}", s);
             return JSONObject.parseObject(s, UserShopDetailsVO.class);
         }
     }