admin
2018-12-15 6a4d58a65e916323b1ea11b36b27e47943482f18
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package com.yeshi.fanli.service.impl.push;
 
import javax.annotation.Resource;
 
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
 
import com.yeshi.fanli.controller.admin.PushController;
import com.yeshi.fanli.dao.mybatis.AccountMessageMapper;
import com.yeshi.fanli.dao.mybatis.push.PushRecordMapper;
import com.yeshi.fanli.entity.bus.user.AccountMessage;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.entity.system.SystemZnx;
import com.yeshi.fanli.entity.xinge.PushRecord;
import com.yeshi.fanli.exception.PushException;
import com.yeshi.fanli.service.inter.push.DeviceTokenHWService;
import com.yeshi.fanli.service.inter.push.HWPushService;
import com.yeshi.fanli.service.inter.push.IOSPushService;
import com.yeshi.fanli.service.inter.push.PushRecordService;
import com.yeshi.fanli.service.inter.push.PushService;
import com.yeshi.fanli.service.inter.push.XMPushService;
import com.yeshi.fanli.service.inter.user.AccountMessageService;
import com.yeshi.fanli.service.inter.user.SystemZnxService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
 
@Service
public class PushServiceImpl implements PushService {
 
    static String IOSBundleId = "";
    static String PROJECT_NAME = "";
 
    static {
        IOSBundleId = Constant.systemCommonConfig.getIosBundleId();
        PROJECT_NAME = Constant.systemCommonConfig.getProjectChineseName();
    }
 
    @Resource
    private PushRecordService pushRecordService;
 
    @Resource
    private SystemZnxService systemZnxService;
 
    @Resource
    private AccountMessageService accountMessageService;
 
    @Resource
    private DeviceTokenHWService deviceTokenHWService;
 
    @Resource
    private IOSPushService iosPushService;
 
    @Resource
    private HWPushService hwPushService;
 
    @Resource
    private XMPushService xmPushService;
 
    @Resource
    private PushRecordMapper pushRecordMapper;
 
    @Resource
    private AccountMessageMapper accountMessageMapper;
 
    @Async("pushExecutor")
    @Override
    public void pushGoods(Long uid, String url, String title, String content) throws PushException {
        String gids = url.split("id=")[1];
        String gid = gids.split("&")[0];
        if (StringUtil.isNullOrEmpty(gid))
            throw new PushException(1, "商品解析失败");
        if (StringUtil.isNullOrEmpty(title))
            throw new PushException(1, "请填写推送标题");
        if (StringUtil.isNullOrEmpty(content))
            throw new PushException(1, "请填写推送内容");
 
        PushRecord pushRecord = new PushRecord();
        pushRecord.setState(1);
        pushRecord.setType(PushController.GOODS); // 都成功
        pushRecord.setUrl(url);
        pushRecord.setTitle(title);
        pushRecord.setAppName(Constant.systemCommonConfig.getProjectChineseName());
        pushRecord.setAccount(1);
 
        xmPushService.pushGoods(uid, Long.parseLong(gid), title, content);
        iosPushService.pushGoods(uid, Long.parseLong(gid), title, content);
        // hwPushService.pushGoods(uid, Long.parseLong(gid), title, content);
 
        pushRecordMapper.insertSelective(pushRecord);
    }
 
    @Async("pushExecutor")
    @Override
    public void pushUrl(Long uid, String url, String title, String content) throws PushException {
 
        if (StringUtil.isNullOrEmpty(url))
            throw new PushException(1, "无推送链接");
        if (StringUtil.isNullOrEmpty(title))
            throw new PushException(1, "无推送标题");
        if (StringUtil.isNullOrEmpty(content))
            throw new PushException(1, "无推送内容");
 
        PushRecord pushRecord = new PushRecord();
        pushRecord.setState(1);
        pushRecord.setType(PushController.URL);
        pushRecord.setUrl(url);
        pushRecord.setTitle(title);
        pushRecord.setAppName(Constant.systemCommonConfig.getProjectChineseName());
 
        xmPushService.pushUrl(uid, url, title, content);
        iosPushService.pushUrl(uid, url, title, content);
        hwPushService.pushUrl(uid, url, title, content);
        pushRecordMapper.insertSelective(pushRecord);
    }
 
    @Async("pushExecutor")
    @Override
    public void pushZNX(Long uId, String title, String content) throws PushException {
        if (StringUtil.isNullOrEmpty(title))
            throw new PushException(1, "无推送标题");
        if (StringUtil.isNullOrEmpty(content))
            throw new PushException(1, "无推送内容");
 
        /* 无uid , 广播 数据插入系统表 */
        if (uId == null || uId == 0) {
            // 插入数据库(系统站内信数据)
            SystemZnx systemZnx = new SystemZnx();
            systemZnx.setTitle(title);
            systemZnx.setContent(content);
            systemZnx.setCreateTime(System.currentTimeMillis());
            systemZnxService.save(systemZnx);
 
            PushRecord pushRecord = new PushRecord();
            pushRecord.setTitle(title);
            pushRecord.setState(1); // 成功
            pushRecord.setType(4); // 类型:站内信
            pushRecord.setAppName(Constant.systemCommonConfig.getProjectChineseName());
            xmPushService.pushZNX(uId, null, systemZnx);
            iosPushService.pushZNX(uId, null, systemZnx);
            hwPushService.pushZNX(uId, null, systemZnx);
            // 插入推送记录
            pushRecordMapper.insertSelective(pushRecord);
        } else {
            AccountMessage accountMessage = new AccountMessage();
            accountMessage.setCreateTime(System.currentTimeMillis());
            accountMessage.setIsOpen(false);
            accountMessage.setUserInfo(new UserInfo(uId));
            accountMessage.setTitle(title);
            accountMessage.setContent(content);
            accountMessageMapper.insertSelective(accountMessage);
 
            xmPushService.pushZNX(uId, accountMessage, null);
            iosPushService.pushZNX(uId, accountMessage, null);
            hwPushService.pushZNX(uId, accountMessage, null);
 
            // 插入推送记录
            PushRecord pushRecord = new PushRecord();
            pushRecord.setTitle(title);
            pushRecord.setUid(uId);
            pushRecord.setState(1); // 成功
            pushRecord.setType(PushController.ZNX); // 类型:站内信
            pushRecord.setAppName(Constant.systemCommonConfig.getProjectChineseName());
            pushRecordMapper.insertSelective(pushRecord);
        }
    }
 
    @Override
    public void pushWEEX(Long uid, String title, String content, String weexUrl) throws PushException {
        if (StringUtil.isNullOrEmpty(title))
            throw new PushException(1, "无推送标题");
        if (StringUtil.isNullOrEmpty(content))
            throw new PushException(1, "无推送内容");
        iosPushService.pushWEEX(uid, title, content, weexUrl);
    }
 
    @Override
    public void pushBaiChuanUrl(Long uid, String title, String content, String url) throws PushException {
        iosPushService.pushBaiChuanUrl(uid, title, content, url);
    }
 
}