Commit 154710e5 by 程裕兵

feat:apply

parent 0efab09d
......@@ -67,4 +67,8 @@ public class ApplyStudioMerchantRequest {
@Valid
private Map<String, BrandResourceInfo> resourceMap;
@ApiModelProperty(value = "验证码", required = true)
@NotBlank(message = "验证码不能为空")
private String smsCode;
}
......@@ -37,6 +37,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
"com.jiejing.filecenter.api",
"com.jiejing.paycenter.api",
"com.jiejing.studio.api",
"com.jiejing.message.api",
})
@SpringBootApplication(scanBasePackages = "com.jiejing", exclude = {
DruidDataSourceAutoConfigure.class
......
......@@ -76,6 +76,11 @@
<artifactId>studio-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.jiejing.base</groupId>
<artifactId>message-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!-- ======================= jiejing api end ======================= -->
......
......@@ -15,11 +15,14 @@
package com.jiejing.fitness.finance.repository.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.collect.Lists;
import com.jiejing.common.utils.text.StringUtil;
import com.jiejing.fitness.finance.repository.entity.StudioMerchantApply;
import com.jiejing.fitness.finance.repository.mapper.StudioMerchantApplyMapper;
import com.jiejing.fitness.finance.repository.query.PageStudioMerchantApplyQuery;
import com.jiejing.mbp.MapperRepoService;
import com.jiejing.paycenter.common.enums.common.OpenStateEnums;
import java.util.Optional;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
......@@ -81,4 +84,13 @@ public class StudioMerchantApplyRpService extends
return this.baseMapper.getLatestOneSuccessByStudioId(studioId);
}
public Integer countProcessByStudioId(Long studioId) {
QueryWrapper<StudioMerchantApply> wrapper = new QueryWrapper<>();
wrapper.eq(StudioMerchantApply.STUDIO_ID, studioId);
wrapper.in(StudioMerchantApply.OPEN_STATE,
Lists.newArrayList(OpenStateEnums.PROCESS, OpenStateEnums.INIT));
Integer count = this.baseMapper.selectCount(wrapper);
return Optional.ofNullable(count).orElse(0);
}
}
......@@ -28,6 +28,10 @@
<artifactId>studio-api</artifactId>
</dependency>
<dependency>
<groupId>com.jiejing.base</groupId>
<artifactId>message-api</artifactId>
</dependency>
<dependency>
<groupId>com.jiejing.event</groupId>
<artifactId>scs-event</artifactId>
</dependency>
......
......@@ -16,12 +16,14 @@ public enum FinanceErrorEnums implements BaseBizError {
PARAMS_ERROR("【参数错误】${message}"),
THIRD_ERROR("【三方异常】${message}"),
BIZ_ERROR("【业务错误】${message}"),
REPEAT_SUBMIT("请勿重复提交"),
NOT_EXIST("数据不存在"),
NOT_SUPPORT_METHOD("不支持的方法"),
NOT_SUPPORT_TYPE("不支持的类型"),
CHANNEL_NOT_OPEN("未开通当前支付通道"),
MERCHANT_NOT_OPEN("未进件"),
NOT_SUPPORT_FILE_TYPE("不支持的文件类型"),
EXIST_PROCESS_APPLY("存在处理中的申请"),
;
@Getter
......
......@@ -62,16 +62,16 @@ import java.util.stream.Collectors;
*/
public class MerchantConvert {
public static ApplyMerchantRequest convertRequest(String channelNo, String applyNo,
ApplyStudioMerchantParams params, StudioVO studio, Map<ResourceTypeEnums, ResourceInfo> resourceMap,
public static ApplyMerchantRequest convertRequest(ApplyStudioMerchantParams params,
StudioMerchantApply apply, Map<ResourceTypeEnums, ResourceInfo> resourceMap,
SubChannelInfoDTO subChannelInfo) {
return ApplyMerchantRequest.builder()
.bizCode(PartyTypeEnum.STUDIO.getCode())
.applyNo(applyNo)
.channelNo(channelNo)
.companyType(params.getCompanyType())
.merchantName(params.getMerchantName())
.shortName(studio.getName())
.applyNo(apply.getApplyNo())
.channelNo(apply.getChannelNo())
.companyType(apply.getCompanyType())
.merchantName(apply.getMerchantName())
.shortName(apply.getShortName())
.legal(convertLegal(params))
.bankCard(convertBankCard(params))
.license(convertLicense(params))
......
......@@ -18,12 +18,14 @@ import com.jiejing.fitness.finance.repository.service.PartyToMerchantRpService;
import com.jiejing.fitness.finance.repository.service.StudioMerchantApplyRpService;
import com.jiejing.fitness.finance.service.enums.FinanceErrorEnums;
import com.jiejing.fitness.finance.service.global.ConfigService;
import com.jiejing.fitness.finance.service.global.dto.SubChannelInfoDTO;
import com.jiejing.fitness.finance.service.merchant.BrandMerchantService;
import com.jiejing.fitness.finance.service.merchant.StudioMerchantService;
import com.jiejing.fitness.finance.service.merchant.convert.MerchantConvert;
import com.jiejing.fitness.finance.service.merchant.params.ApplyStudioMerchantParams;
import com.jiejing.fitness.finance.service.merchant.params.PageStudioMerchantApplyParams;
import com.jiejing.fitness.finance.service.rpc.MerchantRpcService;
import com.jiejing.fitness.finance.service.rpc.MessageRpcService;
import com.jiejing.fitness.finance.service.rpc.ResourceRpcService;
import com.jiejing.fitness.finance.service.rpc.StudioRpcService;
import com.jiejing.paycenter.api.merchant.request.ApplyMerchantRequest;
......@@ -50,7 +52,6 @@ import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
......@@ -87,37 +88,39 @@ public class StudioMerchantServiceImpl implements StudioMerchantService {
@Resource
private ConfigService configService;
@Resource
private MessageRpcService messageRpcService;
@Resource(name = "financeThreadPool")
private Executor executor;
@Async(value = "financeThreadPool")
@Override
public Long apply(ApplyStudioMerchantParams params) {
Long id = IdWorker.getId();
StudioVO studio = studioRpcService.getStudio(params.getStudioId());
StudioMerchantApply exist = studioMerchantApplyRpService.getLatestOneSuccessByStudioId(studio.getId());
StudioMerchantApply apply = MerchantConvert.convertApply(id, params, studio, exist, channel);
this.checkBeforeApply(params);
studioMerchantApplyRpService.insert(apply);
StudioMerchantApply apply = this.saveApply(params);
executor.execute(() -> {
try {
Map<ResourceTypeEnums, ResourceInfo> resourceMap = this.upload(params);
ApplyMerchantRequest request = MerchantConvert.convertRequest(channel, apply.getApplyNo(), params,
studio, resourceMap, configService.getDefaultBrandSubChannelInfo());
SubChannelInfoDTO subChannel = configService.getDefaultBrandSubChannelInfo();
ApplyMerchantRequest request = MerchantConvert.convertRequest(params, apply, resourceMap, subChannel);
merchantRpcService.apply(request);
} catch (Exception e) {
log.error("apply brand merchant fail {}, brand id = {}, studio id = {}", id, studio.getBrandId(),
params.getStudioId(), e);
this.doOpenMerchantFail(id, e.getMessage());
return id;
log.error("apply brand merchant fail {}, studio id = {}", apply.getId(), params.getStudioId(), e);
this.doOpenMerchantFail(apply.getId(), e.getMessage());
return;
}
this.doOpenMerchantProcess(id);
this.doOpenMerchantProcess(apply.getId());
});
return id;
return apply.getId();
}
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
......@@ -326,4 +329,28 @@ public class StudioMerchantServiceImpl implements StudioMerchantService {
StudioMerchantApply.builder().id(id).openState(OpenStateEnums.PROCESS).build());
}
private void validSmsCode(String phone, String smsCode) {
messageRpcService.validSmsCode(phone, smsCode, "FINANCE_MERCHANT");
}
private StudioMerchantApply saveApply(ApplyStudioMerchantParams params) {
Long id = IdWorker.getId();
StudioVO studio = studioRpcService.getStudio(params.getStudioId());
StudioMerchantApply exist = studioMerchantApplyRpService.getLatestOneSuccessByStudioId(studio.getId());
StudioMerchantApply apply = MerchantConvert.convertApply(id, params, studio, exist, channel);
studioMerchantApplyRpService.insert(apply);
return apply;
}
private void checkBeforeApply(ApplyStudioMerchantParams params) {
// 校验验证码
this.validSmsCode(params.getBankCard().getPhone(), params.getSmsCode());
// 重复提交
Integer count = studioMerchantApplyRpService.countProcessByStudioId(params.getStudioId());
if (count.compareTo(0) > 0) {
throw new BizException(FinanceErrorEnums.EXIST_PROCESS_APPLY);
}
}
}
......@@ -69,6 +69,10 @@ public class ApplyStudioMerchantParams {
@Valid
private Map<String, BrandResourceInfo> resourceMap;
@ApiModelProperty(value = "验证码", required = true)
@NotBlank(message = "验证码不能为空")
private String smsCode;
public ApplyStudioMerchantParams encrypt(String salt) {
ApplyStudioMerchantParams copy = JSON.parseObject(JSON.toJSONString(this),
ApplyStudioMerchantParams.class);
......
package com.jiejing.fitness.finance.service.rpc;
import com.jiejing.message.api.SendMessageApi;
import com.jiejing.message.api.request.VerifyCodeCheckRequest;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* @author chengyubing
* @since 2024/4/2 10:00
*/
@Slf4j
@Service
public class MessageRpcService {
@Resource
private SendMessageApi sendMessageApi;
public void validSmsCode(String phone, String code, String bizType) {
VerifyCodeCheckRequest request = VerifyCodeCheckRequest.builder().phone(phone).bizType(bizType).code(code)
.build();
sendMessageApi.verifyCodeCheck(request).assertSuccess();
}
}
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