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("订单异常,请稍后重试");
|
}
|
|
|
|
|
|
}
|