|
|
@@ -1,10 +1,14 @@
|
|
|
package com.fs.qw.service.impl;
|
|
|
|
|
|
import com.fs.common.exception.CustomException;
|
|
|
+import com.fs.company.domain.CompanyDept;
|
|
|
import com.fs.company.domain.CompanyUser;
|
|
|
+import com.fs.company.mapper.CompanyDeptMapper;
|
|
|
import com.fs.his.domain.FsImportMember;
|
|
|
import com.fs.his.mapper.FsImportMemberMapper;
|
|
|
import com.fs.qw.domain.FsCompanyCustomer;
|
|
|
+import com.fs.qw.domain.FsCompanyCustomerLog;
|
|
|
+import com.fs.qw.mapper.FsCompanyCustomerLogMapper;
|
|
|
import com.fs.qw.mapper.FsCompanyCustomerMapper;
|
|
|
import com.fs.qw.param.TransferCustomerParam;
|
|
|
import com.fs.qw.service.IFsCompanyCustomerService;
|
|
|
@@ -16,6 +20,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.Collections;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
@@ -30,9 +35,15 @@ public class FsCompanyCustomerServiceImpl implements IFsCompanyCustomerService {
|
|
|
@Autowired
|
|
|
private FsCompanyCustomerMapper fsCompanyCustomerMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private FsCompanyCustomerLogMapper companyCustomerLogMapper;
|
|
|
+
|
|
|
@Autowired
|
|
|
private FsImportMemberMapper importMemberMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private CompanyDeptMapper companyDeptMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public FsCompanyCustomer selectFsCompanyCustomerById(Long id) {
|
|
|
return fsCompanyCustomerMapper.selectFsCompanyCustomerById(id);
|
|
|
@@ -44,22 +55,38 @@ public class FsCompanyCustomerServiceImpl implements IFsCompanyCustomerService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public int insertFsCompanyCustomer(FsCompanyCustomer customer) {
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public int insertFsCompanyCustomer(FsCompanyCustomer customer,CompanyUser companyUser) {
|
|
|
try {
|
|
|
customer.setClaimStatus(BigDecimal.ONE.intValue());
|
|
|
- return fsCompanyCustomerMapper.insertFsCompanyCustomer(customer);
|
|
|
+ setCompleteStatus(customer);
|
|
|
+ int result=fsCompanyCustomerMapper.insertFsCompanyCustomer(customer);
|
|
|
+ //单独新增也需要增加认领日志
|
|
|
+ FsCompanyCustomerLog claimLog = new FsCompanyCustomerLog();
|
|
|
+ claimLog.setCompanyCustomerId(customer.getId());
|
|
|
+ claimLog.setCompanyUserId(companyUser.getUserId());
|
|
|
+ claimLog.setCompanyUserName(companyUser.getNickName());
|
|
|
+ claimLog.setDeptId(companyUser.getDeptId());
|
|
|
+ CompanyDept companyDept = companyDeptMapper.selectCompanyDeptById(companyUser.getDeptId());
|
|
|
+ if (companyDept!=null&&companyDept.getDeptName()!=null){
|
|
|
+ claimLog.setDeptName(companyDept.getDeptName());
|
|
|
+ }
|
|
|
+ //增加认领记录
|
|
|
+ companyCustomerLogMapper.insertFsCompanyCustomerLog(claimLog);
|
|
|
+ return result;
|
|
|
} catch (Exception e) {
|
|
|
// 判断是否为唯一键冲突(电话号码重复)
|
|
|
if (isDuplicatePhoneException(e)) {
|
|
|
throw new CustomException("电话号码已存在");
|
|
|
}
|
|
|
// 其他异常统一提示
|
|
|
+ log.error("添加客户失败", e);
|
|
|
throw new CustomException("添加失败,请联系管理员");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 判断异常是否为“电话号码重复”导致的唯一键冲突
|
|
|
+ * 根据异常判断是否为“电话号码重复”导致的唯一键冲突
|
|
|
*/
|
|
|
private boolean isDuplicatePhoneException(Exception e) {
|
|
|
Throwable cause = e;
|
|
|
@@ -76,17 +103,34 @@ public class FsCompanyCustomerServiceImpl implements IFsCompanyCustomerService {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据填写内容设置客户信息表的完善状态
|
|
|
+ */
|
|
|
+ private void setCompleteStatus(FsCompanyCustomer customer) {
|
|
|
+ // 获取用户填写内容
|
|
|
+ String allergyHistory = customer.getAllergyHistory();
|
|
|
+ String presentIllness = customer.getPresentIllness();
|
|
|
+ String currentMedication = customer.getCurrentMedication();
|
|
|
+ Date appointmentTime = customer.getAppointmentTime();
|
|
|
+ //只要有一个为空或空字符串,就设置completeStatus为0
|
|
|
+ if (allergyHistory == null || allergyHistory.isEmpty()
|
|
|
+ || presentIllness == null || presentIllness.isEmpty()
|
|
|
+ || currentMedication == null || currentMedication.isEmpty()
|
|
|
+ || appointmentTime == null
|
|
|
+ ) {
|
|
|
+ customer.setCompleteStatus(BigDecimal.ZERO.intValue());//完善状态,0:未完善
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ customer.setCompleteStatus(BigDecimal.ONE.intValue());//完善状态,1:完善
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public int updateFsCompanyCustomer(FsCompanyCustomer fsCompanyCustomer) {
|
|
|
if (fsCompanyCustomer.getPhone()!=null&&fsCompanyCustomer.getPhone().contains("*")){
|
|
|
//若提交的号码是脱敏的号码,则不需要更新号码
|
|
|
fsCompanyCustomer.setPhone(null);
|
|
|
}
|
|
|
- //更新之前查询一下
|
|
|
- FsCompanyCustomer oldCustomer = selectFsCompanyCustomerById(fsCompanyCustomer.getId());
|
|
|
- if(oldCustomer.getCompanyUserId()!=null&&oldCustomer.getCompanyUserId()!=fsCompanyCustomer.getCompanyUserId()){
|
|
|
- throw new CustomException("网络繁忙!请稍后再试");
|
|
|
- }
|
|
|
+ setCompleteStatus(fsCompanyCustomer);
|
|
|
return fsCompanyCustomerMapper.updateFsCompanyCustomer(fsCompanyCustomer);
|
|
|
}
|
|
|
|
|
|
@@ -119,19 +163,12 @@ public class FsCompanyCustomerServiceImpl implements IFsCompanyCustomerService {
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public int claimCustomer(FsCompanyCustomer fsCompanyCustomer, CompanyUser companyUser) {
|
|
|
- if (fsCompanyCustomer.getPhone()!=null&&fsCompanyCustomer.getPhone().contains("*")){
|
|
|
- //若提交的号码是脱敏的号码,则不需要更新号码
|
|
|
- fsCompanyCustomer.setPhone(null);
|
|
|
- }
|
|
|
// 使用行锁查询客户信息(阻塞直到获得锁)
|
|
|
FsCompanyCustomer oldCustomer = fsCompanyCustomerMapper.selectByIdForUpdate(fsCompanyCustomer.getId());
|
|
|
- if(oldCustomer.getCompanyUserId()!=null){
|
|
|
- throw new CustomException("客户已被其它销售认领!请刷新后重试");
|
|
|
- }
|
|
|
-
|
|
|
- if (oldCustomer.getImportMemberId()==null){
|
|
|
- log.error("销售认领客户数据异常,客户信息id:{}",oldCustomer.getId());
|
|
|
- throw new CustomException("网络繁忙!请稍后再试");
|
|
|
+ //校验认领号码与客户号码是否一致
|
|
|
+ if (!fsCompanyCustomer.getClaimPhone().equals(oldCustomer.getPhone())){
|
|
|
+ log.error("认领号码:{},客户号码:{}",fsCompanyCustomer.getClaimPhone(),oldCustomer.getPhone());
|
|
|
+ throw new CustomException("认领号码与客户号码不一致,请重试");
|
|
|
}
|
|
|
FsImportMember fsImportMember=new FsImportMember();
|
|
|
fsImportMember.setId(oldCustomer.getImportMemberId());
|
|
|
@@ -139,6 +176,18 @@ public class FsCompanyCustomerServiceImpl implements IFsCompanyCustomerService {
|
|
|
fsImportMember.setCompanyUserId(companyUser.getUserId());
|
|
|
//更新关联的导入会员表信息
|
|
|
importMemberMapper.updateFsImportMember(fsImportMember);
|
|
|
+
|
|
|
+ FsCompanyCustomerLog claimLog = new FsCompanyCustomerLog();
|
|
|
+ claimLog.setCompanyCustomerId(fsCompanyCustomer.getId());
|
|
|
+ claimLog.setCompanyUserId(companyUser.getUserId());
|
|
|
+ claimLog.setCompanyUserName(companyUser.getNickName());
|
|
|
+ claimLog.setDeptId(companyUser.getDeptId());
|
|
|
+ CompanyDept companyDept = companyDeptMapper.selectCompanyDeptById(companyUser.getDeptId());
|
|
|
+ if (companyDept!=null&&companyDept.getDeptName()!=null){
|
|
|
+ claimLog.setDeptName(companyDept.getDeptName());
|
|
|
+ }
|
|
|
+ //增加认领记录
|
|
|
+ companyCustomerLogMapper.insertFsCompanyCustomerLog(claimLog);
|
|
|
fsCompanyCustomer.setClaimStatus(BigDecimal.ONE.intValue());//已认领
|
|
|
return fsCompanyCustomerMapper.updateFsCompanyCustomer(fsCompanyCustomer);
|
|
|
}
|