fix client_less_info

master
luoyang 7 years ago
parent a4481c6c0e
commit 94ad879dc5

@ -57,4 +57,6 @@ public interface SignInAccountService {
void deleteClientCodeKey(String codekey); void deleteClientCodeKey(String codekey);
void deleteManagerCodeKey(String codekey); void deleteManagerCodeKey(String codekey);
JSONObject checkAuthFileStatus(JSONObject client);
} }

@ -93,9 +93,10 @@ public class SignInAccountServiceImpl implements SignInAccountService, Applicati
@PostConstruct @PostConstruct
public void init(){ public void init() {
tags.add("account"); tags.add("account");
} }
@Override @Override
@Cacheable(value = ":login:managers:", key = "''+#accountId") @Cacheable(value = ":login:managers:", key = "''+#accountId")
public JSONObject getManager(String accountId) { public JSONObject getManager(String accountId) {
@ -127,7 +128,7 @@ public class SignInAccountServiceImpl implements SignInAccountService, Applicati
manager.put("available_func_names", funcNames); manager.put("available_func_names", funcNames);
manager.put("modules", modules.values()); manager.put("modules", modules.values());
manager.put("module_names", modules.keySet()); manager.put("module_names", modules.keySet());
if((manager.getIntValue("role")& ManagerRole.SERVANT.getMask())>0){ if ((manager.getIntValue("role") & ManagerRole.SERVANT.getMask()) > 0) {
JSONObject cs = sysCustomerServiceMapper.findByManagerId(accountId); JSONObject cs = sysCustomerServiceMapper.findByManagerId(accountId);
if (cs != null) { if (cs != null) {
manager.put("onoff", cs.getBoolean("onoff")); manager.put("onoff", cs.getBoolean("onoff"));
@ -159,7 +160,18 @@ public class SignInAccountServiceImpl implements SignInAccountService, Applicati
} }
client.putAll(clientConfigService.find(client_id)); client.putAll(clientConfigService.find(client_id));
client = clientInfoWithNoSecretInfo(client); client = clientInfoWithNoSecretInfo(client);
checkAuthFileStatus(client); client.put("client_less_file", false);
if (client.getIntValue("approve_result") == 2 || client.getIntValue("open_status") == 10) {
List<JSONObject> clientFiles = clientFilesMapper.findAllClientFile(client.getIntValue("client_id"));
if (clientFiles != null && clientFiles.size() > 0) {
String[] fileKeys = {"client_bank_file", "client_company_file", "client_id_file", "client_agree_file"};
for (String fileKey : fileKeys) {
if (clientFiles.stream().noneMatch(fileJson -> fileKey.equals(fileJson.getString("file_name")))) {
client.put("client_less_file", true);
}
}
}
}
if (client.getInteger("parent_client_id") != null) { if (client.getInteger("parent_client_id") != null) {
JSONObject rootPartner = clientManager.getClientInfoIgnoreInvalid(client.getIntValue("parent_client_id")); JSONObject rootPartner = clientManager.getClientInfoIgnoreInvalid(client.getIntValue("parent_client_id"));
rootPartner.putAll(clientConfigService.find(client.getIntValue("parent_client_id"))); rootPartner.putAll(clientConfigService.find(client.getIntValue("parent_client_id")));
@ -374,7 +386,7 @@ public class SignInAccountServiceImpl implements SignInAccountService, Applicati
ctx.setVariable("url", url); ctx.setVariable("url", url);
ctx.setVariable("accounts", accounts); ctx.setVariable("accounts", accounts);
ctx.setVariable("client_moniker", client_moniker); ctx.setVariable("client_moniker", client_moniker);
final String content = thymeleaf.process( "mail/reset_password", ctx); final String content = thymeleaf.process("mail/reset_password", ctx);
//final String content = VelocityEngineUtils.mergeTemplateIntoString(null, "mail/reset_password.vm", "utf-8", map); //final String content = VelocityEngineUtils.mergeTemplateIntoString(null, "mail/reset_password.vm", "utf-8", map);
new Thread(() -> { new Thread(() -> {
@ -440,11 +452,11 @@ public class SignInAccountServiceImpl implements SignInAccountService, Applicati
public static JSONObject clientInfoWithNoSecretInfo(JSONObject client) { public static JSONObject clientInfoWithNoSecretInfo(JSONObject client) {
JSONObject simpleClient = new JSONObject(); JSONObject simpleClient = new JSONObject();
String[] columns = { "client_id", "client_moniker", "parent_client_id", "company_name", "address", "business_name", "business_structure", "abn", "acn", String[] columns = {"client_id", "client_moniker", "parent_client_id", "company_name", "address", "business_name", "business_structure", "abn", "acn",
"company_phone", "suburb", "postcode", "state", "contact_person", "contact_phone", "contact_email", "short_name", "logo_url", "enable_refund", "company_phone", "suburb", "postcode", "state", "contact_person", "contact_phone", "contact_email", "short_name", "logo_url", "enable_refund",
"enable_refund_auth", "retail_surcharge", "require_custinfo", "require_remark", "logo_thumbnail", "creator", "create_time", "approver", "enable_refund_auth", "retail_surcharge", "require_custinfo", "require_remark", "logo_thumbnail", "creator", "create_time", "approver",
"approve_result", "approve_time", "open_status", "timezone", "has_children", "source", "customer_surcharge_rate", "enable_alipay", "enable_wechat", "approve_result", "approve_time", "open_status", "timezone", "has_children", "source", "customer_surcharge_rate", "enable_alipay", "enable_wechat",
"enable_bestpay", "manual_settle", "skip_clearing" ,"mail_confirm","surcharge_mode"}; "enable_bestpay", "manual_settle", "skip_clearing", "mail_confirm", "surcharge_mode"};
for (String col : columns) { for (String col : columns) {
simpleClient.put(col, client.get(col)); simpleClient.put(col, client.get(col));
} }
@ -480,24 +492,24 @@ public class SignInAccountServiceImpl implements SignInAccountService, Applicati
} }
@Override @Override
public void getClientResetPwdCode(JSONObject account,String type) { public void getClientResetPwdCode(JSONObject account, String type) {
if(StringUtils.equals(type,"email") && !account.containsKey("contact_email")){ if (StringUtils.equals(type, "email") && !account.containsKey("contact_email")) {
throw new BadRequestException("Your account is not bound to your mailbox!"); throw new BadRequestException("Your account is not bound to your mailbox!");
} }
if(StringUtils.equals(type,"phone") && !account.containsKey("contact_phone") && !account.containsKey("nation_code")){ if (StringUtils.equals(type, "phone") && !account.containsKey("contact_phone") && !account.containsKey("nation_code")) {
throw new BadRequestException("Your account is not bound to your phone!"); throw new BadRequestException("Your account is not bound to your phone!");
} }
String accountId = account.getString("account_id"); String accountId = account.getString("account_id");
String codeKeyValueRedis = stringRedisTemplate.boundValueOps(getResetClientAccountKey(accountId)).get(); String codeKeyValueRedis = stringRedisTemplate.boundValueOps(getResetClientAccountKey(accountId)).get();
if(StringUtils.isNotEmpty(codeKeyValueRedis)){ if (StringUtils.isNotEmpty(codeKeyValueRedis)) {
throw new BadRequestException("Captcha has been sent.Please check your "+type+" or try again in 5 minutes."); throw new BadRequestException("Captcha has been sent.Please check your " + type + " or try again in 5 minutes.");
} }
String codeKeyValue = RandomStringUtils.random(6, false, true); String codeKeyValue = RandomStringUtils.random(6, false, true);
switch(type){ switch (type) {
case "email": case "email":
Context ctx = new Context(); Context ctx = new Context();
ctx.setVariable("account",account); ctx.setVariable("account", account);
ctx.setVariable("captcha",codeKeyValue); ctx.setVariable("captcha", codeKeyValue);
final String content = thymeleaf.process("mail/account_reset_email.html", ctx); final String content = thymeleaf.process("mail/account_reset_email.html", ctx);
royalThreadPoolExecutor.execute(() -> { royalThreadPoolExecutor.execute(() -> {
try { try {
@ -522,28 +534,28 @@ public class SignInAccountServiceImpl implements SignInAccountService, Applicati
} }
break; break;
} }
stringRedisTemplate.boundValueOps(getResetClientAccountKey(accountId)).set(codeKeyValue,5, TimeUnit.MINUTES); stringRedisTemplate.boundValueOps(getResetClientAccountKey(accountId)).set(codeKeyValue, 5, TimeUnit.MINUTES);
} }
@Override @Override
public void getManagerResetPwdCode(JSONObject account, String type) { public void getManagerResetPwdCode(JSONObject account, String type) {
if(StringUtils.equals(type,"email") && !account.containsKey("email")){ if (StringUtils.equals(type, "email") && !account.containsKey("email")) {
throw new BadRequestException("Your account is not bound to your mailbox!"); throw new BadRequestException("Your account is not bound to your mailbox!");
} }
if(StringUtils.equals(type,"phone") && !account.containsKey("phone") && !account.containsKey("nation_code")){ if (StringUtils.equals(type, "phone") && !account.containsKey("phone") && !account.containsKey("nation_code")) {
throw new BadRequestException("Your account is not bound to your phone!"); throw new BadRequestException("Your account is not bound to your phone!");
} }
String managerId = account.getString("manager_id"); String managerId = account.getString("manager_id");
String codeKeyValueRedis = stringRedisTemplate.boundValueOps(getResetManagerAccountKey(managerId)).get(); String codeKeyValueRedis = stringRedisTemplate.boundValueOps(getResetManagerAccountKey(managerId)).get();
if(StringUtils.isNotEmpty(codeKeyValueRedis)){ if (StringUtils.isNotEmpty(codeKeyValueRedis)) {
throw new BadRequestException("Captcha has been sent.Please check your "+type+" or try again in 5 minutes."); throw new BadRequestException("Captcha has been sent.Please check your " + type + " or try again in 5 minutes.");
} }
String codeKeyValue = RandomStringUtils.random(6, false, true); String codeKeyValue = RandomStringUtils.random(6, false, true);
switch(type){ switch (type) {
case "email": case "email":
Context ctx = new Context(); Context ctx = new Context();
ctx.setVariable("account",account); ctx.setVariable("account", account);
ctx.setVariable("captcha",codeKeyValue); ctx.setVariable("captcha", codeKeyValue);
final String content = thymeleaf.process("mail/account_reset_email.html", ctx); final String content = thymeleaf.process("mail/account_reset_email.html", ctx);
royalThreadPoolExecutor.execute(() -> { royalThreadPoolExecutor.execute(() -> {
try { try {
@ -568,16 +580,16 @@ public class SignInAccountServiceImpl implements SignInAccountService, Applicati
} }
break; break;
} }
stringRedisTemplate.boundValueOps(getResetManagerAccountKey(managerId)).set(codeKeyValue,5, TimeUnit.MINUTES); stringRedisTemplate.boundValueOps(getResetManagerAccountKey(managerId)).set(codeKeyValue, 5, TimeUnit.MINUTES);
} }
@Override @Override
public void verifyClientCaptcha(JSONObject account, String captcha) { public void verifyClientCaptcha(JSONObject account, String captcha) {
String captchaRedis = stringRedisTemplate.boundValueOps(getResetClientAccountKey(account.getString("account_id"))).get(); String captchaRedis = stringRedisTemplate.boundValueOps(getResetClientAccountKey(account.getString("account_id"))).get();
if(StringUtils.isBlank(captchaRedis)){ if (StringUtils.isBlank(captchaRedis)) {
throw new BadRequestException("Captcha has expired"); throw new BadRequestException("Captcha has expired");
} }
if(StringUtils.equals(captcha,captchaRedis)){ if (StringUtils.equals(captcha, captchaRedis)) {
throw new BadRequestException("Captcha is wrong"); throw new BadRequestException("Captcha is wrong");
} }
} }
@ -585,10 +597,10 @@ public class SignInAccountServiceImpl implements SignInAccountService, Applicati
@Override @Override
public void verifyManagerCaptcha(JSONObject account, String captcha) { public void verifyManagerCaptcha(JSONObject account, String captcha) {
String captchaRedis = stringRedisTemplate.boundValueOps(getResetManagerAccountKey(account.getString("manager_id"))).get(); String captchaRedis = stringRedisTemplate.boundValueOps(getResetManagerAccountKey(account.getString("manager_id"))).get();
if(StringUtils.isBlank(captchaRedis)){ if (StringUtils.isBlank(captchaRedis)) {
throw new BadRequestException("Captcha has expired"); throw new BadRequestException("Captcha has expired");
} }
if(StringUtils.equals(captcha,captchaRedis)){ if (StringUtils.equals(captcha, captchaRedis)) {
throw new BadRequestException("Captcha is wrong"); throw new BadRequestException("Captcha is wrong");
} }
} }
@ -603,23 +615,25 @@ public class SignInAccountServiceImpl implements SignInAccountService, Applicati
deleteManagerAccountKey(codekey); deleteManagerAccountKey(codekey);
} }
private void deleteClientAccountKey(String codeKey){ private void deleteClientAccountKey(String codeKey) {
stringRedisTemplate.delete(getResetClientAccountKey(codeKey)); stringRedisTemplate.delete(getResetClientAccountKey(codeKey));
} }
private void deleteManagerAccountKey(String codeKey){ private void deleteManagerAccountKey(String codeKey) {
stringRedisTemplate.delete(getResetManagerAccountKey(codeKey)); stringRedisTemplate.delete(getResetManagerAccountKey(codeKey));
} }
private String getResetClientAccountKey(String codeKey){ private String getResetClientAccountKey(String codeKey) {
return RESET_CLIENT_ACCOUNT_PREFIX + codeKey; return RESET_CLIENT_ACCOUNT_PREFIX + codeKey;
} }
private String getResetManagerAccountKey(String codeKey){ private String getResetManagerAccountKey(String codeKey) {
return RESET_MANAGER_ACCOUNT_PREFIX + codeKey; return RESET_MANAGER_ACCOUNT_PREFIX + codeKey;
} }
private void checkAuthFileStatus(JSONObject client) { public JSONObject checkAuthFileStatus(JSONObject client) {
JSONObject result = new JSONObject();
result.put("client_less_file", false);
if (client.getIntValue("approve_result") == 2 || client.getIntValue("open_status") == 10) { if (client.getIntValue("approve_result") == 2 || client.getIntValue("open_status") == 10) {
List<JSONObject> clientFiles = clientFilesMapper.findAllClientFile(client.getIntValue("client_id")); List<JSONObject> clientFiles = clientFilesMapper.findAllClientFile(client.getIntValue("client_id"));
String[] fileKeys = {"client_bank_file", "client_company_file", "client_id_file", "client_agree_file"}; String[] fileKeys = {"client_bank_file", "client_company_file", "client_id_file", "client_agree_file"};
@ -629,39 +643,53 @@ public class SignInAccountServiceImpl implements SignInAccountService, Applicati
List<JSONObject> resultFile = new ArrayList<>(); List<JSONObject> resultFile = new ArrayList<>();
for (int i = 0; i < fileKeys.length; i++) { for (int i = 0; i < fileKeys.length; i++) {
String fileKey = fileKeys[i]; String fileKey = fileKeys[i];
List<String> clientFileUrl = clientFiles.stream() if (clientFiles != null && clientFiles.size() > 0) {
.filter(fileJson -> (fileKey.equals(fileJson.getString("file_name")) && (fileJson.getIntValue("status")==1 || fileJson.getIntValue("status")==2))) List<JSONObject> clientFileUrl = clientFiles.stream()
.sorted((log1, log2) -> log2.getDate("last_update_date").compareTo(log1.getDate("last_update_date"))) .filter(fileJson -> (fileKey.equals(fileJson.getString("file_name")) && (fileJson.getIntValue("status") == 1 || fileJson.getIntValue("status") == 2)))
.map(json -> json.getString("file_value"))
.collect(Collectors.toList());
if (clientFileUrl!=null && clientFileUrl.size()>0) {
JSONObject fileJson = new JSONObject();
fileJson.put("key", putKeys[i]);
fileJson.put("name", fileNames[i]);
fileJson.put("file_value", clientFileUrl);
resultFile.add(fileJson);
}else {
List<String> clientBackToFileUrl = clientFiles.stream()
.filter(fileJson -> (fileKey.equals(fileJson.getString("file_name")) && (fileJson.getIntValue("status")==0 || fileJson.getIntValue("status")==2)))
.sorted((log1, log2) -> log2.getDate("last_update_date").compareTo(log1.getDate("last_update_date"))) .sorted((log1, log2) -> log2.getDate("last_update_date").compareTo(log1.getDate("last_update_date")))
.map(json -> json.getString("file_value")) .map(json -> {
JSONObject params = new JSONObject();
params.put("file_id", json.getString("file_id"));
params.put("file_value", json.getString("file_value"));
return params;
})
.collect(Collectors.toList()); .collect(Collectors.toList());
JSONObject fileJson = new JSONObject(); if (clientFileUrl != null && clientFileUrl.size() > 0) {
fileJson.put("key", putKeys[i]); JSONObject fileJson = new JSONObject();
fileJson.put("name", fileNames[i]); fileJson.put("key", putKeys[i]);
if (clientBackToFileUrl !=null &&clientBackToFileUrl.size() > 0) { fileJson.put("name", fileNames[i]);
fileJson.put("file_value", clientBackToFileUrl); fileJson.put("file_value", clientFileUrl);
fileJson.put("file_write", false);
resultFile.add(fileJson);
} else {
List<JSONObject> clientBackToFileUrl = clientFiles.stream()
.filter(fileJson -> (fileKey.equals(fileJson.getString("file_name")) && (fileJson.getIntValue("status") == 0 || fileJson.getIntValue("status") == 3)))
.sorted((log1, log2) -> log2.getDate("last_update_date").compareTo(log1.getDate("last_update_date")))
.map(json -> {
JSONObject params = new JSONObject();
params.put("file_id", json.getString("file_id"));
params.put("file_value", json.getString("file_value"));
return params;
})
.collect(Collectors.toList());
JSONObject fileJson = new JSONObject();
fileJson.put("key", putKeys[i]);
fileJson.put("name", fileNames[i]);
if (clientBackToFileUrl != null && clientBackToFileUrl.size() > 0) {
fileJson.put("file_value", clientBackToFileUrl);
}
fileJson.put("file_write", true);
resultFile.add(fileJson);
clientFilesIsLess = true;
} }
resultFile.add(fileJson);
clientFilesIsLess = true;
} }
} result.put("client_less_file", clientFilesIsLess);
client.put("greenChannel", 1); if (clientFilesIsLess) {
client.put("client_less_file", clientFilesIsLess); result.put("client_files", resultFile);
if (clientFilesIsLess) { }
client.put("client_files", resultFile);
} }
} }
return result;
} }
} }

Loading…
Cancel
Save