/*
 * Author: wangjian
 * 生成controller
 */
package com.tofly.xrtymis.custom.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.api.CodeClient;
import com.tofly.api.DepartmentClient;
import com.tofly.api.UserClent;
import com.tofly.api.audit.AuditClient;
import com.tofly.api.order.OrderClient;
import com.tofly.common.core.constant.ResponeStatus;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.common.core.util.StringUtil;
import com.tofly.common.log.annotation.ToFlyAppLog;
import com.tofly.common.oauth.util.SecurityUtils;
import com.tofly.pojo.Department;
import com.tofly.pojo.comm.Audit;
import com.tofly.pojo.maintain.vo.AuxiliarySingleVo;
import com.tofly.pojo.maintain.vo.datail.RepairOrderDetailVo;
import com.tofly.pojo.plan.Checkhistory;
import com.tofly.xrtymis.custom.dto.*;
import com.tofly.xrtymis.custom.em.AuditEnum;
import com.tofly.xrtymis.custom.em.RejectedNodeEnum;
import com.tofly.xrtymis.custom.service.GdglCirculationService;
import com.tofly.xrtymis.custom.service.GdglinfoService;
import com.tofly.xrtymis.custom.service.ResultdispService;
import com.tofly.xrtymis.custom.utils.DateTimeUtil;
import com.tofly.xrtymis.custom.utils.DateUtils;
import com.tofly.xrtymis.custom.vo.AuditInfoVo;
import com.tofly.xrtymis.custom.vo.ClassificationStatisticsVO;
import com.tofly.xrtymis.custom.vo.OrderStatisticalVO;
import com.tofly.xrtymis.custom.vo.OrderUserDealNumVo;
import com.tofly.xrtymis.em.Constant;
import com.tofly.xrtymis.em.ExcelExportFileTypeEnum;
import com.tofly.xrtymis.entity.GdglCirculation;
import com.tofly.xrtymis.entity.Gdglinfo;
import com.tofly.xrtymis.entity.Resultdisp;
import com.tofly.xrtymis.exception.BusinessException;
import com.tofly.xrtymis.util.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;
import java.util.*;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;

/**
 * 业务工单详情表
 *
 * @author fu
 * @date Fri Mar 19 00:00:00 CST 2021
 */
@RestController
@RequestMapping("/gdglinfo")
@Api(tags = "业务工单详情表接口")
public class GdglinfoController {

    @Autowired
    private GdglinfoService gdglinfoService;
    @Autowired
    private DepartmentClient departmentClient;

    @Autowired
    private CodeClient codeClient;
    @Autowired
    private AuditClient auditClient;
    @Autowired
    private ResultdispService resultdispService;
    @Autowired
    private GdglCirculationService gdglCirculationService;
    @Autowired
    private UserClent userClent;
    @Autowired
    private OrderClient orderClient;

    @GetMapping("/gdInfoQuery")
    @ApiOperation("工单详情查询")
    @ApiImplicitParam(name = "export", value = "0:不导出 1：导出", required = true, dataType = "Integer")
    public ResultRespone gdInfoQuery(HttpServletResponse response, Page page, GdInfoQueryDto dto, Integer export) {
        return ResultRespone.success(gdglinfoService.gdInfoQuery(response, page, dto, export));
    }

    @GetMapping("/getUserByRole")
    @ApiOperation("根据角色获取用户信息")
    @ApiImplicitParam(name = "roleId", value = "角色id，多个‘,’分隔", required = true, dataType = "String")
    public ResultRespone getUserByRole(String roleId) {
        return ResultRespone.success(gdglinfoService.getUserByRole(roleId));
    }

    /**
     * 分页查询
     *
     * @param page     分页对象
     * @param gdglinfo 业务工单详情表
     * @return
     */
    @GetMapping("/page")
    @ApiOperation(value = "分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startTime", value = "开始日期 yyyy-MM-dd HH:mm:ss", dataType = "String"),
            @ApiImplicitParam(name = "endTime", value = "结束日期 yyyy-MM-dd HH:mm:ss", dataType = "String"),
            @ApiImplicitParam(name = "notLcjd", value = "不是本流程节点,审核前有效", dataType = "Long"),
            @ApiImplicitParam(name = "sort", value = "是否分类 1:已分类 0:未分类 ", dataType = "String"),
            @ApiImplicitParam(name = "export", value = "是否导出", dataType = "Integer"),
            @ApiImplicitParam(name = "presentDeptList", value = "当前处理部门,多个以分隔", dataType = "String"),
            @ApiImplicitParam(name = "djDeptList", value = "登记部门,多个以分隔", dataType = "String"),
            @ApiImplicitParam(name = "gdlxList", value = "工单类型,多个以分隔", dataType = "String"),
            @ApiImplicitParam(name = "gdlx1List", value = "工单类型细分1,多个以分隔", dataType = "String"),
            @ApiImplicitParam(name = "gdlx2List", value = "工单类型细分2,多个以分隔", dataType = "String"),
            @ApiImplicitParam(name = "likeUserInfo", value = "客户信息查询", dataType = "String"),
            @ApiImplicitParam(name = "lcjdList", value = "流程节点,多个以,分隔", dataType = "String"),
            @ApiImplicitParam(name = "aboutDept", value = "相关部门查询", dataType = "String"),
            @ApiImplicitParam(name = "aboutUser", value = "人员查询，多个逗号隔开", dataType = "String")
    })
    @ToFlyAppLog(title = "业务工单详情分页查询")
    public ResultRespone getGdglinfoPage(HttpServletResponse response, Page page,
                                         @ModelAttribute Gdglinfo gdglinfo, String startTime,
                                         String endTime, Long notLcjd, String sort, Integer export,
                                         String presentDeptList, String djDeptList, String gdlxList,
                                         String gdlx1List, String gdlx2List, String lcjdList,
                                         String likeUserInfo, String aboutDept, String aboutUser) {
        //TODO 哇，这下面这个查询太多了，而且很多都是重复的，也没有优化，直接怼进来的
        Date stTime = null;
        Date enTime = null;
        try {
            if (StringUtils.isNotEmpty(startTime)) {
                stTime = DateUtils.parseCurrentDateTime(startTime);
            }
            if (StringUtils.isNotEmpty(endTime)) {
                enTime = DateUtils.parseCurrentDateTime(endTime);
            }
//            else {
//                if (StringUtils.isEmpty(startTime) && StringUtils.isEmpty(endTime)) {
//                    enTime = new Date();
//                    stTime = DateTimeUtil.dateTimeDifference(enTime, -1, Calendar.MONTH);
//                } else if (StringUtils.isEmpty(startTime)) {
//                    enTime = DateUtils.parseCurrentDateTime(endTime);
//                    stTime = DateTimeUtil.dateTimeDifference(enTime, -1, Calendar.MONTH);
//                } else if (StringUtils.isEmpty(endTime)) {
//                    stTime = DateUtils.parseCurrentDateTime(startTime);
//                    enTime = DateTimeUtil.dateTimeDifference(stTime, 1, Calendar.MONTH);
//                } else {
//                    stTime = DateUtils.parseCurrentDateTime(startTime);
//                    enTime = DateUtils.parseCurrentDateTime(endTime);
//                }
//            }
            Set<Long> djDepts = null;
            if (StringUtils.isNotEmpty(djDeptList)) {
                djDepts = Arrays.stream(djDeptList.split(Constant.CSV)).map(s -> Long.parseLong(s.trim()))
                        .collect(Collectors.toSet());
            }
            Set<Long> aboutDepts = null;
            if (StringUtils.isNotEmpty(aboutDept)) {
                aboutDepts = Arrays.stream(aboutDept.split(Constant.CSV)).map(s -> Long.parseLong(s.trim()))
                        .collect(Collectors.toSet());
            }
            Set<Long> aboutUsers = null;
            if (StringUtil.isNotEmpty(aboutUser)) {
                aboutUsers = Arrays.stream(aboutUser.split(Constant.CSV)).map(s -> Long.parseLong(s.trim()))
                        .collect(Collectors.toSet());
            }
            Set<Long> gdlxs = null;
            if (StringUtils.isNotEmpty(gdlxList)) {
                gdlxs = Arrays.stream(gdlxList.split(Constant.CSV)).map(s -> Long.parseLong(s.trim()))
                        .collect(Collectors.toSet());
            }
            Set<Long> gdlx1s = null;
            if (StringUtils.isNotEmpty(gdlx1List)) {
                gdlx1s = Arrays.stream(gdlx1List.split(Constant.CSV)).map(s -> Long.parseLong(s.trim()))
                        .collect(Collectors.toSet());
            }
            Set<Long> gdlx2s = null;
            if (StringUtils.isNotEmpty(gdlx2List)) {
                gdlx2s = Arrays.stream(gdlx2List.split(Constant.CSV)).map(s -> Long.parseLong(s.trim()))
                        .collect(Collectors.toSet());
            }
            Set<Long> lcjds = null;
            if (StringUtils.isNotEmpty(lcjdList)) {
                lcjds = Arrays.stream(lcjdList.split(Constant.CSV)).map(s -> Long.parseLong(s.trim()))
                        .collect(Collectors.toSet());
            }
            Set<Long> finalGdlxs = gdlxs;
            Set<Long> finalGdlx1s = gdlx1s;
            Set<Long> finalGdlx2s = gdlx2s;
            Set<Long> finalAboutDepts = aboutDepts;
            // 判断当前分页查询模块是否为结果审核
            Long lcjd = gdglinfo.getLcjd();
            List<Gdglinfo> exportgds = new ArrayList<>();
            Long userId = SecurityUtils.getUserId();
            //结果审核流程节点的查看
            if (RejectedNodeEnum.JGSH.getCode().equals(lcjd)) {
                // 前端多余参数清除
                gdglinfo.setJgczry(null);
                // 查询审核表符合条件的数据id列表
                // 1.工单类型 11 2.当前对象 3.待审核状态
                Audit audit = new Audit();
                audit.setAuditType(AuditEnum.GD_TYPE.getCode());
                audit.setAuditUser(userId);
                audit.setAuditState(AuditEnum.AUDIT_UNCOMMITTED.getCode());
                List<Audit> result = auditClient.getAuditInfo(audit).getResult();
                Set<Long> collect = new HashSet<>();
                if (null != result && result.size() > 0) {
                    collect.addAll(result.stream().map(Audit::getAuditPlanId).collect(Collectors.toSet()));
                }
                // 未新增审批链的数据,也满足条件
                Set<Long> collect1 = gdglinfoService.list(new QueryWrapper<Gdglinfo>().lambda().eq(Gdglinfo::getJgczry, userId)
                        .eq(StringUtils.isNotEmpty(gdglinfo.getKhbh()),Gdglinfo::getKhbh,gdglinfo.getKhbh())
                        .eq(gdglinfo.getDjry() != null,Gdglinfo::getDjry,gdglinfo.getDjry())
                        .eq(Gdglinfo::getLcjd, RejectedNodeEnum.JGSH.getCode())).stream().map(Gdglinfo::getId).collect(Collectors.toSet());
                collect.addAll(collect1);
                if (collect.size() > 0) {
                    if (export == null || export != 1) {
                        if (StringUtils.isNotEmpty(gdglinfo.getHangUp()) && gdglinfo.getHangUp().equals("2")) {
                            gdglinfo.setHangUp(null);

                            Page page1 = gdglinfoService.page(page, Wrappers.query(gdglinfo).lambda().in(Gdglinfo::getId, collect)
                                    .ne(Gdglinfo::getHangUp, "1")
                                    .ge(StringUtil.isNotNull(stTime), Gdglinfo::getDjsj, stTime)
                                    .eq(gdglinfo.getDjry() != null,Gdglinfo::getDjry,gdglinfo.getDjry())
                                    .eq(StringUtils.isNotEmpty(gdglinfo.getKhbh()),Gdglinfo::getKhbh,gdglinfo.getKhbh())
                                    .le(StringUtil.isNotNull(enTime), Gdglinfo::getDjsj, enTime)
                                    .eq(StringUtil.isNotNull(gdglinfo.getDjbm()), Gdglinfo::getDjbm, gdglinfo.getDjbm())
                                    .eq(StringUtil.isNotNull(gdglinfo.getLcjd()), Gdglinfo::getLcjd, gdglinfo.getLcjd())
                                    .eq(StringUtil.isNotNull(gdglinfo.getGdlx()), Gdglinfo::getGdlx, gdglinfo.getGdlx())
                                    .eq(StringUtil.isNotNull(gdglinfo.getGdxf1()), Gdglinfo::getGdxf1, gdglinfo.getGdxf1())
                                    .eq(StringUtil.isNotNull(gdglinfo.getGdxf2()), Gdglinfo::getGdxf2, gdglinfo.getGdxf2())
                                    .in(StringUtil.isNotNull(djDepts), Gdglinfo::getDjbm, djDepts)
                                    .and(StringUtil.isNotNull(aboutDepts), v -> v.in(Gdglinfo::getCzbm, finalAboutDepts).or()
                                            .in(Gdglinfo::getRzbm, finalAboutDepts).or()
                                            .in(Gdglinfo::getShbm, finalAboutDepts).or()
                                            .in(Gdglinfo::getSlbm, finalAboutDepts).or()
                                            .in(Gdglinfo::getSqbm, finalAboutDepts).or()
                                            .in(Gdglinfo::getZjbm, finalAboutDepts).or()
                                            .in(Gdglinfo::getDjbm, finalAboutDepts))
                                    .in(StringUtil.isNotNull(finalGdlxs), Gdglinfo::getGdlx, finalGdlxs)
                                    .in(StringUtil.isNotNull(finalGdlx1s), Gdglinfo::getGdxf1, finalGdlx1s)
                                    .in(StringUtil.isNotNull(finalGdlx2s), Gdglinfo::getGdxf2, finalGdlx2s)
                                    .in(StringUtil.isNotNull(lcjds), Gdglinfo::getLcjd, lcjds)
                                    .and(StringUtil.isNotNull(likeUserInfo), v -> v.like(Gdglinfo::getKhbh, likeUserInfo)
                                            .or()
                                            .like(Gdglinfo::getKhxm, likeUserInfo)
                                            .or()
                                            .like(Gdglinfo::getKhdz, likeUserInfo)
                                            .or()
                                            .like(Gdglinfo::getLxdh, likeUserInfo)
                                            .or()
                                            .like(Gdglinfo::getGdbh, likeUserInfo))
                                    .orderByDesc(Gdglinfo::getDjsj));
                            // 判断当前处理部门是否为空
                            presentDeptFilter(presentDeptList, page1);
                            return ResultRespone.success(page1);


                        }
                        Page page1 = gdglinfoService.page(page, Wrappers.query(gdglinfo).lambda().in(Gdglinfo::getId, collect)
                                .eq(gdglinfo.getDjry() != null,Gdglinfo::getDjry,gdglinfo.getDjry())
                                .eq(StringUtils.isNotEmpty(gdglinfo.getKhbh()),Gdglinfo::getKhbh,gdglinfo.getKhbh())
                                .ge(StringUtil.isNotNull(stTime), Gdglinfo::getDjsj, stTime)
                                .le(StringUtil.isNotNull(enTime), Gdglinfo::getDjsj, enTime)
                                .eq(StringUtil.isNotNull(gdglinfo.getDjbm()), Gdglinfo::getDjbm, gdglinfo.getDjbm())
                                .eq(StringUtil.isNotNull(gdglinfo.getLcjd()), Gdglinfo::getLcjd, gdglinfo.getLcjd())
                                .eq(StringUtil.isNotNull(gdglinfo.getGdlx()), Gdglinfo::getGdlx, gdglinfo.getGdlx())
                                .eq(StringUtil.isNotNull(gdglinfo.getGdxf1()), Gdglinfo::getGdxf1, gdglinfo.getGdxf1())
                                .eq(StringUtil.isNotNull(gdglinfo.getGdxf2()), Gdglinfo::getGdxf2, gdglinfo.getGdxf2())
                                .in(StringUtil.isNotNull(djDepts), Gdglinfo::getDjbm, djDepts)
                                .and(StringUtil.isNotNull(aboutDepts), v -> v.in(Gdglinfo::getCzbm, finalAboutDepts).or()
                                        .in(Gdglinfo::getRzbm, finalAboutDepts).or()
                                        .in(Gdglinfo::getShbm, finalAboutDepts).or()
                                        .in(Gdglinfo::getSlbm, finalAboutDepts).or()
                                        .in(Gdglinfo::getSqbm, finalAboutDepts).or()
                                        .in(Gdglinfo::getZjbm, finalAboutDepts).or()
                                        .in(Gdglinfo::getDjbm, finalAboutDepts))
                                .in(StringUtil.isNotNull(finalGdlxs), Gdglinfo::getGdlx, finalGdlxs)
                                .in(StringUtil.isNotNull(finalGdlx1s), Gdglinfo::getGdxf1, finalGdlx1s)
                                .in(StringUtil.isNotNull(finalGdlx2s), Gdglinfo::getGdxf2, finalGdlx2s)
                                .in(StringUtil.isNotNull(lcjds), Gdglinfo::getLcjd, lcjds)
                                .and(StringUtil.isNotNull(likeUserInfo), v -> v.like(Gdglinfo::getKhbh, likeUserInfo)
                                        .or()
                                        .like(Gdglinfo::getKhxm, likeUserInfo)
                                        .or()
                                        .like(Gdglinfo::getKhdz, likeUserInfo)
                                        .or()
                                        .like(Gdglinfo::getLxdh, likeUserInfo)
                                        .or()
                                        .like(Gdglinfo::getGdbh, likeUserInfo))
                                .orderByDesc(Gdglinfo::getDjsj));
                        // 判断当前处理部门是否为空
                        presentDeptFilter(presentDeptList, page1);
                        return ResultRespone.success(page1);
                    } else if (export != null && export == 1) {
                        if (StringUtils.isNotEmpty(gdglinfo.getHangUp()) && gdglinfo.getHangUp().equals("2")) {
                            gdglinfo.setHangUp(null);
                            List<Gdglinfo> list = gdglinfoService.list(Wrappers.query(gdglinfo).lambda().in(Gdglinfo::getId, collect)
                                    .ne(Gdglinfo::getHangUp, "1")
                                    .ge(StringUtil.isNotNull(stTime), Gdglinfo::getDjsj, stTime)
                                    .le(StringUtil.isNotNull(enTime), Gdglinfo::getDjsj, enTime)
                                    .eq(StringUtil.isNotNull(gdglinfo.getLcjd()), Gdglinfo::getLcjd, gdglinfo.getLcjd())
                                    .eq(StringUtil.isNotNull(gdglinfo.getDjbm()), Gdglinfo::getDjbm, gdglinfo.getDjbm())
                                    .eq(StringUtil.isNotNull(gdglinfo.getGdlx()), Gdglinfo::getGdlx, gdglinfo.getGdlx())
                                    .eq(StringUtil.isNotNull(gdglinfo.getGdxf1()), Gdglinfo::getGdxf1, gdglinfo.getGdxf1())
                                    .eq(StringUtil.isNotNull(gdglinfo.getGdxf2()), Gdglinfo::getGdxf2, gdglinfo.getGdxf2())
                                    .in(StringUtil.isNotNull(djDepts), Gdglinfo::getDjbm, djDepts)
                                    .and(StringUtil.isNotNull(aboutDepts), v -> v.in(Gdglinfo::getCzbm, finalAboutDepts).or()
                                            .in(Gdglinfo::getRzbm, finalAboutDepts).or()
                                            .in(Gdglinfo::getShbm, finalAboutDepts).or()
                                            .in(Gdglinfo::getSlbm, finalAboutDepts).or()
                                            .in(Gdglinfo::getSqbm, finalAboutDepts).or()
                                            .in(Gdglinfo::getZjbm, finalAboutDepts).or()
                                            .in(Gdglinfo::getDjbm, finalAboutDepts))
                                    .in(StringUtil.isNotNull(finalGdlxs), Gdglinfo::getGdlx, finalGdlxs)
                                    .in(StringUtil.isNotNull(finalGdlx1s), Gdglinfo::getGdxf1, finalGdlx1s)
                                    .in(StringUtil.isNotNull(finalGdlx2s), Gdglinfo::getGdxf2, finalGdlx2s)
                                    .in(StringUtil.isNotNull(lcjds), Gdglinfo::getLcjd, lcjds)
                                    .and(StringUtil.isNotNull(likeUserInfo), v -> v.like(Gdglinfo::getKhbh, likeUserInfo)
                                            .or()
                                            .like(Gdglinfo::getKhxm, likeUserInfo)
                                            .or()
                                            .like(Gdglinfo::getKhdz, likeUserInfo)
                                            .or()
                                            .like(Gdglinfo::getLxdh, likeUserInfo)
                                            .or()
                                            .like(Gdglinfo::getGdbh, likeUserInfo))
                                    //导出按照升序
                                    .orderByAsc(Gdglinfo::getDjsj)
                                    //WJL加的；因为之前的工单查询每次都是查询全部字段，然后在数据导出太多的情况下太卡了
                                    .select(Gdglinfo::getId, Gdglinfo::getGdbh, Gdglinfo::getGdlx, Gdglinfo::getGdxf1, Gdglinfo::getGdxf2, Gdglinfo::getFinishTime, Gdglinfo::getKhbh,
                                            Gdglinfo::getKhxm, Gdglinfo::getKhdz, Gdglinfo::getLxdh, Gdglinfo::getGdms, Gdglinfo::getLcjd, Gdglinfo::getJjcd, Gdglinfo::getDjry, Gdglinfo::getDjbm,
                                            Gdglinfo::getDjsj, Gdglinfo::getGdsx, Gdglinfo::getCzry, Gdglinfo::getCzyj, Gdglinfo::getGdcsFlag, Gdglinfo::getBhzt, Gdglinfo::getGdhfCs,
                                            Gdglinfo::getGdzzzt, Gdglinfo::getGdgzlx, Gdglinfo::getGdgzyy));
                            exportgds = getGdglinfos(presentDeptList, exportgds, list);
                        } else {
                            List<Gdglinfo> list = gdglinfoService.list(Wrappers.query(gdglinfo).lambda().in(Gdglinfo::getId, collect)
                                    .ge(StringUtil.isNotNull(stTime), Gdglinfo::getDjsj, stTime)
                                    .le(StringUtil.isNotNull(enTime), Gdglinfo::getDjsj, enTime)
                                    .eq(gdglinfo.getDjry() != null,Gdglinfo::getDjry,gdglinfo.getDjry())
                                    .eq(StringUtils.isNotEmpty(gdglinfo.getKhbh()),Gdglinfo::getKhbh,gdglinfo.getKhbh())
                                    .eq(StringUtil.isNotNull(gdglinfo.getDjbm()), Gdglinfo::getDjbm, gdglinfo.getDjbm())
                                    .eq(StringUtil.isNotNull(gdglinfo.getLcjd()), Gdglinfo::getLcjd, gdglinfo.getLcjd())
                                    .eq(StringUtil.isNotNull(gdglinfo.getGdlx()), Gdglinfo::getGdlx, gdglinfo.getGdlx())
                                    .eq(StringUtil.isNotNull(gdglinfo.getGdxf1()), Gdglinfo::getGdxf1, gdglinfo.getGdxf1())
                                    .eq(StringUtil.isNotNull(gdglinfo.getGdxf2()), Gdglinfo::getGdxf2, gdglinfo.getGdxf2())
                                    .in(StringUtil.isNotNull(djDepts), Gdglinfo::getDjbm, djDepts)
                                    .and(StringUtil.isNotNull(aboutDepts), v -> v.in(Gdglinfo::getCzbm, finalAboutDepts).or()
                                            .in(Gdglinfo::getRzbm, finalAboutDepts).or()
                                            .in(Gdglinfo::getShbm, finalAboutDepts).or()
                                            .in(Gdglinfo::getSlbm, finalAboutDepts).or()
                                            .in(Gdglinfo::getSqbm, finalAboutDepts).or()
                                            .in(Gdglinfo::getZjbm, finalAboutDepts).or()
                                            .in(Gdglinfo::getDjbm, finalAboutDepts))
                                    .in(StringUtil.isNotNull(finalGdlxs), Gdglinfo::getGdlx, finalGdlxs)
                                    .in(StringUtil.isNotNull(finalGdlx1s), Gdglinfo::getGdxf1, finalGdlx1s)
                                    .in(StringUtil.isNotNull(finalGdlx2s), Gdglinfo::getGdxf2, finalGdlx2s)
                                    .in(StringUtil.isNotNull(lcjds), Gdglinfo::getLcjd, lcjds)
                                    .and(StringUtil.isNotNull(likeUserInfo), v -> v.like(Gdglinfo::getKhbh, likeUserInfo)
                                            .or()
                                            .like(Gdglinfo::getKhxm, likeUserInfo)
                                            .or()
                                            .like(Gdglinfo::getKhdz, likeUserInfo)
                                            .or()
                                            .like(Gdglinfo::getLxdh, likeUserInfo)
                                            .or()
                                            .like(Gdglinfo::getGdbh, likeUserInfo))
                                    //导出按照升序
                                    .orderByAsc(Gdglinfo::getDjsj)
                                    //WJL加的；因为之前的工单查询每次都是查询全部字段，然后在数据导出太多的情况下太卡了
                                    .select(Gdglinfo::getId, Gdglinfo::getGdbh, Gdglinfo::getGdlx, Gdglinfo::getGdxf1, Gdglinfo::getGdxf2, Gdglinfo::getFinishTime, Gdglinfo::getKhbh,
                                            Gdglinfo::getKhxm, Gdglinfo::getKhdz, Gdglinfo::getLxdh, Gdglinfo::getGdms, Gdglinfo::getLcjd, Gdglinfo::getJjcd, Gdglinfo::getDjry, Gdglinfo::getDjbm,
                                            Gdglinfo::getDjsj, Gdglinfo::getGdsx, Gdglinfo::getCzry, Gdglinfo::getCzyj, Gdglinfo::getGdcsFlag, Gdglinfo::getBhzt, Gdglinfo::getGdhfCs,
                                            Gdglinfo::getGdzzzt, Gdglinfo::getGdgzlx, Gdglinfo::getGdgzyy));

                            exportgds = getGdglinfos(presentDeptList, exportgds, list);
                        }
                    }
                }
            } else {
                //存放人员筛选结果审核中的工单ID；主要用于工单总览出查询
                Set<Long> gdIds = new HashSet<>();
                //存放人员筛选结果处置工单编号；主要用于工单总览出查询
                Set<String> gdbhs = new HashSet<>();
                //人员条件筛选，则需要根据人员筛选具体工单查询，只有工单总览才有人员筛选
                if (StringUtil.isNotEmpty(aboutUsers)) {
                    //人员筛选查询
                    aboutUsers.forEach(user -> {
                        Audit audit = new Audit();
                        audit.setAuditUser(user);
                        audit.setAuditType(AuditEnum.GD_TYPE.getCode());
                        List<Audit> result = auditClient.getAuditInfo(audit).getResult();
                        if (null != result && result.size() > 0) {
                            gdIds.addAll(result.stream().map(Audit::getAuditPlanId).collect(Collectors.toSet()));
                        }
                    });
                    //查询结果处置中的工单
                    List<Resultdisp> resultdispList = resultdispService.list(Wrappers.<Resultdisp>lambdaQuery()
                            .in(Resultdisp::getPersonId, aboutUsers).select(Resultdisp::getGdbh));
                    if (StringUtil.isNotNull(resultdispList) && resultdispList.size() > 0) {
                        gdbhs.addAll(resultdispList.stream().map(Resultdisp::getGdbh).collect(Collectors.toList()));
                    }
                }
                Set<Long> finalAboutUsers = aboutUsers;
                if (export == null || export != 1) {
                    if (StringUtils.isNotEmpty(gdglinfo.getHangUp()) && gdglinfo.getHangUp().equals("2")) {
                        gdglinfo.setHangUp(null);
                        //结果处置
                        if (RejectedNodeEnum.JGCZ.getCode().equals(lcjd)) {
                            //存放工单编号集合
                            Set<String> collect = new HashSet<>();
                            //查询结果处置中暂未处理的工单
                            List<Resultdisp> resultdispList = resultdispService.list(Wrappers.<Resultdisp>lambdaQuery()
                                    .eq(Resultdisp::getPersonId, userId).eq(Resultdisp::getIsFinish, "0")
                                    .select(Resultdisp::getGdbh).orderByDesc(Resultdisp::getImportDate));
                            if (StringUtil.isNotNull(resultdispList) && resultdispList.size() > 0) {
                                collect.addAll(resultdispList.stream().map(Resultdisp::getGdbh).collect(Collectors.toList()));
                            }
                            if (collect.size() > 0) {
                                Page page1 = gdglinfoService.page(page, Wrappers.query(gdglinfo).lambda().in(Gdglinfo::getGdbh, collect).orderByDesc(Gdglinfo::getDjsj));
                                // 判断当前处理部门是否为空
                                presentDeptFilter(presentDeptList, page1);
                                return ResultRespone.success(page1);
                            } else {
                                //没有该用户结果处置的
                                return ResultRespone.failed("暂无数据");
                            }
                        }

                        Page page1 = gdglinfoService.page(page, Wrappers.query(gdglinfo).lambda()
                                .ne(Gdglinfo::getHangUp, "1")
                                .eq(gdglinfo.getDjry() != null,Gdglinfo::getDjry,gdglinfo.getDjry())
                                .eq(StringUtils.isNotEmpty(gdglinfo.getKhbh()),Gdglinfo::getKhbh,gdglinfo.getKhbh())
                                .gt(notLcjd != null && gdglinfo.getLcjd() == null, Gdglinfo::getLcjd, notLcjd)
                                .isNotNull("1".equals(sort), Gdglinfo::getGdgzlx).isNull("0".equals(sort), Gdglinfo::getGdgzlx)
                                .ge(StringUtil.isNotNull(stTime), Gdglinfo::getDjsj, stTime)
                                .le(StringUtil.isNotNull(enTime), Gdglinfo::getDjsj, enTime)
                                .eq(StringUtil.isNotNull(gdglinfo.getDjbm()), Gdglinfo::getDjbm, gdglinfo.getDjbm())
                                .eq(StringUtil.isNotNull(gdglinfo.getLcjd()), Gdglinfo::getLcjd, gdglinfo.getLcjd())
                                .eq(StringUtil.isNotNull(gdglinfo.getGdlx()), Gdglinfo::getGdlx, gdglinfo.getGdlx())
                                .eq(StringUtil.isNotNull(gdglinfo.getGdxf1()), Gdglinfo::getGdxf1, gdglinfo.getGdxf1())
                                .eq(StringUtil.isNotNull(gdglinfo.getGdxf2()), Gdglinfo::getGdxf2, gdglinfo.getGdxf2())
                                .in(StringUtil.isNotNull(djDepts), Gdglinfo::getDjbm, djDepts)
                                .and(StringUtil.isNotNull(aboutDepts), v -> v.in(Gdglinfo::getCzbm, finalAboutDepts).or()
                                        .in(Gdglinfo::getRzbm, finalAboutDepts).or()
                                        .in(Gdglinfo::getShbm, finalAboutDepts).or()
                                        .in(Gdglinfo::getSlbm, finalAboutDepts).or()
                                        .in(Gdglinfo::getSqbm, finalAboutDepts).or()
                                        .in(Gdglinfo::getZjbm, finalAboutDepts).or()
                                        .in(Gdglinfo::getDjbm, finalAboutDepts))
                                //人员筛选 其实在工单查询这里，可以单独提一个条件查询构造出来，因为全是重复的查询，但是现在不好提了，因为一开始就没提出来，导致这里查询代码太重复，太长了
                                .and(StringUtil.isNotNull(aboutUsers), v -> v.in(gdbhs.size() > 0, Gdglinfo::getGdbh, gdbhs).or()
                                        .in(gdIds.size() > 0, Gdglinfo::getId, gdIds).or()
                                        .in(Gdglinfo::getDjry, finalAboutUsers).or()
                                        .in(Gdglinfo::getSlry, finalAboutUsers).or()
                                        .in(Gdglinfo::getShslry, finalAboutUsers).or()
                                        .in(Gdglinfo::getRzslry, finalAboutUsers))
                                .in(StringUtil.isNotNull(finalGdlxs), Gdglinfo::getGdlx, finalGdlxs)
                                .in(StringUtil.isNotNull(finalGdlx1s), Gdglinfo::getGdxf1, finalGdlx1s)
                                .in(StringUtil.isNotNull(finalGdlx2s), Gdglinfo::getGdxf2, finalGdlx2s)
                                .in(StringUtil.isNotNull(lcjds), Gdglinfo::getLcjd, lcjds)
                                .and(StringUtil.isNotNull(likeUserInfo), v -> v.like(Gdglinfo::getKhbh, likeUserInfo)
                                        .or()
                                        .like(Gdglinfo::getKhxm, likeUserInfo)
                                        .or()
                                        .like(Gdglinfo::getKhdz, likeUserInfo)
                                        .or()
                                        .like(Gdglinfo::getLxdh, likeUserInfo)
                                        .or()
                                        .like(Gdglinfo::getGdbh, likeUserInfo))
                                .orderByDesc(Gdglinfo::getDjsj));
                        // 判断当前处理部门是否为空
                        presentDeptFilter(presentDeptList, page1);
                        return ResultRespone.success(page1);
                    }
                    Page<Gdglinfo> page1 = gdglinfoService.getWorkOrderInfo(page, gdglinfo, notLcjd, sort, stTime, enTime, djDepts, aboutDepts, aboutUsers, gdbhs, gdIds, finalGdlxs, finalGdlx1s, finalGdlx2s, lcjds, likeUserInfo);
                    /*Page page1 = gdglinfoService.page(page, Wrappers.query(gdglinfo).lambda().gt(notLcjd != null && gdglinfo.getLcjd() == null, Gdglinfo::getLcjd, notLcjd)
                            .isNotNull("1".equals(sort), Gdglinfo::getGdgzlx).isNull("0".equals(sort), Gdglinfo::getGdgzlx)
                            .ge(StringUtil.isNotNull(stTime), Gdglinfo::getDjsj, stTime)
                            .le(StringUtil.isNotNull(enTime), Gdglinfo::getDjsj, enTime)
                            .eq(StringUtil.isNotNull(gdglinfo.getDjbm()), Gdglinfo::getDjbm, gdglinfo.getDjbm())
                            .eq(StringUtil.isNotNull(gdglinfo.getLcjd()), Gdglinfo::getLcjd, gdglinfo.getLcjd())
                            .eq(StringUtil.isNotNull(gdglinfo.getGdlx()), Gdglinfo::getGdlx, gdglinfo.getGdlx())
                            .eq(StringUtil.isNotNull(gdglinfo.getGdxf1()), Gdglinfo::getGdxf1, gdglinfo.getGdxf1())
                            .eq(StringUtil.isNotNull(gdglinfo.getGdxf2()), Gdglinfo::getGdxf2, gdglinfo.getGdxf2())
                            .in(StringUtil.isNotNull(djDepts), Gdglinfo::getDjbm, djDepts)
                            .and(StringUtil.isNotNull(aboutDepts), v -> v.in(Gdglinfo::getCzbm, finalAboutDepts).or()
                                    .in(Gdglinfo::getRzbm, finalAboutDepts).or()
                                    .in(Gdglinfo::getShbm, finalAboutDepts).or()
                                    .in(Gdglinfo::getSlbm, finalAboutDepts).or()
                                    .in(Gdglinfo::getSqbm, finalAboutDepts).or()
                                    .in(Gdglinfo::getZjbm, finalAboutDepts).or()
                                    .in(Gdglinfo::getDjbm, finalAboutDepts))
                            //人员筛选 其实在工单查询这里，可以单独提一个条件查询构造出来，因为全是重复的查询，但是现在不好提了，因为一开始就没提出来，导致这里查询代码太重复，太长了
                            .and(StringUtil.isNotNull(aboutUsers), v -> v.in(gdbhs.size() > 0, Gdglinfo::getGdbh, gdbhs).or()
                                    .in(gdIds.size() > 0, Gdglinfo::getId, gdIds).or()
                                    .in(Gdglinfo::getDjry, finalAboutUsers).or()
                                    .in(Gdglinfo::getSlry, finalAboutUsers).or()
                                    .in(Gdglinfo::getShslry, finalAboutUsers).or()
                                    .in(Gdglinfo::getRzslry, finalAboutUsers))
                            .in(StringUtil.isNotNull(finalGdlxs),  Gdglinfo::getGdlx, finalGdlxs)
                            .in(StringUtil.isNotNull(finalGdlx1s), Gdglinfo::getGdxf1, finalGdlx1s)
                            .in(StringUtil.isNotNull(finalGdlx2s), Gdglinfo::getGdxf2, finalGdlx2s)
                            .in(StringUtil.isNotNull(lcjds), Gdglinfo::getLcjd, lcjds)
                            .and(StringUtil.isNotNull(likeUserInfo), v -> v.like(Gdglinfo::getKhbh, likeUserInfo)
                                    .or()
                                    .like(Gdglinfo::getKhxm, likeUserInfo)
                                    .or()
                                    .like(Gdglinfo::getKhdz, likeUserInfo)
                                    .or()
                                    .like(Gdglinfo::getLxdh, likeUserInfo)
                                    .or()
                                    .like(Gdglinfo::getGdbh, likeUserInfo))
                            .orderByDesc(Gdglinfo::getDjsj));*/
                    // 判断当前处理部门是否为空
                    presentDeptFilter(presentDeptList, page1);
                    return ResultRespone.success(page1);
                } else if (export != null && export == 1) {
                    if (StringUtils.isNotEmpty(gdglinfo.getHangUp()) && gdglinfo.getHangUp().equals("2")) {
                        gdglinfo.setHangUp(null);
                        /*List<Gdglinfo> list = gdglinfoService.list(Wrappers.query(gdglinfo).lambda().ne(Gdglinfo::getHangUp, "1").gt(notLcjd != null && gdglinfo.getLcjd() == null, Gdglinfo::getLcjd, notLcjd)
                                .isNotNull("1".equals(sort), Gdglinfo::getGdgzlx).isNull("0".equals(sort), Gdglinfo::getGdgzlx)
                                .ge(StringUtil.isNotNull(stTime), Gdglinfo::getDjsj, stTime)
                                .le(StringUtil.isNotNull(enTime), Gdglinfo::getDjsj, enTime)
                                .eq(StringUtil.isNotNull(gdglinfo.getDjbm()), Gdglinfo::getDjbm, gdglinfo.getDjbm())
                                .eq(StringUtil.isNotNull(gdglinfo.getLcjd()), Gdglinfo::getLcjd, gdglinfo.getLcjd())
                                .eq(StringUtil.isNotNull(gdglinfo.getGdlx()), Gdglinfo::getGdlx, gdglinfo.getGdlx())
                                .eq(StringUtil.isNotNull(gdglinfo.getGdxf1()), Gdglinfo::getGdxf1, gdglinfo.getGdxf1())
                                .eq(StringUtil.isNotNull(gdglinfo.getGdxf2()), Gdglinfo::getGdxf2, gdglinfo.getGdxf2())
                                .in(StringUtil.isNotNull(djDepts), Gdglinfo::getDjbm, djDepts)
                                .and(StringUtil.isNotNull(aboutDepts), v -> v.in(Gdglinfo::getCzbm, finalAboutDepts).or()
                                        .in(Gdglinfo::getRzbm, finalAboutDepts).or()
                                        .in(Gdglinfo::getShbm, finalAboutDepts).or()
                                        .in(Gdglinfo::getSlbm, finalAboutDepts).or()
                                        .in(Gdglinfo::getSqbm, finalAboutDepts).or()
                                        .in(Gdglinfo::getZjbm, finalAboutDepts).or()
                                        .in(Gdglinfo::getDjbm, finalAboutDepts))
                                //人员筛选 其实在工单查询这里，可以单独提一个条件查询构造出来，因为全是重复的查询，但是现在不好提了，因为一开始就没提出来，导致这里查询代码太重复，太长了
                                .and(StringUtil.isNotNull(aboutUsers), v -> v.in(gdbhs.size() > 0, Gdglinfo::getGdbh, gdbhs).or()
                                        .in(gdIds.size() > 0, Gdglinfo::getId, gdIds).or()
                                        .in(Gdglinfo::getDjry, finalAboutUsers).or()
                                        .in(Gdglinfo::getSlry, finalAboutUsers).or()
                                        .in(Gdglinfo::getShslry, finalAboutUsers).or()
                                        .in(Gdglinfo::getRzslry, finalAboutUsers))
                                .in(StringUtil.isNotNull(finalGdlxs), Gdglinfo::getGdlx, finalGdlxs)
                                .in(StringUtil.isNotNull(finalGdlx1s), Gdglinfo::getGdxf1, finalGdlx1s)
                                .in(StringUtil.isNotNull(finalGdlx2s), Gdglinfo::getGdxf2, finalGdlx2s)
                                .in(StringUtil.isNotNull(lcjds), Gdglinfo::getLcjd, lcjds)
                                .and(StringUtil.isNotNull(likeUserInfo), v -> v.like(Gdglinfo::getKhbh, likeUserInfo)
                                        .or()
                                        .like(Gdglinfo::getKhxm, likeUserInfo)
                                        .or()
                                        .like(Gdglinfo::getKhdz, likeUserInfo)
                                        .or()
                                        .like(Gdglinfo::getLxdh, likeUserInfo)
                                        .or()
                                        .like(Gdglinfo::getGdbh, likeUserInfo))
                                //导出按照升序
                                .orderByAsc(Gdglinfo::getDjsj)
                                //WJL加的；因为之前的工单查询每次都是查询全部字段，然后在数据导出太多的情况下太卡了
                                .select(Gdglinfo::getId, Gdglinfo::getGdbh, Gdglinfo::getGdlx, Gdglinfo::getGdxf1, Gdglinfo::getGdxf2, Gdglinfo::getFinishTime, Gdglinfo::getKhbh,
                                        Gdglinfo::getKhxm, Gdglinfo::getKhdz, Gdglinfo::getLxdh, Gdglinfo::getGdms, Gdglinfo::getLcjd, Gdglinfo::getJjcd, Gdglinfo::getDjry, Gdglinfo::getDjbm,
                                        Gdglinfo::getDjsj, Gdglinfo::getGdsx, Gdglinfo::getCzry, Gdglinfo::getCzyj, Gdglinfo::getGdcsFlag, Gdglinfo::getBhzt, Gdglinfo::getGdhfCs,
                                        Gdglinfo::getGdzzzt, Gdglinfo::getGdgzlx, Gdglinfo::getGdgzyy));
                        exportgds = getGdglinfos(presentDeptList, exportgds, list);*/
                    }/* else {
                        List<Gdglinfo> list = gdglinfoService.list(Wrappers.query(gdglinfo).lambda().gt(notLcjd != null && gdglinfo.getLcjd() == null, Gdglinfo::getLcjd, notLcjd)
                                .isNotNull("1".equals(sort), Gdglinfo::getGdgzlx).isNull("0".equals(sort), Gdglinfo::getGdgzlx)
                                .ge(StringUtil.isNotNull(stTime), Gdglinfo::getDjsj, stTime)
                                .le(StringUtil.isNotNull(enTime), Gdglinfo::getDjsj, enTime)
                                .eq(StringUtil.isNotNull(gdglinfo.getDjbm()), Gdglinfo::getDjbm, gdglinfo.getDjbm())
                                .eq(StringUtil.isNotNull(gdglinfo.getLcjd()), Gdglinfo::getLcjd, gdglinfo.getLcjd())
                                .eq(StringUtil.isNotNull(gdglinfo.getGdlx()), Gdglinfo::getGdlx, gdglinfo.getGdlx())
                                .eq(StringUtil.isNotNull(gdglinfo.getGdxf1()), Gdglinfo::getGdxf1, gdglinfo.getGdxf1())
                                .eq(StringUtil.isNotNull(gdglinfo.getGdxf2()), Gdglinfo::getGdxf2, gdglinfo.getGdxf2())
                                .in(StringUtil.isNotNull(djDepts), Gdglinfo::getDjbm, djDepts)
                                .and(StringUtil.isNotNull(aboutDepts), v -> v.in(Gdglinfo::getCzbm, finalAboutDepts).or()
                                        .in(Gdglinfo::getRzbm, finalAboutDepts).or()
                                        .in(Gdglinfo::getShbm, finalAboutDepts).or()
                                        .in(Gdglinfo::getSlbm, finalAboutDepts).or()
                                        .in(Gdglinfo::getSqbm, finalAboutDepts).or()
                                        .in(Gdglinfo::getZjbm, finalAboutDepts).or()
                                        .in(Gdglinfo::getDjbm, finalAboutDepts))
                                //人员筛选 其实在工单查询这里，可以单独提一个条件查询构造出来，因为全是重复的查询，但是现在不好提了，因为一开始就没提出来，导致这里查询代码太重复，太长了
                                .and(StringUtil.isNotNull(aboutUsers), v -> v.in(gdbhs.size() > 0, Gdglinfo::getGdbh, gdbhs).or()
                                        .in(gdIds.size() > 0, Gdglinfo::getId, gdIds).or()
                                        .in(Gdglinfo::getDjry, finalAboutUsers).or()
                                        .in(Gdglinfo::getSlry, finalAboutUsers).or()
                                        .in(Gdglinfo::getShslry, finalAboutUsers).or()
                                        .in(Gdglinfo::getRzslry, finalAboutUsers))
                                .in(StringUtil.isNotNull(finalGdlxs), Gdglinfo::getGdlx, finalGdlxs)
                                .in(StringUtil.isNotNull(finalGdlx1s), Gdglinfo::getGdxf1, finalGdlx1s)
                                .in(StringUtil.isNotNull(finalGdlx2s), Gdglinfo::getGdxf2, finalGdlx2s)
                                .in(StringUtil.isNotNull(lcjds), Gdglinfo::getLcjd, lcjds)
                                .and(StringUtil.isNotNull(likeUserInfo), v -> v.like(Gdglinfo::getKhbh, likeUserInfo)
                                        .or()
                                        .like(Gdglinfo::getKhxm, likeUserInfo)
                                        .or()
                                        .like(Gdglinfo::getKhdz, likeUserInfo)
                                        .or()
                                        .like(Gdglinfo::getLxdh, likeUserInfo)
                                        .or()
                                        .like(Gdglinfo::getGdbh, likeUserInfo))
                                //导出按照升序
                                .orderByAsc(Gdglinfo::getDjsj)
                                //WJL加的；因为之前的工单查询每次都是查询全部字段，然后在数据导出太多的情况下太卡了
                                .select(Gdglinfo::getId, Gdglinfo::getGdbh, Gdglinfo::getGdlx, Gdglinfo::getGdxf1, Gdglinfo::getGdxf2, Gdglinfo::getFinishTime, Gdglinfo::getKhbh,
                                        Gdglinfo::getKhxm, Gdglinfo::getKhdz, Gdglinfo::getLxdh, Gdglinfo::getGdms, Gdglinfo::getLcjd, Gdglinfo::getJjcd, Gdglinfo::getDjry, Gdglinfo::getDjbm,
                                        Gdglinfo::getDjsj, Gdglinfo::getGdsx, Gdglinfo::getCzry, Gdglinfo::getCzyj, Gdglinfo::getGdcsFlag, Gdglinfo::getBhzt, Gdglinfo::getGdhfCs,
                                        Gdglinfo::getGdzzzt, Gdglinfo::getGdgzlx, Gdglinfo::getGdgzyy));
                        exportgds = getGdglinfos(presentDeptList, exportgds, list);
                    }*/

                    List<Gdglinfo> list = gdglinfoService.getWorkOrderInfo(gdglinfo, notLcjd, sort, stTime, enTime, djDepts, aboutDepts, aboutUsers, gdbhs, gdIds, finalGdlxs, finalGdlx1s, finalGdlx2s, lcjds, likeUserInfo);
                    exportgds = getGdglinfos(presentDeptList, exportgds, list);

                }
            }
            if (export != null && export == 1) {
                ExcelExportFileTypeEnum excelExportFileTypeEnum = ExcelExportFileTypeEnum.getExcelExportFileTypeEnum("exportGdglService", String.valueOf(export));
                if (null == excelExportFileTypeEnum) {
                    return null;
                }
                AtomicLong i = new AtomicLong(1);
                exportgds.forEach(info -> {
                    // 类型拼接
                    String gdlxName = info.getGdlxName();
                    String gdxf1Name = info.getGdxf1Name();
                    String gdxf2Name = info.getGdxf2Name();
                    if (StringUtil.isNotEmpty(gdxf1Name)) {
                        gdlxName = gdlxName + "-" + gdxf1Name;
                        if (StringUtil.isNotEmpty(gdxf2Name)) {
                            gdlxName = gdlxName + "-" + gdxf2Name;
                        }
                    }
                    info.setTypeJoint(gdlxName);
                    //序号从1开始
                    info.setId(i.getAndIncrement());
                });
                // 将查询的结果转json字符串的格式，因为导出的时候只能传一个字符串
                // 从模型类型枚举根据templateServiceType获取策略对应模板数据
                Map<String, Object> dataMap = new HashMap<>();
                List<Gdglinfo> collect = exportgds.stream().sorted(Comparator.comparing(Gdglinfo::getDjsj)).collect(Collectors.toList());
                dataMap.put("list", collect);
                ExcelUtil.export(dataMap, excelExportFileTypeEnum, Constant.FILE_PATH_TEST_EXPORT_EXCEL, response);
                return null;
            }
            return ResultRespone.success(new Page<Gdglinfo>());
        } catch (Exception e) {
            return ResultRespone.failed(null, e.getMessage());
        }
    }

    private List<Gdglinfo> getGdglinfos(String presentDeptList, List<Gdglinfo> exportgds, List<Gdglinfo> list) {
        if (StringUtil.isNotNull(presentDeptList)) {
            List<Long> deptIdList = Arrays.stream(presentDeptList.split(Constant.CSV)).map(s -> Long.parseLong(s.trim()))
                    .collect(Collectors.toList());
            exportgds = exportgds.stream().filter(info -> null != info.getNodeInfo() && null != info.getNodeInfo().getPresentDept() && deptIdList.contains(info.getNodeInfo().getPresentDept())).collect(Collectors.toList());
        } else {
            exportgds = list;
        }
        return exportgds;
    }

    /**
     * 判断是否传入处理部门条件,若传入则过滤
     *
     * @param presentDeptList
     * @param page1
     */
    private void presentDeptFilter(String presentDeptList, Page page1) {

        if (StringUtil.isNotNull(presentDeptList)) {
            Set<Long> deptIdList = Arrays.stream(presentDeptList.split(Constant.CSV)).map(s -> Long.parseLong(s.trim()))
                    .collect(Collectors.toSet());
            List<Gdglinfo> records = page1.getRecords();

            List<Gdglinfo> collect2 = records.stream().filter(info -> null != info.getNodeInfo() && null != info.getNodeInfo().getPresentDept() && deptIdList.contains(info.getNodeInfo().getPresentDept())).collect(Collectors.toList());
            page1.setTotal(collect2.size());
            page1.setRecords(collect2);

        }
    }

    /**
     * 获取部门信息
     */
    @GetMapping("/getDepartment")
    @ApiOperation(value = "获取部门信息")
    public ResultRespone getGdglinfoPage() {
        return ResultRespone.success(departmentClient.departmentListAll());
    }

    /**
     * 通过id查询业务工单详情表
     *
     * @param id id
     * @return ResultRespone
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "通过ID查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    @ToFlyAppLog(title = "通过id查询业务工单详情表")
    public ResultRespone getById(@PathVariable("id") Long id) {
        return ResultRespone.success(gdglinfoService.getById(id));
    }

    /**
     * 新增业务工单详情表
     *
     * @param extend 业务工单扩展详情表
     * @return ResultRespone
     */
    @ToFlyAppLog(title = "工单登记")
    @ApiOperation(value = "工单登记")
    @PostMapping("/save")
    public ResultRespone save(List<MultipartFile> fileList, GdglinfoExtendDto extend) {
        List<Resultdisp> resultdispList = extend.getResultdispList();
        return gdglinfoService.saveGdglInfo(fileList, extend, resultdispList);
    }

    @ToFlyAppLog(title = "工单登记远程调用")
    @ApiOperation(value = "工单登记远程调用")
    @PostMapping("/saveFeign")
    public ResultRespone saveFeign(@RequestBody GdglinfoExtendDto extend) {
        List<Resultdisp> resultdispList = extend.getResultdispList();
        return gdglinfoService.saveGdglInfo(null, extend, resultdispList);
    }

    @ToFlyAppLog(title = "工单登记远程调用")
    @ApiOperation(value = "工单登记远程调用")
    @PostMapping("/saveGdglInfoMeter")
    public ResultRespone saveGdglInfoMeter(@RequestParam("extend") String extend) {
        GdglinfoExtendDto gdglinfoExtendDto = JSONObject.parseObject(extend, GdglinfoExtendDto.class);
        List<Resultdisp> resultdispList = gdglinfoExtendDto.getResultdispList();
        return gdglinfoService.saveGdglInfo(null, gdglinfoExtendDto, resultdispList);
    }


    @ApiOperation(value = "工单登记远程调用2(由于文件与对象远程调用的时候传参问题，所以另起一个远程调用接口，封装了传参)")
    @PostMapping("/saveGdglInfo2")
    public ResultRespone saveGdglInfo2(@RequestParam("extend") FeignGdInfoDto extend) {
        List<Resultdisp> resultdispList = extend.getResultdispList();
        List<MultipartFile> fileList = extend.getFileList();
        return gdglinfoService.saveGdglInfo(fileList, extend, resultdispList);
    }

    /**
     * 通过部门id获取部门信息和用户信息
     */
    @ApiOperation(value = "通过部门id获取部门信息和用户信息")
    @GetMapping("/getDepartmentIdByUser")
    public ResultRespone getDepartmentIdByUser() {
        ResultRespone<List<Department>> department = departmentClient.departmentListAll();
        List<Department> departmentList = department.getResult();
        StringBuffer stringId = new StringBuffer();
        for (Department d : departmentList) {
            stringId.append(d.getId() + ",");
        }
        String s = stringId.toString();
        return ResultRespone.success(departmentClient.getUserByDepts(s));
    }


    /**
     * 接单
     */
    @GetMapping("/jd")
    @ApiOperation(value = "修改接单状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "工单ID", required = true, dataType = "Long")
    })
    @ToFlyAppLog(title = "修改接单状态")
    public ResultRespone updateJdZT(long id) {
        return ResultRespone.success(gdglinfoService.updateJdZT(id));
    }


    /**
     * 认证处理
     *
     * @param extend 认证处理
     * @return ResultRespone
     */
    @ToFlyAppLog(title = "认证处置")
    @ApiOperation(value = "认证处置")
    @PostMapping("/saveCertification")
    public ResultRespone saveCertification(List<MultipartFile> fileList, GdglinfoExtendDto extend) {
        List<Resultdisp> resultdispList = extend.getResultdispList();
        return ResultRespone.success(gdglinfoService.saveCertification(fileList, extend, resultdispList));
    }

    /**
     * 催单
     *
     * @return ResultRespone
     */
    @ToFlyAppLog(title = "催单")
    @ApiOperation(value = "催单")
    @PostMapping("/reminder")
    public ResultRespone reminder(@RequestBody Gdglinfo gdglinfo) {
        return ResultRespone.success(gdglinfoService.reminder(gdglinfo));
    }

    /**
     * APP统计工单处理情况
     *
     * @return ResultRespone
     */
    @ToFlyAppLog(title = "APP统计工单处理情况")
    @ApiOperation(value = "APP统计工单处理情况")
    @GetMapping("/reminder")
    public ResultRespone statistical() {
        OrderStatisticalVO orderStatisticalVO = gdglinfoService.statistical();
        return ResultRespone.success(orderStatisticalVO);
    }

    /**
     * 获取上传文件信息
     *
     * @return ResultRespone
     */
    @ToFlyAppLog(title = "获取上传文件信息")
    @ApiOperation(value = "获取上传文件信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "上传文件的ids，多个id以逗号隔开", required = true, dataType = "String")
    })
    @GetMapping("/getFileInformation")
    public ResultRespone getFileInformation(String ids) {
        return ResultRespone.success(gdglinfoService.getFileInformation(ids));
    }

    /**
     * 工单审核
     *
     * @param extend GdglinfoExtendDto工单审核
     * @return ResultRespone
     */
    @ToFlyAppLog(title = "认证审核")
    @ApiOperation(value = "认证审核")
    @PostMapping("/orderReview")
    public ResultRespone orderReview(@RequestBody GdglinfoExtendDto extend) {
        List<Resultdisp> resultdispList = extend.getResultdispList();
        return ResultRespone.success(gdglinfoService.orderReview(extend, resultdispList));
    }

    /**
     * 质检复核
     *
     * @param extend 质检复核
     * @return ResultRespone
     */
    @ToFlyAppLog(title = "认证质检")
    @ApiOperation(value = "认证质检")
    @PostMapping("/qcCheck")
    public ResultRespone qcCheck(@RequestBody GdglinfoExtendDto extend) {
        List<Resultdisp> resultdispList = extend.getResultdispList();
        return ResultRespone.success(gdglinfoService.qcCheck(extend, resultdispList));
    }

    /**
     * 处置结果
     *
     * @param extend 处置结果
     * @return ResultRespone
     */
    @ToFlyAppLog(title = "结果处置")
    @ApiOperation(value = "结果处置")
    @PostMapping("/actionResults")
    public ResultRespone actionResults(List<MultipartFile> fileList, GdglinfoExtendDto extend) {
        return ResultRespone.success(gdglinfoService.actionResults(fileList, extend));
    }

    @ApiOperation(value = "转抢维修下单")
    @PostMapping("/qwxPlaceOrder")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "业务工单id", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "startTime", value = "开始时间 yyyy-MM-dd HH:mm:ss", required = true, dataType = "String"),
            @ApiImplicitParam(name = "endTime", value = "结束时间 yyyy-MM-dd HH:mm:ss", required = true, dataType = "String"),
            @ApiImplicitParam(name = "orderSource", value = "工单来源，字典编码表，0计划、1自建、2热线", required = true, dataType = "String"),
            @ApiImplicitParam(name = "typeId", value = "维修类型,关联表TF_YWPN_REPAIRTYPE_D的关键值", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "phone", value = "电话", required = false, dataType = "String"),
            @ApiImplicitParam(name = "respUser", value = "维修人ID,主要负责人", required = true, dataType = "Long")
    })
    @ToFlyAppLog(title = "转抢维修下单")
    public ResultRespone qwxPlaceOrder(
            @RequestParam(value = "id", required = true) Long id,
            @RequestParam(value = "startTime", required = true) String startTime,
            @RequestParam(value = "endTime", required = true) String endTime,
            @RequestParam(value = "orderSource", required = true) String orderSource,
            @RequestParam(value = "typeId", required = true) Long typeId,
            @RequestParam(value = "phone", required = false) String phone,
            @RequestParam(value = "respUser", required = true) Long respUser) {
        try {
            GdglinfoExtendDto gdglinfoExtendDto = new GdglinfoExtendDto();
            gdglinfoExtendDto.setId(id);
            gdglinfoExtendDto.setStartTime(DateUtils.parseCurrentDateTime(startTime));
            gdglinfoExtendDto.setEndTime(DateUtils.parseCurrentDateTime(endTime));
            gdglinfoExtendDto.setRespUser(respUser);
            gdglinfoExtendDto.setOrderSource(orderSource);
            gdglinfoExtendDto.setTypeId(typeId);
            gdglinfoExtendDto.setPhone(phone);

            return ResultRespone.success(gdglinfoService.gdglToPwxPlaceOrder(gdglinfoExtendDto));
        } catch (ParseException e) {
            return ResultRespone.failed(e.getMessage());

        }
    }

    /**
     * 结果审核
     *
     * @param planId
     * @param auditResult
     * @param auditNotes
     * @return
     */
//    @ToFlyAppLog(title="结果审核" )
    @ApiOperation(value = "结果审核")
    @PostMapping("/orderReturnVisit")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startTime", value = "开始时间 yyyy-MM-dd HH:mm:ss", required = false, dataType = "String"),
            @ApiImplicitParam(name = "endTime", value = "结束时间 yyyy-MM-dd HH:mm:ss", required = false, dataType = "String"),
            @ApiImplicitParam(name = "orderSource", value = "工单来源，字典编码表，0计划、1自建、2热线", required = false, dataType = "String"),
            @ApiImplicitParam(name = "typeId", value = "维修类型,关联表TF_YWPN_REPAIRTYPE_D的关键值", required = false, dataType = "Long"),
            @ApiImplicitParam(name = "typeId", value = "维修类型,关联表TF_YWPN_REPAIRTYPE_D的关键值", required = false, dataType = "Long"),
            @ApiImplicitParam(name = "respUser", value = "维修人ID,主要负责人", required = false, dataType = "Long")
    })
    @ToFlyAppLog(title = "结果审核")
    public ResultRespone orderReturnVisit(@RequestParam(value = "planId") Long planId,
                                          @RequestParam(value = "auditResult") String auditResult,
                                          @RequestParam(value = "auditNotes", required = false) String auditNotes,
                                          @RequestParam(value = "startTime", required = false) String startTime,
                                          @RequestParam(value = "endTime", required = false) String endTime,
                                          @RequestParam(value = "orderSource", required = false) String orderSource,
                                          @RequestParam(value = "typeId", required = false) Long typeId,
                                          @RequestParam(value = "phone", required = false) String phone,
                                          @RequestParam(value = "respUser", required = false) Long respUser,
                                          @RequestParam(value = "auditPersonid", required = false) Long auditPersonid,
                                          @RequestParam(value = "shrdj", required = false) Integer shrdj) {


        ResultRespone rest = new ResultRespone<>();
        try {
            GdglinfoExtendDto gdglinfoExtendDto = new GdglinfoExtendDto();
            if (StringUtils.isNotEmpty(startTime) && StringUtils.isNotEmpty(endTime) && typeId != null && respUser != null) {
                gdglinfoExtendDto.setStartTime(DateUtils.parseCurrentDateTime(startTime));
                gdglinfoExtendDto.setEndTime(DateUtils.parseCurrentDateTime(endTime));
                gdglinfoExtendDto.setRespUser(respUser);
                gdglinfoExtendDto.setOrderSource(orderSource);
                gdglinfoExtendDto.setTypeId(typeId);
                gdglinfoExtendDto.setPhone(phone);
            }
            Audit audit = new Audit();
            audit.setAuditUser(auditPersonid);
            gdglinfoExtendDto.setAudit(audit);
            if (!gdglinfoService.auditDispose(planId, auditResult, auditNotes, gdglinfoExtendDto, shrdj)) {
                return ResultRespone.failed(false, "转抢维修失败");
            } else {
                rest.setCode(ResponeStatus.SUCCESS.getCode());
            }
        } catch (BusinessException e) {
            rest.setCode(e.getRetCd());
            rest.setMessage(e.getMsgDes());
        } catch (ParseException e) {
            rest.setCode(ResponeStatus.FAIL.getCode());
            rest.setMessage(e.getMessage());
        }

        return rest;
    }

    //结果审核的时候查看是否有审批人员配置

    /**
     * 后续的结果审核暂时没有审批链这一步骤了，都是逐级选择下一审批人信息
     *
     * @param planId
     * @return
     */
    @ApiOperation(value = "结果审核 - 当前工单是否已添加审批链")
    @GetMapping("/isAuditChain")
    public ResultRespone<List<AuditInfoVo>> isAuditChain(@RequestParam(value = "planId") Long planId) {
        ResultRespone<List<AuditInfoVo>> rest = new ResultRespone<>();
        try {
            rest.setResult(gdglinfoService.isAuditChain(planId));
        } catch (BusinessException e) {
            rest.setCode(e.getRetCd());
            rest.setMessage(e.getMsgDes());

        }
        return rest;
    }

    //新增审批人员配置

    /**
     * 后续的结果审核暂时没有审批链这一步骤了，都是逐级选择下一审批人信息
     *
     * @param dto
     * @return
     */
    @ApiOperation(value = "结果审核 - 新增审批链")
    @PostMapping("/saveAuditChain")
    @ToFlyAppLog(title = "结果审核 - 新增审批链")
    public ResultRespone<Boolean> saveAuditChain(@RequestBody AuditDto dto) {
        return ResultRespone.success(gdglinfoService.saveAuditChain(dto.getAuditList()));
    }

    /**
     * 后续的结果审核暂时没有审批链这一步骤了，都是逐级选择下一审批人信息
     *
     * @param dto
     * @return
     */
    @ApiOperation(value = "结果审核 - 修改审批链")
    @PostMapping("/updateAuditChain")
    @ToFlyAppLog(title = "结果审核 - 修改审批链")
    public ResultRespone<Boolean> updateAuditChain(@RequestBody AuditDto dto) {
        return ResultRespone.success(gdglinfoService.updateAuditChain(dto.getAuditList()));
    }

    @ApiOperation(value = "结果审核 - 获取对应工单id的审核历史记录")
    @GetMapping("/getorderReturnHis")
    @ToFlyAppLog(title = "结果审核 - 获取对应工单id的审核历史记录")
    public ResultRespone<List<Checkhistory>> getorderReturnHis(@RequestParam(value = "planId") Long planId) {
        return ResultRespone.success(gdglinfoService.getAuditHisInfo(planId));
    }


    @ApiOperation(value = "转入维修调用工单接口工单.")
    @GetMapping("/gdGdUpdateState")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "抢维修工单id", required = true, dataType = "String"),
            @ApiImplicitParam(name = "type", value = "工单状态1:归档；0:驳回", required = true, dataType = "Integer")
    })
    public ResultRespone<Boolean> gdGdUpdateState(@RequestParam(value = "id") String id, @RequestParam(value = "type") Integer type) {
        return ResultRespone.success(gdglinfoService.updateGdLcjdState(id, type));
    }


    @ApiOperation(value = "查询抢维修信息")
    @GetMapping("/gdGdQWXInfo")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "gdbh", value = "业务工地编号", required = true, dataType = "String"),
            @ApiImplicitParam(name = "flag", value = "是否展示部门下所有数据 是则填1 个人不填为空", required = false, dataType = "String"),
            @ApiImplicitParam(name = "type", value = "抢维修工单状态0:正常工单", required = false, dataType = "String")
    })
    public ResultRespone<List<RepairOrderDetailVo>> gdGdQWXInfo(@RequestParam(value = "gdbh") String gdbh, @RequestParam(value = "flag", required = false) String flag, String type) {
        return ResultRespone.success(gdglinfoService.gdGdQWXInfo(gdbh, flag, type));
    }

    @ApiOperation(value = "归档后工单分类、备注")
    @PostMapping("/gdgdfl")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "工单id", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "lxid", value = "归档工单故障类型", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "remarks", value = "归档工单故障备注", dataType = "String")
    })
    public ResultRespone updateGDGDLx(Long id, Long lxid, String remarks) {
        //ResultRespone

        return gdglinfoService.updateGDGDLxInfo(id, lxid, remarks);
    }


    /**
     * 修改业务工单详情表
     *
     * @param extend 业务工单详情表
     * @return ResultRespone
     */
    @ToFlyAppLog(title = "修改业务工单详情表")
    @ApiOperation(value = "修改业务工单详情表")
    @PutMapping("/updateById")
    public ResultRespone updateById(List<MultipartFile> fileList, GdglinfoExtendDto extend) {
        return gdglinfoService.updateGdglInfo(fileList, extend);
    }


    /**
     * 通过id删除业务工单详情表
     *
     * @param id id
     * @return ResultRespone
     */
    @ToFlyAppLog(title = "通过id删除业务工单详情表")
    @ApiOperation(value = "通过ID删除业务工单详情表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    @DeleteMapping("/{id}")
    public ResultRespone removeById(@PathVariable Long id) {
        return ResultRespone.success(gdglinfoService.removeById(id));
    }


    /**
     * 通过id批量删除业务工单详情表
     *
     * @param ids id
     * @return ResultRespone
     */
    @ToFlyAppLog(title = "通过id批量删除业务工单详情表")
    @ApiOperation(value = "通过ID批量删除业务工单详情表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "批量删除，多个id以逗号隔开", required = true, dataType = "String")
    })
    @DeleteMapping("/deleteByIds")
    public ResultRespone removeByIds(String ids) {
        return ResultRespone.success(gdglinfoService.removeByIds(Arrays.asList(ids.split(","))));
    }

    /**
     * 获取码表得接口
     */
    @GetMapping("/getClock")
    @ApiOperation(value = "获取码表得接口")
    public ResultRespone getClock() {
        return ResultRespone.success(codeClient.getAll());
    }

    /**
     * 分页查询根据时间和工单类型进行查询
     */
    @ToFlyAppLog(title = "分页查询根据时间和工单类型进行查询")
    @ApiOperation(value = "分页查询根据时间和工单类型进行查询")
    @GetMapping("/pageTypeSelect")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "gdlx", value = "工单类型", required = false, dataType = "String"),
            @ApiImplicitParam(name = "startAuditTime", value = "开始日期", required = false, dataType = "String"),
            @ApiImplicitParam(name = "endAuditTime", value = "结束日期", required = false, dataType = "String"),
            @ApiImplicitParam(name = "lcjd", value = "流程节点", required = false, dataType = "Long")
    })
    public ResultRespone pageTypeSelect(Page page, String gdlx, String startAuditTime, String endAuditTime, Long lcjd) {
        Date stTime = new Date();
        Date enTime = new Date();
        ResultRespone<Object> failed = StartEndTimd(startAuditTime, endAuditTime, stTime, enTime);
        if (failed != null) return failed;
        return ResultRespone.success(gdglinfoService.pageTypeSelect(page, gdlx, lcjd, stTime, enTime));
    }

    /**
     * 分页查询业务工单监控
     *
     * @param page
     * @return ResultRespone
     */
    @GetMapping("/orderMonitoring")
    @ApiOperation(value = "分页查询业务工单监控")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startAuditTime", value = "开始日期 yyyy-MM-dd", required = false, dataType = "String"),
            @ApiImplicitParam(name = "endAuditTime", value = "结束日期 yyyy-MM-dd", required = false, dataType = "String")
    })
    public ResultRespone orderMonitoring(Page page, String startAuditTime, String endAuditTime) {
        Map map = new HashMap();
        Date stTime = new Date();
        Date enTime = new Date();
        ResultRespone<Object> failed = StartEndTimd(startAuditTime, endAuditTime, stTime, enTime);
        if (failed != null) return failed;
        map.put("startAuditTime", stTime);
        map.put("endAuditTime", enTime);
        return ResultRespone.success(gdglinfoService.orderMonitoring(page, map));
    }

    private ResultRespone<Object> StartEndTimd(String startTime, String endTime, Date stTime, Date enTime) {
        try {
            if (StringUtils.isEmpty(startTime) && StringUtils.isEmpty(endTime)) {
                stTime.setTime(DateTimeUtil.dateTimeDifference(enTime, -1, Calendar.MONTH).getTime());
            } else if (StringUtils.isEmpty(startTime)) {
                enTime.setTime(DateTimeUtil.getAssignTodayEndTime(DateUtils.parseCurrentDate(endTime)).getTime());
                stTime.setTime(DateTimeUtil.dateTimeDifference(enTime, -1, Calendar.MONTH).getTime());
            } else if (StringUtils.isEmpty(endTime)) {
                stTime.setTime(DateTimeUtil.getAssignTodayBeginTime(DateUtils.parseCurrentDate(startTime)).getTime());
                enTime.setTime(DateTimeUtil.dateTimeDifference(stTime, 1, Calendar.MONTH).getTime());
            } else {
                stTime.setTime(DateTimeUtil.getAssignTodayBeginTime(DateUtils.parseCurrentDate(startTime)).getTime());
                enTime.setTime(DateTimeUtil.getAssignTodayEndTime(DateUtils.parseCurrentDate(endTime)).getTime());
            }
        } catch (ParseException pex) {
            return ResultRespone.failed("时间格式错误!");
        }
        return null;
    }

    /**
     * 业务工单监控详情
     */
    @GetMapping("/orderMonitoringDetails")
    @ApiOperation(value = "业务工单监控详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "time", value = "时间", required = false, dataType = "String"),
            @ApiImplicitParam(name = "state", value = "状态", required = false, dataType = "String")
    })
    public ResultRespone orderMonitoringDetails(Page page, String time, String state) {
        Map map = new HashMap();
        map.put("time", StringUtil.isEmpty(time) ? null : time);
        map.put("state", StringUtil.isEmpty(state) ? null : state);
        Date stTime = new Date();
        Date enTime = new Date();
        try {
            Date dtime = DateUtils.parseCurrentDate(time);
            stTime = DateTimeUtil.getAssignTodayBeginTime(dtime);
            enTime = DateTimeUtil.getAssignTodayEndTime(dtime);
        } catch (ParseException pex) {
            return ResultRespone.failed("时间格式错误!");
        }
        return ResultRespone.success(gdglinfoService.orderMonitoringDetails(page, state, stTime, enTime));
    }

    /**
     * 外业人员管理
     */
    @ToFlyAppLog(title = "外业人员管理")
    @ApiOperation(value = "外业人员管理")
    @GetMapping("/fieldPersonnel")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "slbm", value = "受理部门", required = false, dataType = "String"),
            @ApiImplicitParam(name = "slry", value = "受理人员", required = false, dataType = "String"),
            @ApiImplicitParam(name = "startAuditTime", value = "开始日期", required = false, dataType = "String"),
            @ApiImplicitParam(name = "endAuditTime", value = "结束日期", required = false, dataType = "String")
    })
    public ResultRespone fieldPersonnel(Page page, String slbm, String slry, String startAuditTime, String endAuditTime) {
        Date stTime = new Date();
        Date enTime = new Date();
        ResultRespone<Object> failed = StartEndTimd(startAuditTime, endAuditTime, stTime, enTime);
        if (failed != null) return failed;
        return ResultRespone.success(gdglinfoService.fieldPersonnel(page, slbm, slry, stTime, enTime));
    }


    /**
     * 分页查询工单分析统计
     */
    @GetMapping("/orderAnalysis")
    @ApiOperation(value = "工单分析")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startAuditTime", value = "开始日期", required = false, dataType = "String"),
            @ApiImplicitParam(name = "endAuditTime", value = "结束日期", required = false, dataType = "String")
    })
    public ResultRespone orderAnalysis(Page page, String startAuditTime, String endAuditTime) {
        Date stTime = new Date();
        Date enTime = new Date();
        ResultRespone<Object> failed = StartEndTimd(startAuditTime, endAuditTime, stTime, enTime);
        if (failed != null) return failed;
        Map map = new HashMap();
        map.put("StartAuditTime", stTime);
        map.put("endAuditTime", enTime);

        return ResultRespone.success(gdglinfoService.orderAnalysis(page, map));
    }

    /**
     * 工单完成情况统计,统计类型 0：工单完成情况；1：工单中的异常情况;2热线工单统计
     * 默认统计时间当前时间往前推一个月
     */
    @GetMapping("/collectGd")
    @ApiOperation(value = "工单完成情况统计，默认统计时间当前时间往前推一个月")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "isExport", value = "是否导出 0 不导出,1导出", required = false, dataType = "String"),
            @ApiImplicitParam(name = "isDetails", value = "是否展示详情", required = false, dataType = "String"),
    })
    public ResultRespone collectGDComplete(@ModelAttribute GdglinfoTjDTO gdglinfoTjDTO, String isExport, String isDetails, HttpServletResponse response) {
        return ResultRespone.success(gdglinfoService.collectGDComplete(gdglinfoTjDTO, isExport, isDetails, response));
    }

    /**
     * 工单汇总情况
     *
     * @param gdglinfoTjDTO 参数实体
     * @return 汇总数据
     */
    @GetMapping("/collectGdIndex")
    @ApiOperation(value = "三层次--工单汇总数据")
    public ResultRespone collectGdIndex(GdglinfoTjDTO gdglinfoTjDTO) {
        return ResultRespone.success(gdglinfoService.collectGdIndex(gdglinfoTjDTO));
    }

    /**
     * 工单报单总数
     *
     * @param page
     * @param gdglinfoTjDTO
     * @return
     */
    @GetMapping("/collectGdAll")
    @ApiOperation(value = "三层次--查看工单报单总数")
    public ResultRespone collectGdAll(Page page, GdglinfoDTO gdglinfoTjDTO) {
        return ResultRespone.success(gdglinfoService.collectGdAll(page, gdglinfoTjDTO));
    }

    /**
     * 点击工单汇总数据展示具体工单数
     *
     * @param gdglinfoDTO 参数实体
     * @return 汇总数据
     */
    @GetMapping("/collectGdInfo")
    @ApiOperation(value = "三层次--点击工单汇总数据展示具体工单数")
    public ResultRespone collectGdInfo(GdglinfoDTO gdglinfoDTO) {
        return ResultRespone.success(gdglinfoService.collectGdInfoDetail(gdglinfoDTO));
    }

    @GetMapping("/collectInfoByJgcz")
    @ApiOperation(value = "三层次--结果处置--汇总数据")
    public ResultRespone collectInfoByJgcz(GdglinfoDTO gdglinfoDTO) {
        return ResultRespone.success(gdglinfoService.collectInfoByJgcz(gdglinfoDTO));
    }

    @GetMapping("/collectInfoByJgsh")
    @ApiOperation(value = "三层次--结果审核--汇总数据")
    public ResultRespone collectInfoByJgsh(GdglinfoDTO gdglinfoDTO) {
        return ResultRespone.success(gdglinfoService.collectInfoByJgsh(gdglinfoDTO));
    }

    @GetMapping("/collectDetails")
    @ApiOperation(value = "三层次--工单汇总详情列表查看")
    public ResultRespone collectDetails(Page page, GdglinfoDTO gdglinfoDTO) {
        return ResultRespone.success(gdglinfoService.gdCollectDetails(page, gdglinfoDTO));
    }
//    @GetMapping("/collectDetailsByJgcz")
//    @ApiOperation(value = "三层次--结果处置--工单汇总详情列表查看")
//    public ResultRespone collectDetailsByJgcz(Page page , GdglinfoDTO gdglinfoDTO) {
//        return ResultRespone.success(gdglinfoService.collectDetailsByJgcz(page , gdglinfoDTO));
//    }


    /**
     * 工单统计查询详情信息
     * 默认统计时间当前时间往前推一个月
     */
    @GetMapping("/gdinfo")
    @ApiOperation(value = "工单统计查询详情信息，默认统计时间当前时间往前推一个月")
    public ResultRespone gdInfoPage(Page page, @ModelAttribute GdglinfoDTO gdglinfoDTO, String templateFlag, HttpServletResponse response) {

        return ResultRespone.success(gdglinfoService.gdStatisticsInfo(page, gdglinfoDTO, templateFlag, response));
    }


    /**
     * 根据比例抽取数据，开始时间结束时间差小于7天
     *
     * @param timeDTO 时间
     * @param bl      比例
     * @return
     */
    @GetMapping("/gdSpotCheck")
    @ApiOperation(value = "根据比例抽取数据，开始时间结束时间差小于7天")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bl", value = "比例", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "isRxlx", value = "工单是否是热线类型 1是", required = false, dataType = "Integer")
    })
    public ResultRespone gdSpotCheck(Page page, @ModelAttribute DateTimeDTO timeDTO, Integer bl, Integer isRxlx) {

        if (timeDTO.getStartTime() != null && timeDTO.getEndTime() != null) {
            if ((timeDTO.getEndTime().getTime() - timeDTO.getStartTime().getTime()) / (1000 * 60 * 60) > 24) {
                return ResultRespone.failed("时间范围大于1天");
            }
        }
        if (timeDTO.getEndTime() != null && DateUtils.getAllDay().getTime() < timeDTO.getEndTime().getTime()) {
            return ResultRespone.failed("截止时间不能大于等于当前时间零点");
        }
        if (bl == null || bl < 0 || bl > 100) {
            return ResultRespone.failed("比例范围越界");
        }
        return ResultRespone.success(gdglinfoService.spotCheckInfo(page, timeDTO, bl, isRxlx));
    }


    /**
     * 工单分析根据时间类型统信息展示
     */
    @GetMapping("/orderAnalysisDetails")
    @ApiOperation(value = "工单分析根据时间类型统信息展示")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "time", value = "日期", required = false, dataType = "String")
    })
    public ResultRespone orderAnalysisDetails(String time) {
        Map map = new HashMap();
        try {
            map.put("time", StringUtil.isEmpty(time) ? null : DateUtils.parseCurrentDate(time));
        } catch (ParseException e) {
            ResultRespone.failed("time 格式错误!");
        }
        return ResultRespone.success(gdglinfoService.orderAnalysisDetails(map));
    }

    /**
     * 统计这个月完成的工单数
     */
    @GetMapping("/monthCount")
    @ApiOperation(value = "统计这个月完成的工单数")
    public ResultRespone monthCount() {
        return ResultRespone.success(gdglinfoService.monthCount());
    }

    /**
     * 工单分析根据“时间和工单类型”统信息展示
     */
    @GetMapping("/orderAnalysisByTimeAndType")
    @ApiOperation(value = "工单分析根据“时间和工单类型”统信息展示")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "time", value = "日期", required = false, dataType = "String"),
            @ApiImplicitParam(name = "type", value = "工单类型", required = false, dataType = "Long")
    })
    public ResultRespone orderAnalysisByTimeAndType(Page page, String time, Long type) {
        Map map = new HashMap();
        map.put("time", StringUtil.isEmpty(time) ? null : time);
        map.put("type", type);
        return ResultRespone.success(gdglinfoService.orderAnalysisByTimeAndType(page, map));
    }


    /**
     * 业务工单统计入口
     */
    @GetMapping("/classificationStatistics")
    @ApiOperation(value = "业务工单统计入口")
    public ResultRespone classificationStatistics() {
        ClassificationStatisticsVO statisticsVO = gdglinfoService.classificationStatistics();
        return ResultRespone.success(statisticsVO);
    }

    /**
     * 接单即将超时提醒
     */
    @GetMapping("/timeoutAnalysis")
    @ApiOperation(value = "接单即将超时提醒")
    public ResultRespone timeoutAnalysis() {
        gdglinfoService.timeoutAnalysis();
        return ResultRespone.success();
    }

    /**
     * 归集管理第一层
     */
    @GetMapping("/collectionManagementOne")
    @ApiOperation(value = "归集管理第一层")
    public ResultRespone collectionManagementOne(Page page, @ModelAttribute Gdglinfo gdglinfo) {
        return ResultRespone.success(gdglinfoService.summarizeNumber(page, gdglinfo));
    }

    /**
     * 归集管理第二层
     */
    @GetMapping("/collectionManagementTwo")
    @ApiOperation(value = "归集管理第二层")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "gdly", value = "工单来源", required = false, dataType = "Long")
    })
    public ResultRespone collectionManagementTwo(Page page, Long gdly) {
        Map map = new HashMap();
        map.put("gdly", gdly);
        return ResultRespone.success(gdglinfoService.collectionManagementTwo(page, map));
    }


    /**
     * 归集管理第三层
     */
    @GetMapping("/collectionManagementThree")
    @ApiOperation(value = "归集管理第三层")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "gdly", value = "工单来源", required = false, dataType = "Long"),
            @ApiImplicitParam(name = "gdlx", value = "工单类型", required = false, dataType = "String")
    })
    public ResultRespone collectionManagementThree(Page page, Long gdly, String gdlx) {
        Map map = new HashMap();
        map.put("gdly", gdly);
        map.put("gdlx", StringUtil.isEmpty(gdlx) ? null : gdlx);
        return ResultRespone.success(gdglinfoService.collectionManagementThree(page, map));
    }

    /**
     * 水表拆换
     */
    @GetMapping("/waterMeterConversion")
    @ApiOperation(value = "表务模块需要的数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startTime", value = "开始日期 yyyy-MM-dd HH:mm:ss", required = false, dataType = "String"),
            @ApiImplicitParam(name = "endTime", value = "结束日期 yyyy-MM-dd HH:mm:ss", required = false, dataType = "String"),
            @ApiImplicitParam(name = "id", value = "工单类型", required = false, dataType = "Long"),
            @ApiImplicitParam(name = "type", value = "类型出库、争议检定", required = false, dataType = "Long"),
            @ApiImplicitParam(name = "status", value = "表务模块使用；1：已完成；0未完成（如：出库或者检定）", required = false, dataType = "String")
    })
    public ResultRespone waterMeterConversion(Page page, String startTime, String endTime, Long id, Long type, String status) {
        Date stTime = null;
        Date enTime = null;
        try {
            if (StringUtils.isNotEmpty(startTime)) {
                stTime = DateUtils.parseCurrentDateTime(startTime);
            }
            if (StringUtils.isNotEmpty(endTime)) {
                enTime = DateUtils.parseCurrentDateTime(endTime);
            }
        } catch (Exception e) {
            return ResultRespone.failed(e);
        }
        return ResultRespone.success(gdglinfoService.getListWater(page, id, type, status, stTime, enTime));
    }

    /**
     * 根据热线编号(工单编号)获取抢维修编码
     */
    @GetMapping("/getRepairreOrderCode")
    @ApiOperation(value = "根据热线编号(工单编号)获取抢维修编码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "gdbh", value = "热线编号(工单编号)", required = true, dataType = "Long")

    })
    public ResultRespone getRepairreOrderCode(String gdbh) {
        List<GdglCirculation> list = gdglCirculationService.list(new QueryWrapper<GdglCirculation>().lambda().eq(GdglCirculation::getGdbh, gdbh));
        if (null != list && list.size() > 0) {
            return ResultRespone.success(list.get(0).getOtherBh());
        }
        return ResultRespone.success("查询为空");
    }


    @PostMapping("/updateGdbhGdByExcel")
    @ApiOperation(value = "根据Excel内提供的工单编号修改工单归档")
    public Map updateGdbhGdByExcel(MultipartFile multipartFile) {
        return gdglinfoService.updateGdbhGdByExcel(multipartFile);
    }


    @GetMapping("/getAuxiliarySingleGdinfoNum")
    @ApiOperation(value = "获取用户部门今天已签到的所有用户最新位置信息列表及用户待办工单数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deptIds", value = "部门id（多个用,分隔）", required = false, dataType = "String"),
            @ApiImplicitParam(name = "flag", value = "是否获取所有部门人员 1是", required = false, dataType = "String"),
    })
    public ResultRespone<List<AuxiliarySingleVo>> getAuxiliarySingleGdinfoNum(@RequestParam(value = "deptIds", required = false) String deptIds, @RequestParam(value = "flag", required = false) String flag) {
        // 获取用户最新经纬度坐标信息
        List<AuxiliarySingleVo> auxiliarySingleVoList = orderClient.getAuxiliarySingle(deptIds, flag).getResult();
        // 需要获取工单数量用户id列表
        Set<Long> userIdSet = auxiliarySingleVoList.stream().map(AuxiliarySingleVo::getUserId).collect(Collectors.toSet());
        StringBuilder stringBuilder = new StringBuilder();
        userIdSet.forEach(info -> {
            stringBuilder.append(info).append(Constant.CSV);
        });
        String users = stringBuilder.deleteCharAt(stringBuilder.length() - 1).toString();
        // 获取结果审核中符合的工单id
        Map<Long, Set<Long>> map1 = new HashMap<>(12);

        List<Audit> result = auditClient.getAuditInfoList(users, AuditEnum.GD_TYPE.getCode(), AuditEnum.AUDIT_UNCOMMITTED.getCode()).getResult();
        if (null != result && result.size() > 0) {
            Map<Long, List<Audit>> collect = result.stream().collect(Collectors.groupingBy(Audit::getAuditUser));
            collect.forEach((k, v) -> {
                map1.put(k, result.stream().map(Audit::getAuditPlanId).collect(Collectors.toSet()));
            });
        }

        Map<Long, Set<Long>> map2 = new HashMap<>(12);
        // 获取结果处置中符合的工单id
        List<Resultdisp> resultdispList = resultdispService.list(Wrappers.<Resultdisp>lambdaQuery()
                .in(Resultdisp::getPersonId, userIdSet).eq(Resultdisp::getIsFinish, "0").select(Resultdisp::getGdbh, Resultdisp::getPersonId));
        if (StringUtil.isNotNull(resultdispList) && resultdispList.size() > 0) {
            Map<Long, Set<String>> map = new HashMap<>(12);
            Map<Long, List<Resultdisp>> collect1 = resultdispList.stream().filter(r -> null != r.getPersonId()).collect(Collectors.groupingBy(Resultdisp::getPersonId));
            collect1.forEach((k, v) -> {
                map.put(k, v.stream().map(Resultdisp::getGdbh).collect(Collectors.toSet()));
            });
            map.forEach((k, v) -> {
                map2.put(k, gdglinfoService.list(new QueryWrapper<Gdglinfo>().lambda().in(Gdglinfo::getGdbh, v).select(Gdglinfo::getId)).stream().map(Gdglinfo::getId).collect(Collectors.toSet()));
            });

        }
        Map<Long, Set<Long>> map3 = new HashMap<>(12);
        // 获取其他流程节点用户对应处理的工单
        List<OrderUserDealNumVo> orderUserDealNum = gdglinfoService.getOrderUserDealNum();
        Map<Long, List<OrderUserDealNumVo>> collect = orderUserDealNum.stream().collect(Collectors.groupingBy(OrderUserDealNumVo::getPresentPerson));
        collect.forEach((k, v) -> {
            map3.put(k, v.stream().map(OrderUserDealNumVo::getId).collect(Collectors.toSet()));
        });
        // 处理map对应工单个数
        auxiliarySingleVoList.forEach(info -> {
            Long userId = info.getUserId();
            Set<Long> longSet1 = map1.get(userId) == null ? new HashSet<>() : map1.get(userId);
            Set<Long> longSet2 = map2.get(userId) == null ? new HashSet<>() : map2.get(userId);
            Set<Long> longSet3 = map3.get(userId) == null ? new HashSet<>() : map3.get(userId);
            longSet1.addAll(longSet2);
            longSet1.addAll(longSet3);
            info.setGdNum((long) longSet1.size());
        });

        return ResultRespone.success(auxiliarySingleVoList);
    }

}
