financial surcharge account detail analysis process fix

master
yixian 6 years ago
parent 51c05147ad
commit 34ed131680

@ -1,11 +1,11 @@
package au.com.royalpay.payment.manage.mappers.system; package au.com.royalpay.payment.manage.mappers.system;
import cn.yixblog.support.mybatis.autosql.annotations.AdvanceSelect;
import cn.yixblog.support.mybatis.autosql.annotations.AutoMapper; import cn.yixblog.support.mybatis.autosql.annotations.AutoMapper;
import cn.yixblog.support.mybatis.autosql.annotations.AutoSql; import cn.yixblog.support.mybatis.autosql.annotations.AutoSql;
import cn.yixblog.support.mybatis.autosql.annotations.SqlType; import cn.yixblog.support.mybatis.autosql.annotations.SqlType;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.joda.time.DateTime;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -22,4 +22,6 @@ public interface ClearingDistributedSurchargeMapper {
List<JSONObject> getMonthDetailByClientId(@Param("datefrom") Date datefrom, @Param("dateto") Date dateto); List<JSONObject> getMonthDetailByClientId(@Param("datefrom") Date datefrom, @Param("dateto") Date dateto);
List<JSONObject> findTransactionsByDate(JSONObject params); List<JSONObject> findTransactionsByDate(JSONObject params);
List<JSONObject> listUnClearedByMonth(@Param("dateto") DateTime dateTo);
} }

@ -6,7 +6,6 @@ import cn.yixblog.support.mybatis.autosql.annotations.SqlType;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.Date;
import java.util.List; import java.util.List;

@ -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.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.joda.time.DateTime;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -19,10 +19,11 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList; import java.util.Comparator;
import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service @Service
public class SurchargeAccountServiceImpl implements SurchargeAccountService { public class SurchargeAccountServiceImpl implements SurchargeAccountService {
@ -42,27 +43,44 @@ public class SurchargeAccountServiceImpl implements SurchargeAccountService{
@Override @Override
@Transactional @Transactional
public void generatorMonthDetail() { public void generatorMonthDetail() {
Calendar monthCal = Calendar.getInstance(); DateTime dateTo = DateTime.now().withMillisOfDay(0).withDayOfMonth(1);
monthCal.setTime(new Date()); logger.info("===============Start generator surcharge account month detail==============={}", new Date());
monthCal.set(Calendar.DAY_OF_MONTH, 1); List<JSONObject> surchargeTransactions = clearingDistributedSurchargeMapper.listUnClearedByMonth(dateTo);
monthCal.set(Calendar.HOUR_OF_DAY, 0); Map<Integer, List<JSONObject>> clientsDistributed = surchargeTransactions.stream().collect(Collectors.groupingBy(trans -> trans.getInteger("client_id")));
monthCal.set(Calendar.MINUTE, 0); for (Map.Entry<Integer, List<JSONObject>> clientEntry : clientsDistributed.entrySet()) {
monthCal.set(Calendar.SECOND, 0); int clientId = clientEntry.getKey();
Date dateto = monthCal.getTime(); List<JSONObject> surchargeTrans = clientEntry.getValue();
monthCal.set(Calendar.MONTH, (monthCal.get(Calendar.MONTH) - 1)); surchargeTrans.sort(Comparator.comparing(trans -> trans.getDate("create_time")));
Date datefrom = monthCal.getTime(); JSONObject detail = new JSONObject();
logger.info("===============Start generator surcharge account month detail===============" + new Date()); detail.put("client_id", clientId);
List<JSONObject> thisMonthDetail = clearingDistributedSurchargeMapper.getMonthDetailByClientId(datefrom, dateto); detail.put("settle_month", dateTo.toString("yyyy-MM"));
logger.info("this month details : " + thisMonthDetail.toString()); BigDecimal creditAmount = surchargeTrans.stream()
for (JSONObject detail : thisMonthDetail) { .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("send_mail", 0);
detail.put("wx_send", 0); detail.put("wx_send", 0);
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); 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

@ -130,6 +130,12 @@ settle.abafile.bank.ANZ.bsb=013006
settle.abafile.bank.ANZ.account-no=837022519 settle.abafile.bank.ANZ.account-no=837022519
settle.abafile.bank.ANZ.account-name=Tunnel Show Pty Ltd settle.abafile.bank.ANZ.account-name=Tunnel Show Pty Ltd
settle.abafile.bank.NAB.manual-sending=true
settle.abafile.bank.NAB.bank=NAB
settle.abafile.bank.NAB.apca=514624
settle.abafile.bank.NAB.bsb=013006
settle.abafile.bank.NAB.account-no=837022519
settle.abafile.bank.NAB.account-name=Tunnel Show Pty Ltd
# 瀚银Secure # 瀚银Secure
app.hanyin-secure.pid=ROYALPAY app.hanyin-secure.pid=ROYALPAY

@ -3,31 +3,47 @@
<mapper namespace="au.com.royalpay.payment.manage.mappers.system.ClearingDistributedSurchargeMapper"> <mapper namespace="au.com.royalpay.payment.manage.mappers.system.ClearingDistributedSurchargeMapper">
<select id="getMonthDetailByClientId" resultType="com.alibaba.fastjson.JSONObject"> <select id="getMonthDetailByClientId" resultType="com.alibaba.fastjson.JSONObject">
<![CDATA[ <![CDATA[
SELECT d.client_id,c.client_moniker,c.company_name, SELECT d.client_id,
c.client_moniker,
c.company_name,
SUM(IF(d.type = 'Debit', total_surcharge, -total_surcharge)) total_surcharge, SUM(IF(d.type = 'Debit', total_surcharge, -total_surcharge)) total_surcharge,
SUM(IF(d.type = 'Credit', amount, 0)) credit_amount, SUM(IF(d.type = 'Credit', amount, 0)) credit_amount,
SUM(IF(d.type = 'Debit', amount, 0)) debit_amount, SUM(IF(d.type = 'Debit', amount, 0)) debit_amount,
SUM(IF(d.type = 'Debit', total_surcharge, 0)) total_surcharge SUM(IF(d.type = 'Debit', total_surcharge, 0)) total_surcharge
FROM log_clearing_distributed_surcharge d INNER JOIN sys_clients c ON c.client_id=d.client_id FROM log_clearing_distributed_surcharge d
WHERE d.create_time >=#{datefrom} AND d.create_time < #{dateto} INNER JOIN sys_clients c ON c.client_id = d.client_id
WHERE d.create_time >= #{datefrom}
AND d.create_time < #{dateto}
AND c.is_valid = 1 AND c.is_valid = 1
GROUP BY d.client_id GROUP BY d.client_id
]]> ]]>
</select> </select>
<select id="findTransactions" resultType="com.alibaba.fastjson.JSONObject"> <select id="findTransactions" resultType="com.alibaba.fastjson.JSONObject">
<![CDATA[ <![CDATA[
SELECT * FROM log_clearing_distributed_surcharge WHERE client_id = #{client_id} SELECT *
FROM log_clearing_distributed_surcharge
WHERE client_id = #{client_id}
ORDER BY create_time DESC ORDER BY create_time DESC
]]> ]]>
</select> </select>
<select id="findTransactionsByDate" resultType="com.alibaba.fastjson.JSONObject"> <select id="findTransactionsByDate" resultType="com.alibaba.fastjson.JSONObject">
<![CDATA[ <![CDATA[
SELECT * FROM log_clearing_distributed_surcharge WHERE client_id = #{client_id} SELECT *
FROM log_clearing_distributed_surcharge
WHERE client_id = #{client_id}
AND year(create_time) = #{year} AND year(create_time) = #{year}
AND month(create_time) = #{month} AND month(create_time) = #{month}
ORDER BY create_time DESC ORDER BY create_time DESC
]]> ]]>
</select> </select>
<select id="listUnClearedByMonth" resultType="com.alibaba.fastjson.JSONObject">
<![CDATA[
select d.*
from log_clearing_distributed_surcharge d
where d.bill_id is null
and d.create_time < #{dateto}
]]>
</select>
</mapper> </mapper>
Loading…
Cancel
Save