parent
4d2a27c2ca
commit
de40d0d0ea
@ -0,0 +1,31 @@
|
||||
package au.com.royalpay.payment.manage.mappers.payment;
|
||||
|
||||
import cn.yixblog.support.mybatis.autosql.annotations.AdvanceSelect;
|
||||
import cn.yixblog.support.mybatis.autosql.annotations.AutoMapper;
|
||||
import cn.yixblog.support.mybatis.autosql.annotations.AutoSql;
|
||||
import cn.yixblog.support.mybatis.autosql.annotations.SqlType;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Create by yixian at 2018-03-20 18:05
|
||||
*/
|
||||
@AutoMapper(tablename = "task_client_manual_settle", pkName = "task_id")
|
||||
public interface TaskManualSettleMapper {
|
||||
|
||||
@AutoSql(type = SqlType.SELECT)
|
||||
@AdvanceSelect(addonWhereClause = "request_time>curdate()")
|
||||
JSONObject findTodayTask(@Param("client_id") int clientId);
|
||||
|
||||
@AutoSql(type = SqlType.SELECT)
|
||||
@AdvanceSelect(addonWhereClause = "clearing_order is null")
|
||||
List<JSONObject> listActiveTasks(@Param("client_id") int clientId);
|
||||
|
||||
@AutoSql(type = SqlType.INSERT)
|
||||
void save(JSONObject task);
|
||||
|
||||
@AutoSql(type = SqlType.UPDATE)
|
||||
void update(JSONObject task);
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package au.com.royalpay.payment.manage.settlement.core;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Create by yixian at 2018-03-20 17:42
|
||||
*/
|
||||
public interface ManualSettleSupport {
|
||||
|
||||
JSONObject requestManualSettle(Date settleTo, String accountId);
|
||||
|
||||
JSONObject findCurrentSettle(int clientId, boolean includingUnsettleData);
|
||||
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
package au.com.royalpay.payment.manage.settlement.core.impls;
|
||||
|
||||
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.ClientAccountMapper;
|
||||
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.merchants.core.MerchantInfoProvider;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.commons.lang3.time.DateFormatUtils;
|
||||
import org.apache.commons.lang3.time.DateUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Create by yixian at 2018-03-20 17:44
|
||||
*/
|
||||
@Service
|
||||
public class ManualSettleSupportImpl implements ManualSettleSupport {
|
||||
|
||||
@Resource
|
||||
private MerchantInfoProvider merchantInfoProvider;
|
||||
@Resource
|
||||
private TransactionMapper transactionMapper;
|
||||
@Resource
|
||||
private TaskManualSettleMapper taskManualSettleMapper;
|
||||
@Resource
|
||||
private ClearingLogMapper clearingLogMapper;
|
||||
@Resource
|
||||
private ClientAccountMapper clientAccountMapper;
|
||||
|
||||
@Override
|
||||
public JSONObject requestManualSettle(Date settleTo, String accountId) {
|
||||
JSONObject account = clientAccountMapper.findById(accountId);
|
||||
int clientId = account.getIntValue("client_id");
|
||||
JSONObject client = merchantInfoProvider.getClientInfo(clientId);
|
||||
if (!client.getBooleanValue("manual_settle")) {
|
||||
throw new ForbiddenException("Manual Settlement Not Enabled");
|
||||
}
|
||||
if (DateUtils.isSameDay(new Date(), settleTo)) {
|
||||
throw new BadRequestException("Cannot settle today's transactions");
|
||||
}
|
||||
JSONObject currentTask = findCurrentSettle(clientId, false);
|
||||
String taskId = currentTask.getString("task_id");
|
||||
currentTask.put("request_time", new Date());
|
||||
currentTask.put("client_id", clientId);
|
||||
currentTask.put("applier_id", account.getString("account_id"));
|
||||
currentTask.put("applier_name", account.getString("display_name"));
|
||||
currentTask.put("settle_to", settleTo);
|
||||
if (taskId != null) {
|
||||
taskManualSettleMapper.update(currentTask);
|
||||
} else {
|
||||
taskManualSettleMapper.save(currentTask);
|
||||
}
|
||||
return currentTask;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject findCurrentSettle(int clientId, boolean includingUnsettleData) {
|
||||
JSONObject todayTask = taskManualSettleMapper.findTodayTask(clientId);
|
||||
if (todayTask != null) {
|
||||
todayTask.put("settle_to", DateFormatUtils.format(todayTask.getDate("settle_to"), "yyyy-MM-dd"));
|
||||
} else {
|
||||
todayTask = new JSONObject();
|
||||
}
|
||||
List<JSONObject> settleLogs = clearingLogMapper.findByDate(new Date());
|
||||
//今天未清算则锁定
|
||||
todayTask.put("locked", settleLogs.isEmpty());
|
||||
if (includingUnsettleData) {
|
||||
List<JSONObject> unsettleReports = transactionMapper.listClientUnsettleDataByDate(clientId);
|
||||
unsettleReports.parallelStream().forEach(report -> report.put("date_str", DateFormatUtils.format(report.getDate("trans_date"), "yyyy-MM-dd")));
|
||||
todayTask.put("unsettle", unsettleReports);
|
||||
}
|
||||
return todayTask;
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
/**
|
||||
* 清算相关
|
||||
* Create by yixian at 2018-03-20 17:42
|
||||
*/
|
||||
package au.com.royalpay.payment.manage.settlement;
|
Loading…
Reference in new issue