|
|
@ -76,6 +76,13 @@ public class PlatformClearAnalysisServiceImpl implements PlatformClearService {
|
|
|
|
logger.error("PlatformClearAnalysisServiceImpl.verifySettleLogByDate ==> 校验" + end_date + "支付宝到账失败:", e);
|
|
|
|
logger.error("PlatformClearAnalysisServiceImpl.verifySettleLogByDate ==> 校验" + end_date + "支付宝到账失败:", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (StringUtils.equals("AlipayOnline", channel)) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
doVerifyAlipayOnlineSettleLog(sdfClear.parse(end_date));
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
logger.error("PlatformClearAnalysisServiceImpl.verifySettleLogByDate ==> 校验" + end_date + "支付宝Online到账失败:", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if (StringUtils.equals("Wechat", channel)) {
|
|
|
|
if (StringUtils.equals("Wechat", channel)) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Map<String, Date> settleDate = new HashMap<>();
|
|
|
|
Map<String, Date> settleDate = new HashMap<>();
|
|
|
@ -95,6 +102,7 @@ public class PlatformClearAnalysisServiceImpl implements PlatformClearService {
|
|
|
|
// deleteSettleLogs();
|
|
|
|
// deleteSettleLogs();
|
|
|
|
generateWechatSettleLogs();
|
|
|
|
generateWechatSettleLogs();
|
|
|
|
generateAlipaySettleLogs();
|
|
|
|
generateAlipaySettleLogs();
|
|
|
|
|
|
|
|
generateAlipayOnlineSettleLogs();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
@Transactional
|
|
|
@ -124,9 +132,35 @@ public class PlatformClearAnalysisServiceImpl implements PlatformClearService {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void generateAlipayOnlineSettleLogs() {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
List<Date> dateList = TimeZoneUtils.getStatetime();
|
|
|
|
|
|
|
|
for (Date dateStr : dateList) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
doVerifyAlipayOnlineSettleLog(dateStr);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
logger.error("获取" + dateStr + "AlipayOnline清算记录失败", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
logger.error("获取AlipayOnline清算记录时间失败", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
@Transactional
|
|
|
|
public void doVerifyAlipaySettleLog(Date dateStr) throws Exception {
|
|
|
|
public void doVerifyAlipaySettleLog(Date dateStr) throws Exception {
|
|
|
|
JSONObject aliSettleLog = alipayClient.downloadRetailSettlements(dateStr);
|
|
|
|
JSONObject aliSettleLog = alipayClient.downloadRetailSettlements(dateStr);
|
|
|
|
|
|
|
|
saveAlipaySettleLog(dateStr, aliSettleLog, "Alipay");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
|
|
|
|
public void doVerifyAlipayOnlineSettleLog(Date dateStr) throws Exception {
|
|
|
|
|
|
|
|
JSONObject aliOnlineSettleLog = alipayClient.downloadOnlineSettlements(dateStr);
|
|
|
|
|
|
|
|
saveAlipaySettleLog(dateStr, aliOnlineSettleLog, "AlipayOnline");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void saveAlipaySettleLog(Date dateStr, JSONObject aliSettleLog, String channel) throws Exception {
|
|
|
|
if (aliSettleLog != null) {
|
|
|
|
if (aliSettleLog != null) {
|
|
|
|
JSONObject settleFee = getAliSettle(aliSettleLog);
|
|
|
|
JSONObject settleFee = getAliSettle(aliSettleLog);
|
|
|
|
JSONObject params = new JSONObject();
|
|
|
|
JSONObject params = new JSONObject();
|
|
|
@ -138,17 +172,17 @@ public class PlatformClearAnalysisServiceImpl implements PlatformClearService {
|
|
|
|
params.put("net_fee", settleFee.getBigDecimal("net_fee"));
|
|
|
|
params.put("net_fee", settleFee.getBigDecimal("net_fee"));
|
|
|
|
params.put("surcharge", settleFee.getBigDecimal("surcharge"));
|
|
|
|
params.put("surcharge", settleFee.getBigDecimal("surcharge"));
|
|
|
|
params.put("settlement_fee", settleFee.getBigDecimal("settlement_fee"));
|
|
|
|
params.put("settlement_fee", settleFee.getBigDecimal("settlement_fee"));
|
|
|
|
params.put("channel", "Alipay");
|
|
|
|
params.put("channel", channel);
|
|
|
|
params.put("last_update_date", new Date());
|
|
|
|
params.put("last_update_date", new Date());
|
|
|
|
JSONObject sysClearData = getSystemClearingAmount(dateStr,null,"Alipay");
|
|
|
|
JSONObject sysClearData = getSystemClearingAmount(dateStr, null, channel);
|
|
|
|
if(sysClearData!=null && sysClearData.size()>0){
|
|
|
|
if (sysClearData != null && sysClearData.size() > 0) {
|
|
|
|
params.put("sys_pay_fee",sysClearData.getBigDecimal("sys_pay_fee"));
|
|
|
|
params.put("sys_pay_fee", sysClearData.getBigDecimal("sys_pay_fee"));
|
|
|
|
params.put("sys_refund_fee",sysClearData.getBigDecimal("sys_refund_fee"));
|
|
|
|
params.put("sys_refund_fee", sysClearData.getBigDecimal("sys_refund_fee"));
|
|
|
|
params.put("sys_net_fee",sysClearData.getBigDecimal("sys_net_fee"));
|
|
|
|
params.put("sys_net_fee", sysClearData.getBigDecimal("sys_net_fee"));
|
|
|
|
params.put("sys_surcharge",sysClearData.getBigDecimal("sys_surcharge"));
|
|
|
|
params.put("sys_surcharge", sysClearData.getBigDecimal("sys_surcharge"));
|
|
|
|
params.put("sys_settlement_fee",sysClearData.getBigDecimal("sys_settle_fee"));
|
|
|
|
params.put("sys_settlement_fee", sysClearData.getBigDecimal("sys_settle_fee"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
JSONObject check = platformSettlementMapper.findByDateMerchant(sdfClear.format(dateStr), "Alipay", "All");
|
|
|
|
JSONObject check = platformSettlementMapper.findByDateMerchant(sdfClear.format(dateStr), channel, "All");
|
|
|
|
if (check != null) {
|
|
|
|
if (check != null) {
|
|
|
|
params.put("log_id", check.getString("log_id"));
|
|
|
|
params.put("log_id", check.getString("log_id"));
|
|
|
|
platformSettlementMapper.update(params);
|
|
|
|
platformSettlementMapper.update(params);
|
|
|
@ -218,9 +252,15 @@ public class PlatformClearAnalysisServiceImpl implements PlatformClearService {
|
|
|
|
if (payments != null) {
|
|
|
|
if (payments != null) {
|
|
|
|
for (int i = 0; i < payments.size(); i++) {
|
|
|
|
for (int i = 0; i < payments.size(); i++) {
|
|
|
|
JSONObject json = payments.getJSONObject(i);
|
|
|
|
JSONObject json = payments.getJSONObject(i);
|
|
|
|
credit = credit.add(json.getBigDecimal("transaction_amount"));
|
|
|
|
BigDecimal transactionAmount = json.getBigDecimal("transaction_amount");
|
|
|
|
creditFee = creditFee.add(json.getBigDecimal("charge_fee"));
|
|
|
|
BigDecimal chargeFee = json.getBigDecimal("charge_fee");
|
|
|
|
|
|
|
|
credit = credit.add(transactionAmount);
|
|
|
|
|
|
|
|
creditFee = creditFee.add(chargeFee);
|
|
|
|
|
|
|
|
if (json.containsKey("settle_amount")) {
|
|
|
|
creditSettle = creditSettle.add(json.getBigDecimal("settle_amount"));
|
|
|
|
creditSettle = creditSettle.add(json.getBigDecimal("settle_amount"));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
creditSettle = creditSettle.add(transactionAmount.subtract(chargeFee));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
alipaySettleLog.put("credit", credit);
|
|
|
|
alipaySettleLog.put("credit", credit);
|
|
|
@ -233,9 +273,15 @@ public class PlatformClearAnalysisServiceImpl implements PlatformClearService {
|
|
|
|
if (refunds != null) {
|
|
|
|
if (refunds != null) {
|
|
|
|
for (int i = 0; i < refunds.size(); i++) {
|
|
|
|
for (int i = 0; i < refunds.size(); i++) {
|
|
|
|
JSONObject json = refunds.getJSONObject(i);
|
|
|
|
JSONObject json = refunds.getJSONObject(i);
|
|
|
|
debit = debit.add(json.getBigDecimal("transaction_amount"));
|
|
|
|
BigDecimal transactionAmount = json.getBigDecimal("transaction_amount");
|
|
|
|
debitFee = debitFee.add(json.getBigDecimal("charge_fee"));
|
|
|
|
BigDecimal chargeFee = json.getBigDecimal("charge_fee");
|
|
|
|
|
|
|
|
debit = debit.add(transactionAmount);
|
|
|
|
|
|
|
|
debitFee = debitFee.add(chargeFee);
|
|
|
|
|
|
|
|
if (json.containsKey("settle_amount")) {
|
|
|
|
debitSettle = debitSettle.add(json.getBigDecimal("settle_amount"));
|
|
|
|
debitSettle = debitSettle.add(json.getBigDecimal("settle_amount"));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
debitSettle = debitSettle.add(transactionAmount.subtract(chargeFee));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
alipaySettleLog.put("debit", debit);
|
|
|
|
alipaySettleLog.put("debit", debit);
|
|
|
@ -246,67 +292,30 @@ public class PlatformClearAnalysisServiceImpl implements PlatformClearService {
|
|
|
|
return alipaySettleLog;
|
|
|
|
return alipaySettleLog;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public JSONObject getSystemClearingAmount(Date settle_date, SettlementLog settlementLog, String channel){
|
|
|
|
public void deleteSettleLogs() {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
List<Date> dateList = TimeZoneUtils.getStatetime();
|
|
|
|
|
|
|
|
for (Date dateStr : dateList) {
|
|
|
|
|
|
|
|
List<JSONObject> logs = platformSettlementMapper.findByDate(DateFormatUtils.format(dateStr, "yyyy-MM-dd"));
|
|
|
|
|
|
|
|
if (logs != null) {
|
|
|
|
|
|
|
|
for (JSONObject log : logs) {
|
|
|
|
|
|
|
|
platformSettlementMapper.delete(log);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public JSONObject getSystemClearingAmount(Date settle_date, SettlementLog settlementLog, String channel) throws Exception {
|
|
|
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd 02:00:00");
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd 02:00:00");
|
|
|
|
JSONObject sysLogs = new JSONObject();
|
|
|
|
JSONObject sysLogs = new JSONObject();
|
|
|
|
String start_date = null;
|
|
|
|
String start_date = null;
|
|
|
|
String end_date = null;
|
|
|
|
String end_date = null;
|
|
|
|
if (StringUtils.equals("Alipay", channel)) {
|
|
|
|
if (StringUtils.equals("Wechat", channel)) {
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject lastClearDay = estimateAnalysisMapper.findLastCleanDays(sdfClear.format(settle_date), 1);
|
|
|
|
|
|
|
|
start_date = sdf.format(lastClearDay.getDate("date_str"));
|
|
|
|
|
|
|
|
end_date = sdf.format(settle_date);
|
|
|
|
|
|
|
|
logger.info("Alipay System Settle Logs:"+start_date+"<====>" +end_date);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else if (StringUtils.equals("Wechat", channel)) {
|
|
|
|
|
|
|
|
start_date = sdf.format(settlementLog.getStart());
|
|
|
|
start_date = sdf.format(settlementLog.getStart());
|
|
|
|
end_date = sdf.format(settlementLog.getEnd());
|
|
|
|
end_date = sdf.format(settlementLog.getEnd());
|
|
|
|
logger.info("Wechat System Settle Logs:"+start_date+"<====>" +end_date);
|
|
|
|
logger.info("Wechat System Settle Logs:" + start_date + "<====>" + end_date);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
JSONObject lastClearDay = estimateAnalysisMapper.findLastCleanDays(sdfClear.format(settle_date), 1);
|
|
|
|
}
|
|
|
|
start_date = sdf.format(lastClearDay.getDate("date_str"));
|
|
|
|
|
|
|
|
end_date = sdf.format(settle_date);
|
|
|
|
//2017-11-01后微信手续费0.5
|
|
|
|
logger.info("Alipay System Settle Logs:" + start_date + "<====>" + end_date);
|
|
|
|
BigDecimal wechat_rate;
|
|
|
|
|
|
|
|
if(end_date.compareTo("2017-11-01 03:00:00")<=0){
|
|
|
|
|
|
|
|
wechat_rate = new BigDecimal("0.006");
|
|
|
|
|
|
|
|
}else {
|
|
|
|
|
|
|
|
wechat_rate = new BigDecimal("0.005");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
JSONObject creditLogs = platformSettlementMapper.calculateSysSettleLog(start_date, end_date, channel, "Credit", wechat_rate);
|
|
|
|
JSONObject creditLogs = platformSettlementMapper.calculateSysSettleLog(start_date, end_date, channel, "Credit");
|
|
|
|
sysLogs.put("sys_pay_fee", creditLogs.getBigDecimal("aud_amount"));
|
|
|
|
sysLogs.put("sys_pay_fee", creditLogs.getBigDecimal("aud_amount"));
|
|
|
|
|
|
|
|
JSONObject debitLogs = platformSettlementMapper.calculateSysSettleLog(start_date, end_date, channel, "Debit");
|
|
|
|
JSONObject debitLogs = platformSettlementMapper.calculateSysSettleLog(start_date, end_date, channel, "Debit", wechat_rate);
|
|
|
|
|
|
|
|
sysLogs.put("sys_refund_fee", debitLogs.getBigDecimal("aud_amount"));
|
|
|
|
sysLogs.put("sys_refund_fee", debitLogs.getBigDecimal("aud_amount"));
|
|
|
|
|
|
|
|
|
|
|
|
sysLogs.put("sys_net_fee", creditLogs.getBigDecimal("aud_amount").subtract(debitLogs.getBigDecimal("aud_amount")));
|
|
|
|
sysLogs.put("sys_net_fee", creditLogs.getBigDecimal("aud_amount").subtract(debitLogs.getBigDecimal("aud_amount")));
|
|
|
|
if(StringUtils.equals("Alipay",channel)){
|
|
|
|
|
|
|
|
sysLogs.put("sys_surcharge",platformSettlementMapper.calculateRmbCharge(start_date, end_date, channel));
|
|
|
|
|
|
|
|
}else {
|
|
|
|
|
|
|
|
sysLogs.put("sys_surcharge", creditLogs.getBigDecimal("charge_amount").subtract(debitLogs.getBigDecimal("charge_amount")));
|
|
|
|
sysLogs.put("sys_surcharge", creditLogs.getBigDecimal("charge_amount").subtract(debitLogs.getBigDecimal("charge_amount")));
|
|
|
|
}
|
|
|
|
|
|
|
|
sysLogs.put("sys_settle_fee", sysLogs.getBigDecimal("sys_net_fee").subtract(sysLogs.getBigDecimal("sys_surcharge")));
|
|
|
|
sysLogs.put("sys_settle_fee", sysLogs.getBigDecimal("sys_net_fee").subtract(sysLogs.getBigDecimal("sys_surcharge")));
|
|
|
|
return sysLogs;
|
|
|
|
return sysLogs;
|
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
//do nothing
|
|
|
|
//do nothing
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|