fix client_less_info

master
luoyang 5 years ago
parent a4481c6c0e
commit 94ad879dc5

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

@ -93,9 +93,10 @@ public class SignInAccountServiceImpl implements SignInAccountService, Applicati
@PostConstruct
public void init(){
public void init() {
tags.add("account");
}
@Override
@Cacheable(value = ":login:managers:", key = "''+#accountId")
public JSONObject getManager(String accountId) {
@ -127,7 +128,7 @@ public class SignInAccountServiceImpl implements SignInAccountService, Applicati
manager.put("available_func_names", funcNames);
manager.put("modules", modules.values());
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);
if (cs != null) {
manager.put("onoff", cs.getBoolean("onoff"));
@ -159,7 +160,18 @@ public class SignInAccountServiceImpl implements SignInAccountService, Applicati
}
client.putAll(clientConfigService.find(client_id));
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) {
JSONObject rootPartner = clientManager.getClientInfoIgnoreInvalid(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("accounts", accounts);
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);
new Thread(() -> {
@ -440,11 +452,11 @@ public class SignInAccountServiceImpl implements SignInAccountService, Applicati
public static JSONObject clientInfoWithNoSecretInfo(JSONObject client) {
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",
"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",
"enable_bestpay", "manual_settle", "skip_clearing" ,"mail_confirm","surcharge_mode"};
"enable_bestpay", "manual_settle", "skip_clearing", "mail_confirm", "surcharge_mode"};
for (String col : columns) {
simpleClient.put(col, client.get(col));
}
@ -480,24 +492,24 @@ public class SignInAccountServiceImpl implements SignInAccountService, Applicati
}
@Override
public void getClientResetPwdCode(JSONObject account,String type) {
if(StringUtils.equals(type,"email") && !account.containsKey("contact_email")){
public void getClientResetPwdCode(JSONObject account, String type) {
if (StringUtils.equals(type, "email") && !account.containsKey("contact_email")) {
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!");
}
String accountId = account.getString("account_id");
String codeKeyValueRedis = stringRedisTemplate.boundValueOps(getResetClientAccountKey(accountId)).get();
if(StringUtils.isNotEmpty(codeKeyValueRedis)){
throw new BadRequestException("Captcha has been sent.Please check your "+type+" or try again in 5 minutes.");
if (StringUtils.isNotEmpty(codeKeyValueRedis)) {
throw new BadRequestException("Captcha has been sent.Please check your " + type + " or try again in 5 minutes.");
}
String codeKeyValue = RandomStringUtils.random(6, false, true);
switch(type){
switch (type) {
case "email":
Context ctx = new Context();
ctx.setVariable("account",account);
ctx.setVariable("captcha",codeKeyValue);
ctx.setVariable("account", account);
ctx.setVariable("captcha", codeKeyValue);
final String content = thymeleaf.process("mail/account_reset_email.html", ctx);
royalThreadPoolExecutor.execute(() -> {
try {
@ -522,28 +534,28 @@ public class SignInAccountServiceImpl implements SignInAccountService, Applicati
}
break;
}
stringRedisTemplate.boundValueOps(getResetClientAccountKey(accountId)).set(codeKeyValue,5, TimeUnit.MINUTES);
stringRedisTemplate.boundValueOps(getResetClientAccountKey(accountId)).set(codeKeyValue, 5, TimeUnit.MINUTES);
}
@Override
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!");
}
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!");
}
String managerId = account.getString("manager_id");
String codeKeyValueRedis = stringRedisTemplate.boundValueOps(getResetManagerAccountKey(managerId)).get();
if(StringUtils.isNotEmpty(codeKeyValueRedis)){
throw new BadRequestException("Captcha has been sent.Please check your "+type+" or try again in 5 minutes.");
if (StringUtils.isNotEmpty(codeKeyValueRedis)) {
throw new BadRequestException("Captcha has been sent.Please check your " + type + " or try again in 5 minutes.");
}
String codeKeyValue = RandomStringUtils.random(6, false, true);
switch(type){
switch (type) {
case "email":
Context ctx = new Context();
ctx.setVariable("account",account);
ctx.setVariable("captcha",codeKeyValue);
ctx.setVariable("account", account);
ctx.setVariable("captcha", codeKeyValue);
final String content = thymeleaf.process("mail/account_reset_email.html", ctx);
royalThreadPoolExecutor.execute(() -> {
try {
@ -568,16 +580,16 @@ public class SignInAccountServiceImpl implements SignInAccountService, Applicati
}
break;
}
stringRedisTemplate.boundValueOps(getResetManagerAccountKey(managerId)).set(codeKeyValue,5, TimeUnit.MINUTES);
stringRedisTemplate.boundValueOps(getResetManagerAccountKey(managerId)).set(codeKeyValue, 5, TimeUnit.MINUTES);
}
@Override
public void verifyClientCaptcha(JSONObject account, String captcha) {
String captchaRedis = stringRedisTemplate.boundValueOps(getResetClientAccountKey(account.getString("account_id"))).get();
if(StringUtils.isBlank(captchaRedis)){
if (StringUtils.isBlank(captchaRedis)) {
throw new BadRequestException("Captcha has expired");
}
if(StringUtils.equals(captcha,captchaRedis)){
if (StringUtils.equals(captcha, captchaRedis)) {
throw new BadRequestException("Captcha is wrong");
}
}
@ -585,10 +597,10 @@ public class SignInAccountServiceImpl implements SignInAccountService, Applicati
@Override
public void verifyManagerCaptcha(JSONObject account, String captcha) {
String captchaRedis = stringRedisTemplate.boundValueOps(getResetManagerAccountKey(account.getString("manager_id"))).get();
if(StringUtils.isBlank(captchaRedis)){
if (StringUtils.isBlank(captchaRedis)) {
throw new BadRequestException("Captcha has expired");
}
if(StringUtils.equals(captcha,captchaRedis)){
if (StringUtils.equals(captcha, captchaRedis)) {
throw new BadRequestException("Captcha is wrong");
}
}
@ -603,23 +615,25 @@ public class SignInAccountServiceImpl implements SignInAccountService, Applicati
deleteManagerAccountKey(codekey);
}
private void deleteClientAccountKey(String codeKey){
private void deleteClientAccountKey(String codeKey) {
stringRedisTemplate.delete(getResetClientAccountKey(codeKey));
}
private void deleteManagerAccountKey(String codeKey){
private void deleteManagerAccountKey(String codeKey) {
stringRedisTemplate.delete(getResetManagerAccountKey(codeKey));
}
private String getResetClientAccountKey(String codeKey){
private String getResetClientAccountKey(String codeKey) {
return RESET_CLIENT_ACCOUNT_PREFIX + codeKey;
}
private String getResetManagerAccountKey(String codeKey){
private String getResetManagerAccountKey(String 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) {
List<JSONObject> clientFiles = clientFilesMapper.findAllClientFile(client.getIntValue("client_id"));
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<>();
for (int i = 0; i < fileKeys.length; i++) {
String fileKey = fileKeys[i];
List<String> clientFileUrl = clientFiles.stream()
.filter(fileJson -> (fileKey.equals(fileJson.getString("file_name")) && (fileJson.getIntValue("status")==1 || fileJson.getIntValue("status")==2)))
.sorted((log1, log2) -> log2.getDate("last_update_date").compareTo(log1.getDate("last_update_date")))
.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)))
if (clientFiles != null && clientFiles.size() > 0) {
List<JSONObject> clientFileUrl = clientFiles.stream()
.filter(fileJson -> (fileKey.equals(fileJson.getString("file_name")) && (fileJson.getIntValue("status") == 1 || fileJson.getIntValue("status") == 2)))
.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());
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);
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);
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;
}
}
client.put("greenChannel", 1);
client.put("client_less_file", clientFilesIsLess);
if (clientFilesIsLess) {
client.put("client_files", resultFile);
result.put("client_less_file", clientFilesIsLess);
if (clientFilesIsLess) {
result.put("client_files", resultFile);
}
}
}
return result;
}
}

Loading…
Cancel
Save