|
@@ -2,28 +2,35 @@ package com.fs.qw.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.fs.common.exception.ServiceException;
|
|
import com.fs.common.exception.ServiceException;
|
|
|
|
+import com.fs.common.utils.StringUtils;
|
|
import com.fs.company.domain.Company;
|
|
import com.fs.company.domain.Company;
|
|
import com.fs.company.domain.CompanyUser;
|
|
import com.fs.company.domain.CompanyUser;
|
|
import com.fs.company.mapper.CompanyMapper;
|
|
import com.fs.company.mapper.CompanyMapper;
|
|
import com.fs.company.mapper.CompanyUserMapper;
|
|
import com.fs.company.mapper.CompanyUserMapper;
|
|
import com.fs.qw.domain.*;
|
|
import com.fs.qw.domain.*;
|
|
|
|
+import com.fs.qw.dto.CompanyTransferAuditDTO;
|
|
import com.fs.qw.dto.CompanyTransferDTO;
|
|
import com.fs.qw.dto.CompanyTransferDTO;
|
|
import com.fs.qw.mapper.QwCompanyMapper;
|
|
import com.fs.qw.mapper.QwCompanyMapper;
|
|
import com.fs.qw.mapper.QwExternalContactMapper;
|
|
import com.fs.qw.mapper.QwExternalContactMapper;
|
|
import com.fs.qw.mapper.QwExternalContactTransferCompanyAuditMapper;
|
|
import com.fs.qw.mapper.QwExternalContactTransferCompanyAuditMapper;
|
|
import com.fs.qw.mapper.QwUserMapper;
|
|
import com.fs.qw.mapper.QwUserMapper;
|
|
-import com.fs.qw.param.QwExternalContactParam;
|
|
|
|
import com.fs.qw.service.IQwExternalContactTransferCompanyAuditService;
|
|
import com.fs.qw.service.IQwExternalContactTransferCompanyAuditService;
|
|
import com.fs.qw.service.IQwExternalContactTransferCompanyAuditUserService;
|
|
import com.fs.qw.service.IQwExternalContactTransferCompanyAuditUserService;
|
|
|
|
+import com.fs.qwApi.domain.QwGetTransferResult;
|
|
|
|
+import com.fs.qwApi.domain.QwTransferCustomerResignedResult;
|
|
|
|
+import com.fs.qwApi.domain.QwTransferCustomerResult;
|
|
|
|
+import com.fs.qwApi.domain.inner.QwCustomer;
|
|
|
|
+import com.fs.qwApi.param.QwGetTransferParam;
|
|
|
|
+import com.fs.qwApi.param.QwTransferCustomerParam;
|
|
|
|
+import com.fs.qwApi.param.QwTransferCustomerResignedParam;
|
|
|
|
+import com.fs.qwApi.service.QwApiService;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.Collections;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Objects;
|
|
|
|
|
|
+import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@@ -42,6 +49,8 @@ public class QwExternalContactTransferCompanyAuditServiceImpl extends ServiceImp
|
|
private CompanyUserMapper companyUserMapper;
|
|
private CompanyUserMapper companyUserMapper;
|
|
@Resource
|
|
@Resource
|
|
private IQwExternalContactTransferCompanyAuditUserService auditUserService;
|
|
private IQwExternalContactTransferCompanyAuditUserService auditUserService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private QwApiService qwApiService;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 添加待审核记录
|
|
* 添加待审核记录
|
|
@@ -49,15 +58,19 @@ public class QwExternalContactTransferCompanyAuditServiceImpl extends ServiceImp
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Override
|
|
@Override
|
|
public void addAudit(CompanyTransferDTO param, Long companyId, String userName) {
|
|
public void addAudit(CompanyTransferDTO param, Long companyId, String userName) {
|
|
|
|
+ if (param.getTransferType() != 1 && param.getTransferType() != 2) {
|
|
|
|
+ throw new ServiceException("转接类型错误");
|
|
|
|
+ }
|
|
|
|
+
|
|
QwUser qwUser = qwUserMapper.selectQwUserById(param.getQwUserId());
|
|
QwUser qwUser = qwUserMapper.selectQwUserById(param.getQwUserId());
|
|
|
|
|
|
if (Objects.isNull(qwUser)) {
|
|
if (Objects.isNull(qwUser)) {
|
|
throw new ServiceException("接替员工不存在");
|
|
throw new ServiceException("接替员工不存在");
|
|
}
|
|
}
|
|
|
|
|
|
-// if (qwUser.getCompanyId().equals(companyId)) {
|
|
|
|
-// throw new ServiceException("接替员工不能为本公司员工");
|
|
|
|
-// }
|
|
|
|
|
|
+ if (qwUser.getCompanyId().equals(companyId)) {
|
|
|
|
+ throw new ServiceException("接替员工不能为本公司员工");
|
|
|
|
+ }
|
|
|
|
|
|
List<QwExternalContact> qwExternalContacts = new ArrayList<>();
|
|
List<QwExternalContact> qwExternalContacts = new ArrayList<>();
|
|
// 为1转移员工下客户 其余转移转递的客户
|
|
// 为1转移员工下客户 其余转移转递的客户
|
|
@@ -93,6 +106,7 @@ public class QwExternalContactTransferCompanyAuditServiceImpl extends ServiceImp
|
|
CompanyUser companyUser = companyUserMapper.selectCompanyUserById(qwUser.getCompanyUserId());
|
|
CompanyUser companyUser = companyUserMapper.selectCompanyUserById(qwUser.getCompanyUserId());
|
|
|
|
|
|
QwExternalContactTransferCompanyAudit audit = new QwExternalContactTransferCompanyAudit();
|
|
QwExternalContactTransferCompanyAudit audit = new QwExternalContactTransferCompanyAudit();
|
|
|
|
+ audit.setTransferType(param.getType());
|
|
audit.setQwCompanyId(qwCompany.getId());
|
|
audit.setQwCompanyId(qwCompany.getId());
|
|
audit.setCorpId(qwCompany.getCorpId());
|
|
audit.setCorpId(qwCompany.getCorpId());
|
|
audit.setCorpName(qwCompany.getCorpName());
|
|
audit.setCorpName(qwCompany.getCorpName());
|
|
@@ -106,6 +120,7 @@ public class QwExternalContactTransferCompanyAuditServiceImpl extends ServiceImp
|
|
audit.setContent(param.getContent());
|
|
audit.setContent(param.getContent());
|
|
audit.setCreateTime(LocalDateTime.now());
|
|
audit.setCreateTime(LocalDateTime.now());
|
|
audit.setCreateBy(userName);
|
|
audit.setCreateBy(userName);
|
|
|
|
+ audit.setOperCompanyId(companyId);
|
|
baseMapper.insert(audit);
|
|
baseMapper.insert(audit);
|
|
|
|
|
|
List<QwExternalContactTransferCompanyAuditUser> auditUserList = qwExternalContacts
|
|
List<QwExternalContactTransferCompanyAuditUser> auditUserList = qwExternalContacts
|
|
@@ -144,4 +159,180 @@ public class QwExternalContactTransferCompanyAuditServiceImpl extends ServiceImp
|
|
public List<QwExternalContactTransferCompanyAudit> selectQwExternalContactTransferCompanyAuditList(QwExternalContactTransferCompanyAudit param) {
|
|
public List<QwExternalContactTransferCompanyAudit> selectQwExternalContactTransferCompanyAuditList(QwExternalContactTransferCompanyAudit param) {
|
|
return baseMapper.selectQwExternalContactTransferCompanyAuditList(param);
|
|
return baseMapper.selectQwExternalContactTransferCompanyAuditList(param);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 记录审核
|
|
|
|
+ */
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ @Override
|
|
|
|
+ public void audit(CompanyTransferAuditDTO param, String userName) {
|
|
|
|
+ QwExternalContactTransferCompanyAudit auditInfo = baseMapper.selectById(param.getAuditId());
|
|
|
|
+ if (Objects.isNull(auditInfo)) {
|
|
|
|
+ throw new ServiceException("记录不存在");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (auditInfo.getStatus() != 1) {
|
|
|
|
+ throw new ServiceException("请勿重复审核");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 审核通过
|
|
|
|
+ if (param.getType() == 1) {
|
|
|
|
+ auditInfo.setStatus(2);
|
|
|
|
+ // 转接
|
|
|
|
+ transferCustomer(auditInfo);
|
|
|
|
+ }
|
|
|
|
+ // 拒绝
|
|
|
|
+ else {
|
|
|
|
+ auditInfo.setStatus(3);
|
|
|
|
+ auditInfo.setReason(param.getReason());
|
|
|
|
+ }
|
|
|
|
+ auditInfo.setAuditBy(userName);
|
|
|
|
+ auditInfo.setAuditTime(LocalDateTime.now());
|
|
|
|
+ baseMapper.updateById(auditInfo);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 转接用户
|
|
|
|
+ */
|
|
|
|
+ private void transferCustomer(QwExternalContactTransferCompanyAudit auditInfo) {
|
|
|
|
+ List<QwExternalContactTransferCompanyAuditUser> auditUserList = auditUserService.getListByAuditId(auditInfo.getId());
|
|
|
|
+ outer:
|
|
|
|
+ for (QwExternalContactTransferCompanyAuditUser auditUser : auditUserList) {
|
|
|
|
+ try {
|
|
|
|
+ // 已提交的不再处理
|
|
|
|
+ if (auditUser.getStatus() != 0) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 在职
|
|
|
|
+ if (auditInfo.getTransferType() == 1) {
|
|
|
|
+ QwTransferCustomerParam qwTransferCustomerParam = new QwTransferCustomerParam();
|
|
|
|
+ String content = auditInfo.getContent();
|
|
|
|
+ if(StringUtils.isBlank(content)){
|
|
|
|
+ content = "您好,您的服务已升级,后续将由我的同事接替我的工作,继续为您服务。";
|
|
|
|
+ }
|
|
|
|
+ qwTransferCustomerParam.setTransfer_success_msg(content);
|
|
|
|
+ qwTransferCustomerParam.setHandover_userid(auditUser.getQwUserExtId());
|
|
|
|
+ qwTransferCustomerParam.setTakeover_userid(auditInfo.getQwUserExtId());
|
|
|
|
+ qwTransferCustomerParam.setExternal_userid(Collections.singletonList(auditUser.getExternalUserId()));
|
|
|
|
+ QwTransferCustomerResult qwTransferCustomerResult = qwApiService.transferCustomer(qwTransferCustomerParam, auditInfo.getCorpId());
|
|
|
|
+
|
|
|
|
+ if (qwTransferCustomerResult.getErrcode() != 0) {
|
|
|
|
+ auditUser.setRemark("接替失败: " + qwTransferCustomerResult.getErrmsg());
|
|
|
|
+ auditUserService.updateById(auditUser);
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<QwCustomer> customer = qwTransferCustomerResult.getCustomer();
|
|
|
|
+ if (Objects.isNull(customer) || customer.isEmpty()) {
|
|
|
|
+ auditUser.setRemark("接替失败: 未获取到数据");
|
|
|
|
+ auditUserService.updateById(auditUser);
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (QwCustomer qwCustomer : customer) {
|
|
|
|
+ if (qwCustomer.getErrcode() != 0) {
|
|
|
|
+ auditUser.setRemark("接替失败: " + qwCustomer.getErrcode());
|
|
|
|
+ auditUserService.updateById(auditUser);
|
|
|
|
+ continue outer;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ QwExternalContact qwExternal = new QwExternalContact();
|
|
|
|
+ qwExternal.setStatus(2);
|
|
|
|
+ qwExternal.setTransferStatus(2);
|
|
|
|
+ qwExternal.setId(auditUser.getExternalId());
|
|
|
|
+ contactMapper.updateQwExternalContact(qwExternal);
|
|
|
|
+
|
|
|
|
+ auditUser.setStatus(2);
|
|
|
|
+ auditUser.setReplaceTime(LocalDateTime.now());
|
|
|
|
+ auditUserService.updateById(auditUser);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 离职
|
|
|
|
+ else if (auditInfo.getTransferType() == 2) {
|
|
|
|
+ QwTransferCustomerResignedParam qwTransferCustomerParam = new QwTransferCustomerResignedParam();
|
|
|
|
+ qwTransferCustomerParam.setHandover_userid(auditUser.getQwUserExtId());
|
|
|
|
+ qwTransferCustomerParam.setTakeover_userid(auditInfo.getQwUserExtId());
|
|
|
|
+ qwTransferCustomerParam.setExternal_userid(Collections.singletonList(auditUser.getExternalUserId()));
|
|
|
|
+ QwTransferCustomerResignedResult qwTransferCustomerResignedParam = qwApiService.resignedTransferCustomer(qwTransferCustomerParam, auditInfo.getCorpId());
|
|
|
|
+
|
|
|
|
+ if (qwTransferCustomerResignedParam.getErrcode() != 0) {
|
|
|
|
+ auditUser.setRemark("接替失败: " + qwTransferCustomerResignedParam.getErrmsg());
|
|
|
|
+ auditUserService.updateById(auditUser);
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<QwCustomer> customer = qwTransferCustomerResignedParam.getCustomer();
|
|
|
|
+ if (Objects.isNull(customer) || customer.isEmpty()) {
|
|
|
|
+ auditUser.setRemark("接替失败: 未获取到数据");
|
|
|
|
+ auditUserService.updateById(auditUser);
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (QwCustomer qwCustomer : customer) {
|
|
|
|
+ if (qwCustomer.getErrcode() != 0) {
|
|
|
|
+ auditUser.setRemark("接替失败: " + qwCustomer.getErrcode());
|
|
|
|
+ auditUserService.updateById(auditUser);
|
|
|
|
+ continue outer;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ QwExternalContact qwExternal = new QwExternalContact();
|
|
|
|
+ qwExternal.setStatus(2);
|
|
|
|
+ qwExternal.setTransferStatus(2);
|
|
|
|
+ qwExternal.setId(auditUser.getExternalId());
|
|
|
|
+ contactMapper.updateQwExternalContact(qwExternal);
|
|
|
|
+
|
|
|
|
+ auditUser.setStatus(2);
|
|
|
|
+ auditUser.setReplaceTime(LocalDateTime.now());
|
|
|
|
+ auditUserService.updateById(auditUser);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ auditUser.setRemark("接替失败: " + e.getMessage());
|
|
|
|
+ auditUserService.updateById(auditUser);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 同步最新状态
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public void syncTransfer(Long auditId) {
|
|
|
|
+ QwExternalContactTransferCompanyAudit auditInfo = baseMapper.selectById(auditId);
|
|
|
|
+ if (Objects.isNull(auditInfo) || auditInfo.getStatus() != 2) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<QwExternalContactTransferCompanyAuditUser> auditUserList = auditUserService.getListByAuditId(auditId);
|
|
|
|
+ for (QwExternalContactTransferCompanyAuditUser auditUser : auditUserList) {
|
|
|
|
+ // 仅处理等待接替状态
|
|
|
|
+ if (auditUser.getStatus() != 2) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ QwGetTransferParam getTransferParam = new QwGetTransferParam();
|
|
|
|
+ getTransferParam.setTakeover_userid(auditInfo.getQwUserExtId());
|
|
|
|
+ getTransferParam.setHandover_userid(auditUser.getQwUserExtId());
|
|
|
|
+ QwGetTransferResult transfer = qwApiService.getTransfer(getTransferParam, auditInfo.getCorpId());
|
|
|
|
+ for (QwGetTransferResult.Customer customer: transfer.getCustomer()) {
|
|
|
|
+ if (customer.getExternal_userid().equals(auditUser.getExternalUserId())){
|
|
|
|
+ if (customer.getStatus() != 2){
|
|
|
|
+ auditUser.setStatus(customer.getStatus());
|
|
|
|
+ auditUserService.updateById(auditUser);
|
|
|
|
+
|
|
|
|
+ QwExternalContact qwExternalContact = new QwExternalContact();
|
|
|
|
+ qwExternalContact.setId(auditUser.getExternalId());
|
|
|
|
+ qwExternalContact.setTransferStatus(customer.getStatus());
|
|
|
|
+ if (customer.getStatus()==1){
|
|
|
|
+ qwExternalContact.setUserId(auditInfo.getQwUserExtId());
|
|
|
|
+ qwExternalContact.setQwUserId(auditInfo.getQwUserId());
|
|
|
|
+ qwExternalContact.setCompanyUserId(auditInfo.getCompanyUserId());
|
|
|
|
+ }
|
|
|
|
+ contactMapper.updateQwExternalContact(qwExternalContact);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|