wuxw
2024-01-02 e42df6bfd9cb5d2182c1082fbad5117543bebd53
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
package com.java110.job.msgNotify;
 
import com.alibaba.fastjson.JSONObject;
import com.java110.core.log.LoggerFactory;
import com.java110.job.adapt.Repair.MachineAddOwnerRepairAdapt;
import com.java110.utils.cache.MappingCache;
import com.java110.utils.constant.MappingConstant;
import com.java110.utils.factory.ApplicationContextFactory;
import com.java110.utils.util.StringUtil;
import com.java110.vo.ResultVo;
import org.slf4j.Logger;
 
import java.util.List;
 
/**
 * 消息通知工具类
 */
public class MsgNotifyFactory {
    private static Logger logger = LoggerFactory.getLogger(MsgNotifyFactory.class);
 
    public static final String DEFAULT_MSG_NOTIFY_WAY = "DEFAULT_MSG_NOTIFY_WAY";
 
    public static final String NOTIFY_WAY_WECHAT = "WECHAT";
    public static final String NOTIFY_WAY_ALI = "ALI";
    public static final String NOTIFY_WAY_TENCENT = "TENCENT";
    public static final String ROLE_OWNER = "OWNER"; // 业主
    public static final String ROLE_STAFF = "STAFF"; // 员工
 
 
    /**
     * 发送退费申请 消息
     *
     * @param userId
     * @param content {
     *                detailId:'',
     *                name:''
     *                }
     * @return
     */
    public static ResultVo sendApplyReturnFeeMsg(String communityId, String userId, JSONObject content) {
        ResultVo resultVo = null;
        try {
            IMsgNotify msgNotify = getMsgNotify();
            resultVo = msgNotify.sendApplyReturnFeeMsg(communityId, userId, content);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("通知 申请退费 消息", e);
            resultVo = new ResultVo(ResultVo.CODE_ERROR, e.getMessage());
        }
 
        return resultVo;
    }
 
    /**
     * 发送欠费 账单信息
     *
     * @param communityId 小区
     * @param userId      用户
     * @param contents     [{
     *                    "feeTypeName",
     *                    "payerObjName",
     *                    "billAmountOwed",
     *                    "date",
     *                    url
     *                    }]
     */
    public static ResultVo sendOweFeeMsg(String communityId, String userId, String ownerId, List<JSONObject> contents, String notifyWay) {
        ResultVo resultVo = null;
        try {
            IMsgNotify msgNotify = getMsgNotify(notifyWay);
            resultVo = msgNotify.sendOweFeeMsg(communityId, userId,ownerId, contents);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("通知 发送欠费 账单信息 消息", e);
            resultVo = new ResultVo(ResultVo.CODE_ERROR, e.getMessage());
        }
 
        return resultVo;
    }
 
    /**
     * 发送欠费 账单信息
     *
     * @param communityId 小区
     * @param userId      用户
     * @param contents     [{
     *                    "feeTypeName",
     *                    "payerObjName",
     *                    "billAmountOwed",
     *                    "date",
     *                    url
     *                    }]
     */
    public static ResultVo sendOweFeeMsg(String communityId, String userId,String ownerId, List<JSONObject> contents) {
        return sendOweFeeMsg(communityId,userId, ownerId,contents,null);
    }
 
    /**
     * 发送缴费成功提醒
     *
     * @param communityId 小区
     * @param userId      用户
     * @param content     {
     *                    "payFeeRoom",
     *                    "feeTypeCdName",
     *                    "payFeeTime",
     *                    "receivedAmount",
     *                    url
     *                    }
     */
    public static ResultVo sendPayFeeMsg(String communityId, String userId, JSONObject content, String role) {
        ResultVo resultVo = null;
        try {
            IMsgNotify msgNotify = getMsgNotify();
            resultVo = msgNotify.sendPayFeeMsg(communityId, userId, content, role);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("通知 发送缴费成功提醒 消息", e);
            resultVo = new ResultVo(ResultVo.CODE_ERROR, e.getMessage());
        }
 
        return resultVo;
    }
 
    /**
     * 业主报修时
     *
     * @param communityId 小区
     * @param userId      用户
     * @param content     {
     *                    repairId,
     *                    repairTypeName,
     *                    repairObjName,
     *                    repairName,
     *                    url
     *                    }
     * @return
     */
    public static ResultVo sendAddOwnerRepairMsg(String communityId, String userId, JSONObject content) {
        ResultVo resultVo = null;
        try {
            IMsgNotify msgNotify = getMsgNotify();
            resultVo = msgNotify.sendAddOwnerRepairMsg(communityId, userId, content);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("通知 业主报修时 消息", e);
            resultVo = new ResultVo(ResultVo.CODE_ERROR, e.getMessage());
        }
 
        return resultVo;
    }
 
    /**
     * 派单给维修师傅
     *
     * @param communityId 小区
     * @param userId      用户
     * @param content     {
     *                    repairId,
     *                    repairName,
     *                    tel,
     *                    time,
     *                    address
     *                    }
     * @return
     */
    public static ResultVo sendDistributeRepairStaffMsg(String communityId, String userId, JSONObject content) {
        ResultVo resultVo = null;
        try {
            IMsgNotify msgNotify = getMsgNotify();
            resultVo = msgNotify.sendDistributeRepairStaffMsg(communityId, userId, content);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("通知 派单给维修师傅 消息", e);
            resultVo = new ResultVo(ResultVo.CODE_ERROR, e.getMessage());
        }
 
        return resultVo;
    }
 
    /**
     * 派单给业主通知
     *
     * @param communityId 小区
     * @param userId      用户
     * @param content     {
     *                    name,
     *                    tel,
     *                    time,
     *                    url
     *                    }
     * @return
     */
    public static ResultVo sendDistributeRepairOwnerMsg(String communityId, String userId, JSONObject content) {
        ResultVo resultVo = null;
        try {
            IMsgNotify msgNotify = getMsgNotify();
            resultVo = msgNotify.sendDistributeRepairOwnerMsg(communityId, userId, content);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("通知 派单给维修师傅 消息", e);
            resultVo = new ResultVo(ResultVo.CODE_ERROR, e.getMessage());
        }
 
        return resultVo;
    }
 
    /**
     * 报修完成给业主通知
     *
     * @param communityId 小区
     * @param userId      用户
     * @param content     {
     *                    repairObjName,
     *                    staffName,
     *                    time,
     *                    url
     *                    }
     * @return
     */
    public static ResultVo sendFinishRepairOwnerMsg(String communityId, String userId, JSONObject content) {
        ResultVo resultVo = null;
        try {
            IMsgNotify msgNotify = getMsgNotify();
            resultVo = msgNotify.sendFinishRepairOwnerMsg(communityId, userId, content);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("通知 报修完成给业主通知 消息", e);
            resultVo = new ResultVo(ResultVo.CODE_ERROR, e.getMessage());
        }
 
        return resultVo;
    }
 
 
    /**
     * 退单给业主发送消息
     *
     * @param communityId 小区
     * @param userId      用户
     * @param content     {
     *                    repairId,
     *                    repairTypeName,
     *                    repairObjName,
     *                    repairName,
     *                    url
     *                    }
     * @return
     */
    public static ResultVo sendReturnRepairMsg(String communityId, String userId, JSONObject content) {
        ResultVo resultVo = null;
        try {
            IMsgNotify msgNotify = getMsgNotify();
            resultVo = msgNotify.sendReturnRepairMsg(communityId, userId, content);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("通知 业主报修时 消息", e);
            resultVo = new ResultVo(ResultVo.CODE_ERROR, e.getMessage());
        }
 
        return resultVo;
    }
 
 
    /**
     *  oa 流程待审批通知
     *
     * @param communityId 小区
     * @param userId      用户
     * @param content     {
     *                    flowName,
     *                    create_user_name,
     *                    create_time,
     *                    url
     *                    }
     * @return
     */
    public static ResultVo sendOaDistributeMsg(String communityId, String userId, JSONObject content) {
        ResultVo resultVo = null;
        try {
            IMsgNotify msgNotify = getMsgNotify();
            resultVo = msgNotify.sendOaDistributeMsg(communityId, userId, content);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("通知 业主报修时 消息", e);
            resultVo = new ResultVo(ResultVo.CODE_ERROR, e.getMessage());
        }
 
        return resultVo;
    }
 
    /**
     *  oa 流程通知发起人
     *
     * @param communityId 小区
     * @param userId      用户
     * @param content     {
     *                    flowName,
     *                    staffName,
     *                    url
     *                    }
     * @return
     */
    public static ResultVo sendOaCreateStaffMsg(String communityId, String userId, JSONObject content) {
        ResultVo resultVo = null;
        try {
            IMsgNotify msgNotify = getMsgNotify();
            resultVo = msgNotify.sendOaCreateStaffMsg(communityId, userId, content);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("通知 业主报修时 消息", e);
            resultVo = new ResultVo(ResultVo.CODE_ERROR, e.getMessage());
        }
 
        return resultVo;
    }
 
    /**
     * 获取通知适配器
     *
     * @return
     */
    private static IMsgNotify getMsgNotify() {
        return getMsgNotify(null);
    }
 
 
    /**
     * 获取通知适配器
     *
     * @param notifyWay
     * @return
     */
    public static IMsgNotify getMsgNotify(String notifyWay) {
        IMsgNotify notify = null;
        if (StringUtil.isEmpty(notifyWay)) {
            notifyWay = MappingCache.getValue(MappingConstant.ENV_DOMAIN, DEFAULT_MSG_NOTIFY_WAY);
        }
 
        if (StringUtil.isEmpty(notifyWay)) {
            notifyWay = NOTIFY_WAY_WECHAT;
        }
 
        switch (notifyWay) {
            case NOTIFY_WAY_TENCENT:
                notify = ApplicationContextFactory.getBean("tencentMsgNotifyImpl", IMsgNotify.class);
                break;
            case NOTIFY_WAY_WECHAT:
                notify = ApplicationContextFactory.getBean("wechatMsgNotifyImpl", IMsgNotify.class);
                break;
            case NOTIFY_WAY_ALI:
                notify = ApplicationContextFactory.getBean("aliMsgNotifyImpl", IMsgNotify.class);
                break;
        }
 
        return notify;
    }
}