puzhibing
2023-08-01 98bc380ae322eaac2ee7e21d0c565e30eacce2b5
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
package com.stylefeng.guns.modular.system.util.task.jobs;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.core.util.SinataUtil;
import com.stylefeng.guns.modular.system.model.TDriver;
import com.stylefeng.guns.modular.system.model.TNotices;
import com.stylefeng.guns.modular.system.model.TSystemNotice;
import com.stylefeng.guns.modular.system.model.TUser;
import com.stylefeng.guns.modular.system.util.JpushUtil;
import com.stylefeng.guns.modular.system.util.task.base.AbstractJob;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
 
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * 添加公告记录
 */
public class AddNotice extends AbstractJob {
 
    public static final String name = "addNoticeJob";
 
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        JobDataMap maps = context.getMergedJobDataMap();
        Integer noticeId = maps.getIntValue("noticeId");
 
        try {
            System.out.println("----定时1秒后生成公告记录-----");
            TNotices tNotices = tNoticesService.selectById(noticeId);
            if (SinataUtil.isNotEmpty(tNotices)){
                if (tNotices.getIsUser() == 2){
                    List<TUser> tUsers = tUserService.selectList(new EntityWrapper<TUser>().eq("state",1));
                    //发送公告给用户
                    for (TUser user : tUsers){
                        TSystemNotice notice = new TSystemNotice();
                        notice.setType(1);
                        notice.setUserType(1);
                        notice.setNoticesId(noticeId);
                        notice.setContent(tNotices.getContent());
                        notice.setUserId(user.getId());
                        notice.setInsertTime(new Date());
                        notice.setRead(1);
                        tSystemNoticeService.insert(notice);
 
                    /*Map<String,Object> map = new HashMap<String,Object>();
                    map.put("sound", userInfo.getIsVoice());   //是否有声音  1=否 2=是
                    map.put("vibrate", userInfo.getIsShake()); //是否有震动  1=否 2=是
                    map.put("type", 2);    //消息类型 1=互动  2=公告
                    map.put("id", record.getId()); //对象ID
                    JpushUtil.SendPushWithCustomForTransmission(String.valueOf(userInfo.getId()),"【超级过客】提醒您,您有一条新的公告消息。","通知消息",map);*/
                    }
                }
                if (tNotices.getIsDriver() == 2){
                    List<TDriver> tDrivers = tDriverService.selectList(new EntityWrapper<TDriver>().eq("authState",2));
                    //发送公告给用户
                    for (TDriver driver : tDrivers){
                        TSystemNotice notice = new TSystemNotice();
                        notice.setType(1);
                        notice.setUserType(2);
                        notice.setNoticesId(noticeId);
                        notice.setContent(tNotices.getContent());
                        notice.setUserId(driver.getId());
                        notice.setInsertTime(new Date());
                        notice.setRead(1);
                        tSystemNoticeService.insert(notice);
 
                        /*Map<String,Object> map = new HashMap<String,Object>();
                        map.put("sound", userInfo.getIsVoice());   //是否有声音  1=否 2=是
                        map.put("vibrate", userInfo.getIsShake()); //是否有震动  1=否 2=是
                        map.put("type", 2);    //消息类型 1=互动  2=公告
                        map.put("id", record.getId()); //对象ID
                        JpushUtil.SendPushWithCustomForTransmission(String.valueOf(userInfo.getId()),"【超级过客】提醒您,您有一条新的公告消息。","通知消息",map);*/
 
                        if (tNotices.getIsBroadcast() == 1){
                            //增加极光推送
                            JpushUtil.SendPushWithCustomForSh("DRIVER"+driver.getId().toString(),tNotices.getTitle(),"通知消息",null);
                        }
 
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}