|
|
@@ -0,0 +1,102 @@
|
|
|
+package cn.com.ctop.job.adq.data.service.impl;
|
|
|
+
|
|
|
+import cn.com.ctop.job.adq.data.mapper.AdvBudgetMapper;
|
|
|
+import cn.com.ctop.job.adq.data.service.IAdvBudgetService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class AdvBudgetServiceImpl implements IAdvBudgetService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AdvBudgetMapper advBudgetMapper;
|
|
|
+
|
|
|
+ public void sumPayAmountByPeriodAndMerchant() {
|
|
|
+ //广告金数据
|
|
|
+ List<Map<String, Object>> adFund = advBudgetMapper.groupByAppIdAndSettleBegin(null);
|
|
|
+
|
|
|
+ //分销商数据
|
|
|
+ List<Map<String, Object>> fx = advBudgetMapper.listTopLevelDistributors();
|
|
|
+
|
|
|
+ for (Map<String, Object> adFundItem : adFund){
|
|
|
+ //周期开始时间
|
|
|
+ Long settleBegin = (Long) adFundItem.get("settle_begin");
|
|
|
+ //周期结束时间
|
|
|
+ Long settleEnd = (Long) adFundItem.get("settle_end");
|
|
|
+ //小程序ID
|
|
|
+ String appId = (String) adFundItem.get("app_id");
|
|
|
+
|
|
|
+ //总通用广告金金额
|
|
|
+ Long totalAmountA = ((Number) adFundItem.get("total_amount_a")).longValue();
|
|
|
+ //总广告激励金金额
|
|
|
+ Long totalAmountB = ((Number) adFundItem.get("total_amount_b")).longValue();
|
|
|
+ //总定向激励金额
|
|
|
+ Long totalAmountC = ((Number) adFundItem.get("total_amount_c")).longValue();
|
|
|
+
|
|
|
+ //过期时间
|
|
|
+ Long expireTime = (Long) adFundItem.get("expire_time");
|
|
|
+
|
|
|
+ //虚拟支付总收入数据
|
|
|
+ Long sum = advBudgetMapper.sumPayAmountByPeriodAndMerchant(15, settleBegin, settleEnd, null, appId);
|
|
|
+
|
|
|
+ //循环分销商数据
|
|
|
+ for (Map<String, Object> fxItem : fx) {
|
|
|
+ //分销商ID
|
|
|
+ Integer distributorId = (Integer) fxItem.get("id");
|
|
|
+ //虚拟支付分销商数据
|
|
|
+ Long fxsum = advBudgetMapper.sumPayAmountByPeriodAndMerchant(15, settleBegin, settleEnd, distributorId, appId);
|
|
|
+
|
|
|
+ if(fxsum > 0){
|
|
|
+ //比例
|
|
|
+ BigDecimal percent = BigDecimal.valueOf(fxsum).divide(BigDecimal.valueOf(sum), 4, RoundingMode.HALF_UP);
|
|
|
+ Double fxPercent = percent.setScale(5, RoundingMode.HALF_UP).doubleValue();
|
|
|
+
|
|
|
+ // 通用广告金金额
|
|
|
+ Integer amountA = (int)(totalAmountA * fxPercent);
|
|
|
+ // 广告激励金金额
|
|
|
+ Integer amountB = (int)(totalAmountB * fxPercent);
|
|
|
+ // 定向激励金额
|
|
|
+ Integer amountC = (int)(totalAmountC * fxPercent);
|
|
|
+
|
|
|
+// System.err.println("小程序周期内总收入:"+sum);
|
|
|
+// System.err.println("分销商小程序周期内总收入:"+fxsum);
|
|
|
+// System.err.println("精确比例:"+percent);
|
|
|
+// System.err.println("四舍五入比例:"+fxPercent);
|
|
|
+// System.err.println("可用通用广告金金额:"+totalAmountA);
|
|
|
+// System.err.println("分销商通用广告金金额:"+amountA);
|
|
|
+// System.err.println("可用广告激励金金额:"+totalAmountB);
|
|
|
+// System.err.println("分销商广告激励金金额:"+amountB);
|
|
|
+// System.err.println("可用定向激励金额:"+totalAmountC);
|
|
|
+// System.err.println("分销商定向激励金额:"+amountC);
|
|
|
+
|
|
|
+ Map<String, Object> data = new HashMap<>();
|
|
|
+ data.put("appId", appId);
|
|
|
+ data.put("personId", distributorId);
|
|
|
+ data.put("settleBegin", settleBegin);
|
|
|
+ data.put("settleEnd", settleEnd);
|
|
|
+ data.put("fundMoneyA", amountA);
|
|
|
+ data.put("fundMoneyB", amountB);
|
|
|
+ data.put("fundMoneyC", amountC);
|
|
|
+ data.put("expireTime", expireTime);
|
|
|
+ data.put("scale", fxPercent);
|
|
|
+ int rows =advBudgetMapper.replaceAdvBudget(data);
|
|
|
+// if (rows == 1) {
|
|
|
+// System.err.println("成功插入新记录");
|
|
|
+// } else if (rows == 2) {
|
|
|
+// System.err.println("成功覆盖旧记录");
|
|
|
+// } else if (rows == 0) {
|
|
|
+// System.err.println("没有任何变化");
|
|
|
+// }
|
|
|
+// System.err.println("----------分割线------------");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|