zyy
2025-12-09 6eef7f43f9ad3d82727fba36f543f268cfb646d2
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
package com.yami.trading.api.controller.dz;
 
import com.yami.trading.bean.dz.ExchangeApplyOrderDz;
import com.yami.trading.common.constants.Constants;
import com.yami.trading.common.domain.Result;
import com.yami.trading.common.exception.YamiShopBindException;
import com.yami.trading.security.common.util.SecurityUtils;
import com.yami.trading.service.dz.StockDzService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
 
@RestController
@CrossOrigin
@Api(tags = "ETF暗池")
@RequestMapping("api/etfDarkPools")
@Slf4j
public class ApiETFDarkPoolsController {
 
    @Resource
    StockDzService stockDzService;
 
    private static final ThreadLocal<Boolean> orderCreated = ThreadLocal.withInitial(() -> false);
    private final Lock lock = new ReentrantLock();
 
 
    @ApiOperation("大宗交易列表")
    @PostMapping({"getDzList.do"})
    @ResponseBody
    public Result getDzList(@RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
                            @RequestParam(value = "pageSize", defaultValue = "5") int pageSize,
                            @RequestParam(value = "orderBy", required = false) String orderBy,
                            @RequestParam(value = "keyWords", required = false) String keyWords) {
        return stockDzService.getDzList(pageNum, pageSize, orderBy,keyWords, Constants.indices_dark);
    }
 
 
 
    @ApiOperation("大宗下单")
    @GetMapping({"buyStockDz.do"})
    @ResponseBody
    public Result buyDz(@RequestParam("dzId") String dzId,
                        @RequestParam(value = "password", required = false) String password,
                        @RequestParam("num") double num) {
        lock.lock();
        try {
            if (orderCreated.get()) {
                throw new YamiShopBindException("当前交易人数过多,请稍后重试");
            }
            orderCreated.set(true);
            String partyId = SecurityUtils.getCurrentUserId();
            if (partyId == null || partyId.isEmpty()) {
                throw new YamiShopBindException("请先登录");
            }
            return stockDzService.buyDz(dzId, password, num, partyId, false);
        } catch (Exception e) {
            log.error(e.getMessage());
        }  finally{
            lock.unlock();
            orderCreated.set(false);
        }
        throw new YamiShopBindException("订单异常,请稍后重试");
    }
 
 
 
 
 
    @ApiOperation("大宗交易持仓订单列表")
    @PostMapping({"getDzOrderList.do"})
    @ResponseBody
    public Result getDzOrderList(@RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
                                         @RequestParam(value = "pageSize", defaultValue = "5") int pageSize) {
        String partyId = SecurityUtils.getCurrentUserId();
        if (partyId == null || partyId.isEmpty()) {
            throw new YamiShopBindException("请先登录");
        }
        return stockDzService.getDzOrderList(pageNum, pageSize, ExchangeApplyOrderDz.STATE_POSITION, partyId, Constants.indices_dark);
    }
 
    @ApiOperation("大宗交易历史订单列表")
    @PostMapping({"getDzHistoryList.do"})
    @ResponseBody
    public Result getDzHistoryList(@RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
                                   @RequestParam(value = "pageSize", defaultValue = "5") int pageSize) {
        String partyId = SecurityUtils.getCurrentUserId();
        if (partyId == null || partyId.isEmpty()) {
            throw new YamiShopBindException("请先登录");
        }
        return stockDzService.getDzOrderList(pageNum, pageSize, null, partyId, Constants.indices_dark);
    }
 
    @ApiOperation("大宗平仓")
    @GetMapping({"closeStockDz.do"})
    @ResponseBody
    public Result closeStockDz(@RequestParam("id") String id,
                               @RequestParam(value = "num", required = false) Double num) {
        lock.lock();
        try {
            if (orderCreated.get()) {
                throw new YamiShopBindException("当前交易人数过多,请稍后重试");
            }
            orderCreated.set(true);
            String partyId = SecurityUtils.getCurrentUserId();
            if (partyId == null || partyId.isEmpty()) {
                throw new YamiShopBindException("请先登录");
            }
            return stockDzService.closeDz(id, num, partyId, false);
        } catch (Exception e) {
            log.error(e.getMessage());
        }  finally{
            lock.unlock();
            orderCreated.set(false);
        }
        throw new YamiShopBindException("订单异常,请稍后重试");
    }
 
}