zyy
2025-07-18 96e443a77b1d425d3e536c288fc271fe182f1496
src/main/java/com/nq/service/impl/UserStockSubscribeServiceImpl.java
@@ -5,6 +5,7 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.nq.Repository.ExchangeRateRepository;
import com.nq.common.ResponseCode;
import com.nq.common.ServerResponse;
import com.nq.dao.StockSubscribeMapper;
@@ -70,13 +71,16 @@
    @Autowired
    UserAssetsMapper userAssetsMapper;
    @Autowired
    ExchangeRateRepository exchangeRateRepository;
    /**
     * 用户新股申购
     * @param model
     * @return
     */
    @Override
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    public ServerResponse insert(UserStockSubscribeAddIn model, HttpServletRequest request) throws Exception {
        int ret = 0;
        if (model == null) {
@@ -148,7 +152,6 @@
                }else{
                    bound =  new BigDecimal(model.getApplyNums()).multiply(stockSubscribe.getPrice());
                }
                if(stockSubscribe.getType() == 1){
                    model.setUserId(user.getId());
                    model.setNewName(stockSubscribe.getName());
@@ -165,6 +168,10 @@
                    userStockSubscribe.setNewStockId(stockSubscribe.getNewlistId());
                    ret = userStockSubscribeMapper.insert(userStockSubscribe);
                    //如果不是墨西哥币需要转换金额
                    if (!stockSubscribe.getStockType().equals(EStockType.MX.getCode())) {
                        bound = iUserAssetsServices.exchangeAmountByRate(stockSubscribe.getStockType(), bound);
                    }
                    BigDecimal subtract = userAssets.getAvailableBalance().subtract(bound);
                    if(subtract.compareTo(BigDecimal.ZERO) >= 0){
                        userAssets.setFreezeMoney(userAssets.getFreezeMoney().add(bound));
@@ -230,7 +237,7 @@
     * admin 新股申购-添加和修改
     */
    @Override
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    public ServerResponse save(UserStockSubscribe model, HttpServletRequest request) throws Exception {
        int ret = 0;
        if( model.getId() != null  ){
@@ -268,12 +275,20 @@
                        if(applyNumber > 0){
                            //需要退回的资金
                            BigDecimal refundPrice = userStockSubscribe.getBuyPrice().multiply(new BigDecimal(applyNumber));
                            //如果不是墨西哥币需要转换金额
                            if (!stockSubscribe.getStockType().equals(EStockType.MX.getCode())) {
                                refundPrice = iUserAssetsServices.exchangeAmountByRate(stockSubscribe.getStockType(), refundPrice);
                            }
                            userAssets.setAvailableBalance(userAssets.getAvailableBalance().add(refundPrice));
                            userAssets.setFreezeMoney(userAssets.getFreezeMoney().subtract(refundPrice));
                        }
                    }else{
                        if(applyNumber > 0){
                            BigDecimal refundPrice = userStockSubscribe.getBuyPrice().multiply(new BigDecimal(applyNumber));
                            //如果不是墨西哥币需要转换金额
                            if (!stockSubscribe.getStockType().equals(EStockType.MX.getCode())) {
                                refundPrice = iUserAssetsServices.exchangeAmountByRate(stockSubscribe.getStockType(), refundPrice);
                            }
                            BigDecimal subtract = refundPrice.subtract(userAssets.getAmountToBeCovered());
                            if(subtract.compareTo(BigDecimal.ZERO) <= 0){//如果退回的资金不足补足待补则直接减
                                userAssets.setAmountToBeCovered(userAssets.getAmountToBeCovered().subtract(refundPrice));
@@ -479,50 +494,54 @@
     * 新股申购-用户提交金额
     */
    @Override
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    public ServerResponse userSubmit(Integer id,HttpServletRequest request) {
        int ret = 0;
        String property = PropertiesUtil.getProperty("user.cookie.name");
        String header = request.getHeader(property);
        if (header != null) {
            User user = iUserService.getCurrentRefreshUser(request);
            if(id == null){
                return ServerResponse.createByErrorMsg("参数错误",request);
            }
            UserStockSubscribe userStockSubscribe = userStockSubscribeMapper.load(id);
            if (userStockSubscribe != null && userStockSubscribe.getUserId().equals(user.getId())) {
                if(userStockSubscribe.getType()== 2 ){
                    return ServerResponse.createByErrorMsg("未中签,无需支付",request);
        try {
            int ret = 0;
            String property = PropertiesUtil.getProperty("user.cookie.name");
            String header = request.getHeader(property);
            if (header != null) {
                User user = iUserService.getCurrentRefreshUser(request);
                if(id == null){
                    return ServerResponse.createByErrorMsg("参数错误",request);
                }
                if (userStockSubscribe.getStatus() == 3) {
                    StockSubscribe stockSubscribe = stockSubscribeMapper.selectOne(new QueryWrapper<>(new StockSubscribe())
                            .eq("newlist_id", userStockSubscribe.getNewStockId()));
                    if (stockSubscribe == null) {
                        return ServerResponse.createByErrorMsg("新股不存在",request);
                UserStockSubscribe userStockSubscribe = userStockSubscribeMapper.load(id);
                if (userStockSubscribe != null && userStockSubscribe.getUserId().equals(user.getId())) {
                    if(userStockSubscribe.getType()== 2 ){
                        return ServerResponse.createByErrorMsg("未中签,无需支付",request);
                    }
                    userStockSubscribe.setSubmitTime(DateTimeUtil.getCurrentDate());
                    userStockSubscribe.setStatus(4);
                    BigDecimal bigDecimal =  iUserAssetsServices.
                            getAvailableBalance(EStockType.US.getCode(),
                                    userStockSubscribe.getUserId());
                    if (userStockSubscribe.getStatus() == 3) {
                        StockSubscribe stockSubscribe = stockSubscribeMapper.selectOne(new QueryWrapper<>(new StockSubscribe())
                                .eq("newlist_id", userStockSubscribe.getNewStockId()));
                        if (stockSubscribe == null) {
                            return ServerResponse.createByErrorMsg("新股不存在",request);
                        }
                        userStockSubscribe.setSubmitTime(DateTimeUtil.getCurrentDate());
                        userStockSubscribe.setStatus(4);
                        BigDecimal bigDecimal =  iUserAssetsServices.
                                getAvailableBalance(EStockType.US.getCode(),
                                        userStockSubscribe.getUserId());
                    BigDecimal multiply = userStockSubscribe.getBuyPrice().multiply(new BigDecimal(userStockSubscribe.getApplyNumber()));
                    if(bigDecimal.compareTo(multiply) <= 0){
                        return ServerResponse.createByErrorMsg("余额不足",request);
                        BigDecimal multiply = userStockSubscribe.getBuyPrice().multiply(new BigDecimal(userStockSubscribe.getApplyNumber()));
                        if(bigDecimal.compareTo(multiply) <= 0){
                            return ServerResponse.createByErrorMsg("余额不足",request);
                        }
                        iUserAssetsServices.availablebalanceChange(stockSubscribe.getStockType(), userStockSubscribe.getUserId(),
                                EUserAssets.BUY,multiply.negate(),"","");
                        userStockSubscribe.setDbMoney(BigDecimal.ZERO);
                        userStockSubscribeMapper.update1(userStockSubscribe);
                        return  ServerResponse.createBySuccess();
                    } else {
                        return ServerResponse.createByErrorMsg("不成功的申请者不收取任何费用",request);
                    }
                    iUserAssetsServices.availablebalanceChange(stockSubscribe.getStockType(), userStockSubscribe.getUserId(),
                            EUserAssets.BUY,multiply.negate(),"","");
                    userStockSubscribe.setDbMoney(BigDecimal.ZERO);
                    userStockSubscribeMapper.update1(userStockSubscribe);
                    return  ServerResponse.createBySuccess();
                } else {
                    return ServerResponse.createByErrorMsg("不成功的申请者不收取任何费用",request);
                    return ServerResponse.createByErrorMsg("新股认购订单不存在!",request);
                }
            } else {
                return ServerResponse.createByErrorMsg("新股认购订单不存在!",request);
            }
            return ServerResponse.createByErrorCodeMsg(ResponseCode.NEED_LOGIN.getCode(),"请先登录");
        } catch (Exception e) {
            return ServerResponse.createByErrorMsg(e.getMessage());
        }
        return ServerResponse.createByErrorCodeMsg(ResponseCode.NEED_LOGIN.getCode(),"请先登录");
    }
    /**
     * 新股申购-删除