QuotaConvertBiz.java
6.66 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package com.cjs.cms.biz.quota;
import java.io.File;
import java.net.URI;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.cjs.cms.action.user.fund.UserBalanceAction;
import com.cjs.cms.dao.quota.OtcStockRealDao;
import com.cjs.cms.dao.quota.QuotaConvertDao;
import com.cjs.cms.model.quota.OtcStockRealInfo;
import com.cjs.cms.model.quota.QuotaConvertInfo;
import com.cjs.cms.util.file.FileUtil;
import com.cjs.cms.util.lang.DateEnum;
import com.cjs.cms.util.lang.DateUtil;
import com.cjs.cms.util.lang.JsonUtil;
import com.cjs.cms.util.poi.ExcelConfig;
import com.cjs.cms.util.poi.ExcelUtil;
/**
* 额度转换
* @author tongxiaochuan
*
*/
@Service
public class QuotaConvertBiz {
@Value("${download.export}")
private String exportPath;
@Autowired
private QuotaConvertDao quotaConvertDao;
@Autowired
private OtcStockRealDao otcDao;
@Autowired
private QuotaConfigBiz quotaConfigBiz;
/**
* 查询转换信息
* @param params
* @return
*/
public List<QuotaConvertInfo> search(Map<String, Object> params) {
return quotaConvertDao.search(params);
}
/**
* 查询转换条目数
* @param params
* @return
*/
public int searchTotal(Map<String, Object> params) {
return quotaConvertDao.searchTotal(params);
}
/**
* 导出确权文件
* @param params
* @return
* @throws Exception
*/
@Transactional
public File export(Map<String, Object> params) throws Exception {
String filename = "额度转换确权文件_" + DateUtil.getNow(DateEnum.UNSIGNED_DATE_TIME);
filename = FileUtil.makeMonthDir(exportPath) + filename + ".xlsx";
File targetFile = new File(filename);
ExcelConfig config = new ExcelConfig();
URI template = UserBalanceAction.class.getResource("/excel/quota_convert.xlsx").toURI();
int realCount;
List<Map<String, Object>> quotaList = quotaConvertDao.searchQuota(params); //
Map<String, Object> realMap = new HashMap<String, Object>();
//获取查询用户的持仓
for (int i = 0; i < quotaList.size(); i++) {
//额度转持仓
if (quotaList.get(i).get("type").toString().equals("0"))
continue;
//持仓转额度
if (realMap.get(quotaList.get(i).get("user_id").toString()) == null) {
realCount = queryotcStockReal(quotaList.get(i).get("otc_code").toString(),
quotaList.get(i).get("user_id").toString());
realMap.put(quotaList.get(i).get("user_id").toString(), realCount);
}
}
//修改实际转换数量
Map<String, Object> updateMap = new HashMap<String, Object>(); //更新转换表
Map<String, Object> modelMap = new HashMap<String, Object>(); //额度转持仓map
int leftCount;
for (int i = 0; i < quotaList.size(); i++) {
//额度转持仓
if (quotaList.get(i).get("type").toString().equals("0")) {
modelMap.put("updateBy", "admin");
modelMap.put("id", quotaList.get(i).get("id"));
modelMap.put("postQuota", quotaList.get(i).get("post_quota"));
quotaConvertDao.updateExportStatusExport(modelMap);
continue;
}
realCount = Integer
.parseInt(realMap.get(quotaList.get(i).get("user_id").toString()).toString());
if (realCount >= 0 - Integer.parseInt(quotaList.get(i).get("quota").toString())) {
leftCount = realCount + Integer.parseInt(quotaList.get(i).get("quota").toString());
updateMap.put("id", quotaList.get(i).get("id"));
updateMap.put("postQuota",
Integer.parseInt(quotaList.get(i).get("quota").toString()));
realMap.put(quotaList.get(i).get("user_id").toString(), leftCount);
} else {
leftCount = realCount;
updateMap.put("id", quotaList.get(i).get("id"));
updateMap.put("postQuota", 0 - realCount);
realMap.put(quotaList.get(i).get("user_id").toString(), 0);
}
//更新转换信息
quotaConvertDao.updateExportStatusExport(updateMap);
}
params.put("exportStatus", 1);
List<Map<String, Object>> list = quotaConvertDao.searchExport(params);
for (Map<String, Object> map : list) {
map.put("market", "O1");
map.put("non_circulation", "0");
map.put("manage_type", "0");
}
// 先生成Excel文件
config.setSourceTemplate(new File(template));
config.setTargetFile(targetFile);
config.setData(list);
new ExcelUtil(config).writeExcel();
return targetFile;
}
/**
* 确认确权
* @return
*/
@Transactional
public String ensure() {
Map<String, Object> params = new HashMap<String, Object>();
params.put("exportStatus", "1");
List<Map<String, Object>> list = quotaConvertDao.searchQuota(params);
Map<String, Object> modelMap = new HashMap<String, Object>();
for (int i = 0; i < list.size(); i++) {
if (list.get(i).get("type").toString().equals("0"))
continue;
//更新用户额度及记录
modelMap.put("userId", list.get(i).get("user_id").toString());
modelMap.put("quota", 0 - Integer.parseInt(list.get(i).get("post_quota").toString()));
modelMap.put("otcCode", list.get(i).get("otc_code").toString());
modelMap.put("otcName", list.get(i).get("otc_name").toString());
modelMap.put("createBy", "admin");
modelMap.put("source", 5);
quotaConfigBiz.updateQuota(modelMap);
}
params.put("updateBy", "admin");
quotaConvertDao.updateEnsure(params);
return JsonUtil.toJson("resultMsg", "操作完毕");
}
/**
* 查询再托管可用持仓
* @param otcCode
* @return
*/
public int queryotcStockReal(String otcCode, String userId) {
Map<String, Object> params = new HashMap<String, Object>();
params.put("otcCode", otcCode);
params.put("userId", userId);
OtcStockRealInfo otcInfo = otcDao.queryRealInfo(params);
//无持仓记录,则返回0
if (otcInfo == null) {
return 0;
}
return otcInfo.getEnableAmount();
}
}