|
|
|
|
package com.example.web.service;
|
|
|
|
|
|
|
|
|
|
import com.example.web.entity.Contacts;
|
|
|
|
|
import com.example.web.entity.Users;
|
|
|
|
|
import com.example.web.mapper.ContactsMapper;
|
|
|
|
|
import com.example.web.mapper.SupplyContactsMapper;
|
|
|
|
|
import com.example.web.mapper.SupplyUsersMapper;
|
|
|
|
|
import com.example.web.mapper.UsersMapper;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
public class FollowUpService {
|
|
|
|
|
|
|
|
|
|
private final ContactsMapper contactsMapper;
|
|
|
|
|
private final UsersMapper usersMapper;
|
|
|
|
|
private final SupplyContactsMapper supplyContactsMapper;
|
|
|
|
|
private final SupplyUsersMapper supplyUsersMapper;
|
|
|
|
|
|
|
|
|
|
public FollowUpService(ContactsMapper contactsMapper, UsersMapper usersMapper, SupplyContactsMapper supplyContactsMapper, SupplyUsersMapper supplyUsersMapper) {
|
|
|
|
|
this.contactsMapper = contactsMapper;
|
|
|
|
|
this.usersMapper = usersMapper;
|
|
|
|
|
this.supplyContactsMapper = supplyContactsMapper;
|
|
|
|
|
this.supplyUsersMapper = supplyUsersMapper;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据电话号码查询跟进信息
|
|
|
|
|
* @param phoneNumber 电话号码
|
|
|
|
|
* @return 跟进信息
|
|
|
|
|
*/
|
|
|
|
|
public String getFollowUpByPhone(String phoneNumber) {
|
|
|
|
|
try {
|
|
|
|
|
// 先尝试在contacts表中查询
|
|
|
|
|
String followup = contactsMapper.getFollowUpByPhone(phoneNumber);
|
|
|
|
|
if (followup != null) {
|
|
|
|
|
return followup;
|
|
|
|
|
}
|
|
|
|
|
// 如果contacts表中没有,尝试在users表中查询
|
|
|
|
|
return supplyUsersMapper.getFollowUpByPhone(phoneNumber);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 保存跟进信息
|
|
|
|
|
* @param phoneNumber 电话号码
|
|
|
|
|
* @param followup 跟进信息
|
|
|
|
|
* @return 是否成功
|
|
|
|
|
*/
|
|
|
|
|
public boolean saveFollowUp(String phoneNumber, String followup) {
|
|
|
|
|
try {
|
|
|
|
|
// 获取当前时间作为updated_at
|
|
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
|
|
|
|
|
|
|
// 先尝试在contacts表中保存
|
|
|
|
|
if (contactsMapper.updateFollowUpByPhone(phoneNumber, followup, now) > 0) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
// 如果contacts表中没有,尝试在users表中保存
|
|
|
|
|
return supplyUsersMapper.updateFollowUpByPhone(phoneNumber, followup, now) > 0;
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|