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