|
@@ -2,11 +2,14 @@ package com.idea.customerManagement.service;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
import com.idea.buildManage.excel.MnpBuildingExcel;
|
|
|
+import com.idea.buildManage.excel.ParkRoomExcel;
|
|
|
+import com.idea.buildManage.excel.WriteHandlerStrategy;
|
|
|
import com.idea.buildManage.mapper.ParkInfoMapper;
|
|
|
import com.idea.buildManage.mapper.ParkRoomMapper;
|
|
|
import com.idea.buildManage.model.ParkInfo;
|
|
@@ -41,6 +44,8 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
@Slf4j
|
|
@@ -376,7 +381,7 @@ public class CustomerManagementService implements BaseService<CustomerManagement
|
|
|
|
|
|
|
|
|
List<CustomerManagementExcel> badList = new ArrayList<>();
|
|
|
- int count = 0;
|
|
|
+ int count;
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
|
|
|
// 先校验
|
|
@@ -523,30 +528,11 @@ public class CustomerManagementService implements BaseService<CustomerManagement
|
|
|
if(map.containsKey(key)){
|
|
|
// 批次号+选房号重复 合并选房人信息
|
|
|
List<CustomerManagementExcel> oldExcels = map.get(key);
|
|
|
-// List<Buyer> buyers = oldExcel.getBuyers();
|
|
|
-// Buyer buyer = new Buyer();
|
|
|
-// buyer.setOrderNum(Integer.valueOf(excel.getOrderNum()));
|
|
|
-// buyer.setName(excel.getBuyerName());
|
|
|
-// buyer.setIdentityCard(excel.getIdentityCard());
|
|
|
-// buyer.setPhone(excel.getPhone());
|
|
|
-// buyer.setRelationship(excel.getRelationship());
|
|
|
-// buyer.setRelationshipStr(excel.getRelationshipStr());
|
|
|
-// buyers.add(buyer);
|
|
|
oldExcels.add(excel);
|
|
|
map.put(key, oldExcels);
|
|
|
}else {
|
|
|
List<CustomerManagementExcel> excelList = new ArrayList<>();
|
|
|
excelList.add(excel);
|
|
|
-// List<Buyer> buyers = new ArrayList<>();
|
|
|
-// Buyer buyer = new Buyer();
|
|
|
-// buyer.setOrderNum(Integer.valueOf(excel.getOrderNum()));
|
|
|
-// buyer.setName(excel.getBuyerName());
|
|
|
-// buyer.setIdentityCard(excel.getIdentityCard());
|
|
|
-// buyer.setPhone(excel.getPhone());
|
|
|
-// buyer.setRelationship(excel.getRelationship());
|
|
|
-// buyer.setRelationshipStr(excel.getRelationshipStr());
|
|
|
-// buyers.add(buyer);
|
|
|
-// excel.setBuyers(buyers);
|
|
|
map.put(key, excelList);
|
|
|
}
|
|
|
}
|
|
@@ -558,21 +544,23 @@ public class CustomerManagementService implements BaseService<CustomerManagement
|
|
|
CustomerManagement customerManagement = new CustomerManagement();
|
|
|
BeanUtil.copyProperties(value.get(0), customerManagement);
|
|
|
String id = IdUtil.simpleUUID();
|
|
|
+ List<Buyer> buyers = new ArrayList<>();
|
|
|
// 拼接买受人姓名
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
+ boolean insertFlag = true;
|
|
|
for (CustomerManagementExcel excel : value){
|
|
|
if(StringUtils.isEmpty(excel.getReason())){
|
|
|
Buyer buyer = new Buyer();
|
|
|
buyer.setCustomerManagementId(id);
|
|
|
buyer.setCreatedAt(new Date());
|
|
|
buyer.setCreatedId(userId);
|
|
|
- buyerService.insertSelective(buyer);
|
|
|
- if(StringUtils.isEmpty(buyer.getRelationship())){
|
|
|
- builder.append(buyer.getName()).append(",");
|
|
|
+ buyers.add(buyer);
|
|
|
+ if(StringUtils.isEmpty(excel.getRelationship())){
|
|
|
+ builder.append(excel.getBuyerName()).append(",");
|
|
|
}else {
|
|
|
- builder.append(buyer.getName())
|
|
|
+ builder.append(excel.getBuyerName())
|
|
|
.append("(")
|
|
|
- .append(buyer.getRelationshipStr())
|
|
|
+ .append(excel.getRelationshipStr())
|
|
|
.append(")")
|
|
|
.append(",");
|
|
|
}
|
|
@@ -581,17 +569,26 @@ public class CustomerManagementService implements BaseService<CustomerManagement
|
|
|
}
|
|
|
|
|
|
}else {
|
|
|
+ insertFlag = false;
|
|
|
badList.add(excel);
|
|
|
}
|
|
|
}
|
|
|
- customerManagement.setBuyerName(builder.toString());
|
|
|
- customerManagement.setId(id);
|
|
|
- customerManagement.setStatus(1);
|
|
|
- customerManagement.setGroupId(parkNameIdMap.get(value.get(0).getGroupName()));
|
|
|
- customerManagement.setDiscId(discNameIdMap.get(value.get(0).getDiscName()));
|
|
|
- customerManagement.setCreatedAt(new Date());
|
|
|
- customerManagement.setCreatedId(userId);
|
|
|
- modelMapper.insertSelective(customerManagement);
|
|
|
+ if(insertFlag){
|
|
|
+ customerManagement.setBuyerName(builder.toString());
|
|
|
+ customerManagement.setId(id);
|
|
|
+ customerManagement.setStatus(1);
|
|
|
+ customerManagement.setGroupId(parkNameIdMap.get(value.get(0).getGroupName()));
|
|
|
+ customerManagement.setDiscId(discNameIdMap.get(value.get(0).getDiscName()));
|
|
|
+ customerManagement.setCreatedAt(new Date());
|
|
|
+ customerManagement.setCreatedId(userId);
|
|
|
+ modelMapper.insertSelective(customerManagement);
|
|
|
+ for (Buyer buyer : buyers){
|
|
|
+ buyer.setCustomerManagementId(id);
|
|
|
+ buyer.setCreatedAt(new Date());
|
|
|
+ buyer.setCreatedId(userId);
|
|
|
+ buyerService.insertSelective(buyer);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
count = list.size();
|
|
@@ -625,7 +622,21 @@ public class CustomerManagementService implements BaseService<CustomerManagement
|
|
|
}
|
|
|
|
|
|
|
|
|
+ public void errorListExport(List<CustomerManagementExcel> list, HttpServletResponse response) throws IOException {
|
|
|
+
|
|
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String date = sdf.format(new Date());
|
|
|
+ response.setContentType("application/vnd.ms-excel");
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
+ String fileName = URLEncoder.encode("失败记录" + date, "UTF-8");
|
|
|
+ response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
|
|
|
+ EasyExcel.write(response.getOutputStream(), CustomerManagementExcel.class)
|
|
|
+ .inMemory(true)
|
|
|
+ .registerWriteHandler(new WriteHandlerStrategy())//自定义样式
|
|
|
+ .sheet().doWrite(list);
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
|
|
|
}
|