Commit 18033f54 by 程裕兵

feat:bind when open merchant success

parent 9b9683d9
......@@ -21,6 +21,7 @@ import com.jiejing.fitness.finance.repository.entity.PartyToMerchant;
import com.jiejing.fitness.finance.repository.mapper.PartyToMerchantMapper;
import com.jiejing.mbp.MapperRepoService;
import java.util.List;
import java.util.Set;
import org.springframework.stereotype.Service;
/**
......@@ -97,4 +98,18 @@ public class PartyToMerchantRpService extends
wrapper.eq(PartyToMerchant.PARTY_TYPE, partyType.getCode());
this.baseMapper.delete(wrapper);
}
public void deleteByMerchantIds(Set<Long> merchantIds, PartyTypeEnum partyType) {
QueryWrapper<PartyToMerchant> wrapper = new QueryWrapper<>();
wrapper.in(PartyToMerchant.MERCHANT_ID, merchantIds);
wrapper.eq(PartyToMerchant.PARTY_TYPE, partyType.getCode());
this.baseMapper.delete(wrapper);
}
public void deleteByMerchantIds(Set<Long> merchantIds) {
QueryWrapper<PartyToMerchant> wrapper = new QueryWrapper<>();
wrapper.in(PartyToMerchant.MERCHANT_ID, merchantIds);
this.baseMapper.delete(wrapper);
}
}
......@@ -148,13 +148,17 @@ public class StudioMerchantApplyRpService extends
}
public StudioMerchantApply getLatestSuccessApply(Long studioId) {
return this.listSuccessApplyByStudioId(studioId).stream().findFirst().orElse(null);
}
public List<StudioMerchantApply> listSuccessApplyByStudioId(Long studioId) {
QueryWrapper<StudioMerchantApply> wrapper = new QueryWrapper<>();
wrapper.eq(StudioMerchantApply.STUDIO_ID, studioId);
wrapper.in(StudioMerchantApply.APPLY_TYPE,
Lists.newArrayList(ApplyTypeEnum.OPEN.getCode(), ApplyTypeEnum.RE_OPEN.getCode()));
wrapper.eq(StudioMerchantApply.OPEN_STATE, OpenStateEnums.SUCCESS.getCode());
wrapper.orderByDesc(StudioMerchantApply.ID);
return Optional.ofNullable(this.baseMapper.selectList(wrapper)).orElse(new ArrayList<>(1)).stream()
.findFirst().orElse(null);
return Optional.ofNullable(this.baseMapper.selectList(wrapper)).orElse(new ArrayList<>(1));
}
}
......@@ -3,6 +3,7 @@ package com.jiejing.fitness.finance.service.merchant;
import com.jiejing.fitness.finance.api.merchant.vo.BrandMerchantVO;
import com.jiejing.fitness.finance.api.merchant.vo.StudioMerchantVO;
import java.util.List;
import java.util.Set;
/**
* 品牌商户服务
......@@ -28,6 +29,14 @@ public interface BrandMerchantService {
*/
void unbind(Long brandId, Long merchantId);
/**
* 解绑
*
* @param merchantIds 商户ID
*/
void unbindAll(Set<Long> merchantIds);
/**
* 查看品牌绑定的所有商户
*
......
......@@ -11,6 +11,7 @@ import com.jiejing.paycenter.common.enums.merchant.SubChannelAuthTypeEnums;
import com.jiejing.paycenter.common.enums.merchant.SubChannelEnums;
import com.jiejing.paycenter.common.event.MerchantEvent;
import java.util.List;
import java.util.Set;
/**
* @author chengyubing
......@@ -50,6 +51,13 @@ public interface StudioMerchantService {
void unbindAll(Long merchantId);
/**
* 解绑绑定了指定商户的所有场馆
*
* @param merchantIds 商户ID
*/
void unbindAll(Set<Long> merchantIds);
/**
* 进件申请回调
*
* @param event 事件
......
package com.jiejing.fitness.finance.service.merchant.impl;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import com.jiejing.common.utils.collection.CollectionUtil;
import com.jiejing.fitness.enums.finance.PartyTypeEnum;
......@@ -18,6 +19,7 @@ import com.jiejing.paycenter.common.model.vo.MerchantVO;
import com.jiejing.studio.api.studio.vo.StudioVO;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
......@@ -72,6 +74,12 @@ public class BrandMerchantServiceImpl implements BrandMerchantService {
}
@Override
public void unbindAll(Set<Long> merchantIds) {
log.info("unbind all brand merchant {}", JSON.toJSONString(merchantIds));
partyToMerchantRpService.deleteByMerchantIds(merchantIds, PartyTypeEnum.BRAND);
}
@Override
public List<BrandMerchantVO> list(Long brandId) {
List<PartyToMerchant> relations = partyToMerchantRpService.listByParty(brandId, PartyTypeEnum.BRAND,
config.getCashier());
......
......@@ -56,6 +56,7 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.Executor;
import java.util.stream.Collectors;
import javax.annotation.Resource;
......@@ -164,6 +165,12 @@ public class StudioMerchantServiceImpl implements StudioMerchantService {
partyToMerchantRpService.deleteByMerchantId(merchantId, PartyTypeEnum.STUDIO);
}
@Override
public void unbindAll(Set<Long> merchantIds) {
log.info("unbind all studio of merchantIds {}", JSON.toJSONString(merchantIds));
partyToMerchantRpService.deleteByMerchantIds(merchantIds, PartyTypeEnum.STUDIO);
}
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
@Override
public void callback(MerchantEvent event) {
......@@ -358,35 +365,27 @@ public class StudioMerchantServiceImpl implements StudioMerchantService {
}
private Long unbindWhenOpenSuccess(StudioMerchantApply apply) {
PartyToMerchant old = this.getRelation(apply.getStudioId());
if (null == old) {
return null;
}
Long oldMerchantId = old.getMerchantId();
StudioMerchantApply exist = studioMerchantApplyRpService.getLatestOneSuccessByMerchantId(oldMerchantId);
log.info("current bound merchant of studio : {}, and the merchant is from studio : {}",
JSON.toJSONString(old), exist.getStudioId());
if (!exist.getStudioId().equals(apply.getStudioId())) {
// 之前绑定的商户不是自己的商户,不需要解绑
log.info("exist merchant no is not studio self {}, {}, {}", oldMerchantId, apply.getStudioId(),
exist.getStudioId());
return oldMerchantId;
private void unbindHistoryMerchant(StudioMerchantApply apply) {
List<StudioMerchantApply> histories = studioMerchantApplyRpService.listSuccessApplyByStudioId(
apply.getStudioId());
if (CollectionUtil.isEmpty(histories)) {
return;
}
// 1. 如果当前场馆绑定的是自己的商户号(old),则需要将绑定了该商户号的所有其他场馆进行解绑
this.unbindAll(oldMerchantId);
// 2. 场馆商户发生了变更,解绑掉绑定了老商户号的品牌
brandMerchantService.unbind(apply.getBrandId(), oldMerchantId);
Set<Long> historyMerchantIds = histories.stream().map(StudioMerchantApply::getMerchantId)
.collect(Collectors.toSet());
// 将绑定了当前场馆商户号的所有其他场馆/品牌进行解绑
partyToMerchantRpService.deleteByMerchantIds(historyMerchantIds);
return oldMerchantId;
}
private void bindWhenOpenSuccess(MerchantEvent event, StudioMerchantApply apply) {
// 1. 解绑历史商户
Long oldMerchantId = this.unbindWhenOpenSuccess(apply);
Long oldMerchantId = Optional.ofNullable(this.getRelation(apply.getStudioId()))
.map(PartyToMerchant::getMerchantId).orElse(null);
// 1. 解绑该场馆进件的历史商户所关联的所有其他场馆和品牌
this.unbindHistoryMerchant(apply);
// 2. 绑定场馆
this.bind(apply.getStudioId(), event.getMerchantId(), false);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment