更新这个货源

This commit is contained in:
super
2026-05-22 09:41:31 +08:00
parent 73d25fcbcb
commit 70e902e7ea
22 changed files with 1136 additions and 52 deletions
@@ -18,7 +18,10 @@ import com.nanri.aiimage.modules.ziniao.service.ZiniaoShopIndexService;
import com.nanri.aiimage.modules.ziniao.service.ZiniaoShopSwitchService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionTemplate;
import java.time.LocalDateTime;
import java.util.ArrayList;
@@ -33,6 +36,13 @@ public class PatrolDeleteResolveService {
private final PatrolDeleteShopCandidateMapper candidateMapper;
private final PatrolDeleteConditionMapper conditionMapper;
private final ZiniaoShopSwitchService ziniaoShopSwitchService;
private final PlatformTransactionManager transactionManager;
private TransactionTemplate newRequiresNewTemplate() {
TransactionTemplate template = new TransactionTemplate(transactionManager);
template.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
return template;
}
public List<ProductRiskCandidateVo> listCandidates(Long userId) {
validateUserId(userId);
@@ -51,14 +61,13 @@ public class PatrolDeleteResolveService {
return list;
}
@Transactional
public ProductRiskCandidateVo addCandidate(ProductRiskCandidateAddRequest request) {
validateUserId(request.getUserId());
String normalized = ziniaoShopSwitchService.normalizeShopName(request.getShopName());
if (normalized.isBlank()) {
throw new BusinessException("店铺名不能为空");
}
ZiniaoShopMatchResultVo indexHit = ziniaoShopSwitchService.findIndexedStoreByName(normalized, false);
ZiniaoShopMatchResultVo indexHit = resolveIndexedShop(normalized);
if (indexHit == null || !indexHit.isMatched()) {
String hint = indexHit != null && indexHit.getMatchMessage() != null && !indexHit.getMatchMessage().isBlank()
? indexHit.getMatchMessage()
@@ -68,9 +77,17 @@ public class PatrolDeleteResolveService {
if (ZiniaoShopIndexService.MATCH_STATUS_CONFLICT.equals(indexHit.getMatchStatus())) {
throw new BusinessException(indexHit.getMatchMessage() != null ? indexHit.getMatchMessage() : "存在多个同名店铺,请人工确认");
}
return newRequiresNewTemplate().execute(status -> persistCandidate(request.getUserId(), normalized));
}
private ZiniaoShopMatchResultVo resolveIndexedShop(String normalizedShopName) {
return ziniaoShopSwitchService.findIndexedStoreByName(normalizedShopName, false);
}
private ProductRiskCandidateVo persistCandidate(Long userId, String normalized) {
PatrolDeleteShopCandidateEntity existing = candidateMapper.selectOne(
new LambdaQueryWrapper<PatrolDeleteShopCandidateEntity>()
.eq(PatrolDeleteShopCandidateEntity::getUserId, request.getUserId())
.eq(PatrolDeleteShopCandidateEntity::getUserId, userId)
.eq(PatrolDeleteShopCandidateEntity::getShopName, normalized)
.last("limit 1"));
if (existing != null) {
@@ -81,7 +98,7 @@ public class PatrolDeleteResolveService {
return vo;
}
PatrolDeleteShopCandidateEntity entity = new PatrolDeleteShopCandidateEntity();
entity.setUserId(request.getUserId());
entity.setUserId(userId);
entity.setShopName(normalized);
entity.setCreatedAt(LocalDateTime.now());
candidateMapper.insert(entity);