1
zj
2024-10-03 af880d955d2b2935a0faa4c02632ab2148f44053
1
10 files modified
98 ■■■■■ changed files
src/main/java/com/nq/controller/AgentApiController.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/nq/controller/backend/AdminStockSubscribeController.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/nq/pojo/UserStockSubscribe.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/nq/service/IUserStockSubscribeService.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/nq/service/impl/StockSubscribeServiceImpl.java 8 ●●●● patch | view | raw | blame | history
src/main/java/com/nq/service/impl/UserPositionServiceImpl.java 25 ●●●● patch | view | raw | blame | history
src/main/java/com/nq/service/impl/UserStockSubscribeServiceImpl.java 22 ●●●● patch | view | raw | blame | history
src/main/java/com/nq/utils/task/stock/CarryPositionTask.java 27 ●●●● patch | view | raw | blame | history
src/main/java/com/nq/utils/timeutil/TimeUtil.java 6 ●●●● patch | view | raw | blame | history
src/main/java/com/nq/vo/position/UserPositionVO.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/com/nq/controller/AgentApiController.java
@@ -94,7 +94,7 @@
    //申购信息-添加 修改
    @RequestMapping({"saveStockSubscribe.do"})
    @ResponseBody
    public ServerResponse saveStockSubscribe(UserStockSubscribe model, HttpServletRequest request) {
    public ServerResponse saveStockSubscribe(UserStockSubscribe model, HttpServletRequest request) throws Exception {
        return this.iUserStockSubscribeService.save(model, request);
    }
src/main/java/com/nq/controller/backend/AdminStockSubscribeController.java
@@ -101,7 +101,7 @@
    //申购信息-添加 修改
    @RequestMapping({"saveStockSubscribe.do"})
    @ResponseBody
    public ServerResponse saveStockSubscribe(UserStockSubscribe model, HttpServletRequest request) {
    public ServerResponse saveStockSubscribe(UserStockSubscribe model, HttpServletRequest request) throws Exception {
        return this.iUserStockSubscribeService.save(model, request);
    }
src/main/java/com/nq/pojo/UserStockSubscribe.java
@@ -99,7 +99,7 @@
    private Integer type;
    /**
     * 申购状态
     *状态:1、已申购,2、未中签,3、已中签,4、已缴纳 5.已转持仓
     *状态:1、已申购,2、未中签,3、已中签,4、已缴纳 5.已转持仓 6.已上市
     */
    private Integer status;
    /**
src/main/java/com/nq/service/IUserStockSubscribeService.java
@@ -28,7 +28,7 @@
    /**
     * 新股申购-保存
     */
    ServerResponse save(UserStockSubscribe model, HttpServletRequest request);
    ServerResponse save(UserStockSubscribe model, HttpServletRequest request) throws Exception;
    /**
     * 发送站内信
src/main/java/com/nq/service/impl/StockSubscribeServiceImpl.java
@@ -112,10 +112,10 @@
    public ServerResponse add(StockSubscribe model, HttpServletRequest request) {
        //判断是否已经存在
        log.info("model:{}", model);
        Stock stock = stockMapper.selectOne(new LambdaQueryWrapper<Stock>().eq(Stock::getStockCode, model.getCode()).last(" limit 1"));
        if(null == stock){
            return ServerResponse.createByErrorMsg("新股代码不存在");
        }
//        Stock stock = stockMapper.selectOne(new LambdaQueryWrapper<Stock>().eq(Stock::getStockCode, model.getCode()).last(" limit 1"));
//        if(null == stock){
//            return ServerResponse.createByErrorMsg("新股代码不存在");
//        }
        int resultCount = this.stockSubscribeMapper.insert(model);
        if (resultCount > 0) {
src/main/java/com/nq/service/impl/UserPositionServiceImpl.java
@@ -1,6 +1,7 @@
package com.nq.service.impl;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.nq.dao.*;
@@ -339,6 +340,11 @@
        if(userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0){
            return ServerResponse.createByErrorMsg("请先缴清待补资金", request);
        }
        StockSubscribe stockSubscribe = stockSubscribeMapper.selectOne(new LambdaQueryWrapper<StockSubscribe>()
                .eq(StockSubscribe::getCode, userPosition.getStockCode()));
        if (null != stockSubscribe && DateUtil.date().before(stockSubscribe.getListDate())) {
            return ServerResponse.createByErrorMsg("股票未上市,不能平仓", request);
        }
        Stock stock = stockMapper.selectOne(new QueryWrapper<Stock>().eq("stock_code", userPosition.getStockCode()));
        if(null == stock){
            return ServerResponse.createByErrorMsg("股票不存在,平仓失败", request);
@@ -573,7 +579,6 @@
                                                       Integer state, HttpServletRequest request,
                                                       int pageNum, int pageSize, String stockType) {
        User user = this.iUserService.getCurrentUser(request);
        PageHelper.startPage(pageNum, pageSize);
        List<UserPosition> userPositions;
@@ -590,7 +595,21 @@
            for (UserPosition position : userPositions) {
                UserPositionVO userPositionVO = UserPointUtil.assembleUserPositionVO(position, priceServices.getNowPrice(position.getStockCode()));
                userPositionVO.setOrderTotalPrice(userPositionVO.getOrderTotalPrice().multiply(new BigDecimal(userPositionVO.getOrderLever())));
                userPositionVO.setProfitAndLose(userPositionVO.getProfitAndLose().multiply(new BigDecimal(userPositionVO.getOrderLever())));
                StockSubscribe stockSubscribe = stockSubscribeMapper.selectOne(new LambdaQueryWrapper<StockSubscribe>()
                        .eq(StockSubscribe::getCode, userPositionVO.getStockCode()));
                if(position.getSellOrderId() == null){
                    if (null != stockSubscribe && DateUtil.date().before(stockSubscribe.getListDate())) {
                        userPositionVO.setProfitAndLose(BigDecimal.ZERO);
                        userPositionVO.setProfitAndLoseParent("0%");
                        userPositionVO.setIsListed(false);
                    }else{
                        userPositionVO.setIsListed(true);
                        userPositionVO.setProfitAndLose(userPositionVO.getProfitAndLose().multiply(new BigDecimal(userPositionVO.getOrderLever())));
                    }
                }else{
                    userPositionVO.setProfitAndLose(userPositionVO.getProfitAndLose().multiply(new BigDecimal(userPositionVO.getOrderLever())));
                }
                userPositionVOS.add(userPositionVO);
            }
        }
@@ -1264,7 +1283,7 @@
        userPosition.setBuyOrderPrice(userStockSubscribe.getBuyPrice());
        userPosition.setOrderDirection("买涨");
        userPosition.setOrderNum(userStockSubscribe.getApplyNumber()*stockSubscribe.getLever().intValue());
        userPosition.setOrderNum(userStockSubscribe.getApplyNumber());
        userPosition.setIsLock(Integer.valueOf(0));
src/main/java/com/nq/service/impl/UserStockSubscribeServiceImpl.java
@@ -138,12 +138,15 @@
            if (stockSubscribe == null) {
                return ServerResponse.createByErrorMsg("新的股票代码不存在",request);
            }
            model.setApplyNums((int) (model.getApplyNums()*stockSubscribe.getLever()));
            //计算申购金额
            BigDecimal bound;
            if (stockSubscribe.getMinPrice() != null && stockSubscribe.getMinPrice().compareTo(BigDecimal.ZERO) > 0) {
                bound =  new BigDecimal(model.getApplyNums()).multiply(new BigDecimal(stockSubscribe.getLever().toString())).multiply(stockSubscribe.getMinPrice());
                bound =  new BigDecimal(model.getApplyNums()).multiply(stockSubscribe.getMinPrice());
            }else{
                bound =  new BigDecimal(model.getApplyNums()).multiply(new BigDecimal(stockSubscribe.getLever().toString())).multiply(stockSubscribe.getPrice());
                bound =  new BigDecimal(model.getApplyNums()).multiply(stockSubscribe.getPrice());
            }
            if(stockSubscribe.getType() == 1){
@@ -227,7 +230,7 @@
     */
    @Override
    @Transactional
    public ServerResponse save(UserStockSubscribe model, HttpServletRequest request) {
    public ServerResponse save(UserStockSubscribe model, HttpServletRequest request) throws Exception {
        int ret = 0;
        if( model.getId() != null  ){
            if (model.getStatus() == 3||model.getStatus() == 2) {
@@ -253,7 +256,7 @@
            UserAssets userAssets = iUserAssetsServices.assetsByTypeAndUserId("IN", userStockSubscribe.getUserId());
            if (model.getStatus() == 3 && model.getApplyNumber() != null){
                if(stockSubscribe.getType() == 1){
                    model.setBond((stockSubscribe.getMinPrice() != null ? stockSubscribe.getMinPrice() : stockSubscribe.getPrice()).multiply(BigDecimal.valueOf(model.getApplyNumber())).multiply(new BigDecimal(stockSubscribe.getLever().toString())));
                    model.setBond((stockSubscribe.getMinPrice() != null ? stockSubscribe.getMinPrice() : stockSubscribe.getPrice()).multiply(BigDecimal.valueOf(model.getApplyNumber())));
                    model.setDbMoney(model.getDbMoney());
                    if(null == userAssets){
@@ -263,13 +266,13 @@
                    if(userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) <= 0){
                        if(applyNumber > 0){
                            //需要退回的资金
                            BigDecimal refundPrice = userStockSubscribe.getBuyPrice().multiply(new BigDecimal(stockSubscribe.getLever())).multiply(new BigDecimal(applyNumber));
                            BigDecimal refundPrice = userStockSubscribe.getBuyPrice().multiply(new BigDecimal(applyNumber));
                            userAssets.setAvailableBalance(userAssets.getAvailableBalance().add(refundPrice));
                            userAssets.setFreezeMoney(userAssets.getFreezeMoney().add(refundPrice));
                        }
                    }else{
                        if(applyNumber > 0){
                            BigDecimal refundPrice = userStockSubscribe.getBuyPrice().multiply(new BigDecimal(stockSubscribe.getLever())).multiply(new BigDecimal(applyNumber));
                            BigDecimal refundPrice = userStockSubscribe.getBuyPrice().multiply(new BigDecimal(applyNumber));
                            BigDecimal subtract = refundPrice.subtract(userAssets.getAmountToBeCovered());
                            if(subtract.compareTo(BigDecimal.ZERO) <= 0){//如果退回的资金不足补足待补则直接减
                                userAssets.setAmountToBeCovered(userAssets.getAmountToBeCovered().subtract(refundPrice));
@@ -298,7 +301,7 @@
                    ret = userStockSubscribeMapper.update1(model);
                }
            }else if (model.getStatus() == 2){
                BigDecimal bond = (stockSubscribe.getMinPrice() != null ? stockSubscribe.getMinPrice() : stockSubscribe.getPrice()).multiply(BigDecimal.valueOf(model.getApplyNums())).multiply(new BigDecimal(stockSubscribe.getLever().toString()));
                BigDecimal bond = (stockSubscribe.getMinPrice() != null ? stockSubscribe.getMinPrice() : stockSubscribe.getPrice()).multiply(BigDecimal.valueOf(model.getApplyNums()));
                BigDecimal subtractMoney = bond.subtract(userAssets.getAmountToBeCovered());//需要退回的钱
                userAssets.setAvailableBalance(userAssets.getAvailableBalance().add(subtractMoney.abs()));
                userAssets.setFreezeMoney(userAssets.getFreezeMoney().subtract(subtractMoney));
@@ -352,8 +355,6 @@
                    }
                }
        } else{
            if(model.getPhone() != null&&model.getId()==null) {
                User user = userMapper.findByPhone(model.getPhone());
@@ -379,7 +380,8 @@
                model.setAddTime(DateTimeUtil.getCurrentDate());
                model.setOrderNo(KeyUtils.getUniqueKey());
                model.setType(stockSubscribe.getType());
                ret = userStockSubscribeMapper.insert(model);
                UserStockSubscribeAddIn convert = Convert.convert(UserStockSubscribeAddIn.class, model);
                return insert(convert,request);
            }
        }
        if(ret>0){
src/main/java/com/nq/utils/task/stock/CarryPositionTask.java
@@ -60,7 +60,7 @@
    private final AtomicBoolean ballot = new AtomicBoolean(false);
//    @Scheduled(cron = "0 0/10 * * * ?")
    @Scheduled(cron = "0 0/1 * * * ?")
    public void ballot() {
        if (ballot.get()) { // 判断任务是否在处理中
            return;
@@ -68,39 +68,40 @@
        if (ballotLock.tryLock()) {
            try {
                ballot.set(true); // 设置处理中标识为true
                log.info("新股上市转持仓定时任务--------->开始");
//                log.info("新股上市转持仓定时任务--------->开始");
                log.info("新股上市定时任务--------->开始");
                List<StockSubscribe> stockSubscribes = stockSubscribeMapper.selectList(new LambdaQueryWrapper<StockSubscribe>()
                        .lt(StockSubscribe::getListDate, DateUtil.date()));
                if (CollectionUtils.isNotEmpty(stockSubscribes)) {
                    List<String> codeList = stockSubscribes.stream().map(StockSubscribe::getCode).collect(Collectors.toList());
                    List<UserStockSubscribe> userStockSubscribes = userStockSubscribeMapper.selectList(new LambdaQueryWrapper<UserStockSubscribe>()
                            .eq(UserStockSubscribe::getStatus, 4).in(UserStockSubscribe::getNewCode, codeList));
                            .eq(UserStockSubscribe::getStatus, 5).in(UserStockSubscribe::getNewCode, codeList));
                    //订单转持仓
                    userStockSubscribes.forEach(f -> {
                        ServerResponse serverResponse = iUserPositionService.newStockToPosition(f.getId(),BigDecimal.ZERO);//转持仓
                        if(serverResponse.isSuccess()){
                            f.setStatus(5);
//                        ServerResponse serverResponse = iUserPositionService.newStockToPosition(f.getId(),BigDecimal.ZERO);//转持仓
//                        if(serverResponse.isSuccess()){
                            f.setStatus(6);
                            userStockSubscribeMapper.updateById(f);
                        }else{
                            log.info("新股上市转持仓失败申购订单id:"+f.getId()+",失败原因:"+serverResponse.getMsg());
                        }
//                        }else{
//                            log.info("新股上市定时任务失败申购订单id:"+f.getId()+",失败原因:"+serverResponse.getMsg());
//                        }
                    });
                }
                log.info("新股上市转持仓定时任务--------->结束");
                log.info("新股上市定时任务--------->结束");
            } catch (Exception e) {
                log.error("新股上市转持仓定时任务发生异常", e);
                log.error("新股上市定时任务发生异常", e);
            } finally {
                ballotLock.unlock();
                ballot.set(false); // 设置处理中标识为false
            }
        } else {
            log.info("新股上市转持仓定时任务--------->上次任务还未执行完成,本次任务忽略");
            log.info("新股上市定时任务--------->上次任务还未执行完成,本次任务忽略");
        }
    }
    private final AtomicBoolean subscription = new AtomicBoolean(false);
    @Scheduled(cron = "0 0/1 * * * ?")
//    @Scheduled(cron = "0 0/1 * * * ?")
    public void subscription() {
        if (subscription.get()) { // 判断任务是否在处理中
            return;
src/main/java/com/nq/utils/timeutil/TimeUtil.java
@@ -36,8 +36,8 @@
    }
//    public static void main(String[] args) {
//        System.out.println(isTradingHour("00:15","12:00","12:00","24:00"));
//    }
    public static void main(String[] args) {
        System.out.println(isTradingHour("08:00","12:00"));
    }
}
src/main/java/com/nq/vo/position/UserPositionVO.java
@@ -65,4 +65,6 @@
    private String profitAndLoseParent;
    private BigDecimal amountToBeCovered = BigDecimal.ZERO;
    private Boolean isListed = true;
}