ShareMoneyMain.java
4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package com.glsx.bzi.cost.hardware;
import com.glsx.conf.ConfigurationManager;
import com.glsx.connection.MysqlConn;
import com.glsx.util.DateUtils;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.Map;
import java.util.TreeMap;
/**
* 硬件成本分摊算法 分渠道/直销 和 结算/激活维度
*/
public class ShareMoneyMain {
public static void main(String[] args) {
Connection mysqlConn = MysqlConn.getConnection(ConfigurationManager.getProperty("mysql_prd_login"));
// 直销配激活 代销(含广汇)配结算
//String type1 = "('直销')";
String type1 = "('代销','广汇','直销')";
String type2 = "settle_time";
//String type2 = "active_time";
int isReturn = 1; //退货
computeShareMoney(mysqlConn, type1, type2, isReturn);
MysqlConn.close(mysqlConn);
}
private static void computeShareMoney(Connection mysqlConn, String type1, String type2, int isReturn) {
// 客户|(结算/激活)时间 -> 结算金额
TreeMap<String, Double> shareMoneyMap = new TreeMap<>();
//String sql = "SELECT sn," + type2 + ",settle_merchant,period,price from t_hardware_cost " +
// "where " + type2 + " !='null' and mer_type='" + type1 + "'" ;//+ " and " + type2 + "<'2021-01-01'";
String sql = "";
if(isReturn == 0) {
sql = "SELECT sn," + type2 + ",settle_merchant,pk_period,hw_cost from dj_2021_settle_details_agg " +
"where " + type2 + " !='null' and hw_cost is not null and channel in " + type1;// + " and " + type2 + "<'2021-01-01'";
}
else {
sql = "SELECT sn," + type2 + ",settle_merchant,pk_period,hw_cost from dj_2021_settle_details_return " +
"where " + type2 + " !='null' and hw_cost is not null and channel in " + type1;// + " and " + type2 + "<'2021-01-01'";
}
MysqlConn.executeQuery(mysqlConn, sql, new MysqlConn.QueryCallback() {
@Override
public void process(ResultSet rs) throws Exception {
while (rs.next()) {
String sn = rs.getString(1).trim();
String time = rs.getString(2);
String settle_merchant = rs.getString(3).trim();
int pk_period = rs.getInt(4);
double price = rs.getDouble(5);
String monTime = "";
/*if (settle_merchant.equals("广汇汽车") && type2.equals("settle_time") &&
time.compareTo("2021-01-01") < 0)
monTime = DateUtils.getAfterMonth2(time);
else*/
monTime = DateUtils.convTime1(time);
// else if(type.equals("直销"))
// monTime = DateUtils.convTime1(time);
// else if (type.equals("渠道"))
// monTime = DateUtils.convTime1(time);
// else
// System.out.println("没找到对应的类型匹配");
double priceMonth = price/pk_period;
String key = "";
for (int i = 0; i < pk_period; i++) {
key = settle_merchant + "|" + monTime;
if (shareMoneyMap.get(key) == null)
shareMoneyMap.put(key, priceMonth);
else
shareMoneyMap.put(key, shareMoneyMap.get(key) + priceMonth);
monTime = DateUtils.getAfterMonth(monTime);
// 摊分截止
// if (monTime.equals("2021-01"))
// break;
}
}
}
});
MysqlConn.executeUpdate(mysqlConn, "TRUNCATE TABLE dj_share_price");
String tmpsql = "INSERT INTO dj_share_price(settle_merchant,mon_time,price) values";
String values = "";
for (Map.Entry<String, Double> entry : shareMoneyMap.entrySet()) {
String[] split = entry.getKey().split("\\|");
String settle_merchant = split[0];
String mon_time = split[1];
Double price = entry.getValue();
values += "('" + settle_merchant + "','" + mon_time + "'," + price + "),";
tmpsql += values.substring(0, values.length() - 1);
MysqlConn.executeUpdate(mysqlConn, tmpsql);
tmpsql = "INSERT INTO dj_share_price(settle_merchant,mon_time,price) values";
values = "";
}
}
}