|
|
|
@ -11,7 +11,7 @@ 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.joda.time.DateTime;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
@ -19,13 +19,14 @@ 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.Comparator;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
public class SurchargeAccountServiceImpl implements SurchargeAccountService{
|
|
|
|
|
public class SurchargeAccountServiceImpl implements SurchargeAccountService {
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private ClearingDistributedSurchargeMapper clearingDistributedSurchargeMapper;
|
|
|
|
@ -41,28 +42,45 @@ public class SurchargeAccountServiceImpl implements SurchargeAccountService{
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional
|
|
|
|
|
public void generatorMonthDetail(){
|
|
|
|
|
Calendar monthCal = Calendar.getInstance();
|
|
|
|
|
monthCal.setTime(new Date());
|
|
|
|
|
monthCal.set(Calendar.DAY_OF_MONTH, 1);
|
|
|
|
|
monthCal.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
|
|
monthCal.set(Calendar.MINUTE, 0);
|
|
|
|
|
monthCal.set(Calendar.SECOND, 0);
|
|
|
|
|
Date dateto = monthCal.getTime();
|
|
|
|
|
monthCal.set(Calendar.MONTH, (monthCal.get(Calendar.MONTH) - 1));
|
|
|
|
|
Date datefrom = monthCal.getTime();
|
|
|
|
|
logger.info("===============Start generator surcharge account month detail===============" + new Date());
|
|
|
|
|
List<JSONObject> thisMonthDetail = clearingDistributedSurchargeMapper.getMonthDetailByClientId(datefrom, dateto);
|
|
|
|
|
logger.info("this month details : " + thisMonthDetail.toString());
|
|
|
|
|
for (JSONObject detail : thisMonthDetail) {
|
|
|
|
|
public void generatorMonthDetail() {
|
|
|
|
|
DateTime dateTo = DateTime.now().withMillisOfDay(0).withDayOfMonth(1);
|
|
|
|
|
logger.info("===============Start generator surcharge account month detail==============={}", new Date());
|
|
|
|
|
List<JSONObject> surchargeTransactions = clearingDistributedSurchargeMapper.listUnClearedByMonth(dateTo);
|
|
|
|
|
Map<Integer, List<JSONObject>> clientsDistributed = surchargeTransactions.stream().collect(Collectors.groupingBy(trans -> trans.getInteger("client_id")));
|
|
|
|
|
for (Map.Entry<Integer, List<JSONObject>> clientEntry : clientsDistributed.entrySet()) {
|
|
|
|
|
int clientId = clientEntry.getKey();
|
|
|
|
|
List<JSONObject> surchargeTrans = clientEntry.getValue();
|
|
|
|
|
surchargeTrans.sort(Comparator.comparing(trans -> trans.getDate("create_time")));
|
|
|
|
|
JSONObject detail = new JSONObject();
|
|
|
|
|
detail.put("client_id", clientId);
|
|
|
|
|
detail.put("settle_month", dateTo.toString("yyyy-MM"));
|
|
|
|
|
BigDecimal creditAmount = surchargeTrans.stream()
|
|
|
|
|
.filter(trans -> "Credit".equals(trans.getString("type")))
|
|
|
|
|
.map(trans -> trans.getBigDecimal("amount"))
|
|
|
|
|
.reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
|
|
|
|
|
BigDecimal debitAmount = surchargeTrans.stream()
|
|
|
|
|
.filter(trans -> "Debit".equals(trans.getString("type")))
|
|
|
|
|
.map(trans -> trans.getBigDecimal("amount"))
|
|
|
|
|
.reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
|
|
|
|
|
detail.put("credit_amount", creditAmount);
|
|
|
|
|
detail.put("debit_amount", debitAmount);
|
|
|
|
|
JSONObject lastTrans = surchargeTrans.stream().max(Comparator.comparing(trans -> trans.getDate("create_time")))
|
|
|
|
|
.orElse(null);
|
|
|
|
|
BigDecimal postBalance;
|
|
|
|
|
if (lastTrans == null) {
|
|
|
|
|
JSONObject account = clientsSurchargeAccountsMapper.find(clientId);
|
|
|
|
|
postBalance = account == null ? BigDecimal.ZERO : account.getBigDecimal("balance");
|
|
|
|
|
} else {
|
|
|
|
|
postBalance = lastTrans.getBigDecimal("post_balance");
|
|
|
|
|
}
|
|
|
|
|
detail.put("post_balance", postBalance);
|
|
|
|
|
detail.put("send_mail", 0);
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
logger.info("===============generator OVER===============" + new Date());
|
|
|
|
|
logger.info("===============generator OVER==============={}", new Date());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -88,12 +106,12 @@ public class SurchargeAccountServiceImpl implements SurchargeAccountService{
|
|
|
|
|
transaction.put("client_id", detail.getIntValue("client_id"));
|
|
|
|
|
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")+"冲正");
|
|
|
|
|
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")));
|
|
|
|
|