|
|
@ -1,9 +1,15 @@
|
|
|
|
package au.com.royalpay.payment.manage.surchargeAccount.core.impl;
|
|
|
|
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.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.mappers.system.FinancialSurchargeAccountDetailMapper;
|
|
|
|
import au.com.royalpay.payment.manage.surchargeAccount.core.SurchargeAccountService;
|
|
|
|
import au.com.royalpay.payment.manage.surchargeAccount.core.SurchargeAccountService;
|
|
|
|
import au.com.royalpay.payment.manage.system.core.impl.ClientContractServiceImpl;
|
|
|
|
import au.com.royalpay.payment.manage.system.core.impl.ClientContractServiceImpl;
|
|
|
|
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
|
|
|
|
|
|
|
|
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 com.alibaba.fastjson.JSONObject;
|
|
|
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
|
|
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.Logger;
|
|
|
@ -12,6 +18,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Calendar;
|
|
|
|
import java.util.Calendar;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.Date;
|
|
|
@ -24,6 +31,10 @@ public class SurchargeAccountServiceImpl implements SurchargeAccountService{
|
|
|
|
private ClearingDistributedSurchargeMapper clearingDistributedSurchargeMapper;
|
|
|
|
private ClearingDistributedSurchargeMapper clearingDistributedSurchargeMapper;
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private FinancialSurchargeAccountDetailMapper financialSurchargeAccountDetailMapper;
|
|
|
|
private FinancialSurchargeAccountDetailMapper financialSurchargeAccountDetailMapper;
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
|
|
private Locker locker;
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
|
|
private ClientsSurchargeAccountsMapper clientsSurchargeAccountsMapper;
|
|
|
|
|
|
|
|
|
|
|
|
Logger logger = LoggerFactory.getLogger(ClientContractServiceImpl.class);
|
|
|
|
Logger logger = LoggerFactory.getLogger(ClientContractServiceImpl.class);
|
|
|
|
|
|
|
|
|
|
|
@ -40,27 +51,59 @@ public class SurchargeAccountServiceImpl implements SurchargeAccountService{
|
|
|
|
Date dateto = monthCal.getTime();
|
|
|
|
Date dateto = monthCal.getTime();
|
|
|
|
monthCal.set(Calendar.MONTH, (monthCal.get(Calendar.MONTH) - 1));
|
|
|
|
monthCal.set(Calendar.MONTH, (monthCal.get(Calendar.MONTH) - 1));
|
|
|
|
Date datefrom = monthCal.getTime();
|
|
|
|
Date datefrom = monthCal.getTime();
|
|
|
|
|
|
|
|
|
|
|
|
logger.info("===============Start generator surcharge account month detail===============" + new Date());
|
|
|
|
logger.info("===============Start generator surcharge account month detail===============" + new Date());
|
|
|
|
List<JSONObject> thisMonthDetail = clearingDistributedSurchargeMapper.getMonthDetailByClientId(datefrom, dateto);
|
|
|
|
List<JSONObject> thisMonthDetail = clearingDistributedSurchargeMapper.getMonthDetailByClientId(datefrom, dateto);
|
|
|
|
logger.info("this month details : " + thisMonthDetail.toString());
|
|
|
|
logger.info("this month details : " + thisMonthDetail.toString());
|
|
|
|
|
|
|
|
|
|
|
|
for (JSONObject detail : thisMonthDetail) {
|
|
|
|
for (JSONObject detail : thisMonthDetail) {
|
|
|
|
detail.put("send_mail", 0);
|
|
|
|
detail.put("send_mail", 0);
|
|
|
|
detail.put("wx_send", 0);
|
|
|
|
detail.put("wx_send", 0);
|
|
|
|
detail.put("settle_month", DateFormatUtils.format(datefrom, "yyyy-MM"));
|
|
|
|
detail.put("settle_month", DateFormatUtils.format(datefrom, "yyyy-MM"));
|
|
|
|
detail.put("create_time", new Date());
|
|
|
|
detail.put("create_time", new Date());
|
|
|
|
|
|
|
|
detail.put("is_valid", 0);
|
|
|
|
financialSurchargeAccountDetailMapper.save(detail);
|
|
|
|
financialSurchargeAccountDetailMapper.save(detail);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
logger.info("===============generator OVER===============" + new Date());
|
|
|
|
logger.info("===============generator OVER===============" + new Date());
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<JSONObject> listSettledDatesInMonth(String mon) {
|
|
|
|
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 (detail.getBooleanValue("is_valid")) {
|
|
|
|
|
|
|
|
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 transaction = new JSONObject();
|
|
|
|
|
|
|
|
transaction.put("client_id", detail.getIntValue("client_id"));
|
|
|
|
|
|
|
|
// transaction.put("settle_date", detail.getString("settle_month"));
|
|
|
|
|
|
|
|
transaction.put("type", "Credit");
|
|
|
|
|
|
|
|
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("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"));
|
|
|
|
|
|
|
|
financialSurchargeAccountDetailMapper.update(detail);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
locker.unlock(detail.getIntValue("client_id") + "_" + detail.getString("settle_month") + "_fill");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|