package com.nantian.cloud.jljc.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nantian.cloud.jljc.entity.TSupervisionPerson;
import com.nantian.cloud.jljc.mapper.TSupervisionPersonMapper;
import com.nantian.cloud.jljc.service.TSupervisionPersonService;
import com.nantian.cloud.jljc.vo.RegionPersonTreeVo;
import com.nantian.sc.cloud.common.data.datascope.DataScope;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.xssf.usermodel.*;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.ArrayList;
import java.util.List;

import static com.nantian.cloud.jljc.vo.util.TreeVoUtil.findTree;

@Service("TSupervisionPersonService")
public class TSupervisionPersonServiceImpl extends ServiceImpl<TSupervisionPersonMapper, TSupervisionPerson> implements TSupervisionPersonService {


    public IPage<TSupervisionPerson> selectall(Page page, TSupervisionPerson tSupervisionPerson) {
        return baseMapper.selectall(page, tSupervisionPerson, new DataScope());
    }

    @Override
    public boolean updateall(TSupervisionPerson tSupervisionPerson) {
        if (baseMapper.updateall(tSupervisionPerson) > 0) {
            return true;
        } else {
            return false;
        }

    }

    @Override
    public boolean deleteall(TSupervisionPerson tSupervisionPerson) {
        if (baseMapper.deleteall(tSupervisionPerson) > 0) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public boolean insertall(TSupervisionPerson tSupervisionPerson) {
        if (baseMapper.insertall(tSupervisionPerson) > 0) {
            return true;
        } else {
            return false;
        }
    }
    @Override
    public boolean importbyexcel(MultipartFile file, TSupervisionPersonService tSupervisionPersonService) throws IOException {//不覆盖
        List<TSupervisionPerson> list = new ArrayList<TSupervisionPerson>();
        List<String> tnames=baseMapper.selectallname();
        InputStream inputStream = file.getInputStream();
        if(file.getOriginalFilename().contains(".xlsx")){
            XSSFWorkbook book = new XSSFWorkbook(inputStream);
            XSSFSheet sheet = book.getSheetAt(0);
            for(int i=1; i<sheet.getLastRowNum()+1; i++) {
                TSupervisionPerson tSupervisionPerson=new TSupervisionPerson();
                XSSFRow row = sheet.getRow(i);
                if(row.getCell(0)==null){
                    break;
                }
                if(tnames.contains(row.getCell(0).toString())){
                    continue;
                }
                tSupervisionPerson.setName(row.getCell(0).toString());//name
                tSupervisionPerson.setSex(row.getCell(1)==null?null:row.getCell(1).toString());//sex
                tSupervisionPerson.setCode(row.getCell(2)==null?null:row.getCell(2).toString());//code
                if(row.getCell(3)==null){
                    tSupervisionPerson.setOrganizationid(row.getCell(3)==null?null:row.getCell(3).getStringCellValue());//organizationid
                }else {
                    if(StringUtils.isNumeric(row.getCell(3).toString().substring(0,row.getCell(3).toString().length()-2))){
                        tSupervisionPerson.setOrganizationid(row.getCell(3)==null?null:row.getCell(3).toString().substring(0,row.getCell(3).toString().length()-2));//organizationid
                    }
                    else {
                        tSupervisionPerson.setOrganizationid(row.getCell(3)==null?null:row.getCell(3).getStringCellValue());//organizationid
                    }
                }
                tSupervisionPerson.setJobs(row.getCell(4)==null?null:row.getCell(4).toString());//jobs
                tSupervisionPerson.setCellphone(row.getCell(5)==null?null:row.getCell(5).toString().substring(0,row.getCell(5).toString().length()-2));//cellphone
                tSupervisionPerson.setAreaCode(row.getCell(6)==null?null:row.getCell(6).toString().substring(0,row.getCell(6).toString().length()-2));//areacode
                tSupervisionPerson.setPersonType(row.getCell(7)==null?null:row.getCell(7).toString().substring(0,row.getCell(7).toString().length()-2));//persontype
                tSupervisionPerson.setLowType(row.getCell(8)==null?null:row.getCell(8).toString().substring(0,row.getCell(8).toString().length()-2));//lowtype
                tSupervisionPerson.setOrgan(row.getCell(9)==null?null:row.getCell(9).toString());//organ
//                tSupervisionPerson.setUserid(row.getCell(10)==null?null:Integer.parseInt(row.getCell(10).toString().substring(0,row.getCell(10).toString().length()-2)));//userid
//                tSupervisionPerson.setRemarks(row.getCell(11)==null?null:row.getCell(11).toString());//remarks
                tSupervisionPerson.setTelephone(row.getCell(10)==null?null:row.getCell(10).toString().substring(0,row.getCell(10).toString().length()-2));//telephone
                list.add(tSupervisionPerson);
            }
            if (baseMapper.insertbyexcel(list)) {
                return true;
            } else {
                return false;
            }
        }else {
            HSSFWorkbook book = new HSSFWorkbook(inputStream);
            HSSFSheet sheet = book.getSheetAt(0);
            for(int i=1; i<sheet.getLastRowNum()+1; i++) {
                TSupervisionPerson tSupervisionPerson=new TSupervisionPerson();
                HSSFRow row = sheet.getRow(i);
                if(row.getCell(0)==null){
                    break;
                }
                tSupervisionPerson.setName(row.getCell(0).toString());//name
                tSupervisionPerson.setSex(row.getCell(1)==null?null:row.getCell(1).toString());//sex
                tSupervisionPerson.setCode(row.getCell(2)==null?null:row.getCell(2).toString());//code
                if(row.getCell(3)==null){
                    tSupervisionPerson.setOrganizationid(row.getCell(3)==null?null:row.getCell(3).getStringCellValue());//organizationid
                }else {
                    if(StringUtils.isNumeric(row.getCell(3).toString().substring(0,row.getCell(3).toString().length()-2))){
                        tSupervisionPerson.setOrganizationid(row.getCell(3)==null?null:row.getCell(3).toString().substring(0,row.getCell(3).toString().length()-2));//organizationid
                    }
                    else {
                        tSupervisionPerson.setOrganizationid(row.getCell(3)==null?null:row.getCell(3).getStringCellValue());//organizationid
                    }
                }
                tSupervisionPerson.setJobs(row.getCell(4)==null?null:row.getCell(4).toString());//jobs
                tSupervisionPerson.setCellphone(row.getCell(5)==null?null:row.getCell(5).toString().substring(0,row.getCell(5).toString().length()-2));//cellphone
                tSupervisionPerson.setAreaCode(row.getCell(6)==null?null:row.getCell(6).toString().substring(0,row.getCell(6).toString().length()-2));//areacode
                tSupervisionPerson.setPersonType(row.getCell(7)==null?null:row.getCell(7).toString().substring(0,row.getCell(7).toString().length()-2));//persontype
                tSupervisionPerson.setLowType(row.getCell(8)==null?null:row.getCell(8).toString().substring(0,row.getCell(8).toString().length()-2));//lowtype
                tSupervisionPerson.setOrgan(row.getCell(9)==null?null:row.getCell(9).toString());//organ
//                tSupervisionPerson.setUserid(row.getCell(10)==null?null:Integer.parseInt(row.getCell(10).toString().substring(0,row.getCell(10).toString().length()-2)));//userid
//                tSupervisionPerson.setRemarks(row.getCell(11)==null?null:row.getCell(11).toString());//remarks
                tSupervisionPerson.setTelephone(row.getCell(10)==null?null:row.getCell(10).toString().substring(0,row.getCell(10).toString().length()-2));//telephone
                list.add(tSupervisionPerson);
            }
            if (baseMapper.insertbyexcel(list)) {
                return true;
            } else {
                return false;
            }
        }
    }

    @Override
    public void outpute(HttpServletRequest request, HttpServletResponse response) throws IOException {
        OutputStream outputStream = response.getOutputStream();
        XSSFWorkbook workbook=new XSSFWorkbook();
        XSSFSheet sheet= workbook.createSheet("监察人员信息模板");
        XSSFCellStyle style = workbook.createCellStyle();
        style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
        style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        style.setBorderBottom(BorderStyle.THIN);
        style.setBorderRight(BorderStyle.THIN);

        XSSFRow rowh=sheet.createRow(0);
        rowh.createCell(0).setCellValue("姓名");
        rowh.getCell(0).setCellStyle(style);
        rowh.createCell(1).setCellValue("性别");
        rowh.getCell(1).setCellStyle(style);
        rowh.createCell(2).setCellValue("行政执法编号");
        rowh.getCell(2).setCellStyle(style);
        rowh.createCell(3).setCellValue("工作单位");
        rowh.getCell(3).setCellStyle(style);
        rowh.createCell(4).setCellValue("工作职位");
        rowh.getCell(4).setCellStyle(style);
        rowh.createCell(5).setCellValue("联系方式（手机)");
        rowh.getCell(5).setCellStyle(style);
        rowh.createCell(6).setCellValue("负责区域（行政区划代码）");
        rowh.getCell(6).setCellStyle(style);
        rowh.createCell(7).setCellValue("人员种类（1 行政执法类公务员; 2 具有行政执法资格的工作人员; 3 从事日常监管工作的人员; 4 专家及其他人员）");
        rowh.getCell(7).setCellStyle(style);
        rowh.createCell(8).setCellValue("执法证类");
        rowh.getCell(8).setCellStyle(style);
        rowh.createCell(9).setCellValue("发证机关");
        rowh.getCell(9).setCellStyle(style);
//        rowh.createCell(10).setCellValue("操作id");
//        rowh.getCell(10).setCellStyle(style);
//        rowh.createCell(11).setCellValue("备注");
//        rowh.getCell(10).setCellStyle(style);
        rowh.createCell(10).setCellValue("电话");
        rowh.getCell(10).setCellStyle(style);

        XSSFRow row=sheet.createRow(1);
        row.createCell(0).setCellValue("王建");
        row.createCell(1).setCellValue("男");
        row.createCell(2).setCellValue("YCX04604");
        row.createCell(3).setCellValue("72/云南省监察中心");
        row.createCell(4).setCellValue("监查员");
        row.createCell(5).setCellValue("13457266303");
        row.createCell(6).setCellValue("530000");
        row.createCell(7).setCellValue("1");
        row.createCell(8).setCellValue("4");
        row.createCell(9).setCellValue("发改委");
//        row.createCell(10).setCellValue("12");
//        row.createCell(11).setCellValue("这里填写备注");
        row.createCell(10).setCellValue("077225622025");
        try {
            response.setCharacterEncoding("utf-8");
            response.setContentType("multipart/form-data");
            response.setHeader("Content-disposition",
                    "attachment;filename=" + java.net.URLEncoder.encode("mediUser.xlsx", "UTF-8"));
            response.flushBuffer();
            workbook.write(response.getOutputStream());
            workbook.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public List<String> checke_allname(MultipartFile file, TSupervisionPersonService tSupervisionPersonService) throws IOException {
        List<String> tnames=baseMapper.selectallname();
        List<String> backtnames=new ArrayList<>();
        InputStream inputStream = file.getInputStream();
        if(file.getOriginalFilename().contains(".xlsx")){
            XSSFWorkbook book = new XSSFWorkbook(inputStream);
            XSSFSheet sheet = book.getSheetAt(0);
            for(int i=1; i<sheet.getLastRowNum()+1; i++) {
                TSupervisionPerson tSupervisionPerson=new TSupervisionPerson();
                XSSFRow row = sheet.getRow(i);
                if(row.getCell(0)==null){
                    break;
                }
                if(tnames.contains(row.getCell(0).toString())){
                    backtnames.add(row.getCell(0).toString());
                }
            }
            System.out.println(backtnames);

        }else {
            HSSFWorkbook book = new HSSFWorkbook(inputStream);
            HSSFSheet sheet = book.getSheetAt(0);
            for(int i=1; i<sheet.getLastRowNum()+1; i++) {
                TSupervisionPerson tSupervisionPerson=new TSupervisionPerson();
                HSSFRow row = sheet.getRow(i);
                if(row.getCell(0)==null){
                    break;
                }
                if(row.getCell(0)==null){
                    break;
                }
                if(tnames.contains(row.getCell(0).toString())){
                    backtnames.add(row.getCell(0).toString());
                }
            }
            System.out.println(backtnames);
        }
        return backtnames;
    }

    @Override
    public boolean importbyexcelf(MultipartFile file, TSupervisionPersonService tSupervisionPersonService) throws IOException {//覆盖 更新
        List<TSupervisionPerson> list = new ArrayList<TSupervisionPerson>();
        List<TSupervisionPerson> uplist=new ArrayList<TSupervisionPerson>();
        List<String> tnames=baseMapper.selectallname();
        InputStream inputStream = file.getInputStream();
        if(file.getOriginalFilename().contains(".xlsx")){
            XSSFWorkbook book = new XSSFWorkbook(inputStream);
            XSSFSheet sheet = book.getSheetAt(0);
            for(int i=1; i<sheet.getLastRowNum()+1; i++) {
                TSupervisionPerson tSupervisionPerson=new TSupervisionPerson();
                XSSFRow row = sheet.getRow(i);
                if(row.getCell(0)==null){
                    break;
                }
                if(tnames.contains(row.getCell(0).toString())) { //如果重复
                    tSupervisionPerson.setName(row.getCell(0).toString());//name
                    tSupervisionPerson.setSex(row.getCell(1) == null ? null : row.getCell(1).toString());//sex
                    tSupervisionPerson.setCode(row.getCell(2) == null ? null : row.getCell(2).toString());//code
                    if (row.getCell(3) == null) {
                        tSupervisionPerson.setOrganizationid(row.getCell(3) == null ? null : row.getCell(3).getStringCellValue());//organizationid
                    } else {
                        if (StringUtils.isNumeric(row.getCell(3).toString().substring(0, row.getCell(3).toString().length() - 2))) {
                            tSupervisionPerson.setOrganizationid(row.getCell(3) == null ? null : row.getCell(3).toString().substring(0, row.getCell(3).toString().length() - 2));//organizationid
                        } else {
                            tSupervisionPerson.setOrganizationid(row.getCell(3) == null ? null : row.getCell(3).getStringCellValue());//organizationid
                        }
                    }
                    tSupervisionPerson.setJobs(row.getCell(4) == null ? null : row.getCell(4).toString());//jobs
                    tSupervisionPerson.setCellphone(row.getCell(5) == null ? null : row.getCell(5).toString());//cellphone
                    tSupervisionPerson.setAreaCode(row.getCell(6) == null ? null : row.getCell(6).toString());//areacode
                    tSupervisionPerson.setPersonType(row.getCell(7) == null ? null : row.getCell(7).toString());//persontype
                    tSupervisionPerson.setLowType(row.getCell(8) == null ? null : row.getCell(8).toString());//lowtype
                    tSupervisionPerson.setOrgan(row.getCell(9) == null ? null : row.getCell(9).toString());//organ
//                tSupervisionPerson.setUserid(row.getCell(10)==null?null:Integer.parseInt(row.getCell(10).toString().substring(0,row.getCell(10).toString().length()-2)));//userid
//                tSupervisionPerson.setRemarks(row.getCell(11)==null?null:row.getCell(11).toString());//remarks
                    tSupervisionPerson.setTelephone(row.getCell(10) == null ? null : row.getCell(10).toString());//telephone
                    uplist.add(tSupervisionPerson);
                }else { //如果不重复
                    tSupervisionPerson.setName(row.getCell(0).toString());//name
                    tSupervisionPerson.setSex(row.getCell(1)==null?null:row.getCell(1).toString());//sex
                    tSupervisionPerson.setCode(row.getCell(2)==null?null:row.getCell(2).toString());//code
                    if(row.getCell(3)==null){
                        tSupervisionPerson.setOrganizationid(row.getCell(3)==null?null:row.getCell(3).getStringCellValue());//organizationid
                    }else {
                        if(StringUtils.isNumeric(row.getCell(3).toString().substring(0,row.getCell(3).toString().length()-2))){
                            tSupervisionPerson.setOrganizationid(row.getCell(3)==null?null:row.getCell(3).toString().substring(0,row.getCell(3).toString().length()-2));//organizationid
                        }
                        else {
                            tSupervisionPerson.setOrganizationid(row.getCell(3)==null?null:row.getCell(3).getStringCellValue());//organizationid
                        }
                    }
                    tSupervisionPerson.setJobs(row.getCell(4)==null?null:row.getCell(4).toString());//jobs
                    tSupervisionPerson.setCellphone(row.getCell(5)==null?null:row.getCell(5).toString());//cellphone
                    tSupervisionPerson.setAreaCode(row.getCell(6)==null?null:row.getCell(6).toString());//areacode
                    tSupervisionPerson.setPersonType(row.getCell(7)==null?null:row.getCell(7).toString());//persontype
                    tSupervisionPerson.setLowType(row.getCell(8)==null?null:row.getCell(8).toString());//lowtype
                    tSupervisionPerson.setOrgan(row.getCell(9)==null?null:row.getCell(9).toString());//organ
//                tSupervisionPerson.setUserid(row.getCell(10)==null?null:Integer.parseInt(row.getCell(10).toString().substring(0,row.getCell(10).toString().length()-2)));//userid
//                tSupervisionPerson.setRemarks(row.getCell(11)==null?null:row.getCell(11).toString());//remarks
                    tSupervisionPerson.setTelephone(row.getCell(10)==null?null:row.getCell(10).toString());//telephone
                    list.add(tSupervisionPerson);
                }
            }
        }else {
            HSSFWorkbook book = new HSSFWorkbook(inputStream);
            HSSFSheet sheet = book.getSheetAt(0);
            for(int i=1; i<sheet.getLastRowNum()+1; i++) {
                TSupervisionPerson tSupervisionPerson=new TSupervisionPerson();
                HSSFRow row = sheet.getRow(i);
                if(row.getCell(0)==null){
                    break;
                }
                if(tnames.contains(row.getCell(0).toString())) { //如果重复
                    tSupervisionPerson.setName(row.getCell(0).toString());//name
                    tSupervisionPerson.setSex(row.getCell(1) == null ? null : row.getCell(1).toString());//sex
                    tSupervisionPerson.setCode(row.getCell(2) == null ? null : row.getCell(2).toString());//code
                    if (row.getCell(3) == null) {
                        tSupervisionPerson.setOrganizationid(row.getCell(3) == null ? null : row.getCell(3).getStringCellValue());//organizationid
                    } else {
                        if (StringUtils.isNumeric(row.getCell(3).toString().substring(0, row.getCell(3).toString().length() - 2))) {
                            tSupervisionPerson.setOrganizationid(row.getCell(3) == null ? null : row.getCell(3).toString().substring(0, row.getCell(3).toString().length() - 2));//organizationid
                        } else {
                            tSupervisionPerson.setOrganizationid(row.getCell(3) == null ? null : row.getCell(3).getStringCellValue());//organizationid
                        }
                    }
                    tSupervisionPerson.setJobs(row.getCell(4) == null ? null : row.getCell(4).toString());//jobs
                    tSupervisionPerson.setCellphone(row.getCell(5) == null ? null : row.getCell(5).toString().substring(0, row.getCell(5).toString().length() - 2));//cellphone
                    tSupervisionPerson.setAreaCode(row.getCell(6) == null ? null : row.getCell(6).toString().substring(0, row.getCell(6).toString().length() - 2));//areacode
                    tSupervisionPerson.setPersonType(row.getCell(7) == null ? null : row.getCell(7).toString().substring(0, row.getCell(7).toString().length() - 2));//persontype
                    tSupervisionPerson.setLowType(row.getCell(8) == null ? null : row.getCell(8).toString().substring(0, row.getCell(8).toString().length() - 2));//lowtype
                    tSupervisionPerson.setOrgan(row.getCell(9) == null ? null : row.getCell(9).toString());//organ
//                tSupervisionPerson.setUserid(row.getCell(10)==null?null:Integer.parseInt(row.getCell(10).toString().substring(0,row.getCell(10).toString().length()-2)));//userid
//                tSupervisionPerson.setRemarks(row.getCell(11)==null?null:row.getCell(11).toString());//remarks
                    tSupervisionPerson.setTelephone(row.getCell(10) == null ? null : row.getCell(10).toString().substring(0, row.getCell(10).toString().length() - 2));//telephone
                    uplist.add(tSupervisionPerson);
                }else { //如果不重复
                    tSupervisionPerson.setName(row.getCell(0).toString());//name
                    tSupervisionPerson.setSex(row.getCell(1)==null?null:row.getCell(1).toString());//sex
                    tSupervisionPerson.setCode(row.getCell(2)==null?null:row.getCell(2).toString());//code
                    if(row.getCell(3)==null){
                        tSupervisionPerson.setOrganizationid(row.getCell(3)==null?null:row.getCell(3).getStringCellValue());//organizationid
                    }else {
                        if(StringUtils.isNumeric(row.getCell(3).toString().substring(0,row.getCell(3).toString().length()-2))){
                            tSupervisionPerson.setOrganizationid(row.getCell(3)==null?null:row.getCell(3).toString().substring(0,row.getCell(3).toString().length()-2));//organizationid
                        }
                        else {
                            tSupervisionPerson.setOrganizationid(row.getCell(3)==null?null:row.getCell(3).getStringCellValue());//organizationid
                        }
                    }
                    tSupervisionPerson.setJobs(row.getCell(4)==null?null:row.getCell(4).toString());//jobs
                    tSupervisionPerson.setCellphone(row.getCell(5)==null?null:row.getCell(5).toString().substring(0,row.getCell(5).toString().length()-2));//cellphone
                    tSupervisionPerson.setAreaCode(row.getCell(6)==null?null:row.getCell(6).toString().substring(0,row.getCell(6).toString().length()-2));//areacode
                    tSupervisionPerson.setPersonType(row.getCell(7)==null?null:row.getCell(7).toString().substring(0,row.getCell(7).toString().length()-2));//persontype
                    tSupervisionPerson.setLowType(row.getCell(8)==null?null:row.getCell(8).toString().substring(0,row.getCell(8).toString().length()-2));//lowtype
                    tSupervisionPerson.setOrgan(row.getCell(9)==null?null:row.getCell(9).toString());//organ
//                tSupervisionPerson.setUserid(row.getCell(10)==null?null:Integer.parseInt(row.getCell(10).toString().substring(0,row.getCell(10).toString().length()-2)));//userid
//                tSupervisionPerson.setRemarks(row.getCell(11)==null?null:row.getCell(11).toString());//remarks
                    tSupervisionPerson.setTelephone(row.getCell(10)==null?null:row.getCell(10).toString().substring(0,row.getCell(10).toString().length()-2));//telephone
                    list.add(tSupervisionPerson);
                }
            }
        }
        if(list.size()==0){
            int a=baseMapper.updatebyexcel(uplist);
            if(a!=0){
                return true;
            }else {
                return false;
            }
        }
        if(uplist.size()==0){
            boolean a=baseMapper.insertbyexcel(list);
            if(a){
                return true;
            }else {
                return false;
            }

        }else {
            int a=baseMapper.updatebyexcel(uplist);
            boolean b=baseMapper.insertbyexcel(list);
            if(a!=0 && b!=false){
                return true;
            }else {
                return false;
            }
        }
    }

    @Override
    public List<TSupervisionPerson> getListByOrgRegion(String organizationid) {
        List<TSupervisionPerson> list = new ArrayList<>();
        String areaCode = baseMapper.getOrgRegion(organizationid);
        if("530000".equals(areaCode)){ //省级部门，只查本部门的监察员
            QueryWrapper<TSupervisionPerson> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("organizationid", organizationid);
            list = baseMapper.selectList(queryWrapper);
        }else{ //州市部门、区县部门获取本级及以下部门的检察员
            if(StringUtils.isNotBlank(areaCode)){
                areaCode = areaCode.replaceAll("00","");
                list = baseMapper.selectListByOrgRegion(areaCode);
            }
        }
        return list;
    }

    @Override
    public List<TSupervisionPerson> getJCPerson(Integer deptId) {
        return baseMapper.getJCPerson(deptId);
    }

    @Override
    public List<TSupervisionPerson> getByOrg(String[] organizationIds) {
        return baseMapper.getByOrg(organizationIds);
    }

    @Override
    public List<RegionPersonTreeVo> regionPersonTree(TSupervisionPerson tSupervisionPerson) {
        List<RegionPersonTreeVo> regionTree = baseMapper.regionTree();
        List<RegionPersonTreeVo> personTree = baseMapper.personTree(tSupervisionPerson);

        String regionStr = baseMapper.getRegionStr(tSupervisionPerson);
        List<RegionPersonTreeVo> newregionTree = new ArrayList<RegionPersonTreeVo>();
        for (RegionPersonTreeVo treeVo : regionTree) {
            if (regionStr != null && regionStr.contains(treeVo.getValue())) {
                newregionTree.add(treeVo);
            }
        }
        if (newregionTree.size() > 0  && !regionStr.contains("530000")) {
            RegionPersonTreeVo vo = new RegionPersonTreeVo();
            vo.setValue("530000");
            vo.setLabel("云南省");
            newregionTree.add(vo);
        }

        List<RegionPersonTreeVo> treeVos = new ArrayList<>();
        treeVos.addAll(newregionTree.size() > 0 ? newregionTree : regionTree);
        treeVos.addAll(personTree);
        return findTree(treeVos);
    }
}
