1
zj
2024-04-25 23c07b71a269f2540e5c09eb8d2002d9f20a857e
src/main/java/com/nq/utils/task/stock/CarryPositionTask.java
@@ -4,12 +4,16 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.nq.common.ServerResponse;
import com.nq.dao.StockSubscribeMapper;
import com.nq.dao.UserAssetsMapper;
import com.nq.dao.UserMapper;
import com.nq.dao.UserStockSubscribeMapper;
import com.nq.pojo.StockSubscribe;
import com.nq.pojo.User;
import com.nq.pojo.UserAssets;
import com.nq.pojo.UserStockSubscribe;
import com.nq.service.IUserAssetsServices;
import com.nq.service.IUserPositionService;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.utils.DateUtils;
@@ -45,7 +49,12 @@
    @Autowired
    UserMapper userMapper;
    @Autowired
    IUserAssetsServices userAssetsServices;
    private final Lock ballotLock = new ReentrantLock();
    private final Lock subscriptionLock = new ReentrantLock();
    @Scheduled(cron = "0 0/10 * * * ?")
    public void ballot() {
@@ -60,9 +69,13 @@
                            .eq(UserStockSubscribe::getStatus, 4).in(UserStockSubscribe::getNewCode, codeList));
                    //订单转持仓
                    userStockSubscribes.forEach(f -> {
                        iUserPositionService.newStockToPosition(f.getId());//转持仓
                        f.setStatus(5);
                        userStockSubscribeMapper.updateById(f);
                        ServerResponse serverResponse = iUserPositionService.newStockToPosition(f.getId());//转持仓
                        if(serverResponse.isSuccess()){
                            f.setStatus(5);
                            userStockSubscribeMapper.updateById(f);
                        }else{
                            log.info("新股上市转持仓失败申购订单id:"+f.getId()+",失败原因:"+serverResponse.getMsg());
                        }
                    });
                }
                log.info("新股上市转持仓定时任务--------->结束");
@@ -76,4 +89,29 @@
        }
    }
    @Scheduled(cron = "0 0/1 * * * ?")
    public void subscription() {
        if (subscriptionLock.tryLock()) {
            try {
                log.info("自动转已认缴--------->开始");
                List<UserStockSubscribe> userStockSubscribes = userStockSubscribeMapper.selectList(new LambdaQueryWrapper<UserStockSubscribe>()
                        .eq(UserStockSubscribe::getStatus, 3));
                userStockSubscribes.forEach(f->{
                    UserAssets userAssets = userAssetsServices.assetsByTypeAndUserId("IN",f.getUserId());
                    if(null != userAssets && userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) == 0){
                        f.setStatus(4);
                        userStockSubscribeMapper.updateById(f);
                    }
                });
                log.info("自动转已认缴--------->结束");
            } catch (Exception e) {
                log.error("自动转已认缴定时任务发生异常", e);
            } finally {
                subscriptionLock.unlock();
            }
        } else {
            log.info("自动转已认缴定时任务--------->上次任务还未执行完成,本次任务忽略");
        }
    }
}