FollowPoolBizService.java
6.21 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
package cn.fw.valhalla.service.bus.follow;
import cn.fw.common.page.AppPage;
import cn.fw.common.web.auth.LoginAuthBean;
import cn.fw.valhalla.common.enums.DefeatTypeEnum;
import cn.fw.valhalla.common.utils.DateUtil;
import cn.fw.valhalla.common.utils.StringUtils;
import cn.fw.valhalla.domain.db.PublicPool;
import cn.fw.valhalla.domain.dto.FollowPoolDTO;
import cn.fw.valhalla.domain.enums.TaskStateEnum;
import cn.fw.valhalla.domain.query.FollowPoolQueryVO;
import cn.fw.valhalla.domain.vo.customer.PublicPoolVO;
import cn.fw.valhalla.domain.vo.follow.FollowPoolListVO;
import cn.fw.valhalla.rpc.erp.UserService;
import cn.fw.valhalla.rpc.erp.dto.UserInfoDTO;
import cn.fw.valhalla.rpc.oop.OopService;
import cn.fw.valhalla.rpc.oop.dto.ShopDTO;
import cn.fw.valhalla.service.data.FollowTaskService;
import cn.fw.valhalla.service.data.PublicPoolService;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import static cn.fw.common.businessvalidator.Validator.BV;
/**
* @author : kurisu
* @className : FollowPoolBizService
* @description : 跟进池服务
* @date: 2020-09-23 15:30
*/
@Slf4j
@Service
public class FollowPoolBizService {
private final FollowTaskService followTaskService;
private final PublicPoolService publicPoolService;
private final OopService oopService;
private final UserService userService;
private final static Integer MONTH_DAY = 31;
@Autowired
public FollowPoolBizService(final FollowTaskService followTaskService,
final PublicPoolService publicPoolService,
final OopService oopService,
final UserService userService) {
this.followTaskService = followTaskService;
this.publicPoolService = publicPoolService;
this.oopService = oopService;
this.userService = userService;
}
/**
* 跟进池
*
* @param queryVO
* @return
*/
public AppPage<FollowPoolListVO> followList(LoginAuthBean user, FollowPoolQueryVO queryVO) {
prepareParams(user, queryVO);
List<FollowPoolDTO> list = followTaskService.followList(queryVO);
List<FollowPoolListVO> followList = new ArrayList<>();
for (FollowPoolDTO followPoolDTO : list) {
FollowPoolListVO vo = trans2Pool(followPoolDTO);
followList.add(vo);
}
AppPage<FollowPoolListVO> page = AppPage.empty(queryVO);
page.setData(followList);
return page;
}
/**
* 公共池
*
* @param queryVO
* @return
*/
public AppPage<PublicPoolVO> publicList(FollowPoolQueryVO queryVO) {
Page<PublicPool> opage = new Page<>(queryVO.getCurrent(), queryVO.getPageSize());
opage = publicPoolService.page(opage, Wrappers.<PublicPool>lambdaQuery()
.eq(StringUtils.isValid(queryVO.getPlateNo()), PublicPool::getPlateNo, "%" + queryVO.getPlateNo() + "%")
.eq(Objects.nonNull(queryVO.getType()), PublicPool::getType, queryVO.getType())
.eq(Objects.nonNull(queryVO.getGroupId()), PublicPool::getGroupId, queryVO.getGroupId())
);
AppPage<PublicPoolVO> page = AppPage.empty(queryVO);
List<PublicPool> list = opage.getRecords();
if (CollectionUtils.isEmpty(list)) {
return page;
}
List<PublicPoolVO> publicList = new ArrayList<>();
for (PublicPool pool : list) {
PublicPoolVO vo = new PublicPoolVO();
BeanUtils.copyProperties(pool, vo);
vo.setTypeDesc(pool.getType().getName());
publicList.add(vo);
}
page.setData(publicList);
return page;
}
private FollowPoolListVO trans2Pool(FollowPoolDTO poolDTO) {
FollowPoolListVO vo = new FollowPoolListVO();
BeanUtils.copyProperties(poolDTO, vo);
UserInfoDTO user = userService.user(poolDTO.getUserId());
if (Objects.nonNull(user)) {
vo.setFollower(user.getUserName());
}
ShopDTO shop = oopService.shop(poolDTO.getShopId());
if (Objects.nonNull(shop)) {
vo.setShopName(shop.getShopName());
}
DefeatTypeEnum defeatTypeEnum = DefeatTypeEnum.ofValue(poolDTO.getInitiative());
if (Objects.nonNull(defeatTypeEnum) && poolDTO.getState() == 3) {
vo.setDefeatType(defeatTypeEnum.getName());
}
if (Boolean.TRUE.equals(poolDTO.getFinished()) && !poolDTO.getOriginShop().equals(poolDTO.getFinishShop())) {
vo.setDefeatDesc("集团内战败");
}
if (poolDTO.getState() == 3 && DefeatTypeEnum.B.equals(defeatTypeEnum)) {
vo.setDefeatDesc("系统划走");
}
return vo;
}
private void prepareParams(LoginAuthBean user, FollowPoolQueryVO queryVO) {
if (Objects.nonNull(user)) {
queryVO.setUserId(user.getUserId());
queryVO.setGroupId(user.getGroupId());
} else {
BV.isFalse(Objects.isNull(queryVO.getShopId()) && Objects.isNull(queryVO.getUserId()), () -> "请选择服务站或者人员");
}
boolean inSection = DateUtil.sub(queryVO.getEndTime(), queryVO.getStartTime(), "d") <= MONTH_DAY;
BV.isTrue(inSection, () -> "暂不支持查询超过一个月区间的数据");
boolean d = DateUtil.sub(queryVO.getEndTime(), queryVO.getStartTime(), "d") >= 0;
BV.isTrue(d, () -> "截止时间必须大于开始时间");
if (Objects.nonNull(queryVO.getOrder()) && StringUtils.isValid(queryVO.getOrderAtt())) {
StringBuilder sb = new StringBuilder(" order by ");
sb.append(StringUtils.toColumnName(queryVO.getOrderAtt()).toLowerCase());
if (queryVO.getOrder() == 1) {
sb.append(" asc ");
} else {
sb.append(" desc ");
}
queryVO.setOrderString(sb.toString());
}
}
}