Преглед на файлове

修改子账号创建时在表中生成多余数据问题

liudongzhi преди 1 месец
родител
ревизия
62a4b4e778

+ 3 - 0
alien-entity/src/main/java/shop/alien/entity/store/vo/SubAccountVo.java

@@ -16,6 +16,9 @@ import lombok.Data;
 @ApiModel(value = "SubAccountVo对象", description = "子账号信息VO")
 public class SubAccountVo {
 
+    @ApiModelProperty(value = "中间表id(子账号id)")
+    private Integer id;
+
     @ApiModelProperty(value = "用户ID")
     private Integer userId;
 

+ 1 - 0
alien-entity/src/main/resources/mapper/StorePlatformUserRoleMapper.xml

@@ -7,6 +7,7 @@
     <!-- 根据店铺ID查询子账号列表(连表查询) -->
     <select id="querySubAccounts" resultType="shop.alien.entity.store.vo.SubAccountVo">
         SELECT
+            spur.id AS id,
             sur.id AS userId,
             spur.account_name AS accountName,
             sur.phone AS phone,

+ 38 - 0
alien-store-platform/src/main/java/shop/alien/storeplatform/controller/StorePlatformUserRoleController.java

@@ -243,6 +243,44 @@ public class StorePlatformUserRoleController {
         return R.fail("更新子账号信息失败");
     }
 
+
+
+    @ApiOperation("更新子账号信息")
+    @ApiOperationSupport(order = 10)
+    @PlatformOperationLog(
+            module = "账号操作记录",
+            type = "修改子账号",
+            content = "修改子账号,用户ID:#{#p0.userId},手机号:#{#p0.phone},账号名:#{#p0.accountName}"
+    )
+    @PostMapping("/updateSubAccountNew")
+    public R<String> updateSubAccountNew(@RequestBody UpdateAccountDto updateAccountDto) {
+        log.info("StorePlatformUserRoleController.updateSubAccount?userId={}, phone={}, accountName={}, storeId={}, roleId={}",
+                updateAccountDto.getUserId(), updateAccountDto.getPhone(), updateAccountDto.getAccountName(),
+                updateAccountDto.getStoreId(), updateAccountDto.getRoleId());
+
+        if (updateAccountDto.getUserId() == null) {
+            return R.fail("用户ID不能为空");
+        }
+        if (updateAccountDto.getStoreId() == null) {
+            return R.fail("店铺ID不能为空");
+        }
+
+        boolean result = storePlatformUserRoleService.updateSubAccountNew(
+                updateAccountDto.getUserId(),
+                updateAccountDto.getPhone(),
+                updateAccountDto.getAccountName(),
+                updateAccountDto.getStoreId(),
+                updateAccountDto.getRoleId(),
+                updateAccountDto.getId()
+        );
+        if (result) {
+            return R.success("更新子账号信息成功");
+        }
+        return R.fail("更新子账号信息失败");
+    }
+
+
+
     @ApiOperation("查询所有子账号信息(分页)")
     @ApiOperationSupport(order = 11)
     @ApiImplicitParams({

+ 3 - 0
alien-store-platform/src/main/java/shop/alien/storeplatform/dto/UpdateAccountDto.java

@@ -14,6 +14,9 @@ import lombok.Data;
 @ApiModel(value = "UpdateAccountDto", description = "更新子账号请求参数")
 public class UpdateAccountDto {
 
+    @ApiModelProperty(value = "中间表id(子账号id)")
+    private Integer id;
+
     @ApiModelProperty(value = "用户ID", required = true)
     private Integer userId;
 

+ 2 - 0
alien-store-platform/src/main/java/shop/alien/storeplatform/service/StorePlatformUserRoleService.java

@@ -123,6 +123,8 @@ public interface StorePlatformUserRoleService extends IService<StorePlatformUser
      */
     boolean updateSubAccount(Integer userId, String phone, String accountName, Integer storeId, Long roleId);
 
+    boolean updateSubAccountNew(Integer userId, String phone, String accountName, Integer storeId, Long roleId,Integer id);
+
     /**
      * 查询所有子账号信息(包含主账号电话)- 分页查询
      * 查询 store_platform_user_role 表中所有的数据

+ 18 - 0
alien-store-platform/src/main/java/shop/alien/storeplatform/service/impl/StorePlatformUserRoleServiceImpl.java

@@ -780,6 +780,24 @@ public class StorePlatformUserRoleServiceImpl extends ServiceImpl<StorePlatformU
     }
 
     @Override
+    public boolean updateSubAccountNew(Integer userId, String phone, String accountName, Integer storeId, Long roleId,Integer id) {
+        LambdaUpdateWrapper<StorePlatformUserRole> deleteWrapper = new LambdaUpdateWrapper<>();
+        deleteWrapper.eq(StorePlatformUserRole::getUserId, userId)
+                .eq(StorePlatformUserRole::getId, id)
+                .set(StorePlatformUserRole::getDeleteFlag, 1);
+        int deleteResult = storePlatformUserRoleMapper.update(null, deleteWrapper);
+        if (deleteResult > 0) {
+            log.info("成功删除角色关联记录: userId={}, storeId={}, roleId={}", userId, storeId, roleId);
+           R<String> A =createAccountAndAssignRole(phone, accountName, storeId, roleId);
+           if (A.getCode()==200){
+               return true;
+           }
+        }
+
+        return false;
+    }
+
+    @Override
     public IPage<SubAccountListVo> queryAllSubAccounts(Integer pageNum, Integer pageSize, String accountId, String phone, Integer status) {
         try {
             // 创建分页对象