WeFlowerCustomerRelServiceImpl.java
5.25 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
package com.linkwechat.wecom.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linkwechat.common.utils.DateUtils;
import com.linkwechat.wecom.domain.WeCustomer;
import com.linkwechat.wecom.domain.WeFlowerCustomerRel;
import com.linkwechat.wecom.domain.WeFlowerCustomerTagRel;
import com.linkwechat.wecom.mapper.WeCustomerMapper;
import com.linkwechat.wecom.mapper.WeCustomerTagRelMapper;
import com.linkwechat.wecom.mapper.WeFlowerCustomerRelMapper;
import com.linkwechat.wecom.mapper.WeFlowerCustomerTagRelMapper;
import com.linkwechat.wecom.service.IWeCustomerService;
import com.linkwechat.wecom.service.IWeCustomerTagRelService;
import com.linkwechat.wecom.service.IWeFlowerCustomerRelService;
import com.linkwechat.wecom.service.IWeFlowerCustomerTagRelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;
/**
* 具有外部联系人功能企业员工也客户的关系Service业务层处理
*
* @author ruoyi
* @date 2020-09-19
*/
@Service
public class WeFlowerCustomerRelServiceImpl extends ServiceImpl<WeFlowerCustomerRelMapper, WeFlowerCustomerRel> implements IWeFlowerCustomerRelService {
@Autowired
@Lazy
IWeCustomerService iWeCustomerService;
@Autowired
WeFlowerCustomerTagRelMapper weFlowerCustomerTagRelMapper;
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteFollowUser(String userId, String externalUserid) {
//如何是首位添加人删除的客户,直接删除该客户,否则直接删除关系
WeCustomer weCustomer
= iWeCustomerService.getById(externalUserid);
if(weCustomer != null){
if(weCustomer.getFirstUserId().equals(userId)){
//删除客户
iWeCustomerService.removeById(externalUserid);
}
//删除更进关系
this.remove(new LambdaQueryWrapper<WeFlowerCustomerRel>()
.eq(WeFlowerCustomerRel::getExternalUserid,externalUserid)
.eq(WeFlowerCustomerRel::getUserId,userId));
//删除跟进人给客户打的标签
weFlowerCustomerTagRelMapper.delete(new LambdaQueryWrapper<WeFlowerCustomerTagRel>()
.eq(WeFlowerCustomerTagRel::getExternalUserid,externalUserid)
.eq(WeFlowerCustomerTagRel::getUserId,userId));
}
}
@Override
public Map<String, Object> getUserAddCustomerStat(WeFlowerCustomerRel weFlowerCustomerRel) {
Map<String, Object> resultMap = new HashMap<>(16);
List<String> dateList = new ArrayList<>();
List<Long> statList = new ArrayList<>();
Long resultTotal = 0L;
List<Map<String, Object>> userAddCustomerStatList = this.baseMapper.getUserAddCustomerStat(weFlowerCustomerRel);
String beginTime = weFlowerCustomerRel.getBeginTime();
String endTime = weFlowerCustomerRel.getEndTime();
if (beginTime != null && endTime != null) {
Date beginDate = DateUtils.dateTime(DateUtils.YYYY_MM_DD, beginTime);
Date endDate = DateUtils.dateTime(DateUtils.YYYY_MM_DD, endTime);
List<Date> dates = DateUtils.findDates(beginDate, endDate);
dateList = dates.stream().map(date -> DateUtils.dateTime(date)).collect(Collectors.toList());
Optional.ofNullable(dateList).orElseGet(ArrayList::new).forEach(date -> {
AtomicLong total = new AtomicLong(0);
Optional.ofNullable(userAddCustomerStatList).orElseGet(ArrayList::new).forEach(statInfo -> {
if (date.equals(statInfo.get("createTime"))) {
total.set((Long) statInfo.get("total"));
return;
}
});
statList.add(total.get());
});
resultTotal = statList.stream().mapToLong(Long::longValue).sum();
} else {
dateList.addAll(Optional.ofNullable(userAddCustomerStatList).orElseGet(ArrayList::new)
.stream()
.filter(statInfo -> null != statInfo.get("createTime"))
.map(statInfo -> (String) statInfo.get("createTime")).collect(Collectors.toList()));
statList.addAll(Optional.ofNullable(userAddCustomerStatList).orElseGet(ArrayList::new)
.stream()
.filter(statInfo -> null != statInfo.get("total"))
.map(statInfo -> (Long) statInfo.get("total")).collect(Collectors.toList()));
resultTotal = Optional.ofNullable(userAddCustomerStatList).orElseGet(ArrayList::new)
.stream()
.filter(statInfo -> null != statInfo.get("total"))
.mapToLong(statInfo -> (Long) statInfo.get("total")).sum();
}
resultMap.put("dateList", dateList);
resultMap.put("statList", statList);
resultMap.put("total", resultTotal);
return resultMap;
}
}