|
@@ -29,12 +29,17 @@ import org.apache.commons.collections.CollectionUtils;
|
29
|
29
|
import org.slf4j.Logger;
|
30
|
30
|
import org.slf4j.LoggerFactory;
|
31
|
31
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
32
|
+import org.springframework.cglib.beans.BeanCopier;
|
32
|
33
|
import org.springframework.stereotype.Service;
|
33
|
34
|
|
34
|
35
|
import java.time.LocalDateTime;
|
|
36
|
+import java.util.ArrayList;
|
35
|
37
|
import java.util.HashMap;
|
36
|
38
|
import java.util.List;
|
37
|
39
|
import java.util.Map;
|
|
40
|
+import java.util.stream.Collector;
|
|
41
|
+import java.util.stream.Collectors;
|
|
42
|
+import java.util.stream.Stream;
|
38
|
43
|
|
39
|
44
|
/**
|
40
|
45
|
* <p>
|
|
@@ -168,6 +173,132 @@ public class TaRecommendCustomerServiceImpl extends ServiceImpl<TaRecommendCusto
|
168
|
173
|
return taRecommendCustomerMapper.getConsultantCustomerList(userId, personId, buildingId, orgId);
|
169
|
174
|
}
|
170
|
175
|
|
|
176
|
+ @Override
|
|
177
|
+ public List<TaRecommendCustomer> newCustomer(Integer orgId, TaPerson person, TaPerson recommender, TaUser consultant, TaBuilding building, TaCustomerFrom from) throws Exception {
|
|
178
|
+ // 如果置业推荐了非自己绑定楼盘, 会生成 2 条客户记录
|
|
179
|
+ List<TaRecommendCustomer> result = new ArrayList<>();
|
|
180
|
+ List<TaBuilding> consultBuildings = null;
|
|
181
|
+ List<String> consultBuildingIds = null;
|
|
182
|
+ if (null != consultant) {
|
|
183
|
+ consultBuildings = taPersonBuildingMapper.getBuildingsOf(consultant.getUserId().toString());
|
|
184
|
+ if (null != consultBuildings && consultBuildings.size() > 0) {
|
|
185
|
+ consultBuildingIds = consultBuildings.stream().map(TaBuilding::getBuildingId).collect(Collectors.toList());
|
|
186
|
+ }
|
|
187
|
+ }
|
|
188
|
+
|
|
189
|
+ Map<String, Number> checkNum = taRecommendCustomerMapper.checkCustomerBy(orgId, person.getPersonId(), consultBuildingIds, null != building ? building.getBuildingId() : null);
|
|
190
|
+ boolean hasOrgCust = checkNum.get("orgNum").intValue() > 0;
|
|
191
|
+ boolean hasConsultCust = checkNum.get("consultNum").intValue() > 0;
|
|
192
|
+ boolean hasBuildingCust = checkNum.get("buildingNum").intValue() > 0;
|
|
193
|
+ LocalDateTime now = LocalDateTime.now();
|
|
194
|
+
|
|
195
|
+ // 控制是否需要插入小程序级别公客
|
|
196
|
+ boolean inserted = false;
|
|
197
|
+ // 置业与楼盘是否有关联关系
|
|
198
|
+ boolean builingAssociated = false;
|
|
199
|
+
|
|
200
|
+ // 私客
|
|
201
|
+ if (null != consultant && !hasConsultCust && null != consultBuildings) {
|
|
202
|
+ TaBuilding taBuilding = null;
|
|
203
|
+ if (consultBuildingIds.contains(null != building ? building.getBuildingId() : null)) {
|
|
204
|
+ taBuilding = building;
|
|
205
|
+ builingAssociated = true;
|
|
206
|
+ } else {
|
|
207
|
+ taBuilding = consultBuildings.get(0);
|
|
208
|
+ }
|
|
209
|
+
|
|
210
|
+ TaRecommendCustomer customer = copyFromPerosn(person, new TaRecommendCustomer());
|
|
211
|
+ fillSomeFieldsOfCustomer(customer, recommender, now);
|
|
212
|
+ customer.setBuildingId(taBuilding.getBuildingId());
|
|
213
|
+ customer.setBuildingName(taBuilding.getBuildingName());
|
|
214
|
+ customer.setRealtyConsultant(consultant.getUserId().toString());
|
|
215
|
+ taRecommendCustomerMapper.insert(customer);
|
|
216
|
+ result.add(customer);
|
|
217
|
+ inserted = true;
|
|
218
|
+
|
|
219
|
+ TaCustomerFrom customerFrom = copyPropertiesFrom(from);
|
|
220
|
+ customerFrom.setCustomerId(customer.getCustomerId());
|
|
221
|
+ customerFrom.setSharePersonId(recommender.getPersonId());
|
|
222
|
+ customerFrom.setSharePersonName(StringUtils.ifNull(recommender.getName(), recommender.getNickname()));
|
|
223
|
+ customerFrom.setBuildingId(taBuilding.getBuildingId());
|
|
224
|
+ customerFrom.setBuildingName(taBuilding.getBuildingName());
|
|
225
|
+ customerFrom.setIsOrgFirst(!hasOrgCust);
|
|
226
|
+ customerFrom.setIsProjectFirst(true);
|
|
227
|
+ customerFrom.setCreateDate(now);
|
|
228
|
+ taCustomerFromMapper.insert(customerFrom);
|
|
229
|
+ }
|
|
230
|
+
|
|
231
|
+ // 项目公客
|
|
232
|
+ if (null != building && !hasBuildingCust && !builingAssociated) {
|
|
233
|
+ TaRecommendCustomer customer = copyFromPerosn(person, new TaRecommendCustomer());
|
|
234
|
+ fillSomeFieldsOfCustomer(customer, recommender, now);
|
|
235
|
+ customer.setBuildingId(building.getBuildingId());
|
|
236
|
+ taRecommendCustomerMapper.insert(customer);
|
|
237
|
+ result.add(customer);
|
|
238
|
+ inserted = true;
|
|
239
|
+
|
|
240
|
+ TaCustomerFrom customerFrom = copyPropertiesFrom(from);
|
|
241
|
+ customerFrom.setCustomerId(customer.getCustomerId());
|
|
242
|
+ customerFrom.setSharePersonId(null == recommender ? null : recommender.getPersonId());
|
|
243
|
+ customerFrom.setSharePersonName(null == recommender ? null : StringUtils.ifNull(recommender.getName(), recommender.getNickname()));
|
|
244
|
+ customerFrom.setBuildingId(building.getBuildingId());
|
|
245
|
+ customerFrom.setBuildingName(building.getBuildingName());
|
|
246
|
+ customerFrom.setIsOrgFirst(!hasOrgCust);
|
|
247
|
+ customerFrom.setIsProjectFirst(true);
|
|
248
|
+ customerFrom.setCreateDate(now);
|
|
249
|
+ taCustomerFromMapper.insert(customerFrom);
|
|
250
|
+ }
|
|
251
|
+
|
|
252
|
+ // 小程序公客
|
|
253
|
+ if (!hasOrgCust && !inserted) {
|
|
254
|
+ TaRecommendCustomer customer = copyFromPerosn(person, new TaRecommendCustomer());
|
|
255
|
+ fillSomeFieldsOfCustomer(customer, recommender, now);
|
|
256
|
+ taRecommendCustomerMapper.insert(customer);
|
|
257
|
+ result.add(customer);
|
|
258
|
+
|
|
259
|
+ TaCustomerFrom customerFrom = copyPropertiesFrom(from);
|
|
260
|
+ customerFrom.setCustomerId(customer.getCustomerId());
|
|
261
|
+ customerFrom.setSharePersonId(null == recommender ? null : recommender.getPersonId());
|
|
262
|
+ customerFrom.setSharePersonName(null == recommender ? null : StringUtils.ifNull(recommender.getName(), recommender.getNickname()));
|
|
263
|
+ customerFrom.setIsOrgFirst(true);
|
|
264
|
+ customerFrom.setIsProjectFirst(false);
|
|
265
|
+ customerFrom.setCreateDate(now);
|
|
266
|
+ taCustomerFromMapper.insert(customerFrom);
|
|
267
|
+ }
|
|
268
|
+
|
|
269
|
+ return result;
|
|
270
|
+ }
|
|
271
|
+
|
|
272
|
+ private void fillSomeFieldsOfCustomer(TaRecommendCustomer customer, TaPerson recommender, LocalDateTime now) {
|
|
273
|
+ customer.setVerifyStatus(CommConstant.VERIFY_AGREE);
|
|
274
|
+ customer.setStatus(CommConstant.CUSTOMER_REPORT);
|
|
275
|
+ customer.setEntryType(null == recommender ? CommConstant.ENTRY_VOLUNTEER : CommConstant.ENTRY_INPUT);
|
|
276
|
+ customer.setCreateDate(now);
|
|
277
|
+ customer.setReportDate(now);
|
|
278
|
+ customer.setRecommendPerson(null == recommender ? null : recommender.getPersonId());
|
|
279
|
+ }
|
|
280
|
+
|
|
281
|
+ private TaRecommendCustomer copyFromPerosn(TaPerson person, TaRecommendCustomer cust) {
|
|
282
|
+ cust.setPersonId(person.getPersonId());
|
|
283
|
+ cust.setName(StringUtils.ifNull(person.getName(), person.getNickname()));
|
|
284
|
+ cust.setSex(null == person.getSex() ? str2Int(person.getGender()) : person.getSex());
|
|
285
|
+ cust.setPhone(StringUtils.ifNull(person.getPhone(), person.getTel()));
|
|
286
|
+ cust.setPicture(StringUtils.ifNull(person.getAvatarurl(), person.getPhoto()));
|
|
287
|
+ cust.setCountry(person.getCountry());
|
|
288
|
+ cust.setCity(person.getCity());
|
|
289
|
+ cust.setProvince(person.getProvince());
|
|
290
|
+ cust.setOrgId(person.getOrgId());
|
|
291
|
+
|
|
292
|
+ return cust;
|
|
293
|
+ }
|
|
294
|
+
|
|
295
|
+ private TaCustomerFrom copyPropertiesFrom(TaCustomerFrom from) {
|
|
296
|
+ BeanCopier copier = BeanCopier.create(TaCustomerFrom.class, TaCustomerFrom.class, false);
|
|
297
|
+ TaCustomerFrom to = new TaCustomerFrom();
|
|
298
|
+ copier.copy(from, to, null);
|
|
299
|
+ return to;
|
|
300
|
+ }
|
|
301
|
+
|
171
|
302
|
@Override
|
172
|
303
|
public ResponseBean getCustDetail(String id) {
|
173
|
304
|
TaRecommendCustomer taRecommendCustomer = taRecommendCustomerMapper.selectById(id);
|