微服务改造

This commit is contained in:
litianxiang
2026-04-27 13:54:05 +08:00
parent 8c29d292d5
commit 9cc302fa53
7 changed files with 62 additions and 25 deletions

View File

@@ -45,6 +45,9 @@ public class ListingServiceImpl extends ServiceImpl<ListingMapper, ListingEntity
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void saveOrUpdate(ListingSaveDTO dto, Long sellerId) { public void saveOrUpdate(ListingSaveDTO dto, Long sellerId) {
// 当 status 为 1已发布检查必填字段
validateListingFields(dto);
ListingEntity entity = new ListingEntity(); ListingEntity entity = new ListingEntity();
BeanUtils.copyProperties(dto, entity); BeanUtils.copyProperties(dto, entity);
entity.setSellerId(sellerId); entity.setSellerId(sellerId);
@@ -252,4 +255,36 @@ public class ListingServiceImpl extends ServiceImpl<ListingMapper, ListingEntity
Object value = redisTemplate.opsForValue().get(key); Object value = redisTemplate.opsForValue().get(key);
return value == null; return value == null;
} }
/**
* 校验商品字段
* 当 status 为 1已发布检查必填字段
*/
private void validateListingFields(ListingSaveDTO dto) {
if (dto.getStatus() != null && dto.getStatus() == 1) {
if (!StringUtils.hasText(dto.getTitle())) {
throw new BusinessException("商品标题不能为空");
}
if (!StringUtils.hasText(dto.getDescription())) {
throw new BusinessException("商品描述不能为空");
}
if (dto.getPrice() == null) {
throw new BusinessException("商品价格不能为空");
}
if (!StringUtils.hasText(dto.getDesignFor())) {
throw new BusinessException("适用性别不能为空");
}
if (DesignForEnum.of(dto.getDesignFor()) == null) {
throw new BusinessException("适用性别只能为 male/female");
}
if (CollectionUtils.isEmpty(dto.getProductCategory())) {
throw new BusinessException("商品分类不能为空");
}
for (String category : dto.getProductCategory()) {
if (ProductCategoryEnum.of(category) == null) {
throw new BusinessException("商品分类只能为 outwear/trousers/blouse/dress/skirt/accessories");
}
}
}
}
} }

View File

@@ -19,9 +19,6 @@ public class OrderInfoEntity implements Serializable {
@TableId(type = IdType.ASSIGN_ID) @TableId(type = IdType.ASSIGN_ID)
private Long id; private Long id;
/** 订单唯一标识(如 SP897772698 */
private String orderId;
/** 卖家ID */ /** 卖家ID */
private Long sellerId; private Long sellerId;

View File

@@ -20,8 +20,8 @@ public class OrderItemEntity implements Serializable {
@TableId(type = IdType.ASSIGN_ID) @TableId(type = IdType.ASSIGN_ID)
private Long id; private Long id;
/** 订单ID关联 order_info */ /** 订单ID关联 seller_orders */
private String orderId; private Long orderId;
/** 商品ID */ /** 商品ID */
private Long productId; private Long productId;

View File

@@ -75,10 +75,10 @@ public class OrderServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
if (StringUtils.hasText(dto.getKeyword())) { if (StringUtils.hasText(dto.getKeyword())) {
String keyword = dto.getKeyword().trim(); String keyword = dto.getKeyword().trim();
queryWrapper.and(w -> w queryWrapper.and(w -> w
.like(OrderInfoEntity::getOrderId, keyword) .like(OrderInfoEntity::getId, keyword)
.or() .or()
.inSql(OrderInfoEntity::getOrderId, .inSql(OrderInfoEntity::getId,
"SELECT order_id FROM order_item WHERE product_name LIKE '%" + keyword + "%'") "SELECT order_id FROM seller_order_item WHERE product_name LIKE '%" + keyword + "%'")
); );
} }
@@ -86,11 +86,11 @@ public class OrderServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
Page<OrderInfoEntity> page = this.page(pageParam, queryWrapper); Page<OrderInfoEntity> page = this.page(pageParam, queryWrapper);
List<String> orderIds = page.getRecords().stream() List<Long> orderIds = page.getRecords().stream()
.map(OrderInfoEntity::getOrderId) .map(OrderInfoEntity::getId)
.collect(Collectors.toList()); .collect(Collectors.toList());
Map<String, List<OrderItemEntity>> itemsMap = orderIds.isEmpty() Map<Long, List<OrderItemEntity>> itemsMap = orderIds.isEmpty()
? Collections.emptyMap() ? Collections.emptyMap()
: orderItemMapper.selectList( : orderItemMapper.selectList(
new LambdaQueryWrapper<OrderItemEntity>() new LambdaQueryWrapper<OrderItemEntity>()
@@ -100,12 +100,12 @@ public class OrderServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
List<OrderVO> voList = page.getRecords().stream().map(order -> { List<OrderVO> voList = page.getRecords().stream().map(order -> {
OrderVO vo = new OrderVO(); OrderVO vo = new OrderVO();
vo.setOrderId(order.getOrderId()); vo.setOrderId(order.getId());
vo.setPrice(order.getTotalPrice()); vo.setPrice(order.getTotalPrice());
vo.setBuyerUsername("@" + (order.getBuyerUsername() != null ? order.getBuyerUsername() : "")); vo.setBuyerUsername("@" + (order.getBuyerUsername() != null ? order.getBuyerUsername() : ""));
vo.setDate(order.getCreateTime()); vo.setDate(order.getCreateTime());
List<OrderItemEntity> items = itemsMap.getOrDefault(order.getOrderId(), new ArrayList<>()); List<OrderItemEntity> items = itemsMap.getOrDefault(order.getId(), new ArrayList<>());
List<OrderVO.ItemVO> itemVOs = items.stream().map(item -> { List<OrderVO.ItemVO> itemVOs = items.stream().map(item -> {
OrderVO.ItemVO itemVO = new OrderVO.ItemVO(); OrderVO.ItemVO itemVO = new OrderVO.ItemVO();
itemVO.setProductId(item.getProductId()); itemVO.setProductId(item.getProductId());

View File

@@ -14,8 +14,8 @@ public class OrderVO implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Schema(description = "订单唯一标识", example = "SP897772698") @Schema(description = "订单唯一标识")
private String orderId; private Long orderId;
@Schema(description = "商品明细列表") @Schema(description = "商品明细列表")
private List<ItemVO> items; private List<ItemVO> items;

View File

@@ -4,21 +4,27 @@
# 示例docker run -e NACOS_NAMESPACE=prod ... # 示例docker run -e NACOS_NAMESPACE=prod ...
# ============================================================ # ============================================================
nacos:
namespace: dev
host: 18.167.251.121:28848
username: nacos
password: Aidlab123123!
spring: spring:
application: application:
name: aida-seller name: aida-seller
config: config:
import: optional:nacos:aida-public-${NACOS_NAMESPACE:test}.yml import: optional:nacos:aida-public-${nacos.namespace}.yml
cloud: cloud:
nacos: nacos:
discovery: discovery:
server-addr: ${NACOS_HOST:18.167.251.121:28848} server-addr: ${nacos.host}
namespace: ${NACOS_NAMESPACE:ltx} namespace: ${nacos.namespace}
username: ${NACOS_USERNAME:nacos} username: ${nacos.username}
password: ${NACOS_PASSWORD:Aidlab123123!} password: ${nacos.password}
config: config:
server-addr: ${NACOS_HOST:18.167.251.121:28848} server-addr: ${nacos.host}
namespace: ${NACOS_NAMESPACE:ltx} namespace: ${nacos.namespace}
file-extension: yaml file-extension: yaml
username: ${NACOS_USERNAME:nacos} username: ${nacos.username}
password: ${NACOS_PASSWORD:Aidlab123123!} password: ${nacos.password}

View File

@@ -59,7 +59,6 @@ CREATE TABLE seller_designer (
-- 订单主表 -- 订单主表
CREATE TABLE seller_orders ( CREATE TABLE seller_orders (
id BIGINT PRIMARY KEY COMMENT '主键ID', id BIGINT PRIMARY KEY COMMENT '主键ID',
order_id VARCHAR(50) NOT NULL COMMENT '订单唯一标识(如 SP897772698',
seller_id BIGINT NOT NULL COMMENT '卖家ID', seller_id BIGINT NOT NULL COMMENT '卖家ID',
total_price DECIMAL(10,2) COMMENT '订单总金额(HK$)', total_price DECIMAL(10,2) COMMENT '订单总金额(HK$)',
buyer_username VARCHAR(100) COMMENT '买家账号', buyer_username VARCHAR(100) COMMENT '买家账号',