|
@@ -2,22 +2,30 @@ 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;
|
|
|
import com.idea.buildManage.model.ParkRoom;
|
|
|
import com.idea.buildManage.response.ParkRoomResponse;
|
|
|
+import com.idea.buildManage.service.ParkFloorDiscService;
|
|
|
+import com.idea.buildManage.service.ParkInfoService;
|
|
|
import com.idea.customerManagement.dto.CustomerManagementDto;
|
|
|
import com.idea.customerManagement.dto.RoomSelectionInfoDto;
|
|
|
+import com.idea.customerManagement.excel.CustomerManagementExcel;
|
|
|
import com.idea.customerManagement.mapper.CustomerManagementExtendMapper;
|
|
|
import com.idea.customerManagement.mapper.CustomerManagementMapper;
|
|
|
import com.idea.customerManagement.mapper.RoomSelectionInfoMapper;
|
|
|
import com.idea.customerManagement.model.*;
|
|
|
import com.idea.util.DateUtils;
|
|
|
+import com.idea.util.ExcelUtils;
|
|
|
import com.idea.util.ReplaceWord;
|
|
|
import com.rockstar.common.base.BaseService;
|
|
|
import com.rockstar.frame.model.FrameUser;
|
|
@@ -27,14 +35,20 @@ import com.rockstar.frame.service.FrameUserService;
|
|
|
import com.rockstar.shiro.util.ShiroUtils;
|
|
|
import com.rockstar.system.service.SysDictService;
|
|
|
import com.rockstar.util.StringUtils;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+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
|
|
|
@Service
|
|
|
public class CustomerManagementService implements BaseService<CustomerManagement, CustomerManagementExample> {
|
|
|
|
|
@@ -55,6 +69,10 @@ public class CustomerManagementService implements BaseService<CustomerManagement
|
|
|
private ParkRoomMapper parkRoomMapper;
|
|
|
@Autowired
|
|
|
private ParkInfoMapper parkInfoMapper;
|
|
|
+ @Autowired
|
|
|
+ private ParkFloorDiscService floorDiscService;
|
|
|
+ @Autowired
|
|
|
+ private ParkInfoService parkInfoService;
|
|
|
|
|
|
@Override
|
|
|
public int deleteByPrimaryKey(String s) {
|
|
@@ -335,6 +353,7 @@ public class CustomerManagementService implements BaseService<CustomerManagement
|
|
|
Map<String, Object> data = new HashMap<>();
|
|
|
Map<String, Object> picData = new HashMap<>();
|
|
|
Map<String, Object> sealData = new HashMap<>();
|
|
|
+ Map<String, Object> settingData = new HashMap<>();
|
|
|
data.put("${name}", name);
|
|
|
data.put("${identityCard}", identityCard);
|
|
|
data.put("${roomSelectionNumber}", roomSelectionNumber);
|
|
@@ -342,7 +361,7 @@ public class CustomerManagementService implements BaseService<CustomerManagement
|
|
|
data.put("${month}", month);
|
|
|
data.put("${date}", date);
|
|
|
data.put("${region}", region);
|
|
|
- ReplaceWord.operateWord(response,filePath,fileName,data, picData,sealData);
|
|
|
+ ReplaceWord.operateWord(response,filePath,fileName,data, picData,sealData,settingData);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -350,7 +369,275 @@ public class CustomerManagementService implements BaseService<CustomerManagement
|
|
|
|
|
|
}
|
|
|
|
|
|
+ public JSONObject handleImport(MultipartFile file) throws IOException {
|
|
|
+
|
|
|
+ String userId = ShiroUtils.getUserId();
|
|
|
+ // 读取excel
|
|
|
+ ExcelUtils excelUtils = new ExcelUtils();
|
|
|
+ List<CustomerManagementExcel> list = excelUtils.excelImport(file.getInputStream(), CustomerManagementExcel.class);
|
|
|
+
|
|
|
+ Map<String, String> discNameIdMap = floorDiscService.getNameIdMap();
|
|
|
+ Map<String, String> parkNameIdMap = parkInfoService.getNameIdMap();
|
|
|
+ List<Map<String, String>> relationship = sysDictService.selectDictList("RELATIONSHIP");
|
|
|
+
|
|
|
+
|
|
|
+ List<CustomerManagementExcel> badList = new ArrayList<>();
|
|
|
+ int count;
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+
|
|
|
+ // 先校验
|
|
|
+ for(CustomerManagementExcel excel : list){
|
|
|
+
|
|
|
+ new CustomerManagement();
|
|
|
+
|
|
|
+ boolean groupNameFlag = true;
|
|
|
+ boolean discNameFlag = true;
|
|
|
+ boolean roomSelectionDateFlag = true;
|
|
|
+ boolean batchNumberFlag = true;
|
|
|
+ boolean roomSelectionNumberFlag = true;
|
|
|
+ boolean buyerNameFlag = true;
|
|
|
+ boolean identityCardFlag = true;
|
|
|
+ boolean phoneFlag = true;
|
|
|
+ boolean relationshipFlag = true;
|
|
|
+
|
|
|
+ StringBuilder builder = new StringBuilder();
|
|
|
+ try {
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(excel.getGroupName())) {
|
|
|
+ groupNameFlag = false;
|
|
|
+ builder.append("楼盘/小区名称为空").append(",");
|
|
|
+ excel.setGroupName("{" + excel.getGroupName() + "}");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(excel.getDiscName())) {
|
|
|
+ discNameFlag = false;
|
|
|
+ builder.append("楼分期名称为空").append(",");
|
|
|
+ excel.setDiscName("{" + excel.getDiscName() + "}");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 判断小区是否存在
|
|
|
+ if(StringUtils.isEmpty(parkNameIdMap.get(excel.getGroupName()))){
|
|
|
+ groupNameFlag = false;
|
|
|
+ builder.append("楼盘/小区不存在").append(",");
|
|
|
+ excel.setGroupName("{" + excel.getGroupName() + "}");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 判断分期是否存在
|
|
|
+ if(StringUtils.isEmpty(discNameIdMap.get(excel.getDiscName()))){
|
|
|
+ discNameFlag = false;
|
|
|
+ builder.append("分期不存在").append(",");
|
|
|
+ excel.setDiscName("{" + excel.getDiscName() + "}");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(StringUtils.isEmpty(excel.getRoomSelectionDate())){
|
|
|
+ roomSelectionDateFlag = false;
|
|
|
+ builder.append("选房日期为空").append(",");
|
|
|
+ excel.setRoomSelectionDate("{" + excel.getRoomSelectionDate() + "}");
|
|
|
+ }else {
|
|
|
+ try {
|
|
|
+ Date date = DateUtils.parseDate(excel.getRoomSelectionDate(), "yyyy/MM/dd");
|
|
|
+ }catch (Exception e){
|
|
|
+ roomSelectionDateFlag = false;
|
|
|
+ builder.append("选房日期格式有误").append(",");
|
|
|
+ excel.setRoomSelectionDate("{" + excel.getRoomSelectionDate() + "}");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(excel.getBatchNumber())){
|
|
|
+ batchNumberFlag = false;
|
|
|
+ builder.append("批次号为空").append(",");
|
|
|
+ excel.setBatchNumber("{" + excel.getBatchNumber() + "}");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(excel.getRoomSelectionNumber())){
|
|
|
+ roomSelectionNumberFlag = false;
|
|
|
+ builder.append("选房号为空").append(",");
|
|
|
+ excel.setRoomSelectionNumber("{" + excel.getRoomSelectionNumber() + "}");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(excel.getBuyerName())){
|
|
|
+ buyerNameFlag = false;
|
|
|
+ builder.append("姓名为空").append(",");
|
|
|
+ excel.setBuyerName("{" + excel.getBuyerName() + "}");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(excel.getIdentityCard())){
|
|
|
+ identityCardFlag = false;
|
|
|
+ builder.append("身份证号为空").append(",");
|
|
|
+ excel.setIdentityCard("{" + excel.getIdentityCard() + "}");
|
|
|
+ }else {
|
|
|
+ if(!this.isIdentityCard(excel.getIdentityCard())){
|
|
|
+ identityCardFlag = false;
|
|
|
+ builder.append("身份证号格式有误").append(",");
|
|
|
+ excel.setIdentityCard("{" + excel.getIdentityCard() + "}");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(excel.getPhone())){
|
|
|
+ phoneFlag = false;
|
|
|
+ builder.append("手机号为空").append(",");
|
|
|
+ excel.setPhone("{" + excel.getPhone() + "}");
|
|
|
+ }else {
|
|
|
+ if(!this.isPhone(excel.getPhone())){
|
|
|
+ phoneFlag = false;
|
|
|
+ builder.append("手机号格式有误").append(",");
|
|
|
+ excel.setPhone("{" + excel.getPhone() + "}");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 关系
|
|
|
+ if (StringUtils.isNotEmpty(excel.getRelationship())) {
|
|
|
+ for (Map<String, String> stringStringMap : relationship) {
|
|
|
+ if (stringStringMap.get("label").equals(excel.getRelationship())) {
|
|
|
+ excel.setRelationship(stringStringMap.get("value"));
|
|
|
+ excel.setRelationshipStr(stringStringMap.get("label"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 没匹配上的情况
|
|
|
+ if (excel.getRelationship() == null) {
|
|
|
+ relationshipFlag = false;
|
|
|
+ builder.append("关系格式有误").append(",");
|
|
|
+ excel.setRelationship("{" + excel.getRelationship() + "}");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(excel.getOrderNum())){
|
|
|
+ relationshipFlag = false;
|
|
|
+ builder.append("顺序号为空").append(",");
|
|
|
+ excel.setOrderNum("{" + excel.getOrderNum() + "}");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (groupNameFlag && discNameFlag && roomSelectionDateFlag && batchNumberFlag && roomSelectionNumberFlag
|
|
|
+ && buyerNameFlag && identityCardFlag && phoneFlag && relationshipFlag){
|
|
|
+
|
|
|
+ }else {
|
|
|
+ throw new RuntimeException(builder.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ }catch (Exception e){
|
|
|
+ String message = e.getMessage();
|
|
|
+ excel.setReason(message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 合并新增
|
|
|
+ Map<String, List<CustomerManagementExcel>> map = new HashMap<>();
|
|
|
+ for(CustomerManagementExcel excel : list){
|
|
|
+ // 判断批次号+选房号是否重复
|
|
|
+ String key = excel.getBatchNumber() + "-" + excel.getRoomSelectionNumber();
|
|
|
+ if(map.containsKey(key)){
|
|
|
+ // 批次号+选房号重复 合并选房人信息
|
|
|
+ List<CustomerManagementExcel> oldExcels = map.get(key);
|
|
|
+ oldExcels.add(excel);
|
|
|
+ map.put(key, oldExcels);
|
|
|
+ }else {
|
|
|
+ List<CustomerManagementExcel> excelList = new ArrayList<>();
|
|
|
+ excelList.add(excel);
|
|
|
+ map.put(key, excelList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 合并后数据
|
|
|
+ for (Map.Entry<String, List<CustomerManagementExcel>> entry : map.entrySet()) {
|
|
|
+ // 批次号+选房号 对应的数据
|
|
|
+ List<CustomerManagementExcel> value = entry.getValue();
|
|
|
+ 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);
|
|
|
+ buyers.add(buyer);
|
|
|
+ if(StringUtils.isEmpty(excel.getRelationship())){
|
|
|
+ builder.append(excel.getBuyerName()).append(",");
|
|
|
+ }else {
|
|
|
+ builder.append(excel.getBuyerName())
|
|
|
+ .append("(")
|
|
|
+ .append(excel.getRelationshipStr())
|
|
|
+ .append(")")
|
|
|
+ .append(",");
|
|
|
+ }
|
|
|
+ if(builder.length() > 0){
|
|
|
+ builder.deleteCharAt(builder.length()-1);
|
|
|
+ }
|
|
|
+
|
|
|
+ }else {
|
|
|
+ insertFlag = false;
|
|
|
+ badList.add(excel);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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();
|
|
|
+ jsonObject.put("successCount", count - badList.size());
|
|
|
+ jsonObject.put("errorList", badList);
|
|
|
+ jsonObject.put("errorCount", badList.size());
|
|
|
+ list.clear();
|
|
|
+ return jsonObject;
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 校验身份证号
|
|
|
+ * @param idCard
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public boolean isIdentityCard(String idCard){
|
|
|
+ String idCardPattern = "^\\d{17}[0-9Xx]$";
|
|
|
+ boolean isValid = idCard.matches(idCardPattern);
|
|
|
+ return isValid;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验手机号
|
|
|
+ * @param phone
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public boolean isPhone(String phone){
|
|
|
+ String idCardPattern = "^1[3-9]\\d{9}$";
|
|
|
+ boolean isValid = phone.matches(idCardPattern);
|
|
|
+ return isValid;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ 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);
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
|
|
|
}
|