微服务改造
This commit is contained in:
@@ -45,6 +45,9 @@ public class ListingServiceImpl extends ServiceImpl<ListingMapper, ListingEntity
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveOrUpdate(ListingSaveDTO dto, Long sellerId) {
|
||||
// 当 status 为 1(已发布)时,检查必填字段
|
||||
validateListingFields(dto);
|
||||
|
||||
ListingEntity entity = new ListingEntity();
|
||||
BeanUtils.copyProperties(dto, entity);
|
||||
entity.setSellerId(sellerId);
|
||||
@@ -252,4 +255,36 @@ public class ListingServiceImpl extends ServiceImpl<ListingMapper, ListingEntity
|
||||
Object value = redisTemplate.opsForValue().get(key);
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,9 +19,6 @@ public class OrderInfoEntity implements Serializable {
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private Long id;
|
||||
|
||||
/** 订单唯一标识(如 SP897772698) */
|
||||
private String orderId;
|
||||
|
||||
/** 卖家ID */
|
||||
private Long sellerId;
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ public class OrderItemEntity implements Serializable {
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private Long id;
|
||||
|
||||
/** 订单ID(关联 order_info) */
|
||||
private String orderId;
|
||||
/** 订单ID(关联 seller_orders) */
|
||||
private Long orderId;
|
||||
|
||||
/** 商品ID */
|
||||
private Long productId;
|
||||
|
||||
@@ -75,10 +75,10 @@ public class OrderServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
||||
if (StringUtils.hasText(dto.getKeyword())) {
|
||||
String keyword = dto.getKeyword().trim();
|
||||
queryWrapper.and(w -> w
|
||||
.like(OrderInfoEntity::getOrderId, keyword)
|
||||
.like(OrderInfoEntity::getId, keyword)
|
||||
.or()
|
||||
.inSql(OrderInfoEntity::getOrderId,
|
||||
"SELECT order_id FROM order_item WHERE product_name LIKE '%" + keyword + "%'")
|
||||
.inSql(OrderInfoEntity::getId,
|
||||
"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);
|
||||
|
||||
List<String> orderIds = page.getRecords().stream()
|
||||
.map(OrderInfoEntity::getOrderId)
|
||||
List<Long> orderIds = page.getRecords().stream()
|
||||
.map(OrderInfoEntity::getId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Map<String, List<OrderItemEntity>> itemsMap = orderIds.isEmpty()
|
||||
Map<Long, List<OrderItemEntity>> itemsMap = orderIds.isEmpty()
|
||||
? Collections.emptyMap()
|
||||
: orderItemMapper.selectList(
|
||||
new LambdaQueryWrapper<OrderItemEntity>()
|
||||
@@ -100,12 +100,12 @@ public class OrderServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
||||
|
||||
List<OrderVO> voList = page.getRecords().stream().map(order -> {
|
||||
OrderVO vo = new OrderVO();
|
||||
vo.setOrderId(order.getOrderId());
|
||||
vo.setOrderId(order.getId());
|
||||
vo.setPrice(order.getTotalPrice());
|
||||
vo.setBuyerUsername("@" + (order.getBuyerUsername() != null ? order.getBuyerUsername() : ""));
|
||||
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 -> {
|
||||
OrderVO.ItemVO itemVO = new OrderVO.ItemVO();
|
||||
itemVO.setProductId(item.getProductId());
|
||||
|
||||
@@ -14,8 +14,8 @@ public class OrderVO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "订单唯一标识", example = "SP897772698")
|
||||
private String orderId;
|
||||
@Schema(description = "订单唯一标识")
|
||||
private Long orderId;
|
||||
|
||||
@Schema(description = "商品明细列表")
|
||||
private List<ItemVO> items;
|
||||
|
||||
@@ -4,21 +4,27 @@
|
||||
# 示例:docker run -e NACOS_NAMESPACE=prod ...
|
||||
# ============================================================
|
||||
|
||||
nacos:
|
||||
namespace: dev
|
||||
host: 18.167.251.121:28848
|
||||
username: nacos
|
||||
password: Aidlab123123!
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: aida-seller
|
||||
config:
|
||||
import: optional:nacos:aida-public-${NACOS_NAMESPACE:test}.yml
|
||||
import: optional:nacos:aida-public-${nacos.namespace}.yml
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: ${NACOS_HOST:18.167.251.121:28848}
|
||||
namespace: ${NACOS_NAMESPACE:ltx}
|
||||
username: ${NACOS_USERNAME:nacos}
|
||||
password: ${NACOS_PASSWORD:Aidlab123123!}
|
||||
server-addr: ${nacos.host}
|
||||
namespace: ${nacos.namespace}
|
||||
username: ${nacos.username}
|
||||
password: ${nacos.password}
|
||||
config:
|
||||
server-addr: ${NACOS_HOST:18.167.251.121:28848}
|
||||
namespace: ${NACOS_NAMESPACE:ltx}
|
||||
server-addr: ${nacos.host}
|
||||
namespace: ${nacos.namespace}
|
||||
file-extension: yaml
|
||||
username: ${NACOS_USERNAME:nacos}
|
||||
password: ${NACOS_PASSWORD:Aidlab123123!}
|
||||
username: ${nacos.username}
|
||||
password: ${nacos.password}
|
||||
|
||||
@@ -59,7 +59,6 @@ CREATE TABLE seller_designer (
|
||||
-- 订单主表
|
||||
CREATE TABLE seller_orders (
|
||||
id BIGINT PRIMARY KEY COMMENT '主键ID',
|
||||
order_id VARCHAR(50) NOT NULL COMMENT '订单唯一标识(如 SP897772698)',
|
||||
seller_id BIGINT NOT NULL COMMENT '卖家ID',
|
||||
total_price DECIMAL(10,2) COMMENT '订单总金额(HK$)',
|
||||
buyer_username VARCHAR(100) COMMENT '买家账号',
|
||||
|
||||
Reference in New Issue
Block a user