TempVelocity.java
5.14 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package com.taover.business.util;
import java.io.File;
import java.io.StringWriter;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.taover.business.Constants;
import com.taover.db.Tools;
import freemarker.template.Configuration;
import freemarker.template.Template;
public class TempVelocity {
public static void main(String args[]) throws SQLException{
String cnFunc = "代销平台毛利=1-代销平台成本/代销平台报价";
// String func = "promotProfit=promotPrice-promotAllCost-shareReward*shareRewardRate/100";
generate(cnFunc);
}
public static void generate(String cnFunc) {
try{
File f = new File(Tools.getPath() + Constants.TEMPATE_PATH);
Configuration cfg = new Configuration();
cfg.setDirectoryForTemplateLoading(f);
StringWriter htmlOut = new StringWriter();
Template htmlTemplate = cfg.getTemplate("Temp.ftl", "UTF-8");
Map<String, Object> data = new HashMap<String, Object>();
data.put("cnFunc", cnFunc);
parseData(data);
htmlTemplate.process(data, htmlOut);
System.out.println(htmlOut.toString());
htmlOut.close();
}catch(Exception e){
e.printStackTrace();
}
}
public static void parseData(Map<String, Object> data){
//propertyList,result
String cnFunc = (String) data.get("cnFunc");
String result = cnFunc.split("=")[0];
String resultEn = getEnName(result);
String propertyStr = cnFunc.split("=")[1];
List<String> propertyList = new ArrayList<String>();
// Pattern pattern = Pattern.compile("[a-zA-Z]+", Pattern.CASE_INSENSITIVE);
Pattern pattern = Pattern.compile("[\u4e00-\u9fa5]+", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(propertyStr);
List<String> cnNameList = new ArrayList<String>();
String enFunc = cnFunc;
while(matcher.find()){
String tempGroup = matcher.group();
cnNameList.add(tempGroup);
}
for(String cnName : cnNameList){
String enName = getEnName(cnName);
if(enName == null){
enName = "errorVal";
}
propertyList.add(enName);
enFunc = enFunc.replaceAll(cnName+"\\b", enName);
}
enFunc = enFunc.replaceAll(result, resultEn);
data.put("enFunc", enFunc);
data.put("result", resultEn);
data.put("propertyList", propertyList);
}
public static String getEnName(String cnName){
Map<String, String> keyReflect = new HashMap<String, String>();
keyReflect.put("供货价格","goodsMoney");
keyReflect.put("物料成本","materielFee");
keyReflect.put("运费","freight");
keyReflect.put("赠品成本","freeGift");
keyReflect.put("检测成本","detectPer");
keyReflect.put("预计件数","preNumber");
keyReflect.put("产品成本","productCost");
keyReflect.put("分享金","shareReward");
keyReflect.put("平台售价","platPrice");
keyReflect.put("平台优惠券","platCoupon");
keyReflect.put("平台销售成本","platSaleCost");
keyReflect.put("平台总成本","platAllCost");
keyReflect.put("平台毛利","platProfit");
keyReflect.put("平台毛利率","platProfitRate");
keyReflect.put("初级分享师返利","primaryShareReward");
keyReflect.put("高级分享师返利","seniorShareReward");
keyReflect.put("分享后平台最低毛利率","afterSharePlatLowestProfit");
keyReflect.put("促销价格","promotPrice");
keyReflect.put("促销产品成本","promotCost");
keyReflect.put("促销优惠券","promotCoupon");
keyReflect.put("促销总成本","promotAllCost");
keyReflect.put("促销毛利","promotProfit");
keyReflect.put("促销毛利率","promotProfitRate");
keyReflect.put("促销初级分享师返利","promotPrimaryShareReward");
keyReflect.put("促销高级分享师返利","promotSeniorShareReward");
keyReflect.put("促销分享后平台最低毛利","promotAfterShareLowestProfit");
keyReflect.put("产销联盟报价","psUionPrice");
keyReflect.put("产销联盟渠道成本","psUnionChannelCost");
keyReflect.put("联盟毛利率","psUnionProfitRate");
keyReflect.put("采购渠道报价","channelPrice");
keyReflect.put("采购渠道成本","purchaseChannelCost");
keyReflect.put("采购毛利率","purchaseChannelProfitRate");
keyReflect.put("代销平台报价","agentPrice");
keyReflect.put("代销平台成本","agentCost");
keyReflect.put("代销平台毛利","agentProfit");
keyReflect.put("试吃供货价格","shichiGoodsMoney");
keyReflect.put("试吃售价","shichiPrice");
keyReflect.put("试吃份数","shichiNumber");
keyReflect.put("试吃成本","shichiCost");
keyReflect.put("试吃利润","shichiProfit");
keyReflect.put("积分使用率","integralUseRate");
keyReflect.put("买手提成","ticheng");
keyReflect.put("运营提点","operateRate");
keyReflect.put("初级分享师返点","primaryAgentRate");
keyReflect.put("高级分享师返点","seniorAgentRate");
keyReflect.put("渠道拓展提点","channelExpRate");
keyReflect.put("渠道维护提点","channelProRate");
keyReflect.put("转账费率","transAccountRate");
keyReflect.put("损耗","lossRate");
keyReflect.put("分享金比例","shareRewardRate");
return keyReflect.get(cnName);
}
}