Upd:数据完整性校对修改

master
duLingLing 5 years ago
parent 089f7fc571
commit 946b4c8f94

@ -3,6 +3,7 @@ package au.com.royalpay.payment.manage.analysis.core.impls;
import au.com.royalpay.payment.manage.analysis.beans.AnalysisBean;
import au.com.royalpay.payment.manage.analysis.core.BDAnalysisService;
import au.com.royalpay.payment.manage.analysis.mappers.BDAnalysisMapper;
import au.com.royalpay.payment.manage.analysis.mappers.TransactionAnalysisMapper;
import au.com.royalpay.payment.manage.mappers.log.StatisticsBDSalesReportMapper;
import au.com.royalpay.payment.tools.permission.enums.ManagerRole;
import com.alibaba.fastjson.JSONArray;
@ -14,6 +15,7 @@ import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@ -40,6 +42,9 @@ public class BDAnalysisServiceImpl implements BDAnalysisService {
@Resource
private StatisticsBDSalesReportMapper bdSalesReportMapper;
@Resource
private TransactionAnalysisMapper transactionAnalysisMapper;
@Override
public List<JSONObject> getSalesAnalysis(JSONObject jsonObject) {
@ -59,7 +64,6 @@ public class BDAnalysisServiceImpl implements BDAnalysisService {
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
if (sd.format(jsonObject.getDate("end")).equals(sd.format(DateUtils.addDays(new Date(), 1)))) {
jsonObject.put("begin", DateUtils.addDays(jsonObject.getDate("end"), -1));
// jsonObject.put("end", DateUtils.addDays(jsonObject.getDate("end"), -2));
jsonObject.put("end",jsonObject.getDate("end"));
List<JSONObject> todaySaleList = bdAnalysisMapper.getBDSaleList(jsonObject);
for (JSONObject todayBDSaleItem : todaySaleList) {
@ -194,7 +198,7 @@ public class BDAnalysisServiceImpl implements BDAnalysisService {
List<JSONObject> bdSaleList = bdAnalysisMapper.getOneDayBDSaleList(params);
if (bdSaleList.size() != 0) {
for (JSONObject item : bdSaleList) {
JSONObject existBDSalesReport = bdSalesReportMapper.findByBDIdAndLogDate(item.getString("bd_id"),beginTime);
JSONObject existBDSalesReport = bdSalesReportMapper.findByBDIdAndLogDate(item.getString("bd_id"),beginTime,0);
if(existBDSalesReport==null){
JSONObject object = new JSONObject(item);
object.put("log_id", UUID.randomUUID().toString());
@ -207,6 +211,24 @@ public class BDAnalysisServiceImpl implements BDAnalysisService {
existBDSalesReport.put("net_amount",item.getString("net_amount"));
bdSalesReportMapper.update(existBDSalesReport);
}
}
}
List<JSONObject> orgSaleList= transactionAnalysisMapper.getOneDayOrgMerchantSaleList(params);
if (orgSaleList.size() != 0) {
for (JSONObject item : orgSaleList) {
JSONObject existOrgSalesReport = bdSalesReportMapper.findByBDIdAndLogDate(item.getString("bd_id"),beginTime,1);
if(existOrgSalesReport==null){
JSONObject object = new JSONObject(item);
object.put("log_id", UUID.randomUUID().toString());
object.put("log_date", beginTime);
object.put("create_time", new Date());
bdSalesReportMapper.save(object);
}else{
existOrgSalesReport.put("pay_amount",item.getString("pay_amount"));
existOrgSalesReport.put("refund_amount",item.getString("refund_amount"));
existOrgSalesReport.put("net_amount",item.getString("net_amount"));
bdSalesReportMapper.update(existOrgSalesReport);
}
}
}

@ -52,13 +52,13 @@ public class OrgAnalysisServiceImp implements OrgAnalysisService {
if (sd.format(params.getDate("end")).equals(sd.format(DateUtils.addDays(new Date(), 1)))) {
params.put("begin", DateUtils.addDays(params.getDate("end"), -1));
params.put("end",params.getDate("end"));
List<JSONObject> todayOrgTransaction = transactionAnalysisMapper.getOrgTransactionAnalysis(params);
List<JSONObject> todayOrgTransaction = transactionAnalysisMapper.getOneDayOrgMerchantSaleList(params);
if(todayOrgTransaction.size()!=0){
for (JSONObject todayOrgTransactionItem : todayOrgTransaction) {
boolean flag = false;
for (JSONObject orgTransaction : newOrgTransaction) {
if (orgTransaction.getString("org_id").equals(todayOrgTransactionItem.getString("org_id"))) {
BigDecimal newAmount = orgTransaction.getBigDecimal("clearing_amount").add(todayOrgTransactionItem.getBigDecimal("amount"));
BigDecimal newAmount = orgTransaction.getBigDecimal("amount").add(todayOrgTransactionItem.getBigDecimal("clearing_amount"));
orgTransaction.put("amount", newAmount);
flag = true;
}

@ -93,4 +93,6 @@ public interface TransactionAnalysisMapper {
* @return
*/
BigDecimal getCnyAmount(JSONObject params);
List<JSONObject> getOneDayOrgMerchantSaleList(JSONObject params);
}

@ -22,7 +22,7 @@ public interface StatisticsBDSalesReportMapper {
List<JSONObject> getPartnerAmountList(JSONObject params);
JSONObject findByBDIdAndLogDate(@Param("bd_id") String bd_id, @Param("log_date")Date beginTime);
JSONObject findByBDIdAndLogDate(@Param("bd_id") String bd_id, @Param("log_date")Date beginTime,@Param("isOrg") int isOrg);
@AutoSql(type = SqlType.UPDATE)
void update(JSONObject existBDSalesReport);

@ -9,6 +9,7 @@
ifnull(SUM(if(temp.refund_id IS NOT NULL, if(temp.transaction_type='Debit', temp.clearing_amount, -temp.clearing_amount) * clinetBD.proportion, 0)), 0) refund_fee
FROM(
SELECT
trans.org_id,
trans.client_id,
trans.clearing_amount,
trans.refund_id,
@ -18,25 +19,28 @@
WHERE (trans.transaction_type = 'Credit' OR trans.refund_id IS NOT NULL)
AND trans.system_generate = 0
AND trans.channel !='Settlement'
<if test="begin != null">
AND trans.channel != 'System'
<if test="begin != null">
AND trans.create_time &gt;= #{begin}
</if>
<if test="end != null">
AND trans.create_time &lt; #{end}
</if>
) AS temp
INNER JOIN sys_org AS org
ON org.org_id = temp.org_id
AND org.is_valid = 1
<if test="org_id != null">
AND org.org_id = #{org_id}
</if>
INNER JOIN sys_client_bd AS clinetBD
ON temp.client_id = clinetBD.client_id
AND clinetBD.start_date &lt;= temp.create_time
AND clinetBD.is_valid = '1'
AND (clinetBD.end_date IS NULL OR clinetBD.end_date > temp.create_time)
INNER JOIN sys_managers AS manage
ON manage.manager_id = clinetBD.bd_id
<if test="org_id != null">
AND manage.org_id = #{org_id}
</if>
GROUP BY clinetBD.bd_id
ORDER BY total DESC
</select>
@ -199,49 +203,50 @@
SELECT
clinetBD.bd_name,
clinetBD.bd_id,
manage.org_id,
org.org_id,
org.type AS org_type,
org.name AS org_name,
if(org.org_id=1,1,0) AS isOrg,
SUM( IF ( temp.transaction_type = 'Credit', temp.clearing_amount, -temp.clearing_amount )) clearing_amount,
0 AS isOrg,
0 AS clearing_amount,
SUM(if(temp.transaction_type = 'Credit',temp.clearing_amount * clinetBD.proportion, -temp.clearing_amount * clinetBD.proportion)) pay_amount,
ifnull(SUM(if(temp.refund_id IS NOT NULL, if(temp.transaction_type='Debit', temp.clearing_amount, -temp.clearing_amount) * clinetBD.proportion, 0)), 0) refund_amount,
(SUM(if(temp.transaction_type = 'Credit', temp.clearing_amount * clinetBD.proportion, -temp.clearing_amount * clinetBD.proportion))) - (ifnull(SUM(if(temp.refund_id IS NOT NULL, if(temp.transaction_type='Debit', temp.clearing_amount, -temp.clearing_amount) * clinetBD.proportion, 0)), 0)) AS net_amount
FROM(
SELECT
trans.client_id,
trans.clearing_amount,
trans.refund_id,
trans.transaction_type,
trans.create_time
FROM pmt_transactions AS trans
WHERE (trans.transaction_type = 'Credit' OR trans.refund_id IS NOT NULL)
AND trans.system_generate = 0
AND trans.channel !='Settlement'
<if test="begin != null">
AND trans.create_time &gt;= #{begin}
</if>
<if test="end != null">
AND trans.create_time &lt; #{end}
</if>
)
SELECT
trans.org_id,
trans.client_id,
trans.clearing_amount,
trans.refund_id,
trans.transaction_type,
trans.create_time
FROM pmt_transactions AS trans
WHERE (trans.transaction_type = 'Credit' OR trans.refund_id IS NOT NULL)
AND trans.system_generate = 0
AND trans.channel !='Settlement'
AND trans.channel != 'System'
<if test="begin != null">
AND trans.create_time &gt;= #{begin}
</if>
<if test="end != null">
AND trans.create_time &lt; #{end}
</if>
)
AS temp
INNER JOIN sys_client_bd AS clinetBD
ON temp.client_id = clinetBD.client_id
AND clinetBD.start_date &lt;= temp.create_time
AND clinetBD.is_valid = '1'
AND (clinetBD.end_date IS NULL OR clinetBD.end_date > temp.create_time)
INNER JOIN sys_managers AS manage
ON manage.manager_id = clinetBD.bd_id
AND manage.org_id IS NOT NULL
INNER JOIN sys_org AS org
ON org.org_id = manage.org_id
ON org.org_id = temp.org_id
AND org.is_valid = 1
<if test="org_id != null">
AND manage.org_id = #{org_id}
</if>
INNER JOIN sys_client_bd AS clinetBD
ON temp.client_id = clinetBD.client_id
AND clinetBD.start_date &lt;= temp.create_time
AND clinetBD.is_valid = '1'
AND (clinetBD.end_date IS NULL OR clinetBD.end_date > temp.create_time)
GROUP BY clinetBD.bd_id
ORDER BY pay_amount DESC
</select>
</mapper>

@ -751,7 +751,10 @@
<select id="getPartnersAmountByOrg" resultType="com.alibaba.fastjson.JSONObject">
<![CDATA[
SELECT c.client_moniker,c.short_name,sum(if(t.transaction_type='Credit',t.clearing_amount,0)) amount
SELECT
c.client_moniker,
c.short_name,
SUM(IF(t.transaction_type = 'Credit', t.clearing_amount,-t.clearing_amount)) AS amount
FROM pmt_transactions t
INNER JOIN pmt_orders ord on ord.order_id = t.order_id
RIGHT JOIN sys_clients c on t.client_id = c.client_id and c.is_valid = 1 AND c.org_id = #{org_id}
@ -980,5 +983,42 @@
LIMIT 1;
</select>
<select id="getOneDayOrgMerchantSaleList" resultType="com.alibaba.fastjson.JSONObject">
SELECT
org.org_id AS org_id,
org.name AS org_name,
org.type AS org_type,
1 AS isOrg,
SUM(IF( trans.transaction_type = 'Credit', trans.clearing_amount, - trans.clearing_amount )) AS clearing_amount,
0 AS pay_amount,
0 AS refund_amount,
0 AS net_amount
FROM
pmt_transactions AS trans
INNER JOIN sys_org AS org ON trans.org_id = org.org_id
AND org.is_valid = 1
AND org.type = 0
AND org.citypartner = 1
AND org.commission = 1
WHERE
trans.channel != 'Settlement'
AND trans.channel != 'System'
AND trans.system_generate = 0
<if test="org_id != null">
AND org.org_id = #{org_id}
</if>
<if test="begin != null">
AND trans.create_time &gt;= #{begin}
</if>
<if test="end != null">
AND trans.create_time &lt; #{end}
</if>
GROUP BY
org.org_id
</select>
</mapper>

@ -10,7 +10,7 @@
SUM(pay_amount) AS total,
SUM(refund_amount) AS refund_fee
FROM statistics_bd_sales
<where>
WHERE isOrg = 0
<if test="org_id != null">
AND org_id = #{org_id}
</if>
@ -27,7 +27,6 @@
AND org.org_id in
<foreach collection="org_ids" item="org_id" open="(" close=")" separator=",">#{org_id}</foreach>
</if>
</where>
GROUP BY bd_id
ORDER BY total DESC
</select>
@ -43,7 +42,7 @@
SUM(pay_amount) AS total,
SUM(refund_amount) AS refund_fee
FROM statistics_bd_sales
WHERE org_id !=1
WHERE isOrg = 1
<if test="org_id != null">
AND org_id = #{org_id}
</if>
@ -80,7 +79,7 @@
create_time,
clearing_amount
FROM statistics_bd_sales
WHERE bd_id = #{bd_id} AND log_date = #{log_date}
WHERE bd_id = #{bd_id} AND log_date = #{log_date} AND isOrg = #{isOrg}
</select>
</mapper>
Loading…
Cancel
Save