Merge remote-tracking branch 'origin/develop' into develop

master
luoyang 5 years ago
commit 345e48cdd9

@ -10,7 +10,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>manage</artifactId> <artifactId>manage</artifactId>
<version>1.0.20</version> <version>1.0.21</version>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

@ -0,0 +1,3 @@
alter table sys_clients add column settle_remark_tpl varchar(100) null default null after settle_hour;
insert into sys_configs values ('settle.remark_template','RoyalPay{date(MMdd)}{moniker}','清算文件备注模板');

@ -16,6 +16,7 @@ import au.com.royalpay.payment.manage.signin.core.ManagerTodoNoticeProvider;
import au.com.royalpay.payment.manage.support.abafile.ABAConfig; import au.com.royalpay.payment.manage.support.abafile.ABAConfig;
import au.com.royalpay.payment.manage.support.abafile.ABAFile; import au.com.royalpay.payment.manage.support.abafile.ABAFile;
import au.com.royalpay.payment.manage.support.abafile.ABATemplate; import au.com.royalpay.payment.manage.support.abafile.ABATemplate;
import au.com.royalpay.payment.manage.support.abafile.SettleRemarkTemplateDescriber;
import au.com.royalpay.payment.manage.tradelog.beans.ClearingLogQuery; import au.com.royalpay.payment.manage.tradelog.beans.ClearingLogQuery;
import au.com.royalpay.payment.tools.connections.mpsupport.MpWechatApi; import au.com.royalpay.payment.tools.connections.mpsupport.MpWechatApi;
import au.com.royalpay.payment.tools.connections.mpsupport.MpWechatApiProvider; import au.com.royalpay.payment.tools.connections.mpsupport.MpWechatApiProvider;
@ -528,8 +529,16 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
if (settle.getBigDecimal("clearing_amount").compareTo(BigDecimal.ZERO) == 0) { if (settle.getBigDecimal("clearing_amount").compareTo(BigDecimal.ZERO) == 0) {
continue; continue;
} }
String clientMoniker = settle.getString("client_moniker"); JSONObject client = clientManager.getClientInfo(settle.getIntValue("client_id"));
String remark = "RoyalPay" + DateFormatUtils.format(dt, "MMdd") + clientMoniker; String remarkTpl = client.getString("settle_remark_tpl");
if (StringUtils.isEmpty(remarkTpl)) {
remarkTpl = sysConfigManager.getSysConfig().getString("settle.remark_template");
if (StringUtils.isEmpty(remarkTpl)) {
remarkTpl = "RoyalPay{date(MMdd)}{moniker}";
}
}
String remark = new SettleRemarkTemplateDescriber(remarkTpl, settle, dt).compile();
aba.addSettleMerchant(settle.getString("bsb_no"), settle.getString("account_no"), settle.getString("account_name"), aba.addSettleMerchant(settle.getString("bsb_no"), settle.getString("account_no"), settle.getString("account_name"),
settle.getBigDecimal("clearing_amount"), remark); settle.getBigDecimal("clearing_amount"), remark);
} }

@ -0,0 +1,93 @@
package au.com.royalpay.payment.manage.support.abafile;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Create by davep at 2019-07-18 15:20
*/
public class SettleRemarkTemplateDescriber {
private Logger logger = LoggerFactory.getLogger(getClass());
private final Pattern pattern = Pattern.compile("\\{[^\\{\\}]+\\}");
private final JSONObject settle;
private final Date settleDate;
private String template;
private List<Replacer> replacers;
public SettleRemarkTemplateDescriber(String template, JSONObject settle, Date settleDate) {
this.template = template;
this.settle = settle;
this.settleDate = settleDate;
replacers = new ArrayList<>();
replacers.add(new ClientMonikerReplacer());
replacers.add(new SettleDateReplacer());
}
public String compile() {
Matcher matcher = pattern.matcher(template);
StringBuilder target = new StringBuilder();
int startPos = 0;
while (matcher.find()) {
int start = matcher.start();
int end = matcher.end();
target.append(template, startPos, start);
String group = StringUtils.substring(matcher.group(), 1, -1);
String replacement = replacers.stream().filter(replacer -> replacer.match(group))
.limit(1)
.map(replacer -> replacer.replacement(group, SettleRemarkTemplateDescriber.this))
.findFirst().orElse("");
target.append(replacement);
startPos = end;
}
target.append(template.substring(startPos));
return target.toString();
}
interface Replacer {
boolean match(String group);
String replacement(String group, SettleRemarkTemplateDescriber describer);
}
class ClientMonikerReplacer implements Replacer {
@Override
public boolean match(String group) {
return "moniker".equals(group);
}
@Override
public String replacement(String group, SettleRemarkTemplateDescriber describer) {
return describer.settle.getString("client_moniker");
}
}
class SettleDateReplacer implements Replacer {
private final String regex = "^date\\((\\w+)\\)$";
@Override
public boolean match(String group) {
return group.matches(regex);
}
@Override
public String replacement(String group, SettleRemarkTemplateDescriber describer) {
Pattern dtPattern = Pattern.compile(regex);
Matcher matcher = dtPattern.matcher(group);
if (matcher.find()) {
String datePattern = matcher.group(1);
return DateFormatUtils.format(describer.settleDate, datePattern);
}
return "";
}
}
}

@ -0,0 +1,34 @@
package au.com.royalpay.payment.manage.support.abafile;
import com.alibaba.fastjson.JSONObject;
import org.joda.time.DateTime;
import org.junit.Assert;
import org.junit.Test;
import java.util.Date;
import static org.junit.Assert.*;
/**
* Create by davep at 2019-07-18 15:27
*/
public class SettleRemarkTemplateDescriberTest {
@Test
public void compile() {
JSONObject settle = new JSONObject();
settle.put("client_moniker", "PINE");
SettleRemarkTemplateDescriber describer = new SettleRemarkTemplateDescriber("RoyalPay{date(MMdd)}{moniker}", settle, DateTime.parse("2019-07-18").toDate());
String result = describer.compile();
Assert.assertEquals("RoyalPay0718PINE", result);
}
@Test
public void compile2() {
JSONObject settle = new JSONObject();
settle.put("client_moniker", "AUPO");
SettleRemarkTemplateDescriber describer = new SettleRemarkTemplateDescriber("Pay By App {date(ddMMyy)}", settle, DateTime.parse("2019-07-18").toDate());
String res = describer.compile();
Assert.assertEquals("Pay By App 180719", res);
}
}
Loading…
Cancel
Save