OtcStockRealBiz.java
5.62 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
package com.cjs.cms.biz.user.point;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.cjs.cms.dao.quota.OtcStockRealDao;
import com.cjs.cms.dao.report.OtcRealTimeDao;
import com.cjs.cms.dao.trade.MarketPriceDao;
import com.cjs.cms.dao.user.UserHisStockDao;
import com.cjs.cms.dao.user.point.PointActiveDao;
import com.cjs.cms.model.quota.OtcStockRealInfo;
import com.cjs.cms.model.user.point.PointActiveInfo;
import com.cjs.cms.util.lang.JsonUtil;
/**
* 有效持仓市值活动
* @author tongxiaochuan
*
*/
@Service
public class OtcStockRealBiz {
@Autowired
private OtcRealTimeDao otcRealTimeDao;
@Autowired
private OtcStockRealDao otcStockRealDao;
@Autowired
private PointActiveDao pointActiveDao;
@Autowired
private MarketPriceDao marketPriceDao;
@Autowired
private PointCommonBiz pointCommonBiz;
@Autowired
private UserHisStockDao userHisStockDao;
Logger log = LogManager.getLogger();
@Transactional
public String sendPoint(int id) throws Exception {
PointActiveInfo pointActiveInfo = pointActiveDao.queryActiveById(id);
Date expiredDate = pointCommonBiz.getExpiredDate(pointActiveInfo.getExpiredDate());
if (new Date().after(pointActiveInfo.getEndDate())) {
return JsonUtil.toFormJson("当前非活动时间", false);
}
String[] otcCodes = pointActiveInfo.getRemark().split(",");
Map<String, Object> stockParam = new HashMap<String, Object>();
Map<String, Double> balanceMap = new HashMap<String, Double>();
Map<String, List<Map<String, Object>>> remarkMap = new HashMap<String, List<Map<String, Object>>>();
Map<String, Object> inmap = new HashMap<String, Object>();
for (String otcCode : otcCodes) {
double price = marketPriceDao.queryClosePirce(otcCode);
double totalPrice;
stockParam.put("otc_code", otcCode);
//查询指定藏品的累计买入量
List<Map<String, Object>> buyTotals = otcRealTimeDao.queryBuyTotal(stockParam);
//查询当前持仓
List<OtcStockRealInfo> stockList = otcStockRealDao.queryList(otcCode);
Map<String, OtcStockRealInfo> stockMap = new HashMap<String, OtcStockRealInfo>();
for (OtcStockRealInfo otcInfo : stockList) {
stockMap.put(otcInfo.getFundAccount(), otcInfo);
}
for (Map<String, Object> map : buyTotals) {
OtcStockRealInfo otcStock = stockMap.get(map.get("FUND_ACCOUNT"));
if (otcStock == null) {
// log.info(otcCode + "藏品用户有累计买入量,当前持仓为空:" + map);
continue;
} else {
int realCount;
if (otcStock.getEnableAmount() > Integer
.parseInt(map.get("BUY_TOTAL").toString())) {
realCount = Integer.parseInt(map.get("BUY_TOTAL").toString());
} else {
realCount = otcStock.getEnableAmount();
}
totalPrice = price * realCount;
if (balanceMap.get(map.get("FUND_ACCOUNT")) == null) {
balanceMap.put(map.get("FUND_ACCOUNT").toString(), totalPrice);
} else {
balanceMap.put(map.get("FUND_ACCOUNT").toString(),
balanceMap.get(map.get("FUND_ACCOUNT")) + totalPrice);
}
Map<String, Object> leafMap = new HashMap<String, Object>();
leafMap.put("otcCode", otcCode);
leafMap.put("realCount", realCount);
leafMap.put("price", price);
leafMap.put("totalPrice", totalPrice);
if (remarkMap.get(map.get("FUND_ACCOUNT")) == null) {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
list.add(leafMap);
remarkMap.put(map.get("FUND_ACCOUNT").toString(), list);
} else {
remarkMap.get(map.get("FUND_ACCOUNT")).add(leafMap);
}
}
}
}
//发放配额
int giftAmount;
for (String userId : balanceMap.keySet()) {
inmap.put("CLIENT_ID", userId);
inmap.put("remark", remarkMap.get(userId));
giftAmount = ((int) (balanceMap.get(userId) / 2000)) * 10;
if (giftAmount == 0) {
continue;
}
pointCommonBiz.sendPoint(inmap, pointActiveInfo, expiredDate, "", giftAmount);
}
log.info("有效持仓市值送配额活动奖励发放完毕");
return JsonUtil.toFormJson("发放完毕", true);
}
public void saveUserHisStock() {
//查询用户当前持仓
List<Map<String, Object>> stokList = otcStockRealDao.searchCurrentStock();
for (Map<String, Object> map : stokList) {
map.put("userId", map.get("FUND_ACCOUNT"));
map.put("otcCode", map.get("OTC_CODE"));
map.put("highAmount", map.get("ENABLE_AMOUNT"));
userHisStockDao.insert(map);
}
log.info("用户当前持仓插入完毕");
}
}