优化合伙人提成sql

master
Yixian 3 years ago
parent 80d6ea5076
commit 796b8d3ef0

@ -22,6 +22,7 @@ import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.usermodel.*;
import org.joda.time.DateTime;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -259,10 +260,10 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
@Transactional @Transactional
public void generateold(String monthStr) { public void generateold(String monthStr) {
Date mon = checkMonth(monthStr); Date mon = checkMonth(monthStr);
Calendar monthCal = Calendar.getInstance(); DateTime begin = new DateTime(mon);
monthCal.setTime(mon); DateTime end = begin.plusMonths(1);
int year = monthCal.get(Calendar.YEAR); int year = begin.getYear();
int month = monthCal.get(Calendar.MONTH) + 1; int month = begin.getMonthOfYear();
JSONObject sysConfig = sysConfigManager.getSysConfig(); JSONObject sysConfig = sysConfigManager.getSysConfig();
BigDecimal alipayChargeRate = new BigDecimal("0.6"); BigDecimal alipayChargeRate = new BigDecimal("0.6");
@ -286,7 +287,7 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
channelMap.put("Wechat", "Wechat"); channelMap.put("Wechat", "Wechat");
channelMap.put("AlipayOnline", "AlipayOnline"); channelMap.put("AlipayOnline", "AlipayOnline");
Set<Integer> orgIds = new HashSet<>(); Set<Integer> orgIds = new HashSet<>();
List<JSONObject> transactionAnalysis = transactionMapper.listTransactionsForCityPartnerCommission(year, month); List<JSONObject> transactionAnalysis = transactionMapper.listTransactionsForCityPartnerCommission(begin.toDate(), end.toDate());
Map<String, CityPartnerCommissionAnalysis> results = new HashMap<>(); Map<String, CityPartnerCommissionAnalysis> results = new HashMap<>();
for (JSONObject analysisDay : transactionAnalysis) { for (JSONObject analysisDay : transactionAnalysis) {
int orgId = analysisDay.getIntValue("org_id"); int orgId = analysisDay.getIntValue("org_id");
@ -339,10 +340,10 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
@Transactional @Transactional
public void generate(String monthStr) { public void generate(String monthStr) {
Date mon = checkMonth(monthStr); Date mon = checkMonth(monthStr);
Calendar monthCal = Calendar.getInstance(); DateTime begin = new DateTime(mon);
monthCal.setTime(mon); DateTime end = begin.plusMonths(1);
int year = monthCal.get(Calendar.YEAR); int year = begin.getYear();
int month = monthCal.get(Calendar.MONTH) + 1; int month = begin.getMonthOfYear();
// List<JSONObject> list = financialPartnerCommissionMapper.list(year, month); // List<JSONObject> list = financialPartnerCommissionMapper.list(year, month);
// if (list != null && !list.isEmpty()) { // if (list != null && !list.isEmpty()) {
@ -374,8 +375,7 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
channelCharge.put("wechatChargeRate", wechatChargeRate); channelCharge.put("wechatChargeRate", wechatChargeRate);
channelCharge.put("jdChargeRate", jdChargeRate); channelCharge.put("jdChargeRate", jdChargeRate);
channelCharge.put("alipayonlineChargeRate", alipayonlineChargeRate); channelCharge.put("alipayonlineChargeRate", alipayonlineChargeRate);
List<JSONObject> transactionDetail = transactionMapper.listTransactionForCityPartnerCommissionByDate(begin.toDate(), end.toDate());
List<JSONObject> transactionDetail = transactionMapper.listTransactionForCityPartnerCommissionByDate(year, month);
transactionDetail.forEach(item -> { transactionDetail.forEach(item -> {
if (StringUtils.equalsIgnoreCase("AlipayPlus", item.getString("channel"))) { if (StringUtils.equalsIgnoreCase("AlipayPlus", item.getString("channel"))) {
item.put("channel", item.getString("pay_type")); item.put("channel", item.getString("pay_type"));
@ -763,15 +763,15 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
@Transactional @Transactional
public void generateReferrer(String monthStr) { public void generateReferrer(String monthStr) {
Date mon = checkMonth(monthStr); Date mon = checkMonth(monthStr);
Calendar monthCal = Calendar.getInstance(); DateTime begin = new DateTime(mon);
monthCal.setTime(mon); DateTime end = begin.plusMonths(1);
int year = monthCal.get(Calendar.YEAR); int year = begin.getYear();
int month = monthCal.get(Calendar.MONTH) + 1; int month = begin.getMonthOfYear();
financialReferrerCommissionDetailMapper.clearData(year, month); financialReferrerCommissionDetailMapper.clearData(year, month);
financialReferrerCommissionMapper.clearData(year, month); financialReferrerCommissionMapper.clearData(year, month);
List<JSONObject> transactionAnalysis = transactionMapper.listTransactionsForReferrerCommission(year, month); List<JSONObject> transactionAnalysis = transactionMapper.listTransactionsForReferrerCommission(begin.toDate(), end.toDate());
Map<Integer, ReferrerCommissionAnalysis> results = new HashMap<>(); Map<Integer, ReferrerCommissionAnalysis> results = new HashMap<>();
for (JSONObject analysisDay : transactionAnalysis) { for (JSONObject analysisDay : transactionAnalysis) {
Integer orgId = analysisDay.getInteger("org_id"); Integer orgId = analysisDay.getInteger("org_id");
@ -850,14 +850,15 @@ public class CityPartnerPrizeServiceImpl implements CityPartnerPrizeService {
public void generateAgent(String monthStr, JSONObject channelCharge) { public void generateAgent(String monthStr, JSONObject channelCharge) {
Date mon = checkMonth(monthStr); Date mon = checkMonth(monthStr);
Calendar monthCal = Calendar.getInstance(); DateTime begin = new DateTime(mon);
monthCal.setTime(mon); DateTime end = begin.plusMonths(1);
int year = monthCal.get(Calendar.YEAR); int year = begin.getYear();
int month = monthCal.get(Calendar.MONTH) + 1; int month = begin.getMonthOfYear();
financialAgentCommissionMapper.clearData(year, month); financialAgentCommissionMapper.clearData(year, month);
financialAgentCommissionDetailMapper.clearData(year, month); financialAgentCommissionDetailMapper.clearData(year, month);
List<JSONObject> transactionDetail = transactionMapper.listTransactionForCityPartnerAgentCommissionByDate(year, month);
List<JSONObject> transactionDetail = transactionMapper.listTransactionForCityPartnerAgentCommissionByDate(begin.toDate(), end.toDate());
transactionDetail.forEach(item -> { transactionDetail.forEach(item -> {
if (StringUtils.equalsIgnoreCase("AlipayPlus", item.getString("channel"))) { if (StringUtils.equalsIgnoreCase("AlipayPlus", item.getString("channel"))) {
item.put("channel", item.getString("pay_type")); item.put("channel", item.getString("pay_type"));

@ -95,13 +95,13 @@ public interface TransactionMapper {
BigDecimal totalAmountForSydneyGMPrize(@Param("year") int year, @Param("month") int month); BigDecimal totalAmountForSydneyGMPrize(@Param("year") int year, @Param("month") int month);
List<JSONObject> listTransactionForCityPartnerCommissionByDate(@Param("year") int year, @Param("month") int month); List<JSONObject> listTransactionForCityPartnerCommissionByDate(@Param("begin") Date begin, @Param("end") Date end);
List<JSONObject> listTransactionForCityPartnerAgentCommissionByDate(@Param("year") int year, @Param("month") int month); List<JSONObject> listTransactionForCityPartnerAgentCommissionByDate(@Param("begin") Date begin, @Param("end") Date end);
List<JSONObject> listTransactionsForCityPartnerCommission(@Param("year") int year, @Param("month") int month); List<JSONObject> listTransactionsForCityPartnerCommission(@Param("begin") Date begin, @Param("end") Date end);
List<JSONObject> listTransactionsForReferrerCommission(@Param("year") int year, @Param("month") int month); List<JSONObject> listTransactionsForReferrerCommission(@Param("begin") Date begin, @Param("end") Date end);
List<JSONObject> listTransactionsForAgentCommission(@Param("year") int year, @Param("month") int month, @Param("parent_org_id") int parent_org_id); List<JSONObject> listTransactionsForAgentCommission(@Param("year") int year, @Param("month") int month, @Param("parent_org_id") int parent_org_id);

@ -1006,8 +1006,8 @@
INNER JOIN sys_org so INNER JOIN sys_org so
ON m.org_id = so.org_id AND so.is_valid = 1 AND so.type = 0 AND so.citypartner = 1 AND ON m.org_id = so.org_id AND so.is_valid = 1 AND so.type = 0 AND so.citypartner = 1 AND
so.commission = 1 so.commission = 1
WHERE year(t.transaction_time) = #{year} WHERE t.transaction_time >= #{begin}
AND month(t.transaction_time) = #{month} AND t.transaction_time < #{end}
AND t.channel != 'Settlement' AND t.channel != 'Settlement'
GROUP BY t.client_id, trade_date, channel GROUP BY t.client_id, trade_date, channel
ORDER BY c.org_id ASC, t.client_id ASC, trade_date ASC ORDER BY c.org_id ASC, t.client_id ASC, trade_date ASC
@ -1036,7 +1036,7 @@
INNER JOIN sys_org so ON t.org_id = so.org_id AND so.is_valid = 1 INNER JOIN sys_org so ON t.org_id = so.org_id AND so.is_valid = 1
AND so.type = 0 AND so.type = 0
AND so.citypartner = 1 AND so.commission = 1 AND so.citypartner = 1 AND so.commission = 1
AND year(t.create_time) = #{year} AND month(t.create_time) = #{month} AND t.create_time >= #{begin} AND t.create_time < #{end}
AND t.channel != 'Settlement' AND t.channel != 'System' AND t.system_generate = 0 AND t.channel != 'Settlement' AND t.channel != 'System' AND t.system_generate = 0
ORDER BY t.client_id asc ORDER BY t.client_id asc
]]> ]]>
@ -1066,7 +1066,7 @@
AND so.type = 0 AND so.type = 0
AND so.parent_org_id != '' AND so.parent_org_id != ''
AND so.citypartner = 1 AND so.commission = 1 AND so.citypartner = 1 AND so.commission = 1
AND year(t.transaction_time) = #{year} AND month(t.transaction_time) = #{month} AND t.transaction_time >= #{begin} AND t.transaction_time < #{end}
AND t.channel != 'Settlement' AND t.channel != 'System' AND t.channel != 'Settlement' AND t.channel != 'System'
ORDER BY t.client_id asc ORDER BY t.client_id asc
]]> ]]>
@ -1084,8 +1084,8 @@
inner join sys_client_config cc on cc.client_id = c.client_id inner join sys_client_config cc on cc.client_id = c.client_id
INNER JOIN sys_org so INNER JOIN sys_org so
ON c.referrer_id = so.org_id AND so.is_valid = 1 AND so.type = 1 AND so.commission = 1 ON c.referrer_id = so.org_id AND so.is_valid = 1 AND so.type = 1 AND so.commission = 1
WHERE year(t.transaction_time) = #{year} WHERE t.transaction_time >= #{begin}
AND month(t.transaction_time) = #{month} AND t.transaction_time &lt; #{end}
AND t.channel != 'Settlement' AND t.channel != 'Settlement'
GROUP BY so.org_id, trade_date, t.client_id GROUP BY so.org_id, trade_date, t.client_id
ORDER BY c.org_id ASC, t.client_id ASC, trade_date ASC ORDER BY c.org_id ASC, t.client_id ASC, trade_date ASC

Loading…
Cancel
Save