|
@@ -22,6 +22,7 @@ import org.apache.poi.xssf.usermodel.XSSFRow;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -53,6 +54,9 @@ import java.util.stream.Collectors;
|
|
|
@Transactional
|
|
|
public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements TaskService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ContactsService contactsService;
|
|
|
+
|
|
|
@Resource
|
|
|
private UserMapper userMapper;
|
|
|
@Resource
|
|
@@ -446,13 +450,23 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements Ta
|
|
|
task.setCreateDate(LocalDateTime.now());
|
|
|
// task.setStatus(0);
|
|
|
task.setIsDelete(0);
|
|
|
+
|
|
|
+ //统计 线索不应与客户/商机/销售订单/联系人一同存在
|
|
|
+ boolean b1=false; //客户/商机/销售订单/联系人
|
|
|
+ boolean b2=false;//线索
|
|
|
+
|
|
|
+ //客户/商机/销售订单不应一同存在
|
|
|
+ boolean b3=false;//客户
|
|
|
+ boolean b4=false;//商机
|
|
|
+ boolean b5=false;//销售订单
|
|
|
+
|
|
|
for (int i = 0; i < cellNum; i++) {
|
|
|
String modelName = modelNameList.get(i);
|
|
|
String className = modelName.substring(0, 1).toUpperCase() + modelName.substring(1);
|
|
|
String getter="get"+className;
|
|
|
String setter="set"+className;
|
|
|
XSSFCell cell = row.getCell(i);
|
|
|
- if(cell!=null&&StringUtils.isNotEmpty(cell.getStringCellValue())){
|
|
|
+ if(cell!=null){
|
|
|
switch (typeList.get(i)){
|
|
|
default:cell.setCellType(CellType.STRING);
|
|
|
}
|
|
@@ -494,7 +508,8 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements Ta
|
|
|
if (first.isPresent()) {
|
|
|
executorIds.add(first.get().getId());
|
|
|
} else {
|
|
|
- throw new Exception("["+userName+"]在系统中不存在");
|
|
|
+ msg.setError("["+userName+"]在系统中不存在");
|
|
|
+ return msg;
|
|
|
}
|
|
|
}
|
|
|
StringJoiner joiner = new StringJoiner(",");
|
|
@@ -546,31 +561,37 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements Ta
|
|
|
|
|
|
else if(modelName.equals("contactsId")){
|
|
|
if(cell!=null&&!StringUtils.isEmpty(cell.getStringCellValue())){
|
|
|
+ b1=true;
|
|
|
+
|
|
|
String contactsName = cell.getStringCellValue();
|
|
|
List<Contacts> collect = contactsList.stream().filter(contacts -> contacts.getName().equals(contactsName)).collect(Collectors.toList());
|
|
|
- if (collect.size()>1){
|
|
|
- throw new Exception("["+contactsName+"]对应的联系人存在多个");
|
|
|
- }else if (collect.size()==1) {
|
|
|
+ if (!collect.isEmpty()) {
|
|
|
Contacts contacts = collect.get(0);
|
|
|
task.setContactsId(contacts.getId());
|
|
|
}else {
|
|
|
- throw new Exception("["+contactsName+"]对应的联系人不存在");
|
|
|
+ msg.setError("["+contactsName+"]对应的联系人不存在");
|
|
|
+ return msg;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
else if(modelName.equals("customId")){
|
|
|
if(cell!=null&&!StringUtils.isEmpty(cell.getStringCellValue())){
|
|
|
+ b1=true;
|
|
|
+ b3=true;
|
|
|
+
|
|
|
String customName = cell.getStringCellValue();
|
|
|
List<Custom> customs = customList.stream().filter(custom -> customName.equals(custom.getCustomName())).collect(Collectors.toList());
|
|
|
if (customs.size()>1){
|
|
|
- throw new Exception("["+customName+"]对应的客户存在多个");
|
|
|
+ msg.setError("["+customName+"]对应的客户存在多个");
|
|
|
+ return msg;
|
|
|
}else if (customs.size()==1){
|
|
|
Custom custom = customs.get(0);
|
|
|
if (task.getContactsId()!=null){
|
|
|
boolean isExist = contactsList.stream().anyMatch(contacts -> custom.getId().equals(contacts.getCustomId())&&contacts.getId().equals(task.getContactsId()));
|
|
|
if(!isExist){
|
|
|
- throw new Exception("["+customName+"]对应的客户没有对应填写的联系人");
|
|
|
+ msg.setError("["+customName+"]对应的客户没有对应填写的联系人");
|
|
|
+ return msg;
|
|
|
}
|
|
|
else {
|
|
|
task.setCustomId(custom.getId());
|
|
@@ -581,43 +602,55 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements Ta
|
|
|
task.setTaskType(0);
|
|
|
}
|
|
|
}else {
|
|
|
- throw new Exception("["+customName+"]对应的客户不存在");
|
|
|
+ msg.setError("["+customName+"]对应的客户不存在");
|
|
|
+ return msg;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
else if (modelName.equals("businessOpportunityId")){
|
|
|
if(cell!=null&&!StringUtils.isEmpty(cell.getStringCellValue())){
|
|
|
+ b1=true;
|
|
|
+ b4=true;
|
|
|
+
|
|
|
String businessName = cell.getStringCellValue();
|
|
|
List<BusinessOpportunity> collect = opportunityList.stream().filter(o -> businessName.equals(o.getName())).collect(Collectors.toList());
|
|
|
if (collect.size()>1){
|
|
|
- throw new Exception("["+businessName+"]对应的商机存在多个");
|
|
|
+ msg.setError("["+businessName+"]名称,对应的商机存在多个");
|
|
|
+ return msg;
|
|
|
}else if (collect.size()==1) {
|
|
|
BusinessOpportunity businessOpportunity = collect.get(0);
|
|
|
if (task.getContactsId()!=null){
|
|
|
if (!businessOpportunity.getContactsId().equals(task.getContactsId())){
|
|
|
- throw new Exception("["+businessName+"]对应的商机没有对应填写的联系人");
|
|
|
+ msg.setError("["+businessName+"]对应的商机没有对应填写的联系人");
|
|
|
+ return msg;
|
|
|
}else {
|
|
|
task.setBusinessOpportunityId(businessOpportunity.getId());
|
|
|
task.setTaskType(1);
|
|
|
}
|
|
|
}
|
|
|
}else {
|
|
|
- throw new Exception("["+businessName+"]对应的商机不存在");
|
|
|
+ msg.setError("["+businessName+"]对应的商机不存在");
|
|
|
+ return msg;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
else if (modelName.equals("orderId")){
|
|
|
if(cell!=null&&!StringUtils.isEmpty(cell.getStringCellValue())){
|
|
|
+ b1=true;
|
|
|
+ b5=true;
|
|
|
+
|
|
|
String orderName = cell.getStringCellValue();
|
|
|
List<SalesOrder> collect = orderList.stream().filter(order -> orderName.equals(order.getOrderName())).collect(Collectors.toList());
|
|
|
if (collect.size()>1){
|
|
|
- throw new Exception("["+orderName+"]对应的销售订单存在多个");
|
|
|
+ msg.setError("["+orderName+"]对应的销售订单存在多个");
|
|
|
+ return msg;
|
|
|
}else if (collect.size()==1) {
|
|
|
SalesOrder order=collect.get(0);
|
|
|
if (task.getContactsId()!=null){
|
|
|
if (!order.getContactsId().equals(task.getContactsId())){
|
|
|
- throw new Exception("["+orderName+"]对应的销售订单没有对应填写的联系人");
|
|
|
+ msg.setError("["+orderName+"]对应的销售订单没有对应填写的联系人");
|
|
|
+ return msg;
|
|
|
}
|
|
|
else {
|
|
|
task.setOrderId(order.getId());
|
|
@@ -625,16 +658,20 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements Ta
|
|
|
}
|
|
|
}
|
|
|
}else {
|
|
|
- throw new Exception("["+orderName+"]对应的销售订单不存在");
|
|
|
+ msg.setError("["+orderName+"]对应的销售订单不存在");
|
|
|
+ return msg;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
else if (modelName.equals("clueId")) {
|
|
|
if (cell!=null&&!StringUtils.isEmpty(cell.getStringCellValue())) {
|
|
|
+ b2=true;
|
|
|
+
|
|
|
String clueName = cell.getStringCellValue();
|
|
|
if (task.getContactsId()!=null){
|
|
|
- throw new Exception("["+clueName+"]对应的线索不存在联系人");
|
|
|
+ msg.setError("["+clueName+"]对应的线索不存在联系人");
|
|
|
+ return msg;
|
|
|
}
|
|
|
List<Clue> collect = clueList.stream().filter(clue -> clueName.equals(clue.getClueName())).collect(Collectors.toList());
|
|
|
if (!collect.isEmpty()) {
|
|
@@ -642,7 +679,8 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements Ta
|
|
|
task.setClueId(clue.getId());
|
|
|
task.setTaskType(3);
|
|
|
}else {
|
|
|
- throw new Exception("["+clueName+"]对应的线索不存在");
|
|
|
+ msg.setError("["+clueName+"]对应的线索不存在");
|
|
|
+ return msg;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -652,12 +690,14 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements Ta
|
|
|
String contactsPhone = cell.getStringCellValue();
|
|
|
List<Contacts> collect = contactsList.stream().filter(contacts -> contactsPhone.equals(contacts.getPhone())).collect(Collectors.toList());
|
|
|
if (collect.size()>1){
|
|
|
- throw new Exception("联系人号码"+"["+contactsPhone+"]对应的联系人存在多个");
|
|
|
+ msg.setError("联系人号码"+"["+contactsPhone+"]对应的联系人存在多个");
|
|
|
+ return msg;
|
|
|
} else if (collect.size() == 1) {
|
|
|
Contacts contacts = collect.get(0);
|
|
|
if (task.getContactsId()!=null){
|
|
|
if (!contacts.getId().equals(task.getContactsId())){
|
|
|
- throw new Exception("联系人号码"+"["+contactsPhone+"]与联系人不绑定");
|
|
|
+ msg.setError("联系人号码"+"["+contactsPhone+"]与联系人不绑定");
|
|
|
+ return msg;
|
|
|
}
|
|
|
}else {
|
|
|
task.setContactsId(contacts.getId());
|
|
@@ -676,7 +716,18 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements Ta
|
|
|
method.invoke(task,cell.getStringCellValue());
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
+ if (b1&&b2){
|
|
|
+ msg.setError("任务名称:"+task.getTaskName()+",线索不应与客户/商机/销售订单/联系人一同存在");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ if (b3&&b4&&b5){
|
|
|
+ msg.setError("任务名称:"+task.getTaskName()+",客户/商机/销售订单不应一同存在");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
importTaskList.add(task);
|
|
|
}
|
|
|
|
|
@@ -702,6 +753,28 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements Ta
|
|
|
task.setStatus(1);
|
|
|
}
|
|
|
|
|
|
+ //判断客户/商机/销售订单跟联系人时候绑定
|
|
|
+ if (task.getTaskType()!=null&&task.getTaskType()<3&&task.getContactsId()!=null){
|
|
|
+ HttpRespMsg httpRespMsg = contactsService.getAllContacts(task.getBusinessOpportunityId(), task.getOrderId(), task.getCustomId(), request);
|
|
|
+ List<Contacts> list = (List<Contacts>) httpRespMsg.getData();
|
|
|
+ if (!list.isEmpty()){
|
|
|
+ boolean present = list.stream().anyMatch(contacts -> contacts.getId().equals(task.getContactsId()));
|
|
|
+ if (!present){
|
|
|
+ String type="";
|
|
|
+ //客户0, 商机1 ,订单2 ,
|
|
|
+ if (task.getTaskType()==0){
|
|
|
+ type="客户";
|
|
|
+ }else if (task.getTaskType()==1){
|
|
|
+ type="商机";
|
|
|
+ }else {
|
|
|
+ type="订单";
|
|
|
+ }
|
|
|
+ msg.setError("存在"+type+"与联系人不一一对应:");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
if(saveOrUpdateBatch(importTaskList)){
|
|
|
ArrayList<TaskExecutor> taskExecutors = new ArrayList<>();
|