LAPTOP-FO2T5SIU\35838 hai 9 meses
pai
achega
68bb92f33f

+ 19 - 4
pro-base/src/main/java/com/idea/customerManagement/controller/CustomerManagementController.java

@@ -1,9 +1,14 @@
 package com.idea.customerManagement.controller;
 
+import com.alibaba.excel.EasyExcel;
+import com.alibaba.fastjson.JSONObject;
 import com.github.pagehelper.PageInfo;
+import com.idea.buildManage.excel.MnpBuildingExcel;
+import com.idea.buildManage.excel.MnpBuildingListener;
 import com.idea.customerManagement.dto.CustomerManagementDto;
 import com.idea.customerManagement.dto.RoomSelectionInfoDto;
 import com.idea.customerManagement.service.CustomerManagementService;
+import com.idea.util.ExcelUtils;
 import com.rockstar.common.base.BaseController;
 import com.rockstar.common.domain.AjaxResult;
 import com.rockstar.frame.model.extend.DateTrans;
@@ -12,13 +17,13 @@ import com.rockstar.frame.model.extend.Tablepar;
 import io.swagger.annotations.Api;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.io.IOException;
 import java.util.Date;
 
 @Controller
@@ -109,4 +114,14 @@ public class CustomerManagementController extends BaseController {
         modelService.downLoad(id,response);
     }
 
+    @PostMapping(value = "handleImport", produces = {"application/json;charset=UTF-8"})
+    @ResponseBody
+    public AjaxResult handleImport(@RequestParam("file") MultipartFile file) throws IOException {
+        JSONObject jsonObject = modelService.handleImport(file);
+        return AjaxResult.success(jsonObject);
+    }
+
+
+
+
 }

+ 55 - 0
pro-base/src/main/java/com/idea/customerManagement/excel/CustomerManagementExcel.java

@@ -0,0 +1,55 @@
+package com.idea.customerManagement.excel;
+
+import com.alibaba.excel.annotation.ExcelIgnore;
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.idea.customerManagement.model.Buyer;
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class CustomerManagementExcel {
+
+    @ExcelProperty(value = "小区名称")
+    private String groupName;
+
+    @ExcelProperty(value = "分期名称")
+    private String discName;
+
+    @ExcelProperty(value = "选房日")
+    private String roomSelectionDate;
+
+    @ExcelProperty(value = "批次号")
+    private String batchNumber;
+
+    @ExcelProperty(value = "选房号")
+    private String roomSelectionNumber;
+
+    @ExcelProperty(value = "姓名")
+    private String buyerName;
+
+    @ExcelProperty(value = "身份证号")
+    private String identityCard;
+
+    @ExcelProperty(value = "手机号")
+    private String phone;
+
+    @ExcelProperty(value = "关系")
+    private String relationship;
+
+    @ExcelProperty(value = "顺序号")
+    private String orderNum;
+
+    @ExcelProperty(value = "失败原因")
+    private String reason;
+
+//    @ExcelIgnore
+//    private List<Buyer> buyers;
+
+    @ExcelIgnore
+    private String relationshipStr;
+
+
+
+
+}

+ 11 - 0
pro-base/src/main/java/com/idea/customerManagement/model/Buyer.java

@@ -28,6 +28,17 @@ public class Buyer implements Serializable {
 
     private static final long serialVersionUID = 1L;
 
+    //非数据库字段
+    private String relationshipStr;
+
+    public String getRelationshipStr() {
+        return relationshipStr;
+    }
+
+    public void setRelationshipStr(String relationshipStr) {
+        this.relationshipStr = relationshipStr;
+    }
+
     public String getId() {
         return id;
     }

+ 275 - 0
pro-base/src/main/java/com/idea/customerManagement/service/CustomerManagementService.java

@@ -6,18 +6,23 @@ 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.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 +32,18 @@ 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.util.*;
 
+@Slf4j
 @Service
 public class CustomerManagementService implements BaseService<CustomerManagement, CustomerManagementExample> {
 
@@ -55,6 +64,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) {
@@ -350,6 +363,268 @@ 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 = 0;
+        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);
+//                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);
+            }
+        }
+
+        // 合并后数据
+        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();
+            // 拼接买受人姓名
+            StringBuilder builder = new StringBuilder();
+            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(",");
+                    }else {
+                        builder.append(buyer.getName())
+                                .append("(")
+                                .append(buyer.getRelationshipStr())
+                                .append(")")
+                                .append(",");
+                    }
+                    if(builder.length() > 0){
+                        builder.deleteCharAt(builder.length()-1);
+                    }
+
+                }else {
+                    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);
+        }
+
+        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;
+    }
+
+