新增删除seller接口
This commit is contained in:
@@ -87,4 +87,12 @@ public class DesignerController {
|
|||||||
DesignerDTO designerInfo = designerService.getDesignerInfo(userId);
|
DesignerDTO designerInfo = designerService.getDesignerInfo(userId);
|
||||||
return Response.success(designerInfo);
|
return Response.success(designerInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "删除设计师", description = "根据当前登录用户ID逻辑删除设计师及其所有关联数据(订单、订单明细、商品、商品图片)")
|
||||||
|
@DeleteMapping("/delete")
|
||||||
|
public Response<Void> delete() {
|
||||||
|
Long userId = UserContext.getUserId();
|
||||||
|
designerService.deleteByUserId(userId);
|
||||||
|
return Response.success();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,4 +49,13 @@ public interface DesignerService extends IService<DesignerEntity> {
|
|||||||
* 获取设计师详细信息
|
* 获取设计师详细信息
|
||||||
*/
|
*/
|
||||||
DesignerDTO getDesignerInfo(Long userId);
|
DesignerDTO getDesignerInfo(Long userId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除设计师(逻辑删除)及其所有关联数据
|
||||||
|
* <p>级联删除:seller_designer(按userId)→ seller_orders → seller_order_item、
|
||||||
|
* seller_listing → seller_listing_image</p>
|
||||||
|
*
|
||||||
|
* @param userId 用户ID
|
||||||
|
*/
|
||||||
|
void deleteByUserId(Long userId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,14 @@ import com.aida.seller.module.designer.dto.DesignerDTO;
|
|||||||
import com.aida.seller.module.designer.entity.DesignerEntity;
|
import com.aida.seller.module.designer.entity.DesignerEntity;
|
||||||
import com.aida.seller.module.designer.enums.DesignerApplyStatusEnum;
|
import com.aida.seller.module.designer.enums.DesignerApplyStatusEnum;
|
||||||
import com.aida.seller.module.designer.mapper.DesignerMapper;
|
import com.aida.seller.module.designer.mapper.DesignerMapper;
|
||||||
|
import com.aida.seller.module.listing.entity.ListingEntity;
|
||||||
|
import com.aida.seller.module.listing.entity.ListingImageEntity;
|
||||||
|
import com.aida.seller.module.listing.mapper.ListingImageMapper;
|
||||||
|
import com.aida.seller.module.listing.mapper.ListingMapper;
|
||||||
|
import com.aida.seller.module.order.entity.OrderInfoEntity;
|
||||||
|
import com.aida.seller.module.order.entity.OrderItemEntity;
|
||||||
|
import com.aida.seller.module.order.mapper.OrderInfoMapper;
|
||||||
|
import com.aida.seller.module.order.mapper.OrderItemMapper;
|
||||||
import com.aida.seller.util.MinioUtil;
|
import com.aida.seller.util.MinioUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
@@ -18,6 +26,9 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@@ -25,6 +36,11 @@ import java.time.LocalDateTime;
|
|||||||
public class DesignerServiceImpl extends ServiceImpl<DesignerMapper, DesignerEntity> implements DesignerService {
|
public class DesignerServiceImpl extends ServiceImpl<DesignerMapper, DesignerEntity> implements DesignerService {
|
||||||
|
|
||||||
private final MinioUtil minioUtil;
|
private final MinioUtil minioUtil;
|
||||||
|
private final OrderInfoMapper orderInfoMapper;
|
||||||
|
private final OrderItemMapper orderItemMapper;
|
||||||
|
private final ListingMapper listingMapper;
|
||||||
|
private final ListingImageMapper listingImageMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean checkQualification(Long userId) {
|
public Boolean checkQualification(Long userId) {
|
||||||
DesignerEntity entity = this.getOne(
|
DesignerEntity entity = this.getOne(
|
||||||
@@ -218,4 +234,66 @@ public class DesignerServiceImpl extends ServiceImpl<DesignerMapper, DesignerEnt
|
|||||||
|
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void deleteByUserId(Long userId) {
|
||||||
|
DesignerEntity designer = this.getOne(
|
||||||
|
new LambdaQueryWrapper<DesignerEntity>()
|
||||||
|
.eq(DesignerEntity::getUserId, userId)
|
||||||
|
.last("LIMIT 1")
|
||||||
|
);
|
||||||
|
if (designer == null) {
|
||||||
|
throw new BusinessException("设计师记录不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
Long sellerId = designer.getId();
|
||||||
|
|
||||||
|
// 1. 查询所有关联的 listing_id,再删除 listing 及其图片
|
||||||
|
List<ListingEntity> listings = listingMapper.selectList(
|
||||||
|
new LambdaQueryWrapper<ListingEntity>()
|
||||||
|
.eq(ListingEntity::getSellerId, sellerId)
|
||||||
|
);
|
||||||
|
if (!listings.isEmpty()) {
|
||||||
|
List<Long> listingIds = listings.stream()
|
||||||
|
.map(ListingEntity::getId)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
// 逻辑删除关联的图片
|
||||||
|
listingImageMapper.delete(
|
||||||
|
new LambdaQueryWrapper<ListingImageEntity>()
|
||||||
|
.in(ListingImageEntity::getListingId, listingIds)
|
||||||
|
);
|
||||||
|
// 逻辑删除 listing
|
||||||
|
listingMapper.delete(
|
||||||
|
new LambdaQueryWrapper<ListingEntity>()
|
||||||
|
.eq(ListingEntity::getSellerId, sellerId)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 删除 seller_orders 及关联的 order_item
|
||||||
|
List<OrderInfoEntity> orders = orderInfoMapper.selectList(
|
||||||
|
new LambdaQueryWrapper<OrderInfoEntity>()
|
||||||
|
.eq(OrderInfoEntity::getSellerId, sellerId)
|
||||||
|
);
|
||||||
|
if (!orders.isEmpty()) {
|
||||||
|
List<Long> orderIds = orders.stream()
|
||||||
|
.map(OrderInfoEntity::getId)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
// 逻辑删除关联的订单明细
|
||||||
|
orderItemMapper.delete(
|
||||||
|
new LambdaQueryWrapper<OrderItemEntity>()
|
||||||
|
.in(OrderItemEntity::getOrderId, orderIds)
|
||||||
|
);
|
||||||
|
// 逻辑删除订单
|
||||||
|
orderInfoMapper.delete(
|
||||||
|
new LambdaQueryWrapper<OrderInfoEntity>()
|
||||||
|
.eq(OrderInfoEntity::getSellerId, sellerId)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 逻辑删除设计师本人
|
||||||
|
this.removeById(sellerId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.aida.seller.module.listing.entity;
|
package com.aida.seller.module.listing.entity;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.*;
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -43,4 +42,7 @@ public class ListingImageEntity implements Serializable {
|
|||||||
@TableField(fill = FieldFill.INSERT)
|
@TableField(fill = FieldFill.INSERT)
|
||||||
private LocalDateTime createTime;
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
/** 是否删除:0-否,1-是 */
|
||||||
|
@TableLogic
|
||||||
|
private Integer deleted;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,8 @@ public class ListingServiceImpl extends ServiceImpl<ListingMapper, ListingEntity
|
|||||||
ListingEntity existing = this.getOne(
|
ListingEntity existing = this.getOne(
|
||||||
new LambdaQueryWrapper<ListingEntity>()
|
new LambdaQueryWrapper<ListingEntity>()
|
||||||
.eq(ListingEntity::getId, dto.getId())
|
.eq(ListingEntity::getId, dto.getId())
|
||||||
.eq(ListingEntity::getSellerId, sellerId));
|
.eq(ListingEntity::getSellerId, sellerId)
|
||||||
|
.eq(ListingEntity::getDeleted, 0));
|
||||||
if (existing == null) {
|
if (existing == null) {
|
||||||
throw new BusinessException("商品不存在");
|
throw new BusinessException("商品不存在");
|
||||||
}
|
}
|
||||||
@@ -111,7 +112,8 @@ public class ListingServiceImpl extends ServiceImpl<ListingMapper, ListingEntity
|
|||||||
ListingEntity entity = this.getOne(
|
ListingEntity entity = this.getOne(
|
||||||
new LambdaQueryWrapper<ListingEntity>()
|
new LambdaQueryWrapper<ListingEntity>()
|
||||||
.eq(ListingEntity::getId, id)
|
.eq(ListingEntity::getId, id)
|
||||||
.eq(ListingEntity::getSellerId, sellerId));
|
.eq(ListingEntity::getSellerId, sellerId)
|
||||||
|
.eq(ListingEntity::getDeleted, 0));
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
throw new BusinessException("商品不存在");
|
throw new BusinessException("商品不存在");
|
||||||
}
|
}
|
||||||
@@ -141,6 +143,7 @@ public class ListingServiceImpl extends ServiceImpl<ListingMapper, ListingEntity
|
|||||||
Page<ListingEntity> pageParam = new Page<>(dto.getPageNum(), dto.getPageSize());
|
Page<ListingEntity> pageParam = new Page<>(dto.getPageNum(), dto.getPageSize());
|
||||||
LambdaQueryWrapper<ListingEntity> queryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<ListingEntity> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
queryWrapper.eq(ListingEntity::getSellerId, sellerId);
|
queryWrapper.eq(ListingEntity::getSellerId, sellerId);
|
||||||
|
queryWrapper.eq(ListingEntity::getDeleted, 0);
|
||||||
if (dto.getStatus() != null) {
|
if (dto.getStatus() != null) {
|
||||||
queryWrapper.eq(ListingEntity::getStatus, dto.getStatus());
|
queryWrapper.eq(ListingEntity::getStatus, dto.getStatus());
|
||||||
} else {
|
} else {
|
||||||
@@ -164,7 +167,8 @@ public class ListingServiceImpl extends ServiceImpl<ListingMapper, ListingEntity
|
|||||||
ListingEntity existing = this.getOne(
|
ListingEntity existing = this.getOne(
|
||||||
new LambdaQueryWrapper<ListingEntity>()
|
new LambdaQueryWrapper<ListingEntity>()
|
||||||
.eq(ListingEntity::getId, id)
|
.eq(ListingEntity::getId, id)
|
||||||
.eq(ListingEntity::getSellerId, sellerId));
|
.eq(ListingEntity::getSellerId, sellerId)
|
||||||
|
.eq(ListingEntity::getDeleted, 0));
|
||||||
if (existing == null) {
|
if (existing == null) {
|
||||||
throw new BusinessException("商品不存在");
|
throw new BusinessException("商品不存在");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
|||||||
.like(OrderInfoEntity::getId, keyword)
|
.like(OrderInfoEntity::getId, keyword)
|
||||||
.or()
|
.or()
|
||||||
.inSql(OrderInfoEntity::getId,
|
.inSql(OrderInfoEntity::getId,
|
||||||
"SELECT order_id FROM seller_order_item WHERE product_name LIKE '%" + keyword + "%'")
|
"SELECT order_id FROM seller_order_item WHERE deleted = 0 AND product_name LIKE '%" + keyword + "%'")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,9 @@ CREATE TABLE seller_listing_image (
|
|||||||
sort_order INT DEFAULT 0 COMMENT '排序',
|
sort_order INT DEFAULT 0 COMMENT '排序',
|
||||||
is_selected INT(1) DEFAULT 0 COMMENT '是否选中: 0-未选中, 1-选中(仅product有效)',
|
is_selected INT(1) DEFAULT 0 COMMENT '是否选中: 0-未选中, 1-选中(仅product有效)',
|
||||||
create_time DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
create_time DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||||
INDEX idx_listing_id (listing_id)
|
deleted INT(1) DEFAULT 0 COMMENT '是否删除:0-否,1-是',
|
||||||
|
INDEX idx_listing_id (listing_id),
|
||||||
|
INDEX idx_deleted (deleted)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='商品图片表';
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='商品图片表';
|
||||||
|
|
||||||
-- 设计师表
|
-- 设计师表
|
||||||
|
|||||||
Reference in New Issue
Block a user