Commit b9adbffd by 程裕兵

feat:apply

parent 59644bd9
...@@ -78,7 +78,12 @@ public class BrandMerchantApply implements Serializable { ...@@ -78,7 +78,12 @@ public class BrandMerchantApply implements Serializable {
private String channelNo; private String channelNo;
/** /**
* 商户号 * 商户ID(pay center提供)
*/
private Long merchantId;
/**
* 三方商户号
*/ */
private String merchantNo; private String merchantNo;
...@@ -113,6 +118,11 @@ public class BrandMerchantApply implements Serializable { ...@@ -113,6 +118,11 @@ public class BrandMerchantApply implements Serializable {
private OpenStateEnums aliOpenState; private OpenStateEnums aliOpenState;
/** /**
* 支付宝认证状态
*/
private OpenStateEnums aliAuthState;
/**
* 支付宝商户号 * 支付宝商户号
*/ */
private String aliMerchantNo; private String aliMerchantNo;
...@@ -420,6 +430,8 @@ public class BrandMerchantApply implements Serializable { ...@@ -420,6 +430,8 @@ public class BrandMerchantApply implements Serializable {
public static final String CHANNEL_NO = "channel_no"; public static final String CHANNEL_NO = "channel_no";
public static final String MERCHANT_ID = "merchant_id";
public static final String MERCHANT_NO = "merchant_no"; public static final String MERCHANT_NO = "merchant_no";
public static final String MERCHANT_NAME = "merchant_name"; public static final String MERCHANT_NAME = "merchant_name";
...@@ -434,6 +446,8 @@ public class BrandMerchantApply implements Serializable { ...@@ -434,6 +446,8 @@ public class BrandMerchantApply implements Serializable {
public static final String ALI_OPEN_STATE = "ali_open_state"; public static final String ALI_OPEN_STATE = "ali_open_state";
public static final String ALI_AUTH_STATE = "ali_auth_state";
public static final String ALI_MERCHANT_NO = "ali_merchant_no"; public static final String ALI_MERCHANT_NO = "ali_merchant_no";
public static final String ALI_OPEN_FAIL_MESSAGE = "ali_open_fail_message"; public static final String ALI_OPEN_FAIL_MESSAGE = "ali_open_fail_message";
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
<!-- 通用查询结果列 --> <!-- 通用查询结果列 -->
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id, brand_id, studio_id, apply_no, apply_type, channel_no, merchant_no, merchant_name, short_name, company_type, open_state, open_fail_message, ali_open_state, ali_merchant_no, ali_open_fail_message, wx_offline_open_state, wx_offline_auth_state, wx_offline_merchant_no, wx_offline_open_fail_message, wx_online_open_state, wx_online_auth_state, wx_online_merchant_no, wx_online_open_fail_message, business_province, business_city, business_district, business_address, license_code, license_expire_type, license_start_date, license_end_date, license_business_scope, license_found_date, license_province, license_city, license_district, license_address, legal_name, legal_cert_no, legal_cert_type, legal_cert_expire_type, legal_cert_start_date, legal_cert_end_date, legal_phone, legal_province, legal_city, legal_district, legal_address, contact_email, bank_card_type, bank_card_no, bank_card_name, bank_phone, bank_cert_no, bank_cert_type, bank_cert_expire_type, bank_cert_start_date, bank_cert_end_date, bank_base_deposit_no, bank_code, bank_name, bank_branch_name, bank_branch_code, bank_card_province, bank_card_city, bank_card_district, bank_card_address, resource_info, salt, finish_time, create_time, update_time id, brand_id, studio_id, apply_no, apply_type, channel_no, merchant_id, merchant_no, merchant_name, short_name, company_type, open_state, open_fail_message, ali_open_state, ali_auth_state, ali_merchant_no, ali_open_fail_message, wx_offline_open_state, wx_offline_auth_state, wx_offline_merchant_no, wx_offline_open_fail_message, wx_online_open_state, wx_online_auth_state, wx_online_merchant_no, wx_online_open_fail_message, business_province, business_city, business_district, business_address, license_code, license_expire_type, license_start_date, license_end_date, license_business_scope, license_found_date, license_province, license_city, license_district, license_address, legal_name, legal_cert_no, legal_cert_type, legal_cert_expire_type, legal_cert_start_date, legal_cert_end_date, legal_phone, legal_province, legal_city, legal_district, legal_address, contact_email, bank_card_type, bank_card_no, bank_card_name, bank_phone, bank_cert_no, bank_cert_type, bank_cert_expire_type, bank_cert_start_date, bank_cert_end_date, bank_base_deposit_no, bank_code, bank_name, bank_branch_name, bank_branch_code, bank_card_province, bank_card_city, bank_card_district, bank_card_address, resource_info, salt, finish_time, create_time, update_time
</sql> </sql>
<select id="getLatestOneSuccessByBrandId" <select id="getLatestOneSuccessByBrandId"
......
/*
* 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.BrandMerchant;
import com.jiejing.mbp.inject.XBaseMapper;
/**
* <p>
* 品牌商户表(只保留最新在用的) Mapper 接口
* </p>
*
* @author chengyubing, created on 2024-02-22
*/
public interface BrandMerchantMapper extends XBaseMapper<BrandMerchant> {
}
<?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.BrandMerchantMapper">
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id, brand_id, channel_no, merchant_id, merchant_no, merchant_name, short_name, company_type, ali_auth_state, ali_merchant_no, wx_offline_auth_state, wx_offline_merchant_no, wx_online_auth_state, wx_online_merchant_no, business_province, business_city, business_district, business_address, license_code, license_expire_type, license_start_date, license_end_date, license_business_scope, license_found_date, license_registered_capital, license_province, license_city, license_district, license_address, legal_name, legal_cert_no, legal_cert_type, legal_cert_expire_type, legal_cert_start_date, legal_cert_end_date, legal_phone, legal_province, legal_city, legal_district, legal_address, contact_email, bank_card_type, bank_card_no, bank_card_name, bank_phone, bank_cert_no, bank_cert_type, bank_cert_expire_type, bank_cert_start_date, bank_cert_end_date, bank_base_deposit_no, bank_code, bank_name, bank_branch_name, bank_branch_code, bank_card_province, bank_card_city, bank_card_district, bank_card_address, resource_info, salt, finish_time, create_time, update_time
</sql>
</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.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jiejing.fitness.finance.repository.entity.BrandMerchant;
import com.jiejing.fitness.finance.repository.mapper.BrandMerchantMapper;
import com.jiejing.mbp.MapperRepoService;
import org.springframework.stereotype.Service;
/**
* <p>
* 品牌商户表(只保留最新在用的) 服务实现类
* </p>
*
* @author chengyubing, created on 2024-02-22
*/
@Service
public class BrandMerchantRpService extends MapperRepoService<Long, BrandMerchant, BrandMerchantMapper> {
public BrandMerchant getByBrandId(Long brandId) {
QueryWrapper<BrandMerchant> wrapper = new QueryWrapper<>();
wrapper.eq(BrandMerchant.BRAND_ID, brandId);
return this.baseMapper.selectOne(wrapper);
}
}
...@@ -51,7 +51,8 @@ public class GeneratorServiceEntity { ...@@ -51,7 +51,8 @@ public class GeneratorServiceEntity {
*/ */
private String author = "chengyubing"; private String author = "chengyubing";
private String[] tableNames = { private String[] tableNames = {
"brand_merchant_apply" // "brand_merchant_apply",
"brand_merchant"
}; };
/** /**
......
package com.jiejing.fitness.finance.service.enums;
import com.jiejing.common.exception.BaseBizError;
import lombok.Getter;
/**
* @author chengyubing
* @since 2024/2/21 14:54
*/
@Getter
public enum FinanceErrorEnums implements BaseBizError {
/**
* 三方异常
*/
PARAMS_ERROR("【参数错误】${message}"),
THIRD_ERROR("【三方异常】${message}"),
NOT_EXIST("数据不存在"),
NOT_SUPPORT_METHOD("不支持的方法"),
NOT_SUPPORT_TYPE("不支持的类型"),
NOT_SUPPORT_FILE_TYPE("不支持的文件类型"),
;
@Getter
private final String module = "PAY_CENTER";
@Getter
private final String code = name();
@Getter
private final String defaultMessage;
FinanceErrorEnums(String defaultMessage) {
this.defaultMessage = defaultMessage;
}
}
package com.jiejing.fitness.finance.service.enums;
import com.baomidou.mybatisplus.annotation.EnumValue;
import java.util.Arrays;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 商户业务类型
*
* @author raccoon
* @since 2020-11-06 16:44
*/
@Getter
@AllArgsConstructor
public enum MerchantTypeEnums {
/**
* 未知
*/
UNKNOWN("", ""),
/**
* 品牌
*/
BRAND("BRAND", "品牌"),
;
@EnumValue
private final String code;
private final String desc;
public static MerchantTypeEnums getByCode(String code) {
return Arrays.stream(MerchantTypeEnums.values()).filter(e -> e.getCode().equals(code)).findFirst()
.orElse(UNKNOWN);
}
}
package com.jiejing.fitness.finance.service.event;
import static org.springframework.integration.IntegrationMessageHeaderAccessor.DELIVERY_ATTEMPT;
import com.alibaba.fastjson.JSON;
import com.jiejing.fitness.finance.service.enums.MerchantTypeEnums;
import com.jiejing.fitness.finance.service.merchant.BrandMerchantService;
import com.jiejing.paycenter.common.event.MerchantEvent;
import com.xiaomai.event.annotation.EventHandler;
import java.util.ArrayList;
import java.util.Optional;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Service;
/**
* @author chengyubing
* @since 2024/2/21 14:30
*/
@Slf4j
@Service
public class ListenerService {
private static final int MAX_RETRY = 3;
@Resource
private BrandMerchantService brandMerchantService;
@EventHandler(value = MerchantEvent.class, binder = "biz-kafka", maxAttempts = MAX_RETRY)
public void handleMerchantEvent(MerchantEvent event, @Header(DELIVERY_ATTEMPT) int retryNum) {
try {
log.info("start process merchant event {}, {}, {}", event.getApplyNo(), event.getMerchantId(),
event.getMerchantNo());
event.setSubChannels(Optional.ofNullable(event.getSubChannels()).orElse(new ArrayList<>(1)));
event.setSubChannelAuths(Optional.ofNullable(event.getSubChannelAuths()).orElse(new ArrayList<>(1)));
MerchantTypeEnums merchantType = MerchantTypeEnums.getByCode(event.getBizCode());
switch (merchantType) {
case BRAND:
brandMerchantService.callback(event);
break;
default:
break;
}
} catch (Exception e) {
log.error("merchant event callback process fail {}", JSON.toJSONString(event));
}
}
}
package com.jiejing.fitness.finance.service.merchant; package com.jiejing.fitness.finance.service.merchant;
import com.jiejing.fitness.finance.service.merchant.params.ApplyBrandMerchantParams; import com.jiejing.fitness.finance.service.merchant.params.ApplyBrandMerchantParams;
import com.jiejing.paycenter.common.event.MerchantEvent;
/** /**
* 品牌商户服务 * 品牌商户服务
...@@ -17,4 +18,11 @@ public interface BrandMerchantService { ...@@ -17,4 +18,11 @@ public interface BrandMerchantService {
*/ */
void apply(ApplyBrandMerchantParams params); void apply(ApplyBrandMerchantParams params);
/**
* 进件申请回调
*
* @param event 事件
*/
void callback(MerchantEvent event);
} }
package com.jiejing.fitness.finance.service.merchant.impl; package com.jiejing.fitness.finance.service.merchant.impl;
import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.jiejing.common.exception.BizException;
import com.jiejing.filecenter.api.resource.vo.ResourceInfoVO; import com.jiejing.filecenter.api.resource.vo.ResourceInfoVO;
import com.jiejing.fitness.finance.repository.entity.BrandMerchant;
import com.jiejing.fitness.finance.repository.entity.BrandMerchantApply; import com.jiejing.fitness.finance.repository.entity.BrandMerchantApply;
import com.jiejing.fitness.finance.repository.service.BrandMerchantApplyRpService; import com.jiejing.fitness.finance.repository.service.BrandMerchantApplyRpService;
import com.jiejing.fitness.finance.repository.service.BrandMerchantRpService;
import com.jiejing.fitness.finance.service.enums.FinanceErrorEnums;
import com.jiejing.fitness.finance.service.merchant.BrandMerchantService; import com.jiejing.fitness.finance.service.merchant.BrandMerchantService;
import com.jiejing.fitness.finance.service.merchant.convert.MerchantConvert; import com.jiejing.fitness.finance.service.merchant.convert.MerchantConvert;
import com.jiejing.fitness.finance.service.merchant.params.ApplyBrandMerchantParams; import com.jiejing.fitness.finance.service.merchant.params.ApplyBrandMerchantParams;
...@@ -11,6 +15,7 @@ import com.jiejing.fitness.finance.service.rpc.MerchantRpcService; ...@@ -11,6 +15,7 @@ import com.jiejing.fitness.finance.service.rpc.MerchantRpcService;
import com.jiejing.fitness.finance.service.rpc.ResourceRpcService; import com.jiejing.fitness.finance.service.rpc.ResourceRpcService;
import com.jiejing.fitness.finance.service.rpc.StudioRpcService; import com.jiejing.fitness.finance.service.rpc.StudioRpcService;
import com.jiejing.paycenter.common.enums.common.OpenStateEnums; import com.jiejing.paycenter.common.enums.common.OpenStateEnums;
import com.jiejing.paycenter.common.event.MerchantEvent;
import com.jiejing.paycenter.common.model.ResourceInfo; import com.jiejing.paycenter.common.model.ResourceInfo;
import com.jiejing.studio.api.studio.vo.StudioVO; import com.jiejing.studio.api.studio.vo.StudioVO;
import java.util.List; import java.util.List;
...@@ -22,6 +27,8 @@ import lombok.extern.slf4j.Slf4j; ...@@ -22,6 +27,8 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
/** /**
* 品牌商户服务 * 品牌商户服务
...@@ -48,6 +55,10 @@ public class BrandMerchantServiceImpl implements BrandMerchantService { ...@@ -48,6 +55,10 @@ public class BrandMerchantServiceImpl implements BrandMerchantService {
@Resource @Resource
private BrandMerchantApplyRpService brandMerchantApplyRpService; private BrandMerchantApplyRpService brandMerchantApplyRpService;
@Resource
private BrandMerchantRpService brandMerchantRpService;
@Async(value = "financeThreadPool") @Async(value = "financeThreadPool")
@Override @Override
public void apply(ApplyBrandMerchantParams params) { public void apply(ApplyBrandMerchantParams params) {
...@@ -63,15 +74,52 @@ public class BrandMerchantServiceImpl implements BrandMerchantService { ...@@ -63,15 +74,52 @@ public class BrandMerchantServiceImpl implements BrandMerchantService {
try { try {
this.upload(params); this.upload(params);
merchantRpcService.apply(MerchantConvert.convertRequest(channel, apply.getApplyNo(), merchantRpcService.apply(MerchantConvert.convertRequest(channel, apply.getApplyNo(), params));
studio.getBrandId(), params));
} catch (Exception e) { } catch (Exception e) {
brandMerchantApplyRpService.updateById( log.error("apply brand merchant fail {}, brand id = {}, studio id = {}", id, studio.getBrandId(),
BrandMerchantApply.builder().id(id).openState(OpenStateEnums.FAIL) params.getStudioId(), e);
.openFailMessage(e.getMessage()).build()); this.doOpenMerchantFail(id, e.getMessage());
return;
} }
this.doOpenMerchantProcess(id);
}
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
@Override
public void callback(MerchantEvent event) {
switch (event.getState()) {
case PROCESS:
this.doOpenMerchantProcess(Long.parseLong(event.getApplyNo()));
break;
case FAIL:
this.doOpenMerchantFail(Long.parseLong(event.getApplyNo()), event.getFailMessage());
break;
case SUCCESS:
this.doOpenMerchantSuccess(event);
break;
default:
break;
}
}
private void doOpenMerchantSuccess(MerchantEvent event) {
BrandMerchantApply apply = brandMerchantApplyRpService.getByIdForUpdate(
Long.parseLong(event.getApplyNo())).orElseThrow(() -> new BizException(FinanceErrorEnums.NOT_EXIST));
BrandMerchantApply applyToModify = MerchantConvert.convertApply(apply, event);
if (OpenStateEnums.SUCCESS == applyToModify.getOpenState()) {
// 所有子通道全部开通成功
BrandMerchant exist = brandMerchantRpService.getByBrandId(apply.getBrandId());
if (null == exist) {
brandMerchantRpService.insert(MerchantConvert.convertMerchant(apply));
} else {
brandMerchantRpService.updateById(MerchantConvert.convertMerchant(apply));
}
}
brandMerchantApplyRpService.updateById(applyToModify);
} }
private void upload(ApplyBrandMerchantParams params) { private void upload(ApplyBrandMerchantParams params) {
...@@ -96,4 +144,15 @@ public class BrandMerchantServiceImpl implements BrandMerchantService { ...@@ -96,4 +144,15 @@ public class BrandMerchantServiceImpl implements BrandMerchantService {
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
private void doOpenMerchantFail(Long id, String failMessage) {
brandMerchantApplyRpService.updateById(
BrandMerchantApply.builder().id(id).openState(OpenStateEnums.FAIL)
.openFailMessage(failMessage).build());
}
private void doOpenMerchantProcess(Long id) {
brandMerchantApplyRpService.updateById(
BrandMerchantApply.builder().id(id).openState(OpenStateEnums.PROCESS).build());
}
} }
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