1
zj
2024-04-24 29446dbdaea7d11eb28a4210ec69a186c54e705e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package com.nq.utils.task.stock;
 
import cn.hutool.core.date.DateUtil;
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.dao.StockSubscribeMapper;
import com.nq.dao.UserMapper;
import com.nq.dao.UserStockSubscribeMapper;
import com.nq.pojo.StockSubscribe;
import com.nq.pojo.User;
import com.nq.pojo.UserStockSubscribe;
import com.nq.service.IUserPositionService;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import java.math.BigDecimal;
import java.util.List;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
 
/**
 * @program: dabao
 * @description:
 * @create: 2024-04-01 17:32
 **/
@Component
@Slf4j
public class CarryPositionTask {
 
 
    @Autowired
    UserStockSubscribeMapper userStockSubscribeMapper;
 
    @Autowired
    IUserPositionService iUserPositionService;
 
    @Autowired
    StockSubscribeMapper stockSubscribeMapper;
 
    @Autowired
    UserMapper userMapper;
 
    private final Lock ballotLock = new ReentrantLock();
 
    @Scheduled(cron = "0 0/10 * * * ?")
    public void ballot() {
        if (ballotLock.tryLock()) {
            try {
                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));
                    //订单转持仓
                    userStockSubscribes.forEach(f -> {
                        iUserPositionService.newStockToPosition(f.getId());//转持仓
                        f.setStatus(5);
                        userStockSubscribeMapper.updateById(f);
                    });
                }
                log.info("新股上市转持仓定时任务--------->结束");
            } catch (Exception e) {
                log.error("新股上市转持仓定时任务发生异常", e);
            } finally {
                ballotLock.unlock();
            }
        } else {
            log.info("新股上市转持仓定时任务--------->上次任务还未执行完成,本次任务忽略");
        }
    }
 
}