admin
2025-02-25 30d8e227e8d823b6c38c3b9c90ac2df03b63befe
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package com.yeshi.fanli.job;
 
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
 
import javax.annotation.Resource;
 
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.yeshi.fanli.entity.SystemEnum;
import com.yeshi.fanli.util.StringUtil;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import com.yeshi.fanli.entity.push.PushGoods;
import com.yeshi.fanli.entity.push.PushInfo;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.push.PushGoodsService;
import com.yeshi.fanli.service.inter.push.PushInfoService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.factory.IOSPushFactory;
import com.yeshi.fanli.util.push.IOSPushUtil;
 
import net.sf.json.JSONObject;
 
@Component
public class PushJob {
 
    @Resource
    private PushInfoService pushInfoService;
 
    @Resource
    private PushGoodsService pushGoodsService;
 
 
    /**
     * 推送老版本IOS(每晚8点推送)
     */
    @Scheduled(cron = "0 0 20 * * ? ")
    public void pushOldIOS() {
        if (!Constant.IS_TASK)
            return;
        Scanner scanner = new Scanner(
                this.getClass().getClassLoader().getResourceAsStream("certificate/devicetoken.txt"));
        List<String> deviceList = new ArrayList<>();
        while (scanner.hasNext()) {
            deviceList.add(scanner.next().trim());
        }
        // 每次推送50条数据
        InputStream cer = null;
 
        int p = deviceList.size() / 50 + 1;
        JSONObject json = IOSPushFactory.createURLPush("https://0x9.me/TusaI", "板栗快省苹果端进行了重大更新!请立即升级",
                "更多优惠券,更高返利,尽在新版苹果端板栗快省!");
        for (int i = 0; i < p; i++) {
            cer = this.getClass().getClassLoader().getResourceAsStream("certificate/老版本-生产证书.p12");
            try {
                IOSPushUtil.pushIOS(
                        deviceList.subList(i * 50,
                                (i * 50 + 50) > deviceList.size() ? deviceList.size() : (i * 50 + 50)),
                        json, cer, "123");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
 
 
    /**
     * 定时消息推送任务 每个30秒爬取
     */
    @Scheduled(cron = "30 * * * * ? ")
    public void pushInfo() {
        if (!Constant.IS_TASK) {
            return;
        }
 
        for (SystemEnum system : SystemEnum.values()) {
 
            // 站内信、网页、百川
            try {
                List<PushInfo> listTask = pushInfoService.listTask(system);
                if (listTask != null && listTask.size() > 0) {
                    for (PushInfo pushInfo : listTask) {
                        pushInfoService.taskPush(pushInfo);
                    }
                }
            } catch (Exception e) {
                try {
                    LogHelper.errorDetailInfo(e);
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
 
            //    今日推荐
            try {
                List<PushGoods> listTask = pushGoodsService.listTask(system);
                if (listTask != null && listTask.size() > 0) {
                    for (PushGoods pushGoods : listTask) {
                        pushGoodsService.taskPush(pushGoods);
                    }
                }
            } catch (Exception e) {
                try {
                    LogHelper.errorDetailInfo(e);
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
 
        }
    }
 
 
    @XxlJob("pushJob-pushById")
    public ReturnT<String> pushById(String param) throws Exception {
        if (!StringUtil.isNullOrEmpty(param)) {
            Long id = Long.parseLong(param);
            PushInfo info = pushInfoService.selectByPrimaryKey(id);
            if (info == null)
                return ReturnT.FAIL;
 
            PushInfo update=new PushInfo();
            update.setId(info.getId());
            update.setState(PushInfo.STATE_INIT);
            pushInfoService.updateSelectiveByPrimaryKey(update);
            Thread.sleep(100);
            pushInfoService.handPush(Long.parseLong(param));
        }
        return ReturnT.SUCCESS;
    }
 
 
}