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