|
|
@ -11,8 +11,6 @@ import au.com.royalpay.payment.tools.exceptions.ServerErrorException;
|
|
|
|
import au.com.royalpay.payment.tools.lock.Locker;
|
|
|
|
import au.com.royalpay.payment.tools.lock.Locker;
|
|
|
|
import au.com.royalpay.payment.tools.permission.enums.ManagerRole;
|
|
|
|
import au.com.royalpay.payment.tools.permission.enums.ManagerRole;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.time.DateUtils;
|
|
|
|
|
|
|
|
import org.joda.time.DateTime;
|
|
|
|
import org.joda.time.DateTime;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
@ -21,7 +19,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
import java.text.DateFormat;
|
|
|
|
|
|
|
|
import java.util.Comparator;
|
|
|
|
import java.util.Comparator;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
@ -39,12 +36,11 @@ public class SurchargeAccountServiceImpl implements SurchargeAccountService {
|
|
|
|
private Locker locker;
|
|
|
|
private Locker locker;
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private ClientsSurchargeAccountsMapper clientsSurchargeAccountsMapper;
|
|
|
|
private ClientsSurchargeAccountsMapper clientsSurchargeAccountsMapper;
|
|
|
|
|
|
|
|
private Logger logger = LoggerFactory.getLogger(ClientContractServiceImpl.class);
|
|
|
|
Logger logger = LoggerFactory.getLogger(ClientContractServiceImpl.class);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@Transactional
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
public void generatorMonthDetail() {
|
|
|
|
public void generatorMonthDetail() {
|
|
|
|
DateTime dateTo = DateTime.now().withMillisOfDay(0).withDayOfMonth(1);
|
|
|
|
DateTime dateTo = DateTime.now().withMillisOfDay(0).withDayOfMonth(1);
|
|
|
|
logger.info("===============Start generator surcharge account month detail==============={}", new Date());
|
|
|
|
logger.info("===============Start generator surcharge account month detail==============={}", new Date());
|
|
|
@ -67,6 +63,7 @@ public class SurchargeAccountServiceImpl implements SurchargeAccountService {
|
|
|
|
.reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
|
|
|
|
.reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
|
|
|
|
detail.put("credit_amount", creditAmount);
|
|
|
|
detail.put("credit_amount", creditAmount);
|
|
|
|
detail.put("debit_amount", debitAmount);
|
|
|
|
detail.put("debit_amount", debitAmount);
|
|
|
|
|
|
|
|
detail.put("total_surcharge", creditAmount.add(debitAmount));
|
|
|
|
JSONObject lastTrans = surchargeTrans.stream().max(Comparator.comparing(trans -> trans.getDate("create_time")))
|
|
|
|
JSONObject lastTrans = surchargeTrans.stream().max(Comparator.comparing(trans -> trans.getDate("create_time")))
|
|
|
|
.orElse(null);
|
|
|
|
.orElse(null);
|
|
|
|
BigDecimal postBalance;
|
|
|
|
BigDecimal postBalance;
|
|
|
@ -80,8 +77,13 @@ public class SurchargeAccountServiceImpl implements SurchargeAccountService {
|
|
|
|
detail.put("send_mail", 0);
|
|
|
|
detail.put("send_mail", 0);
|
|
|
|
detail.put("wx_send", 0);
|
|
|
|
detail.put("wx_send", 0);
|
|
|
|
detail.put("create_time", new Date());
|
|
|
|
detail.put("create_time", new Date());
|
|
|
|
detail.put("is_valid", 0);
|
|
|
|
detail.put("checkout", 0);
|
|
|
|
financialSurchargeAccountDetailMapper.save(detail);
|
|
|
|
financialSurchargeAccountDetailMapper.save(detail);
|
|
|
|
|
|
|
|
//更新手续费明细中的账单id
|
|
|
|
|
|
|
|
surchargeTrans.forEach(trans -> {
|
|
|
|
|
|
|
|
trans.put("bill_id", detail.getString("detail_id"));
|
|
|
|
|
|
|
|
clearingDistributedSurchargeMapper.update(trans);
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
logger.info("===============generator OVER==============={}", new Date());
|
|
|
|
logger.info("===============generator OVER==============={}", new Date());
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -92,35 +94,36 @@ public class SurchargeAccountServiceImpl implements SurchargeAccountService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void fillMothsSurcharge(JSONObject manager, String detail_id) {
|
|
|
|
public void fillMothsSurcharge(JSONObject manager, String detailId) {
|
|
|
|
if (!(ManagerRole.ADMIN.hasRole(manager.getIntValue("role")) || ManagerRole.OPERATOR.hasRole(manager.getIntValue("role")) || ManagerRole.FINANCIAL_STAFF.hasRole(manager.getIntValue("role")))) {
|
|
|
|
if (!(ManagerRole.ADMIN.hasRole(manager.getIntValue("role")) || ManagerRole.OPERATOR.hasRole(manager.getIntValue("role")) || ManagerRole.FINANCIAL_STAFF.hasRole(manager.getIntValue("role")))) {
|
|
|
|
throw new ForbiddenException("无法执行平账操作,权限不足");
|
|
|
|
throw new ForbiddenException("无法执行平账操作,权限不足");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
JSONObject detail = financialSurchargeAccountDetailMapper.findByDetailId(detail_id);
|
|
|
|
JSONObject detail = financialSurchargeAccountDetailMapper.findByDetailId(detailId);
|
|
|
|
if (detail.getBooleanValue("is_valid")) {
|
|
|
|
if (detail.getBooleanValue("checkout")) {
|
|
|
|
throw new BadRequestException("该记录已结清");
|
|
|
|
throw new BadRequestException("该记录已结清");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!locker.lock(detail.getIntValue("client_id") + "_" + detail.getString("settle_month") + "_fill", 120_000)) {
|
|
|
|
if (!locker.lock(detail.getIntValue("client_id") + "_" + detail.getString("settle_month") + "_fill", 120_000)) {
|
|
|
|
throw new ServerErrorException("Processing task, wait for a moment");
|
|
|
|
throw new ServerErrorException("Processing task, wait for a moment");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
JSONObject surcharge_account = clientsSurchargeAccountsMapper.find(detail.getIntValue("client_id"));
|
|
|
|
JSONObject surchargeAccount = clientsSurchargeAccountsMapper.find(detail.getIntValue("client_id"));
|
|
|
|
JSONObject transaction = new JSONObject();
|
|
|
|
JSONObject transaction = new JSONObject();
|
|
|
|
transaction.put("client_id", detail.getIntValue("client_id"));
|
|
|
|
transaction.put("client_id", detail.getIntValue("client_id"));
|
|
|
|
transaction.put("type", "Credit");
|
|
|
|
transaction.put("type", "Credit");
|
|
|
|
|
|
|
|
transaction.put("bill_id", detailId);
|
|
|
|
transaction.put("total_surcharge", BigDecimal.ZERO);
|
|
|
|
transaction.put("total_surcharge", BigDecimal.ZERO);
|
|
|
|
transaction.put("tax_amount", BigDecimal.ZERO);
|
|
|
|
transaction.put("tax_amount", BigDecimal.ZERO);
|
|
|
|
transaction.put("amount", detail.getBigDecimal("debit_amount").negate());
|
|
|
|
transaction.put("amount", detail.getBigDecimal("debit_amount").negate());
|
|
|
|
transaction.put("post_balance", surcharge_account.getBigDecimal("balance").add(transaction.getBigDecimal("amount")));
|
|
|
|
transaction.put("post_balance", surchargeAccount.getBigDecimal("balance").add(transaction.getBigDecimal("amount")));
|
|
|
|
transaction.put("operation", manager.getString("manager_id"));
|
|
|
|
transaction.put("operation", manager.getString("manager_id"));
|
|
|
|
transaction.put("create_time", new Date());
|
|
|
|
transaction.put("create_time", new Date());
|
|
|
|
transaction.put("remark", detail.getString("settle_month") + "冲正");
|
|
|
|
transaction.put("remark", detail.getString("settle_month") + "冲正");
|
|
|
|
clearingDistributedSurchargeMapper.save(transaction);
|
|
|
|
clearingDistributedSurchargeMapper.save(transaction);
|
|
|
|
|
|
|
|
|
|
|
|
surcharge_account.put("balance", surcharge_account.getBigDecimal("balance").add(transaction.getBigDecimal("amount")));
|
|
|
|
surchargeAccount.put("balance", surchargeAccount.getBigDecimal("balance").add(transaction.getBigDecimal("amount")));
|
|
|
|
clientsSurchargeAccountsMapper.update(surcharge_account);
|
|
|
|
clientsSurchargeAccountsMapper.update(surchargeAccount);
|
|
|
|
detail.put("is_valid", 1);
|
|
|
|
detail.put("checkout", 1);
|
|
|
|
detail.put("operator_id", manager.getString("manager_id"));
|
|
|
|
detail.put("operator_id", manager.getString("display_name"));
|
|
|
|
financialSurchargeAccountDetailMapper.update(detail);
|
|
|
|
financialSurchargeAccountDetailMapper.update(detail);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
locker.unlock(detail.getIntValue("client_id") + "_" + detail.getString("settle_month") + "_fill");
|
|
|
|
locker.unlock(detail.getIntValue("client_id") + "_" + detail.getString("settle_month") + "_fill");
|
|
|
|