zyy
2025-12-06 ab7e92d5154b5acf05699bd527c4d8b5fff10550
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
package com.yami.trading.api.controller.ats;
 
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.ats.StockAtsService;
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 = "股票Ats")
@RequestMapping("api/stockAts")
@Slf4j
public class ApiStockAtsController {
 
    @Resource
    StockAtsService stockAtsService;
 
    private static final ThreadLocal<Boolean> orderCreated = ThreadLocal.withInitial(() -> false);
    private final Lock lock = new ReentrantLock();
 
    @ApiOperation("ATS订单列表")
    @PostMapping({"getOrderList.do"})
    @ResponseBody
    public Result getOrderList(@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 stockAtsService.getList(pageNum, pageSize, partyId);
    }
 
    @ApiOperation("ATS下单")
    @GetMapping({"buyStockAts.do"})
    @ResponseBody
    public Result buyDz(@RequestParam(name = "price") double price) {
        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 stockAtsService.buyAts(price, partyId);
        } catch (Exception e) {
            log.error(e.getMessage());
        }  finally{
            lock.unlock();
            orderCreated.set(false);
        }
        throw new YamiShopBindException("订单异常,请稍后重试");
    }
 
 
 
 
 
}