package com.sptg.gateway.controller.common.excel;

import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.metadata.BaseRowModel;
import com.alibaba.excel.support.ExcelTypeEnum;
import com.baomidou.mybatisplus.toolkit.IdWorker;
import com.google.common.collect.Lists;
import com.sptg.common.core.beans.ExcelResultEnum;
import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.core.beans.ResultEnum;
import com.sptg.common.core.constant.CommonConstant;
import com.sptg.common.core.constant.OperationConstant;
import com.sptg.common.core.constant.SymbolConstant;
import com.sptg.common.core.module.ResidentialExportModule;
import com.sptg.common.core.module.ResidentialImportModule;
import com.sptg.common.core.util.CommonUtil;
import com.sptg.common.core.util.JsonUtils;
import com.sptg.estate.api.dto.*;
import com.sptg.estate.api.entity.*;
import com.sptg.estate.api.feigns.*;
import com.sptg.permissions.api.dto.AreaDto;
import com.sptg.permissions.api.dto.OrgDto;
import com.sptg.permissions.api.entity.Account;
import com.sptg.permissions.api.entity.Organization;
import com.sptg.permissions.api.feigns.AreaFeign;
import com.sptg.permissions.api.feigns.OrgFeign;
import lombok.RequiredArgsConstructor;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RestController;
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.io.InputStream;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Pattern;

/**
 * title: ImportExcelController
 * package: com.sptg.gateway.controller.common.excel
 * description: 导入处理
 */
@RestController
@RequiredArgsConstructor
public class ImportExcelController {

    private final AgencyFeign agencyFeign;
    private final OrgFeign orgFeign;
    private final AreaFeign areaFeign;
    private final ResidentialFeign residentialFeign;
    private final BuildingFeign buildingFeign;
    private final UnitFeign unitFeign;
    private final FloorFeign floorFeign;
    private final RoomFeign roomFeign;
    private final UserFeign userFeign;
    private final ThirdUserFeign thirdUserFeign;
    private final AccessCardFeign accessCardFeign;
    private final RedisTemplate<String, String> redisTemplate;

    private static final String REGEX_EXCEL2003 = "^.+\\.(?i)(xls)$";
    private static final String REGEX_EXCEL2007 = "^.+\\.(?i)(xlsx)$";
    private static final String REGEX_MOBILE = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(17[013678])|(18[0,5-9]))\\d{8}$";
    private static final String REGEX_NUMBER = "[0-9]+";
    private static final String REGEX_AREA = "^(([1-9]{1}\\d*)|([0]{1}))(\\.(\\d){0,2})?$";

    private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");


    private final static String IMPORT_CACHE_ORG_CODE = "sptg:import:org:code";
    private final static String IMPORT_CACHE_AREA = "sptg:import:area";
    private final static String IMPORT_CACHE_RESIDENTIAL_CODE = "sptg:import:residential:code";
    private final static String IMPORT_CACHE_UNIT_CODE_NAME = "sptg:import:unit:code:name";
    private final static String IMPORT_CACHE_ROOM_CODE_NAME = "sptg:import:room:code:name";
    private final static String IMPORT_CACHE_UNIT_CODE = "sptg:import:card:unit:code";
    private final static String IMPORT_CACHE_ROOM_CODE = "sptg:import:card:room:code";
    private final static String IMPORT_CACHE_USER_NMAE = "sptg:import:card:user:name";



    public ResultBean<Object> readAgencyExcel(MultipartFile file, Account onLineUser) {
        List<Object> errorList = new ArrayList<>();
        Workbook workbook = null;
        InputStream is = null;
        try {
            String fileName = file.getOriginalFilename();
            if (!fileName.matches(REGEX_EXCEL2003) && !fileName.matches(REGEX_EXCEL2007)) {
                return new ResultBean<>(ExcelResultEnum.FILE_TYPE_ERROR);
            }
            is = file.getInputStream();
            if (fileName.matches(REGEX_EXCEL2007)) {
                workbook = new XSSFWorkbook(is);
            }
            if (fileName.matches(REGEX_EXCEL2003)) {
                workbook = new HSSFWorkbook(is);
            }
            //默认第一页
            Sheet sheet = workbook.getSheetAt(0);
            //空白页或空白内容
            if (sheet.getPhysicalNumberOfRows() < 2 || sheet.getLastRowNum() < 1) {
                return new ResultBean<>(ExcelResultEnum.FILE_CONTENT_ERROR);
            }
//            //文件格式错误
//            if(sheet.getRow(0) != null &&  sheet.getRow(0).getPhysicalNumberOfCells() != 12){
//                return new ResultBean<>(ExcelResultEnum.FILE_CONTENT_ERROR);
//            }
            //文件数据量太大
            if (sheet.getPhysicalNumberOfRows() > 1000 && sheet.getLastRowNum() > 1000) {
                return new ResultBean<>(ExcelResultEnum.FILE_IS_BIG_1000);
            }
            int count = sheet.getLastRowNum();
            for (int j = 1; j <= count; j++) {
                //判断该行数据是否有误
                boolean flag = true;
                //造成行数据导入失败的错误信息
                StringBuffer importErrorMsg = new StringBuffer();
                Row row = sheet.getRow(j);
                if (null == row) {
                    continue;
                }
                AgencyDto agencyDto = new AgencyDto();

                // 省ID
                String regionProvince = getCellValue(row.getCell(0));
                if (StringUtils.isNotBlank(regionProvince)){
                    regionProvince = regionProvince.split("_")[1];
                    agencyDto.setRegionProvince(regionProvince);
                }else {
                    flag = false;
                    importErrorMsg.append("所属省为空；");
                }

                // 市ID
                String regionCity = getCellValue(row.getCell(1));
                if (StringUtils.isNotBlank(regionCity)){
                    regionCity = regionCity.split("_")[1];
                    agencyDto.setRegionCity(regionCity);
                }else {
                    flag = false;
                    importErrorMsg.append("所属市为空；");
                }

                // 区/县ID
                String regionArea = getCellValue(row.getCell(2));
                if (StringUtils.isNotBlank(regionArea)){
                    regionArea = regionArea.split("_")[1];
                    agencyDto.setRegionArea(regionArea);
                }else {
                    flag = false;
                    importErrorMsg.append("所属区/县ID为空；");
                }

                // 所属街道
                String regionStreet = getCellValue(row.getCell(3));
                if (StringUtils.isNotBlank(regionStreet)){
                    regionStreet = regionStreet.split("_")[1];
                    agencyDto.setRegionStreet(regionStreet);
                }else {
                    flag = false;
                    importErrorMsg.append("所属街道为空；");
                }

                // 社区名称
                String agencyName = getCellValue(row.getCell(4));
                if (StringUtils.isNotBlank(agencyName)){
                    agencyDto.setAgencyName(agencyName);
                }else {
                    flag = false;
                    importErrorMsg.append("社区名称为空；");
                }

                if (flag) {
                    List<Agency> agencyList = agencyFeign.getListByCondition(agencyDto);
                    /// 找到原有的记录，做更新
                    if (agencyList.size() == 1){
                        Agency one = agencyList.get(0);
                        agencyDto.setAgency(one);
                    }
                }

                // 详细地址
                String address = getCellValue(row.getCell(5));
                if (StringUtils.isNotBlank(address)){
                    agencyDto.setAddress(address);
                }

                // 负责人姓名
                String personName = getCellValue(row.getCell(6));
                if (StringUtils.isNotBlank(personName)){
                    agencyDto.setPersonName(personName);
                }

                // 负责人电话
                String personPhone = getCellValue(row.getCell(7));
                if (StringUtils.isNotBlank(personPhone)){
                    agencyDto.setPersonPhone(personPhone);
                }

                // 备注
                String remark = getCellValue(row.getCell(8));
                if (StringUtils.isNotBlank(remark)){
                    agencyDto.setRemark(remark);
                }

                if (flag) {
                    ResultBean<Agency> resultBean = agencyFeign.addAgency(agencyDto);
                    System.out.println(resultBean.getCode() + " " + resultBean.getData() + " " + resultBean.getMsg());
                    if (resultBean.getCode().equals(ResultEnum.SUCCESS.getCode()) && resultBean.getData()!=null) {

                    } else {
                        agencyDto.setImportErrorMsg("后台添加失败，联系管理员;");
                        errorList.add(agencyDto);
                    }

                } else {
                    agencyDto.setImportErrorMsg(importErrorMsg.toString());
                    errorList.add(agencyDto);
                }
            }

            if (!errorList.isEmpty()) {
                return new ResultBean<>(ExcelResultEnum.SUCCESS_ERROR, errorList);
            } else {
                return new ResultBean<>(ExcelResultEnum.SUCCESS);
            }

        } catch (IOException e) {
            e.printStackTrace();
            return new ResultBean<>(ExcelResultEnum.ERROR);
        } finally {
            try {
                if (null != is) {
                    is.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 功能描述:小区导入
     *
     * @param file onLineUser
     * @return ResultBean<ResidentialDto>
     */
    public ResultBean<Object> readResidentialExcel(MultipartFile file, Account onLineUser) {
        List<Object> errorList = new ArrayList<>();
        Workbook workbook = null;
        InputStream is = null;
        try {
            String fileName = file.getOriginalFilename();
            if (!fileName.matches(REGEX_EXCEL2003) && !fileName.matches(REGEX_EXCEL2007)) {
                return new ResultBean<>(ExcelResultEnum.FILE_TYPE_ERROR);
            }
            is = file.getInputStream();
            if (fileName.matches(REGEX_EXCEL2007)) {
                workbook = new XSSFWorkbook(is);
            }
            if (fileName.matches(REGEX_EXCEL2003)) {
                workbook = new HSSFWorkbook(is);
            }
            //默认第一页
            Sheet sheet = workbook.getSheetAt(0);
            //空白页或空白内容
            if (sheet.getPhysicalNumberOfRows() < 2 || sheet.getLastRowNum() < 1) {
                return new ResultBean<>(ExcelResultEnum.FILE_CONTENT_ERROR);
            }
//            //文件格式错误
//            if(sheet.getRow(0) != null &&  sheet.getRow(0).getPhysicalNumberOfCells() != 12){
//                return new ResultBean<>(ExcelResultEnum.FILE_CONTENT_ERROR);
//            }
            //文件数据量太大
            if (sheet.getPhysicalNumberOfRows() > 1000 && sheet.getLastRowNum() > 1000) {
                return new ResultBean<>(ExcelResultEnum.FILE_IS_BIG_1000);
            }
            int count = sheet.getLastRowNum();
            for (int j = 1; j <= count; j++) {
                //判断该行数据是否有误
                boolean flag = true;
                //造成行数据导入失败的错误信息
                StringBuffer importErrorMsg = new StringBuffer();
                Row row = sheet.getRow(j);
                if (null == row) {
                    continue;
                }
                ResidentialDto residentialDto = new ResidentialDto();

                //  所属社区名称
                String agencyName = getCellValue(row.getCell(1));
                if (StringUtils.isBlank(agencyName)) {
                    flag = false;
                    importErrorMsg.append("所属物业机构编号为空；");
                }else{
                    AgencyDto agencyDto = new AgencyDto();
                    agencyDto.setAgencyName(agencyName);
                    List<Agency> agencyList = agencyFeign.getListByCondition(agencyDto);
                    if (agencyList.size() == 0){
                        flag = false;
                        importErrorMsg.append("找不到该社区;");
                    }else if (agencyList.size() > 1) {
                        flag = false;
                        importErrorMsg.append("该社区名称已存在;");
                    }else {
                        residentialDto.setAgencyName(agencyName);
                        residentialDto.setAgencyId(agencyList.get(0).getId());
                    }

                }

                //  小区名称
                String name = getCellValue(row.getCell(0));
                if (StringUtils.isBlank(name)) {
                    flag = false;
                    importErrorMsg.append("小区名称为空；");
                }
                residentialDto.setName(name);
                //  详细地址
                String address = getCellValue(row.getCell(2));
                if (StringUtils.isBlank(address)) {
                    flag = false;
                    importErrorMsg.append("详细地址为空；");
                }
                residentialDto.setAddress(address);

                //物业名称
                String estateName = getCellValue(row.getCell(3));
//                if (StringUtils.isBlank(estateName)) {
//                    flag = false;
//                    importErrorMsg.append("物业名称为空；");
//                }
                residentialDto.setEstatePidName(estateName);

                // 物业电话
                String estateTel = getCellValue(row.getCell(4));
//                if (StringUtils.isBlank(estateTel)) {
//                    flag = false;
//                    importErrorMsg.append("物业电话为空；");
//                }
                residentialDto.setEstateTel(estateTel);

                // 负责人姓名
                String personName = getCellValue(row.getCell(5));
                residentialDto.setPersonName(personName);
                //  负责人电话
                String personTel = getCellValue(row.getCell(6));
                if (StringUtils.isNotBlank(personTel)) {
//                    if (!Pattern.matches(REGEX_MOBILE, personTel)) {
//                        flag = false;
//                        importErrorMsg.append("负责人电话格式错误；");
//                    }
                    residentialDto.setPersonTel(personTel);
                }

                // 备注
                String remark = getCellValue(row.getCell(7));
                residentialDto.setRemark(remark);

                if (flag) {
                    residentialDto.setCreateAccountId(onLineUser.getId());
                    ResultBean<Residential> resultBean = this.residentialFeign.addResidential(residentialDto);
                    System.out.println(resultBean.getCode() + " " + resultBean.getData() + " " + resultBean.getMsg());
                    if (resultBean.getCode().equals(ResultEnum.SUCCESS.getCode()) && resultBean.getData()!=null) {
                    } else {
                        residentialDto.setImportErrorMsg("后台添加失败，联系管理员;");
                        errorList.add(residentialDto);
                    }

                } else {
                    residentialDto.setImportErrorMsg(importErrorMsg.toString());
                    errorList.add(residentialDto);
                }
            }

            if (!errorList.isEmpty()) {
                return new ResultBean<>(ExcelResultEnum.SUCCESS_ERROR, errorList);
            } else {
                return new ResultBean<>(ExcelResultEnum.SUCCESS);
            }
        } catch (IOException e) {
            e.printStackTrace();
            return new ResultBean<>(ExcelResultEnum.ERROR);
        } finally {
            try {
                if (null != is) {
                    is.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
    /**
     * 功能描述:机构导入
     *
     * @param file onLineUser
     * @return ResultBean<Organization>
     */
    public ResultBean<Object> readOrgExcel(MultipartFile file, Account onLineUser) {
        List<Object> errorList = new ArrayList<>();
        Workbook workbook = null;
        InputStream is = null;
        try {
            String fileName = file.getOriginalFilename();
            if (!fileName.matches(REGEX_EXCEL2003) && !fileName.matches(REGEX_EXCEL2007)) {
                return new ResultBean<>(ExcelResultEnum.FILE_TYPE_ERROR);
            }
            is = file.getInputStream();
            if (fileName.matches(REGEX_EXCEL2007)) {
                workbook = new XSSFWorkbook(is);
            }
            if (fileName.matches(REGEX_EXCEL2003)) {
                workbook = new HSSFWorkbook(is);
            }
            //默认第一页
            Sheet sheet = workbook.getSheetAt(0);
            //空白页或空白内容
            if (sheet.getPhysicalNumberOfRows() < 2 || sheet.getLastRowNum() < 1) {
                return new ResultBean<>(ExcelResultEnum.FILE_CONTENT_ERROR);
            }
//            //文件格式错误
//            if(sheet.getRow(0) != null &&  sheet.getRow(0).getPhysicalNumberOfCells() != 12){
//                return new ResultBean<>(ExcelResultEnum.FILE_CONTENT_ERROR);
//            }
            //文件数据量太大
            if (sheet.getPhysicalNumberOfRows() > 1000 && sheet.getLastRowNum() > 1000) {
                return new ResultBean<>(ExcelResultEnum.FILE_IS_BIG_1000);
            }
            int count = sheet.getLastRowNum();
            for (int j = 1; j <= count; j++) {
                //判断该行数据是否有误
                boolean flag = true;
                //造成行数据导入失败的错误信息
                StringBuffer importErrorMsg = new StringBuffer();
                Row row = sheet.getRow(j);
                if (null == row) {
                    continue;
                }
                OrgDto orgDto = new OrgDto();
                //  机构名称
                String orgName = getCellValue(row.getCell(0));
                orgDto.setName(orgName);
                if (StringUtils.isBlank(orgName)) {
                    flag = false;
                    importErrorMsg.append("机构名称为空；");
                }
                //  机构类型
                String orgType = getCellValue(row.getCell(1));
                if (StringUtils.isBlank(orgType)) {
                    flag = false;
                    importErrorMsg.append("机构类型为空；");
                }
                orgDto.setOrgType(Integer.parseInt(orgType));
                //  省市区
                String regionProvince = getCellValue(row.getCell(2));
                if (StringUtils.isBlank(regionProvince)) {
                    flag = false;
                    importErrorMsg.append("小区所属省为空；");
                }
                String regionCity = getCellValue(row.getCell(3));
                if (StringUtils.isBlank(regionCity)) {
                    flag = false;
                    importErrorMsg.append("小区所属市为空；");
                }
                String regionArea = getCellValue(row.getCell(4));
                if (StringUtils.isBlank(regionArea)) {
                    flag = false;
                    importErrorMsg.append("小区所属县/区为空；");
                }
                //  负责人电话
                String personName = getCellValue(row.getCell(5));
                if (StringUtils.isNotBlank(personName)) {
                    orgDto.setPersonName(personName);
                }
                //  负责人电话
                String personTel = getCellValue(row.getCell(6));
                if (StringUtils.isNotBlank(personTel)) {
//                    if (!Pattern.matches(REGEX_MOBILE, personTel)) {
//                        flag = false;
//                        importErrorMsg.append("负责人电话格式错误；");
//                    }
                    orgDto.setPersonTel(personTel);
                }

                //  详细地址
                String address = getCellValue(row.getCell(7));
                if (StringUtils.isNotBlank(address)) {
                    orgDto.setAddress(address);
                }
                //  备注
                String remark = getCellValue(row.getCell(8));
                if (StringUtils.isNotBlank(remark)) {
                    orgDto.setRemark(remark);
                }

                //  从缓存中获取省市区的信息
                HashOperations<String, String, String> hashOperations = this.redisTemplate.opsForHash();
                String cacheKey = DigestUtils.md5Hex(regionProvince + regionCity + regionArea);
                String json = hashOperations.get(IMPORT_CACHE_AREA, cacheKey);
                AreaDto dto;
                if (StringUtils.isEmpty(json)) {
                    dto = this.getArea(regionProvince, regionCity, regionArea);
                    if (null == dto) {
                        flag = false;
                        orgDto.setRegionProvince(regionProvince);
                        orgDto.setRegionCity(regionCity);
                        orgDto.setRegionArea(regionArea);
                        importErrorMsg.append("所属省市区不存在；");
                    } else {
                        orgDto.setRegionProvince(dto.getRegionProvince());
                        orgDto.setRegionCity(dto.getRegionCity());
                        orgDto.setRegionArea(dto.getRegionArea());
                        orgDto.setRegion(dto.getRegionName());
                        json = JsonUtils.objectToJson(dto);
                        hashOperations.put(IMPORT_CACHE_AREA, cacheKey, json);
                    }
                } else {
                    dto = JsonUtils.jsonToPojo(json, AreaDto.class);
                    orgDto.setRegionProvince(dto.getRegionProvince());
                    orgDto.setRegionCity(dto.getRegionCity());
                    orgDto.setRegionArea(dto.getRegionArea());
                    orgDto.setRegion(dto.getRegionName());
                }

                //没必要做缓存
                ;
                if (this.orgFeign.checkNameIsExist(orgName)) {
                    flag = false;
                    orgDto.setRegionProvince(regionProvince);
                    orgDto.setRegionCity(regionCity);
                    orgDto.setRegionArea(regionArea);
                    importErrorMsg.append("机构已存在；");
                }

                if (flag) {
                    orgDto.setCreateAccountId(onLineUser.getId());
                    Organization parent = this.orgFeign.getOrgById(1L);
                    orgDto.setRootOrgId(parent.getId());//挂在机构总管理
                    orgDto.setPid(parent.getId());//挂在机构总管理
                    orgDto.setPosition(parent.getPosition());
                    orgDto.setFlag(1);// 机构

                    orgDto.setCode("O");
                    //机构类型 { 1：内部,2：广告,3：物业, 4：社区 }
                    if ((orgDto.getOrgType() == OperationConstant.THREE || orgDto.getOrgType() == OperationConstant.TWO || orgDto.getOrgType() == OperationConstant.FOUR) && orgDto.getPid() == null){
                        //如果是新建物业或者广告商，则pid为空，隐形挂在常运智慧科技下面，方便常运智慧管理（常运智慧id为1）
                        Organization org = this.orgFeign.getOrgById(1L);
                        orgDto.setPid(org.getId());
                        orgDto.setPosition(org.getPosition());
                    }

                    ResultBean<Organization> resultBean = this.orgFeign.addEntity(orgDto);
                    System.out.println(resultBean.getCode() + " " + resultBean.getData() + " " + resultBean.getMsg());
                    if (resultBean.getCode().equals(ResultEnum.SUCCESS.getCode())) {

                    } else {
                        orgDto.setRegionProvince(regionProvince);
                        orgDto.setRegionCity(regionCity);
                        orgDto.setRegionArea(regionArea);
                        orgDto.setImportErrorMsg("后台添加失败，联系管理员;");
                        errorList.add(orgDto);
                    }

                } else {
                    orgDto.setImportErrorMsg(importErrorMsg.toString());
                    errorList.add(orgDto);
                }
            }

            if (!errorList.isEmpty()) {
                return new ResultBean<>(ExcelResultEnum.SUCCESS_ERROR, errorList);
            } else {
                return new ResultBean<>(ExcelResultEnum.SUCCESS);
            }
        } catch (IOException e) {
            e.printStackTrace();
            return new ResultBean<>(ExcelResultEnum.ERROR);
        } finally {
            try {
                if (null != is) {
                    is.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }


    /**
     * 功能描述:单元导入
     *
     * @param file onLineUser
     * @return ResultBean<ResidentialDto>
     */
    public ResultBean<Object> readUnitExcel(MultipartFile file, Account onLineUser) {
        UnitDto unitImportExcelDto = new UnitDto();
        List<Unit> list = new ArrayList<>();
        List<Object> errorList = new ArrayList<>();
        Map<Long, Integer> map = new HashMap<>();
        Workbook workbook = null;
        InputStream is = null;
        try {
            String fileName = file.getOriginalFilename();
            if (!fileName.matches(REGEX_EXCEL2003) && !fileName.matches(REGEX_EXCEL2007)) {
                return new ResultBean<>(ExcelResultEnum.FILE_TYPE_ERROR);
            }
            is = file.getInputStream();
            if (fileName.matches(REGEX_EXCEL2007)) {
                workbook = new XSSFWorkbook(is);
            }
            if (fileName.matches(REGEX_EXCEL2003)) {
                workbook = new HSSFWorkbook(is);
            }
            //默认第一页
            Sheet sheet = workbook.getSheetAt(0);
            //空白页或空白内容
            if (sheet.getPhysicalNumberOfRows() < 2 || sheet.getLastRowNum() < 1) {
                return new ResultBean<>(ExcelResultEnum.FILE_CONTENT_ERROR);
            }
//            //文件格式错误
//            if(sheet.getRow(0) != null &&  sheet.getRow(0).getPhysicalNumberOfCells() != 9){
//                return new ResultBean<>(ExcelResultEnum.FILE_CONTENT_ERROR);
//            }
            //文件数据量太大
            if (sheet.getPhysicalNumberOfRows() > 1000 && sheet.getLastRowNum() > 1000) {
                return new ResultBean<>(ExcelResultEnum.FILE_IS_BIG_1000);
            }
            int count = sheet.getLastRowNum();
            for (int j = 1; j <= count; j++) {
                //判断该行数据是否有误
                boolean flag = true;
                //造成行数据导入失败的错误信息
                StringBuffer importErrorMsg = new StringBuffer();
                int rowNum = j + 1;
                Row row = sheet.getRow(j);
                if (null == row) {
                    continue;
                }
                UnitDto unit = new UnitDto();
                //  小区名称
                String residentialNumber = getCellValue(row.getCell(0));
                if (StringUtils.isBlank(residentialNumber)) {
                    flag = false;
                    importErrorMsg.append("所属小区编号为空;");
                }
                //  单元名称
                String name = getCellValue(row.getCell(1));
                if (StringUtils.isBlank(name)) {
                    flag = false;
                    importErrorMsg.append("单元名称为空;");
                }
                unit.setName(name);
                //  单元编号
//                String unitNumber = getCellValue(row.getCell(2));
//                if(StringUtils.isBlank(unitNumber)){
//                    return new ResultBean<>("200","第"+rowNum+"行单元编号为空，请核实后重新操作");
//                }
//                if(!Pattern.matches(REGEX_NUMBER, unitNumber)){
//                    return new ResultBean<>("200","第"+rowNum+"行单元编号格式错误，请核实后重新操作");
//                }
//                unit.setUnitNumber(unitNumber);
                //  联系人电话
                String personTel = getCellValue(row.getCell(3));
                if (StringUtils.isNotBlank(personTel)) {
                    if (!Pattern.matches(REGEX_MOBILE, personTel)) {
                        flag = false;
                        importErrorMsg.append("联系人电话格式错误;");
                    }
                }
                unit.setPersonTel(personTel);
                //排序必须是整数
                String serial = getCellValue(row.getCell(8));
                Integer serial1 = null;
                if (StringUtils.isNotBlank(serial)) {
                    try {
                        serial1 = Integer.valueOf(serial);
                        unit.setSerial(Integer.valueOf(serial1));
                    } catch (Exception e) {
                        flag = false;
                        importErrorMsg.append("排序的值不是整数;");
                    }
                } else {
                    unit.setSerial(OperationConstant.ONE);
                }

                UnitDto unitDto = new UnitDto();
                //  获取小区信息
//                ResultBean<Residential> resultBean = this.getResidential(residentialNumber,rowNum);
                Residential residential = this.residentialFeign.findResidentialByNumber(residentialNumber);
                if (null == residential) {
                    flag = false;
                    importErrorMsg.append("所属小区编号不存在");
                } else {
                    long residentialId = residential.getId();
                    String residentialName = residential.getName();
                    unit.setResidentialId(residentialId);
                    unitDto.setResidentialId(residentialId);
//                unitDto.setUnitNumber(unitNumber);
                    //没必要做缓存
                    if (this.unitFeign.findUnitByCondition(unitDto) > 0) {
                        flag = false;
                        importErrorMsg.append("单元已存在");
                    }
                    unitDto.setResidentialName(residentialName);
                    unitDto.setOrgPid(residentialId);
                    unitDto.setOrgPidName(residentialName);
                    unitDto.setRootOrgId(residential.getRootOrgId());
                    unitDto.setOrgPosition(residential.getOrgPosition() + unit.getId() + SymbolConstant.BACK_SLASH);
                    unitDto.setEstatePosition(residential.getEstatePosition() + unit.getId() + SymbolConstant.BACK_SLASH);

                    if (map.containsKey(residentialId)) {
                        map.put(residentialId, map.get(residentialId) + 1);
                        unitDto.setUnitNumber(SymbolConstant.B_NO + CommonUtil.autoZeroFilling(4, residential.getUnitNumber() + map.get(residentialId)));
                    } else {
                        map.put(residentialId, 1);
                        unitDto.setUnitNumber(SymbolConstant.B_NO + CommonUtil.autoZeroFilling(4, residential.getUnitNumber() + 1));
                    }
                }
                unitDto.setName(name);
                unitDto.setResidentialNumber(residentialNumber);
                unitDto.setPersonTel(personTel);
                unitDto.setSerial(serial1);
                unitDto.setPersonName(getCellValue(row.getCell(2)));
                unitDto.setBuiltYear(getCellValue(row.getCell(4)));
                unitDto.setPropertyNature(getCellValue(row.getCell(5)));
                unitDto.setIncludingElevator(getCellValue(row.getCell(6)));
                unitDto.setRemark(getCellValue(row.getCell(7)));
                unitDto.setCreateAccountId(onLineUser.getId());
                unitDto.setId(IdWorker.getId());
                unitDto.setRoomNumber(OperationConstant.ZERO);
                unitDto.setUserNumber(OperationConstant.ZERO);
                unitDto.setCreateDate(new Date());
                unitDto.setStatus(OperationConstant.ZERO);
                if (flag) {
                    ResultBean<UnitDto> resultBean = this.unitFeign.addUnit(unitDto);
                    System.out.println(resultBean.getCode() + " " + resultBean.getData() + " " + resultBean.getMsg());
                    if (resultBean.getCode().equals(ResultEnum.SUCCESS.getCode())) {
                    } else {
                        unitDto.setImportErrorMsg("后台添加失败，联系管理员;");
                        errorList.add(unitDto);
                    }

                } else {
                    unitDto.setImportErrorMsg(importErrorMsg.toString());
                    errorList.add(unitDto);
                }


//                if(map.containsKey(residentialId)){
//                    map.put(residentialId,map.get(residentialId)+1);
//                }else{
//                    map.put(residentialId,1);
//                }
            }
//            if (!list.isEmpty() && !map.isEmpty()) {
////                unitImportExcelDto.setList(list);
////                unitImportExcelDto.setMap(map);
//                return new ResultBean<>(ExcelResultEnum.SUCCESS, errorList);
//            } else {
//                return new ResultBean<>(ExcelResultEnum.FILE_CONTENT_ERROR);
//            }
            if (!errorList.isEmpty()) {
                return new ResultBean<>(ExcelResultEnum.SUCCESS_ERROR, errorList);
            } else {
                return new ResultBean<>(ExcelResultEnum.SUCCESS);
            }
        } catch (IOException e) {
            e.printStackTrace();
            return new ResultBean<>(ExcelResultEnum.ERROR);
        } finally {
            try {
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 功能描述:房间导入
     *
     * @param file onLineUser
     * @return ResultBean<ResidentialDto>
     */
    public ResultBean<RoomDto> readRoomExcel_old(MultipartFile file, Account onLineUser) {
        RoomDto roomImportExcelDto = new RoomDto();
        List<Room> list = new ArrayList<>();
        Map<Long, Integer> residentialMap = new HashMap<>();
        Map<Long, Integer> unitMap = new HashMap<>();
        Workbook workbook = null;
        InputStream is = null;
        try {
            String fileName = file.getOriginalFilename();
            if (!fileName.matches(REGEX_EXCEL2003) && !fileName.matches(REGEX_EXCEL2007)) {
                return new ResultBean<>(ExcelResultEnum.FILE_TYPE_ERROR);
            }
            is = file.getInputStream();
            if (fileName.matches(REGEX_EXCEL2007)) {
                workbook = new XSSFWorkbook(is);
            }
            if (fileName.matches(REGEX_EXCEL2003)) {
                workbook = new HSSFWorkbook(is);
            }
            //默认第一页
            Sheet sheet = workbook.getSheetAt(0);
            //空白页或空白内容
            if (sheet.getPhysicalNumberOfRows() < 2 || sheet.getLastRowNum() < 1) {
                return new ResultBean<>(ExcelResultEnum.FILE_CONTENT_ERROR);
            }
//            //文件格式错误
//            if(sheet.getRow(0) != null &&  sheet.getRow(0).getPhysicalNumberOfCells() != 11){
//                return new ResultBean<>(ExcelResultEnum.FILE_CONTENT_ERROR);
//            }
            //文件数据量太大
            if (sheet.getPhysicalNumberOfRows() > 1000 && sheet.getLastRowNum() > 1000) {
                return new ResultBean<>(ExcelResultEnum.FILE_IS_BIG_1000);
            }
            int count = sheet.getLastRowNum();
            for (int j = 1; j <= count; j++) {
                int rowNum = j + 1;
                Row row = sheet.getRow(j);
                if (null == row) {
                    continue;
                }
                Room room = new Room();
                String residentialNumber = getCellValue(row.getCell(0));
                if (StringUtils.isBlank(residentialNumber)) {
                    return new ResultBean<>("200", "第" + rowNum + "行所属小区编号为空，请核实后重新操作");
                }
                String unitName = getCellValue(row.getCell(1));
                if (StringUtils.isBlank(unitName)) {
                    return new ResultBean<>("200", "第" + rowNum + "行单元名称为空，请核实后重新操作");
                }
                String unitNumber = getCellValue(row.getCell(2));
                if (StringUtils.isBlank(unitNumber)) {
                    return new ResultBean<>("200", "第" + rowNum + "行单元编号为空，请核实后重新操作");
                }
                String name = getCellValue(row.getCell(3));
                if (StringUtils.isBlank(name)) {
                    return new ResultBean<>("200", "第" + rowNum + "行房间名称为空，请核实后重新操作");
                }
                room.setName(name);
                String houseNumber = getCellValue(row.getCell(4));
                if (StringUtils.isBlank(houseNumber)) {
                    return new ResultBean<>("200", "第" + rowNum + "行门牌号为空，请核实后重新操作");
                }
                if (!Pattern.matches(REGEX_NUMBER, houseNumber)) {
                    return new ResultBean<>("200", "第" + rowNum + "行门牌号格式错误，请核实后重新操作");
                }
                room.setHouseNumber(houseNumber);
                String area = getCellValue(row.getCell(9));
                if (StringUtils.isNotBlank(area)) {
                    if (!Pattern.matches(REGEX_AREA, area)) {
                        return new ResultBean<>("200", "第" + rowNum + "行房间面积格式错误，请核实后重新操作");
                    }
                }
                ResultBean<Residential> residentialResultBean = this.getResidential(residentialNumber, rowNum);
                Residential residential = residentialResultBean.getData();
                if (null == residential || null == residential.getId()) {
                    return new ResultBean<>("200", residentialResultBean.getMsg());
                }
                long residentialId = residential.getId();
                room.setResidentialId(residentialId);

                UnitDto unitDto = new UnitDto();
                unitDto.setResidentialId(residentialId);
                unitDto.setUnitNumber(unitNumber);
                unitDto.setName(unitName);
                ResultBean<Unit> unitResultBean = this.getUnit(unitDto, rowNum, onLineUser);
                Unit unit = unitResultBean.getData();
                if (null == unit || null == unit.getId()) {
                    return new ResultBean<>("200", unitResultBean.getMsg());
                }
                long unitId = unit.getId();
                room.setUnitId(unitId);

                RoomDto roomDto = new RoomDto();
                roomDto.setUnitId(unitId);
                roomDto.setName(name);
                roomDto.setHouseNumber(houseNumber);
                //没必要做缓存
                if (this.roomFeign.findRoomByCondition(roomDto) > 0) {
                    return new ResultBean<>("200", "第" + rowNum + "行房间名称或编号已存在，请核实后重新操作");
                }
                room.setUnitName(unit.getName());
                room.setResidentialName(unit.getResidentialName());
                room.setRootOrgId(unit.getRootOrgId());
                room.setHouseType(getCellValue(row.getCell(5)));
                room.setFloor(getCellValue(row.getCell(6)));
                room.setOrientation(getCellValue(row.getCell(7)));
                room.setOrnament(getCellValue(row.getCell(8)));
                room.setArea(area == null ? null : Double.valueOf(area));
                room.setRemark(getCellValue(row.getCell(10)));
                room.setUserNumber(OperationConstant.ZERO);
                room.setCreateDate(new Date());
                room.setStatus(OperationConstant.ZERO);
                room.setCreateAccountId(onLineUser.getId());
                room.setId(IdWorker.getId());
                room.setOrgPosition(unit.getOrgPosition() + room.getId() + SymbolConstant.BACK_SLASH);
                room.setEstatePosition(unit.getEstatePosition() + room.getId() + SymbolConstant.BACK_SLASH);
                list.add(room);
                if (residentialMap.containsKey(residentialId)) {
                    residentialMap.put(residentialId, residentialMap.get(residentialId) + 1);
                } else {
                    residentialMap.put(residentialId, 1);
                }
                if (unitMap.containsKey(unitId)) {
                    unitMap.put(unitId, unitMap.get(unitId) + 1);
                } else {
                    unitMap.put(unitId, 1);
                }
            }
            if (!list.isEmpty() && !residentialMap.isEmpty() && !unitMap.isEmpty()) {
                roomImportExcelDto.setList(list);
                roomImportExcelDto.setResidentialMap(residentialMap);
                roomImportExcelDto.setUnitMap(unitMap);
                return new ResultBean<>(ExcelResultEnum.SUCCESS, roomImportExcelDto);
            } else {
                return new ResultBean<>(ExcelResultEnum.FILE_CONTENT_ERROR);
            }
        } catch (IOException e) {
            e.printStackTrace();
            return new ResultBean<>(ExcelResultEnum.ERROR);
        } finally {
            try {
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 功能描述:房间导入2.0
     *
     * @param file onLineUser
     * @return ResultBean<ResidentialDto>
     */
    public ResultBean<Object> readRoomExcel(MultipartFile file, Account onLineUser) {
        RoomDto roomImportExcelDto = new RoomDto();
        List<Room> list = new ArrayList<>();
        List<Object> errorList = new ArrayList<>();
        Map<Long, Integer> residentialMap = new HashMap<>();
        Map<Long, Integer> unitMap = new HashMap<>();
        Workbook workbook = null;
        InputStream is = null;
        try {
            String fileName = file.getOriginalFilename();
            if (!fileName.matches(REGEX_EXCEL2003) && !fileName.matches(REGEX_EXCEL2007)) {
                return new ResultBean<>(ExcelResultEnum.FILE_TYPE_ERROR);
            }
            is = file.getInputStream();
            if (fileName.matches(REGEX_EXCEL2007)) {
                workbook = new XSSFWorkbook(is);
            }
            if (fileName.matches(REGEX_EXCEL2003)) {
                workbook = new HSSFWorkbook(is);
            }
            //默认第一页
            Sheet sheet = workbook.getSheetAt(0);
            //空白页或空白内容
            if (sheet.getPhysicalNumberOfRows() < 2 || sheet.getLastRowNum() < 1) {
                return new ResultBean<>(ExcelResultEnum.FILE_CONTENT_ERROR);
            }
//            //文件格式错误
//            if(sheet.getRow(0) != null &&  sheet.getRow(0).getPhysicalNumberOfCells() != 11){
//                return new ResultBean<>(ExcelResultEnum.FILE_CONTENT_ERROR);
//            }
            //文件数据量太大
            if (sheet.getPhysicalNumberOfRows() > 1000 && sheet.getLastRowNum() > 1000) {
                return new ResultBean<>(ExcelResultEnum.FILE_IS_BIG_1000);
            }
            int count = sheet.getLastRowNum();
            for (int j = 1; j <= count; j++) {
                //判断该行数据是否有误
                boolean flag = true;
                //造成行数据导入失败的错误信息
                StringBuffer importErrorMsg = new StringBuffer();
                int rowNum = j + 1;
                Row row = sheet.getRow(j);
                if (null == row) {
                    continue;
                }
                RoomDto roomDto = new RoomDto();
                String residentialNumber = getCellValue(row.getCell(0));
                if (StringUtils.isBlank(residentialNumber)) {
                    flag = false;
                    importErrorMsg.append("所属小区编号为空;");
                }
                roomDto.setResidentialNumber(residentialNumber);
                String unitNumber = getCellValue(row.getCell(1));
                if (StringUtils.isBlank(unitNumber)) {
                    flag = false;
                    importErrorMsg.append("单元编号为空;");
                }
                roomDto.setUnitNumber(unitNumber);
                String name = getCellValue(row.getCell(2));
                if (StringUtils.isBlank(name)) {
                    flag = false;
                    importErrorMsg.append("房间名称为空;");
                }
                roomDto.setName(name);
                String area = getCellValue(row.getCell(7));
                if (StringUtils.isNotBlank(area)) {
                    if (!Pattern.matches(REGEX_AREA, area)) {
                        flag = false;
                        importErrorMsg.append("房间面积格式错误;");
                    } else {
                        roomDto.setArea(area == null ? null : Double.valueOf(area));
                    }
                }

                //排序必须是整数
                String serial = getCellValue(row.getCell(9));
                if (StringUtils.isNotBlank(serial)) {
                    try {
                        roomDto.setSerial(Integer.valueOf(serial));
                    } catch (Exception e) {
                        flag = false;
                        importErrorMsg.append("排序的值不是整数;");
                    }
                } else {
                    roomDto.setSerial(OperationConstant.ONE);
                }


                ResultBean<Residential> residentialResultBean = this.getResidential(residentialNumber, rowNum);
                Residential residential = residentialResultBean.getData();
                long residentialId = 0L;
                if (null == residential || null == residential.getId()) {
                    flag = false;
                    importErrorMsg.append("小区编号对应的小区不存在;");
                } else {
                    residentialId = residential.getId();
                    roomDto.setResidentialId(residentialId);
                    if (residentialMap.containsKey(residentialId)) {
                        residentialMap.put(residentialId, residentialMap.get(residentialId) + 1);
                    } else {
                        residentialMap.put(residentialId, 1);
                    }
                }


                UnitDto unitDto = new UnitDto();
                unitDto.setResidentialId(residentialId);
                unitDto.setUnitNumber(unitNumber);
//                unitDto.setName(unitName);
                Unit unit = unitFeign.findUnitByNameAndNumber(unitDto);

                if (null == unit || null == unit.getId()) {
                    //去重
                    if (this.unitFeign.findUnitByCondition(unitDto) > 0) {
                        flag = false;
                        importErrorMsg.append("单元编号与小区编号不匹配;");
                    }
//                ResultBean<Unit> unitResultBean = this.getUnit(unitDto,rowNum,onLineUser);
//                Unit unit = unitResultBean.getData();
//                if(null == unit || null == unit.getId()){
//                    return new ResultBean<>("200",unitResultBean.getMsg());
                } else {
                    RoomDto roomDtoIsExit = new RoomDto();
                    long unitId = unit.getId();
                    roomDtoIsExit.setUnitId(unitId);
                    roomDtoIsExit.setName(name);
                    //没必要做缓存
                    if (this.roomFeign.findRoomByCondition(roomDtoIsExit) > 0) {
                        flag = false;
                        importErrorMsg.append("房间已存在；");
                    }
                    roomDto.setId(IdWorker.getId());
                    roomDto.setUnitName(unit.getName());
                    roomDto.setUnitId(unit.getId());
                    roomDto.setResidentialName(unit.getResidentialName());
                    roomDto.setRootOrgId(unit.getRootOrgId());
                    roomDto.setOrgPosition(unit.getOrgPosition() + roomDto.getId() + SymbolConstant.BACK_SLASH);
                    roomDto.setEstatePosition(unit.getEstatePosition() + roomDto.getId() + SymbolConstant.BACK_SLASH);
                    if (unitMap.containsKey(unitId)) {
                        unitMap.put(unitId, unitMap.get(unitId) + 1);
                        roomDto.setHouseNumber(CommonUtil.autoZeroFilling(4, unit.getRoomNumber() + unitMap.get(unitId)));
                    } else {
                        unitMap.put(unitId, 1);
                        roomDto.setHouseNumber(CommonUtil.autoZeroFilling(4, unit.getRoomNumber() + 1));
                    }
                }

                roomDto.setHouseType(getCellValue(row.getCell(3)));
                roomDto.setFloor(getCellValue(row.getCell(4)));
                roomDto.setOrientation(getCellValue(row.getCell(5)));
                roomDto.setOrnament(getCellValue(row.getCell(6)));
                roomDto.setRemark(getCellValue(row.getCell(8)));
                roomDto.setUserNumber(OperationConstant.ZERO);
                roomDto.setCreateDate(new Date());
                roomDto.setStatus(OperationConstant.ZERO);
                roomDto.setCreateAccountId(onLineUser.getId());

                if (flag) {
                    ResultBean<Room> resultBean = this.roomFeign.addRoom(roomDto);
                    System.out.println(resultBean.getCode() + " " + resultBean.getData() + " " + resultBean.getMsg());
                    if (resultBean.getCode().equals(ResultEnum.SUCCESS.getCode())) {
                    } else {
                        roomDto.setImportErrorMsg("后台添加失败，联系管理员;");
                        errorList.add(roomDto);
                    }

                } else {
                    roomDto.setImportErrorMsg(importErrorMsg.toString());
                    errorList.add(roomDto);
                }
            }
            if (!errorList.isEmpty()) {
                return new ResultBean<>(ExcelResultEnum.SUCCESS_ERROR, errorList);
            } else {
                return new ResultBean<>(ExcelResultEnum.SUCCESS);
            }
        } catch (IOException e) {
            e.printStackTrace();
            return new ResultBean<>(ExcelResultEnum.ERROR);
        } finally {
            try {
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 功能描述:住户导入
     *
     * @param file onLineUser
     * @return ResultBean<ResidentialDto>
     */
    public ResultBean<UserDto> readUserExcel_old(MultipartFile file, Account onLineUser, String isUpdate) {
        UserDto userImportExcelDto = new UserDto();
        List<User> list = new ArrayList<>();
        //新增集合
        List<User> addList = new ArrayList<>();
        Map<Long, Integer> residentialMap = new HashMap<>();
        Map<Long, Integer> unitMap = new HashMap<>();
        Map<Long, Integer> roomMap = new HashMap<>();
        Workbook workbook = null;
        InputStream is = null;
        try {
            String fileName = file.getOriginalFilename();
            if (!fileName.matches(REGEX_EXCEL2003) && !fileName.matches(REGEX_EXCEL2007)) {
                return new ResultBean<>(ExcelResultEnum.FILE_TYPE_ERROR);
            }
            is = file.getInputStream();
            if (fileName.matches(REGEX_EXCEL2007)) {
                workbook = new XSSFWorkbook(is);
            }
            if (fileName.matches(REGEX_EXCEL2003)) {
                workbook = new HSSFWorkbook(is);
            }
            //默认第一页
            Sheet sheet = workbook.getSheetAt(0);
            //空白页或空白内容
            if (sheet.getPhysicalNumberOfRows() < 2 || sheet.getLastRowNum() < 1) {
                return new ResultBean<>(ExcelResultEnum.FILE_CONTENT_ERROR);
            }
//            //文件格式错误
//            if(sheet.getRow(0) != null &&  sheet.getRow(0).getPhysicalNumberOfCells() != 12){
//                return new ResultBean<>(ExcelResultEnum.FILE_CONTENT_ERROR);
//            }
            //文件数据量太大
            if (sheet.getPhysicalNumberOfRows() > 1000 && sheet.getLastRowNum() > 1000) {
                return new ResultBean<>(ExcelResultEnum.FILE_IS_BIG_1000);
            }
            int count = sheet.getLastRowNum();
            for (int j = 1; j <= count; j++) {
                int rowNum = j + 1;
                Row row = sheet.getRow(j);
                if (null == row) {
                    continue;
                }
                User user = new User();
                String residentialNumber = getCellValue(row.getCell(0));
                if (StringUtils.isBlank(residentialNumber)) {
                    return new ResultBean<>("200", "第" + rowNum + "行所属小区编号为空，请核实后重新操作");
                }
                String unitName = getCellValue(row.getCell(1));
                if (StringUtils.isBlank(unitName)) {
                    return new ResultBean<>("200", "第" + rowNum + "行单元名称为空，请核实后重新操作");
                }
                String unitNumber = getCellValue(row.getCell(2));
                if (StringUtils.isBlank(unitNumber)) {
                    return new ResultBean<>("200", "第" + rowNum + "行单元编号为空，请核实后重新操作");
                }
                String roomName = getCellValue(row.getCell(3));
                if (StringUtils.isBlank(roomName)) {
                    return new ResultBean<>("200", "第" + rowNum + "行房间名称为空，请核实后重新操作");
                }
                String houseNumber = getCellValue(row.getCell(4));
                if (StringUtils.isBlank(houseNumber)) {
                    return new ResultBean<>("200", "第" + rowNum + "行门牌号为空，请核实后重新操作");
                }
                if (!Pattern.matches(REGEX_NUMBER, houseNumber)) {
                    return new ResultBean<>("200", "第" + rowNum + "行门牌号格式错误，请核实后重新操作");
                }
                String name = getCellValue(row.getCell(5));
                if (StringUtils.isBlank(name)) {
                    return new ResultBean<>("200", "第" + rowNum + "行房间名称为空，请核实后重新操作");
                }
                user.setName(name);
                String tel = getCellValue(row.getCell(6));
                if (StringUtils.isBlank(tel)) {
                    return new ResultBean<>("200", "第" + rowNum + "行住户联系方式为空，请核实后重新操作");
                }
                if (!Pattern.matches(REGEX_MOBILE, tel)) {
                    return new ResultBean<>("200", "第" + rowNum + "行住户联系方式格式错误，请核实后重新操作");
                }
                user.setTel(tel);
                String sexName = getCellValue(row.getCell(7));
                if (StringUtils.isBlank(sexName)) {
                    return new ResultBean<>("200", "第" + rowNum + "行住户性别为空，请核实后重新操作");
                }
                int sex = this.getSexBySexName(sexName);
                if (sex == OperationConstant.MINUS_ONE) {
                    return new ResultBean<>("200", "第" + rowNum + "行住户性别填写错误，请核实后重新操作");
                }
                user.setSex(sex);
                String typeName = getCellValue(row.getCell(8));
                String idCard = getCellValue(row.getCell(9));
                if (StringUtils.isBlank(typeName)) {
                    return new ResultBean<>("200", "第" + rowNum + "行住户类型为空，请核实后重新操作");
                }
                int type = this.getTypeByTypeName(typeName);
                if (type == OperationConstant.MINUS_ONE) {
                    return new ResultBean<>("200", "第" + rowNum + "行住户类型填写错误，请核实后重新操作");
                } else {
                    if (type == OperationConstant.ZERO) {
                        if (StringUtils.isBlank(idCard)) {
                            return new ResultBean<>("200", "第" + rowNum + "行业主身份证必填，请核实后重新操作");
                        }
                        if (idCard.length() > 18) {
                            return new ResultBean<>("200", "第" + rowNum + "行身份证格式错误，请核实后重新操作");
                        }
                    }
                }
                user.setIdCard(idCard);
                user.setType(type);
                ResultBean<Residential> residentialResultBean = this.getResidential(residentialNumber, rowNum);
                Residential residential = residentialResultBean.getData();
                if (null == residential || null == residential.getId()) {
                    return new ResultBean<>("200", residentialResultBean.getMsg());
                }
                long residentialId = residential.getId();
                user.setResidentialId(residentialId);

                UnitDto unitDto = new UnitDto();
                unitDto.setResidentialId(residentialId);
                unitDto.setUnitNumber(unitNumber);
                unitDto.setName(unitName);
                ResultBean<Unit> unitResultBean = this.getUnit(unitDto, rowNum, onLineUser);
                Unit unit = unitResultBean.getData();
                if (null == unit || null == unit.getId()) {
                    return new ResultBean<>("200", unitResultBean.getMsg());
                }
                long unitId = unit.getId();
                user.setUnitId(unitId);

                RoomDto roomDto = new RoomDto();
                roomDto.setResidentialId(residentialId);
                roomDto.setUnitId(unitId);
                roomDto.setName(roomName);
                roomDto.setHouseNumber(houseNumber);
                ResultBean<Room> roomResultBean = this.getRoom(roomDto, rowNum, onLineUser);
                Room room = roomResultBean.getData();
                if (null == room || null == room.getId()) {
                    return new ResultBean<>("200", roomResultBean.getMsg());
                }
                long roomId = room.getId();
                user.setRoomId(roomId);

                UserDto userDto = new UserDto();
                userDto.setRoomId(roomId);
                userDto.setName(name);
                userDto.setTel(tel);
                User dbUser = this.userFeign.findUserByCondition(userDto);
                if (null != dbUser) {
                    if ("1".equals(isUpdate)) {
                        user.setId(dbUser.getId());
                    } else {
                        return new ResultBean<>("200", "第" + rowNum + "行住户信息已存在，请核实后重新操作");
                    }
                }
                user.setRoomName(room.getName());
                user.setUnitName(unit.getName());
                user.setResidentialName(residential.getName());
                user.setRegionProvince(residential.getRegionProvince());
                user.setRegionCity(residential.getRegionCity());
                user.setRegionArea(residential.getRegionArea());
                user.setCheckState(OperationConstant.ZERO);
                user.setRootOrgId(room.getRootOrgId());
                user.setCreateDate(new Date());
                user.setStatus(OperationConstant.ZERO);
                user.setCreateType(OperationConstant.TWO);
                user.setBirthPlace(getCellValue(row.getCell(10)));
                user.setRemark(getCellValue(row.getCell(11)));
                user.setCreateId(onLineUser.getId());
                if (null == user.getId()) {
                    //id不存在 才算新增
                    if (residentialMap.containsKey(residentialId)) {
                        residentialMap.put(residentialId, residentialMap.get(residentialId) + 1);
                    } else {
                        residentialMap.put(residentialId, 1);
                    }
                    if (unitMap.containsKey(unitId)) {
                        unitMap.put(unitId, unitMap.get(unitId) + 1);
                    } else {
                        unitMap.put(unitId, 1);
                    }
                    if (roomMap.containsKey(roomId)) {
                        roomMap.put(roomId, roomMap.get(roomId) + 1);
                    } else {
                        roomMap.put(roomId, 1);
                    }
                    user.setId(IdWorker.getId());
                    addList.add(user);
                }
                user.setOrgPosition(room.getOrgPosition() + user.getId() + SymbolConstant.BACK_SLASH);
                user.setEstatePosition(room.getEstatePosition() + user.getId() + SymbolConstant.BACK_SLASH);
                list.add(user);
            }
            if (!list.isEmpty()) {
                userImportExcelDto.setList(list);
                userImportExcelDto.setAddList(addList);
                userImportExcelDto.setResidentialMap(residentialMap);
                userImportExcelDto.setUnitMap(unitMap);
                userImportExcelDto.setRoomMap(roomMap);
                return new ResultBean<>(ExcelResultEnum.SUCCESS, userImportExcelDto);
            } else {
                return new ResultBean<>(ExcelResultEnum.FILE_CONTENT_ERROR);
            }
        } catch (IOException e) {
            e.printStackTrace();
            return new ResultBean<>(ExcelResultEnum.ERROR);
        } finally {
            try {
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 功能描述:住户导入2.0版本
     *
     * @param file onLineUser
     * @return ResultBean<ResidentialDto>
     */
    public ResultBean<Object> readUserExcel(MultipartFile file, Account onLineUser, String isUpdate) {
        UserDto userImportExcelDto = new UserDto();
        List<User> list = new ArrayList<>();
        List<Object> errorList = new ArrayList<>();
        //新增集合
        List<User> addList = new ArrayList<>();
        Map<Long, Integer> residentialMap = new HashMap<>();
        Map<Long, Integer> unitMap = new HashMap<>();
        Map<Long, Integer> roomMap = new HashMap<>();
        Workbook workbook = null;
        InputStream is = null;
        try {
            String fileName = file.getOriginalFilename();
            if (!fileName.matches(REGEX_EXCEL2003) && !fileName.matches(REGEX_EXCEL2007)) {
                return new ResultBean<>(ExcelResultEnum.FILE_TYPE_ERROR);
            }
            is = file.getInputStream();
            if (fileName.matches(REGEX_EXCEL2007)) {
                workbook = new XSSFWorkbook(is);
            }
            if (fileName.matches(REGEX_EXCEL2003)) {
                workbook = new HSSFWorkbook(is);
            }
            //默认第一页
            Sheet sheet = workbook.getSheetAt(0);
            //空白页或空白内容
            if (sheet.getPhysicalNumberOfRows() < 2 || sheet.getLastRowNum() < 1) {
                return new ResultBean<>(ExcelResultEnum.FILE_CONTENT_ERROR);
            }
//            //文件格式错误
//            if(sheet.getRow(0) != null &&  sheet.getRow(0).getPhysicalNumberOfCells() != 12){
//                return new ResultBean<>(ExcelResultEnum.FILE_CONTENT_ERROR);
//            }
            //文件数据量太大
            if (sheet.getPhysicalNumberOfRows() > 1000 && sheet.getLastRowNum() > 1000) {
                return new ResultBean<>(ExcelResultEnum.FILE_IS_BIG_1000);
            }
            int count = sheet.getLastRowNum();
            for (int j = 1; j <= count; j++) {
                //判断该行数据是否有误
                boolean flag = true;
                //造成行数据导入失败的错误信息
                StringBuffer importErrorMsg = new StringBuffer();
                int rowNum = j + 1;
                Row row = sheet.getRow(j);
                if (null == row) {
                    continue;
                }
                ResidentialDto residentialDto = new ResidentialDto();
                BuildingDto buildingDto = new BuildingDto();
                UnitDto unitDto = new UnitDto();
                FloorDto floorDto = new FloorDto();
                RoomDto roomDto = new RoomDto();
                UserDto userDto = new UserDto();


                /*省*/
                String regionProvince = getCellValue(row.getCell(0));
                if (StringUtils.isBlank(regionProvince)) {
                    flag = false;
                    importErrorMsg.append("小区所属省为空;");
                }
                String provinceCode = regionProvince.split("_")[1];
                residentialDto.setRegionProvince(provinceCode);

                /*市*/
                String regionCity = getCellValue(row.getCell(1));
                if (StringUtils.isBlank(regionCity)) {
                    flag = false;
                    importErrorMsg.append("小区所属市为空;");
                }
                String cityCode = regionCity.split("_")[1];
                residentialDto.setRegionCity(cityCode);

                /*区/县*/
                String regionArea = getCellValue(row.getCell(2));
                if (StringUtils.isBlank(regionArea)) {
                    flag = false;
                    importErrorMsg.append("小区所属区/县为空;");
                }
                String areaCode = regionArea.split("_")[1];
                residentialDto.setRegionArea(areaCode);

                //小区名称（全称）
                String residentialName = getCellValue(row.getCell(3));
                if (StringUtils.isBlank(residentialName)){
                    flag = false;
                    importErrorMsg.append("小区名称为空;");
                    userDto.setImportErrorMsg(importErrorMsg.toString());
                    errorList.add(userDto);
                    continue;
                }else{
                    residentialDto.setName(residentialName);

                    Residential residential = null;
                    ResultBean<Residential> residentialBean = residentialFeign.getListByCondition(residentialDto);
                    if (residentialBean.getList().size() > 0){
                        residential = residentialBean.getList().get(0);
                        buildingDto.setResidentialId(residential.getId());
                        unitDto.setResidentialId(residential.getId());
                        floorDto.setResidentialId(residential.getId());
                        roomDto.setResidentialId(residential.getId());
                        userDto.setResidentialId(residential.getId());
                        userDto.setResidentialName(residentialName);
                    }else{
                        flag = false;
                        importErrorMsg.append("找不到该小区;");
                        userDto.setImportErrorMsg(importErrorMsg.toString());
                        errorList.add(userDto);
                        continue;
                    }
                }

                // 楼栋
                String buildingName = getCellValue(row.getCell(4));
                if (StringUtils.isBlank(buildingName)) {
                    flag = false;
                    importErrorMsg.append("楼栋名称为空;");
                    userDto.setImportErrorMsg(importErrorMsg.toString());
                    errorList.add(userDto);
                    continue;
                }else {
                    buildingDto.setName(buildingName);

                    Building building = null;
                    List<Building> buildingList = buildingFeign.getListByCondition(buildingDto);
                    if (buildingList.size() > 0){
                        building = buildingList.get(0);
                        unitDto.setBuildingId(building.getId());
                        floorDto.setBuildingId(building.getId());
                        roomDto.setBuildingId(building.getId());
                        userDto.setBuildingId(building.getId());
                        userDto.setBuildingName(buildingName);
                    }else{
                        flag = false;
                        importErrorMsg.append("找不到该楼栋（" + buildingName + "）;");
                        userDto.setImportErrorMsg(importErrorMsg.toString());
                        errorList.add(userDto);
                        continue;
                    }
                }

                // 单元
                String unitName = getCellValue(row.getCell(5));
                if (StringUtils.isBlank(unitName)) {
                    flag = false;
                    importErrorMsg.append("房间编号为空;");
                    userDto.setImportErrorMsg(importErrorMsg.toString());
                    errorList.add(userDto);
                    continue;
                }else{
                    unitDto.setName(unitName);

                    Unit unit = null;
                    List<Unit> unitList = unitFeign.getListByCondition(unitDto);
                    if (unitList.size() > 0){
                        unit = unitList.get(0);
                        floorDto.setUnitId(unit.getId());
                        roomDto.setUnitId(unit.getId());
                        userDto.setUnitId(unit.getId());
                        userDto.setUnitName(unitName);
                    }else{
                        flag = false;
                        importErrorMsg.append("找不到该单元（" + unitName + "）;");
                        userDto.setImportErrorMsg(importErrorMsg.toString());
                        errorList.add(userDto);
                        continue;
                    }
                }

                // 楼层
                String floorName = getCellValue(row.getCell(6));
                if (StringUtils.isBlank(floorName)) {
                    flag = false;
                    importErrorMsg.append("楼层为空");
                    userDto.setImportErrorMsg(importErrorMsg.toString());
                    errorList.add(userDto);
                    continue;
                }else{
                    floorDto.setName(floorName);

                    Floor floor = null;
                    List<Floor> floorList = floorFeign.getListByCondition(floorDto);
                    if (floorList.size() > 0){
                        floor = floorList.get(0);
                        roomDto.setFloorId(floor.getId());
                        userDto.setFloorId(floor.getId());
                        userDto.setFloorName(floorName);
                    }else{
                        flag = false;
                        importErrorMsg.append("找不到该楼层（" + floorName + "）;");
                        userDto.setImportErrorMsg(importErrorMsg.toString());
                        errorList.add(userDto);
                        continue;
                    }

                }

                // 房屋
                Room room = null;
                String roomName = getCellValue(row.getCell(7));
                if (StringUtils.isBlank(roomName)) {
                    flag = false;
                    importErrorMsg.append("房屋名称为空;");
                    userDto.setImportErrorMsg(importErrorMsg.toString());
                    errorList.add(userDto);
                    continue;
                }else{
                    roomDto.setName(roomName);


                    List<Room> roomList = roomFeign.getListByCondition(roomDto);
                    if (roomList.size() > 0){
                        room = roomList.get(0);
                        userDto.setRoomId(room.getId());
                        userDto.setRoomName(roomName);
                    }else {
                        flag = false;
                        importErrorMsg.append("找不到该房屋（" + roomName + "）;");
                        userDto.setImportErrorMsg(importErrorMsg.toString());
                        errorList.add(userDto);
                        continue;
                    }
                }

                // 姓名
                String userName = getCellValue(row.getCell(8));
                if (StringUtils.isBlank(userName)) {
                    flag = false;
                    importErrorMsg.append("姓名为空;");
                }
                userDto.setName(userName);

                //性别
                String sexName = getCellValue(row.getCell(10));
                if (StringUtils.isBlank(sexName)) {
                    flag = false;
                    importErrorMsg.append("性别为空;");
                }
                int sex = this.getSexBySexName(sexName);
                if (sex == OperationConstant.MINUS_ONE) {
                    flag = false;
                    importErrorMsg.append("性别填写错误;");
                }
                userDto.setSex(sex);

                // 手机
                String tel = getCellValue(row.getCell(9));
                //住户类型
                String typeName = getCellValue(row.getCell(11));
                //身份证
                String idCard = getCellValue(row.getCell(12));
                if (StringUtils.isBlank(typeName)) {
                    flag = false;
                    importErrorMsg.append("住户类型为空;");
                }
                int type = this.getTypeByTypeName(typeName);
                if (type == OperationConstant.MINUS_ONE) {
                    flag = false;
                    importErrorMsg.append("住户类型填写错误;");
                } else {
                    if (type == OperationConstant.ZERO) {
                        if (StringUtils.isBlank(idCard)) {
                            flag = false;
                            importErrorMsg.append("业主身份证必填;");
                        }
                        if (idCard.length() > 18) {
                            flag = false;
                            importErrorMsg.append("身份证格式错误;");
                        }
                        if (StringUtils.isBlank(tel)){
                            flag = false;
                            importErrorMsg.append("业主联系方式必填;");
                        }
                    }
                }
                userDto.setIdCard(idCard);
                userDto.setType(type);
                userDto.setTel(tel);


                UserDto userDtoIsExist = new UserDto();
                userDtoIsExist.setRoomId(room.getId());
                userDtoIsExist.setName(userName);
                userDtoIsExist.setTel(tel);
                User dbUser = this.userFeign.findUserByCondition(userDtoIsExist);
                if (null != dbUser) {
                    if ("1".equals(isUpdate)) {
                        userDto.setId(dbUser.getId());
                    } else {
                        flag = false;
                        importErrorMsg.append("住户信息已存在;");
                    }
                }

                userDto.setCheckState(OperationConstant.MINUS_ONE); //未上传人脸状态
                userDto.setCreateDate(new Date());
                userDto.setStatus(OperationConstant.ZERO);
                userDto.setCreateType(OperationConstant.TWO);
                userDto.setBirthPlace(getCellValue(row.getCell(13)));
                userDto.setRemark(getCellValue(row.getCell(14)));
                userDto.setCreateId(onLineUser.getId());
                userDto.setIsMember(OperationConstant.ZERO); //未激活APP
                if (null == userDto.getId()) {
                    /*//id不存在 才算新增
                    if (residentialId != 0L && residentialMap.containsKey(residentialId)) {
                        residentialMap.put(residentialId, residentialMap.get(residentialId) + 1);
                    } else if (residentialId != 0L) {
                        residentialMap.put(residentialId, 1);
                    }
                    if (unitId != 0L && unitMap.containsKey(unitId)) {
                        unitMap.put(unitId, unitMap.get(unitId) + 1);
                    } else if (unitId != 0L) {
                        unitMap.put(unitId, 1);
                    }
                    if (roomMap.containsKey(roomId)) {
                        roomMap.put(roomId, roomMap.get(roomId) + 1);
                    } else {
                        roomMap.put(roomId, 1);
                    }*/
                    userDto.setId(IdWorker.getId());
                }
                if (room != null) {
                    userDto.setOrgPosition(room.getOrgPosition() + userDto.getId() + SymbolConstant.BACK_SLASH);
                    userDto.setEstatePosition(room.getEstatePosition() + userDto.getId() + SymbolConstant.BACK_SLASH);
                }

                if (flag) {
                    ResultBean<Boolean> resultBean = this.userFeign.addUser(userDto);
                    System.out.println(resultBean.getCode() + " " + resultBean.getData() + " " + resultBean.getMsg());
                    if (resultBean.getCode().equals(ResultEnum.SUCCESS.getCode())) {
                    } else {
                        roomDto.setImportErrorMsg("后台添加失败，联系管理员;");
                        errorList.add(userDto);
                    }

                } else {
                    userDto.setImportErrorMsg(importErrorMsg.toString());
                    errorList.add(userDto);
                }
            }
            if (!errorList.isEmpty()) {
                return new ResultBean<>(ExcelResultEnum.SUCCESS_ERROR, errorList);
            } else {
                return new ResultBean<>(ExcelResultEnum.SUCCESS);
            }
        } catch (IOException e) {
            e.printStackTrace();
            return new ResultBean<>(ExcelResultEnum.ERROR);
        } finally {
            try {
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 功能描述:住户卡导入
     *
     * @param file onLineUser
     * @return ResultBean<ResidentialDto>
     */
    public ResultBean<Object> readUserCardExcel(MultipartFile file, Account onLineUser) {
        List<AccessCard> list = new ArrayList<>();
        Workbook workbook = null;
        List<Object> errorList = new ArrayList<>();
        InputStream is = null;
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            String fileName = file.getOriginalFilename();
            if (!fileName.matches(REGEX_EXCEL2003) && !fileName.matches(REGEX_EXCEL2007)) {
                return new ResultBean<>(ExcelResultEnum.FILE_TYPE_ERROR);
            }
            is = file.getInputStream();
            if (fileName.matches(REGEX_EXCEL2007)) {
                workbook = new XSSFWorkbook(is);
            }
            if (fileName.matches(REGEX_EXCEL2003)) {
                workbook = new HSSFWorkbook(is);
            }
            //默认第一页
            Sheet sheet = workbook.getSheetAt(0);
            //空白页或空白内容
            if (sheet.getPhysicalNumberOfRows() < 2 || sheet.getLastRowNum() < 1) {
                return new ResultBean<>(ExcelResultEnum.FILE_CONTENT_ERROR);
            }
//            //文件格式错误
//            if(sheet.getRow(0) != null &&  sheet.getRow(0).getPhysicalNumberOfCells() != 7){
//                return new ResultBean<>(ExcelResultEnum.FILE_CONTENT_ERROR);
//            }
            //文件数据量太大
            if (sheet.getPhysicalNumberOfRows() > 2000 && sheet.getLastRowNum() > 2000) {
                return new ResultBean<>(ExcelResultEnum.FILE_IS_BIG_2000);
            }
            int count = sheet.getLastRowNum();
            for (int j = 1; j <= count; j++) {
                //判断该行数据是否有误
                boolean flag = true;
                //造成行数据导入失败的错误信息
                StringBuffer importErrorMsg = new StringBuffer();
                int rowNum = j + 1;
                Row row = sheet.getRow(j);
                if (null == row) {
                    continue;
                }
                AccessCardDto accessCardDto = new AccessCardDto();
                String residentialNumber = getCellValue(row.getCell(0));
                if (StringUtils.isBlank(residentialNumber)) {
                    flag = false;
                    importErrorMsg.append("所属小区编号为空;");
                }
                accessCardDto.setResidentialNumber(residentialNumber);
                String unitNumber = getCellValue(row.getCell(1));
                if (StringUtils.isBlank(unitNumber)) {
                    flag = false;
                    importErrorMsg.append("所属单元编号为空;");
                }
                accessCardDto.setUnitNumber(unitNumber);
                String houseNumber = getCellValue(row.getCell(2));
                if (StringUtils.isBlank(houseNumber)) {
                    flag = false;
                    importErrorMsg.append("所属房间编号为空;");
                }
                accessCardDto.setHouseNumber(houseNumber);
                String userName = getCellValue(row.getCell(3));
                if (StringUtils.isBlank(userName)) {
                    flag = false;
                    importErrorMsg.append("住户姓名为空;");
                }
                accessCardDto.setUserName(userName);
                String cardNo = getCellValue(row.getCell(4));
                if (StringUtils.isBlank(cardNo)) {
                    flag = false;
                    importErrorMsg.append("卡号为空;");
                }
                accessCardDto.setCardNo(cardNo);
                String beginDate = getCellValue(row.getCell(5));
                if (StringUtils.isBlank(beginDate)) {
                    flag = false;
                    importErrorMsg.append("卡号开始有效期为空;");
                } else {
                    try {
                        Date date = dateFormat.parse(beginDate);
                        accessCardDto.setBeginDate(date);
                    } catch (ParseException e) {
                        flag = false;
                        importErrorMsg.append("卡号开始有效期有误;");
                    }
                }
                String endDate = getCellValue(row.getCell(6));
                if (StringUtils.isBlank(endDate)) {
                    flag = false;
                    importErrorMsg.append("卡号结束有效期为空;");
                }else {
                    try {
                        Date date = dateFormat.parse(endDate);
                        accessCardDto.setEndDate(date);
                    } catch (ParseException e) {
                        flag = false;
                        importErrorMsg.append("卡号结束有效期有误;");
                    }
                }

                ResultBean<Residential> residentialResultBean = this.getResidential(residentialNumber, rowNum);
                Residential residential = residentialResultBean.getData();
                long residentialId = 0L;
                if (null == residential || null == residential.getId()) {
                    flag = false;
                    importErrorMsg.append("小区编号对应的小区不存在;");
                } else {
                    residentialId = residential.getId();
                    accessCardDto.setResidentialName(residential.getName());
                }

                accessCardDto.setResidentialId(residentialId);

                UnitDto unitDto = new UnitDto();
                unitDto.setResidentialId(residentialId);
                unitDto.setUnitNumber(unitNumber);
                ResultBean<Unit> unitResultBean = this.getUnitByAccessCard(unitDto, rowNum);
                Unit unit = unitResultBean.getData();
                long unitId = 0L;
                if (null == unit || null == unit.getId()) {
                    flag = false;
                    importErrorMsg.append("单元编号与小区编号不对应;");
                } else {
                    unitId = unit.getId();
                    accessCardDto.setUnitName(unit.getName());
                }

                accessCardDto.setUnitId(unitId);

                RoomDto roomDto = new RoomDto();
                roomDto.setUnitId(unitId);
                roomDto.setHouseNumber(houseNumber);
                ResultBean<Room> roomResultBean = this.getRoomByAccessCard(roomDto, rowNum);
                Room room = roomResultBean.getData();
                long roomId = 0L;
                if (null == room || null == room.getId()) {
                    flag = false;
                    importErrorMsg.append("房间编号与小区、单元编号不对应;");
                } else {
                    roomId = room.getId();
                    accessCardDto.setRoomName(room.getName());
                }
                accessCardDto.setRoomId(roomId);

                UserDto userDto = new UserDto();
                userDto.setRoomId(roomId);
                userDto.setName(userName);
                HashOperations<String, String, String> hashOperations = this.redisTemplate.opsForHash();
                StringBuffer sb = new StringBuffer(roomId + "" + userName);
                String hashKey = sb.toString();
                String json = hashOperations.get(IMPORT_CACHE_USER_NMAE, hashKey);
                User user;
                long userId = 0L;
                if (StringUtils.isEmpty(json)) {
                    user = this.userFeign.findUserByName(userDto);
                    if (null == user || null == user.getId()) {
                        flag = false;
                        importErrorMsg.append("所属住户姓名不存在;");
                    }else {
                        user = JsonUtils.jsonToPojo(json, User.class);
                        userId = user.getId();
                        accessCardDto.setUserName(user.getName());
                        accessCardDto.setRootOrgId(user.getRootOrgId());
                        accessCardDto.setOrgPosition(user.getOrgPosition());
                    }
                    json = JsonUtils.objectToJson(user);
                    hashOperations.put(IMPORT_CACHE_USER_NMAE, hashKey, json);
                }
                accessCardDto.setUserId(String.valueOf(userId));

                AccessCardDto accessCardDtoIsExist = new AccessCardDto();
                accessCardDtoIsExist.setResidentialId(residentialId);
                accessCardDtoIsExist.setCardNo(cardNo);
                List<AccessCard> accessCardList = accessCardFeign.findAccessCardByCondition(accessCardDtoIsExist);
                if (null != accessCardList && !accessCardList.isEmpty()) {
                    flag = false;
                    importErrorMsg.append("卡号已存在;");
                }

                accessCardDto.setType(OperationConstant.ZERO);
                accessCardDto.setCreateDate(new Date());
                accessCardDto.setStatus(OperationConstant.ZERO);
                accessCardDto.setCreateAccountId(onLineUser.getId());
                if (flag) {
                    ResultBean<Boolean> resultBean = this.accessCardFeign.addAccessCard(accessCardDto);
                    System.out.println(resultBean.getCode() + " " + resultBean.getData() + " " + resultBean.getMsg());
                    if (resultBean.getCode().equals(ResultEnum.SUCCESS.getCode())) {
                    } else {
                        accessCardDto.setImportErrorMsg("后台添加失败，联系管理员;");
                        errorList.add(accessCardDto);
                    }

                } else {
                    accessCardDto.setImportErrorMsg(importErrorMsg.toString());
                    errorList.add(accessCardDto);
                }
            }
            if (!errorList.isEmpty()) {
                return new ResultBean<>(ExcelResultEnum.SUCCESS_ERROR, errorList);
            } else {
                return new ResultBean<>(ExcelResultEnum.SUCCESS);
            }

        } catch (Exception e) {
            e.printStackTrace();
            return new ResultBean<>(ExcelResultEnum.ERROR);
        } finally {
            try {
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 功能描述:管理卡导入
     *
     * @param file onLineUser
     * @return ResultBean<ResidentialDto>
     */
    public ResultBean<Object> readAccessCardExcel(MultipartFile file, Account onLineUser) {
        List<AccessCard> list = new ArrayList<>();
        List<Object> errorList = new ArrayList<>();
        Workbook workbook = null;
        InputStream is = null;
        try {
            String fileName = file.getOriginalFilename();
            if (!fileName.matches(REGEX_EXCEL2003) && !fileName.matches(REGEX_EXCEL2007)) {
                return new ResultBean<>(ExcelResultEnum.FILE_TYPE_ERROR);
            }
            is = file.getInputStream();
            if (fileName.matches(REGEX_EXCEL2007)) {
                workbook = new XSSFWorkbook(is);
            }
            if (fileName.matches(REGEX_EXCEL2003)) {
                workbook = new HSSFWorkbook(is);
            }
            //默认第一页
            Sheet sheet = workbook.getSheetAt(0);
            //空白页或空白内容
            if (sheet.getPhysicalNumberOfRows() < 2 || sheet.getLastRowNum() < 1) {
                return new ResultBean<>(ExcelResultEnum.FILE_CONTENT_ERROR);
            }
            //文件格式错误
//            if(sheet.getRow(0) != null &&  sheet.getRow(0).getPhysicalNumberOfCells() != 6){
//                return new ResultBean<>(ExcelResultEnum.FILE_CONTENT_ERROR);
//            }
            //  获取第2000行数据
            Row maxRow = sheet.getRow(2001);
            //  判断是否超出大小
            if (null != maxRow && org.springframework.util.StringUtils.hasText(getCellValue(maxRow.getCell(0)))) {
                return new ResultBean<>(ExcelResultEnum.FILE_IS_BIG_2000);
            }
            long nowTime = System.currentTimeMillis();
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            int count = sheet.getLastRowNum();
            List<AccessCardDto> accessCardList = new ArrayList<>();
            for (int j = 1; j <= count; j++) {
                //判断该行数据是否有误
                boolean flag = true;
                //造成行数据导入失败的错误信息
                StringBuffer importErrorMsg = new StringBuffer();
                int rowNum = j + 1;
                Row row = sheet.getRow(j);
                if (null == row) {
                    continue;
                }
                AccessCardDto accessCardDto = new AccessCardDto();
                String cardNo = getCellValue(row.getCell(0));
                if (StringUtils.isBlank(cardNo)) {
                    flag = false;
                    importErrorMsg.append("卡号为空;");
                }
                accessCardDto.setCardNo(cardNo);
                String beginDate = getCellValue(row.getCell(1));
                if (StringUtils.isBlank(beginDate)) {
                    flag = false;
                    importErrorMsg.append("卡号开始有效期为空;");
                } else {
                    try {
                        Date date = dateFormat.parse(beginDate);
                        accessCardDto.setBeginDate(date);
                    } catch (ParseException e) {
                        flag = false;
                        importErrorMsg.append("卡号开始有效期有误;");
                    }
                }

                String endDate = getCellValue(row.getCell(2));
                if (StringUtils.isBlank(endDate)) {
                    flag = false;
                    importErrorMsg.append("卡号结束有效期为空;");
                }
                //  判断有效期是否已小于当前时间
                try {
                    Date parse = dateFormat.parse(endDate);
                    accessCardDto.setEndDate(parse);
                    if (parse.getTime() < nowTime) {
                        flag = false;
                        importErrorMsg.append("卡号有效期已超时;");
                    }
                } catch (ParseException e) {
                    flag = false;
                    importErrorMsg.append("卡号结束有效期有误;");
                }
                String residentialNumber = getCellValue(row.getCell(3));
                accessCardDto.setResidentialNumber(residentialNumber);
                if (StringUtils.isBlank(residentialNumber)) {
                    flag = false;
                    importErrorMsg.append("所属小区编号为空;");
                }
                ResultBean<Residential> residentialResultBean = this.getResidential(residentialNumber, rowNum);
                Residential residential = residentialResultBean.getData();
                long residentialId = 0L;
                if (null == residential || null == residential.getId()) {
                    flag = false;
                    importErrorMsg.append("小区编号对应的小区不存在;");
                } else {
                    residentialId = residential.getId();
                    accessCardDto.setResidentialId(residentialId);
                    accessCardDto.setResidentialName(residential.getName());
                    accessCardDto.setOrgPosition(residential.getOrgPosition());
                    accessCardDto.setEstatePosition(residential.getEstatePosition());
                    accessCardDto.setType(OperationConstant.THREE);
                    accessCardDto.setRootOrgId(residential.getRootOrgId());
                }


                String unitNumber = getCellValue(row.getCell(4));
                accessCardDto.setUnitNumber(unitNumber);
                if (StringUtils.isNotBlank(unitNumber)) {
                    UnitDto unitDto = new UnitDto();
                    unitDto.setResidentialId(residentialId);
                    unitDto.setUnitNumber(unitNumber);
                    ResultBean<Unit> unitResultBean = this.getUnitByAccessCard(unitDto, rowNum);
                    Unit unit = unitResultBean.getData();
                    long unitId = 0L;
                    if (null == unit || null == unit.getId()) {
                        flag = false;
                        importErrorMsg.append("单元编号与小区编号不对应;");
                    } else {
                        unitId = unit.getId();
                        accessCardDto.setUnitId(unitId);
                        accessCardDto.setUnitName(unit.getName());
                        accessCardDto.setType(OperationConstant.TWO);
                        accessCardDto.setOrgPosition(unit.getOrgPosition());
                        accessCardDto.setEstatePosition(unit.getEstatePosition());
                    }


                    String houseNumber = getCellValue(row.getCell(5));
                    accessCardDto.setHouseNumber(houseNumber);
                    if (StringUtils.isNotBlank(houseNumber)) {
                        RoomDto roomDto = new RoomDto();
                        roomDto.setUnitId(unitId);
                        roomDto.setHouseNumber(houseNumber);
                        ResultBean<Room> roomResultBean = this.getRoomByAccessCard(roomDto, rowNum);
                        Room room = roomResultBean.getData();
                        long roomId = 0L;
                        if (null == room || null == room.getId()) {
                            flag = false;
                            importErrorMsg.append("房间编号与小区、单元编号不对应;");
                        }else {
                            roomId = room.getId();
                            accessCardDto.setRoomId(roomId);
                            accessCardDto.setRoomName(room.getName());
                            accessCardDto.setType(OperationConstant.ONE);
                            accessCardDto.setOrgPosition(room.getOrgPosition());
                            accessCardDto.setEstatePosition(room.getEstatePosition());
                        }
                    }
                }

                accessCardDto.setCreateDate(new Date());
                accessCardDto.setStatus(OperationConstant.ZERO);
                accessCardDto.setCreateAccountId(onLineUser.getId());

                ResultBean<AccessCardDto> resultBean = this.accessCardFeign.simpleAddOrUpdateUserCard(accessCardDto);
                if(resultBean.getData() != null){
                    accessCardList.add(resultBean.getData());
                }
//                if (flag) {
//                    ResultBean<Boolean> resultBean = this.accessCardFeign.addAccessCard(accessCardDto);
//                    System.out.println(resultBean.getCode() + " " + resultBean.getData() + " " + resultBean.getMsg());
//                    if (resultBean.getCode().equals(ResultEnum.SUCCESS.getCode())) {
//                    } else {
//                        accessCardDto.setImportErrorMsg("后台添加失败，联系管理员;");
//                        errorList.add(accessCardDto);
//                    }
//
//                } else {
//                    accessCardDto.setImportErrorMsg(importErrorMsg.toString());
//                    errorList.add(accessCardDto);
//                }
            }
            if (!errorList.isEmpty()) {
                return new ResultBean<>(ExcelResultEnum.SUCCESS_ERROR, errorList);
            } else {
                //批量不记名门禁卡下发
                if(accessCardList.size() > 0){
                    this.accessCardFeign.pushAccessCardBatch(accessCardList);
                }
                return new ResultBean<>(ExcelResultEnum.SUCCESS);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultBean<>(ExcelResultEnum.ERROR);
        } finally {
            try {
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 功能描述:获取单元格中的对象
     *
     * @param cell 一格
     * @return String
     */
    private static String getCellValue(Cell cell) {
        if (cell == null) {
            return null;
        }
        switch (cell.getCellTypeEnum()) {
            case NUMERIC:
                if (DateUtil.isCellDateFormatted(cell)) {
                    return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(cell.getDateCellValue());
                }
                return new BigDecimal(cell.getNumericCellValue()).toString().trim();
            case STRING:
                return StringUtils.trimToEmpty(cell.getStringCellValue());
            case FORMULA:
                return StringUtils.trimToEmpty(cell.getCellFormula());
            case BLANK:
                return null;
            case BOOLEAN:
                return String.valueOf(cell.getBooleanCellValue());
            case ERROR:
                return null;
            default:
                return cell.toString().trim();
        }
    }

    /**
     * 功能描述:根据名称和层级获取区域
     *
     * @param regionProvince 省名称
     * @param regionCity     市名称
     * @param regionArea     区名称
     * @return Area
     */
    private AreaDto getArea(String regionProvince, String regionCity, String regionArea) {
        AreaDto dto = new AreaDto();
        dto.setRegionProvince(regionProvince);
        dto.setRegionCity(regionCity);
        dto.setRegionArea(regionArea);
        Map<String, Object> map = this.areaFeign.selectByNameAndLayer(dto);
        if (map != null) {
            dto.setRegionProvince(String.valueOf((map.get("regionProvince"))));
            dto.setRegionCity(String.valueOf((map.get("regionCity"))));
            dto.setRegionArea(String.valueOf((map.get("regionArea"))));
            dto.setRegionName(String.valueOf((map.get("regionName"))));
        } else {
            dto = null;
        }

        return dto;
    }

    /**
     * 功能描述:获取小区并存入缓存
     *
     * @param residentialNumber 小区编号
     * @param rowNum            行好
     * @return ResultBean<Residential>
     */
    private ResultBean<Residential> getResidential(String residentialNumber, int rowNum) {
        HashOperations<String, String, String> hashOperations = this.redisTemplate.opsForHash();
        String hashKey = residentialNumber;
        String json = hashOperations.get(IMPORT_CACHE_RESIDENTIAL_CODE, hashKey);
        Residential residential;
        if (StringUtils.isEmpty(json)) {
            residential = this.residentialFeign.findResidentialByNumber(residentialNumber);
            if (null == residential || null == residential.getId()) {
                return new ResultBean<>("200", "第" + rowNum + "行所属小区编号不存在，请核实后重新操作");
            } else {
                json = JsonUtils.objectToJson(residential);
                hashOperations.put(IMPORT_CACHE_RESIDENTIAL_CODE, hashKey, json);
            }
        } else {
            residential = JsonUtils.jsonToPojo(json, Residential.class);
        }
        return new ResultBean<>(ResultEnum.SUCCESS, residential);
    }

    /**
     * 功能描述:获取单元 并存入缓存
     *
     * @param dto        单元业务对象
     * @param rowNum     行号
     * @param onLineUser 登陆用户
     * @return ResultBean<Unit>
     */
    private ResultBean<Unit> getUnit(UnitDto dto, int rowNum, Account onLineUser) {
        HashOperations<String, String, String> hashOperations = this.redisTemplate.opsForHash();
        long residentialId = dto.getResidentialId();
        String unitName = dto.getName();
        String unitNumber = dto.getUnitNumber();
        StringBuffer sb = new StringBuffer(residentialId + "-" + unitName + "-" + unitNumber);
        String hashKey = sb.toString();
        String json = hashOperations.get(IMPORT_CACHE_UNIT_CODE_NAME, hashKey);
        Unit unit;
        if (StringUtils.isEmpty(json)) {
            unit = this.unitFeign.findUnitByNameAndNumber(dto);
            if (null == unit || null == unit.getId()) {
                //去重
                if (this.unitFeign.findUnitByCondition(dto) > 0) {
                    return new ResultBean<>("200", "第" + rowNum + "行单元名称与编号不匹配，请核实后重新操作");
                }
                //新增单元
                unit = new Unit();
                unit.setCreateAccountId(onLineUser.getId());
                unit.setResidentialId(residentialId);
                unit.setUnitNumber(unitNumber);
                unit.setName(unitName);
                unit = this.unitFeign.addUnitByImport(unit);
                if (null != unit && null == unit.getId()) {
                    return new ResultBean<>("200", "第" + rowNum + "行生成单元信息有误，请核实后重新操作");
                }
            }
            json = JsonUtils.objectToJson(unit);
            hashOperations.put(IMPORT_CACHE_UNIT_CODE_NAME, hashKey, json);
        } else {
            unit = JsonUtils.jsonToPojo(json, Unit.class);
        }
        return new ResultBean<>(ResultEnum.SUCCESS, unit);
    }

    /**
     * 功能描述:获取小区，并存入缓存
     *
     * @param dto        单元业务对象
     * @param rowNum     行号
     * @param onLineUser 登陆用户
     * @return ResultBean<Room>
     */
    private ResultBean<Room> getRoom(RoomDto dto, int rowNum, Account onLineUser) {
        HashOperations<String, String, String> hashOperations = this.redisTemplate.opsForHash();
        long residentialId = dto.getResidentialId();
        long unitId = dto.getUnitId();
        String roomName = dto.getName();
        String houseNumber = dto.getHouseNumber();
        StringBuffer sb = new StringBuffer(residentialId + "" + unitId + "-" + roomName + "-" + houseNumber);
        String hashKey = sb.toString();
        String json = hashOperations.get(IMPORT_CACHE_ROOM_CODE_NAME, hashKey);
        Room room;
        if (StringUtils.isEmpty(json)) {
            room = this.roomFeign.findRoomByNameAndNumber(dto);
            if (null == room || null == room.getId()) {
                //去重
                if (this.roomFeign.findRoomByCondition(dto) > 0) {
                    return new ResultBean<>("200", "第" + rowNum + "行房间名称与门牌号不匹配，请核实后重新操作");
                }
                room = new Room();
                room.setCreateAccountId(onLineUser.getId());
                room.setResidentialId(residentialId);
                room.setUnitId(unitId);
                room.setHouseNumber(houseNumber);
                room.setName(roomName);
                room = this.roomFeign.addRoomByImport(room);
                if (null != room && null == room.getId()) {
                    return new ResultBean<>("200", "第" + rowNum + "行生成房间信息有误，请核实后重新操作");
                }
            }
            json = JsonUtils.objectToJson(room);
            hashOperations.put(IMPORT_CACHE_ROOM_CODE_NAME, hashKey, json);
        } else {
            room = JsonUtils.jsonToPojo(json, Room.class);
        }
        return new ResultBean<>(ResultEnum.SUCCESS, room);
    }

    /**
     * 功能描述:住户卡或卡管理 获取单元 并存入缓存
     *
     * @param dto    单元业务对象
     * @param rowNum 行号
     * @return ResultBean<Unit>
     */
    private ResultBean<Unit> getUnitByAccessCard(UnitDto dto, int rowNum) {
        HashOperations<String, String, String> hashOperations = this.redisTemplate.opsForHash();
        long residentialId = dto.getResidentialId();
        String unitNumber = dto.getUnitNumber();
        StringBuffer sb = new StringBuffer(residentialId + "" + unitNumber);
        String hashKey = sb.toString();
        String json = hashOperations.get(IMPORT_CACHE_UNIT_CODE, hashKey);
        Unit unit;
        if (StringUtils.isEmpty(json)) {
            unit = this.unitFeign.findUnitByNameAndNumber(dto);
            if (null == unit || null == unit.getId()) {
                return new ResultBean<>("200", "第" + rowNum + "行所属单元编号不存在，请核实后重新操作");
            }
            json = JsonUtils.objectToJson(unit);
            hashOperations.put(IMPORT_CACHE_UNIT_CODE, hashKey, json);
        } else {
            unit = JsonUtils.jsonToPojo(json, Unit.class);
        }
        return new ResultBean<>(ResultEnum.SUCCESS, unit);
    }

    /**
     * 功能描述:住户卡或卡管理 获取房间元 并存入缓存
     *
     * @param dto    房间业务对象
     * @param rowNum 行号
     * @return ResultBean<Room>
     */
    private ResultBean<Room> getRoomByAccessCard(RoomDto dto, int rowNum) {
        HashOperations<String, String, String> hashOperations = this.redisTemplate.opsForHash();
        long unitId = dto.getUnitId();
        String houseNumber = dto.getHouseNumber();
        StringBuffer sb = new StringBuffer(unitId + "" + houseNumber);
        String hashKey = sb.toString();
        String json = hashOperations.get(IMPORT_CACHE_ROOM_CODE, hashKey);
        Room room;
        if (StringUtils.isEmpty(json)) {
            room = this.roomFeign.findRoomByNameAndNumber(dto);
            if (null == room || null == room.getId()) {
                return new ResultBean<>("200", "第" + rowNum + "行所属房间编号不存在，请核实后重新操作");
            }
            json = JsonUtils.objectToJson(room);
            hashOperations.put(IMPORT_CACHE_ROOM_CODE, hashKey, json);
        } else {
            room = JsonUtils.jsonToPojo(json, Room.class);
        }
        return new ResultBean<>(ResultEnum.SUCCESS, room);
    }

    /**
     * 功能描述:根据类型名称获取类型状态
     *
     * @param typeName 类型名称
     * @return int
     */
    private int getTypeByTypeName(String typeName) {
        if(null == typeName){
            return -1;
        }
        switch (typeName) {
            case "业主":
                return 0;
            case "家属":
                return 1;
            case "租客":
                return 2;
            default:
                return -1;
        }
    }

    /**
     * 功能描述:根据性别名称获取性别状态
     *
     * @param sexName 性别名称
     * @return int
     */
    private int getSexBySexName(String sexName) {
        if(null == sexName){
            return -1;
        }
        switch (sexName) {
            case "未定义":
                return 0;
            case "男":
                return 1;
            case "女":
                return 2;
            default:
                return -1;
        }
    }

    /**
     * 第三方用户信息导入
     * @param file
     * @param onLineUser
     * @return
     */
    public ResultBean<Object> readThirdUserExcel(MultipartFile file, Account onLineUser) {
        ThirdUserDto userImportExcelDto = new ThirdUserDto();
        List<User> list = new ArrayList<>();
        List<Object> errorList = new ArrayList<>();
        //新增集合
        List<User> addList = new ArrayList<>();
        Map<Long, Integer> residentialMap = new HashMap<>();
        Map<Long, Integer> unitMap = new HashMap<>();
        Map<Long, Integer> roomMap = new HashMap<>();
        Workbook workbook = null;
        InputStream is = null;
        try {
            String fileName = file.getOriginalFilename();
            if (!fileName.matches(REGEX_EXCEL2003) && !fileName.matches(REGEX_EXCEL2007)) {
                return new ResultBean<>(ExcelResultEnum.FILE_TYPE_ERROR);
            }
            is = file.getInputStream();
            if (fileName.matches(REGEX_EXCEL2007)) {
                workbook = new XSSFWorkbook(is);
            }
            if (fileName.matches(REGEX_EXCEL2003)) {
                workbook = new HSSFWorkbook(is);
            }
            //默认第一页
            Sheet sheet = workbook.getSheetAt(0);
            //空白页或空白内容
            if (sheet.getPhysicalNumberOfRows() < 2 || sheet.getLastRowNum() < 1) {
                return new ResultBean<>(ExcelResultEnum.FILE_CONTENT_ERROR);
            }

            //文件数据量太大
            /*if (sheet.getPhysicalNumberOfRows() > 1000 && sheet.getLastRowNum() > 1000) {
                return new ResultBean<>(ExcelResultEnum.FILE_IS_BIG_1000);
            }*/
            int count = sheet.getLastRowNum();
            for (int j = 2; j <= count; j++) {
                //判断该行数据是否有误
                boolean flag = true;
                //造成行数据导入失败的错误信息
                StringBuffer importErrorMsg = new StringBuffer();
                int rowNum = j + 1;
                Row row = sheet.getRow(j);
                if (null == row) {
                    continue;
                }
                ResidentialDto residentialDto = new ResidentialDto();
                BuildingDto buildingDto = new BuildingDto();
                UnitDto unitDto = new UnitDto();
                FloorDto floorDto = new FloorDto();
                RoomDto roomDto = new RoomDto();
                UserDto userDto = new UserDto();

                ThirdUserDto thirdUserDto = new ThirdUserDto();

                /*省*/
                String name = getCellValue(row.getCell(1));
                String sex = getCellValue(row.getCell(2));
                String key = getCellValue(row.getCell(3));
                String agencyName = getCellValue(row.getCell(4));
                String residentialName = getCellValue(row.getCell(5));
                String houseInfo = getCellValue(row.getCell(6));
                String imageName = getCellValue(row.getCell(7));
                String idcard = getCellValue(row.getCell(8));
                String tel = getCellValue(row.getCell(9));
                String type = getCellValue(row.getCell(10));

                thirdUserDto.setName(name);
                thirdUserDto.setSex(sex);
                thirdUserDto.setKey(key);
                thirdUserDto.setAgencyName(agencyName);
                thirdUserDto.setResidentialname(residentialName);
                thirdUserDto.setHouseInfo(houseInfo);
                thirdUserDto.setImageName(imageName);
                thirdUserDto.setIdcard(idcard);
                thirdUserDto.setTel(tel);
                thirdUserDto.setType(type);

                thirdUserDto.setStatus(0);
                thirdUserDto.setCreateDate(new Date(System.currentTimeMillis()));
                ResultBean<Boolean> booleanResultBean = thirdUserFeign.addUser(thirdUserDto);

                /*residentialDto.setAgencyName(agencyName);
                residentialDto.setName(residentialName);
                ResultBean<Residential> residentialResultBean = this.residentialFeign.getListByCondition(residentialDto);
                List<Residential> residentialList = residentialResultBean.getList();
                Residential residential = null;
                if (residentialList.size() > 0) {
                    residential = residentialList.get(0);

                    String[] houseMsg = houseInfo.split("-");
                    String buildingName = houseMsg[houseMsg.length - 3] + "栋";
                    String unitName = houseMsg[houseMsg.length - 2] + "单元";
                    String roomName = houseMsg[houseMsg.length - 1];
                    String floorName = roomName.substring(0, roomName.length() - 2) + "层";
                    buildingDto.setResidentialId(residential.getId());
                    buildingDto.setName(buildingName);
                    List<Building> buildingList = this.buildingFeign.getListByCondition(buildingDto);

                    if (buildingList.size() > 0) {
                        Building building = buildingList.get(0);
                        unitDto.setResidentialId(residential.getId());
                        unitDto.setBuildingId(building.getId());
                        unitDto.setName(unitName);
                        List<Unit> unitList = this.unitFeign.getListByCondition(unitDto);
                        if (unitList.size() > 0) {
                            Unit unit = unitList.get(0);
                            floorDto.setResidentialId(residential.getId());
                            floorDto.setBuildingId(building.getId());
                            floorDto.setUnitId(unit.getId());
                            floorDto.setName(floorName);
                            List<Floor> floorList = this.floorFeign.getListByCondition(floorDto);
                            if (floorList.size() > 0) {
                                Floor floor = floorList.get(0);
                                roomDto.setResidentialId(residential.getId());
                                roomDto.setBuildingId(building.getId());
                                roomDto.setFloorId(floor.getId());
                                roomDto.setName(roomName);
                                List<Room> roomList = this.roomFeign.getListByCondition(roomDto);
                                if (roomList.size() > 0) {
                                    userDto.setResidentialId(residential.getId());
                                    userDto.setResidentialName(residentialName);
                                    userDto.setBuildingId(building.getId());
                                    userDto.setBuildingName(buildingName);
                                    userDto.setUnitId(unit.getId());
                                    userDto.setUnitName(unitName);
                                    userDto.setFloorId(floor.getId());
                                    userDto.setFloorName(floorName);
                                    userDto.setRoomId(roomList.get(0).getId());
                                    userDto.setRoomName(roomName);
                                    userDto.setImageUri(imageName);
                                    userDto.setName(name);
                                    userDto.setSex(this.getSexBySexName(sex));
                                    userDto.setIdCard(idcard);
                                    userDto.setTel(tel);
                                    userDto.setSign(0);
                                    userDto.setCreateType(1);//后台导入
                                    userDto.setCheckState(1);//审核通过

                                    this.userFeign.addUser(userDto);
                                } else {
                                    flag = false;
                                    importErrorMsg.append("找不到相应房屋；");
                                }
                            } else {
                                flag = false;
                                importErrorMsg.append("找不到相应楼层；");
                            }

                        } else {
                            flag = false;
                            importErrorMsg.append("找不到相应单元；");
                        }

                    } else {
                        flag = false;
                        importErrorMsg.append("找不到相应楼栋；");
                    }


                } else {
                    flag = false;
                    importErrorMsg.append("该社区下找不到该小区;");
                }

                if (!flag) {
                    thirdUserDto.setImportErrorMsg(importErrorMsg.toString());
                    errorList.add(thirdUserDto);
                }*/

            }

            if (!errorList.isEmpty()) {
                return new ResultBean<>(ExcelResultEnum.SUCCESS_ERROR, errorList);
            } else {
                return new ResultBean<>(ExcelResultEnum.SUCCESS);
            }

        } catch (IOException e) {
            e.printStackTrace();
            return new ResultBean<>(ExcelResultEnum.ERROR);
        } finally {
            try {
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }

}

