更新这个货源
This commit is contained in:
+21
-4
@@ -17,7 +17,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;
|
||||
@@ -34,6 +37,13 @@ public class QueryAsinResolveService {
|
||||
private final QueryAsinShopCandidateMapper candidateMapper;
|
||||
private final ZiniaoShopSwitchService ziniaoShopSwitchService;
|
||||
private final QueryAsinMapper queryAsinMapper;
|
||||
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);
|
||||
@@ -52,14 +62,13 @@ public class QueryAsinResolveService {
|
||||
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()
|
||||
@@ -69,9 +78,17 @@ public class QueryAsinResolveService {
|
||||
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) {
|
||||
QueryAsinShopCandidateEntity existing = candidateMapper.selectOne(
|
||||
new LambdaQueryWrapper<QueryAsinShopCandidateEntity>()
|
||||
.eq(QueryAsinShopCandidateEntity::getUserId, request.getUserId())
|
||||
.eq(QueryAsinShopCandidateEntity::getUserId, userId)
|
||||
.eq(QueryAsinShopCandidateEntity::getShopName, normalized)
|
||||
.last("limit 1"));
|
||||
if (existing != null) {
|
||||
@@ -82,7 +99,7 @@ public class QueryAsinResolveService {
|
||||
return vo;
|
||||
}
|
||||
QueryAsinShopCandidateEntity entity = new QueryAsinShopCandidateEntity();
|
||||
entity.setUserId(request.getUserId());
|
||||
entity.setUserId(userId);
|
||||
entity.setShopName(normalized);
|
||||
entity.setCreatedAt(LocalDateTime.now());
|
||||
candidateMapper.insert(entity);
|
||||
|
||||
Reference in New Issue
Block a user