Commit e758cd08 by 章家宝

feat(store):门店审批通过之后同步门店成本

1 parent d1726bc8
package com.youjia.store.listener;
import com.youjia.store.event.StoreApprovalPassedEvent;
import com.youjia.store.remote.StoreCostSyncer;
import com.youjia.store.remote.StorePartnerMerchantSyncer;
import com.youjia.store.service.ReconciliationRulePublishService;
import lombok.RequiredArgsConstructor;
......@@ -22,11 +23,14 @@ public class StoreApprovalPassedListener {
private final StorePartnerMerchantSyncer storePartnerMerchantSyncer;
private final StoreCostSyncer storeCostSyncer;
private final ReconciliationRulePublishService reconciliationRulePublishService;
@EventListener
public void onApprovalPassed(StoreApprovalPassedEvent event) {
syncPartnerMerchant(event);
syncCost(event);
publishReconciliationRule(event);
// TODO 接入企业微信通知发起人
// notifySubmitter(event);
......@@ -44,6 +48,19 @@ public class StoreApprovalPassedListener {
}
}
private void syncCost(StoreApprovalPassedEvent event) {
try {
storeCostSyncer.syncCost(
event.getListingId(),
event.getMerchantNo(),
event.getBusinessSceneCode(),
event.getApproveUserName());
} catch (Exception e) {
log.error("审批通过后同步成本失败:listingId={}, merchantNo={}",
event.getListingId(), event.getMerchantNo(), e);
}
}
/**
* 发布对账规则:以事件中的 listingId 为准,回查门店上架主表与明细后调用 D+ 接口。
*
......
package com.youjia.store.remote;
import com.fasterxml.jackson.core.type.TypeReference;
import com.youjia.common.core.ResultCode;
import com.youjia.common.exception.BusinessException;
import com.youjia.framework.rop.RopClient;
import com.youjia.framework.rop.RopProperties;
import com.youjia.store.entity.StoreListing;
import com.youjia.store.mapper.StoreListingMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import java.math.BigDecimal;
/**
* 审批通过后同步门店运营成本至 D+ smartcarlife。
*
* <p>将优加侧的「装修、设备总投入」和「其他费用/月」同步到 smartcarlife 的
* dj_car_life_merchant_store_info 表,使 queryMerchantDetail 可查到最新值。</p>
*/
@Slf4j
@Component
@RequiredArgsConstructor
public class StoreCostSyncer {
private static final String METHOD_UPDATE_MERCHANT_COST =
"dj.api.scenemerchantref.updateMerchantCost";
private final RopClient ropClient;
private final StoreListingMapper storeListingMapper;
/**
* 同步门店成本到 smartcarlife。
*
* @param listingId 门店上架记录 ID
* @param merchantNo 门店商户号(对应 smartcarlife 的 traffic_party_id)
* @param businessSceneCode 业务场景编码(对应 smartcarlife 的 base_scene_code)
* @param operatorName 操作人(审批人姓名)
*/
public void syncCost(Long listingId, String merchantNo, String businessSceneCode, String operatorName) {
StoreListing listing = storeListingMapper.selectById(listingId);
if (listing == null) {
log.warn("[成本同步] 门店上架记录不存在,listingId={}", listingId);
return;
}
BigDecimal costDecoration = listing.getCostDecoration();
BigDecimal costMonthly = listing.getCostMonthly();
if (costDecoration == null && costMonthly == null) {
log.info("[成本同步] 成本均为空,跳过 listingId={}, merchantNo={}", listingId, merchantNo);
return;
}
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("merchantId", merchantNo);
params.add("baseSceneCode", businessSceneCode);
if (costDecoration != null) {
params.add("renovationEquipmentCost", costDecoration.toPlainString());
}
if (costMonthly != null) {
params.add("otherCostPerMonth", costMonthly.toPlainString());
}
params.add("updatedBy", operatorName != null ? operatorName : "system");
try {
Boolean result = ropClient.invokeForResult(
RopProperties.APP_SMARTCARLIFE,
METHOD_UPDATE_MERCHANT_COST,
params,
new TypeReference<Boolean>() {});
log.info("[成本同步] 成功 listingId={}, merchantNo={}, costDecoration={}, costMonthly={}, result={}",
listingId, merchantNo, costDecoration, costMonthly, result);
} catch (BusinessException e) {
log.error("[成本同步] 失败 listingId={}, merchantNo={}, error={}",
listingId, merchantNo, e.getMessage(), e);
throw new BusinessException(ResultCode.REMOTE_CALL_FAILED, "成本同步失败:" + e.getMessage());
}
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!