You've already forked FrameTour-BE
Compare commits
5 Commits
4a05773860
...
4f1443a3ca
Author | SHA1 | Date | |
---|---|---|---|
4f1443a3ca | |||
aba9fb0a15 | |||
ab3208c9df | |||
09e376e089 | |||
dad9ddc17c |
@@ -10,6 +10,7 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
|
||||
import org.springframework.kafka.core.*;
|
||||
import org.springframework.kafka.listener.ContainerProperties;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -80,4 +81,21 @@ public class KafkaConfig {
|
||||
factory.setConsumerFactory(consumerFactory());
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ConcurrentKafkaListenerContainerFactory<String, String> manualCommitKafkaListenerContainerFactory() {
|
||||
ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>();
|
||||
|
||||
Map<String, Object> props = new HashMap<>();
|
||||
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
|
||||
props.put(ConsumerConfig.GROUP_ID_CONFIG, consumerGroupId);
|
||||
props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
|
||||
props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
|
||||
props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, autoOffsetReset);
|
||||
props.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, false);
|
||||
|
||||
factory.setConsumerFactory(new DefaultKafkaConsumerFactory<>(props));
|
||||
factory.getContainerProperties().setAckMode(ContainerProperties.AckMode.MANUAL_IMMEDIATE);
|
||||
return factory;
|
||||
}
|
||||
}
|
@@ -6,7 +6,7 @@ import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* zt-face topic消息结构
|
||||
@@ -44,7 +44,7 @@ public class FaceProcessingMessage {
|
||||
* 拍摄时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime shotTime;
|
||||
private Date shotTime;
|
||||
|
||||
// status字段已移除,由系统内部管理状态
|
||||
|
||||
@@ -54,7 +54,7 @@ public class FaceProcessingMessage {
|
||||
* 消息创建时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime createTime;
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 消息来源
|
||||
@@ -69,14 +69,14 @@ public class FaceProcessingMessage {
|
||||
* 创建人脸处理消息的工厂方法(使用外部传入的faceId)
|
||||
*/
|
||||
public static FaceProcessingMessage create(Long externalFaceId, Long scenicId, Long deviceId,
|
||||
String faceUrl, LocalDateTime shotTime) {
|
||||
String faceUrl, Date shotTime) {
|
||||
return FaceProcessingMessage.builder()
|
||||
.faceSampleId(externalFaceId) // 使用外部传入的ID作为唯一标识
|
||||
.scenicId(scenicId)
|
||||
.deviceId(deviceId)
|
||||
.faceUrl(faceUrl)
|
||||
.shotTime(shotTime)
|
||||
.createTime(LocalDateTime.now())
|
||||
.createTime(new Date())
|
||||
.source("external-system")
|
||||
.build();
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.kafka.annotation.KafkaListener;
|
||||
import org.springframework.kafka.support.Acknowledgment;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.ZoneId;
|
||||
@@ -43,8 +44,8 @@ public class FaceProcessingKafkaService {
|
||||
* 消费外部系统发送的人脸处理消息
|
||||
* 先保存人脸样本数据,再进行异步人脸识别处理
|
||||
*/
|
||||
@KafkaListener(topics = ZT_FACE_TOPIC)
|
||||
public void processFaceMessage(String message) {
|
||||
@KafkaListener(topics = ZT_FACE_TOPIC, containerFactory = "manualCommitKafkaListenerContainerFactory")
|
||||
public void processFaceMessage(String message, Acknowledgment ack) {
|
||||
try {
|
||||
FaceProcessingMessage faceMessage = JacksonUtil.parseObject(message, FaceProcessingMessage.class);
|
||||
log.info("接收到外部人脸处理消息, scenicId: {}, deviceId: {}, faceUrl: {}",
|
||||
@@ -62,12 +63,21 @@ public class FaceProcessingKafkaService {
|
||||
|
||||
// 然后进行人脸识别处理
|
||||
if (saved) {
|
||||
processFaceRecognition(faceMessage);
|
||||
boolean processed = processFaceRecognition(faceMessage);
|
||||
if (processed) {
|
||||
// 只有在所有处理都成功后才手动提交
|
||||
ack.acknowledge();
|
||||
log.info("消息处理成功并已提交, faceSampleId: {}", externalFaceId);
|
||||
} else {
|
||||
log.warn("人脸识别处理失败,消息不会被提交, faceSampleId: {}", externalFaceId);
|
||||
}
|
||||
} else {
|
||||
log.warn("人脸样本保存失败,消息不会被提交, faceSampleId: {}", externalFaceId);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("处理外部人脸消息失败: {}", e.getMessage(), e);
|
||||
// TODO: 考虑错误重试机制或死信队列
|
||||
log.error("处理外部人脸消息失败,消息不会被提交: {}", e.getMessage(), e);
|
||||
// 不调用ack.acknowledge(),消息保持未提交状态,可以重新消费
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +98,7 @@ public class FaceProcessingKafkaService {
|
||||
|
||||
// 转换时间格式
|
||||
if (faceMessage.getShotTime() != null) {
|
||||
Date shotTime = Date.from(faceMessage.getShotTime().atZone(ZoneId.systemDefault()).toInstant());
|
||||
Date shotTime = faceMessage.getShotTime();
|
||||
faceSample.setCreateAt(shotTime);
|
||||
} else {
|
||||
faceSample.setCreateAt(new Date());
|
||||
@@ -111,7 +121,7 @@ public class FaceProcessingKafkaService {
|
||||
* 执行人脸识别处理逻辑
|
||||
* 对已保存的人脸样本进行识别处理
|
||||
*/
|
||||
private void processFaceRecognition(FaceProcessingMessage message) {
|
||||
private boolean processFaceRecognition(FaceProcessingMessage message) {
|
||||
Long faceSampleId = message.getFaceSampleId();
|
||||
Long scenicId = message.getScenicId();
|
||||
String faceUrl = message.getFaceUrl();
|
||||
@@ -124,7 +134,7 @@ public class FaceProcessingKafkaService {
|
||||
if (faceBodyAdapter == null) {
|
||||
log.error("人脸识别适配器不存在, scenicId: {}", scenicId);
|
||||
updateFaceSampleStatus(faceSampleId, -1);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -157,9 +167,11 @@ public class FaceProcessingKafkaService {
|
||||
DynamicTaskGenerator.addTask(faceSampleId);
|
||||
log.info("已添加到预订任务队列, faceSampleId: {}", faceSampleId);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
log.warn("人脸添加返回空结果, faceSampleId: {}", faceSampleId);
|
||||
updateFaceSampleStatus(faceSampleId, -1);
|
||||
return false;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
@@ -168,6 +180,7 @@ public class FaceProcessingKafkaService {
|
||||
|
||||
// 标记人脸样本为处理失败状态
|
||||
updateFaceSampleStatus(faceSampleId, -1);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -144,6 +144,17 @@ public enum ProductType {
|
||||
}
|
||||
```
|
||||
|
||||
#### 商品价格配置控制字段
|
||||
`PriceProductConfig` 实体包含以下优惠控制字段:
|
||||
- `canUseCoupon`: 是否可使用优惠券
|
||||
- `canUseVoucher`: 是否可使用券码
|
||||
- `canUseOnePrice`: 是否可使用一口价优惠(新增)
|
||||
|
||||
#### 一口价优惠控制机制
|
||||
- 当购物车中任何商品的 `canUseOnePrice` 为 `false` 时,将跳过整个购物车的一口价优惠检测
|
||||
- 配置优先级:具体商品配置 > 商品类型默认配置 > 系统默认(支持)
|
||||
- 异常情况下默认支持一口价优惠,确保业务流程不受影响
|
||||
|
||||
#### 分层定价
|
||||
支持基于数量的分层定价策略,通过 `PriceTierConfig` 配置不同数量区间的单价。
|
||||
|
||||
@@ -339,6 +350,7 @@ public interface IDiscountDetectionService {
|
||||
#### OnePricePurchaseDiscountProvider (优先级: 120)
|
||||
- 处理一口价优惠逻辑(景区级统一价格)
|
||||
- **最高优先级**,优先于所有其他优惠类型
|
||||
- 商品级别控制:检查购物车中所有商品的 `canUseOnePrice` 配置,任一商品不支持则跳过检测
|
||||
- 仅当一口价小于当前金额时产生优惠;是否可与券码/优惠券叠加由配置 `canUseCoupon/canUseVoucher` 决定
|
||||
|
||||
#### BundleDiscountProvider (优先级: 100)
|
||||
@@ -370,7 +382,7 @@ public interface IDiscountDetectionService {
|
||||
|
||||
特殊情况:
|
||||
- 全场免费券码:直接最终价=0,停止后续优惠
|
||||
- 一口价:可叠加性由配置 canUseCoupon / canUseVoucher 控制
|
||||
- 一口价:可叠加性由配置 canUseCoupon / canUseVoucher 控制;商品级别由 canUseOnePrice 控制参与检测
|
||||
```
|
||||
|
||||
#### 扩展支持
|
||||
@@ -535,7 +547,7 @@ public class PriceCalculationResult {
|
||||
## 数据库设计
|
||||
|
||||
### 核心表结构(摘)
|
||||
- `price_product_config`: 商品价格基础配置
|
||||
- `price_product_config`: 商品价格基础配置(包含 `can_use_coupon`、`can_use_voucher`、`can_use_one_price` 优惠控制字段)
|
||||
- `price_tier_config`: 分层定价配置
|
||||
- `price_bundle_config`: 套餐配置
|
||||
- `price_coupon_config`: 优惠券配置
|
||||
|
@@ -39,6 +39,7 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.Strings;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@@ -49,6 +50,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@@ -377,8 +379,16 @@ public class PrinterServiceImpl implements PrinterService {
|
||||
printerMapper.updateUserPhotoListToPrinter(memberId, scenicId, printerId);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<String, String> redisTemplate;
|
||||
private static final String USER_PHOTO_LIST_TO_PRINTER = "USER_PHOTO_LIST_TO_PRINTER:";
|
||||
|
||||
@Override
|
||||
public void setUserIsBuyItem(Long memberId, Long id, Long orderId) {
|
||||
if (redisTemplate.opsForValue().get(USER_PHOTO_LIST_TO_PRINTER + memberId + ":" + orderId) != null) {
|
||||
return;
|
||||
}
|
||||
redisTemplate.opsForValue().set(USER_PHOTO_LIST_TO_PRINTER + memberId + ":" + orderId, "1", 60, TimeUnit.SECONDS);
|
||||
printerMapper.setUserIsBuyItem(memberId, id, orderId);
|
||||
// 创建打印任务
|
||||
List<MemberPrintResp> userPhotoListByOrderId = getUserPhotoListByOrderId(orderId);
|
||||
|
@@ -318,6 +318,10 @@ public class VideoPieceGetter {
|
||||
}
|
||||
if (source == null) {
|
||||
SourceEntity imgSource = sourceMapper.findBySampleId(faceSampleId);
|
||||
if (imgSource == null) {
|
||||
log.warn("imgSource为null,跳过保存source记录, faceSampleId: {}", faceSampleId);
|
||||
return false;
|
||||
}
|
||||
SourceEntity sourceEntity = new SourceEntity();
|
||||
sourceEntity.setId(SnowFlakeUtil.getLongId());
|
||||
sourceEntity.setCreateTime(baseTime);
|
||||
|
Reference in New Issue
Block a user