Commit 59644bd9 by 程裕兵

feat:upload

parent d1430411
...@@ -15,8 +15,8 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; ...@@ -15,8 +15,8 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
@Configuration @Configuration
public class FinanceAsyncConfiguration { public class FinanceAsyncConfiguration {
@Bean(value = "financeAsyncConfiguration") @Bean(value = "financeThreadPool")
public AsyncTaskExecutor payCenterThreadPool() { public AsyncTaskExecutor financeThreadPool() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(Runtime.getRuntime().availableProcessors() * 8); executor.setCorePoolSize(Runtime.getRuntime().availableProcessors() * 8);
executor.setMaxPoolSize(Runtime.getRuntime().availableProcessors() * 16); executor.setMaxPoolSize(Runtime.getRuntime().availableProcessors() * 16);
......
package com.jiejing.fitness.finance.service.merchant.convert; package com.jiejing.fitness.finance.service.merchant.convert;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.jiejing.common.utils.crypt.AesUtil; import com.jiejing.common.utils.crypt.AesUtil;
import com.jiejing.filecenter.api.resource.vo.ResourceInfoVO;
import com.jiejing.fitness.finance.api.enums.ApplyTypeEnums; import com.jiejing.fitness.finance.api.enums.ApplyTypeEnums;
import com.jiejing.fitness.finance.repository.entity.BrandMerchantApply; import com.jiejing.fitness.finance.repository.entity.BrandMerchantApply;
import com.jiejing.fitness.finance.service.merchant.params.ApplyBrandMerchantParams; import com.jiejing.fitness.finance.service.merchant.params.ApplyBrandMerchantParams;
import com.jiejing.paycenter.api.merchant.request.ApplyMerchantRequest; import com.jiejing.paycenter.api.merchant.request.ApplyMerchantRequest;
import com.jiejing.paycenter.api.merchant.request.UploadRequest;
import com.jiejing.paycenter.common.enums.common.OpenStateEnums; import com.jiejing.paycenter.common.enums.common.OpenStateEnums;
import com.jiejing.paycenter.common.enums.merchant.BusinessTypeEnums; import com.jiejing.paycenter.common.enums.merchant.BusinessTypeEnums;
import com.jiejing.paycenter.common.enums.merchant.LicenseTypeEnums; import com.jiejing.paycenter.common.enums.merchant.LicenseTypeEnums;
import com.jiejing.paycenter.common.enums.merchant.MccEnums; import com.jiejing.paycenter.common.enums.merchant.MccEnums;
import com.jiejing.paycenter.common.enums.merchant.PaySceneEnums; import com.jiejing.paycenter.common.enums.merchant.PaySceneEnums;
import com.jiejing.paycenter.common.enums.merchant.ResourceTypeEnums;
import com.jiejing.paycenter.common.enums.merchant.SceneTypeEnums; import com.jiejing.paycenter.common.enums.merchant.SceneTypeEnums;
import com.jiejing.paycenter.common.model.Address; import com.jiejing.paycenter.common.model.Address;
import com.jiejing.paycenter.common.model.BankCard; import com.jiejing.paycenter.common.model.BankCard;
...@@ -146,9 +148,8 @@ public class MerchantConvert { ...@@ -146,9 +148,8 @@ public class MerchantConvert {
.build(); .build();
} }
public static BrandMerchantApply convertApply(ApplyBrandMerchantParams params, StudioVO studio, public static BrandMerchantApply convertApply(Long id, ApplyBrandMerchantParams params, StudioVO studio,
BrandMerchantApply exist, String channel) { BrandMerchantApply exist, String channel) {
long id = IdWorker.getId();
String salt = AesUtil.getSalt(8); String salt = AesUtil.getSalt(8);
ApplyBrandMerchantParams encrypt = params.encrypt(salt); ApplyBrandMerchantParams encrypt = params.encrypt(salt);
return BrandMerchantApply.builder() return BrandMerchantApply.builder()
...@@ -212,4 +213,16 @@ public class MerchantConvert { ...@@ -212,4 +213,16 @@ public class MerchantConvert {
.updateTime(new Date()) .updateTime(new Date())
.build(); .build();
} }
public static UploadRequest convertUploadRequest(String channel, ResourceTypeEnums type,
ResourceInfoVO vo) {
return UploadRequest.builder()
.url(vo.getUrl())
.fileSize(vo.getFileSize())
.suffix(vo.getSuffix())
.channelNo(channel)
.resourceType(type)
.build();
}
} }
package com.jiejing.fitness.finance.service.merchant.impl; package com.jiejing.fitness.finance.service.merchant.impl;
import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.jiejing.common.exception.BizException;
import com.jiejing.common.utils.collection.CollectionUtil;
import com.jiejing.filecenter.api.resource.vo.ResourceInfoVO; import com.jiejing.filecenter.api.resource.vo.ResourceInfoVO;
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;
...@@ -12,11 +10,7 @@ import com.jiejing.fitness.finance.service.merchant.params.ApplyBrandMerchantPar ...@@ -12,11 +10,7 @@ import com.jiejing.fitness.finance.service.merchant.params.ApplyBrandMerchantPar
import com.jiejing.fitness.finance.service.rpc.MerchantRpcService; 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.api.merchant.request.ApplyMerchantRequest;
import com.jiejing.paycenter.api.merchant.request.UploadRequest;
import com.jiejing.paycenter.common.enums.common.OpenStateEnums; import com.jiejing.paycenter.common.enums.common.OpenStateEnums;
import com.jiejing.paycenter.common.enums.error.PayErrorEnums;
import com.jiejing.paycenter.common.enums.merchant.ResourceTypeEnums;
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;
...@@ -26,6 +20,7 @@ import java.util.stream.Collectors; ...@@ -26,6 +20,7 @@ import java.util.stream.Collectors;
import javax.annotation.Resource; import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j; 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.stereotype.Service; import org.springframework.stereotype.Service;
/** /**
...@@ -53,51 +48,44 @@ public class BrandMerchantServiceImpl implements BrandMerchantService { ...@@ -53,51 +48,44 @@ public class BrandMerchantServiceImpl implements BrandMerchantService {
@Resource @Resource
private BrandMerchantApplyRpService brandMerchantApplyRpService; private BrandMerchantApplyRpService brandMerchantApplyRpService;
@Async(value = "financeThreadPool")
@Override @Override
public void apply(ApplyBrandMerchantParams params) { public void apply(ApplyBrandMerchantParams params) {
this.upload(params); Long id = IdWorker.getId();
StudioVO studio = studioRpcService.getStudio(params.getStudioId()); StudioVO studio = studioRpcService.getStudio(params.getStudioId());
BrandMerchantApply exist = brandMerchantApplyRpService.getLatestOneSuccessByBrandId(studio.getBrandId()); BrandMerchantApply exist = brandMerchantApplyRpService.getLatestOneSuccessByBrandId(
BrandMerchantApply apply = MerchantConvert.convertApply(params, studio, exist, channel); studio.getBrandId());
BrandMerchantApply apply = MerchantConvert.convertApply(id, params, studio, exist, channel);
try {
brandMerchantApplyRpService.insert(apply); brandMerchantApplyRpService.insert(apply);
ApplyMerchantRequest request = MerchantConvert.convertRequest(channel, apply.getApplyNo(), try {
studio.getBrandId(), params);
merchantRpcService.apply(request); this.upload(params);
merchantRpcService.apply(MerchantConvert.convertRequest(channel, apply.getApplyNo(),
studio.getBrandId(), params));
} catch (Exception e) { } catch (Exception e) {
brandMerchantApplyRpService.updateById( brandMerchantApplyRpService.updateById(
BrandMerchantApply.builder().id(apply.getId()).openState(OpenStateEnums.FAIL) BrandMerchantApply.builder().id(id).openState(OpenStateEnums.FAIL)
.openFailMessage(e.getMessage()).build()); .openFailMessage(e.getMessage()).build());
} }
} }
private void upload(ApplyBrandMerchantParams params) { private void upload(ApplyBrandMerchantParams params) {
Map<Long, ResourceInfoVO> resourceIdUrlMap = resourceRpcService.getResourceMap(params.getStudioId(), Map<Long, ResourceInfoVO> resourceIdUrlMap = resourceRpcService.getResourceMap(params.getStudioId(),
getResourceIds(params)); getResourceIds(params));
List<ResourceTypeEnums> resourceTypes = params.getResourceInfo().keySet().stream().filter(type -> {
Long resourceId = params.getResourceInfo().get(type).getResourceId();
return type.getMaxSize().compareTo(resourceIdUrlMap.get(resourceId).getFileSize()) < 0;
}).collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(resourceTypes)) {
String message = "";
for (ResourceTypeEnums type : resourceTypes) {
message = message + "[" + type.getDesc() + "大小不超过" + type.getMaxSize() / 1024 / 1024 + "MB]";
}
throw new BizException(PayErrorEnums.PARAMS_ERROR, new JSONObject().fluentPut("message", message));
}
params.getResourceInfo().keySet().forEach(type -> { params.getResourceInfo().keySet().forEach(type -> {
Long resourceId = params.getResourceInfo().get(type).getResourceId(); ResourceInfo info = params.getResourceInfo().get(type);
String url = resourceIdUrlMap.get(resourceId).getUrl(); ResourceInfoVO vo = resourceIdUrlMap.get(info.getResourceId());
String thirdId = merchantRpcService.upload( String thirdId = merchantRpcService.upload(MerchantConvert.convertUploadRequest(channel, type, vo));
UploadRequest.builder().url(url).channelNo(channel).resourceType(type).build()); info.setThirdId(thirdId);
params.getResourceInfo().get(type).setThirdId(thirdId);
}); });
} }
private List<Long> getResourceIds(ApplyBrandMerchantParams params) { private List<Long> getResourceIds(ApplyBrandMerchantParams params) {
......
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