|
@@ -1,345 +1,345 @@
|
1
|
|
-package com.huiju.estateagents.service.impl;
|
2
|
|
-
|
3
|
|
-import ch.qos.logback.core.status.StatusUtil;
|
4
|
|
-import com.alibaba.fastjson.JSONObject;
|
5
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
6
|
|
-import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
7
|
|
-import com.baomidou.mybatisplus.core.metadata.IPage;
|
8
|
|
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
9
|
|
-import com.huiju.estateagents.base.ResponseBean;
|
10
|
|
-import com.huiju.estateagents.common.CommConstant;
|
11
|
|
-import com.huiju.estateagents.common.DateUtils;
|
12
|
|
-import com.huiju.estateagents.common.StringUtils;
|
13
|
|
-import com.huiju.estateagents.entity.TaPerson;
|
14
|
|
-import com.huiju.estateagents.entity.TaRecommendCustomer;
|
15
|
|
-import com.huiju.estateagents.mapper.TaPersonMapper;
|
16
|
|
-import com.huiju.estateagents.mapper.TaPersonVisitRecordMapper;
|
17
|
|
-import com.huiju.estateagents.mapper.TaRecommendCustomerMapper;
|
18
|
|
-import com.huiju.estateagents.service.IMiniAppService;
|
19
|
|
-import com.huiju.estateagents.service.ITaRecommendCustomerService;
|
20
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
21
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
22
|
|
-import org.springframework.stereotype.Service;
|
23
|
|
-
|
24
|
|
-import javax.naming.spi.ResolveResult;
|
25
|
|
-import java.time.LocalDateTime;
|
26
|
|
-import java.util.HashMap;
|
27
|
|
-import java.util.List;
|
28
|
|
-import java.util.Map;
|
29
|
|
-
|
30
|
|
-/**
|
31
|
|
- * <p>
|
32
|
|
- * 推荐客户表 服务实现类
|
33
|
|
- * </p>
|
34
|
|
- *
|
35
|
|
- * @author jobob
|
36
|
|
- * @since 2019-05-10
|
37
|
|
- */
|
38
|
|
-@Service
|
39
|
|
-public class TaRecommendCustomerServiceImpl extends ServiceImpl<TaRecommendCustomerMapper, TaRecommendCustomer> implements ITaRecommendCustomerService {
|
40
|
|
-
|
41
|
|
- @Autowired
|
42
|
|
- TaPersonMapper taPersonMapper;
|
43
|
|
-
|
44
|
|
- @Autowired
|
45
|
|
- TaRecommendCustomerMapper taRecommendCustomerMapper;
|
46
|
|
-
|
47
|
|
- @Autowired
|
48
|
|
- IMiniAppService iMiniAppService;
|
49
|
|
-
|
50
|
|
- @Autowired
|
51
|
|
- TaPersonVisitRecordMapper taPersonVisitRecordMapper;
|
52
|
|
-
|
53
|
|
- @Override
|
54
|
|
- public ResponseBean getMyCustList(String openid, String keywords, int pageNumber, int pageSize) {
|
55
|
|
- List<TaPerson> taPersons = getPersonsByOpenId(openid);
|
56
|
|
- if (null == taPersons || taPersons.size() != 1) {
|
57
|
|
- return ResponseBean.error("验证当前人员信息失败", ResponseBean.ERROR_UNAVAILABLE);
|
58
|
|
- }
|
59
|
|
-
|
60
|
|
- TaPerson taPerson = taPersons.get(0);
|
61
|
|
-
|
62
|
|
- IPage<TaRecommendCustomer> page = new Page<>();
|
63
|
|
- page.setCurrent(pageNumber);
|
64
|
|
- page.setSize(pageSize);
|
65
|
|
-
|
66
|
|
- QueryWrapper<TaRecommendCustomer> query = new QueryWrapper<>();
|
67
|
|
- query.eq("person_id", taPerson.getPersonId());
|
68
|
|
- query.like(null != keywords && "".equals(keywords.trim()), "name", keywords);
|
69
|
|
- query.orderByDesc("report_date");
|
70
|
|
-
|
71
|
|
- IPage<TaRecommendCustomer> result = taRecommendCustomerMapper.selectPage(page, query);
|
72
|
|
- return ResponseBean.success(result);
|
73
|
|
- }
|
74
|
|
-
|
75
|
|
- @Override
|
76
|
|
- public ResponseBean getCustDetail(String id) {
|
77
|
|
- TaRecommendCustomer taRecommendCustomer = taRecommendCustomerMapper.selectById(id);
|
78
|
|
-
|
79
|
|
- if (!StringUtils.isEmpty(taRecommendCustomer.getRealtyConsultant())) {
|
80
|
|
- TaPerson taPerson = taPersonMapper.selectById(taRecommendCustomer.getRealtyConsultant());
|
81
|
|
- if (null != taPerson) {
|
82
|
|
- taRecommendCustomer.setConsultants(new HashMap<String, Object>() {{
|
83
|
|
- put("name", taPerson.getName());
|
84
|
|
- put("phone", taPerson.getTel());
|
85
|
|
- put("photo", taPerson.getPhoto());
|
86
|
|
- }});
|
87
|
|
- }
|
88
|
|
- }
|
89
|
|
-
|
90
|
|
- return ResponseBean.success(taRecommendCustomer);
|
91
|
|
- }
|
92
|
|
-
|
93
|
|
- @Override
|
94
|
|
- public ResponseBean updateCustByJSON(String paramStr) {
|
95
|
|
- JSONObject params = JSONObject.parseObject(paramStr);
|
96
|
|
- if (null == params) {
|
97
|
|
- return ResponseBean.error("解析参数失败", ResponseBean.ERROR_ILLEGAL_PARAMS);
|
98
|
|
- }
|
99
|
|
-
|
100
|
|
- String checkResult = checkCustomerParams(params);
|
101
|
|
- if (null != checkResult) {
|
102
|
|
- return ResponseBean.error(checkResult, ResponseBean.ERROR_MISSING_PARAMS);
|
103
|
|
- }
|
104
|
|
-
|
105
|
|
-
|
106
|
|
- UpdateWrapper<TaRecommendCustomer> wrapper = new UpdateWrapper<>();
|
107
|
|
- wrapper.eq("customer_id", params.get("id"));
|
108
|
|
- wrapper.set("name", params.get("name"));
|
109
|
|
- wrapper.set("picture", params.get("picture"));
|
110
|
|
- wrapper.set("phone", params.get("phone"));
|
111
|
|
- wrapper.set("sex", params.get("sex"));
|
112
|
|
- wrapper.set("describe", params.get("describe"));
|
113
|
|
-
|
114
|
|
- String at = params.getString("appointmentTime");
|
115
|
|
- if (!StringUtils.isEmpty(at)) {
|
116
|
|
- wrapper.set("appointmentTime", DateUtils.day2LocalDateime(at));
|
117
|
|
- }
|
118
|
|
- wrapper.set("vistors", params.get("vistors"));
|
119
|
|
- wrapper.set("explain", params.get("explain"));
|
120
|
|
- wrapper.set("intention", params.get("intention"));
|
121
|
|
- wrapper.set("realtyManageType", params.get("realtyManageType"));
|
122
|
|
- wrapper.set("demandType", params.get("demandType"));
|
123
|
|
- wrapper.set("priceRange", params.get("priceRange"));
|
124
|
|
- wrapper.set("realtyConsultant", params.get("realtyConsultant"));
|
125
|
|
-
|
126
|
|
- // todo 需要约定时间格式
|
127
|
|
-// wrapper.set("reportDate", params.get("reportDate"));
|
128
|
|
-
|
129
|
|
- String status = params.getString("status");
|
130
|
|
- if (null != status) {
|
131
|
|
- wrapper.set("status", params.get("status"));
|
132
|
|
- }
|
133
|
|
-
|
134
|
|
- int row = taRecommendCustomerMapper.update(new TaRecommendCustomer(), wrapper);
|
135
|
|
- if (row <= 0) {
|
136
|
|
- return ResponseBean.error("更新客户信息失败", ResponseBean.ERROR_UNAVAILABLE);
|
137
|
|
- }
|
138
|
|
-
|
139
|
|
- return ResponseBean.success("更新客户信息成功");
|
140
|
|
- }
|
141
|
|
-
|
142
|
|
- @Override
|
143
|
|
- public ResponseBean recommendCust(String paramStr, String openid) {
|
144
|
|
- JSONObject params = JSONObject.parseObject(paramStr);
|
145
|
|
- if (null == params) {
|
146
|
|
- return ResponseBean.error("解析参数失败", ResponseBean.ERROR_ILLEGAL_PARAMS);
|
147
|
|
- }
|
148
|
|
- List<TaPerson> taPersons = getPersonsByOpenId(openid);
|
149
|
|
- if (null == taPersons || taPersons.size() != 1) {
|
150
|
|
- return ResponseBean.error("验证当前人员信息失败", ResponseBean.ERROR_UNAVAILABLE);
|
151
|
|
- }
|
152
|
|
- TaPerson taPerson = taPersons.get(0);
|
153
|
|
-
|
154
|
|
- String checkResult = checkCustomerParams(params);
|
155
|
|
- if (null != checkResult) {
|
156
|
|
- return ResponseBean.error(checkResult, ResponseBean.ERROR_MISSING_PARAMS);
|
157
|
|
- }
|
158
|
|
-
|
159
|
|
- TaRecommendCustomer taRecommendCustomer = new TaRecommendCustomer();
|
160
|
|
-
|
161
|
|
- taRecommendCustomer.setName(params.getString("name"));
|
162
|
|
- taRecommendCustomer.setPicture(params.getString("picture"));
|
163
|
|
- taRecommendCustomer.setPhone(params.getString("phone"));
|
164
|
|
- taRecommendCustomer.setSex(params.getInteger("sex"));
|
165
|
|
- taRecommendCustomer.setDescribe(params.getString("describe"));
|
166
|
|
- taRecommendCustomer.setRealtyConsultant(params.getString("realtyConsultant"));
|
167
|
|
-
|
168
|
|
- // 时间格式 yyyy-MM-dd
|
169
|
|
- String at = params.getString("appointmentTime");
|
170
|
|
- if (!StringUtils.isEmpty(at)) {
|
171
|
|
- taRecommendCustomer.setAppointmentTime(DateUtils.day2LocalDateime(at));
|
172
|
|
- }
|
173
|
|
-
|
174
|
|
-// taRecommendCustomer.setAppointmentTime((String) params.get("appointmentTime"));
|
175
|
|
- taRecommendCustomer.setVisiteNum(params.getInteger("visiteNum"));
|
176
|
|
- taRecommendCustomer.setIntention(params.getString("intention"));
|
177
|
|
- taRecommendCustomer.setRealtyManageType(params.getString("realtyManageType"));
|
178
|
|
- taRecommendCustomer.setDemandType(params.getString("demandType"));
|
179
|
|
- taRecommendCustomer.setPriceRange(params.getString("priceRange"));
|
180
|
|
-
|
181
|
|
- // 报备日期是今天
|
182
|
|
- taRecommendCustomer.setReportDate(LocalDateTime.now());
|
183
|
|
-
|
184
|
|
- String status = params.getString("status");
|
185
|
|
- if (null == status) status = "1";
|
186
|
|
- taRecommendCustomer.setStatus(status);
|
187
|
|
- taRecommendCustomer.setRecommendPerson(taPerson.getPersonId());
|
188
|
|
-
|
189
|
|
- // 报备有 10 天有效期
|
190
|
|
- QueryWrapper<TaRecommendCustomer> queryWrapper = new QueryWrapper<>();
|
191
|
|
- queryWrapper.eq("name", taRecommendCustomer.getName());
|
192
|
|
- queryWrapper.eq("phone", taRecommendCustomer.getPhone());
|
193
|
|
- queryWrapper.ge("report_date", LocalDateTime.now().minusDays(10));
|
194
|
|
- List<TaRecommendCustomer> result = taRecommendCustomerMapper.selectList(queryWrapper);
|
195
|
|
- if (null != result && result.size() > 0) {
|
196
|
|
- return ResponseBean.error("当前客户尚在保护期, 不能再次推荐", ResponseBean.ERROR_ILLEGAL_PARAMS);
|
197
|
|
- }
|
198
|
|
-
|
199
|
|
- int row = taRecommendCustomerMapper.insert(taRecommendCustomer);
|
200
|
|
- if (row < 1) {
|
201
|
|
- return ResponseBean.error("推荐客户失败", ResponseBean.ERROR_UNAVAILABLE);
|
202
|
|
- }
|
203
|
|
-
|
204
|
|
- // 找到销售经理,并推送消息
|
205
|
|
- TaPerson saleMan = taPersonMapper.getSalesExecutive();
|
206
|
|
- if (null != saleMan && !StringUtils.isEmpty(saleMan.getMiniOpenid())) {
|
207
|
|
- // 发送消息
|
208
|
|
- iMiniAppService.sendNewCustomerMessage(saleMan.getMiniOpenid(), CommConstant.MINIAPP_INDEX, taRecommendCustomer.getName(), taRecommendCustomer.getPhone(), "", taPerson.getName());
|
209
|
|
- }
|
210
|
|
-
|
211
|
|
- return ResponseBean.success(taRecommendCustomer);
|
212
|
|
- }
|
213
|
|
-
|
214
|
|
- String checkCustomerParams(JSONObject params) {
|
215
|
|
- if (null == params.getString("name")) {
|
216
|
|
- return "请设置客户姓名";
|
217
|
|
- }
|
218
|
|
- if (null == params.getString("phone")) {
|
219
|
|
- return "请设置客户电话";
|
220
|
|
- }
|
221
|
|
- if (null == params.getInteger("sex")) {
|
222
|
|
- return "请设置客户性别";
|
223
|
|
- }
|
224
|
|
- if (null == params.getString("intention")) {
|
225
|
|
- return "请设置意向楼盘";
|
226
|
|
- }
|
227
|
|
-
|
228
|
|
- return null;
|
229
|
|
- }
|
230
|
|
-
|
231
|
|
-
|
232
|
|
-
|
233
|
|
-
|
234
|
|
- List<TaPerson> getPersonsByOpenId(String openid) {
|
235
|
|
- return taPersonMapper.getPersonByOpenId(openid);
|
236
|
|
- }
|
237
|
|
-
|
238
|
|
- @Override
|
239
|
|
- public IPage<TaRecommendCustomer> getUnSignedCustomerList(int pageNumber, int pageSize,String building,String personId){
|
240
|
|
- QueryWrapper<TaRecommendCustomer>queryWrapper = new QueryWrapper<>();
|
241
|
|
-// queryWrapper.eq("building_id",building);
|
242
|
|
- queryWrapper.eq("realty_consultant",personId);
|
243
|
|
- queryWrapper.gt("status", CommConstant.MESSAGE_UNREAD);
|
244
|
|
- IPage<TaRecommendCustomer>page = new Page<>(pageNumber,pageSize);
|
245
|
|
- return taRecommendCustomerMapper.selectPage(page,queryWrapper);
|
246
|
|
- }
|
247
|
|
-
|
248
|
|
- @Override
|
249
|
|
- public IPage<TaRecommendCustomer> getCustomerList(int pageNumber, int pageSize,String building,String name,String tel,String consultName,String consultTel,String entryType,String verifyStatus){
|
250
|
|
- IPage<TaRecommendCustomer>page = new Page<>(pageNumber,pageSize);
|
251
|
|
- return taRecommendCustomerMapper.getCustomerList(page,building,name,tel,consultName,consultTel,entryType,verifyStatus);
|
252
|
|
- }
|
253
|
|
-
|
254
|
|
- @Override
|
255
|
|
- public TaRecommendCustomer getCustomerById(String customerId){
|
256
|
|
- return taRecommendCustomerMapper.getCustomerById(customerId);
|
257
|
|
- }
|
258
|
|
-
|
259
|
|
-
|
260
|
|
- @Override
|
261
|
|
- public TaRecommendCustomer getCustomerDetail(String customerId){
|
262
|
|
- String personId = taRecommendCustomerMapper.getCustomerPersonId(customerId);
|
263
|
|
- TaRecommendCustomer taRecommendCustomer = taRecommendCustomerMapper.getCustomerDetail(customerId);
|
264
|
|
- if(!StringUtils.isEmpty(personId)){
|
265
|
|
- taRecommendCustomer.setVisitRecords(taPersonVisitRecordMapper.visitRecordByPersonId(personId));
|
266
|
|
- taRecommendCustomer.setVisitTimes(taPersonVisitRecordMapper.visitRecordByPersonId(personId).size());
|
267
|
|
- }
|
268
|
|
- if(!StringUtils.isEmpty(taRecommendCustomer.getRealtyConsultant())){
|
269
|
|
- TaPerson consultant = taPersonMapper.getById(taRecommendCustomer.getRealtyConsultant());
|
270
|
|
- consultant.setProjects(taPersonMapper.getUserProjects(consultant.getPersonId()));
|
271
|
|
- taRecommendCustomer.setConsultant(consultant);
|
272
|
|
- }
|
273
|
|
- return taRecommendCustomer;
|
274
|
|
- }
|
275
|
|
-
|
276
|
|
- @Override
|
277
|
|
- public IPage<TaRecommendCustomer>getCustomersIRecommended(int pageNumber, int pageSize,String customerId,String building){
|
278
|
|
- String personId = taRecommendCustomerMapper.getCustomerPersonId(customerId);
|
279
|
|
- QueryWrapper<TaRecommendCustomer>queryWrapper = new QueryWrapper<>();
|
280
|
|
- queryWrapper.eq("person_id",personId);
|
281
|
|
-// queryWrapper.eq("building_id",building);
|
282
|
|
- queryWrapper.gt("status", CommConstant.MESSAGE_UNREAD);
|
283
|
|
- IPage<TaRecommendCustomer>page = new Page<>(pageNumber,pageSize);
|
284
|
|
- return taRecommendCustomerMapper.selectPage(page,queryWrapper);
|
285
|
|
- }
|
286
|
|
-
|
287
|
|
- @Override
|
288
|
|
- public TaRecommendCustomer newByPerson(TaPerson person) {
|
289
|
|
- // 没有手机号, 暂时不生成客户信息
|
290
|
|
- String phone = StringUtils.ifNull(person.getTel(), person.getPhone());
|
291
|
|
- if (StringUtils.isEmpty(phone)) {
|
292
|
|
- return null;
|
293
|
|
- }
|
294
|
|
-
|
295
|
|
- // 已经存在的, 随机返回一条记录
|
296
|
|
- List<TaRecommendCustomer> custs = getCustomerByPhone(phone);
|
297
|
|
- if (null != custs && custs.size() > 0) {
|
298
|
|
- return custs.get(0);
|
299
|
|
- }
|
300
|
|
-
|
301
|
|
- TaRecommendCustomer cust = new TaRecommendCustomer();
|
302
|
|
- cust.setName(StringUtils.ifNull(person.getName(), person.getNickname()));
|
303
|
|
- cust.setSex(null == person.getSex() ? str2Int(person.getGender()) : person.getSex());
|
304
|
|
- cust.setPhone(phone);
|
305
|
|
- cust.setPicture(StringUtils.ifNull(person.getPhoto(), person.getAvatarurl()));
|
306
|
|
- cust.setCountry(person.getCountry());
|
307
|
|
- cust.setCity(person.getCity());
|
308
|
|
- cust.setProvince(person.getProvince());
|
309
|
|
- // 审核同意
|
310
|
|
- cust.setVerifyStatus(CommConstant.VERIFY_AGREE);
|
311
|
|
- // 报备状态
|
312
|
|
- cust.setStatus(CommConstant.CUSTOMER_REPORT);
|
313
|
|
- // 当前日期
|
314
|
|
- cust.setReportDate(LocalDateTime.now());
|
315
|
|
-
|
316
|
|
- if (taRecommendCustomerMapper.insert(cust) > 0) {
|
317
|
|
- return cust;
|
318
|
|
- } else {
|
319
|
|
- log.error("依据人员新增推荐客户失败");
|
320
|
|
- return null;
|
321
|
|
- }
|
322
|
|
- }
|
323
|
|
-
|
324
|
|
- private List<TaRecommendCustomer> getCustomerByPhone(String phone) {
|
325
|
|
- QueryWrapper<TaRecommendCustomer> queryWrapper = new QueryWrapper<>();
|
326
|
|
- queryWrapper.eq("phone", phone);
|
327
|
|
- queryWrapper.gt("status", CommConstant.STATUS_DELETE);
|
328
|
|
- queryWrapper.orderByDesc("report_date");
|
329
|
|
-
|
330
|
|
- List<TaRecommendCustomer> custs = taRecommendCustomerMapper.selectList(queryWrapper);
|
331
|
|
- return custs;
|
332
|
|
- }
|
333
|
|
-
|
334
|
|
- private Integer str2Int(String str) {
|
335
|
|
- if (null == str) {
|
336
|
|
- return null;
|
337
|
|
- }
|
338
|
|
-
|
339
|
|
- try {
|
340
|
|
- return Integer.valueOf(str);
|
341
|
|
- } catch (Exception e) {
|
342
|
|
- return 0;
|
343
|
|
- }
|
344
|
|
- }
|
345
|
|
-}
|
|
1
|
+package com.huiju.estateagents.service.impl;
|
|
2
|
+
|
|
3
|
+import ch.qos.logback.core.status.StatusUtil;
|
|
4
|
+import com.alibaba.fastjson.JSONObject;
|
|
5
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
6
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
7
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
8
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
9
|
+import com.huiju.estateagents.base.ResponseBean;
|
|
10
|
+import com.huiju.estateagents.common.CommConstant;
|
|
11
|
+import com.huiju.estateagents.common.DateUtils;
|
|
12
|
+import com.huiju.estateagents.common.StringUtils;
|
|
13
|
+import com.huiju.estateagents.entity.TaPerson;
|
|
14
|
+import com.huiju.estateagents.entity.TaRecommendCustomer;
|
|
15
|
+import com.huiju.estateagents.mapper.TaPersonMapper;
|
|
16
|
+import com.huiju.estateagents.mapper.TaPersonVisitRecordMapper;
|
|
17
|
+import com.huiju.estateagents.mapper.TaRecommendCustomerMapper;
|
|
18
|
+import com.huiju.estateagents.service.IMiniAppService;
|
|
19
|
+import com.huiju.estateagents.service.ITaRecommendCustomerService;
|
|
20
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
21
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
22
|
+import org.springframework.stereotype.Service;
|
|
23
|
+
|
|
24
|
+import javax.naming.spi.ResolveResult;
|
|
25
|
+import java.time.LocalDateTime;
|
|
26
|
+import java.util.HashMap;
|
|
27
|
+import java.util.List;
|
|
28
|
+import java.util.Map;
|
|
29
|
+
|
|
30
|
+/**
|
|
31
|
+ * <p>
|
|
32
|
+ * 推荐客户表 服务实现类
|
|
33
|
+ * </p>
|
|
34
|
+ *
|
|
35
|
+ * @author jobob
|
|
36
|
+ * @since 2019-05-10
|
|
37
|
+ */
|
|
38
|
+@Service
|
|
39
|
+public class TaRecommendCustomerServiceImpl extends ServiceImpl<TaRecommendCustomerMapper, TaRecommendCustomer> implements ITaRecommendCustomerService {
|
|
40
|
+
|
|
41
|
+ @Autowired
|
|
42
|
+ TaPersonMapper taPersonMapper;
|
|
43
|
+
|
|
44
|
+ @Autowired
|
|
45
|
+ TaRecommendCustomerMapper taRecommendCustomerMapper;
|
|
46
|
+
|
|
47
|
+ @Autowired
|
|
48
|
+ IMiniAppService iMiniAppService;
|
|
49
|
+
|
|
50
|
+ @Autowired
|
|
51
|
+ TaPersonVisitRecordMapper taPersonVisitRecordMapper;
|
|
52
|
+
|
|
53
|
+ @Override
|
|
54
|
+ public ResponseBean getMyCustList(String openid, String keywords, int pageNumber, int pageSize) {
|
|
55
|
+ List<TaPerson> taPersons = getPersonsByOpenId(openid);
|
|
56
|
+ if (null == taPersons || taPersons.size() != 1) {
|
|
57
|
+ return ResponseBean.error("验证当前人员信息失败", ResponseBean.ERROR_UNAVAILABLE);
|
|
58
|
+ }
|
|
59
|
+
|
|
60
|
+ TaPerson taPerson = taPersons.get(0);
|
|
61
|
+
|
|
62
|
+ IPage<TaRecommendCustomer> page = new Page<>();
|
|
63
|
+ page.setCurrent(pageNumber);
|
|
64
|
+ page.setSize(pageSize);
|
|
65
|
+
|
|
66
|
+ QueryWrapper<TaRecommendCustomer> query = new QueryWrapper<>();
|
|
67
|
+ query.eq("recommend_person", taPerson.getPersonId());
|
|
68
|
+ query.like(null != keywords && "".equals(keywords.trim()), "name", keywords);
|
|
69
|
+ query.orderByDesc("report_date");
|
|
70
|
+
|
|
71
|
+ IPage<TaRecommendCustomer> result = taRecommendCustomerMapper.selectPage(page, query);
|
|
72
|
+ return ResponseBean.success(result);
|
|
73
|
+ }
|
|
74
|
+
|
|
75
|
+ @Override
|
|
76
|
+ public ResponseBean getCustDetail(String id) {
|
|
77
|
+ TaRecommendCustomer taRecommendCustomer = taRecommendCustomerMapper.selectById(id);
|
|
78
|
+
|
|
79
|
+ if (!StringUtils.isEmpty(taRecommendCustomer.getRealtyConsultant())) {
|
|
80
|
+ TaPerson taPerson = taPersonMapper.selectById(taRecommendCustomer.getRealtyConsultant());
|
|
81
|
+ if (null != taPerson) {
|
|
82
|
+ taRecommendCustomer.setConsultants(new HashMap<String, Object>() {{
|
|
83
|
+ put("name", taPerson.getName());
|
|
84
|
+ put("phone", taPerson.getTel());
|
|
85
|
+ put("photo", taPerson.getPhoto());
|
|
86
|
+ }});
|
|
87
|
+ }
|
|
88
|
+ }
|
|
89
|
+
|
|
90
|
+ return ResponseBean.success(taRecommendCustomer);
|
|
91
|
+ }
|
|
92
|
+
|
|
93
|
+ @Override
|
|
94
|
+ public ResponseBean updateCustByJSON(String paramStr) {
|
|
95
|
+ JSONObject params = JSONObject.parseObject(paramStr);
|
|
96
|
+ if (null == params) {
|
|
97
|
+ return ResponseBean.error("解析参数失败", ResponseBean.ERROR_ILLEGAL_PARAMS);
|
|
98
|
+ }
|
|
99
|
+
|
|
100
|
+ String checkResult = checkCustomerParams(params);
|
|
101
|
+ if (null != checkResult) {
|
|
102
|
+ return ResponseBean.error(checkResult, ResponseBean.ERROR_MISSING_PARAMS);
|
|
103
|
+ }
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+ UpdateWrapper<TaRecommendCustomer> wrapper = new UpdateWrapper<>();
|
|
107
|
+ wrapper.eq("customer_id", params.get("id"));
|
|
108
|
+ wrapper.set("name", params.get("name"));
|
|
109
|
+ wrapper.set("picture", params.get("picture"));
|
|
110
|
+ wrapper.set("phone", params.get("phone"));
|
|
111
|
+ wrapper.set("sex", params.get("sex"));
|
|
112
|
+ wrapper.set("describe", params.get("describe"));
|
|
113
|
+
|
|
114
|
+ String at = params.getString("appointmentTime");
|
|
115
|
+ if (!StringUtils.isEmpty(at)) {
|
|
116
|
+ wrapper.set("appointmentTime", DateUtils.day2LocalDateime(at));
|
|
117
|
+ }
|
|
118
|
+ wrapper.set("vistors", params.get("vistors"));
|
|
119
|
+ wrapper.set("explain", params.get("explain"));
|
|
120
|
+ wrapper.set("intention", params.get("intention"));
|
|
121
|
+ wrapper.set("realtyManageType", params.get("realtyManageType"));
|
|
122
|
+ wrapper.set("demandType", params.get("demandType"));
|
|
123
|
+ wrapper.set("priceRange", params.get("priceRange"));
|
|
124
|
+ wrapper.set("realtyConsultant", params.get("realtyConsultant"));
|
|
125
|
+
|
|
126
|
+ // todo 需要约定时间格式
|
|
127
|
+// wrapper.set("reportDate", params.get("reportDate"));
|
|
128
|
+
|
|
129
|
+ String status = params.getString("status");
|
|
130
|
+ if (null != status) {
|
|
131
|
+ wrapper.set("status", params.get("status"));
|
|
132
|
+ }
|
|
133
|
+
|
|
134
|
+ int row = taRecommendCustomerMapper.update(new TaRecommendCustomer(), wrapper);
|
|
135
|
+ if (row <= 0) {
|
|
136
|
+ return ResponseBean.error("更新客户信息失败", ResponseBean.ERROR_UNAVAILABLE);
|
|
137
|
+ }
|
|
138
|
+
|
|
139
|
+ return ResponseBean.success("更新客户信息成功");
|
|
140
|
+ }
|
|
141
|
+
|
|
142
|
+ @Override
|
|
143
|
+ public ResponseBean recommendCust(String paramStr, String openid) {
|
|
144
|
+ JSONObject params = JSONObject.parseObject(paramStr);
|
|
145
|
+ if (null == params) {
|
|
146
|
+ return ResponseBean.error("解析参数失败", ResponseBean.ERROR_ILLEGAL_PARAMS);
|
|
147
|
+ }
|
|
148
|
+ List<TaPerson> taPersons = getPersonsByOpenId(openid);
|
|
149
|
+ if (null == taPersons || taPersons.size() != 1) {
|
|
150
|
+ return ResponseBean.error("验证当前人员信息失败", ResponseBean.ERROR_UNAVAILABLE);
|
|
151
|
+ }
|
|
152
|
+ TaPerson taPerson = taPersons.get(0);
|
|
153
|
+
|
|
154
|
+ String checkResult = checkCustomerParams(params);
|
|
155
|
+ if (null != checkResult) {
|
|
156
|
+ return ResponseBean.error(checkResult, ResponseBean.ERROR_MISSING_PARAMS);
|
|
157
|
+ }
|
|
158
|
+
|
|
159
|
+ TaRecommendCustomer taRecommendCustomer = new TaRecommendCustomer();
|
|
160
|
+
|
|
161
|
+ taRecommendCustomer.setName(params.getString("name"));
|
|
162
|
+ taRecommendCustomer.setPicture(params.getString("picture"));
|
|
163
|
+ taRecommendCustomer.setPhone(params.getString("phone"));
|
|
164
|
+ taRecommendCustomer.setSex(params.getInteger("sex"));
|
|
165
|
+ taRecommendCustomer.setDescribe(params.getString("describe"));
|
|
166
|
+ taRecommendCustomer.setRealtyConsultant(params.getString("realtyConsultant"));
|
|
167
|
+
|
|
168
|
+ // 时间格式 yyyy-MM-dd
|
|
169
|
+ String at = params.getString("appointmentTime");
|
|
170
|
+ if (!StringUtils.isEmpty(at)) {
|
|
171
|
+ taRecommendCustomer.setAppointmentTime(DateUtils.day2LocalDateime(at));
|
|
172
|
+ }
|
|
173
|
+
|
|
174
|
+// taRecommendCustomer.setAppointmentTime((String) params.get("appointmentTime"));
|
|
175
|
+ taRecommendCustomer.setVisiteNum(params.getInteger("visiteNum"));
|
|
176
|
+ taRecommendCustomer.setIntention(params.getString("intention"));
|
|
177
|
+ taRecommendCustomer.setRealtyManageType(params.getString("realtyManageType"));
|
|
178
|
+ taRecommendCustomer.setDemandType(params.getString("demandType"));
|
|
179
|
+ taRecommendCustomer.setPriceRange(params.getString("priceRange"));
|
|
180
|
+
|
|
181
|
+ // 报备日期是今天
|
|
182
|
+ taRecommendCustomer.setReportDate(LocalDateTime.now());
|
|
183
|
+
|
|
184
|
+ String status = params.getString("status");
|
|
185
|
+ if (null == status) status = "1";
|
|
186
|
+ taRecommendCustomer.setStatus(status);
|
|
187
|
+ taRecommendCustomer.setRecommendPerson(taPerson.getPersonId());
|
|
188
|
+
|
|
189
|
+ // 报备有 10 天有效期
|
|
190
|
+ QueryWrapper<TaRecommendCustomer> queryWrapper = new QueryWrapper<>();
|
|
191
|
+ queryWrapper.eq("name", taRecommendCustomer.getName());
|
|
192
|
+ queryWrapper.eq("phone", taRecommendCustomer.getPhone());
|
|
193
|
+ queryWrapper.ge("report_date", LocalDateTime.now().minusDays(10));
|
|
194
|
+ List<TaRecommendCustomer> result = taRecommendCustomerMapper.selectList(queryWrapper);
|
|
195
|
+ if (null != result && result.size() > 0) {
|
|
196
|
+ return ResponseBean.error("当前客户尚在保护期, 不能再次推荐", ResponseBean.ERROR_ILLEGAL_PARAMS);
|
|
197
|
+ }
|
|
198
|
+
|
|
199
|
+ int row = taRecommendCustomerMapper.insert(taRecommendCustomer);
|
|
200
|
+ if (row < 1) {
|
|
201
|
+ return ResponseBean.error("推荐客户失败", ResponseBean.ERROR_UNAVAILABLE);
|
|
202
|
+ }
|
|
203
|
+
|
|
204
|
+ // 找到销售经理,并推送消息
|
|
205
|
+ TaPerson saleMan = taPersonMapper.getSalesExecutive();
|
|
206
|
+ if (null != saleMan && !StringUtils.isEmpty(saleMan.getMiniOpenid())) {
|
|
207
|
+ // 发送消息
|
|
208
|
+ iMiniAppService.sendNewCustomerMessage(saleMan.getMiniOpenid(), CommConstant.MINIAPP_INDEX, taRecommendCustomer.getName(), taRecommendCustomer.getPhone(), "", taPerson.getName());
|
|
209
|
+ }
|
|
210
|
+
|
|
211
|
+ return ResponseBean.success(taRecommendCustomer);
|
|
212
|
+ }
|
|
213
|
+
|
|
214
|
+ String checkCustomerParams(JSONObject params) {
|
|
215
|
+ if (null == params.getString("name")) {
|
|
216
|
+ return "请设置客户姓名";
|
|
217
|
+ }
|
|
218
|
+ if (null == params.getString("phone")) {
|
|
219
|
+ return "请设置客户电话";
|
|
220
|
+ }
|
|
221
|
+ if (null == params.getInteger("sex")) {
|
|
222
|
+ return "请设置客户性别";
|
|
223
|
+ }
|
|
224
|
+ if (null == params.getString("intention")) {
|
|
225
|
+ return "请设置意向楼盘";
|
|
226
|
+ }
|
|
227
|
+
|
|
228
|
+ return null;
|
|
229
|
+ }
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+ List<TaPerson> getPersonsByOpenId(String openid) {
|
|
235
|
+ return taPersonMapper.getPersonByOpenId(openid);
|
|
236
|
+ }
|
|
237
|
+
|
|
238
|
+ @Override
|
|
239
|
+ public IPage<TaRecommendCustomer> getUnSignedCustomerList(int pageNumber, int pageSize,String building,String personId){
|
|
240
|
+ QueryWrapper<TaRecommendCustomer>queryWrapper = new QueryWrapper<>();
|
|
241
|
+// queryWrapper.eq("building_id",building);
|
|
242
|
+ queryWrapper.eq("realty_consultant",personId);
|
|
243
|
+ queryWrapper.gt("status", CommConstant.MESSAGE_UNREAD);
|
|
244
|
+ IPage<TaRecommendCustomer>page = new Page<>(pageNumber,pageSize);
|
|
245
|
+ return taRecommendCustomerMapper.selectPage(page,queryWrapper);
|
|
246
|
+ }
|
|
247
|
+
|
|
248
|
+ @Override
|
|
249
|
+ public IPage<TaRecommendCustomer> getCustomerList(int pageNumber, int pageSize,String building,String name,String tel,String consultName,String consultTel,String entryType,String verifyStatus){
|
|
250
|
+ IPage<TaRecommendCustomer>page = new Page<>(pageNumber,pageSize);
|
|
251
|
+ return taRecommendCustomerMapper.getCustomerList(page,building,name,tel,consultName,consultTel,entryType,verifyStatus);
|
|
252
|
+ }
|
|
253
|
+
|
|
254
|
+ @Override
|
|
255
|
+ public TaRecommendCustomer getCustomerById(String customerId){
|
|
256
|
+ return taRecommendCustomerMapper.getCustomerById(customerId);
|
|
257
|
+ }
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+ @Override
|
|
261
|
+ public TaRecommendCustomer getCustomerDetail(String customerId){
|
|
262
|
+ String personId = taRecommendCustomerMapper.getCustomerPersonId(customerId);
|
|
263
|
+ TaRecommendCustomer taRecommendCustomer = taRecommendCustomerMapper.getCustomerDetail(customerId);
|
|
264
|
+ if(!StringUtils.isEmpty(personId)){
|
|
265
|
+ taRecommendCustomer.setVisitRecords(taPersonVisitRecordMapper.visitRecordByPersonId(personId));
|
|
266
|
+ taRecommendCustomer.setVisitTimes(taPersonVisitRecordMapper.visitRecordByPersonId(personId).size());
|
|
267
|
+ }
|
|
268
|
+ if(!StringUtils.isEmpty(taRecommendCustomer.getRealtyConsultant())){
|
|
269
|
+ TaPerson consultant = taPersonMapper.getById(taRecommendCustomer.getRealtyConsultant());
|
|
270
|
+ consultant.setProjects(taPersonMapper.getUserProjects(consultant.getPersonId()));
|
|
271
|
+ taRecommendCustomer.setConsultant(consultant);
|
|
272
|
+ }
|
|
273
|
+ return taRecommendCustomer;
|
|
274
|
+ }
|
|
275
|
+
|
|
276
|
+ @Override
|
|
277
|
+ public IPage<TaRecommendCustomer>getCustomersIRecommended(int pageNumber, int pageSize,String customerId,String building){
|
|
278
|
+ String personId = taRecommendCustomerMapper.getCustomerPersonId(customerId);
|
|
279
|
+ QueryWrapper<TaRecommendCustomer>queryWrapper = new QueryWrapper<>();
|
|
280
|
+ queryWrapper.eq("person_id",personId);
|
|
281
|
+// queryWrapper.eq("building_id",building);
|
|
282
|
+ queryWrapper.gt("status", CommConstant.MESSAGE_UNREAD);
|
|
283
|
+ IPage<TaRecommendCustomer>page = new Page<>(pageNumber,pageSize);
|
|
284
|
+ return taRecommendCustomerMapper.selectPage(page,queryWrapper);
|
|
285
|
+ }
|
|
286
|
+
|
|
287
|
+ @Override
|
|
288
|
+ public TaRecommendCustomer newByPerson(TaPerson person) {
|
|
289
|
+ // 没有手机号, 暂时不生成客户信息
|
|
290
|
+ String phone = StringUtils.ifNull(person.getTel(), person.getPhone());
|
|
291
|
+ if (StringUtils.isEmpty(phone)) {
|
|
292
|
+ return null;
|
|
293
|
+ }
|
|
294
|
+
|
|
295
|
+ // 已经存在的, 随机返回一条记录
|
|
296
|
+ List<TaRecommendCustomer> custs = getCustomerByPhone(phone);
|
|
297
|
+ if (null != custs && custs.size() > 0) {
|
|
298
|
+ return custs.get(0);
|
|
299
|
+ }
|
|
300
|
+
|
|
301
|
+ TaRecommendCustomer cust = new TaRecommendCustomer();
|
|
302
|
+ cust.setName(StringUtils.ifNull(person.getName(), person.getNickname()));
|
|
303
|
+ cust.setSex(null == person.getSex() ? str2Int(person.getGender()) : person.getSex());
|
|
304
|
+ cust.setPhone(phone);
|
|
305
|
+ cust.setPicture(StringUtils.ifNull(person.getPhoto(), person.getAvatarurl()));
|
|
306
|
+ cust.setCountry(person.getCountry());
|
|
307
|
+ cust.setCity(person.getCity());
|
|
308
|
+ cust.setProvince(person.getProvince());
|
|
309
|
+ // 审核同意
|
|
310
|
+ cust.setVerifyStatus(CommConstant.VERIFY_AGREE);
|
|
311
|
+ // 报备状态
|
|
312
|
+ cust.setStatus(CommConstant.CUSTOMER_REPORT);
|
|
313
|
+ // 当前日期
|
|
314
|
+ cust.setReportDate(LocalDateTime.now());
|
|
315
|
+
|
|
316
|
+ if (taRecommendCustomerMapper.insert(cust) > 0) {
|
|
317
|
+ return cust;
|
|
318
|
+ } else {
|
|
319
|
+ log.error("依据人员新增推荐客户失败");
|
|
320
|
+ return null;
|
|
321
|
+ }
|
|
322
|
+ }
|
|
323
|
+
|
|
324
|
+ private List<TaRecommendCustomer> getCustomerByPhone(String phone) {
|
|
325
|
+ QueryWrapper<TaRecommendCustomer> queryWrapper = new QueryWrapper<>();
|
|
326
|
+ queryWrapper.eq("phone", phone);
|
|
327
|
+ queryWrapper.gt("status", CommConstant.STATUS_DELETE);
|
|
328
|
+ queryWrapper.orderByDesc("report_date");
|
|
329
|
+
|
|
330
|
+ List<TaRecommendCustomer> custs = taRecommendCustomerMapper.selectList(queryWrapper);
|
|
331
|
+ return custs;
|
|
332
|
+ }
|
|
333
|
+
|
|
334
|
+ private Integer str2Int(String str) {
|
|
335
|
+ if (null == str) {
|
|
336
|
+ return null;
|
|
337
|
+ }
|
|
338
|
+
|
|
339
|
+ try {
|
|
340
|
+ return Integer.valueOf(str);
|
|
341
|
+ } catch (Exception e) {
|
|
342
|
+ return 0;
|
|
343
|
+ }
|
|
344
|
+ }
|
|
345
|
+}
|