MerchantService.java
33.6 KB
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
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
package cn.com.glsx.entmicro.service;
import cn.com.glsx.entmicro.Enum.BusinessExceptionEnum;
import cn.com.glsx.entmicro.constants.Constants;
import cn.com.glsx.entmicro.constants.RedisCacheKeyPreConstants;
import cn.com.glsx.entmicro.entity.EntmicroStaff;
import cn.com.glsx.entmicro.model.*;
import cn.com.glsx.entmicro.model.request.EntmicroAuthorizeRequest;
import cn.com.glsx.entmicro.model.request.FindMerchantByPageRequest;
import cn.com.glsx.entmicro.model.response.DictDataResponse;
import cn.com.glsx.entmicro.model.response.EntmicroStaffResponse;
import cn.com.glsx.entmicro.model.response.FindMerchantByPageResponse;
import cn.com.glsx.entmicro.model.response.StaffDetailResponse;
import cn.com.glsx.entmicro.model.response.dj.ListYqAndShopRopResponse;
import cn.com.glsx.entmicro.model.response.subscribe.SubscribeMerchantResponse;
import cn.com.glsx.entmicro.service.cache.RedisCacheService;
import cn.com.glsx.entmicro.util.ListUtils;
import cn.com.glsx.entmicro.util.RopDJHttpUtil;
import cn.com.glsx.entmicro.util.RopHttpUtil;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.framework.core.util.RpcAssert;
import cn.com.glsx.scrm.proxy.dto.merchant.ListMerchantRequest;
import cn.com.glsx.scrm.proxy.model.merchant.response.MerchantTreeOpenResponse;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.nacos.client.naming.utils.CollectionUtils;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.Page;
import com.glsx.plat.common.utils.DateUtils;
import com.glsx.plat.common.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.rpc.RpcException;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author zhouhaibao
* @version 1.0
* @description: 商户服务
* @date 2021/9/24 14:34
*/
@Service
@Slf4j
public class MerchantService {
@Value("${merchant.baseurl}")
private String baseurl;
@Value("${merchant.relevanceMerchantMethod}")
private String relevanceMerchantMethod;
@Value("${merchant.syncEntmicroStaffMethod}")
private String syncEntmicroStaffMethod;
@Value("${merchant.findAllDictDataMethod}")
private String findAllDictDataMethod;
@Value("${merchant.findMerchantDetailByMerchantNoMethod}")
private String findMerchantDetailByMerchantNoMethod;
@Value("${merchant.findSubordinateListByPageMethod}")
private String findSubordinateListByPageMethod;
@Value("merchants.api.open.findUserById")
private String findByCreatedBy;
@Value("${merchant.updateMerchantByMerchantNo}")
private String updateMerchantByMerchantNo;
@Value("merchants.api.open.findSuperiorList")
private String findSuperiorList;
@Value("merchants.api.open.findSuperlativeMerchant")
private String findSuperlativeMerchant;
@Value("${merchant.findJoinEntMicroStaffByMerchantNo}")
private String findJoinEntMicroStaffByMerchantNo;
@Value("${merchant.findMerchantListMethod}")
private String findMerchantListMethod;
@Value("${merchant.findMerchantListByModelMethod}")
private String findMerchantListByModelMethod;
@Value("${merchant.merchantNoListByStaffPhone}")
private String merchantNoListByStaffPhone;
@Value("${merchant.findMerchantByPageMethod}")
private String findMerchantByPageMethod;
@Value("${merchant.findStaffListByMerchantNo}")
private String findStaffListByMerchantNoMethod;
@Value("${merchant.findMerchantStaffMethod}")
private String findMerchantStaffMethod;
@Autowired
private EntmicroStaffService entmicroStaffService;
@Autowired
private Environment environment;
@Autowired
private RedisCacheService redisCacheService;
@Value("${dj.baseurl}")
private String djBaseUrl;
@Value("${merchant.findMerchantTreeByMerchantNoMethod}")
private String findMerchantTreeByMerchantNoMethod;
public List<StaffDetailResponse> staffDetailByMerchantId(Integer merchantId) {
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>(4);
params.set("merchantNo", merchantId + "");
List<StaffDetailResponse> responseList = new ArrayList<>();
try {
RopResponse response = RopHttpUtil.post(params, RopResponse.class, baseurl, findStaffListByMerchantNoMethod);
if (("0").equals(response.getCode())) {
String data = JSONObject.toJSONString(response.getData(), SerializerFeature.WriteMapNullValue);
log.info("查询员工详情,{}", data);
responseList = JSONObject.parseArray(data, StaffDetailResponse.class);
responseList.forEach(v -> v.setMerchantNo(merchantId));
}
} catch (Exception e) {
e.printStackTrace();
log.info("查询员工详情异常,{}", e);
throw new RpcServiceException(BusinessExceptionEnum.AUTHORIZE_ENTMICRO_FAIL.getValue(), BusinessExceptionEnum.AUTHORIZE_ENTMICRO_FAIL.getDisplayName());
}
return responseList;
}
/**
* 企微授权
*
* @param entmicroAuthorizeRequest 企微授权
*/
public void authorizeEntmicro(EntmicroAuthorizeRequest entmicroAuthorizeRequest) {
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>(4);
params.set("merchantId", entmicroAuthorizeRequest.getMerchantId() + "");
params.set("entmicroId", entmicroAuthorizeRequest.getEntmicroId());
params.set("entmicroName", entmicroAuthorizeRequest.getEntmicroName());
try {
RopHttpUtil.post(params, Object.class, baseurl, relevanceMerchantMethod);
} catch (Exception e) {
e.printStackTrace();
log.info("同步员工账号异常,{}", e);
throw new RpcServiceException(BusinessExceptionEnum.AUTHORIZE_ENTMICRO_FAIL.getValue(), BusinessExceptionEnum.AUTHORIZE_ENTMICRO_FAIL.getDisplayName());
}
}
/**
* 同步员工账号
*
* @param entmicroStaff 员工
*/
public void syncEntmicroStaff(List<EntmicroStaff> entmicroStaff) {
List<MerchantStaffModel> entmicroStaffList = new ArrayList<>();
List<Map<String, Object>> collect = entmicroStaff.stream().map(index -> {
Map<String, Object> map = new HashMap<>();
map.put("staffName", index.getStaffName());
map.put("entmicroName", index.getStaffName());
map.put("entmicroId", index.getStaffUuid());
map.put("staffPhone", index.getStaffPhone());
map.put("staffJob", index.getStaffTitle());
map.put("merchantId", index.getMerchantid());
map.put("oldMerchantId", index.getOldMerchantId());
map.put("staffEmail", index.getStaffEmail());
map.put("password", index.getStaffPhone().substring(index.getStaffPhone().length() - 6, index.getStaffPhone().length()));
map.put("type", index.getType());
map.put("oldPhone", index.getOldPhone());
return map;
}).collect(Collectors.toList());
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>(4);
params.set("data", JSONObject.toJSONString(collect));
try {
log.info("同步员工数据{}", collect);
RopResponse ropResponse = RopHttpUtil.post(params, RopResponse.class, baseurl, syncEntmicroStaffMethod);
if (("0").equals(ropResponse.getCode())) {
List<Map> baseData = (List<Map>) ropResponse.getData();
entmicroStaffList = baseData.stream().map(index -> {
MerchantStaffModel dictDataResponse = new MerchantStaffModel();
dictDataResponse.setMerchantId((Integer) index.get("merchantId"));
dictDataResponse.setStaffPhone(index.get("staffPhone") + "");
dictDataResponse.setUuid(index.get("uuid") + "");
return dictDataResponse;
}).collect(Collectors.toList());
log.info("商户返回{}", entmicroStaffList);
if (org.springframework.util.CollectionUtils.isEmpty(entmicroStaffList)) {
return;
}
log.info("update staff uuid size:{}", entmicroStaffList.size());
entmicroStaffService.updateUUID(entmicroStaffList);
}
} catch (Exception e) {
e.printStackTrace();
log.info("同步员工账号异常,{}", e);
throw new RpcException();
}
}
/**
* 查询字典
*
* @param dictType 字典类型
* @return
*/
public List<DictDataResponse> findAllByDictType(String dictType) {
try {
Object cache = redisCacheService.getCache(RedisCacheKeyPreConstants.dictionariesKey + dictType);
if (cache != null) {
List<DictDataResponse> rep = (List<DictDataResponse>) cache;
return rep;
}
} catch (Exception e) {
}
List<DictDataResponse> dictDataResponseList = null;
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>(4);
params.set("dictType", dictType);
try {
log.info("查询字典{}", dictType);
RopResponse ropResponse = RopHttpUtil.get(params, RopResponse.class, baseurl, findAllDictDataMethod);
if (("0").equals(ropResponse.getCode())) {
List<Map> baseData = (List<Map>) ropResponse.getData();
dictDataResponseList = baseData.stream().map(index -> {
DictDataResponse dictDataResponse = new DictDataResponse();
dictDataResponse.setDictType(index.get("dictType") + "");
dictDataResponse.setDictValue((Integer) index.get("dictValue"));
dictDataResponse.setDictLabel(index.get("dictLabel") + "");
return dictDataResponse;
}).collect(Collectors.toList());
}
} catch (Exception e) {
e.printStackTrace();
log.info("查询字典异常,{}", e);
}
if (dictDataResponseList != null) {
redisCacheService.setCache(RedisCacheKeyPreConstants.dictionariesKey + dictType, dictDataResponseList, RedisCacheKeyPreConstants.dictionariesKeyTimeout);
}
return dictDataResponseList;
}
/**
* 根据商户号查询商户
*
* @param merchantNo 商户号
*/
public MerchantRopResponse findMerchantByMerchantNo(Integer merchantNo) {
try {
Object cache = redisCacheService.getCache(RedisCacheKeyPreConstants.merchantDetailKey + merchantNo);
if (cache != null) {
MerchantRopResponse rep = (MerchantRopResponse) cache;
return rep;
}
} catch (Exception e) {
try {
//转换异常证明旧的数据已经无效了
redisCacheService.deleteCache(RedisCacheKeyPreConstants.merchantDetailKey + merchantNo);
} catch (Exception e1) {
}
}
MerchantRopResponse merchantRopResponse = new MerchantRopResponse();
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>(4);
params.set("merchantId", merchantNo + "");
try {
RopResponse ropResponse = RopHttpUtil.get(params, RopResponse.class, baseurl, findMerchantDetailByMerchantNoMethod);
// log.info("查询授权商户信息,{}",ropResponse);
if (("0").equals(ropResponse.getCode())) {
Map baseData = (Map) ropResponse.getData();
if (baseData == null) {
return null;
}
BeanUtils.copyProperties(baseData, merchantRopResponse);
merchantRopResponse.setMerchantModel((Integer) baseData.get("merchantModel"));
merchantRopResponse.setChannelId((Integer) baseData.get("channelId"));
merchantRopResponse.setMerchantName((String) baseData.get("merchantName"));
merchantRopResponse.setMerchantLegalPersonPhone((String) baseData.get("merchantLegalPersonPhone"));
merchantRopResponse.setCreatedTime(DateUtils.parse(baseData.get("createdTime") + ""));
merchantRopResponse.setBusinessTypeId((String) baseData.get("businessType"));
merchantRopResponse.setBusinessTypeName((String) baseData.get("businessTypeName"));
merchantRopResponse.setMerchantAddress((String) baseData.get("merchantAddress"));
redisCacheService.setCache(RedisCacheKeyPreConstants.merchantDetailKey + merchantNo, merchantRopResponse, RedisCacheKeyPreConstants.merchantDetailKeyTimeout);
} else {
log.info("根据商户号查询商户异常:{}", ropResponse);
throw new RpcServiceException(BusinessExceptionEnum.FIND_MERCHANT_EXCEPTION.getValue(), BusinessExceptionEnum.FIND_MERCHANT_EXCEPTION.getDisplayName());
}
} catch (Exception e) {
e.printStackTrace();
log.info("根据商户号查询商户异常,{}", e);
throw new RpcServiceException(BusinessExceptionEnum.AUTHORIZE_ENTMICRO_FAIL.getValue(), BusinessExceptionEnum.AUTHORIZE_ENTMICRO_FAIL.getDisplayName());
}
return merchantRopResponse;
}
/**
* 根据商户号查询门店信息
*
* @param merchantId 商户号
*/
public List<MerchantRopResponse> findSubordinateListByPage(Integer merchantId) {
List<MerchantRopResponse> responseList = null;
MultiValueMap<String, String> params = new LinkedMultiValueMap<>(4);
params.add("merchantId", merchantId + "");
params.add("merchantLevel", "4");
params.add("pageSize", "10000");
params.add("pageNum", "1");
try {
RopResponse ropResponse = RopHttpUtil.get(params, RopResponse.class, baseurl, findSubordinateListByPageMethod);
if (("0").equals(ropResponse.getCode())) {
Map<String, Object> page = (Map<String, Object>) ropResponse.getData();
String data = JSONObject.toJSONString(page.get("data"), SerializerFeature.WriteMapNullValue);
log.info("查询商户门店列表,{}", data);
responseList = JSONObject.parseArray(data, MerchantRopResponse.class);
}
} catch (Exception e) {
e.printStackTrace();
log.info("查询商户门店列表异常,{}", e);
}
return responseList;
}
/**
* 查询上级商户
*
* @param merchantId 商户号
*/
public List<MerchantRopResponse> findSuperiorList(Integer merchantId) {
List<MerchantRopResponse> responseList = null;
MultiValueMap<String, String> params = new LinkedMultiValueMap<>(4);
params.add("merchantId", merchantId + "");
try {
RopResponse ropResponse = RopHttpUtil.get(params, RopResponse.class, baseurl, findSuperiorList);
if (("0").equals(ropResponse.getCode())) {
responseList = (List<MerchantRopResponse>) ropResponse.getData();
}
} catch (Exception e) {
e.printStackTrace();
log.info("查询商户门店列表异常,{}", e);
}
return responseList;
}
/**
* 查询工厂商户
*
* @param merchantId 商户号
*/
public Integer findSuperlativeMerchant(Integer merchantId) {
try {
Object cache = redisCacheService.getCache(RedisCacheKeyPreConstants.merchantKey + merchantId);
if (cache != null) {
return (int) cache;
}
} catch (Exception e) {
}
MultiValueMap<String, String> params = new LinkedMultiValueMap<>(4);
params.add("merchantId", merchantId + "");
Integer merchantNo = null;
try {
RopResponse ropResponse = RopHttpUtil.get(params, RopResponse.class, baseurl, findSuperlativeMerchant);
if (("0").equals(ropResponse.getCode())) {
merchantNo = (Integer) ropResponse.getData();
}
} catch (Exception e) {
e.printStackTrace();
log.info("查询商户门店列表异常,{}", e);
}
if (merchantNo != null) {
redisCacheService.setCache(RedisCacheKeyPreConstants.merchantKey + merchantId, merchantNo, RedisCacheKeyPreConstants.merchantKeyTimeout);
}
return merchantNo;
}
public List<MerchantRopResponse> findShopMerchant(Integer merchantId) {
List<MerchantRopResponse> subordinateList = findSubordinateListByPage(merchantId);
log.info("subordinateList:{}", subordinateList);
if (!CollectionUtils.isEmpty(subordinateList)) {
//过滤出已关联企微
List<MerchantRopResponse> merchantNotEntmicro = subordinateList.stream().filter(merchant -> {
String entmicroName = merchant.getEntmicroName();
return !StringUtils.isEmpty(entmicroName);
}).collect(Collectors.toList());
return merchantNotEntmicro;
} else {
return null;
}
}
/**
* 跟进创建人查询用户
*
* @param createdBy 创建人
*/
public List<UserResponse> findAllUser(List<Integer> createdBy) {
List<UserResponse> responseList = null;
MultiValueMap<String, String> params = new LinkedMultiValueMap<>(4);
params.add("createdBy", ListUtils.listToString(createdBy, ','));
try {
RopResponse ropResponse = RopHttpUtil.get(params, RopResponse.class, baseurl, findByCreatedBy);
if (("0").equals(ropResponse.getCode())) {
String data = JSONObject.toJSONString(ropResponse.getData(), SerializerFeature.WriteMapNullValue);
log.info("查询用户列表,{}", data);
responseList = JSONObject.parseArray(data, UserResponse.class);
}
} catch (Exception e) {
e.printStackTrace();
log.info("查询用户列表,{}", e);
}
return responseList;
}
public List<Integer> findSubordinateMerchantList(Integer merchantId) {
List<Integer> merchantIds = null;
List<MerchantRopResponse> subordinateListByPage = findSubordinateListByPage(merchantId);
if (!CollectionUtils.isEmpty(subordinateListByPage)) {
merchantIds = subordinateListByPage.stream().map(MerchantRopResponse::getMerchantNo).collect(Collectors.toList());
}
return merchantIds;
}
/**
* 商户号修改关联部门名称
*
* @param merchantId
* @param departmentName
*/
public void updateMerchantByMerchantNo(Integer merchantId, String departmentName) {
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>(2);
params.set("merchantNo", merchantId + "");
params.set("entmicroName", departmentName);
try {
RopResponse post = RopHttpUtil.post(params, RopResponse.class, baseurl, updateMerchantByMerchantNo);
log.info("商户号修改关联部门名称:{}, result:{}", params.toString(), post.toString());
} catch (Exception e) {
e.printStackTrace();
log.info("同步修改部门名称异常,{}", params.toString());
}
}
/**
* 根据商户号查询已加入企微员工
*
* @param merchantNo 员工
*/
public List<StaffRopResponse> findJoinEntMicroStaffByMerchantNo(Integer merchantNo) {
List<StaffRopResponse> responseList = new ArrayList<>();
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>(4);
params.set("merchantNo", merchantNo + "");
try {
RopResponse ropResponse = RopHttpUtil.get(params, RopResponse.class, baseurl, findJoinEntMicroStaffByMerchantNo);
if (("0").equals(ropResponse.getCode())) {
String data = JSONObject.toJSONString(ropResponse.getData(), SerializerFeature.WriteMapNullValue);
log.info("查询已加入企微员工,{}", data);
responseList = JSONObject.parseArray(data, StaffRopResponse.class);
}
} catch (Exception e) {
e.printStackTrace();
log.info("根据商户号查询已加入企微员工异常,{}", e);
throw new RpcServiceException(BusinessExceptionEnum.AUTHORIZE_ENTMICRO_FAIL.getValue(), BusinessExceptionEnum.AUTHORIZE_ENTMICRO_FAIL.getDisplayName());
}
return responseList;
}
/**
* 查询服务商关联的园区店、4s店
*
* @param merchantId 商户号列表字符串(以,分隔)
* @return
*/
public List<ListYqAndShopRopResponse> getPartnerMerchant(Integer merchantId) {
String property = environment.getProperty("dj.partnerMerchant.listYqAndShop");
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
paramsMap.add("merchantIdsStr", JSONArray.toJSONString(merchantId));
List<ListYqAndShopRopResponse> responseList = new ArrayList<>();
try {
RopResponse ropResponse = RopDJHttpUtil.post(paramsMap, RopResponse.class, djBaseUrl, property);
log.info("查询服务商关联的园区店、4s店, param:{}, result:{}", paramsMap, ropResponse);
if (("0").equals(ropResponse.getCode())) {
String data = JSONObject.toJSONString(ropResponse.getData(), SerializerFeature.WriteMapNullValue);
responseList = JSONObject.parseArray(data, ListYqAndShopRopResponse.class);
}
} catch (Exception e) {
log.info("请求嘀加服务商失败: {}", e);
}
return responseList;
}
/**
* 查询授权商户
*
* @param merchantId 商户号
* @return
*/
public Integer findSupMerchantNo(Integer merchantId) {
MerchantRopResponse merchantByMerchantNo = findMerchantByMerchantNo(merchantId);
Integer merchantModel = merchantByMerchantNo.getMerchantModel();
if (merchantModel != null) {
if (merchantModel.intValue() == Constants.STORE_MODEL) {
return merchantId;
} else {
return findSuperlativeMerchant(merchantId);
}
}
return null;
}
/**
* 查询员工
*
* @param uuid uuid
* @return
*/
public UserResponse getAccountInfoByUuid(String uuid) {
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
paramsMap.add("uuid", uuid);
UserResponse userResponse = null;
try {
RopResponse ropResponse = RopHttpUtil.post(paramsMap, RopResponse.class, baseurl, "merchants.api.open.getAccountInfoByUuid");
log.info("查询员工param:{}, result:{}", paramsMap, ropResponse);
if (("0").equals(ropResponse.getCode())) {
String data = JSONObject.toJSONString(ropResponse.getData(), SerializerFeature.WriteMapNullValue);
userResponse = JSONObject.parseObject(data, UserResponse.class);
}
} catch (Exception e) {
log.info("请求嘀加服务商失败: {}", e);
}
return userResponse;
}
/**
* 根据商户名模糊查询商户
*/
public List<MerchantRopResponse> findMerchantListByCondition(ListMerchantRequest merchantRequest) {
RpcAssert.assertNotNull(merchantRequest, BusinessExceptionEnum.EMPTY_PARAMS);
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>(1);
params.set("merchantName", merchantRequest.getMerchantName());
params.set("merchantNoStr", merchantRequest.getMerchantNoStrSet());
List<MerchantRopResponse> responseList = new ArrayList<>();
try {
log.info("模糊查询商户名的门店参数{}", params);
RopResponse ropResponse = RopHttpUtil.post(params, RopResponse.class, baseurl, findMerchantListMethod);
log.info("模糊查询商户名的门店{}", ropResponse);
if (("0").equals(ropResponse.getCode())) {
String data = JSONObject.toJSONString(ropResponse.getData(), SerializerFeature.WriteMapNullValue);
responseList = JSONObject.parseArray(data, MerchantRopResponse.class);
}
} catch (Exception e) {
e.printStackTrace();
throw new RpcServiceException(BusinessExceptionEnum.FIND_MERCHANT_EXCEPTION.getValue(), BusinessExceptionEnum.FIND_MERCHANT_EXCEPTION.getDisplayName());
}
return responseList;
}
/**
* 3
* 根据商户模式查询商户
*
* @param level 商户等级,1.工厂 2.省代 3.市代 4.门店
* @param model 商户模式,1.集团版 2.门店版
* @param channelId 渠道,1.嘀加 2.广汇
* @return
*/
public List<Integer> findMerchantListByModel(Integer level, Integer model, Integer channelId) {
MultiValueMap<String, String> params = new LinkedMultiValueMap<>(3);
if (level != null) params.set("merchantAccountLevel", level + "");
if (model != null) params.set("merchantModel", model + "");
if (channelId != null) params.set("channelId", channelId + "");
List<Integer> responseList = new ArrayList<>();
try {
log.info("根据模式查询的商户号参数{}", params);
RopResponse ropResponse = RopHttpUtil.post(params, RopResponse.class, baseurl, findMerchantListByModelMethod);
log.info("根据模式查询的商户号结果{}", ropResponse);
if (("0").equals(ropResponse.getCode())) {
String data = JSONObject.toJSONString(ropResponse.getData(), SerializerFeature.WriteMapNullValue);
responseList = JSONObject.parseArray(data, Integer.class);
}
} catch (Exception e) {
e.printStackTrace();
throw new RpcServiceException(BusinessExceptionEnum.FIND_MERCHANT_EXCEPTION.getValue(), BusinessExceptionEnum.FIND_MERCHANT_EXCEPTION.getDisplayName());
}
return responseList;
}
/**
* 根据员工手机号查询商户号列表
*
* @param staffphone
* @return
*/
public List<Integer> merchantNoListByStaffPhone(String staffphone) {
if (StringUtils.isEmpty(staffphone)) return new ArrayList<>();
MultiValueMap<String, String> params = new LinkedMultiValueMap<>(3);
params.set("staffPhone", staffphone);
List<Integer> responseList = new ArrayList<>();
try {
log.info("根据员工手机号查询商户号列表参数{}", params);
RopResponse ropResponse = RopHttpUtil.post(params, RopResponse.class, baseurl, merchantNoListByStaffPhone);
log.info("根据员工手机号查询商户号列表结果{}", ropResponse);
if (("0").equals(ropResponse.getCode())) {
String data = JSONObject.toJSONString(ropResponse.getData(), SerializerFeature.WriteMapNullValue);
responseList = JSONObject.parseArray(data, Integer.class);
}
} catch (Exception e) {
e.printStackTrace();
throw new RpcServiceException(BusinessExceptionEnum.FIND_MERCHANT_EXCEPTION.getValue(), BusinessExceptionEnum.FIND_MERCHANT_EXCEPTION.getDisplayName());
}
return responseList;
}
/**
* 查询商户列表
*
* @param request
* @return
*/
public Page<SubscribeMerchantResponse> findMerchantByPage(FindMerchantByPageRequest request) {
MultiValueMap<String, String> params = new LinkedMultiValueMap<>(8);
if (request.getPageNum() != null) params.set("pageNum", request.getPageNum() + "");
if (request.getPageSize() != null) params.set("pageSize", request.getPageSize() + "");
if (request.getIsRelevance() != null) params.set("isRelevance", request.getIsRelevance() + "");
if (request.getChannelId() != null) params.set("channelId", request.getChannelId() + "");
if (request.getMerchantAccountLevel() != null)
params.set("merchantAccountLevel", request.getMerchantAccountLevel() + "");
if (request.getAccountOrPhone() != null) params.set("accountOrPhone", request.getAccountOrPhone() + "");
if (request.getMerchantNo() != null) params.set("merchantNo", request.getMerchantNo() + "");
if (request.getMerchantName() != null) params.set("merchantName", request.getMerchantName());
Page<SubscribeMerchantResponse> responseList = new Page<>();
try {
log.info("查询商户列表参数{}", params);
RopResponse ropResponse = RopHttpUtil.post(params, RopResponse.class, baseurl, findMerchantByPageMethod);
log.info("查询商户列表结果{}", ropResponse);
if (("0").equals(ropResponse.getCode())) {
String data = JSONObject.toJSONString(ropResponse.getData(), SerializerFeature.WriteMapNullValue);
// responseList = JSONObject.parseArray(data, SubscribeMerchantResponse.class);
FindMerchantByPageResponse response = JSON.parseObject(data, FindMerchantByPageResponse.class);
responseList.setPageSize(response.getPageSize());
responseList.setPageNum(response.getPageNum());
responseList.setTotal(response.getCount());
responseList.addAll(response.getData());
}
} catch (Exception e) {
e.printStackTrace();
throw new RpcServiceException(BusinessExceptionEnum.FIND_MERCHANT_EXCEPTION.getValue(), BusinessExceptionEnum.FIND_MERCHANT_EXCEPTION.getDisplayName());
}
return responseList;
}
public List<MerchantTreeOpenResponse> findMerchantTreeByMerchantNo(Integer merchantId) {
List<MerchantTreeOpenResponse> merchantTreeOpenResponses = null;
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>(4);
params.set("merchantId", merchantId + "");
params.set("flag", "true");
try {
RopResponse ropResponse = RopHttpUtil.get(params, RopResponse.class, baseurl, findMerchantTreeByMerchantNoMethod);
log.info("查询商户树返回 ropResponse:{}", ropResponse);
if (("0").equals(ropResponse.getCode())) {
merchantTreeOpenResponses = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.convertValue(ropResponse.getData(), new TypeReference<List<MerchantTreeOpenResponse>>() {
});
}
} catch (Exception e) {
e.printStackTrace();
log.info("查询商户树异常,{}", e);
}
return merchantTreeOpenResponses;
}
public List<Integer> findMerchantTreeId(Integer merchantId) {
List<Integer> merchantIdList = new ArrayList<>();
try {
List<MerchantTreeOpenResponse> treeByMerchantNo = findMerchantTreeByMerchantNo(merchantId);
if (!CollectionUtils.isEmpty(treeByMerchantNo)) {
merchantIdList = recursionMerchantTree(merchantIdList, treeByMerchantNo);
merchantIdList.add(merchantId);
return merchantIdList;
}
return merchantIdList;
} catch (Exception e) {
log.warn("递归商户树异常 merchantId:{}", merchantId, e);
return merchantIdList;
}
}
private List<Integer> recursionMerchantTree(List<Integer> merchantIdList, List<MerchantTreeOpenResponse> treeByMerchantNo) {
if (merchantIdList == null) merchantIdList = new ArrayList<>();
if (CollectionUtils.isEmpty(treeByMerchantNo)) return merchantIdList;
List<Integer> idList = treeByMerchantNo.stream().map(MerchantTreeOpenResponse::getId).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(idList)) merchantIdList.addAll(idList);
List<MerchantTreeOpenResponse> childrenList = new ArrayList<>();
treeByMerchantNo.stream().filter(s -> s.getChildren() != null).forEach(s -> childrenList.addAll(s.getChildren()));
if (CollectionUtils.isEmpty(childrenList)) return merchantIdList;
return recursionMerchantTree(merchantIdList, childrenList);
}
public List<EntmicroStaffResponse> findStaffByUUidList(List<String> uuidList){
List<EntmicroStaffResponse> result = new ArrayList<>();
if (CollectionUtils.isEmpty(uuidList)) return result;
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>(4);
for (int i = 0; i < uuidList.size(); i++) {
params.add("staffUuidList["+i+"]", uuidList.get(i));
}
try {
RopResponse ropResponse = RopHttpUtil.get(params, RopResponse.class, baseurl, findMerchantStaffMethod);
log.info("根据uuid查询员工 ropResponse:{}", ropResponse);
if (("0").equals(ropResponse.getCode())) {
String data = JSONObject.toJSONString(ropResponse.getData(), SerializerFeature.WriteMapNullValue);
result = JSONObject.parseArray(data, EntmicroStaffResponse.class);
}
} catch (Exception e) {
e.printStackTrace();
log.info("根据uuid查询员工异常,{}", e);
}
return result;
}
}