package com.mosty.qwzx.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mosty.base.model.dto.base.GetDeptListDTO;
import com.mosty.base.model.dto.jcgl.TbJcglXfllVo;
import com.mosty.base.model.dto.qwzx.TbQwSearchJlqdDto;
import com.mosty.base.model.entity.jcgl.TbJcglXfll;
import com.mosty.base.model.entity.qwzx.*;
import com.mosty.base.model.query.jcgl.TbJcglXfllQueryAllDto;
import com.mosty.base.model.vo.base.DeptInfoVo;
import com.mosty.base.model.vo.qwzx.Gzqk;
import com.mosty.base.model.vo.yszx.TbYsGajgGlbmVo;
import com.mosty.base.model.vo.yszx.TbYsGajgQuery;
import com.mosty.base.utils.Constant;
import com.mosty.base.utils.Kit;
import com.mosty.base.utils.UUIDGenerator;
import com.mosty.common.base.util.DateUtils;
import com.mosty.common.core.business.entity.SysDept;
import com.mosty.common.core.business.entity.vo.SysUserDeptVO;
import com.mosty.common.redis.service.RedisService;
import com.mosty.qwzx.mapper.*;
import com.mosty.qwzx.remote.TbBaseAdaptRemoteService;
import com.mosty.qwzx.remote.TbJcglAdaptRemoteService;
import com.mosty.qwzx.remote.TbYszxAdaptRemoteService;
import com.mosty.qwzx.service.TbQwBmjlbbService;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 * 部门每日警力报备表 服务实现类
 * </p>
 *
 * @author zengbo
 * @since 2022-06-27
 */
@AllArgsConstructor
@Service
public class TbQwBmjlbbServiceImpl extends ServiceImpl<TbQwBmjlbbMapper, TbQwBmjlbb>
        implements TbQwBmjlbbService {


    private final TbQwBmjlbbJlmxMapper tbQwBmjlbbJlmxMapper;
    private final TbQwJjrMapper tbQwJjrMapper;
    private final TbBaseAdaptRemoteService tbBaseAdaptRemoteService;
    private final TbQwQxjMapper tbQwQxjMapper;
    private final TbJcglAdaptRemoteService tbJcglAdaptRemoteService;
    private final TbYszxAdaptRemoteService tbYszxAdaptRemoteService;
    private final TbQwZbbbMapper tbQwzbbbMapper;
    private final TbQwZbpbZqMapper tbQwZbpbZqMapper;
    private final RedisService redisService;
    private final TbQwXfbbMapper tbQwXfbbMapper;
    private final TbQwZbpbMapper tbQwZbpbMapper;
    private final TbQwJlMapper tbQwJlMapper;
    private final TbQwXfpbMapper tbQwXfpbMapper;

    @Override
    public Gzqk selectOnCop() {
//        UserInfo userInfo = UserInfoManager.get();
        String ssbmdm = tbBaseAdaptRemoteService.getSsbm(null, null);
        return this.baseMapper.selectOnCop(ssbmdm);
    }

    @Override
    public void setBmjlbbInfo(String time) {
        // 查询所有的部门信息
//        List<DeptInfoVo> deptList = this.tbBaseAdaptRemoteService.getDeptAll();
        //获取所有巡防里面表的部门
        List<TbJcglXfll> bmAll = this.tbJcglAdaptRemoteService.getBmAll();
        if (!CollectionUtils.isEmpty(bmAll)) {
            for (TbJcglXfll xfll : bmAll) {
                DeptInfoVo item = this.tbBaseAdaptRemoteService.getOrgByOrgcode(xfll.getSsbmdm());
                TbQwBmjlbb bb = new TbQwBmjlbb();
                bb.setBbrq(DateUtils.dateTime("yyyy-MM-dd", time));
                bb.setId(UUIDGenerator.getUUID());
                // 查询是否节假日
                TbQwJjr jjr = this.tbQwJjrMapper.selectOne(
                        new LambdaQueryWrapper<TbQwJjr>()
                                .eq(TbQwJjr::getJjrq, new Date())
                );
                if (jjr != null) {
                    bb.setSfjjr("1");
                    bb.setJjrmc(jjr.getJjrmc());
                } else {
                    bb.setSfjjr("0");
                }
                String date = DateUtils.getDate();
                try {
                    bb.setKssj(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date + " 00:00:00"));
                    bb.setJssj(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date + " 23:59:59"));
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                bb.setSsbm(item.getDeptname());
                bb.setSsbmid(item.getDeptid());
                bb.setSsbmdm(item.getDeptcode());
                bb.setSsxgajdm(item.getFxjcode());
                bb.setSsxgajid(item.getFxjid());
                bb.setSsxgaj(item.getFxjname());
                bb.setSssgaj(item.getDszname());
                bb.setSssgajdm(item.getDszcode());
                bb.setSssgajid(item.getDszid());
                // 查询部门下的人员信息(民警)
                if (item.getDeptid() != null) {
//                    List<SysUserDeptVO> userList = this.tbBaseAdaptRemoteService.getUserAll(item.getDeptid());
                    TbJcglXfllQueryAllDto dto = new TbJcglXfllQueryAllDto();
                    dto.setFl("01");
                    dto.setSsbmdm(item.getDeptcode());
                    //查询巡逻民警数据
                    List<TbJcglXfllVo> mjList = this.tbJcglAdaptRemoteService.getXfll(dto);
                    bb.setBmmjsl(mjList.size());
                    int zgmjsl = mjList.size();
                    List<String> zgmj = mjList.stream().map(it -> String.valueOf(it.getId())).collect(Collectors.toList());
                    List<String> bzgmj = new ArrayList<>();
                    int bzmjsl = 0;
                    for (TbJcglXfllVo user : mjList) {
                        // 查询是否在岗（是否请休假）
                        TbQwQxj qxj = this.tbQwQxjMapper.selectOne(
                                new LambdaQueryWrapper<TbQwQxj>()
                                        .eq(TbQwQxj::getSqrlx, "01")
                                        .eq(TbQwQxj::getSqrSfzh, user.getSfzh())
                                        .le(TbQwQxj::getKssj, DateUtils.getDate())
                                        .ge(TbQwQxj::getJssj, DateUtils.getDate())
                        );
                        if (qxj == null) {
                            // 保存子表数据
                            this.setJlmx(user, bb.getId(), "1", "1", DateUtils.dateTime("yyyy-MM-dd", time));
                        } else {
                            zgmjsl--;
                            zgmj = zgmj.stream().filter(it -> !it.equals(String.valueOf(user.getId()))).collect(Collectors.toList());
                            bzmjsl++;
                            bzgmj.add(String.valueOf(user.getId()));
                            this.setJlmx(user, bb.getId(), "0", "4", DateUtils.dateTime("yyyy-MM-dd", time));
                        }
                    }
                    // 查询部门下的辅警
                    dto.setFl("02");
                    List<TbJcglXfllVo> fjList = this.tbJcglAdaptRemoteService.getXfll(dto);
                    bb.setBmfjsl(fjList.size());
                    int zgfjsl = fjList.size();
                    int bzfjsl = 0;
                    List<String> zgfj = fjList.stream().map(TbJcglXfllVo::getId).collect(Collectors.toList());
                    List<String> bzgfj = new ArrayList<>();
                    for (TbJcglXfllVo fj : fjList) {
                        // 查询是否在岗（是否请休假）
                        TbQwQxj qxj = this.tbQwQxjMapper.selectOne(
                                new LambdaQueryWrapper<TbQwQxj>()
                                        .eq(TbQwQxj::getSqrlx, "02")
                                        .eq(TbQwQxj::getSqrId, fj.getId())
                                        .le(TbQwQxj::getKssj, DateUtils.getDate())
                                        .ge(TbQwQxj::getJssj, DateUtils.getDate())
                        );
                        if (qxj == null) {
                            // 保存子表数据
                            this.setJlmxFj(fj, bb.getId(), "1", "2", DateUtils.dateTime("yyyy-MM-dd", time));
                        } else {
                            zgfjsl--;
                            zgfj = zgfj.stream().filter(it -> !it.equals(fj.getId())).collect(Collectors.toList());
                            bzfjsl++;
                            bzgfj.add(fj.getId());
                            this.setJlmxFj(fj, bb.getId(), "0", "5", DateUtils.dateTime("yyyy-MM-dd", time));
                        }
                    }
                    bb.setZgfjsl(zgfjsl);
                    bb.setBzgfjsl(bzfjsl);
                    bb.setZgmjsl(zgmjsl);
                    bb.setBzmjlsl(bzmjsl);
                    bb.setXtSjly("1");
                    bb.setZgmj(JSONArray.toJSONString(zgmj));
                    bb.setBzgmj(JSONArray.toJSONString(bzgmj));
                    bb.setZgfj(JSONArray.toJSONString(zgfj));
                    bb.setBzgfj(JSONArray.toJSONString(bzgfj));
                    this.baseMapper.insert(bb);
                }
            }
        }
    }

    @Override
    public List<Map<String, Object>> getJlqdListToRedis(TbQwSearchJlqdDto dto) {
        List<Map<String, Object>> resList = new ArrayList<>();
//        TbYsGajgQuery query = new TbYsGajgQuery();
//        query.setYsxl("001001003,001001004");
//        query.setJd(dto.getJd());
//        query.setWd(dto.getWd());
//        query.setRadius(dto.getDistance());
//        List<TbYsGajgGlbmVo> list = this.tbYszxAdaptRemoteService.getGajgList(query);

        List<TbJcglXfll> list = this.tbJcglAdaptRemoteService.getBmAll();
        if (!CollectionUtils.isEmpty(list)) {
            for (TbJcglXfll item : list) {
                SysDept org = this.tbBaseAdaptRemoteService.getSysDeptBySsbmdm(item.getSsbmdm());
                Map<String, Object> map = new HashMap<>();
                map.put("ssbmdm", org.getOrgCode());
                map.put("ssbmid", org.getId());
                map.put("ssbmmc", org.getOrgName());
                map.put("ssbmjc", org.getOrgJc());
                map.put("wzXz", org.getAddress());
//                String ssbm = this.tbBaseAdaptRemoteService.getSsbm(org.getOrgCode(), null);
                // 查询在岗警力数
                int mj = this.tbQwBmjlbbJlmxMapper.selectCount(
                        new LambdaQueryWrapper<TbQwBmjlbbJlmx>()
                                .eq(TbQwBmjlbbJlmx::getBbrq, dto.getBbrq())
                                .eq(TbQwBmjlbbJlmx::getJllx, "01")
                                .ne(TbQwBmjlbbJlmx::getJlzt, "0")
                                .eq(StringUtils.isNotBlank(org.getOrgCode()),TbQwBmjlbbJlmx::getSsbmdm,org.getOrgCode())
//                                .in(TbQwBmjlbbJlmx::getSsbmid, item.getGlbmSsbmdmList())
                );
                int fj = this.tbQwBmjlbbJlmxMapper.selectCount(
                        new LambdaQueryWrapper<TbQwBmjlbbJlmx>()
                                .eq(TbQwBmjlbbJlmx::getBbrq, dto.getBbrq())
                                .eq(TbQwBmjlbbJlmx::getJllx, "02")
                                .ne(TbQwBmjlbbJlmx::getJlzt, "0")
                                .eq(StringUtils.isNotBlank(org.getOrgCode()),TbQwBmjlbbJlmx::getSsbmdm,org.getOrgCode())
//                                .in(TbQwBmjlbbJlmx::getSsbmid, item.getGlbmSsbmdmList())
                );
                map.put("mj", mj);
                map.put("fj", fj);
                map.put("jl", mj + fj);
                // 查询该部门的值班排班或值班报备情况
                this.getZbpb(map, item.getSsbmid());
                resList.add(map);
            }
        }
        if (dto != null) {
            // 删除之前的数据
            redisService.deleteObject(Constant.BMJLBB + dto.getBbrq());
            if (!CollectionUtils.isEmpty(resList)) {
                redisService.setCacheList(Constant.BMJLBB + dto.getBbrq(), resList);
            }
        }
        return resList;
    }

    @Override
    public List<Map<String, Object>> getJlqdList(TbQwSearchJlqdDto dto) {
        List<Map<String, Object>> list = redisService.getCacheList(Constant.BMJLBB + dto.getBbrq());
        if (CollectionUtils.isEmpty(list)) return new ArrayList<>();
        if (dto.getJd() != null && dto.getWd() != null && dto.getDistance() != null) {
            list = list.stream().filter(item -> {
                double jl = Kit.getDistance(Double.parseDouble(String.valueOf(item.get("jd"))),
                        Double.parseDouble(String.valueOf(item.get("wd"))),
                        dto.getJd().doubleValue(), dto.getWd().doubleValue());
                item.put("distance", jl);
                return jl <= dto.getDistance().doubleValue();
            }).collect(Collectors.toList());
        }
        return list;
    }

    @Override
    public Map<String, Object> getZgjlCount() {
        String ssbmdm = tbBaseAdaptRemoteService.getSsbm(null, null);
//        UserInfo user = UserInfoManager.get();
        TbQwBmjlbb bb = this.baseMapper.selectOne(
                new LambdaQueryWrapper<TbQwBmjlbb>()
                        .eq(TbQwBmjlbb::getBbrq, com.mosty.base.utils.DateUtils.getQueryDateString(new Date(), "01"))
//                        .eq(TbQwBmjlbb::getSsbmid, String.valueOf(user.getDeptId()))
                        .likeRight(StringUtils.isNotBlank(ssbmdm), TbQwBmjlbb::getSsbmdm, ssbmdm)
                        .last(" limit 1")
        );
        if (bb == null) return null;
        Map<String, Object> map = new HashMap<>();
        map.put("orgcode", bb.getSsbmdm());
        map.put("orgid", bb.getSsbmid());
        map.put("orgname", bb.getSsbm());
        map.put("zgfj", bb.getZgfjsl());
        map.put("zgmj", bb.getZgmjsl());
        map.put("zgjl", bb.getZgfjsl() + bb.getZgmjsl());
        return map;
    }

    private void getZbpb(Map<String, Object> map, String ssbmid) {
        // 过去,有值班展示值班信息，没有就不展示
        List<TbQwZbbb> bbList = this.tbQwzbbbMapper.selectList(
                new LambdaQueryWrapper<TbQwZbbb>()
                        .eq(TbQwZbbb::getZbrq, com.mosty.base.utils.DateUtils.getQueryDateString(new Date(), "01"))
                        .eq(TbQwZbbb::getXtSjzt, "1")
                        .eq(TbQwZbbb::getSsbmid, ssbmid)
        );
        if (bbList != null && bbList.size() != 0) {
            map.put("zbld", bbList.get(0).getZbldXm());
            map.put("zbldDh", bbList.get(0).getZbldDh());
        } else {
            List<TbQwZbpbZq> zqList = this.tbQwZbpbZqMapper.getDeptByMonth(new Date(), ssbmid);
            if (zqList != null && zqList.size() > 0) {
                map.put("zbld", zqList.get(0).getZbldXm());
                map.put("zbldDh", zqList.get(0).getZbldDh());
            } else {
                map.put("zbld", "暂无");
                map.put("zbldDh", "暂无");
            }
        }
    }

    // 保存警力表的数据
    public void setJlmxFj(TbJcglXfllVo fj, String bbid, String jlzt, String bblx, Date date) {
        // 查询是否保存了该人员今天的数据
        TbQwBmjlbbJlmx jlmx = this.tbQwBmjlbbJlmxMapper.selectOne(
                new LambdaQueryWrapper<TbQwBmjlbbJlmx>()
                        .eq(TbQwBmjlbbJlmx::getJlId, fj.getId())
                        .eq(TbQwBmjlbbJlmx::getBbrq, DateUtils.dateTime(date))
        );
        if (jlmx != null) {
            return;
        }
        // 查询该人员是否报备了值班报备
        jlmx = new TbQwBmjlbbJlmx();
        jlmx.setJlzt(jlzt);
        jlmx.setBblx(bblx);
        jlmx.setId(UUIDGenerator.getUUID());
        jlmx.setJlbbId(bbid);
        jlmx.setJlId(String.valueOf(fj.getId()));
        jlmx.setJlxm(fj.getXm());
        jlmx.setSfzh(fj.getSfzh());
        jlmx.setJh(fj.getJh());
        jlmx.setXbdm(fj.getXbdm());
        jlmx.setLxdh(fj.getLxdh());
        DeptInfoVo dept = this.tbBaseAdaptRemoteService.getOrgByOrgcode(String.valueOf(fj.getSsbmdm()));
        if (dept != null) {
            jlmx.setSsbm(dept.getDeptname());
            jlmx.setSsbmid(dept.getDeptid());
            jlmx.setSsbmdm(dept.getDeptcode());
            jlmx.setSsxgajdm(dept.getFxjcode());
            jlmx.setSsxgajid(dept.getFxjid());
            jlmx.setSsxgaj(dept.getFxjname());
            jlmx.setSssgaj(dept.getDszname());
            jlmx.setSssgajdm(dept.getDszcode());
            jlmx.setSssgajid(dept.getDszid());
        }
        jlmx.setJllx("02");
        jlmx.setBbrq(date);
        jlmx.setXtSjly("1");
        this.tbQwBmjlbbJlmxMapper.insert(jlmx);
    }


    // 保存警力表的数据
    public void setJlmx(TbJcglXfllVo user, String bbid, String jlzt, String bblx, Date date) {
        // 查询是否保存了该人员今天的数据
        TbQwBmjlbbJlmx jlmx = this.tbQwBmjlbbJlmxMapper.selectOne(
                new LambdaQueryWrapper<TbQwBmjlbbJlmx>()
                        .eq(TbQwBmjlbbJlmx::getJlId, String.valueOf(user.getId()))
                        .eq(TbQwBmjlbbJlmx::getBbrq, DateUtils.dateTime(date))
        );
        if (jlmx != null) {
            return;
        }
        // 查询该人员是否报备了值班报备
        jlmx = new TbQwBmjlbbJlmx();
        jlmx.setJlzt(jlzt);
        jlmx.setBblx(bblx);
        jlmx.setId(UUIDGenerator.getUUID());
        jlmx.setJlbbId(bbid);
        jlmx.setJlId(String.valueOf(user.getId()));
        jlmx.setJlxm(user.getXm());
        jlmx.setSfzh(user.getSfzh());
        jlmx.setJh(user.getJh());
        jlmx.setXbdm(user.getXbdm());
        jlmx.setLxdh(user.getLxdh());
        DeptInfoVo dept = this.tbBaseAdaptRemoteService.getOrgByOrgcode(user.getSsbmdm());
        if (dept != null) {
            jlmx.setSsbm(dept.getDeptname());
            jlmx.setSsbmid(dept.getDeptid());
            jlmx.setSsbmdm(dept.getDeptcode());
            jlmx.setSsxgajdm(dept.getFxjcode());
            jlmx.setSsxgajid(dept.getFxjid());
            jlmx.setSsxgaj(dept.getFxjname());
            jlmx.setSssgaj(dept.getDszname());
            jlmx.setSssgajdm(dept.getDszcode());
            jlmx.setSssgajid(dept.getDszid());
        }
        jlmx.setJllx("01");
        jlmx.setXtSjly("1");
        jlmx.setBbrq(date);
        this.tbQwBmjlbbJlmxMapper.insert(jlmx);
    }

    @Override
    public List<Map<String, Object>> countCdepTree(String ssbmdm) {

        List<Map<String, Object>> resList = new ArrayList<>();
        ssbmdm = tbBaseAdaptRemoteService.getSsbm(ssbmdm, null);
        if (StringUtils.isNotBlank(ssbmdm) && ssbmdm.length() == 2) {
            ssbmdm = Constant.SSDSZ;
        }
        ssbmdm = StringUtils.rightPad(ssbmdm, 12, "0");
        SysDept dept = this.tbBaseAdaptRemoteService.getSysDeptBySsbmdm(ssbmdm);
        if (ObjectUtils.isNotEmpty(dept)) {
            GetDeptListDTO dto = new GetDeptListDTO();
            dto.setDeptid(String.valueOf(dept.getId()));
            List<String> levle = new ArrayList<>();
//            levle.add("30");
//            levle.add("31");
//            levle.add("40");
//            levle.add("21");
            dto.setLevels(levle);
            List<DeptInfoVo> deptList = this.tbBaseAdaptRemoteService.getChildDept(dto);
            if (!CollectionUtils.isEmpty(deptList)) {
                for (DeptInfoVo item : deptList) {
                    if (StringUtils.isNotBlank(item.getOrgLevel()) && Integer.valueOf(item.getOrgLevel()) > 20) {
                        Map<String, Object> resMap = new HashMap<>();
                        String ssbm = tbBaseAdaptRemoteService.getSsbm(item.getDeptcode(), null);
                        //查询报备数据
                        List<TbQwXfbb> xfbbList = this.tbQwXfbbMapper.selectList(new LambdaQueryWrapper<TbQwXfbb>()
                                .likeRight(StringUtils.isNotBlank(ssbm), TbQwXfbb::getSsbmdm, ssbm)
                                .eq(TbQwXfbb::getBbzt, "0")
                        );
                        int bbmj = 0;
                        int bbfj = 0;

                        if (!CollectionUtils.isEmpty(xfbbList)) {
                            //获取人员数据
                            bbmj = xfbbList.stream().collect(Collectors.summingInt(TbQwXfbb::getMjsl));
                            bbfj = xfbbList.stream().collect(Collectors.summingInt(TbQwXfbb::getFjsl));
                        }
                        //获取未在岗数据
                        List<TbQwQxj> qxjList = this.tbQwQxjMapper.selectList(new LambdaQueryWrapper<TbQwQxj>()
                                .le(TbQwQxj::getKssj, new Date())
                                .ge(TbQwQxj::getJssj, new Date())
                                .likeRight(StringUtils.isNotBlank(ssbm), TbQwQxj::getSsbmdm, ssbm)
                        );
                        int qjmj = 0;
                        int qjfj = 0;
                        if (!CollectionUtils.isEmpty(qxjList)) {
                            qjmj = qxjList.stream().filter(s -> s.getSqrlx().equals("1")).collect(Collectors.toList()).size();
                            qjfj = qxjList.stream().filter(s -> s.getSqrlx().equals("2")).collect(Collectors.toList()).size();
                        }
                        //值班数据
                        List<TbQwZbpb> tbQwZbpbs = this.tbQwZbpbMapper.selectList(new LambdaQueryWrapper<TbQwZbpb>()
                                .likeRight(StringUtils.isNotBlank(ssbm), TbQwZbpb::getSsbmdm, ssbm)
                                .le(TbQwZbpb::getZbpbksrq, new Date())
                                .ge(TbQwZbpb::getZbpbjsrq, new Date())
                        );
                        int zbmj = 0;
                        int zbfj = 0;
                        if (!CollectionUtils.isEmpty(tbQwZbpbs)) {
                            for (TbQwZbpb zbpb : tbQwZbpbs) {
                                List<TbQwJl> jlList = this.tbQwJlMapper.selectList(new LambdaQueryWrapper<TbQwJl>()
                                        .eq(TbQwJl::getYwid, zbpb.getId())
                                );
                                if (!CollectionUtils.isEmpty(jlList)) {
                                    zbmj += jlList.stream().filter(s -> s.getJllx().equals("01")).collect(Collectors.toList()).size();
                                    zbfj += jlList.stream().filter(s -> s.getJllx().equals("02")).collect(Collectors.toList()).size();
                                }
                            }
                        }
                        //获取排班数据
                        List<TbQwXfpb> xfpbList = this.tbQwXfpbMapper.selectList(new LambdaQueryWrapper<TbQwXfpb>()
                                .likeRight(StringUtils.isNotBlank(ssbm), TbQwXfpb::getSsbmdm, ssbm)
                                .le(TbQwXfpb::getPbksrq, new Date())
                                .ge(TbQwXfpb::getPbjsrq, new Date())
                        );
                        int pbmj = 0;
                        int pbfj = 0;
                        if (!CollectionUtils.isEmpty(xfpbList)) {
                            for (TbQwXfpb xfpb : xfpbList) {
                                List<TbQwJl> jlList = this.tbQwJlMapper.selectList(new LambdaQueryWrapper<TbQwJl>()
                                        .eq(TbQwJl::getYwid, xfpb.getId())
                                );
                                if (!CollectionUtils.isEmpty(jlList)) {
                                    pbmj += jlList.stream().filter(s -> s.getJllx().equals("01")).collect(Collectors.toList()).size();
                                    pbfj += jlList.stream().filter(s -> s.getJllx().equals("02")).collect(Collectors.toList()).size();
                                }
                            }
                        }
                        //获取总民辅警
                        TbJcglXfllQueryAllDto jcglXfllQueryAllDto = new TbJcglXfllQueryAllDto();
                        jcglXfllQueryAllDto.setSsbmdm(item.getDeptcode());
                        List<TbJcglXfllVo> xfll = tbJcglAdaptRemoteService.getXfll(jcglXfllQueryAllDto);
                        int mjAll = 0;
                        int fjAll = 0;
                        if (!CollectionUtils.isEmpty(xfll)) {
                            mjAll = xfll.stream().filter(s -> s.getFl().equals("01")).collect(Collectors.toList()).size();
                            fjAll = xfll.stream().filter(s -> s.getFl().equals("02")).collect(Collectors.toList()).size();
                        }
                        //可抽调
                        int kcdmj = (mjAll - pbmj - zbmj - bbmj) < 0 ? 0 : mjAll - pbmj - zbmj - bbmj;
                        int kcdfj = (fjAll - pbfj - zbfj - bbfj) < 0 ? 0 : fjAll - pbfj - zbfj - bbfj;
                        resMap.put("kcdmj", kcdmj);
                        resMap.put("kcdfj", kcdfj);
                        resMap.put("fjAll", fjAll);
                        resMap.put("mjAll", mjAll);
                        resMap.put("pbmj", pbmj);
                        resMap.put("pbfj", pbfj);
                        resMap.put("zbmj", zbmj);
                        resMap.put("zbfj", zbfj);
                        resMap.put("qjmj", qjmj);
                        resMap.put("qjfj", qjfj);
                        resMap.put("bbmj", bbmj);
                        resMap.put("bbfj", bbfj);
                        resMap.put("ssbmmc", item.getDeptname());
                        resMap.put("ssbmdm", item.getDeptcode());
                        resMap.put("ssbmid", item.getDeptid());
                        resList.add(resMap);
                    }
                }
            }
        }
        return resList;
    }
}
