|
@@ -0,0 +1,147 @@
|
|
|
|
+package com.fs.qw.service.impl;
|
|
|
|
+
|
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.fs.common.exception.ServiceException;
|
|
|
|
+import com.fs.company.domain.Company;
|
|
|
|
+import com.fs.company.domain.CompanyUser;
|
|
|
|
+import com.fs.company.mapper.CompanyMapper;
|
|
|
|
+import com.fs.company.mapper.CompanyUserMapper;
|
|
|
|
+import com.fs.qw.domain.*;
|
|
|
|
+import com.fs.qw.dto.CompanyTransferDTO;
|
|
|
|
+import com.fs.qw.mapper.QwCompanyMapper;
|
|
|
|
+import com.fs.qw.mapper.QwExternalContactMapper;
|
|
|
|
+import com.fs.qw.mapper.QwExternalContactTransferCompanyAuditMapper;
|
|
|
|
+import com.fs.qw.mapper.QwUserMapper;
|
|
|
|
+import com.fs.qw.param.QwExternalContactParam;
|
|
|
|
+import com.fs.qw.service.IQwExternalContactTransferCompanyAuditService;
|
|
|
|
+import com.fs.qw.service.IQwExternalContactTransferCompanyAuditUserService;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Collections;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Objects;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+@Service
|
|
|
|
+public class QwExternalContactTransferCompanyAuditServiceImpl extends ServiceImpl<QwExternalContactTransferCompanyAuditMapper, QwExternalContactTransferCompanyAudit>
|
|
|
|
+ implements IQwExternalContactTransferCompanyAuditService {
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private QwUserMapper qwUserMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private QwExternalContactMapper contactMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private QwCompanyMapper qwCompanyMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private CompanyMapper companyMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private CompanyUserMapper companyUserMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private IQwExternalContactTransferCompanyAuditUserService auditUserService;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 添加待审核记录
|
|
|
|
+ */
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ @Override
|
|
|
|
+ public void addAudit(CompanyTransferDTO param, Long companyId, String userName) {
|
|
|
|
+ QwUser qwUser = qwUserMapper.selectQwUserById(param.getQwUserId());
|
|
|
|
+
|
|
|
|
+ if (Objects.isNull(qwUser)) {
|
|
|
|
+ throw new ServiceException("接替员工不存在");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+// if (qwUser.getCompanyId().equals(companyId)) {
|
|
|
|
+// throw new ServiceException("接替员工不能为本公司员工");
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+ List<QwExternalContact> qwExternalContacts = new ArrayList<>();
|
|
|
|
+ // 为1转移员工下客户 其余转移转递的客户
|
|
|
|
+ if (param.getType() == 1) {
|
|
|
|
+ if (Objects.nonNull(param.getOldQwUserId())) {
|
|
|
|
+ QwExternalContact params = new QwExternalContact();
|
|
|
|
+ params.setCompanyId(companyId);
|
|
|
|
+ params.setQwUserId(param.getOldQwUserId());
|
|
|
|
+ qwExternalContacts = contactMapper.selectQwExternalContactList(params);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ qwExternalContacts = contactMapper.selectQwExternalContactByIds(param.getIds());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ boolean hasNotCurrentCompanyUser = qwExternalContacts.stream().anyMatch(c -> !c.getCompanyId().equals(companyId));
|
|
|
|
+ if (hasNotCurrentCompanyUser) {
|
|
|
|
+ throw new ServiceException("只能转移本公司下的客户");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (qwExternalContacts.isEmpty()) {
|
|
|
|
+ throw new ServiceException("请选择需要分配的客户");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<Long> extIds = qwExternalContacts.stream().map(QwExternalContact::getId).collect(Collectors.toList());
|
|
|
|
+ List<QwExternalContactTransferCompanyAuditUser> existAuditList = auditUserService.getExistAuditByExtIds(extIds);
|
|
|
|
+ if (!existAuditList.isEmpty()) {
|
|
|
|
+ String names = existAuditList.stream().map(QwExternalContactTransferCompanyAuditUser::getExternalUserName).collect(Collectors.joining());
|
|
|
|
+ throw new ServiceException("客户[" + names + "]已提交审核,请勿重复提交");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ QwCompany qwCompany = qwCompanyMapper.selectQwCompanyByCorpId(qwUser.getCorpId());
|
|
|
|
+ Company company = companyMapper.selectCompanyById(qwUser.getCompanyId());
|
|
|
|
+ CompanyUser companyUser = companyUserMapper.selectCompanyUserById(qwUser.getCompanyUserId());
|
|
|
|
+
|
|
|
|
+ QwExternalContactTransferCompanyAudit audit = new QwExternalContactTransferCompanyAudit();
|
|
|
|
+ audit.setQwCompanyId(qwCompany.getId());
|
|
|
|
+ audit.setCorpId(qwCompany.getCorpId());
|
|
|
|
+ audit.setCorpName(qwCompany.getCorpName());
|
|
|
|
+ audit.setCompanyId(company.getCompanyId());
|
|
|
|
+ audit.setCompanyName(company.getCompanyName());
|
|
|
|
+ audit.setCompanyUserId(companyUser.getUserId());
|
|
|
|
+ audit.setCompanyUserName(companyUser.getUserName());
|
|
|
|
+ audit.setQwUserId(qwUser.getId());
|
|
|
|
+ audit.setQwUserExtId(qwUser.getQwUserId());
|
|
|
|
+ audit.setQwUserName(qwUser.getQwUserName());
|
|
|
|
+ audit.setContent(param.getContent());
|
|
|
|
+ audit.setCreateTime(LocalDateTime.now());
|
|
|
|
+ audit.setCreateBy(userName);
|
|
|
|
+ baseMapper.insert(audit);
|
|
|
|
+
|
|
|
|
+ List<QwExternalContactTransferCompanyAuditUser> auditUserList = qwExternalContacts
|
|
|
|
+ .stream()
|
|
|
|
+ .map(c -> {
|
|
|
|
+
|
|
|
|
+ // 后面可优化为一起查询再取值
|
|
|
|
+ Company userCompany = companyMapper.selectCompanyById(c.getCompanyId());
|
|
|
|
+ CompanyUser userCompanyUser = companyUserMapper.selectCompanyUserById(c.getCompanyUserId());
|
|
|
|
+ QwUser userQwUser = qwUserMapper.selectQwUserById(c.getQwUserId());
|
|
|
|
+
|
|
|
|
+ QwExternalContactTransferCompanyAuditUser auditUser = new QwExternalContactTransferCompanyAuditUser();
|
|
|
|
+ auditUser.setAuditId(audit.getId());
|
|
|
|
+ auditUser.setExternalId(c.getId());
|
|
|
|
+ auditUser.setExternalUserId(c.getExternalUserId());
|
|
|
|
+ auditUser.setExternalUserName(c.getName());
|
|
|
|
+ auditUser.setCompanyId(userCompany.getCompanyId());
|
|
|
|
+ auditUser.setCompanyName(userCompany.getCompanyName());
|
|
|
|
+ auditUser.setCompanyUserId(userCompanyUser.getUserId());
|
|
|
|
+ auditUser.setCompanyUserName(userCompanyUser.getUserName());
|
|
|
|
+ auditUser.setQwUserId(userQwUser.getId());
|
|
|
|
+ auditUser.setQwUserExtId(userQwUser.getQwUserId());
|
|
|
|
+ auditUser.setQwUserName(userQwUser.getQwUserName());
|
|
|
|
+ auditUser.setCreateTime(LocalDateTime.now());
|
|
|
|
+
|
|
|
|
+ return auditUser;
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ auditUserService.saveBatch(auditUserList);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 查询审核记录列表
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public List<QwExternalContactTransferCompanyAudit> selectQwExternalContactTransferCompanyAuditList(QwExternalContactTransferCompanyAudit param) {
|
|
|
|
+ return baseMapper.selectQwExternalContactTransferCompanyAuditList(param);
|
|
|
|
+ }
|
|
|
|
+}
|