| | |
| | | package com.nq.controller.echo; |
| | | |
| | | import com.nq.common.ServerResponse; |
| | | import com.nq.dao.EChoMapper; |
| | | import com.nq.enums.EStockType; |
| | | import com.nq.pojo.EChoBean; |
| | | import com.nq.pojo.User; |
| | | import com.nq.pojo.UserAssets; |
| | | import com.nq.service.IEchoServices; |
| | | import com.nq.service.IUserService; |
| | | import com.nq.service.impl.UserAssetsServices; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.math.BigDecimal; |
| | | |
| | | /** |
| | | * 利息报接口 |
| | |
| | | |
| | | @Autowired |
| | | IEchoServices iEchoServices; |
| | | |
| | | @Autowired |
| | | EChoMapper eChoMapper; |
| | | |
| | | @Autowired |
| | | UserAssetsServices userAssetsServices; |
| | | |
| | | @Autowired |
| | | IUserService iUserService; |
| | |
| | | |
| | | @PostMapping("buyEcho.do") |
| | | @ResponseBody |
| | | public ServerResponse buyEcho(@RequestParam("eId") String eid, @RequestParam("money") Integer money, HttpServletRequest request) { |
| | | User user = this.iUserService.getCurrentRefreshUser(request); |
| | | if(user == null){ |
| | | return ServerResponse.createByErrorMsg("Please Login"); |
| | | public ServerResponse buyEcho(@RequestParam("eId") String eid, @RequestParam("money") BigDecimal money, HttpServletRequest request) { |
| | | if(null == money || money.compareTo(BigDecimal.ZERO) <= 0){ |
| | | return ServerResponse.createByErrorMsg("金额不能小于0",request); |
| | | } |
| | | if (iEchoServices.buyECho(eid, money,request)) { |
| | | return ServerResponse.createBySuccess("Buy Successed"); |
| | | EChoBean eChoBean = eChoMapper.selectById(Integer.parseInt(eid)); |
| | | if (eChoBean == null) { |
| | | return ServerResponse.createByErrorMsg("基金产品不存在",request); |
| | | } else { |
| | | return ServerResponse.createByErrorMsg("Buy Fail"); |
| | | if (null != eChoBean.getBuyLowestNum() && money.compareTo(new BigDecimal(eChoBean.getBuyLowestNum())) < 0) { |
| | | return ServerResponse.createByErrorMsg("购买失败,最低购买数量:"+eChoBean.getBuyLowestNum(),request); |
| | | } |
| | | } |
| | | User user = this.iUserService.getCurrentRefreshUser(request); |
| | | UserAssets userAssets = userAssetsServices.assetsByTypeAndUserId(EStockType.MX.getCode(), user.getId()); |
| | | if(userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0){ |
| | | return ServerResponse.createByErrorMsg("请先缴清待补资金", request); |
| | | } |
| | | if(userAssets.getAvailableBalance().compareTo(money) < 0){ |
| | | return ServerResponse.createByErrorMsg("配资不足",request); |
| | | } |
| | | if (iEchoServices.buyECho(eid, money, userAssets.getAccectType(), request)) { |
| | | return ServerResponse.createBySuccess("购买成功",request); |
| | | } else { |
| | | return ServerResponse.createByErrorMsg("购买失败",request); |
| | | } |
| | | } |
| | | |
| | |
| | | @PostMapping("queryOrderEcho.do") |
| | | @ResponseBody |
| | | public ServerResponse queryOrderEcho(HttpServletRequest request) { |
| | | return ServerResponse.createBySuccess(iEchoServices.queryOrderEcho(request)); |
| | | return ServerResponse.createBySuccess(iEchoServices.queryOrderEcho(request)); |
| | | } |
| | | |
| | | |