master
wangning 6 years ago
parent 92ab3b61f4
commit 0489cbf660

@ -48,6 +48,8 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.Set; import java.util.Set;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
@ -56,11 +58,9 @@ import javax.annotation.Resource;
import cn.yixblog.platform.http.HttpRequestGenerator; import cn.yixblog.platform.http.HttpRequestGenerator;
import cn.yixblog.platform.http.HttpRequestResult; import cn.yixblog.platform.http.HttpRequestResult;
@Service @Service
public class SimpleClientApplyServiceImpl implements SimpleClientApplyService { public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
@Value("${royalpay.sms.appid:1400094878}") @Value("${royalpay.sms.appid:1400094878}")
private int appId; private int appId;
@Value("${royalpay.sms.appkey:43390d81e20c5191c278fbf4cd275be2}") @Value("${royalpay.sms.appkey:43390d81e20c5191c278fbf4cd275be2}")
@ -97,6 +97,8 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
private ClientConfigMapper clientConfigMapper; private ClientConfigMapper clientConfigMapper;
@Resource @Resource
private PmtSubMerchantIdMapper pmtSubMerchantIdMapper; private PmtSubMerchantIdMapper pmtSubMerchantIdMapper;
private ThreadPoolExecutor pool = new ThreadPoolExecutor(1, 10, 5, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
@Resource @Resource
private StringRedisTemplate stringRedisTemplate; private StringRedisTemplate stringRedisTemplate;
@ -140,7 +142,6 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
if (StringUtils.isNotEmpty(value)) { if (StringUtils.isNotEmpty(value)) {
throw new BadRequestException("SMS has been sentPlease check your messages or try again in 3 minutes."); throw new BadRequestException("SMS has been sentPlease check your messages or try again in 3 minutes.");
} }
JSONObject sysConfig = sysConfigManager.getSysConfig();
ArrayList<String> param = new ArrayList<>(); ArrayList<String> param = new ArrayList<>();
String registerClientCode = RandomStringUtils.random(6, false, true); String registerClientCode = RandomStringUtils.random(6, false, true);
param.add("RoyalPay"); param.add("RoyalPay");
@ -158,17 +159,17 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
} }
@Override @Override
public void sendVerifyEmail(String address, int client_id,String username) { public void sendVerifyEmail(String address, int client_id, String username) {
JSONObject client = clientManager.getClientInfo(client_id); JSONObject client = clientManager.getClientInfo(client_id);
if (client == null) { if (client == null) {
throw new BadRequestException("Merchant not found"); throw new BadRequestException("Merchant not found");
} }
if(client.getBooleanValue("mail_confirm")){ if (client.getBooleanValue("mail_confirm")) {
throw new BadRequestException("mail address has been verified"); throw new BadRequestException("mail address has been verified");
} }
String key = checkOrGenerateVerifyMailKey(address, null); String key = checkOrGenerateVerifyMailKey(address, null);
Context ctx = new Context(); Context ctx = new Context();
ctx.setVariable("url", PlatformEnvironment.getEnv().concatUrl("/register/account/mail/" + address + "/verify/" + key + "/jump?username="+username)); ctx.setVariable("url", PlatformEnvironment.getEnv().concatUrl("/register/account/mail/" + address + "/verify/" + key + "/jump?username=" + username));
final String content = thymeleaf.process("mail/register_application", ctx); final String content = thymeleaf.process("mail/register_application", ctx);
SendMail sendMail = new SendMail(); SendMail sendMail = new SendMail();
Set<String> to = new HashSet<>(); Set<String> to = new HashSet<>();
@ -226,13 +227,13 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
} }
@Override @Override
public void checkAccountName(String contact_phone,String nation_code) { public void checkAccountName(String contact_phone, String nation_code) {
nation_code = nation_code.trim(); nation_code = nation_code.trim();
if(!nation_code.startsWith("+")){ if (!nation_code.startsWith("+")) {
nation_code ="+"+nation_code; nation_code = "+" + nation_code;
} }
JSONObject account = clientAccountMapper.findByPhone(contact_phone,nation_code); JSONObject account = clientAccountMapper.findByPhone(contact_phone, nation_code);
if (account != null){ if (account != null) {
throw new ForbiddenException("用户名已被注册"); throw new ForbiddenException("用户名已被注册");
} }
} }
@ -241,125 +242,125 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
@Transactional @Transactional
public void saveOrUpdateApplyInfo(JSONObject applyInfo, String username) { public void saveOrUpdateApplyInfo(JSONObject applyInfo, String username) {
JSONObject apply = sysClientPreMapperMapper.findByUserName(username); JSONObject apply = sysClientPreMapperMapper.findByUserName(username);
if (apply == null ){ if (apply == null) {
sysClientPreMapperMapper.save(applyInfo); sysClientPreMapperMapper.save(applyInfo);
}else { } else {
applyInfo.put("client_pre_apply_id", apply.getIntValue("client_pre_apply_id")); applyInfo.put("client_pre_apply_id", apply.getIntValue("client_pre_apply_id"));
applyInfo.put("update_time", new Date()); applyInfo.put("update_time", new Date());
sysClientPreMapperMapper.update(applyInfo); sysClientPreMapperMapper.update(applyInfo);
if(applyInfo.getBooleanValue("agree")){ if (applyInfo.getBooleanValue("agree")) {
applyerToClient(username); applyerToClient(username);
} }
} }
} }
private void applyerToClient(String username){ private void applyerToClient(String username) {
Date now = new Date(); Date now = new Date();
JSONObject param = new JSONObject(); JSONObject param = new JSONObject();
param.put("begin_time",DateFormatUtils.format(now,"YYYYMMdd")); param.put("begin_time", DateFormatUtils.format(now, "YYYYMMdd"));
param.put("end_time",DateFormatUtils.format(DateUtils.addDays(now,1),"YYYYMMdd")); param.put("end_time", DateFormatUtils.format(DateUtils.addDays(now, 1), "YYYYMMdd"));
param.put("agree",true); param.put("agree", true);
List<JSONObject> existCount = sysClientPreMapperMapper.query(param); List<JSONObject> existCount = sysClientPreMapperMapper.query(param);
if(existCount.size()>30){ if (existCount.size() > 30) {
throw new BadRequestException("New merchant over limit,Please contact us"); throw new BadRequestException("New merchant over limit,Please contact us");
} }
JSONObject apply = sysClientPreMapperMapper.findByUserName(username); JSONObject apply = sysClientPreMapperMapper.findByUserName(username);
JSONObject sysConfig = sysConfigManager.getSysConfig(); JSONObject sysConfig = sysConfigManager.getSysConfig();
String arr [] = sysConfig.getString("temp_sub_mch_id").split(","); String arr[] = sysConfig.getString("temp_sub_mch_id").split(",");
String tempSubMerchantId = arr[new Random().nextInt(arr.length)]; String tempSubMerchantId = arr[new Random().nextInt(arr.length)];
WeChatPayConfig.Merchant availableMerchant = mpPaymentApi.determineMerchant(tempSubMerchantId); WeChatPayConfig.Merchant availableMerchant = mpPaymentApi.determineMerchant(tempSubMerchantId);
String clientMoniker = generateClientMoniker(); String clientMoniker = generateClientMoniker();
JSONObject sysClient = new JSONObject(); JSONObject sysClient = new JSONObject();
sysClient.put("company_name",apply.getString("company_name")); sysClient.put("company_name", apply.getString("company_name"));
sysClient.put("abn",apply.getString("abn")); sysClient.put("abn", apply.getString("abn"));
sysClient.put("short_name",apply.getString("short_name")); sysClient.put("short_name", apply.getString("short_name"));
sysClient.put("address",apply.getString("address")); sysClient.put("address", apply.getString("address"));
sysClient.put("suburb",apply.getString("suburb")); sysClient.put("suburb", apply.getString("suburb"));
sysClient.put("state",apply.getString("state")); sysClient.put("state", apply.getString("state"));
sysClient.put("postcode",apply.getString("postcode")); sysClient.put("postcode", apply.getString("postcode"));
sysClient.put("royalpayindustry",apply.getString("industry")); sysClient.put("royalpayindustry", apply.getString("industry"));
sysClient.put("contact_person",apply.getString("contact_person")); sysClient.put("contact_person", apply.getString("contact_person"));
sysClient.put("contact_email",apply.getString("contact_email")); sysClient.put("contact_email", apply.getString("contact_email"));
sysClient.put("contact_phone",apply.getString("contact_phone")); sysClient.put("contact_phone", apply.getString("contact_phone"));
sysClient.put("company_phone",apply.getString("company_phone")); sysClient.put("company_phone", apply.getString("company_phone"));
sysClient.put("client_moniker",clientMoniker); sysClient.put("client_moniker", clientMoniker);
sysClient.put("create_time",new Date()); sysClient.put("create_time", new Date());
sysClient.put("source",4); sysClient.put("source", 4);
sysClient.put("org_id",1); sysClient.put("org_id", 1);
sysClient.put("approve_result",2); sysClient.put("approve_result", 2);
sysClient.put("approve_time",new Date()); sysClient.put("approve_time", new Date());
sysClient.put("creator",0); sysClient.put("creator", 0);
sysClient.put("business_name",apply.getString("short_name")); sysClient.put("business_name", apply.getString("short_name"));
sysClient.put("industry",331); sysClient.put("industry", 331);
sysClient.put("merchant_id", availableMerchant.getMerchantId()); sysClient.put("merchant_id", availableMerchant.getMerchantId());
sysClient.put("sub_merchant_id",tempSubMerchantId); sysClient.put("sub_merchant_id", tempSubMerchantId);
sysClient.put("common_sub_merchant_id",1); sysClient.put("common_sub_merchant_id", 1);
sysClient.put("skip_clearing",1); sysClient.put("skip_clearing", 1);
sysClient.put("country","AUS"); sysClient.put("country", "AUS");
sysClient.put("credential_code", RandomStringUtils.random(32, true, true)); sysClient.put("credential_code", RandomStringUtils.random(32, true, true));
clientMapper.save(sysClient); clientMapper.save(sysClient);
int clientId = sysClient.getIntValue("client_id"); int clientId = sysClient.getIntValue("client_id");
JSONObject sysAccount = new JSONObject(); JSONObject sysAccount = new JSONObject();
sysAccount.put("username",apply.getString("username")); sysAccount.put("username", apply.getString("username"));
sysAccount.put("display_name",apply.getString("username")); sysAccount.put("display_name", apply.getString("username"));
String salt = PasswordUtils.newSalt(); String salt = PasswordUtils.newSalt();
sysAccount.put("salt", salt); sysAccount.put("salt", salt);
sysAccount.put("role", 1); sysAccount.put("role", 1);
sysAccount.put("password_hash", PasswordUtils.hashPwd(apply.getString("password"), salt)); sysAccount.put("password_hash", PasswordUtils.hashPwd(apply.getString("password"), salt));
sysAccount.put("password_aes", PasswordUtils.encryptAESPwd(apply.getString("password"))); sysAccount.put("password_aes", PasswordUtils.encryptAESPwd(apply.getString("password")));
sysAccount.put("creator",0); sysAccount.put("creator", 0);
sysAccount.put("contact_phone",apply.getString("contact_phone")); sysAccount.put("contact_phone", apply.getString("contact_phone"));
sysAccount.put("client_id",clientId); sysAccount.put("client_id", clientId);
sysAccount.put("create_time",new Date()); sysAccount.put("create_time", new Date());
sysAccount.put("is_password_expired",0); sysAccount.put("is_password_expired", 0);
sysAccount.put("nation_code","+61"); sysAccount.put("nation_code", "+61");
clientAccountMapper.save(sysAccount); clientAccountMapper.save(sysAccount);
JSONObject sysBank = new JSONObject(); JSONObject sysBank = new JSONObject();
sysBank.put("client_id",clientId); sysBank.put("client_id", clientId);
sysBank.put("account_no",apply.getString("bank_no")); sysBank.put("account_no", apply.getString("bank_no"));
sysBank.put("account_name",apply.getString("bank_name")); sysBank.put("account_name", apply.getString("bank_name"));
sysBank.put("bsb_no",apply.getString("bsb_no")); sysBank.put("bsb_no", apply.getString("bsb_no"));
JSONObject bankInfo = getBankInfo(apply.getString("bsb_no")); JSONObject bankInfo = getBankInfo(apply.getString("bsb_no"));
sysBank.put("bank",bankInfo.getString("bank")); sysBank.put("bank", bankInfo.getString("bank"));
sysBank.put("city",bankInfo.getString("city")); sysBank.put("city", bankInfo.getString("city"));
sysBank.put("address",bankInfo.getString("address")); sysBank.put("address", bankInfo.getString("address"));
sysBank.put("system",bankInfo.getString("system")); sysBank.put("system", bankInfo.getString("system"));
sysBank.put("postcode",bankInfo.getString("postcode")); sysBank.put("postcode", bankInfo.getString("postcode"));
sysBank.put("state",bankInfo.getString("state")); sysBank.put("state", bankInfo.getString("state"));
sysBank.put("branch",bankInfo.getString("branch")); sysBank.put("branch", bankInfo.getString("branch"));
clientBankAccountMapper.save(sysBank); clientBankAccountMapper.save(sysBank);
JSONObject clientConfig = new JSONObject(); JSONObject clientConfig = new JSONObject();
clientConfig.put("client_id",clientId); clientConfig.put("client_id", clientId);
clientConfig.put("skip_clearing",1); clientConfig.put("skip_clearing", 1);
clientConfig.put("client_moniker",clientMoniker); clientConfig.put("client_moniker", clientMoniker);
clientConfig.put("clean_days",apply.getIntValue("clean_days")); clientConfig.put("clean_days", apply.getIntValue("clean_days"));
clientConfig.put("common_sub_merchant_id",1); clientConfig.put("common_sub_merchant_id", 1);
clientConfigMapper.save(clientConfig); clientConfigMapper.save(clientConfig);
JSONObject sysRate = new JSONObject(); JSONObject sysRate = new JSONObject();
sysRate.put("client_id",clientId); sysRate.put("client_id", clientId);
sysRate.put("clean_days",apply.getIntValue("clean_days")); sysRate.put("clean_days", apply.getIntValue("clean_days"));
sysRate.put("remark","自主申请"); sysRate.put("remark", "自主申请");
sysRate.put("create_time", new Date()); sysRate.put("create_time", new Date());
sysRate.put("update_time", new Date()); sysRate.put("update_time", new Date());
sysRate.put("active_time", DateFormatUtils.format(new Date(), "yyyy-MM-dd")); sysRate.put("active_time", DateFormatUtils.format(new Date(), "yyyy-MM-dd"));
sysRate.put("expiry_time", DateFormatUtils.format(DateUtils.addYears(new Date(),1), "yyyy-MM-dd")); sysRate.put("expiry_time", DateFormatUtils.format(DateUtils.addYears(new Date(), 1), "yyyy-MM-dd"));
JSONObject rateConfig = clientManager.getSysRateConfig(); JSONObject rateConfig = clientManager.getSysRateConfig();
JSONObject chooseRate = new JSONObject(); JSONObject chooseRate = new JSONObject();
if (apply.getIntValue("clean_days") == 1){ if (apply.getIntValue("clean_days") == 1) {
chooseRate = rateConfig.getJSONObject("t1"); chooseRate = rateConfig.getJSONObject("t1");
} }
if (apply.getIntValue("clean_days") == 2){ if (apply.getIntValue("clean_days") == 2) {
chooseRate = rateConfig.getJSONObject("t2"); chooseRate = rateConfig.getJSONObject("t2");
} }
if (apply.getIntValue("clean_days") == 3){ if (apply.getIntValue("clean_days") == 3) {
chooseRate = rateConfig.getJSONObject("t3"); chooseRate = rateConfig.getJSONObject("t3");
} }
sysRate.putAll(chooseRate); sysRate.putAll(chooseRate);
@ -369,23 +370,25 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
configNewClientRate(sysRate, clientId, "AlipayOnline", "AlipayOnline"); configNewClientRate(sysRate, clientId, "AlipayOnline", "AlipayOnline");
configNewClientRate(sysRate, clientId, "Bestpay", "Bestpay"); configNewClientRate(sysRate, clientId, "Bestpay", "Bestpay");
configNewClientRate(sysRate, clientId, "jd", "JDpay"); configNewClientRate(sysRate, clientId, "jd", "JDpay");
try { Runnable task2 = () -> {
clientManager.getNewAggregateAgreeFile(clientMoniker,null,false); try {
} catch (Exception ignore) { clientManager.getNewAggregateAgreeFile(clientMoniker, null, false);
} } catch (Exception ignore) {
}
};
pool.execute(task2);
} }
private String generateClientMoniker(){ private String generateClientMoniker() {
String clientMoniker = RandomStringUtils.random(4, true, true).toUpperCase(); String clientMoniker = RandomStringUtils.random(4, true, true).toUpperCase();
JSONObject client = clientMapper.findClientByMoniker(clientMoniker); JSONObject client = clientMapper.findClientByMoniker(clientMoniker);
if (client != null){ if (client != null) {
generateClientMoniker(); generateClientMoniker();
} }
return clientMoniker; return clientMoniker;
} }
private void configNewClientRate(JSONObject config, int clientId, String channel, String rateKey) { private void configNewClientRate(JSONObject config, int clientId, String channel, String rateKey) {
if (config.containsKey(rateKey)) { if (config.containsKey(rateKey)) {
JSONObject newConfig = new JSONObject(); JSONObject newConfig = new JSONObject();
@ -430,13 +433,13 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
throw new BadRequestException(LocaleSupport.localeMessage("error.login.password")); throw new BadRequestException(LocaleSupport.localeMessage("error.login.password"));
} }
JSONObject record = new JSONObject(); JSONObject record = new JSONObject();
record.put("client_id",client.getIntValue("client_id")); record.put("client_id", client.getIntValue("client_id"));
record.put("mail_confirm",true); record.put("mail_confirm", true);
clientMapper.update(record); clientMapper.update(record);
} }
private String getRegisterClientRedisKey(String phoneNumber){ private String getRegisterClientRedisKey(String phoneNumber) {
return REGISTER_CLIENT_PREFIX +phoneNumber; return REGISTER_CLIENT_PREFIX + phoneNumber;
} }
private String getRegisterClientProcessRedisKey(String codeKey) { private String getRegisterClientProcessRedisKey(String codeKey) {

Loading…
Cancel
Save