Browse Source

修改子账号列表以及子账号禁用

liudongzhi 2 months ago
parent
commit
5866a02b54

+ 19 - 12
alien-store-platform/src/main/java/shop/alien/storeplatform/controller/StorePlatformUserRoleController.java

@@ -248,7 +248,7 @@ public class StorePlatformUserRoleController {
     @ApiImplicitParams({
     @ApiImplicitParams({
             @ApiImplicitParam(name = "pageNum", value = "页码", dataType = "int", paramType = "query", required = false, defaultValue = "1"),
             @ApiImplicitParam(name = "pageNum", value = "页码", dataType = "int", paramType = "query", required = false, defaultValue = "1"),
             @ApiImplicitParam(name = "pageSize", value = "每页大小", dataType = "int", paramType = "query", required = false, defaultValue = "10"),
             @ApiImplicitParam(name = "pageSize", value = "每页大小", dataType = "int", paramType = "query", required = false, defaultValue = "10"),
-            @ApiImplicitParam(name = "accountId", value = "账号ID(主账号ID或子账号用户ID,模糊查询)", dataType = "String", paramType = "query", required = false),
+            @ApiImplicitParam(name = "mainAccountId", value = "账号ID(主账号ID或子账号用户ID,模糊查询)", dataType = "String", paramType = "query", required = false),
             @ApiImplicitParam(name = "phone", value = "联系电话(子账号电话,模糊查询)", dataType = "String", paramType = "query", required = false),
             @ApiImplicitParam(name = "phone", value = "联系电话(子账号电话,模糊查询)", dataType = "String", paramType = "query", required = false),
             @ApiImplicitParam(name = "status", value = "状态(0:启用 1:禁用)", dataType = "int", paramType = "query", required = false)
             @ApiImplicitParam(name = "status", value = "状态(0:启用 1:禁用)", dataType = "int", paramType = "query", required = false)
     })
     })
@@ -256,12 +256,12 @@ public class StorePlatformUserRoleController {
     public R<IPage<SubAccountListVo>> queryAllSubAccounts(
     public R<IPage<SubAccountListVo>> queryAllSubAccounts(
             @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
             @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
             @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
             @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
-            @RequestParam(value = "accountId", required = false) String accountId,
+            @RequestParam(value = "mainAccountId", required = false) String mainAccountId,
             @RequestParam(value = "phone", required = false) String phone,
             @RequestParam(value = "phone", required = false) String phone,
             @RequestParam(value = "status", required = false) Integer status) {
             @RequestParam(value = "status", required = false) Integer status) {
-        log.info("StorePlatformUserRoleController.queryAllSubAccounts?pageNum={}, pageSize={}, accountId={}, phone={}, status={}", 
-                pageNum, pageSize, accountId, phone, status);
-        IPage<SubAccountListVo> subAccountPage = storePlatformUserRoleService.queryAllSubAccounts(pageNum, pageSize, accountId, phone, status);
+        log.info("StorePlatformUserRoleController.queryAllSubAccounts?pageNum={}, pageSize={}, mainAccountId={}, phone={}, status={}",
+                pageNum, pageSize, mainAccountId, phone, status);
+        IPage<SubAccountListVo> subAccountPage = storePlatformUserRoleService.queryAllSubAccounts(pageNum, pageSize, mainAccountId, phone, status);
         return R.data(subAccountPage);
         return R.data(subAccountPage);
     }
     }
 
 
@@ -273,21 +273,28 @@ public class StorePlatformUserRoleController {
             content = "禁用子账号(关联记录ID=#{#id})"
             content = "禁用子账号(关联记录ID=#{#id})"
     )
     )
     @ApiImplicitParams({
     @ApiImplicitParams({
-            @ApiImplicitParam(name = "id", value = "子账号关联记录的主键ID", dataType = "Long", paramType = "query", required = true)
+            @ApiImplicitParam(name = "id", value = "子账号关联记录的主键ID", dataType = "Long", paramType = "query", required = true),
+            @ApiImplicitParam(name = "status", value = "状态标志(0启用 1禁用)", dataType = "Integer", paramType = "query", required = true)
     })
     })
-    @PostMapping("/disableSubAccount")
-    public R<String> disableSubAccount(@RequestParam("id") Long id) {
-        log.info("StorePlatformUserRoleController.disableSubAccount?id={}", id);
+    @GetMapping("/disableSubAccount")
+    public R<String> disableSubAccount(@RequestParam("id") Long id, @RequestParam("status") Integer status) {
+        log.info("StorePlatformUserRoleController.disableSubAccount?id={}, status={}", id, status);
         
         
         if (id == null) {
         if (id == null) {
             return R.fail("子账号关联记录ID不能为空");
             return R.fail("子账号关联记录ID不能为空");
         }
         }
         
         
-        boolean result = storePlatformUserRoleService.disableSubAccount(id);
+        if (status == null || (status != 0 && status != 1)) {
+            return R.fail("状态参数必须为0(启用)或1(禁用)");
+        }
+        
+        boolean result = storePlatformUserRoleService.disableSubAccount(id, status);
         if (result) {
         if (result) {
-            return R.success("禁用子账号成功");
+            String message = status == 0 ? "启用子账号成功" : "禁用子账号成功";
+            return R.success(message);
         }
         }
-        return R.fail("禁用子账号失败");
+        String message = status == 0 ? "启用子账号失败" : "禁用子账号失败";
+        return R.fail(message);
     }
     }
 
 
 }
 }

+ 7 - 5
alien-store-platform/src/main/java/shop/alien/storeplatform/service/StorePlatformUserRoleService.java

@@ -131,20 +131,22 @@ public interface StorePlatformUserRoleService extends IService<StorePlatformUser
      *
      *
      * @param pageNum   页码
      * @param pageNum   页码
      * @param pageSize  每页大小
      * @param pageSize  每页大小
-     * @param accountId 账号ID(主账号ID或子账号用户ID,模糊查询)
+     * @param mainAccountId 账号ID(主账号ID或子账号用户ID,模糊查询)
      * @param phone     联系电话(子账号电话,模糊查询)
      * @param phone     联系电话(子账号电话,模糊查询)
      * @param status    状态(精确查询)
      * @param status    状态(精确查询)
      * @return 子账号分页列表
      * @return 子账号分页列表
      */
      */
-    IPage<SubAccountListVo> queryAllSubAccounts(Integer pageNum, Integer pageSize, String accountId, String phone, Integer status);
+    IPage<SubAccountListVo> queryAllSubAccounts(Integer pageNum, Integer pageSize, String mainAccountId, String phone, Integer status);
 
 
     /**
     /**
-     * 禁用子账号
-     * 将 store_platform_user_role 表中指定记录的 status 从 0 改为 1
+     * 更新子账号状态
+     * 根据传入的 status 值更新 store_platform_user_role 表中指定记录的 status 字段
+     * status 为 0 表示启用,status 为 1 表示禁用
      *
      *
      * @param id 子账号关联记录的主键ID
      * @param id 子账号关联记录的主键ID
+     * @param status 状态值(0启用 1禁用)
      * @return 是否成功
      * @return 是否成功
      */
      */
-    boolean disableSubAccount(Long id);
+    boolean disableSubAccount(Long id, Integer status);
 }
 }
 
 

+ 19 - 11
alien-store-platform/src/main/java/shop/alien/storeplatform/service/impl/StorePlatformUserRoleServiceImpl.java

@@ -800,12 +800,17 @@ public class StorePlatformUserRoleServiceImpl extends ServiceImpl<StorePlatformU
     }
     }
 
 
     @Override
     @Override
-    public boolean disableSubAccount(Long id) {
+    public boolean disableSubAccount(Long id, Integer status) {
         if (id == null) {
         if (id == null) {
             log.error("子账号关联记录ID不能为空");
             log.error("子账号关联记录ID不能为空");
             return false;
             return false;
         }
         }
 
 
+        if (status == null || (status != 0 && status != 1)) {
+            log.error("状态参数必须为0(启用)或1(禁用): status={}", status);
+            return false;
+        }
+
         try {
         try {
             // 1. 先查询记录是否存在
             // 1. 先查询记录是否存在
             StorePlatformUserRole userRole = storePlatformUserRoleMapper.selectById(id);
             StorePlatformUserRole userRole = storePlatformUserRoleMapper.selectById(id);
@@ -814,29 +819,32 @@ public class StorePlatformUserRoleServiceImpl extends ServiceImpl<StorePlatformU
                 return false;
                 return false;
             }
             }
 
 
-            // 2. 检查当前状态
-            if (userRole.getStatus() != null && userRole.getStatus() == 1) {
-                log.warn("子账号已经是禁用状态: id={}", id);
-                return true; // 已经是禁用状态,返回成功
+            // 2. 检查当前状态是否已经是目标状态
+            if (userRole.getStatus() != null && userRole.getStatus().equals(status)) {
+                String statusText = status == 0 ? "启用" : "禁用";
+                log.warn("子账号已经是{}状态: id={}", statusText, id);
+                return true; // 已经是目标状态,返回成功
             }
             }
 
 
-            // 3. 更新状态为禁用(1)
+            // 3. 根据传入的 status 值更新状态
             LambdaUpdateWrapper<StorePlatformUserRole> updateWrapper = new LambdaUpdateWrapper<>();
             LambdaUpdateWrapper<StorePlatformUserRole> updateWrapper = new LambdaUpdateWrapper<>();
             updateWrapper.eq(StorePlatformUserRole::getId, id)
             updateWrapper.eq(StorePlatformUserRole::getId, id)
                     .eq(StorePlatformUserRole::getDeleteFlag, 0) // 只更新未删除的记录
                     .eq(StorePlatformUserRole::getDeleteFlag, 0) // 只更新未删除的记录
-                    .set(StorePlatformUserRole::getStatus, 1); // 1代表禁用
+                    .set(StorePlatformUserRole::getStatus, status); // 根据传入的 status 值更新
 
 
             int updateResult = storePlatformUserRoleMapper.update(null, updateWrapper);
             int updateResult = storePlatformUserRoleMapper.update(null, updateWrapper);
             if (updateResult > 0) {
             if (updateResult > 0) {
-                log.info("成功禁用子账号: id={}, userId={}, storeId={}, roleId={}", 
-                        id, userRole.getUserId(), userRole.getStoreId(), userRole.getRoleId());
+                String statusText = status == 0 ? "启用" : "禁用";
+                log.info("成功{}子账号: id={}, userId={}, storeId={}, roleId={}, status={}", 
+                        statusText, id, userRole.getUserId(), userRole.getStoreId(), userRole.getRoleId(), status);
                 return true;
                 return true;
             } else {
             } else {
-                log.error("禁用子账号失败: id={}", id);
+                String statusText = status == 0 ? "启用" : "禁用";
+                log.error("{}子账号失败: id={}", statusText, id);
                 return false;
                 return false;
             }
             }
         } catch (Exception e) {
         } catch (Exception e) {
-            log.error("禁用子账号异常: id={}", id, e);
+            log.error("更新子账号状态异常: id={}, status={}", id, status, e);
             return false;
             return false;
         }
         }
     }
     }