Commit 19089da6 by 周立明

优加审核通过后在审核事件里发布对账规则

1 parent c666ebe7
package com.youjia.store.service; package com.youjia.store.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.youjia.common.enums.CalcModeEnum; import com.youjia.common.enums.CalcModeEnum;
...@@ -8,9 +9,13 @@ import com.youjia.framework.rop.RopClient; ...@@ -8,9 +9,13 @@ import com.youjia.framework.rop.RopClient;
import com.youjia.framework.rop.RopProperties; import com.youjia.framework.rop.RopProperties;
import com.youjia.store.entity.StoreListing; import com.youjia.store.entity.StoreListing;
import com.youjia.store.entity.StoreListingItem; import com.youjia.store.entity.StoreListingItem;
import com.youjia.store.mapper.StoreListingItemMapper;
import com.youjia.store.mapper.StoreListingMapper;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
...@@ -146,6 +151,56 @@ public class ReconciliationRulePublishService { ...@@ -146,6 +151,56 @@ public class ReconciliationRulePublishService {
private final ObjectMapper objectMapper; private final ObjectMapper objectMapper;
private final StoreListingMapper storeListingMapper;
private final StoreListingItemMapper storeListingItemMapper;
/**
* 按门店上架记录ID 发布对账规则(<b>事件监听器入口</b>)。
*
* <p>供「审核通过」事件监听器直接调用:内部自行查库取主表与明细,
* 调用方只需传 listingId,无需关心查询与组装细节。</p>
*
* <p>使用 {@link Propagation#REQUIRES_NEW} 独立事务查询:
* 事件由审批事务内发布时,独立事务可避免复用尚未提交的数据连接,
* 也能读到审批提交后的最新状态。</p>
*
* <p>整体 best-effort:查库失败或 D+ 发布失败都只记日志并返回 {@code false},
* 不抛异常,保证不影响调用方(事件监听器)的处理流程。</p>
*
* @param listingId 门店上架记录ID
* @param operator 操作人,写入对账规则的 updatedBy
* @return 是否发布成功
*/
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public boolean publishByListingId(Long listingId, String operator) {
try {
StoreListing listing = storeListingMapper.selectOne(new LambdaQueryWrapper<StoreListing>()
.eq(StoreListing::getListingId, listingId)
.eq(StoreListing::getIsDeleted, 0));
if (listing == null) {
log.warn("门店上架记录不存在,跳过对账规则发布, listingId={}", listingId);
return false;
}
List<StoreListingItem> items = storeListingItemMapper.selectList(new LambdaQueryWrapper<StoreListingItem>()
.eq(StoreListingItem::getListingId, listingId)
.eq(StoreListingItem::getIsDeleted, 0));
boolean published = publish(listing, items, operator);
if (published) {
log.info("对账规则发布成功, listingId={}, merchantNo={}, baseSceneCode={}, 明细行数={}",
listingId, listing.getMerchantNo(), listing.getBusinessSceneCode(), items.size());
} else {
log.warn("对账规则发布失败,需人工补发, listingId={}, merchantNo={}, baseSceneCode={}",
listingId, listing.getMerchantNo(), listing.getBusinessSceneCode());
}
return published;
} catch (Exception e) {
// 兜底:发布失败绝不冒泡到调用方
log.error("对账规则发布异常, listingId={}", listingId, e);
return false;
}
}
/** /**
* 发布某条门店上架的对账规则。 * 发布某条门店上架的对账规则。
* *
......
...@@ -23,7 +23,6 @@ import com.youjia.store.mapper.StoreChangeLogMapper; ...@@ -23,7 +23,6 @@ import com.youjia.store.mapper.StoreChangeLogMapper;
import com.youjia.store.mapper.StoreListingItemMapper; import com.youjia.store.mapper.StoreListingItemMapper;
import com.youjia.store.mapper.StoreListingMapper; import com.youjia.store.mapper.StoreListingMapper;
import com.youjia.store.remote.StorePartnerMerchantSyncer; import com.youjia.store.remote.StorePartnerMerchantSyncer;
import com.youjia.store.service.ReconciliationRulePublishService;
import com.youjia.store.service.StoreApprovalService; import com.youjia.store.service.StoreApprovalService;
import com.youjia.store.support.StoreApprovalConfig; import com.youjia.store.support.StoreApprovalConfig;
import com.youjia.store.support.StoreListingAssembler; import com.youjia.store.support.StoreListingAssembler;
...@@ -56,7 +55,6 @@ public class StoreApprovalServiceImpl implements StoreApprovalService { ...@@ -56,7 +55,6 @@ public class StoreApprovalServiceImpl implements StoreApprovalService {
private final StoreApprovalConfig storeApprovalConfig; private final StoreApprovalConfig storeApprovalConfig;
private final DataScopeHelper dataScopeHelper; private final DataScopeHelper dataScopeHelper;
private final StorePartnerMerchantSyncer storePartnerMerchantSyncer; private final StorePartnerMerchantSyncer storePartnerMerchantSyncer;
private final ReconciliationRulePublishService reconciliationRulePublishService;
@Override @Override
public PageResult<StoreApprovalTaskVO> pagePending(StoreApprovalTaskQueryDTO query) { public PageResult<StoreApprovalTaskVO> pagePending(StoreApprovalTaskQueryDTO query) {
...@@ -149,32 +147,14 @@ public class StoreApprovalServiceImpl implements StoreApprovalService { ...@@ -149,32 +147,14 @@ public class StoreApprovalServiceImpl implements StoreApprovalService {
StoreStatusEnum.PENDING.getCode(), StoreStatusEnum.APPROVED.getCode(), "审批通过"); StoreStatusEnum.PENDING.getCode(), StoreStatusEnum.APPROVED.getCode(), "审批通过");
log.info("门店上架审批通过:listingId={}, 门店={}, 场景={}", log.info("门店上架审批通过:listingId={}, 门店={}, 场景={}",
listing.getListingId(), listing.getStoreName(), listing.getBusinessScene()); listing.getListingId(), listing.getStoreName(), listing.getBusinessScene());
// 终审通过后发布对账规则(best-effort,失败仅告警不回滚审批) // 对账规则发布由「审核通过」事件监听器处理(publishByListingId),
publishReconciliationRule(listing); // 此处不直接调用,避免审批流程与外部接口耦合。
storePartnerMerchantSyncer.syncPartnerMerchant( storePartnerMerchantSyncer.syncPartnerMerchant(
listing.getMerchantNo(), listing.getBusinessSceneCode(), CurrentUserHolder.getName()); listing.getMerchantNo(), listing.getBusinessSceneCode(), CurrentUserHolder.getName());
// TODO 接入企业微信通知发起人 // TODO 接入企业微信通知发起人
} }
} }
/**
* 发布对账规则:按 listingId 查明细,组装后交由 ReconciliationRulePublishService 调用 D+ 接口。
*
* <p>明细查询显式过滤 is_deleted = 0,避免把已软删除的品类行带入规则。</p>
*/
private void publishReconciliationRule(StoreListing listing) {
List<StoreListingItem> items = storeListingItemMapper.selectList(
new LambdaQueryWrapper<StoreListingItem>()
.eq(StoreListingItem::getListingId, listing.getListingId())
.eq(StoreListingItem::getIsDeleted, 0));
String operator = CurrentUserHolder.getName();
boolean published = reconciliationRulePublishService.publish(listing, items, operator);
if (!published) {
log.warn("门店上架对账规则发布失败,需人工补发, listingId={}, merchantNo={}, businessScene={}",
listing.getListingId(), listing.getMerchantNo(), listing.getBusinessScene());
}
}
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void reject(StoreApprovalActionDTO dto) { public void reject(StoreApprovalActionDTO dto) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!