zj
2025-05-28 bcd36411feb0351347289476eb7ee9e5dd1c3b9d
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
package project.web.admin;
 
import java.math.BigDecimal;
import java.text.MessageFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
 
import javax.servlet.http.HttpServletRequest;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
 
import kernel.exception.BusinessException;
import kernel.util.Arith;
import kernel.util.JsonUtils;
import kernel.util.StringUtils;
import kernel.util.ThreadUtils;
import kernel.web.Page;
import kernel.web.PageActionSupport;
import project.Constants;
import project.contract.AdminMarketQuotationsService;
import project.data.AdjustmentValue;
import project.data.AdjustmentValueService;
import project.data.DataCache;
import project.data.DataService;
import project.data.model.Realtime;
import project.item.ItemService;
import project.item.model.Item;
import project.log.LogService;
import security.SecUser;
import security.internal.SecUserService;
 
/**
 * 行情数据
 *
 */
@RestController
public class AdminMarketQuotationsManageController extends PageActionSupport {
    
    @Autowired
    private LogService logService;
    
    @Autowired
    private ItemService itemService;
    
    @Autowired
    private DataService dataService;
    
    @Autowired
    private SecUserService secUserService;
    
    @Autowired
    private AdjustmentValueService adjustmentValueService;
    
    @Autowired
    private AdminMarketQuotationsService adminMarketQuotationsService;
    
    private final String action = "normal/adminMarketQuotationsManageAction!";
    
    private static final Logger logger = LoggerFactory.getLogger(AdminMarketQuotationsManageController.class);
 
    /**
     * 列表
     */
    @RequestMapping(action + "list.action")
    public ModelAndView list(HttpServletRequest request) {
        String message = request.getParameter("message");
        String error = request.getParameter("error");
        
        int pageSize = 30;
        int pageNo=checkAndSetPageNo(request.getParameter("pageNo"));
        Page page = this.adminMarketQuotationsService.pageQuery(pageNo, pageSize);
        
        ModelAndView model = new ModelAndView();
        model.addObject("pageNo", pageNo);
        model.addObject("pageSize", pageSize);
        model.addObject("page", page);
        model.addObject("message", message);
        model.addObject("error", error);
        model.setViewName("market_quotations_list");
        return model;
    }
 
    /**
     * 行情管理-调整弹框显示
     */
    @RequestMapping(action + "showModal.action")
    public String showModal(HttpServletRequest request) {
        
        String symbol = request.getParameter("symbol");
        
        Map<String, Object> resultMap = new HashMap<String, Object>();
        Realtime realtime = DataCache.getRealtime(symbol);
        if (realtime == null) {
            realtime = this.dataService.realtime(symbol).get(0);
        }
        Item item = this.itemService.cacheBySymbol(symbol, false);
        Double currentValues = this.adjustmentValueService.getCurrentValue(symbol);
        String currentValue = new BigDecimal(String.valueOf(currentValues)).toPlainString();
        if (currentValue == null) {
            resultMap.put("adjust_value", 0D);
        } else {
            resultMap.put("adjust_value", currentValue);
        }
        if (currentValue == null) {
            resultMap.put("new_price", realtime.getClose());
        } else {
            resultMap.put("new_price", Arith.sub(realtime.getClose(), currentValues));
        }
 
        resultMap.put("pips",new BigDecimal(String.valueOf(item.getPips())).toPlainString());
        resultMap.put("totalPrice",new BigDecimal(String.valueOf(realtime.getClose()+currentValues)).toPlainString());
        AdjustmentValue delayValue = this.adjustmentValueService.getDelayValue(symbol);
 
        if (delayValue != null) {
            resultMap.put("delay_value", delayValue.getValue());
            resultMap.put("delay_second", delayValue.getSecond());
        }
        return JsonUtils.getJsonString(resultMap);
    }
 
    /**
     * 页面计算
     * 
     */
    @RequestMapping(action + "getValue.action")
    public String getValue(HttpServletRequest request) {
        if (!StringUtils.isNullOrEmpty(getLoginPartyId())) {
            return "";
        }
        
        String symbol = request.getParameter("symbol");
        // 0增加一个pips 1减少一个pips 2直接修改调整值
        String type_temp = request.getParameter("type");
        String value_temp = request.getParameter("value");
        
        Double type = Double.valueOf(type_temp);
        Double value = Double.valueOf(value_temp);
 
        Map<String, Object> resultMap = new HashMap<String, Object>();
 
        Realtime realtime = null;
 
        if (realtime == null) {
            realtime = this.dataService.realtime(symbol).get(0);
        }
        Item item = this.itemService.cacheBySymbol(symbol, false);
        Double currentValue = this.adjustmentValueService.getCurrentValue(symbol);
        if (currentValue == null) {
            resultMap.put("new_price", realtime.getClose());
        } else {
            resultMap.put("new_price", Arith.sub(realtime.getClose(), currentValue));
        }
 
        double temp;
        if (type == 0) {
            temp = Arith.add(value, item.getPips());
            // 调整量
            resultMap.put("adjust_current_value",new BigDecimal(String.valueOf(temp)).toPlainString());
            // 调整后的值
            resultMap.put("adjust_value_after",new BigDecimal(String.valueOf(Arith.add(realtime.getClose(), temp))).toPlainString());
        } else if (type == 1) {
            temp = Arith.sub(value, item.getPips());
 
            resultMap.put("adjust_current_value", new BigDecimal(String.valueOf(temp)).toPlainString());
            resultMap.put("adjust_value_after",new BigDecimal(String.valueOf(Arith.add(realtime.getClose(), temp))).toPlainString());
        } else {
            temp = value;
            resultMap.put("adjust_current_value", new BigDecimal(String.valueOf(temp)).toPlainString());
            resultMap.put("adjust_value_after",new BigDecimal(String.valueOf(Arith.add(realtime.getClose(), temp))).toPlainString());
        }
 
        if (currentValue == null) {
            resultMap.put("adjust_value",new BigDecimal(String.valueOf(item.getPips())).toPlainString());
        } else {
            resultMap.put("adjust_value",new BigDecimal(String.valueOf(Arith.add(temp, currentValue))).toPlainString());
        }
        AdjustmentValue delayValue = this.adjustmentValueService.getDelayValue(symbol);
 
        if (delayValue != null) {
            resultMap.put("delay_value", delayValue.getValue());
            resultMap.put("delay_second", delayValue.getSecond());
        }
 
        return JsonUtils.getJsonString(resultMap);
    }
 
    /**
     * 调整
     */
    @RequestMapping(action + "adjust.action")
    public ModelAndView adjust(HttpServletRequest request) {
        ModelAndView model = new ModelAndView();
        String message = "";
        String error = "";
        
        // 调整值
        String value = request.getParameter("value");
        String symbol = request.getParameter("symbol");
        // 延迟秒
        String second = request.getParameter("second");
        
        if (StringUtils.isNullOrEmpty(value)) {
            throw new BusinessException("调整值不能为空!");
        }
        try {
            
            Double currentValue = this.adjustmentValueService.getCurrentValue(symbol);
            if (currentValue == null) {
                Realtime realtime =  this.dataService.realtime(symbol).get(0);;
                currentValue=realtime.getClose();
            } 
            SecUser sec = this.secUserService.findUserByLoginName(this.getUsername_login());
            String log = MessageFormat.format("ip:"+this.getIp()+",管理员调整行情,币种:{0},原值:{1},调整值:{2},调整时间:{3}", 
                    symbol,new BigDecimal(currentValue).toPlainString(),new BigDecimal(value).toPlainString(),second);
            
            this.adjustmentValueService.adjust(symbol, Double.valueOf(value), Double.valueOf(second));
            saveLog(sec, this.getUsername_login(), log);
            
            ThreadUtils.sleep(1000);
            message = "操作成功";
        } catch (BusinessException e) {
            error = e.getMessage();
        } catch (Exception e) {
            logger.error("error ", e);
            error = "程序错误";
        }
        model.addObject("message", message);
        model.addObject("error", error);
        model.setViewName("redirect:/" + action + "list.action");
        return model;
    }
 
    public void saveLog(SecUser secUser, String operator,String context) {
        project.log.Log log = new project.log.Log();
        log.setCategory(Constants.LOG_CATEGORY_OPERATION);
        log.setOperator(operator);
        log.setUsername(secUser.getUsername());
        log.setPartyId(secUser.getPartyId());
        log.setLog(context);
        log.setCreateTime(new Date());
        logService.saveSync(log);
    }    
}