88e030b7
王彪总
init project
|
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
|
CommunityDto communityDto = new CommunityDto();
communityDto.setCommunityId(communityId);
List<CommunityDto> communityDtos = communityInnerServiceSMO.queryCommunitys(communityDto);
//todo 转单
if (RepairDto.STATE_TRANSFER.equals(repairState)) {
JSONObject paramIn = new JSONObject();
paramIn.put("repairName", repairName);
paramIn.put("repairObjName", repairObjName);
paramIn.put("tel", tel);
paramIn.put("context", context);
paramIn.put("time", time);
paramIn.put("staffId", businessRepairUser.getString("staffId"));
paramIn.put("preStaffName", businessRepairUser.getString("preStaffName"));
paramIn.put("repairId", repairId);
//给维修师傅推送信息
sendStaffMsg(paramIn, communityDtos.get(0), msgNotify);
return;
}
//todo 不是结单跳过
if (!RepairDto.STATE_TAKING.equals(repairState)) {
return;
}
//todo 派单只打印小票
if (RepairUserDto.STATE_DISPATCH.equals(businessRepairUser.getString("state"))) { //派单
// 自动打印小票
autoPrintRepair(repairUserDtos.get(0).getRuId(), repairDtos.get(0).getRepairType(), communityDtos.get(0));
return;
}
JSONObject paramIn = new JSONObject();
paramIn.put("staffId", businessRepairUser.getString("staffId"));
paramIn.put("context", context);
paramIn.put("time", time);
paramIn.put("repairObjId", repairObjId);
paramIn.put("preStaffId", businessRepairUser.getString("preStaffId"));
paramIn.put("repairName", repairName);
paramIn.put("tel", tel);
paramIn.put("repairObjName", repairObjName);
paramIn.put("repairId", repairId);
//抢单成功给维修师傅推送信息
sendStaffMsg(paramIn, communityDtos.get(0), msgNotify);
//抢单成功给业主推送信息
sendOwnerMsg(paramIn, communityDtos.get(0), msgNotify);
//为企业微信群发消息
sendMsgToWechatGroup(paramIn, communityDtos.get(0));
}
/**
* 派单给维修师傅推送信息
*
* @param paramIn
* @param communityDto
*/
private void sendStaffMsg(JSONObject paramIn, CommunityDto communityDto, IMsgNotify msgNotify) {
JSONObject content = new JSONObject();
content.put("repairId", paramIn.getString("repairId"));
content.put("repairName", paramIn.getString("repairName"));
content.put("tel", paramIn.getString("tel"));
content.put("time", paramIn.getString("time"));
String wechatUrl = MappingCache.getValue(MappingConstant.URL_DOMAIN, "STAFF_WECHAT_URL");
content.put("url", wechatUrl);
//获取具体位置
String address = "";
if (communityDto.getName().equals(paramIn.getString("repairObjName"))) {
address = paramIn.getString("repairObjName");
} else {
address = communityDto.getName() + paramIn.getString("repairObjName");
}
content.put("address", address);
msgNotify.sendDistributeRepairStaffMsg(communityDto.getCommunityId(), paramIn.getString("staffId"), content);
}
/**
* 派单(抢单)成功后给业主推送信息
*
* @param paramIn
* @param communityDto
*/
private void sendOwnerMsg(JSONObject paramIn, CommunityDto communityDto, IMsgNotify msgNotify) {
//查询公众号配置
SmallWeChatDto smallWeChatDto = new SmallWeChatDto();
smallWeChatDto.setWeChatType("1100");
smallWeChatDto.setObjType(SmallWeChatDto.OBJ_TYPE_COMMUNITY);
smallWeChatDto.setObjId(communityDto.getCommunityId());
List<SmallWeChatDto> smallWeChatDtos = smallWeChatInnerServiceSMOImpl.querySmallWeChats(smallWeChatDto);
if (ListUtil.isNull(smallWeChatDtos)) {
logger.info("未配置微信公众号信息,定时任务执行结束");
return;
}
//查询维修员工信息
UserDto userDto = new UserDto();
userDto.setUserId(paramIn.getString("staffId"));
userDto.setStatusCd("0");
List<UserDto> users = userInnerServiceSMO.getUsers(userDto);
//获取维修员工姓名
String name = users.get(0).getName();
//获取维修员工联系方式
String tel = users.get(0).getTel();
//获取用户id
String preStaffId = paramIn.getString("preStaffId");
if (StringUtil.isEmpty(preStaffId)) {
return;
}
JSONObject content = new JSONObject();
content.put("name", name);
content.put("tel", tel);
content.put("time", paramIn.getString("time"));
String wechatUrl = UrlCache.getOwnerUrl();
if (!StringUtil.isEmpty(wechatUrl) && wechatUrl.contains("?")) {
wechatUrl += ("&wAppId=" + smallWeChatDtos.get(0).getAppId());
} else {
wechatUrl += ("?wAppId=" + smallWeChatDtos.get(0).getAppId());
}
content.put("url", wechatUrl);
msgNotify.sendDistributeRepairOwnerMsg(communityDto.getCommunityId(), preStaffId, content);
}
private void sendMsgToWechatGroup(JSONObject paramIn, CommunityDto communityDto) {
//查询公众号配置
String url = CommunitySettingFactory.getRemark(communityDto.getCommunityId(), "WECHAT_SEND_REPAIR_URL");
if (StringUtil.isEmpty(url)) {
return;
}
JSONObject rebootParam = new JSONObject();
rebootParam.put("msgtype", "markdown");
JSONObject rebootMarkdown = new JSONObject();
rebootParam.put("markdown", rebootMarkdown);
//获取具体位置
String address = "";
if (communityDto.getName().equals(paramIn.getString("repairObjName"))) {
address = paramIn.getString("repairObjName");
} else {
address = communityDto.getName() + paramIn.getString("repairObjName");
}
//根据 userId 查询到openId
UserDto userDto = new UserDto();
userDto.setUserId(paramIn.getString("staffId"));
List<UserDto> userDtos = userInnerServiceSMO.getUsers(userDto);
String staffName = "";
if (userDtos != null && userDtos.size() > 0) {
staffName = userDtos.get(0).getName();
}
String content = staffName + " 您有新的维修任务,维修信息如下:\n";
content += ("> 标题:<font color=\"comment\">" + paramIn.getString("repairName") + "</font> \n");
content += ("> 电话:<font color=\"comment\">" + paramIn.getString("tel") + "</font> \n");
content += ("> 时间:<font color=\"comment\">" + paramIn.getString("time") + "</font> \n");
content += ("> 内容:<font color=\"comment\">" + paramIn.getString("context") + "</font> \n");
content += ("> 位置:<font color=\"comment\">" + address + "</font> \n");
content += ("> 单号:<font color=\"comment\">" + paramIn.getString("repairId") + "</font> \n");
rebootMarkdown.put("content", content);
logger.info("发送消息内容:{}", content);
ResponseEntity<String> responseEntity = outRestTemplate.postForEntity(url, rebootParam.toJSONString(), String.class);
logger.info("企业微信返回内容:{}", responseEntity);
if (responseEntity.getStatusCode() != HttpStatus.OK) {
return;
}
String imgUrl = MappingCache.getValue(MappingConstant.FILE_DOMAIN, "IMG_PATH");
FileRelDto fileRelDto = new FileRelDto();
fileRelDto.setObjId(paramIn.getString("repairId"));
List<FileRelDto> fileRelDtos = fileRelInnerServiceSMOImpl.queryFileRels(fileRelDto);
if (fileRelDtos == null || fileRelDtos.size() < 1) {
return;
}
rebootParam = JSONObject.parseObject(" {\n" +
" \"msgtype\":\"image\",\n" +
" \"image\":{\n" +
" }\n" +
" }");
JSONObject image = rebootParam.getJSONObject("image");
String imageUrl = "";
for (FileRelDto tmpFileRelDto : fileRelDtos) {
if (!tmpFileRelDto.getRelTypeCd().equals(FileRelDto.REL_TYPE_CD_REPAIR)) { //维修图片
continue;
}
imageUrl = imgUrl + tmpFileRelDto.getFileRealName();
image.put("base64", ImageUtils.getBase64ByImgUrl(imageUrl));
image.put("md5", ImageUtils.getMd5ByImgUrl(imageUrl));
responseEntity = outRestTemplate.postForEntity(url, rebootParam.toJSONString(), String.class);
logger.debug("返回信息:" + responseEntity);
}
}
/**
* // 自动打印小票
*
* @param ruId
* @param repairType
* @param communityDto
*/
private void autoPrintRepair(String ruId, String repairType, CommunityDto communityDto) {
PrinterRuleRepairDto printerRuleRepairDto = new PrinterRuleRepairDto();
printerRuleRepairDto.setCommunityId(communityDto.getCommunityId());
printerRuleRepairDto.setRepairType(repairType);
List<PrinterRuleRepairDto> printerRuleRepairDtos = printerRuleRepairV1InnerServiceSMOImpl.queryPrinterRuleRepairs(printerRuleRepairDto);
if (printerRuleRepairDtos == null || printerRuleRepairDtos.size() < 1) {
return;
}
PrinterRuleDto printerRuleDto = new PrinterRuleDto();
printerRuleDto.setRuleId(printerRuleRepairDtos.get(0).getRuleId());
printerRuleDto.setCommunityId(communityDto.getCommunityId());
printerRuleDto.setState(PrinterRuleDto.STATE_NORMAL);
int count = printerRuleV1InnerServiceSMOImpl.queryPrinterRulesCount(printerRuleDto);
if (count < 1) {
return;
}
PrinterRuleMachineDto printerRuleMachineDto = new PrinterRuleMachineDto();
printerRuleMachineDto.setCommunityId(communityDto.getCommunityId());
printerRuleMachineDto.setRuleId(printerRuleRepairDtos.get(0).getRuleId());
List<PrinterRuleMachineDto> printerRuleMachineDtos = printerRuleMachineV1InnerServiceSMOImpl.queryPrinterRuleMachines(printerRuleMachineDto);
if (printerRuleMachineDtos == null || printerRuleMachineDtos.size() < 1) {
return;
}
for (PrinterRuleMachineDto tmpPrinterRuleMachineDto : printerRuleMachineDtos) {
try {
doPrint(tmpPrinterRuleMachineDto, ruId);
} catch (Exception e) {
e.printStackTrace();
}
}
}
private void doPrint(PrinterRuleMachineDto tmpPrinterRuleMachineDto, String ruId) {
MachinePrinterDto machinePrinterDto = new MachinePrinterDto();
machinePrinterDto.setCommunityId(tmpPrinterRuleMachineDto.getCommunityId());
machinePrinterDto.setMachineId(tmpPrinterRuleMachineDto.getMachineId());
List<MachinePrinterDto> machinePrinterDtos = machinePrinterV1InnerServiceSMOImpl.queryMachinePrinters(machinePrinterDto);
Assert.listOnlyOne(machinePrinterDtos, "云打印机不存在");
IPrinter printer = ApplicationContextFactory.getBean(machinePrinterDtos.get(0).getImplBean(), IPrinter.class);
if (printer == null) {
throw new CmdException("打印机异常,未包含适配器");
}
printer.printRepair(ruId, tmpPrinterRuleMachineDto.getCommunityId(), Integer.parseInt(tmpPrinterRuleMachineDto.getQuantity()), machinePrinterDtos.get(0));
}
}
|