|
|
|
@ -5,22 +5,29 @@ import au.com.royalpay.payment.channels.wechat.config.WechatPayEnvironment;
|
|
|
|
|
import au.com.royalpay.payment.channels.wechat.runtime.MpPaymentApi;
|
|
|
|
|
import au.com.royalpay.payment.channels.wechat.runtime.beans.SettlementLog;
|
|
|
|
|
import au.com.royalpay.payment.manage.analysis.core.EstimateAnalysisService;
|
|
|
|
|
import au.com.royalpay.payment.manage.analysis.core.EstimateCacheSupport;
|
|
|
|
|
import au.com.royalpay.payment.manage.analysis.mappers.EstimateAnalysisMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.log.ClearingDetailMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.log.ClearingLogMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.log.PlatformSettlementMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.payment.TransactionMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.system.ClientMapper;
|
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
|
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.NotFoundException;
|
|
|
|
|
import au.com.royalpay.payment.tools.utils.TimeZoneUtils;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
|
|
|
|
import org.apache.commons.lang3.time.DateUtils;
|
|
|
|
|
import org.jsoup.helper.DataUtil;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.cache.annotation.Cacheable;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.text.DateFormat;
|
|
|
|
|
import java.text.ParseException;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
@ -51,6 +58,10 @@ public class EstimateAnalysisServiceImpl implements EstimateAnalysisService {
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private ClearingDetailMapper clearingDetailMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private EstimateCacheSupport estimateCacheSupport;
|
|
|
|
|
@Resource
|
|
|
|
|
private TransactionMapper transactionMapper;
|
|
|
|
|
|
|
|
|
|
public static List<String> t1client;
|
|
|
|
|
|
|
|
|
@ -71,10 +82,16 @@ public class EstimateAnalysisServiceImpl implements EstimateAnalysisService {
|
|
|
|
|
private EstimateAnalysisMapper estimateAnalysisMapper;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<JSONObject> listFurtureInfo() throws Exception {
|
|
|
|
|
@Cacheable(value = ":estimate_analysis_future:", key = "''")
|
|
|
|
|
public List<JSONObject> listFutureInfo() throws Exception {
|
|
|
|
|
return listSettlementInfo();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void clearEstimateFutureCache() {
|
|
|
|
|
estimateCacheSupport.clearEstimateFutureCache();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<JSONObject> listSettlementInfo() throws Exception {
|
|
|
|
|
initClient();
|
|
|
|
|
|
|
|
|
@ -102,6 +119,7 @@ public class EstimateAnalysisServiceImpl implements EstimateAnalysisService {
|
|
|
|
|
today.put("t2", realToday.getBigDecimal("t2"));
|
|
|
|
|
today.put("t3", realToday.getBigDecimal("t3"));
|
|
|
|
|
today.put("total", realToday.getBigDecimal("total"));
|
|
|
|
|
today.put("net_amount", realToday.getBigDecimal("net_amount"));
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("今日清算记录未生成,使用自助查询!");
|
|
|
|
|
}
|
|
|
|
@ -138,13 +156,13 @@ public class EstimateAnalysisServiceImpl implements EstimateAnalysisService {
|
|
|
|
|
dayInfo.put("t1", new BigDecimal(0.00));
|
|
|
|
|
dayInfo.put("t2", new BigDecimal(0.00));
|
|
|
|
|
dayInfo.put("t3", new BigDecimal(0.00));
|
|
|
|
|
dayInfo.put("net_amount", new BigDecimal(0.00));
|
|
|
|
|
//todo 支持多个清算记录
|
|
|
|
|
List<JSONObject> logs = clearingLogMapper.findByDate(settleDate);
|
|
|
|
|
if (logs == null || logs.size() <= 0) {
|
|
|
|
|
throw new NotFoundException();
|
|
|
|
|
}
|
|
|
|
|
for (JSONObject log : logs) {
|
|
|
|
|
dayInfo.put("total", log.getBigDecimal("net_amount"));
|
|
|
|
|
JSONObject details = clearingDetailMapper.listReportsOfSettleCleanDay(log.getIntValue("clearing_id"), t1client);
|
|
|
|
|
dayInfo.put("t1", dayInfo.getBigDecimal("t1").add(details.getBigDecimal("total_amount")));
|
|
|
|
|
details.clear();
|
|
|
|
@ -155,7 +173,10 @@ public class EstimateAnalysisServiceImpl implements EstimateAnalysisService {
|
|
|
|
|
|
|
|
|
|
details = clearingDetailMapper.listReportsOfSettleCleanDay(log.getIntValue("clearing_id"), t3client);
|
|
|
|
|
dayInfo.put("t3", dayInfo.getBigDecimal("t3").add(details.getBigDecimal("total_amount")));
|
|
|
|
|
|
|
|
|
|
dayInfo.put("net_amount", dayInfo.getBigDecimal("net_amount").add(log.getBigDecimal("net_amount")));
|
|
|
|
|
}
|
|
|
|
|
dayInfo.put("total", dayInfo.getBigDecimal("t1").add(dayInfo.getBigDecimal("t2")).add(dayInfo.getBigDecimal("t3")));
|
|
|
|
|
return dayInfo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -202,6 +223,30 @@ public class EstimateAnalysisServiceImpl implements EstimateAnalysisService {
|
|
|
|
|
}
|
|
|
|
|
dayInfo.put("estimate_date", endStr);
|
|
|
|
|
dayInfo.put("total", dayInfo.getBigDecimal("t1").add(dayInfo.getBigDecimal("t2")).add(dayInfo.getBigDecimal("t3")));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//预计到账金额
|
|
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
|
|
cal.setTime(date);
|
|
|
|
|
cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH)-1, 0, 0, 0);
|
|
|
|
|
Date datefrom = cal.getTime();
|
|
|
|
|
|
|
|
|
|
if (new Date().getDate() == datefrom.getDate()) {
|
|
|
|
|
JSONObject params = new JSONObject();
|
|
|
|
|
params.put("datefrom", DateFormatUtils.format(datefrom, "yyyy-MM-dd HH:mm:ss"));
|
|
|
|
|
params.put("dateto", DateFormatUtils.format(DateUtils.addDays(datefrom, 1),"yyyy-MM-dd HH:mm:ss"));
|
|
|
|
|
|
|
|
|
|
List<JSONObject> lastDayClearingAmount = transactionMapper.getLastDaytransAmount(params);
|
|
|
|
|
BigDecimal total_clearing = BigDecimal.ZERO;
|
|
|
|
|
BigDecimal total_surcharge = BigDecimal.ZERO;
|
|
|
|
|
for (JSONObject e : lastDayClearingAmount) {
|
|
|
|
|
total_clearing = total_clearing.add(e.getBigDecimal("clearing_amount"));
|
|
|
|
|
total_surcharge = total_surcharge.add(e.getBigDecimal("channel_surcharge"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dayInfo.put("total_clearing", total_clearing.subtract(total_surcharge));
|
|
|
|
|
dayInfo.put("clearing", lastDayClearingAmount);
|
|
|
|
|
}
|
|
|
|
|
return dayInfo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -277,7 +322,7 @@ public class EstimateAnalysisServiceImpl implements EstimateAnalysisService {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void generateSettleAmount() {
|
|
|
|
|
String report_date = DateFormatUtils.format(new Date(), "yyyy/MM/dd");
|
|
|
|
|
String report_date = DateFormatUtils.format(DateUtils.addDays(new Date(),-1), "yyyy/MM/dd");
|
|
|
|
|
logger.info("系统开始生成[ " + report_date + " ]清算总额");
|
|
|
|
|
|
|
|
|
|
JSONObject isClearDay = estimateAnalysisMapper.checkIsClearDay(report_date);
|
|
|
|
@ -327,8 +372,19 @@ public class EstimateAnalysisServiceImpl implements EstimateAnalysisService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<JSONObject> listEstimateLog(int logType) {
|
|
|
|
|
return estimateAnalysisMapper.listEstimateLog(logType);
|
|
|
|
|
public List<JSONObject> listEstimateLog(int logType, String date) {
|
|
|
|
|
Date monthDate;
|
|
|
|
|
try {
|
|
|
|
|
monthDate = DateUtils.parseDate(date, new String[] { "yyyy-MM" });
|
|
|
|
|
} catch (ParseException e) {
|
|
|
|
|
throw new BadRequestException("Invalid month format");
|
|
|
|
|
}
|
|
|
|
|
Calendar monthCal = Calendar.getInstance();
|
|
|
|
|
monthCal.setTime(monthDate);
|
|
|
|
|
int year = monthCal.get(Calendar.YEAR);
|
|
|
|
|
int month = monthCal.get(Calendar.MONTH) + 1;
|
|
|
|
|
|
|
|
|
|
return estimateAnalysisMapper.listEstimateLog(logType, year, month);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|