| | |
| | | package com.nq.controller; |
| | | |
| | | import com.nq.common.ServerResponse; |
| | | import com.nq.service.ExchangeRateService; |
| | | import com.nq.service.IStockAiService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Controller; |
| | |
| | | |
| | | @Autowired |
| | | IStockAiService stockAiService; |
| | | @Autowired |
| | | ExchangeRateService exchangeRateService; |
| | | |
| | | private static final ThreadLocal<Boolean> buyOrderCreated = ThreadLocal.withInitial(() -> false); |
| | | private final Lock buyLock = new ReentrantLock(); |
| | |
| | | public ServerResponse buyStockAi(@RequestParam(value = "id") Long id, |
| | | @RequestParam(value = "buyNum") BigDecimal buyNum, HttpServletRequest request) { |
| | | if (buyNum.compareTo(BigDecimal.ZERO) <= 0) { |
| | | return ServerResponse.createByErrorMsg("购买金额不能小于0"); |
| | | return ServerResponse.createByErrorMsg("购买金额不能小于0", request); |
| | | } |
| | | buyLock.lock(); |
| | | try { |
| | | if (buyOrderCreated.get()) { |
| | | return ServerResponse.createByErrorMsg("当前下单人数过多,请稍后重试"); |
| | | return ServerResponse.createByErrorMsg("当前下单人数过多,请稍后重试", request); |
| | | } |
| | | buyOrderCreated.set(true); |
| | | return stockAiService.buyStockAi(id, buyNum, request); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return ServerResponse.createByErrorMsg("订单异常,请稍后重试"); |
| | | return ServerResponse.createByErrorMsg("订单异常,请稍后重试", request); |
| | | } finally{ |
| | | buyLock.unlock(); |
| | | buyOrderCreated.set(false); |
| | |
| | | |
| | | /** |
| | | * 获取ai交易产品订单列表 |
| | | * @param pageNum |
| | | * @param pageSize |
| | | * @param status 状态 |
| | | * @param request |
| | | * @return |
| | | */ |
| | | @RequestMapping("getStockAiOrderList.do") |
| | |
| | | HttpServletRequest request) { |
| | | return stockAiService.getStockAiOrderList(pageNum, pageSize, status ,request); |
| | | } |
| | | |
| | | //查询汇率信息 |
| | | @RequestMapping({"getRateInfo.do"}) |
| | | @ResponseBody |
| | | public ServerResponse getInfo() { |
| | | return exchangeRateService.getInfo(); |
| | | } |
| | | } |