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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
package com.java110.job.msgNotify.ali;
 
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.java110.core.factory.AliSendMessageFactory;
import com.java110.core.factory.CommunitySettingFactory;
import com.java110.core.factory.LogFactory;
import com.java110.core.log.LoggerFactory;
import com.java110.dto.owner.OwnerDto;
import com.java110.dto.user.StaffAppAuthDto;
import com.java110.dto.user.UserDto;
import com.java110.intf.user.IOwnerV1InnerServiceSMO;
import com.java110.intf.user.IStaffAppAuthInnerServiceSMO;
import com.java110.intf.user.IUserV1InnerServiceSMO;
import com.java110.job.msgNotify.IMsgNotify;
import com.java110.utils.cache.MappingCache;
import com.java110.utils.util.Assert;
import com.java110.utils.util.DateUtil;
import com.java110.utils.util.StringUtil;
import com.java110.vo.ResultVo;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
 
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
 
@Service("aliMsgNotifyImpl")
public class AliMsgNotifyImpl implements IMsgNotify {
    private final static Logger logger = LoggerFactory.getLogger(AliMsgNotifyImpl.class);
    @Autowired
    private IOwnerV1InnerServiceSMO ownerV1InnerServiceSMOImpl;
 
    @Autowired
    private IUserV1InnerServiceSMO userV1InnerServiceSMOImpl;
 
    @Override
    public ResultVo sendApplyReturnFeeMsg(String communityId, String userId, JSONObject content) {
        return null;
    }
 
 
    /**
     * 发送欠费 账单信息
     * <p>
     * 需要在阿里云 申请短信模板为
     * 尊敬的业主,您${house}的账单已生成,缴费金额:${mount}元,请及时缴费
     *
     * @param communityId 小区
     * @param userId      用户
     * @param contents    [{
     *                    "feeTypeName",
     *                    "payerObjName",
     *                    "billAmountOwed",
     *                    "date",
     *                    url
     *                    }]
     * @return
     */
    @Override
    public ResultVo sendOweFeeMsg(String communityId, String userId, String ownerId, List<JSONObject> contents) {
 
 
        if (StringUtil.isEmpty(ownerId) || ownerId.startsWith("-")) {
            throw new IllegalArgumentException("业主不存在,ownerId = " + ownerId);
        }
 
 
        OwnerDto ownerDto = new OwnerDto();
        ownerDto.setMemberId(ownerId);
        ownerDto.setCommunityId(communityId);
        List<OwnerDto> ownerDtos = ownerV1InnerServiceSMOImpl.queryOwners(ownerDto);
 
        Assert.listOnlyOne(ownerDtos, "业主不存在,ownerId = " + ownerId);
 
        String accessKeyId = CommunitySettingFactory.getValue(communityId, "ALI_ACCESS_KEY_ID");
        String accessSecret = CommunitySettingFactory.getValue(communityId, "ALI_ACCESS_SECRET");
        String region = CommunitySettingFactory.getValue(communityId, "ALI_REGION");
        String signName = CommunitySettingFactory.getValue(communityId, "ALI_SIGN_NAME");
        String templateCode = CommunitySettingFactory.getValue(communityId, "ALI_OWE_TEMPLATE_CODE");
        DefaultProfile profile = DefaultProfile.getProfile(region,
                accessKeyId,
                accessSecret);
        IAcsClient client = new DefaultAcsClient(profile);
 
        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");
        request.putQueryParameter("RegionId", region);
        request.putQueryParameter("PhoneNumbers", ownerDtos.get(0).getLink());
        request.putQueryParameter("SignName", signName);
        request.putQueryParameter("TemplateCode", templateCode);
 
        BigDecimal oweFee = new BigDecimal(0);
 
        Date startDate = null;
        Date endDate = null;
        Date tmpStartDate = null;
        Date tmpEndDate = null;
        for (JSONObject content : contents) {
            oweFee = oweFee.add(new BigDecimal(content.getDouble("billAmountOwed"))).setScale(2, BigDecimal.ROUND_HALF_UP);
            tmpStartDate = DateUtil.getDateFromStringB(content.getString("date").split("~")[0]);
            tmpEndDate = DateUtil.getDateFromStringB(content.getString("date").split("~")[1]);
            if (startDate == null) {
                startDate = tmpStartDate;
                endDate = tmpEndDate;
                continue;
            }
            if (startDate.getTime() > tmpStartDate.getTime()) {
                startDate = tmpStartDate;
            }
            if (endDate.getTime() < tmpEndDate.getTime()) {
                endDate = tmpEndDate;
            }
        }
 
        JSONObject param = new JSONObject();
        param.put("house", contents.get(0).getString("payerObjName"));
//        param.put("feeType", content.getString("feeTypeName"));
        param.put("date", DateUtil.getFormatTimeStringB(startDate));
        param.put("date2", DateUtil.getFormatTimeStringB(endDate));
        param.put("mount", oweFee.doubleValue());
        request.putQueryParameter("TemplateParam", param.toString());
 
        String resParam = "";
        try {
            CommonResponse response = client.getCommonResponse(request);
            logger.debug("发送验证码信息:{}", response.getData());
            resParam = response.getData();
        } catch (Exception e) {
            e.printStackTrace();
            resParam = e.getMessage();
            throw new IllegalArgumentException("短信催缴失败" + e.getMessage());
        } finally {
            LogFactory.saveOutLog("SMS", param.toString(), new ResponseEntity(resParam, HttpStatus.OK));
        }
        return new ResultVo(ResultVo.CODE_OK, "成功");
    }
 
    @Override
    public ResultVo sendPayFeeMsg(String communityId, String userId, JSONObject content, String role) {
        return null;
    }
 
    /**
     * 发送内容  尊敬的员工,您有一个报修单需要处理,单号为{repairId},请您及时处理
     *
     * @param communityId 小区
     * @param userId      用户
     * @param content     {
     *                    repairId,
     *                    repairTypeName,
     *                    repairObjName,
     *                    repairName,
     *                    url
     *                    }
     * @return
     */
    @Override
    public ResultVo sendAddOwnerRepairMsg(String communityId, String userId, JSONObject content) {
        if (StringUtil.isEmpty(userId) || userId.startsWith("-")) {
            throw new IllegalArgumentException("员工不存在,userId = " + userId);
        }
 
 
        UserDto userDto = new UserDto();
        userDto.setUserId(userId);
        List<UserDto> userDtos = userV1InnerServiceSMOImpl.queryUsers(userDto);
        if (userDtos == null || userDtos.size() < 1) {
            throw new IllegalArgumentException("员工不存在");
        }
 
 
        String accessKeyId = CommunitySettingFactory.getValue(communityId, "ALI_ACCESS_KEY_ID");
        String accessSecret = CommunitySettingFactory.getValue(communityId, "ALI_ACCESS_SECRET");
        String region = CommunitySettingFactory.getValue(communityId, "ALI_REGION");
        String signName = CommunitySettingFactory.getValue(communityId, "ALI_SIGN_NAME");
        String templateCode = CommunitySettingFactory.getValue(communityId, "ALI_REPAIR_TEMPLATE_CODE");
        DefaultProfile profile = DefaultProfile.getProfile(region,
                accessKeyId,
                accessSecret);
        IAcsClient client = new DefaultAcsClient(profile);
 
        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");
        request.putQueryParameter("RegionId", region);
        request.putQueryParameter("PhoneNumbers", userDtos.get(0).getTel());
        request.putQueryParameter("SignName", signName);
        request.putQueryParameter("TemplateCode", templateCode);
 
 
 
        JSONObject param = new JSONObject();
        param.put("repairId", content.getString("repairId"));
        request.putQueryParameter("TemplateParam", param.toString());
 
        String resParam = "";
        try {
            CommonResponse response = client.getCommonResponse(request);
            logger.debug("发送验证码信息:{}", response.getData());
            resParam = response.getData();
        } catch (Exception e) {
            e.printStackTrace();
            resParam = e.getMessage();
            throw new IllegalArgumentException("短信工单失败" + e.getMessage());
        } finally {
            LogFactory.saveOutLog("SMS", param.toString(), new ResponseEntity(resParam, HttpStatus.OK));
        }
        return new ResultVo(ResultVo.CODE_OK, "成功");
    }
 
    /**
     *  发送内容  尊敬的员工,您有一个报修单需要处理,单号为{repairId},请您及时处理
     * @param communityId 小区
     * @param userId      用户
     * @param content     {
     *                    repairId,
     *                    repairName,
     *                    tel,
     *                    time,
     *                    address
     *                    }
     * @return
     */
    @Override
    public ResultVo sendDistributeRepairStaffMsg(String communityId, String userId, JSONObject content) {
 
        if (StringUtil.isEmpty(userId) || userId.startsWith("-")) {
            throw new IllegalArgumentException("员工不存在,userId = " + userId);
        }
 
 
        UserDto userDto = new UserDto();
        userDto.setUserId(userId);
        List<UserDto> userDtos = userV1InnerServiceSMOImpl.queryUsers(userDto);
        if (userDtos == null || userDtos.size() < 1) {
            throw new IllegalArgumentException("员工不存在");
        }
 
 
        String accessKeyId = CommunitySettingFactory.getValue(communityId, "ALI_ACCESS_KEY_ID");
        String accessSecret = CommunitySettingFactory.getValue(communityId, "ALI_ACCESS_SECRET");
        String region = CommunitySettingFactory.getValue(communityId, "ALI_REGION");
        String signName = CommunitySettingFactory.getValue(communityId, "ALI_SIGN_NAME");
        String templateCode = CommunitySettingFactory.getValue(communityId, "ALI_REPAIR_TEMPLATE_CODE");
        DefaultProfile profile = DefaultProfile.getProfile(region,
                accessKeyId,
                accessSecret);
        IAcsClient client = new DefaultAcsClient(profile);
 
        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");
        request.putQueryParameter("RegionId", region);
        request.putQueryParameter("PhoneNumbers", userDtos.get(0).getTel());
        request.putQueryParameter("SignName", signName);
        request.putQueryParameter("TemplateCode", templateCode);
 
        JSONObject param = new JSONObject();
        param.put("repairId", content.getString("repairId"));
        request.putQueryParameter("TemplateParam", param.toString());
 
        String resParam = "";
        try {
            CommonResponse response = client.getCommonResponse(request);
            logger.debug("发送验证码信息:{}", response.getData());
            resParam = response.getData();
        } catch (Exception e) {
            e.printStackTrace();
            resParam = e.getMessage();
            throw new IllegalArgumentException("短信工单失败" + e.getMessage());
        } finally {
            LogFactory.saveOutLog("SMS", param.toString(), new ResponseEntity(resParam, HttpStatus.OK));
        }
        return new ResultVo(ResultVo.CODE_OK, "成功");
    }
 
    @Override
    public ResultVo sendDistributeRepairOwnerMsg(String communityId, String userId, JSONObject content) {
 
        return new ResultVo(ResultVo.CODE_OK,"成功");
 
    }
 
    @Override
    public ResultVo sendFinishRepairOwnerMsg(String communityId, String userId, JSONObject content) {
 
        return new ResultVo(ResultVo.CODE_OK,"成功");
    }
 
    /**
     *
     * @param communityId 小区
     * @param userId      用户
     * @param content     {
     *                    repairTypeName,
     *                    repairObjName,
     *                    repairName,
     *                    url
     *                    }
     * @return
     */
    @Override
    public ResultVo sendReturnRepairMsg(String communityId, String userId, JSONObject content) {
        if (StringUtil.isEmpty(userId) || userId.startsWith("-")) {
            throw new IllegalArgumentException("员工不存在,userId = " + userId);
        }
 
        UserDto userDto = new UserDto();
        userDto.setUserId(userId);
        List<UserDto> userDtos = userV1InnerServiceSMOImpl.queryUsers(userDto);
        if (userDtos == null || userDtos.size() < 1) {
            throw new IllegalArgumentException("员工不存在");
        }
 
 
        String accessKeyId = CommunitySettingFactory.getValue(communityId, "ALI_ACCESS_KEY_ID");
        String accessSecret = CommunitySettingFactory.getValue(communityId, "ALI_ACCESS_SECRET");
        String region = CommunitySettingFactory.getValue(communityId, "ALI_REGION");
        String signName = CommunitySettingFactory.getValue(communityId, "ALI_SIGN_NAME");
        String templateCode = CommunitySettingFactory.getValue(communityId, "ALI_REPAIR_TEMPLATE_CODE");
        DefaultProfile profile = DefaultProfile.getProfile(region,
                accessKeyId,
                accessSecret);
        IAcsClient client = new DefaultAcsClient(profile);
 
        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");
        request.putQueryParameter("RegionId", region);
        request.putQueryParameter("PhoneNumbers", userDtos.get(0).getTel());
        request.putQueryParameter("SignName", signName);
        request.putQueryParameter("TemplateCode", templateCode);
 
 
        JSONObject param = new JSONObject();
        param.put("repairId", content.getString("repairId"));
        request.putQueryParameter("TemplateParam", param.toString());
 
        String resParam = "";
        try {
            CommonResponse response = client.getCommonResponse(request);
            logger.debug("发送验证码信息:{}", response.getData());
            resParam = response.getData();
        } catch (Exception e) {
            e.printStackTrace();
            resParam = e.getMessage();
            throw new IllegalArgumentException("短信工单失败" + e.getMessage());
        } finally {
            LogFactory.saveOutLog("SMS", param.toString(), new ResponseEntity(resParam, HttpStatus.OK));
        }
        return new ResultVo(ResultVo.CODE_OK, "成功");
    }
 
    /**
     * 待处理
     * @param communityId 小区
     * @param userId      用户
     * @param content     {
     *                    flowName,
     *                    create_user_name,
     *                    create_time,
     *                    url
     *                    }
     * @return
     */
    @Override
    public ResultVo sendOaDistributeMsg(String communityId, String userId, JSONObject content) {
        if (StringUtil.isEmpty(userId) || userId.startsWith("-")) {
            throw new IllegalArgumentException("员工不存在,userId = " + userId);
        }
 
 
        UserDto userDto = new UserDto();
        userDto.setUserId(userId);
        List<UserDto> userDtos = userV1InnerServiceSMOImpl.queryUsers(userDto);
        if (userDtos == null || userDtos.size() < 1) {
            throw new IllegalArgumentException("员工不存在");
        }
 
 
        String accessKeyId = CommunitySettingFactory.getValue(communityId, "ALI_ACCESS_KEY_ID");
        String accessSecret = CommunitySettingFactory.getValue(communityId, "ALI_ACCESS_SECRET");
        String region = CommunitySettingFactory.getValue(communityId, "ALI_REGION");
        String signName = CommunitySettingFactory.getValue(communityId, "ALI_SIGN_NAME");
        String templateCode = CommunitySettingFactory.getValue(communityId, "ALI_OA_UNDO_TEMPLATE_CODE");
        DefaultProfile profile = DefaultProfile.getProfile(region,
                accessKeyId,
                accessSecret);
        IAcsClient client = new DefaultAcsClient(profile);
 
        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");
        request.putQueryParameter("RegionId", region);
        request.putQueryParameter("PhoneNumbers", userDtos.get(0).getTel());
        request.putQueryParameter("SignName", signName);
        request.putQueryParameter("TemplateCode", templateCode);
 
 
        JSONObject param = new JSONObject();
        param.put("orderId", content.getString("orderId"));
        request.putQueryParameter("TemplateParam", param.toString());
 
        String resParam = "";
        try {
            CommonResponse response = client.getCommonResponse(request);
            logger.debug("发送验证码信息:{}", response.getData());
            resParam = response.getData();
        } catch (Exception e) {
            e.printStackTrace();
            resParam = e.getMessage();
            throw new IllegalArgumentException("短信工单失败" + e.getMessage());
        } finally {
            LogFactory.saveOutLog("SMS", param.toString(), new ResponseEntity(resParam, HttpStatus.OK));
        }
        return new ResultVo(ResultVo.CODE_OK, "成功");
    }
 
    @Override
    public ResultVo sendOaCreateStaffMsg(String communityId, String userId, JSONObject content) {
 
        if (StringUtil.isEmpty(userId) || userId.startsWith("-")) {
            throw new IllegalArgumentException("员工不存在,userId = " + userId);
        }
 
 
        UserDto userDto = new UserDto();
        userDto.setUserId(userId);
        List<UserDto> userDtos = userV1InnerServiceSMOImpl.queryUsers(userDto);
        if (userDtos == null || userDtos.size() < 1) {
            throw new IllegalArgumentException("员工不存在");
        }
 
 
        String accessKeyId = CommunitySettingFactory.getValue(communityId, "ALI_ACCESS_KEY_ID");
        String accessSecret = CommunitySettingFactory.getValue(communityId, "ALI_ACCESS_SECRET");
        String region = CommunitySettingFactory.getValue(communityId, "ALI_REGION");
        String signName = CommunitySettingFactory.getValue(communityId, "ALI_SIGN_NAME");
        String templateCode = CommunitySettingFactory.getValue(communityId, "ALI_OA_FINISH_TEMPLATE_CODE");
        DefaultProfile profile = DefaultProfile.getProfile(region,
                accessKeyId,
                accessSecret);
        IAcsClient client = new DefaultAcsClient(profile);
 
        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");
        request.putQueryParameter("RegionId", region);
        request.putQueryParameter("PhoneNumbers", userDtos.get(0).getTel());
        request.putQueryParameter("SignName", signName);
        request.putQueryParameter("TemplateCode", templateCode);
 
 
        JSONObject param = new JSONObject();
        param.put("orderId", content.getString("orderId"));
        request.putQueryParameter("TemplateParam", param.toString());
 
        String resParam = "";
        try {
            CommonResponse response = client.getCommonResponse(request);
            logger.debug("发送验证码信息:{}", response.getData());
            resParam = response.getData();
        } catch (Exception e) {
            e.printStackTrace();
            resParam = e.getMessage();
            throw new IllegalArgumentException("短信工单失败" + e.getMessage());
        } finally {
            LogFactory.saveOutLog("SMS", param.toString(), new ResponseEntity(resParam, HttpStatus.OK));
        }
        return new ResultVo(ResultVo.CODE_OK, "成功");
    }
}