package com.mosty.qwzx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mosty.base.model.dto.qwzx.TbQwMfjSearchDto;
import com.mosty.base.model.entity.qwzx.TbQwQxj;
import com.mosty.base.model.vo.base.DeptInfoVo;
import com.mosty.base.utils.DateUtils;
import com.mosty.common.core.business.entity.SysUser;
import com.mosty.common.token.UserInfo;
import com.mosty.common.token.UserInfoManager;
import com.mosty.common.util.PermissionsUtil;
import com.mosty.qwzx.mapper.QwzxStatisticsMapper;
import com.mosty.qwzx.mapper.TbQwQxjMapper;
import com.mosty.qwzx.remote.TbBaseAdaptRemoteService;
import com.mosty.qwzx.service.QwzxStatisticsService;
import com.mosty.qwzx.service.TbQwXfbbService;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.swing.*;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@AllArgsConstructor
public class QwzxStatisticsServiceImpl implements QwzxStatisticsService {

    private final QwzxStatisticsMapper qwzxStatisticsMapper;
    private final TbBaseAdaptRemoteService tbBaseAdaptRemoteService;
    private final TbQwQxjMapper tbQwQxjMapper;
    private final TbQwXfbbService tbQwXfbbService;

    @Override
    public Integer qbfj(TbQwMfjSearchDto dto) {
        Map<String, Object> map = new HashMap<>();
//        UserInfo user = UserInfoManager.get();
//        map.put("useSql", PermissionsUtil.createSql("a", user));
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        map.put("dto", dto);
        return this.qwzxStatisticsMapper.getQbfjCount(map);
    }

    @Override
    public IPage<Map<String, Object>> qbfjList(TbQwMfjSearchDto dto) {
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        Map<String, Object> map = new HashMap<>();
//        UserInfo user = UserInfoManager.get();
        map.put("pageIndex", (dto.getPageCurrent() - 1) * dto.getPageSize());
        map.put("pageSize", dto.getPageSize());
//        map.put("useSql", PermissionsUtil.createSql("a", user));
        map.put("dto", dto);
        int count = this.qwzxStatisticsMapper.getQbfjCount(map);
        List<Map<String, Object>> list = this.qwzxStatisticsMapper.getQbfjList(map);
        IPage<Map<String, Object>> page = new Page<>(dto.getPageCurrent(), dto.getPageSize());
        page.setTotal(count);
        page.setRecords(list);
        return page;
    }

    /**
     * 查询全部列表 qblb
     * 警力情况-辅警-全部列表
     *
     * @param dto
     * @return
     */
    @Override
    public IPage<Map<String, Object>> qblb(TbQwMfjSearchDto dto) {
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        Map<String, Object> map = new HashMap<>();
//        UserInfo user = UserInfoManager.get();
        map.put("pageIndex", (dto.getPageCurrent() - 1) * dto.getPageSize());
        map.put("pageSize", dto.getPageSize());
//        map.put("useSql", PermissionsUtil.createSql("", user));
        map.put("dto", dto);
        int count = this.qwzxStatisticsMapper.getQblbCount(map);
        List<Map<String, Object>> list = this.qwzxStatisticsMapper.qblb(map);
        IPage<Map<String, Object>> page = new Page<>(dto.getPageCurrent(), dto.getPageSize());
        page.setTotal(count);
        page.setRecords(list);
        return page;
    }

    /**
     * 警力情况-辅警-全部在岗统计 qbzgtj
     *
     * @param dto
     * @return
     */
    @Override
    public IPage<Map<String, Object>> qbzgtj(TbQwMfjSearchDto dto) {
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        Map<String, Object> map = new HashMap<>();
//        UserInfo user = UserInfoManager.get();
        map.put("pageIndex", (dto.getPageCurrent() - 1) * dto.getPageSize());
        map.put("pageSize", dto.getPageSize());
//        map.put("useSql", PermissionsUtil.createSql("", user));
        map.put("dto", dto);
        int count = this.qwzxStatisticsMapper.getQbzgtjCount(map);
        List<Map<String, Object>> list = this.qwzxStatisticsMapper.qbzgtj(map);
        IPage<Map<String, Object>> page = new Page<>(dto.getPageCurrent(), dto.getPageSize());
        page.setTotal(count);
        page.setRecords(list);
        return page;
    }

    @Override
    public Integer zgfj(TbQwMfjSearchDto dto) {
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        Map<String, Object> map = new HashMap<>();
//        UserInfo user = UserInfoManager.get();
//        map.put("useSql", PermissionsUtil.createSql("a", user));
        map.put("dto", dto);
        return this.qwzxStatisticsMapper.getZgfjCount(map);
    }

    @Override
    public IPage<Map<String, Object>> zgfjList(TbQwMfjSearchDto dto) {
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        Map<String, Object> map = new HashMap<>();
//        UserInfo user = UserInfoManager.get();
        map.put("pageIndex", (dto.getPageCurrent() - 1) * dto.getPageSize());
        map.put("pageSize", dto.getPageSize());
//        map.put("useSql", PermissionsUtil.createSql("a", user));
        map.put("dto", dto);
        int count = this.qwzxStatisticsMapper.getZgfjCount(map);
        List<Map<String, Object>> list = this.qwzxStatisticsMapper.getZgfjList(map);
        IPage<Map<String, Object>> page = new Page<>(dto.getPageCurrent(), dto.getPageSize());
        page.setTotal(count);
        page.setRecords(list);
        return page;
    }

    @Override
    public IPage<Map<String, Object>> zglb(TbQwMfjSearchDto dto) {
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        Map<String, Object> map = new HashMap<>();
//        UserInfo user = UserInfoManager.get();
        map.put("pageIndex", (dto.getPageCurrent() - 1) * dto.getPageSize());
        map.put("pageSize", dto.getPageSize());
//        map.put("useSql", PermissionsUtil.createSql("", user));
        map.put("dto", dto);
        int count = this.qwzxStatisticsMapper.getZglbCount(map);
        List<Map<String, Object>> list = this.qwzxStatisticsMapper.zglb(map);
        IPage<Map<String, Object>> page = new Page<>(dto.getPageCurrent(), dto.getPageSize());
        page.setTotal(count);
        page.setRecords(list);
        return page;
    }

    @Override
    public IPage<Map<String, Object>> fjlb(TbQwMfjSearchDto dto) {
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        Map<String, Object> map = new HashMap<>();
        UserInfo user = UserInfoManager.get();
        map.put("pageIndex", (dto.getPageCurrent() - 1) * dto.getPageSize());
        map.put("pageSize", dto.getPageSize());
//        map.put("useSql", PermissionsUtil.createSql("a", user));
        map.put("dto", dto);
        int count = this.qwzxStatisticsMapper.getFjlbCount(map);
        List<Map<String, Object>> list = this.qwzxStatisticsMapper.fjlb(map);
        IPage<Map<String, Object>> page = new Page<>(dto.getPageCurrent(), dto.getPageSize());
        page.setTotal(count);
        page.setRecords(list);
        return page;
    }

    @Override
    public IPage<Map<String, Object>> mjlb(TbQwMfjSearchDto dto) {
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        Map<String, Object> map = new HashMap<>();
//        UserInfo user = UserInfoManager.get();
        map.put("pageIndex", (dto.getPageCurrent() - 1) * dto.getPageSize());
        map.put("pageSize", dto.getPageSize());
//        map.put("useSql", PermissionsUtil.createSql("a", user));
        map.put("dto", dto);
        int count = this.qwzxStatisticsMapper.getMjlbCount(map);
        List<Map<String, Object>> list = this.qwzxStatisticsMapper.mjlb(map);
        IPage<Map<String, Object>> page = new Page<>(dto.getPageCurrent(), dto.getPageSize());
        page.setTotal(count);
        page.setRecords(list);
        return page;
    }

    @Override
    public Integer qb(TbQwMfjSearchDto dto) {
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        Map<String, Object> map = new HashMap<>();
//        UserInfo user = UserInfoManager.get();
//        map.put("useSql", PermissionsUtil.createSql("a", user));
        map.put("dto", dto);
        return this.qwzxStatisticsMapper.getQbCount(map);
    }

    @Override
    public IPage<Map<String, Object>> qbList(TbQwMfjSearchDto dto) {
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        Map<String, Object> map = new HashMap<>();
//        UserInfo user = UserInfoManager.get();
        map.put("pageIndex", (dto.getPageCurrent() - 1) * dto.getPageSize());
        map.put("pageSize", dto.getPageSize());
//        map.put("useSql", PermissionsUtil.createSql("a", user));
        map.put("dto", dto);
        int count = this.qwzxStatisticsMapper.getQbCount(map);
        List<Map<String, Object>> list = this.qwzxStatisticsMapper.qbList(map);
        IPage<Map<String, Object>> page = new Page<>(dto.getPageCurrent(), dto.getPageSize());
        page.setTotal(count);
        page.setRecords(list);
        return page;
    }

    @Override
    public Integer zg(TbQwMfjSearchDto dto) {
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        Map<String, Object> map = new HashMap<>();
//        UserInfo user = UserInfoManager.get();
//        map.put("useSql", PermissionsUtil.createSql("a", user));
        map.put("dto", dto);
        return this.qwzxStatisticsMapper.getZgCount(map);
    }

    @Override
    public IPage<Map<String, Object>> zgList(TbQwMfjSearchDto dto) {
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        Map<String, Object> map = new HashMap<>();
//        UserInfo user = UserInfoManager.get();
        map.put("pageIndex", (dto.getPageCurrent() - 1) * dto.getPageSize());
        map.put("pageSize", dto.getPageSize());
//        map.put("useSql", PermissionsUtil.createSql("a", user));
        map.put("dto", dto);
        int count = this.qwzxStatisticsMapper.getZgCount(map);
        List<Map<String, Object>> list = this.qwzxStatisticsMapper.zgList(map);
        IPage<Map<String, Object>> page = new Page<>(dto.getPageCurrent(), dto.getPageSize());
        page.setTotal(count);
        page.setRecords(list);
        return page;
    }

    @Override
    public IPage<Map<String, Object>> kcdFjlb(TbQwMfjSearchDto dto) {
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        Map<String, Object> map = new HashMap<>();
//        UserInfo user = UserInfoManager.get();
        map.put("pageIndex", (dto.getPageCurrent() - 1) * dto.getPageSize());
        map.put("pageSize", dto.getPageSize());
//        map.put("useSql", PermissionsUtil.createSql("", user));
        map.put("dto", dto);
        int count = this.qwzxStatisticsMapper.getKcdFjlbCount(map);
        List<Map<String, Object>> list = this.qwzxStatisticsMapper.kcdFjlb(map);
        IPage<Map<String, Object>> page = new Page<>(dto.getPageCurrent(), dto.getPageSize());
        page.setTotal(count);
        page.setRecords(list);
        return page;
    }

    @Override
    public List<Map<String, Object>> zbtj(TbQwMfjSearchDto dto) {
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        Map<String, Object> map = new HashMap<>();
//        UserInfo user = UserInfoManager.get();
//        map.put("useSql", PermissionsUtil.createSql("a", user));
        map.put("dto", dto);
        return this.qwzxStatisticsMapper.getZbtjCount(map);
    }

    @Override
    public IPage<Map<String, Object>> kcdMjlb(TbQwMfjSearchDto dto) {
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        Map<String, Object> map = new HashMap<>();
//        UserInfo user = UserInfoManager.get();
        map.put("pageIndex", (dto.getPageCurrent() - 1) * dto.getPageSize());
        map.put("pageSize", dto.getPageSize());
//        map.put("useSql", PermissionsUtil.createSql("a", user));
        map.put("dto", dto);
        int count = this.qwzxStatisticsMapper.kcdMjCount(map);
        List<Map<String, Object>> list = this.qwzxStatisticsMapper.kcdMjList(map);
        IPage<Map<String, Object>> page = new Page<>(dto.getPageCurrent(), dto.getPageSize());
        page.setTotal(count);
        page.setRecords(list);
        return page;
    }

    @Override
    public IPage<Map<String, Object>> mjfjzh(TbQwMfjSearchDto dto) {
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        Map<String, Object> map = new HashMap<>();
        UserInfo user = UserInfoManager.get();
        map.put("pageIndex", (dto.getPageCurrent() - 1) * dto.getPageSize());
        map.put("pageSize", dto.getPageSize());
//        map.put("useSql", PermissionsUtil.createSql("a", user));
//        map.put("useDept", user.getUserPermissionsInfo() == null ? "" : user.getUserPermissionsInfo().getIds());
        map.put("dto", dto);
        List<Map<String, Object>> list = this.qwzxStatisticsMapper.mjfjzh(map);
        int count = this.qwzxStatisticsMapper.mjfjzhCount(map);
        IPage<Map<String, Object>> page = new Page<>(dto.getPageCurrent(), dto.getPageSize());
        page.setRecords(list);
        page.setTotal(count);
        return page;
    }

    @Override
    public IPage<Map<String, Object>> mjQblb(TbQwMfjSearchDto dto) {
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        Map<String, Object> map = new HashMap<>();
//        UserInfo user = UserInfoManager.get();
        map.put("pageIndex", (dto.getPageCurrent() - 1) * dto.getPageSize());
        map.put("pageSize", dto.getPageSize());
//        map.put("useSql", PermissionsUtil.createSqlOfCode("a", user));
        map.put("dto", dto);
//        map.put("useDept", user.getUserPermissionsInfo() == null ? "" : user.getUserPermissionsInfo().getIds());
        int count = this.qwzxStatisticsMapper.mjQblbCount(map);
        List<Map<String, Object>> list = this.qwzxStatisticsMapper.mjQblb(map);
        IPage<Map<String, Object>> page = new Page<>(dto.getPageCurrent(), dto.getPageSize());
        page.setRecords(list);
        page.setTotal(count);
        return page;
    }

    @Override
    public Integer qbmj(TbQwMfjSearchDto dto) {
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        Map<String, Object> map = new HashMap<>();
        UserInfo user = UserInfoManager.get();
//        map.put("useSql", PermissionsUtil.createSql("", user));
        map.put("dto", dto);
        return this.qwzxStatisticsMapper.getQbmjCount(map);
    }

    @Override
    public IPage<Map<String, Object>> qbmjList(TbQwMfjSearchDto dto) {
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        Map<String, Object> map = new HashMap<>();
//        UserInfo user = UserInfoManager.get();
        map.put("pageIndex", (dto.getPageCurrent() - 1) * dto.getPageSize());
        map.put("pageSize", dto.getPageSize());
//        map.put("useSql", PermissionsUtil.createSql("a", user));
        map.put("dto", dto);
        int count = this.qwzxStatisticsMapper.getQbmjCount(map);
        List<Map<String, Object>> list = this.qwzxStatisticsMapper.qbmjList(map);
        IPage<Map<String, Object>> page = new Page<>(dto.getPageCurrent(), dto.getPageSize());
        page.setTotal(count);
        page.setRecords(list);
        return page;
    }

    @Override
    public Integer mjQbzgtj(TbQwMfjSearchDto dto) {
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        Map<String, Object> map = new HashMap<>();
        UserInfo user = UserInfoManager.get();
//        map.put("useDept", user.getUserPermissionsInfo() == null ? "" : user.getUserPermissionsInfo().getIds());
//        map.put("useSql", PermissionsUtil.createSql("", user));
        map.put("dto", dto);
        return this.qwzxStatisticsMapper.getQbzgCount(map);
    }

    @Override
    public IPage<Map<String, Object>> mjZglb(TbQwMfjSearchDto dto) {
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));

        Map<String, Object> map = new HashMap<>();
//        UserInfo user = UserInfoManager.get();
        map.put("pageIndex", (dto.getPageCurrent() - 1) * dto.getPageSize());
        map.put("pageSize", dto.getPageSize());
//        map.put("useSql", PermissionsUtil.createSqlOfCode("a", user));
        map.put("dto", dto);
        int count = this.qwzxStatisticsMapper.getmMjzglbCount(map);
        List<Map<String, Object>> list = this.qwzxStatisticsMapper.mjZglb(map);
        IPage<Map<String, Object>> page = new Page<>(dto.getPageCurrent(), dto.getPageSize());
        page.setRecords(list);
        page.setTotal(count);
        return page;
    }

    @Override
    public Integer zgmj(TbQwMfjSearchDto dto) {
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        Map<String, Object> map = new HashMap<>();
        UserInfo user = UserInfoManager.get();
//        map.put("useSql", PermissionsUtil.createSql("", user));
        map.put("dto", dto);
        return this.qwzxStatisticsMapper.getZgmj(map);
    }

    @Override
    public List<Map<String, Object>> zgmjfjzh(TbQwMfjSearchDto dto) {
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        Map<String, Object> map = new HashMap<>();
//        UserInfo user = UserInfoManager.get();
//        map.put("useSql", PermissionsUtil.createSql("a", user));
        map.put("dto", dto);
        return this.qwzxStatisticsMapper.fjlb(map);
    }

    @Override
    public IPage<Map<String, Object>> zgmjList(TbQwMfjSearchDto dto) {
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        Map<String, Object> map = new HashMap<>();
//        UserInfo user = UserInfoManager.get();
        map.put("pageIndex", (dto.getPageCurrent() - 1) * dto.getPageSize());
        map.put("pageSize", dto.getPageSize());
//        map.put("useSql", PermissionsUtil.createSqlOfCode("a", user));
        map.put("dto", dto);
        int count = this.qwzxStatisticsMapper.kcdMjCount(map);
        List<Map<String, Object>> list = this.qwzxStatisticsMapper.zgmjList(map);
        IPage<Map<String, Object>> page = new Page<>(dto.getPageCurrent(), dto.getPageSize());
        page.setTotal(count);
        page.setRecords(list);
        return page;
    }

    @Override
    public IPage<Map<String, Object>> qxFjlb(TbQwMfjSearchDto dto) {
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        Map<String, Object> map = new HashMap<>();
//        UserInfo user = UserInfoManager.get();
        map.put("pageIndex", (dto.getPageCurrent() - 1) * dto.getPageSize());
        map.put("pageSize", dto.getPageSize());
//        map.put("useSql", PermissionsUtil.createSql("a", user));
        map.put("dto", dto);
        int count = this.qwzxStatisticsMapper.qxFjlbCount(map);
        List<Map<String, Object>> list = this.qwzxStatisticsMapper.qxFjlb(map);
        IPage<Map<String, Object>> page = new Page<>(dto.getPageCurrent(), dto.getPageSize());
        page.setTotal(count);
        page.setRecords(list);
        return page;
    }

    @Override
    public List<Map<String, Object>> mjfjtj(TbQwMfjSearchDto dto) {
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        Map<String, Object> map = new HashMap<>();
//        UserInfo user = UserInfoManager.get();
//        map.put("useSql", PermissionsUtil.createSqlOfCode("a", user));
        map.put("dto", dto);
        return this.qwzxStatisticsMapper.mjfjtj(map);
    }

    @Override
    public IPage<Map<String, Object>> qxjMjlb(TbQwMfjSearchDto dto) {
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        Map<String, Object> map = new HashMap<>();
//        UserInfo user = UserInfoManager.get();
        map.put("pageIndex", (dto.getPageCurrent() - 1) * dto.getPageSize());
        map.put("pageSize", dto.getPageSize());
//        map.put("useSql", PermissionsUtil.createSql("", user));
        map.put("dto", dto);
        int count = this.qwzxStatisticsMapper.qxjMjlbCount(map);
        List<Map<String, Object>> list = this.qwzxStatisticsMapper.qxjMjlb(map);
        list.forEach(item -> {
            SysUser sysUser = this.tbBaseAdaptRemoteService.getUserOrFjInfoBySfzh(String.valueOf(item.get("sfzh")));
            if (sysUser != null) {
                DeptInfoVo dept = this.tbBaseAdaptRemoteService.getDeptInfoByUserId(String.valueOf(sysUser.getId()));
                item.put("orgcode", dept.getDeptcode());
                item.put("orgid", dept.getDeptid());
                item.put("orgname", dept.getDeptname());
                TbQwQxj qxj = this.tbQwQxjMapper.selectOne(
                        new LambdaQueryWrapper<TbQwQxj>()
                                .ge(StringUtils.isNotBlank(dto.getKssj()), TbQwQxj::getKssj, dto.getKssj())
                                .le(StringUtils.isNotBlank(dto.getJssj()), TbQwQxj::getJssj, dto.getJssj())
                                .orderByDesc(TbQwQxj::getKssj)
                                .last(" limit 1")
                );
                if (qxj != null) {
                    item.put("kssj", DateUtils.getQueryDateString(qxj.getKssj(), "01"));
                    item.put("jssj", DateUtils.getQueryDateString(qxj.getJssj(), "01"));
                }
            }
        });
        IPage<Map<String, Object>> page = new Page<>(dto.getPageCurrent(), dto.getPageSize());
        page.setTotal(count);
        page.setRecords(list);
        return page;
    }

    @Override
    public IPage<Map<String, Object>> mjQblbOther(TbQwMfjSearchDto dto) {
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        Map<String, Object> map = new HashMap<>();
        map.put("pageIndex", (dto.getPageCurrent() - 1) * dto.getPageSize());
        map.put("pageSize", dto.getPageSize());
        map.put("dto", dto);
        int count = this.qwzxStatisticsMapper.mjQblbCount(map);
        List<Map<String, Object>> list = this.qwzxStatisticsMapper.mjQblb(map);
        IPage<Map<String, Object>> page = new Page<>(dto.getPageCurrent(), dto.getPageSize());
        page.setRecords(list);
        page.setTotal(count);
        return page;
    }

    @Override
    public IPage<Map<String, Object>> mjlbOther(TbQwMfjSearchDto dto) {
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        Map<String, Object> map = new HashMap<>();
        map.put("pageIndex", (dto.getPageCurrent() - 1) * dto.getPageSize());
        map.put("pageSize", dto.getPageSize());
        map.put("dto", dto);
        int count = this.qwzxStatisticsMapper.getMjlbCount(map);
        List<Map<String, Object>> list = this.qwzxStatisticsMapper.mjlb(map);
        IPage<Map<String, Object>> page = new Page<>(dto.getPageCurrent(), dto.getPageSize());
        page.setTotal(count);
        page.setRecords(list);
        return page;
    }

    @Override
    public IPage<Map<String, Object>> zgmjListOther(TbQwMfjSearchDto dto) {
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        Map<String, Object> map = new HashMap<>();
        map.put("pageIndex", (dto.getPageCurrent() - 1) * dto.getPageSize());
        map.put("pageSize", dto.getPageSize());
        map.put("dto", dto);
        int count = this.qwzxStatisticsMapper.kcdMjCount(map);
        List<Map<String, Object>> list = this.qwzxStatisticsMapper.zgmjList(map);
        IPage<Map<String, Object>> page = new Page<>(dto.getPageCurrent(), dto.getPageSize());
        page.setTotal(count);
        page.setRecords(list);
        return page;
    }

    @Override
    public IPage<Map<String, Object>> qxjMjlbOther(TbQwMfjSearchDto dto) {
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        Map<String, Object> map = new HashMap<>();
        map.put("pageIndex", (dto.getPageCurrent() - 1) * dto.getPageSize());
        map.put("pageSize", dto.getPageSize());
        map.put("dto", dto);
        int count = this.qwzxStatisticsMapper.qxjMjlbCount(map);
        List<Map<String, Object>> list = this.qwzxStatisticsMapper.qxjMjlb(map);
        list.forEach(item -> {
            SysUser sysUser = this.tbBaseAdaptRemoteService.getUserOrFjInfoBySfzh(String.valueOf(item.get("sfzh")));
            if (sysUser != null) {
                DeptInfoVo dept = this.tbBaseAdaptRemoteService.getDeptInfoByUserId(String.valueOf(sysUser.getId()));
                item.put("orgcode", dept.getDeptcode());
                item.put("orgid", dept.getDeptid());
                item.put("orgname", dept.getDeptname());
                TbQwQxj qxj = this.tbQwQxjMapper.selectOne(
                        new LambdaQueryWrapper<TbQwQxj>()
                                .ge(StringUtils.isNotBlank(dto.getKssj()), TbQwQxj::getKssj, dto.getKssj())
                                .le(StringUtils.isNotBlank(dto.getJssj()), TbQwQxj::getJssj, dto.getJssj())
                                .orderByDesc(TbQwQxj::getKssj)
                                .last(" limit 1")
                );
                if (qxj != null) {
                    item.put("kssj", DateUtils.getQueryDateString(qxj.getKssj(), "01"));
                    item.put("jssj", DateUtils.getQueryDateString(qxj.getJssj(), "01"));
                }
            }
        });
        IPage<Map<String, Object>> page = new Page<>(dto.getPageCurrent(), dto.getPageSize());
        page.setTotal(count);
        page.setRecords(list);
        return page;
    }


    @Override
    public IPage<Map<String, Object>> qblbOther(TbQwMfjSearchDto dto) {
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        Map<String, Object> map = new HashMap<>();
        map.put("pageIndex", (dto.getPageCurrent() - 1) * dto.getPageSize());
        map.put("pageSize", dto.getPageSize());
        map.put("dto", dto);
        int count = this.qwzxStatisticsMapper.getQblbCount(map);
        List<Map<String, Object>> list = this.qwzxStatisticsMapper.qblb(map);
        IPage<Map<String, Object>> page = new Page<>(dto.getPageCurrent(), dto.getPageSize());
        page.setTotal(count);
        page.setRecords(list);
        return page;
    }

    @Override
    public IPage<Map<String, Object>> fjlbOther(TbQwMfjSearchDto dto) {
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        Map<String, Object> map = new HashMap<>();
        map.put("pageIndex", (dto.getPageCurrent() - 1) * dto.getPageSize());
        map.put("pageSize", dto.getPageSize());
        map.put("dto", dto);
        int count = this.qwzxStatisticsMapper.getFjlbCount(map);
        List<Map<String, Object>> list = this.qwzxStatisticsMapper.fjlb(map);
        IPage<Map<String, Object>> page = new Page<>(dto.getPageCurrent(), dto.getPageSize());
        page.setTotal(count);
        page.setRecords(list);
        return page;
    }

    @Override
    public IPage<Map<String, Object>> zgfjListOther(TbQwMfjSearchDto dto) {
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        Map<String, Object> map = new HashMap<>();
        map.put("pageIndex", (dto.getPageCurrent() - 1) * dto.getPageSize());
        map.put("pageSize", dto.getPageSize());
        map.put("dto", dto);
        int count = this.qwzxStatisticsMapper.getZgfjCount(map);
        List<Map<String, Object>> list = this.qwzxStatisticsMapper.getZgfjList(map);
        IPage<Map<String, Object>> page = new Page<>(dto.getPageCurrent(), dto.getPageSize());
        page.setTotal(count);
        page.setRecords(list);
        return page;
    }

    @Override
    public IPage<Map<String, Object>> qxFjlbOther(TbQwMfjSearchDto dto) {
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        Map<String, Object> map = new HashMap<>();
        map.put("pageIndex", (dto.getPageCurrent() - 1) * dto.getPageSize());
        map.put("pageSize", dto.getPageSize());
        map.put("dto", dto);
        int count = this.qwzxStatisticsMapper.qxFjlbCount(map);
        List<Map<String, Object>> list = this.qwzxStatisticsMapper.qxFjlb(map);
        IPage<Map<String, Object>> page = new Page<>(dto.getPageCurrent(), dto.getPageSize());
        page.setTotal(count);
        page.setRecords(list);
        return page;
    }

    @Override
    public Integer selectXfbbDkCount(String ssbmdm, String isChild) {
        return tbQwXfbbService.selectXfbbDkCount(ssbmdm, isChild);
    }


}
