|
|
|
@ -1,9 +1,14 @@
|
|
|
|
|
package au.com.royalpay.payment.manage.surchargeAccount.core.impl;
|
|
|
|
|
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.system.ClearingDistributedSurchargeMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.system.ClientsSurchargeAccountsMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.system.FinancialSurchargeAccountDetailMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.surchargeAccount.core.SurchargeAccountService;
|
|
|
|
|
import au.com.royalpay.payment.manage.system.core.impl.ClientContractServiceImpl;
|
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.ForbiddenException;
|
|
|
|
|
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.slf4j.Logger;
|
|
|
|
@ -12,6 +17,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
import java.util.Date;
|
|
|
|
@ -24,6 +30,10 @@ public class SurchargeAccountServiceImpl implements SurchargeAccountService{
|
|
|
|
|
private ClearingDistributedSurchargeMapper clearingDistributedSurchargeMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private FinancialSurchargeAccountDetailMapper financialSurchargeAccountDetailMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private Locker locker;
|
|
|
|
|
@Resource
|
|
|
|
|
private ClientsSurchargeAccountsMapper clientsSurchargeAccountsMapper;
|
|
|
|
|
|
|
|
|
|
Logger logger = LoggerFactory.getLogger(ClientContractServiceImpl.class);
|
|
|
|
|
|
|
|
|
@ -50,6 +60,7 @@ public class SurchargeAccountServiceImpl implements SurchargeAccountService{
|
|
|
|
|
detail.put("wx_send", 0);
|
|
|
|
|
detail.put("settle_month", DateFormatUtils.format(datefrom, "yyyy-MM"));
|
|
|
|
|
detail.put("create_time", new Date());
|
|
|
|
|
detail.put("is_valid", 0);
|
|
|
|
|
financialSurchargeAccountDetailMapper.save(detail);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -59,8 +70,41 @@ public class SurchargeAccountServiceImpl implements SurchargeAccountService{
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<JSONObject> listSettledDatesInMonth(String mon) {
|
|
|
|
|
List<JSONObject> settledDates = financialSurchargeAccountDetailMapper.listSettlementDatesInMonth(mon);
|
|
|
|
|
return financialSurchargeAccountDetailMapper.listSettlementDatesInMonth(mon);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return settledDates;
|
|
|
|
|
@Override
|
|
|
|
|
public void fillMothsSurcharge(JSONObject manager, String detail_id) {
|
|
|
|
|
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 (!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 transaction = new JSONObject();
|
|
|
|
|
transaction.put("client_id", detail.getIntValue("client_id"));
|
|
|
|
|
transaction.put("settle_date", detail.getString("settle_date"));
|
|
|
|
|
transaction.put("type", "Credit");
|
|
|
|
|
transaction.put("total_surcharge", BigDecimal.ZERO);
|
|
|
|
|
transaction.put("tax_amount", BigDecimal.ZERO);
|
|
|
|
|
transaction.put("amount", detail.getBigDecimal("debit_amount"));
|
|
|
|
|
transaction.put("post_balance", surcharge_account.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_date")+"冲正");
|
|
|
|
|
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"));
|
|
|
|
|
financialSurchargeAccountDetailMapper.update(detail);
|
|
|
|
|
} finally {
|
|
|
|
|
locker.unlock(detail.getIntValue("client_id") + "_" + detail.getString("settle_month") + "_fill");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|