Jelajahi Sumber

商家pc端 分权限 第五笔提交

liudongzhi 3 bulan lalu
induk
melakukan
34ded16a7b

+ 2 - 1
alien-store-platform/src/main/java/shop/alien/storeplatform/controller/PlatformOperationLogController.java

@@ -10,6 +10,7 @@ import io.swagger.annotations.ApiSort;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.format.annotation.DateTimeFormat;
+import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
@@ -62,7 +63,7 @@ public class PlatformOperationLogController {
     }
 
     private String resolveModuleName(String module) {
-        if (!org.springframework.util.StringUtils.hasText(module)) {
+        if (!StringUtils.hasText(module)) {
             return null;
         }
         PlatformOperationModule operationModule = PlatformOperationModule.fromCode(module);

+ 14 - 12
alien-store-platform/src/main/java/shop/alien/storeplatform/controller/StorePlatformRoleController.java

@@ -189,22 +189,24 @@ public class StorePlatformRoleController {
         return R.fail("删除失败");
     }
 
-    @ApiOperation("修改角色状态")
+    @ApiOperation("逻辑删除角色")
     @ApiOperationSupport(order = 6)
     @ApiImplicitParams({
-            @ApiImplicitParam(name = "roleId", value = "角色ID", dataType = "Long", paramType = "query", required = true),
-            @ApiImplicitParam(name = "status", value = "角色状态(0正常 1停用)", dataType = "String", paramType = "query", required = true)
+            @ApiImplicitParam(name = "roleId", value = "角色ID", dataType = "Long", paramType = "query", required = true)
     })
-    @PutMapping("/updateStatus")
-    public R<String> updateStatus(
-            @RequestParam("roleId") Long roleId,
-            @RequestParam("status") String status) {
-        log.info("StorePlatformRoleController.updateStatus?roleId={}, status={}", roleId, status);
-        boolean result = storePlatformRoleService.updateStatus(roleId, status);
-        if (result) {
-            return R.success("操作成功");
+    @PlatformOperationLog(
+            module = "角色操作记录",
+            type = "删除角色",
+            content = "删除角色ID=#{#roleId}"
+    )
+    @DeleteMapping("/deleteRoleWithCheck")
+    public R<String> deleteRoleWithCheck(@RequestParam("roleId") Long roleId) {
+        log.info("StorePlatformRoleController.deleteRoleWithCheck?roleId={}", roleId);
+        String errorMsg = storePlatformRoleService.deleteRoleWithCheck(roleId);
+        if (errorMsg == null) {
+            return R.success("删除成功");
         }
-        return R.fail("操作失败");
+        return R.fail(errorMsg);
     }
 
     @ApiOperation("查询所有正常状态的角色列表")

+ 4 - 4
alien-store-platform/src/main/java/shop/alien/storeplatform/service/StorePlatformRoleService.java

@@ -104,13 +104,13 @@ public interface StorePlatformRoleService extends IService<StorePlatformRole> {
     boolean deleteRole(Long roleId);
 
     /**
-     * 修改角色状态
+     * 逻辑删除角色
+     * 如果角色有关联的子账号,则不允许删除
      *
      * @param roleId 角色ID
-     * @param status 角色状态(0正常 1停用)
-     * @return 是否成功
+     * @return 删除结果信息,成功返回null,失败返回错误信息
      */
-    boolean updateStatus(Long roleId, String status);
+    String deleteRoleWithCheck(Long roleId);
 
     /**
      * 查询所有正常状态的角色列表

+ 26 - 9
alien-store-platform/src/main/java/shop/alien/storeplatform/service/impl/StorePlatformRoleServiceImpl.java

@@ -291,22 +291,39 @@ public class StorePlatformRoleServiceImpl extends ServiceImpl<StorePlatformRoleM
     }
 
     @Override
-    public boolean updateStatus(Long roleId, String status) {
+    public String deleteRoleWithCheck(Long roleId) {
         if (roleId == null) {
             log.error("角色ID不能为空");
-            return false;
+            return "角色ID不能为空";
         }
-        if (!StringUtils.hasText(status)) {
-            log.error("角色状态不能为空");
-            return false;
+
+        // 查询角色信息,获取 storeId
+        StorePlatformRole role = storePlatformRoleMapper.selectById(roleId);
+        if (role == null) {
+            log.error("角色不存在: roleId={}", roleId);
+            return "角色不存在";
         }
-        
+
+        // 检查角色是否有关联的子账号
+        List<Integer> userIds = storePlatformUserRoleService.getUserIdsByRoleId(roleId, role.getStoreId());
+        if (userIds != null && !userIds.isEmpty()) {
+            log.warn("角色有关联的子账号,不允许删除: roleId={}, 关联子账号数量={}", roleId, userIds.size());
+            return "该角色下存在关联的子账号,不允许删除";
+        }
+
+        // 执行逻辑删除
         LambdaUpdateWrapper<StorePlatformRole> updateWrapper = new LambdaUpdateWrapper<>();
         updateWrapper.eq(StorePlatformRole::getRoleId, roleId);
-        updateWrapper.set(StorePlatformRole::getStatus, status);
-        
+        updateWrapper.set(StorePlatformRole::getDelFlag, "2"); // 2代表删除
+
         int result = storePlatformRoleMapper.update(null, updateWrapper);
-        return result > 0;
+        if (result > 0) {
+            log.info("角色逻辑删除成功: roleId={}", roleId);
+            return null; // 成功返回null
+        } else {
+            log.error("角色逻辑删除失败: roleId={}", roleId);
+            return "删除失败";
+        }
     }
 
     @Override