Commit 0776bd03 by 程裕兵

feat:sub channel config

parent f582ba88
......@@ -5,7 +5,6 @@ import com.jiejing.common.config.idgen.EnableLeaseIdWorker;
import com.jiejing.filecenter.api.common.event.ResourceEvent;
import com.jiejing.fitness.finance.service.event.ListenerService;
import com.jiejing.paycenter.common.event.MerchantEvent;
import com.jiejing.paycenter.common.event.MerchantSubChannelConfigEvent;
import com.jiejing.paycenter.common.event.PayEvent;
import com.xiaomai.event.annotation.EnableEventBinding;
import com.xiaomai.event.annotation.EventConfig;
......@@ -29,8 +28,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
@EnableEventBinding(
configs = {
@EventConfig(event = PayEvent.class, binder = "biz-kafka"),
@EventConfig(event = MerchantEvent.class, binder = "biz-kafka"),
@EventConfig(event = MerchantSubChannelConfigEvent.class, binder = "biz-kafka")
@EventConfig(event = MerchantEvent.class, binder = "biz-kafka")
},
listenerClass = {ListenerService.class})
@EnableFeignClients(basePackages = {
......
/*
* Copyright © 2024 Hangzhou Jiejing Technology Co., Ltd. All rights reserved.
*
* The copyright of the company's program code belongs to Hangzhou Jiejing Technology Co., Ltd. No one can illegally copy it without the explicit permission of this website.
* Official website: www.xiaomai5.com
*
*
*
* Copyright © 2024 杭州杰竞科技有限公司 版权所有.
*
* 本公司程序代码的版权归杭州杰竞科技有限公司所有,未经本网站的明确许可,任何人不得非法复制。
* 官网: www.xiaomai5.com
*/
package com.jiejing.fitness.finance.repository.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.jiejing.paycenter.common.enums.common.OpenStateEnums;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
/**
* <p>
* 品牌商户绑定微信appId申请表
* </p>
*
* @author chengyubing, created on 2024-02-26
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Builder(toBuilder = true)
@NoArgsConstructor
@AllArgsConstructor
public class BrandBindWxAppIdApply implements Serializable {
private static final long serialVersionUID = -9166678474448013070L;
/**
* 备注: 主键 是否允许为null: NO
*/
@TableId(value = "id", type = IdType.ID_WORKER)
private Long id;
/**
* 备注: 品牌ID 是否允许为null: YES
*/
private Long brandId;
/**
* 备注: 商户ID 是否允许为null: YES
*/
private Long merchantId;
/**
* 备注: appID 是否允许为null: YES
*/
private String appId;
/**
* 备注: 申请单号 是否允许为null: YES
*/
private String applyNo;
/**
* 备注: 申请状态 是否允许为null: YES
*/
private OpenStateEnums state;
/**
* 失败原因
*/
private String failMessage;
/**
* 备注: 创建时间 是否允许为null: YES
*/
private Date createTime;
/**
* 备注: 更新时间 是否允许为null: YES
*/
private Date updateTime;
public static final String ID = "id";
public static final String BRAND_ID = "brand_id";
public static final String MERCHANT_ID = "merchant_id";
public static final String APP_ID = "app_id";
public static final String APPLY_NO = "apply_no";
public static final String STATE = "state";
public static final String FAIL_MESSAGE = "fail_message";
public static final String CREATE_TIME = "create_time";
public static final String UPDATE_TIME = "update_time";
}
/*
* Copyright © 2024 Hangzhou Jiejing Technology Co., Ltd. All rights reserved.
*
* The copyright of the company's program code belongs to Hangzhou Jiejing Technology Co., Ltd. No one can illegally copy it without the explicit permission of this website.
* Official website: www.xiaomai5.com
*
*
*
* Copyright © 2024 杭州杰竞科技有限公司 版权所有.
*
* 本公司程序代码的版权归杭州杰竞科技有限公司所有,未经本网站的明确许可,任何人不得非法复制。
* 官网: www.xiaomai5.com
*/
package com.jiejing.fitness.finance.repository.mapper;
import com.jiejing.fitness.finance.repository.entity.BrandBindWxAppIdApply;
import com.jiejing.mbp.inject.XBaseMapper;
import org.apache.ibatis.annotations.Param;
/**
* <p>
* 品牌商户绑定微信appId申请表 Mapper 接口
* </p>
*
* @author chengyubing, created on 2024-02-26
*/
public interface BrandBindWxAppIdApplyMapper extends XBaseMapper<BrandBindWxAppIdApply> {
BrandBindWxAppIdApply selectLatestSuccess(@Param("merchantId") Long merchantId,
@Param("appId") String appId);
BrandBindWxAppIdApply selectLatestOne(@Param("merchantId") Long merchantId,
@Param("appId") String appId);
}
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright © 2024 Hangzhou Jiejing Technology Co., Ltd. All rights reserved.
~
~ The copyright of the company's program code belongs to Hangzhou Jiejing Technology Co., Ltd. No one can illegally copy it without the explicit permission of this website.
~ Official website: www.xiaomai5.com
~
~
~
~ Copyright © 2024 杭州杰竞科技有限公司 版权所有.
~
~ 本公司程序代码的版权归杭州杰竞科技有限公司所有,未经本网站的明确许可,任何人不得非法复制。
~ 官网: www.xiaomai5.com
-->
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.jiejing.fitness.finance.repository.mapper.BrandBindWxAppIdApplyMapper">
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id, brand_id, merchant_id, app_id, apply_no, state, fail_message, create_time, update_time
</sql>
<select id="selectLatestSuccess"
resultType="com.jiejing.fitness.finance.repository.entity.BrandBindWxAppIdApply">
select *
from brand_bind_wx_app_id_apply
where merchant_id = #{merchantId}
and app_id = #{appId}
and state = 'S'
order by id desc
limit 1;
</select>
<select id="selectLatestOne"
resultType="com.jiejing.fitness.finance.repository.entity.BrandBindWxAppIdApply">
select *
from brand_bind_wx_app_id_apply
where merchant_id = #{merchantId}
and app_id = #{appId}
order by id desc
limit 1;
</select>
</mapper>
/*
* Copyright © 2024 Hangzhou Jiejing Technology Co., Ltd. All rights reserved.
*
* The copyright of the company's program code belongs to Hangzhou Jiejing Technology Co., Ltd. No one can illegally copy it without the explicit permission of this website.
* Official website: www.xiaomai5.com
*
*
*
* Copyright © 2024 杭州杰竞科技有限公司 版权所有.
*
* 本公司程序代码的版权归杭州杰竞科技有限公司所有,未经本网站的明确许可,任何人不得非法复制。
* 官网: www.xiaomai5.com
*/
package com.jiejing.fitness.finance.repository.service;
import com.jiejing.fitness.finance.repository.entity.BrandBindWxAppIdApply;
import com.jiejing.fitness.finance.repository.mapper.BrandBindWxAppIdApplyMapper;
import com.jiejing.mbp.MapperRepoService;
import org.springframework.stereotype.Service;
/**
* <p>
* 品牌商户绑定微信appId申请表 服务实现类
* </p>
*
* @author chengyubing, created on 2024-02-26
*/
@Service
public class BrandBindWxAppIdApplyRpService extends
MapperRepoService<Long, BrandBindWxAppIdApply, BrandBindWxAppIdApplyMapper> {
public BrandBindWxAppIdApply getLatestSuccessByMerchantIdAndAppId(Long merchantId, String appId) {
return this.baseMapper.selectLatestSuccess(merchantId, appId);
}
public BrandBindWxAppIdApply getLatestByMerchantIdAndAppId(Long merchantId, String appId) {
return this.baseMapper.selectLatestOne(merchantId, appId);
}
}
......@@ -7,7 +7,6 @@ import com.jiejing.fitness.finance.api.enums.MerchantTypeEnums;
import com.jiejing.fitness.finance.service.merchant.BrandMerchantService;
import com.jiejing.fitness.finance.service.pay.PayService;
import com.jiejing.paycenter.common.event.MerchantEvent;
import com.jiejing.paycenter.common.event.MerchantSubChannelConfigEvent;
import com.jiejing.paycenter.common.event.PayEvent;
import com.xiaomai.event.annotation.EventHandler;
import java.util.ArrayList;
......@@ -66,17 +65,4 @@ public class ListenerService {
}
}
@EventHandler(value = MerchantSubChannelConfigEvent.class, binder = "biz-kafka", maxAttempts = MAX_RETRY)
public void handleMerchantSubChannelConfigEvent(MerchantSubChannelConfigEvent event,
@Header(DELIVERY_ATTEMPT) int retryNum) {
try {
log.info("start process merchant sub channel config event {}, {}", event.getApplyNo(),
event.getMerchantId());
brandMerchantService.bindXcxAppIdCallback(event);
} catch (Exception e) {
log.info("merchant sub channel config event callback process fail {}", JSON.toJSONString(event), e);
}
}
}
......@@ -10,7 +10,6 @@ import com.jiejing.fitness.finance.service.merchant.params.PageBrandMerchantAppl
import com.jiejing.paycenter.common.enums.merchant.SubChannelAuthTypeEnums;
import com.jiejing.paycenter.common.enums.merchant.SubChannelEnums;
import com.jiejing.paycenter.common.event.MerchantEvent;
import com.jiejing.paycenter.common.event.MerchantSubChannelConfigEvent;
import java.util.List;
/**
......@@ -78,13 +77,6 @@ public interface BrandMerchantService {
BrandMerchantBindXcxAppIdVO checkBindXcxAppId(Long brandId, String appId);
/**
* 绑定小程序AppId回调
*
* @param event 事件
*/
void bindXcxAppIdCallback(MerchantSubChannelConfigEvent event);
/**
* 授权子渠道
*
* @param brandId 品牌ID
......
......@@ -3,7 +3,6 @@ package com.jiejing.fitness.finance.service.merchant.convert;
import static com.jiejing.paycenter.common.enums.merchant.ResourceTypeEnums.*;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.jiejing.common.utils.convert.BeanUtil;
import com.jiejing.common.utils.crypt.AesUtil;
import com.jiejing.filecenter.api.resource.vo.ResourceInfoVO;
......@@ -17,7 +16,6 @@ import com.jiejing.fitness.finance.api.merchant.model.BrandResourceInfo;
import com.jiejing.fitness.finance.api.merchant.vo.BrandMerchantApplyVO;
import com.jiejing.fitness.finance.api.merchant.vo.BrandMerchantBindXcxAppIdVO;
import com.jiejing.fitness.finance.api.merchant.vo.BrandMerchantVO;
import com.jiejing.fitness.finance.repository.entity.BrandBindWxAppIdApply;
import com.jiejing.fitness.finance.repository.entity.BrandMerchantApply;
import com.jiejing.fitness.finance.repository.entity.BrandToMerchant;
import com.jiejing.fitness.finance.service.merchant.params.ApplyBrandMerchantParams;
......@@ -33,7 +31,6 @@ import com.jiejing.paycenter.common.enums.merchant.SceneTypeEnums;
import com.jiejing.paycenter.common.enums.merchant.SubChannelAuthTypeEnums;
import com.jiejing.paycenter.common.enums.merchant.SubChannelOpenTypeEnums;
import com.jiejing.paycenter.common.event.MerchantEvent;
import com.jiejing.paycenter.common.event.MerchantSubChannelConfigEvent;
import com.jiejing.paycenter.common.model.Address;
import com.jiejing.paycenter.common.model.BankCard;
import com.jiejing.paycenter.common.model.BusinessInfo;
......@@ -42,6 +39,7 @@ import com.jiejing.paycenter.common.model.Legal;
import com.jiejing.paycenter.common.model.License;
import com.jiejing.paycenter.common.model.ResourceInfo;
import com.jiejing.paycenter.common.model.SubChannelAuthInfo;
import com.jiejing.paycenter.common.model.SubChannelConfigInfo;
import com.jiejing.paycenter.common.model.SubChannelInfo;
import com.jiejing.studio.api.studio.vo.StudioVO;
import java.util.ArrayList;
......@@ -474,32 +472,13 @@ public class MerchantConvert {
.collect(Collectors.toList());
}
public static BrandBindWxAppIdApply convertBrandBindWxAppIdApply(BrandToMerchant relation, String appId) {
Long id = IdWorker.getId();
return BrandBindWxAppIdApply.builder()
.id(id)
.applyNo(id.toString())
.brandId(relation.getBrandId())
.merchantId(relation.getMerchantId())
.appId(appId)
.state(OpenStateEnums.INIT)
.createTime(new Date())
.updateTime(new Date())
.build();
}
public static BrandMerchantBindXcxAppIdVO convertBrandBindWxAppIdApply(BrandBindWxAppIdApply apply) {
return BrandMerchantBindXcxAppIdVO.builder().state(apply.getState()).failMessage(apply.getFailMessage())
.build();
}
public static BrandBindWxAppIdApply convertBrandBindWxAppIdApply(BrandBindWxAppIdApply apply,
OpenStateEnums state, String failMessage) {
return BrandBindWxAppIdApply.builder()
.id(apply.getId())
.state(state)
.failMessage(failMessage)
.updateTime(new Date())
public static BrandMerchantBindXcxAppIdVO convertBrandBindWxAppIdApply(
List<SubChannelConfigInfo> configs, String appId) {
SubChannelConfigInfo config = Optional.ofNullable(configs).orElse(new ArrayList<>(1)).stream()
.filter(e -> e.getAppId().equals(appId)).findFirst().orElse(new SubChannelConfigInfo());
return BrandMerchantBindXcxAppIdVO.builder()
.state(config.getState())
.failMessage(config.getFailMessage())
.build();
}
}
......@@ -11,12 +11,10 @@ import com.jiejing.fitness.finance.api.merchant.vo.BrandMerchantApplyVO;
import com.jiejing.fitness.finance.api.merchant.vo.BrandMerchantAuthSubChannelVO;
import com.jiejing.fitness.finance.api.merchant.vo.BrandMerchantBindXcxAppIdVO;
import com.jiejing.fitness.finance.api.merchant.vo.BrandMerchantVO;
import com.jiejing.fitness.finance.repository.entity.BrandBindWxAppIdApply;
import com.jiejing.fitness.finance.repository.entity.BrandMerchantApply;
import com.jiejing.fitness.finance.repository.entity.BrandToMerchant;
import com.jiejing.fitness.finance.repository.entity.GlobalConfig;
import com.jiejing.fitness.finance.repository.query.PageBrandMerchantApplyQuery;
import com.jiejing.fitness.finance.repository.service.BrandBindWxAppIdApplyRpService;
import com.jiejing.fitness.finance.repository.service.BrandMerchantApplyRpService;
import com.jiejing.fitness.finance.repository.service.BrandToMerchantRpService;
import com.jiejing.fitness.finance.repository.service.GlobalConfigRpService;
......@@ -38,18 +36,14 @@ import com.jiejing.paycenter.common.enums.merchant.ResourceTypeEnums;
import com.jiejing.paycenter.common.enums.merchant.SubChannelAuthTypeEnums;
import com.jiejing.paycenter.common.enums.merchant.SubChannelEnums;
import com.jiejing.paycenter.common.event.MerchantEvent;
import com.jiejing.paycenter.common.event.MerchantSubChannelConfigEvent;
import com.jiejing.paycenter.common.model.ResourceInfo;
import com.jiejing.paycenter.common.model.SubChannelAuthInfo;
import com.jiejing.paycenter.common.model.SubChannelConfigInfo;
import com.jiejing.paycenter.common.model.SubChannelInfo;
import com.jiejing.studio.api.studio.vo.StudioVO;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
......@@ -89,9 +83,6 @@ public class BrandMerchantServiceImpl implements BrandMerchantService {
private BrandToMerchantRpService brandToMerchantRpService;
@Resource
private BrandBindWxAppIdApplyRpService brandBindWxAppIdApplyRpService;
@Resource
private GlobalConfigRpService globalConfigRpService;
......@@ -170,20 +161,9 @@ public class BrandMerchantServiceImpl implements BrandMerchantService {
@Override
public BrandMerchantBindXcxAppIdVO bindXcxAppId(Long brandId, String appId) {
BrandToMerchant relation = brandToMerchantRpService.getByBrandId(brandId);
BrandBindWxAppIdApply latest = brandBindWxAppIdApplyRpService.getLatestSuccessByMerchantIdAndAppId(
relation.getMerchantId(), appId);
if (null != latest) {
throw new BizException(FinanceErrorEnums.BIZ_ERROR,
new JSONObject().fluentPut("message", "appId已绑定"));
}
BrandBindWxAppIdApply apply = MerchantConvert.convertBrandBindWxAppIdApply(relation, appId);
brandBindWxAppIdApplyRpService.insert(apply);
ConfigSubChannelVO vo = merchantRpcService.bindAppIdWxXcxOffline(channel, apply.getApplyNo(),
ConfigSubChannelVO vo = merchantRpcService.bindAppIdWxXcxOffline(channel, IdWorker.getIdStr(),
relation.getMerchantId(), appId);
BrandBindWxAppIdApply toModify = MerchantConvert.convertBrandBindWxAppIdApply(apply, vo.getState(),
vo.getFailMessage());
brandBindWxAppIdApplyRpService.updateById(toModify);
return BrandMerchantBindXcxAppIdVO.builder().state(vo.getState()).failMessage(vo.getFailMessage())
.build();
......@@ -192,21 +172,8 @@ public class BrandMerchantServiceImpl implements BrandMerchantService {
@Override
public BrandMerchantBindXcxAppIdVO checkBindXcxAppId(Long brandId, String appId) {
BrandToMerchant relation = brandToMerchantRpService.getByBrandId(brandId);
BrandBindWxAppIdApply latest = brandBindWxAppIdApplyRpService.getLatestByMerchantIdAndAppId(
relation.getMerchantId(), appId);
return MerchantConvert.convertBrandBindWxAppIdApply(latest);
}
@Override
public void bindXcxAppIdCallback(MerchantSubChannelConfigEvent event) {
BrandBindWxAppIdApply apply = brandBindWxAppIdApplyRpService.getById(Long.parseLong(event.getApplyNo()))
.orElse(null);
if (null == apply) {
return;
}
BrandBindWxAppIdApply toModify = MerchantConvert.convertBrandBindWxAppIdApply(apply, event.getState(),
event.getFailMessage());
brandBindWxAppIdApplyRpService.updateById(toModify);
MerchantVO merchant = merchantRpcService.getByMerchantId(relation.getMerchantId());
return MerchantConvert.convertBrandBindWxAppIdApply(merchant.getSubChannelConfigs(), appId);
}
@Override
......
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