|
|
|
@ -4,14 +4,15 @@ import au.com.royalpay.payment.manage.analysis.mappers.ClientAnalysisMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.log.ClearingLogMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.payment.TaskManualSettleMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.payment.TransactionMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.system.CalendarMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.system.ClientAccountMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.system.HolidayDAO;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.system.HolidayMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.merchants.core.ClientManager;
|
|
|
|
|
import au.com.royalpay.payment.manage.settlement.core.ManualSettleSupport;
|
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
|
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.ForbiddenException;
|
|
|
|
|
import au.com.royalpay.payment.tools.locale.LocaleSupport;
|
|
|
|
|
import au.com.royalpay.payment.tools.merchants.core.MerchantInfoProvider;
|
|
|
|
|
import au.com.royalpay.payment.tools.merchants.beans.BalanceGroup;
|
|
|
|
|
import au.com.royalpay.payment.tools.permission.enums.PartnerRole;
|
|
|
|
|
import au.com.royalpay.payment.tools.utils.CurrencyAmountUtils;
|
|
|
|
|
import au.com.royalpay.payment.tools.utils.PageListUtils;
|
|
|
|
@ -21,6 +22,8 @@ import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
|
|
|
|
|
import com.github.miemiedev.mybatis.paginator.domain.PageList;
|
|
|
|
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
|
|
|
|
import org.apache.commons.lang3.time.DateUtils;
|
|
|
|
|
import org.joda.time.DateTime;
|
|
|
|
|
import org.joda.time.DateTimeConstants;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
@ -35,8 +38,6 @@ import java.util.List;
|
|
|
|
|
@Service
|
|
|
|
|
public class ManualSettleSupportImpl implements ManualSettleSupport {
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private MerchantInfoProvider merchantInfoProvider;
|
|
|
|
|
@Resource
|
|
|
|
|
private TransactionMapper transactionMapper;
|
|
|
|
|
@Resource
|
|
|
|
@ -46,7 +47,7 @@ public class ManualSettleSupportImpl implements ManualSettleSupport {
|
|
|
|
|
@Resource
|
|
|
|
|
private ClientAccountMapper clientAccountMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private CalendarMapper calendarMapper;
|
|
|
|
|
private HolidayMapper holidayMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private ClientManager clientManager;
|
|
|
|
|
@Resource
|
|
|
|
@ -99,18 +100,18 @@ public class ManualSettleSupportImpl implements ManualSettleSupport {
|
|
|
|
|
} else {
|
|
|
|
|
todayTask = new JSONObject();
|
|
|
|
|
}
|
|
|
|
|
Date nextSettle = calendarMapper.findNextClearingDate(DateUtils.truncate(new Date(), Calendar.DATE));
|
|
|
|
|
boolean locked = DateUtils.isSameDay(nextSettle, new Date());
|
|
|
|
|
HolidayDAO holiday = holidayMapper.findDefine(DateTime.now().toString("yyyy-MM-dd"));
|
|
|
|
|
boolean locked = holiday != null;
|
|
|
|
|
//今天是清算日
|
|
|
|
|
if (locked) {
|
|
|
|
|
List<JSONObject> settleLogs = clearingLogMapper.findByDate(new Date());
|
|
|
|
|
//清算日但无清算记录
|
|
|
|
|
locked = locked && settleLogs.isEmpty();
|
|
|
|
|
locked = settleLogs.isEmpty();
|
|
|
|
|
}
|
|
|
|
|
//今天未清算则锁定
|
|
|
|
|
todayTask.put("locked", locked);
|
|
|
|
|
if (includingUnsettleData) {
|
|
|
|
|
Date end = findSettleTo(clientId);
|
|
|
|
|
Date end = findSettleTo(client.getIntValue("clean_days"), new Date(), client);
|
|
|
|
|
List<JSONObject> unsettleReports = transactionMapper.listClientUnsettleDataByDate(clientId, end);
|
|
|
|
|
unsettleReports.parallelStream().forEach(report -> {
|
|
|
|
|
report.put("clearing_amount", CurrencyAmountUtils.scalePlatformCurrency(report.getBigDecimal("clearing_amount")));
|
|
|
|
@ -129,20 +130,43 @@ public class ManualSettleSupportImpl implements ManualSettleSupport {
|
|
|
|
|
return todayTask;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Date findSettleTo(int clientId) {
|
|
|
|
|
Date today = DateUtils.truncate(new Date(), Calendar.DATE);
|
|
|
|
|
JSONObject rateConfig = merchantInfoProvider.clientCurrentRate(clientId, today, "Wechat");
|
|
|
|
|
int cleanDays = rateConfig.getIntValue("clean_days");
|
|
|
|
|
List<Date> settleDateRange = calendarMapper.findClearingDateRange(today, cleanDays - 1);
|
|
|
|
|
Date end;
|
|
|
|
|
if (settleDateRange.size() < 2) {
|
|
|
|
|
end = DateUtils.addDays(today, -cleanDays);
|
|
|
|
|
} else {
|
|
|
|
|
end = DateUtils.addDays(settleDateRange.get(0), -1);
|
|
|
|
|
|
|
|
|
|
private Date findSettleTo(int cleanDays, Date settleDate, JSONObject client) {
|
|
|
|
|
Date end = findPreviousWorkDay(settleDate, true);
|
|
|
|
|
for (int d = 0; d < cleanDays; d++) {
|
|
|
|
|
end = findPreviousWorkDay(end, false);
|
|
|
|
|
end = DateUtils.addDays(end, -1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (client.getBooleanValue("weekend_delay") && cleanDays == 1 && new DateTime(settleDate).dayOfWeek().get() == DateTimeConstants.MONDAY) {// 周一
|
|
|
|
|
end = findPreviousWorkDay(end, false);
|
|
|
|
|
}
|
|
|
|
|
end = DateUtils.truncate(end, Calendar.DATE);
|
|
|
|
|
return end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Date findPreviousWorkDay(Date end, boolean testHoliday) {
|
|
|
|
|
while (isWeekend(new DateTime(end)) || (testHoliday && isHoliday(end))) {
|
|
|
|
|
end = DateUtils.addDays(end, -1);
|
|
|
|
|
}
|
|
|
|
|
return end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean isHoliday(Date date) {
|
|
|
|
|
HolidayDAO define = holidayMapper.findDefine(new DateTime(date).toString("yyyy-MM-dd"));
|
|
|
|
|
if (define == null) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return !define.toHolidayDefine().canSettle(BalanceGroup.NORMAL_CROSS_BORDER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static boolean isWeekend(DateTime date) {
|
|
|
|
|
int day = date.dayOfWeek().get();
|
|
|
|
|
return day == DateTimeConstants.SATURDAY || day == DateTimeConstants.SUNDAY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public JSONObject listWithClearInfo(int page) {
|
|
|
|
|
PageList<JSONObject> manuals = taskManualSettleMapper.getEveryLatestRecord(
|
|
|
|
|