package com.yeejoin.amos.patrol.business.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
import com.yeejoin.amos.boot.biz.common.utils.DateUtils;
import com.yeejoin.amos.boot.module.common.api.feign.EquipFeignClient;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import com.yeejoin.amos.patrol.business.constants.XJConstant;
import com.yeejoin.amos.patrol.business.dao.mapper.CheckMapper;
import com.yeejoin.amos.patrol.business.dao.mapper.PlanTaskMapper;
import com.yeejoin.amos.patrol.business.dao.mapper.PointMapper;
import com.yeejoin.amos.patrol.business.dao.repository.ESPlanTaskList;
import com.yeejoin.amos.patrol.business.dao.repository.ICheckInputDao;
import com.yeejoin.amos.patrol.business.dto.CheckDto;
import com.yeejoin.amos.patrol.business.dto.SendToMsgRiskAlarmInfoVo;
import com.yeejoin.amos.patrol.business.dto.SendToMsgRiskDetailVo;
import com.yeejoin.amos.patrol.business.dto.SendToMsgRiskEquipInfoVo;
import com.yeejoin.amos.patrol.business.dto.TopicEntityVo;
import com.yeejoin.amos.patrol.business.param.CheckInfoPageParam;
import com.yeejoin.amos.patrol.business.param.CheckInputParam;
import com.yeejoin.amos.patrol.business.param.CheckRecordParam;
import com.yeejoin.amos.patrol.business.param.CheckStatisticalParam;
import com.yeejoin.amos.patrol.business.service.intfc.ICheckService;
import com.yeejoin.amos.patrol.business.service.intfc.IMessageService;
import com.yeejoin.amos.patrol.business.service.intfc.IPlanTaskService;
import com.yeejoin.amos.patrol.business.service.intfc.IPointService;
import com.yeejoin.amos.patrol.business.service.intfc.ISafety3DDataSendService;
import com.yeejoin.amos.patrol.business.util.CheckPageParamUtil;
import com.yeejoin.amos.patrol.business.util.CheckParamUtil;
import com.yeejoin.amos.patrol.business.util.CommonResponse;
import com.yeejoin.amos.patrol.business.util.CommonResponseUtil;
import com.yeejoin.amos.patrol.business.util.DaoCriteria;
import com.yeejoin.amos.patrol.business.util.FileHelper;
import com.yeejoin.amos.patrol.business.util.ResponseHelperUtil;
import com.yeejoin.amos.patrol.business.util.Toke;
import com.yeejoin.amos.patrol.business.util.ToolUtils;
import com.yeejoin.amos.patrol.business.vo.CheckAnalysisVo;
import com.yeejoin.amos.patrol.business.vo.CheckInfoVo;
import com.yeejoin.amos.patrol.common.enums.PlanTaskFinishStatusEnum;
import com.yeejoin.amos.patrol.common.enums.PlanTaskTypeStatusEnum;
import com.yeejoin.amos.patrol.core.async.AsyncTask;
import com.yeejoin.amos.patrol.core.common.request.CommonPageable;
import com.yeejoin.amos.patrol.core.common.request.CommonRequest;
import com.yeejoin.amos.patrol.core.common.response.AppCheckInputRespone;
import com.yeejoin.amos.patrol.core.common.response.AppPointCheckRespone;
import com.yeejoin.amos.patrol.core.common.response.GraphInitDataResponse;
import com.yeejoin.amos.patrol.core.enums.QueryOperatorEnum;
import com.yeejoin.amos.patrol.core.util.DateUtil;
import com.yeejoin.amos.patrol.core.util.StringUtil;
import com.yeejoin.amos.patrol.dao.entity.*;
import com.yeejoin.amos.patrol.feign.RemoteSecurityService;
import com.yeejoin.amos.patrol.mqtt.WebMqttComponent;
import com.yeejoin.amos.patrol.quartz.JobService;
import com.yeejoin.amos.patrol.utils.UserTransmittableUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.scheduling.annotation.Async;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StopWatch;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel;

import javax.servlet.http.HttpServletResponse;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@RestController
@RequestMapping(value = "/api/check")
@Api(tags = "巡检记录api")
public class CheckController extends AbstractBaseController {
    private final Logger log = LoggerFactory.getLogger(CheckController.class);

    @Autowired
    private ICheckService checkService;

    @Autowired
    private IPointService iPointService;

    @Autowired
    private AsyncTask asyncTask;


    @Autowired
    private EquipFeignClient equipFeign;

    @Autowired
    private IPlanTaskService planTaskService;

    @Autowired
    private ISafety3DDataSendService is;

    @Autowired
    private RemoteSecurityService remoteSecurityService;

    @Autowired
    private IMessageService messageService;

    @Value("${windows.img.path}")
    private String winImgPath;

    @Value("${linux.img.path}")
    private String linuxImgPath;

//    @Value("${file.ip}")
//    private String fileIp;
//
//    @Value("${file.port}")
//    private String filePort;
    
//    @Value("${file.url}")
//    private String fileUrl;
    
    @Value("${amosRefresh.patrol.topic}")
    private String patrolTopic;
    @Autowired
    private WebMqttComponent webMqttComponent;

    @Value("${patrol.message.create.topic}")
    private String patrolRiskCreateTopic;

    @Value("${patrol.center.risk.topic}")
    private String riskTopic;

    @Autowired
    private CheckMapper checkMapper;

    @Autowired
    private ICheckInputDao checkInputDao;

    @Autowired
    PointMapper pointMapper;

    @Autowired
    JobService jobService;

    private String P_STATIC_DAY = "p_static_day";

    private String P_STATIC_MONTH = "p_static_month";

    private String P_STATIC_WEEK = "p_static_week";


    @Autowired
    PlanTaskMapper planTaskMapper;
    /**
     *
     * 巡查记录列表
     * **/

    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "巡检记录查询", notes = "巡检记录查询")
    @RequestMapping(value = "/listNew", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    public CommonResponse qryCheckInfoPageNew(
            @ApiParam(value = "查询条件", required = false) @RequestBody(required = false) CheckInfoPageParam param,
            @ApiParam(value = "分页参数", required = true) CommonPageable commonPageable) {
        ReginParams reginParams = getSelectedOrgInfo();
        param.setOrderBy("checkDate desc");
        param.setBizOrgCode(ObjectUtils.isEmpty(param.getBizOrgCode()) ?
                "3".equals(param.getIsOK()) ? null : reginParams.getPersonIdentity().getBizOrgCode()
                : param.getBizOrgCode());
        if(commonPageable !=null){
            param.setPageNumber(commonPageable.getPageNumber()-1);
            param.setPageSize(commonPageable.getPageSize());
        }

        Page<CheckInfoVo> list = checkService.getCheckInfoNew(null,null,null,param);
        return CommonResponseUtil.success(list);
    }







    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "巡检记录查询", notes = "巡检记录查询")
    @RequestMapping(value = "/listXNew", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    public CommonResponse qryCheckInfoPageNew(
            @ApiParam(value = "查询条件", required = false) @RequestBody(required = false) List<CommonRequest> queryRequests,
            @ApiParam(value = "分页参数", required = true) CommonPageable commonPageable) {
        ReginParams reginParams = getSelectedOrgInfo();

        HashMap<String, Object> paramMap = new HashMap<>();
        paramMap.put("bizOrgCode", reginParams.getPersonIdentity().getBizOrgCode());

        CheckInfoPageParam param = CheckPageParamUtil.fillCheckInfoParam(queryRequests, commonPageable, paramMap);
        if (ObjectUtils.isEmpty(param.getOrderBy())) {
            param.setOrderBy("checkDate desc");
        }
        Page<CheckInfoVo> list = checkService.getCheckInfoNew(null,null,null,param);
        return CommonResponseUtil.success(list);
    }

    @Deprecated
    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "一键提交巡检任务", notes = "一键提交巡检任务<font color='blue'>手机app</font>")
    @RequestMapping(value = "/saveRecordAll2", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    public ResponseModel<Object> saveCheckRecordAll(@RequestParam String ids) {
        String userId = RequestContext.getExeUserId();
        try {
            // 查询数据库和es 单线程串行执行
            UserTransmittableUtils.setUser();
            planTaskService.handleAllBatch(ids, userId);
        } catch (Exception e) {
            return ResponseHelperUtil.buildErrorResponse("提交失败:"+e.getMessage());
        } finally {
            UserTransmittableUtils.clear();
        }
        return ResponseHelper.buildResponse("提交成功");
    }

    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "一键提交巡检任务", notes = "一键提交巡检任务<font color='blue'>手机app</font>")
    @RequestMapping(value = "/saveRecordAll", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    public ResponseModel<Object> saveCheckRecordAll2(@RequestParam String ids) {
        String userId = RequestContext.getExeUserId();
        try {
            // 查询数据库和es 多线程并行执行
            UserTransmittableUtils.setUser();
            planTaskService.handleAllBatch2(ids, userId);
        } catch (Exception e) {
            return ResponseHelperUtil.buildErrorResponse("提交失败:"+e.getMessage());
        } finally {
            UserTransmittableUtils.clear();
        }
        return ResponseHelper.buildResponse("提交成功");
    }

    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "保存巡检记录<font color='blue'>手机app</font>", notes = "保存巡检记录<font color='blue'>手机app</font>")
    @RequestMapping(value = "/saveRecordNew", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    public ResponseModel<Object> saveCheckRecordNew(
            @ApiParam(value = "检查信息", required = false) @RequestBody(required = true) CheckRecordParam requestParam) {
        int statu = -1;
        PlanTask planTask = planTaskService.selectPlanTaskStatus(requestParam.getPlanTaskId());
        log.info("手机app保存巡检记录++++++++++++++++++++++: {}", JSON.toJSONString(requestParam));

        AgencyUserModel user = getUserInfo();
        String userId = user.getUserId();
        String realName = user.getRealName();
        requestParam.setUserId(userId);
        requestParam.setUserName(realName);
        try {
            if (planTask != null) {
                if (!ToolUtils.transBeanList(planTask.getUserId()).contains(userId.toString())) {
                    return ResponseHelper.buildResponse("无权执行该任务");
                }

                statu = planTask.getFinishStatus();
                if( statu == PlanTaskFinishStatusEnum.FINISHED.getValue()){
                    return ResponseHelper.buildResponse("任务已完成！");
                }

                Date checkTime = new Date();
                Date beginTime = DateUtil.getLongDate(planTask.getBeginTime());
                Date endTime = DateUtil.getLongDate(planTask.getEndTime());
                int beginCompareTo = checkTime.compareTo(beginTime);
                int endCompareTo = checkTime.compareTo(endTime);
                if(beginCompareTo < 0 || endCompareTo > 0){
                    return ResponseHelper.buildResponse("请在计划时间内完成任务！");
                }
            }
            int count = checkService.checkHasRecord(requestParam);
            if (count < 1) {
                //准备es数据
                ESTaskDetailDto esTaskDetailDto = checkService.buildEsDetailData(requestParam, planTask);
                ESPlanTaskListDto esPlanTaskListDto = checkService.buildEsTaskData(requestParam.getPlanTaskId(),esTaskDetailDto);
                // 更新 es 数据
                checkService.saveMustData(esTaskDetailDto, esPlanTaskListDto, planTask);
                // 更新数据库巡检数据及es的统计汇总信息
                CheckDto checkDto = checkService.saveCheckRecordNew(requestParam, planTask);
                return ResponseHelper.buildResponse("ok");
            } else {
                return ResponseHelperUtil.buildErrorResponse("无需重新巡检");
            }
        } catch (Exception e) {
            e.printStackTrace();
            // TODO Auto-generated catch block
            log.error(e.getMessage());
            return ResponseHelperUtil.buildErrorResponse("数据提交失败");
        }
    }

    /**
     * 巡检组装发送风险消息
     * @param
     */
    public void publishDataToMessage(List<Map<String, Object>> checkInputItems) {
        for (Map<String, Object> map : checkInputItems) {
            SendToMsgRiskDetailVo detailVo = new SendToMsgRiskDetailVo();
            SendToMsgRiskEquipInfoVo equipInfoVo = new SendToMsgRiskEquipInfoVo();
            SendToMsgRiskAlarmInfoVo alarmInfoVo = new SendToMsgRiskAlarmInfoVo();
            if (map.containsKey("equipId") && !map.get("input_value").equals("合格") ){
                equipFeign.updateEquipSpecificStatus("1",map.get("equipId").toString(),map.get("traceId").toString(),"patrol");
                equipInfoVo.setEquipSpeId(String.valueOf(map.get("equipId")));
                equipInfoVo.setReportIsAlarm(Boolean.TRUE);
            }
            equipInfoVo.setId(String.valueOf(map.get("id")));
            equipInfoVo.setName(String.valueOf(map.get("inputItem")));
            equipInfoVo.setValue(String.valueOf(map.get("input_value")));
            equipInfoVo.setCode(String.valueOf(map.get("item_no")));
            equipInfoVo.setBizOrgCode(String.valueOf(map.get("biz_org_code")));
            equipInfoVo.setBizOrgName(String.valueOf(map.get("biz_org_name")));
            if (map.containsKey("traceId")){
            equipInfoVo.setTraceId(map.get("traceId").toString());
            }

            Map<String, Object> pointMap = pointMapper.getPointById(Long.valueOf(String.valueOf(map.get("pointId"))));
            alarmInfoVo.setIndexNo(String.valueOf(pointMap.get("id")));
            alarmInfoVo.setName(String.valueOf(pointMap.get("pointName")));
            alarmInfoVo.setIndexNo(String.valueOf(pointMap.get("pointNo")));
            alarmInfoVo.setKey(String.valueOf(map.get("inputItem")));
            alarmInfoVo.setValue(String.valueOf(map.get("input_value")));

            TopicEntityVo topicEntityVo = new TopicEntityVo();
            topicEntityVo.setTopic(riskTopic);
            detailVo.setEquipInfo(equipInfoVo);
            detailVo.setAlarmInfo(alarmInfoVo);
            topicEntityVo.setData(JSON.toJSONString(detailVo));
            try {
                webMqttComponent.publish(patrolRiskCreateTopic, JSON.toJSONString(topicEntityVo));
            } catch (Exception e) {
                log.error("推送失败-----------" + e.getMessage());
            }
        }
    }

    /**
     * 巡检计划查询
     *
     * @param
     * @param
     * @return
     */
    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "巡检记录查询", notes = "巡检记录查询")
    @RequestMapping(value = "/list", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    public CommonResponse qryCheckInfoPage(
            @ApiParam(value = "查询条件", required = false) @RequestBody(required = false) List<CommonRequest> queryRequests,
            @ApiParam(value = "分页参数", required = true) CommonPageable commonPageable) {
    	ReginParams reginParams = getSelectedOrgInfo();
        String orgCode = getOrgCode(reginParams);

        String roleTypeName = getRoleTypeName(reginParams);
        HashMap<String, Object> paramMap = buildMybatisCriterias(orgCode, roleTypeName);
//        String departmentId=getDepartmentId(reginParams);
//        if(!XJConstant.ROLE_NAME_PERSON.equals(roleTypeName)){
//            paramMap.put("departmentId",departmentId);
//        }else{
//            paramMap.put("departmentId",departmentId);
//        }
        CheckInfoPageParam param = CheckPageParamUtil.fillCheckInfoParam(queryRequests, commonPageable, paramMap);
        if (ObjectUtils.isEmpty(param.getOrderBy())) {
            param.setOrderBy("checkDate desc");
        }
        Page<CheckInfoVo> list = checkService.getCheckInfo(getToken(),getProduct(),getAppKey(),param);
        return CommonResponseUtil.success(list);
    }

    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "导出巡检记录", notes = "导出巡检记录")
    @PostMapping(value = "/export",produces = "application/vnd.ms-excel;charset=UTF-8")
    public void exportCheck(
            @ApiParam(value = "查询条件", required = false) @RequestBody(required = false) List<CommonRequest> queryRequests,
            HttpServletResponse response) {
    	ReginParams reginParams = getSelectedOrgInfo();
        String orgCode = getOrgCode(reginParams);
        String roleTypeName = getRoleTypeName(reginParams);
        HashMap<String, Object> paramMap = buildMybatisCriterias(orgCode, roleTypeName);
        CheckInfoPageParam param = CheckPageParamUtil.fillCheckInfoParam(queryRequests, null, paramMap);
        param.setPageSize(-1);
        param.setOrderBy("checkDate DESC");
        List<CheckInfoVo> list = checkService.getCheckInfoList(getToken(),getProduct(),getAppKey(),param);
        String fileName = "巡检记录" + new Date().getTime();
        FileHelper.exportExcel(list, "巡检记录", "巡检记录", CheckInfoVo.class, fileName + ".xls", response);
//        List<Long> idsList = checkService.getAllIdsByConditions(param);
//        if (!CollectionUtils.isEmpty(idsList)) {
//            List<CheckInfoVo> list = checkService.getSelectedCheckInfoList(idsList.toArray(new Long[idsList.size()]));
//            this.userDeptNameConver(list);
//            String fileName = "巡检记录" + System.currentTimeMillis();
//            FileHelper.exportExcel(list, "巡检记录", "巡检记录", CheckInfoVo.class, fileName + ".xls", response);
//        }

    }

    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "导出巡检记录", notes = "导出巡检记录")
    @RequestMapping(value = "/exportSelectRecord", method = RequestMethod.GET)
    public void exportSelectCheckRecord(
            @ApiParam(value = "查询条件", required = false) @RequestParam(required = false) Long[] ids,
            HttpServletResponse response) {
        List<CheckInfoVo> list = checkService.getSelectedCheckInfoList(getToken(),getProduct(),getAppKey(),ids);
        String fileName = "巡检记录" + new Date().getTime();
        FileHelper.exportExcel(list, "巡检记录", "巡检记录", CheckInfoVo.class, fileName + ".xls", response);
    }

    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "导出巡检记录图片", notes = "导出巡检记录图片")
    @RequestMapping(value = "/exportImgs", method = RequestMethod.POST)
    public void exportCheckImgs(
            @ApiParam(value = "查询条件", required = false) @RequestBody(required = false) List<CommonRequest> queryRequests,
            HttpServletResponse response) {
    	ReginParams reginParams = getSelectedOrgInfo();
        String orgCode = getOrgCode(reginParams);
        String roleTypeName = getRoleTypeName(reginParams);
        HashMap<String, Object> paramMap = buildMybatisCriterias(orgCode, roleTypeName);
        CheckInfoPageParam param = CheckPageParamUtil.fillCheckInfoParam(queryRequests, null, paramMap);
        List<Map<String, Object>> list = checkService.getCheckInfoImgsList(param);
        String fileName = "巡检记录图片" + new Date().getTime() + ".zip";
//        String rootPath = "http://" + fileIp + ":" + filePort + "/";
        for (Map<String, Object> map : list) {
//            map.put("photoData", fileUrl + map.get("photoData").toString());
            map.put("photoData", map.get("photoData").toString());
        }
        FileHelper.exportZip(list, fileName, response);
    }

    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "导出巡检记录图片", notes = "导出巡检记录图片")
    @RequestMapping(value = "/exportImgsByIds", method = RequestMethod.GET)
    public void exportCheckImgs(@ApiParam(value = "查询条件", required = false) @RequestParam(required = false) Long[] ids,
                                HttpServletResponse response) {
        List<Map<String, Object>> list = checkService.getCheckInfoImgsList(ids);
        String fileName = "巡检记录图片" + new Date().getTime() + ".zip";
//        String rootPath = "http://" + fileIp + ":" + filePort + "/";
        for (Map<String, Object> map : list) {
//            map.put("photoData", fileUrl + map.get("photoData").toString());
            map.put("photoData", map.get("photoData").toString());
        }
        FileHelper.exportZip(list, fileName, response);
    }

    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "保存巡检记录<font color='blue'>手机app</font>", notes = "保存巡检记录<font color='blue'>手机app</font>")
    @RequestMapping(value = "/saveRecord", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    public CommonResponse saveCheckRecord(
            @ApiParam(value = "检查信息", required = false) @RequestBody(required = true) CheckRecordParam requestParam) {
        Toke token  =  new Toke();
        token.setProduct(request.getHeader("product"));
        token.setToke(request.getHeader("X-Access-Token"));
        token.setAppKey(request.getHeader("appKey"));
        int statu = -1;
        PlanTask planTask =null;
        if(requestParam.getPlanTaskId()!=null && requestParam.getPlanTaskId() !=0){
       	 planTask = planTaskService.selectPlanTaskStatus(requestParam.getPlanTaskId());
        }
        AgencyUserModel user = getUserInfo();
        String userId = user.getUserId();
        String realName = user.getRealName();
        requestParam.setIsOffline(requestParam.getIsOffline()==null?false:requestParam.getIsOffline());
        try {
	        if (planTask != null) {
	            if (!ToolUtils.transBeanList(planTask.getUserId()).contains(userId.toString())) {
	                return CommonResponseUtil.failure("无权执行该任务");
	            }

	            statu = planTask.getFinishStatus();
	            if (!requestParam.getIsOffline() && statu == PlanTaskFinishStatusEnum.OVERTIME.getValue()) {
	                return CommonResponseUtil.failure("任务已超时，上传失败！");
	            }else if( statu == PlanTaskFinishStatusEnum.FINISHED.getValue()){
	            	return CommonResponseUtil.failure("任务已完成！");
	            }

	            Date checkTime = requestParam.getIsOffline()?DateUtil.getLongDate(requestParam.getCheckTime()):new Date();
	            Date beginTime = DateUtil.getLongDate(planTask.getBeginTime());
	            Date endTime = DateUtil.getLongDate(planTask.getEndTime());
	            int beginCompareTo = checkTime.compareTo(beginTime);
	            int endCompareTo = checkTime.compareTo(endTime);
	            if(beginCompareTo == -1 || endCompareTo == 1){
	            	return CommonResponseUtil.failure("请在计划时间内完成任务！");
	            }
	        }
	        int count = checkService.checkHasRecord(requestParam);
	        if (count < 1 || requestParam.getPlanTaskId() < 1) {
	        	 ReginParams reginParams = getSelectedOrgInfo();
	             String orgCode = getOrgCode(reginParams);
	             String departmentId = getDepartmentId(reginParams);
	             requestParam.setOrgCode(orgCode);
	             requestParam.setUserId(getUserId());
	             requestParam.setCheckDepartmentId(departmentId);
	             CheckDto checkDto = checkService.saveCheckRecord(requestParam,getUserInfo(),reginParams.getDepartment(),token);
	            if(StringUtil.isNotEmpty(checkDto)){
	                asyncTaskf(checkDto.getCheckId());
	            }
	            is.pointCheckInfoPushToB(checkDto.getCheckId());
	            //数字换流站页面刷新
	            try {
                    webMqttComponent.publish(patrolTopic, "");

                }catch (Exception e){
                    log.error("数字换流站页面推送失败-----------"+e.getMessage());
                }
	            return CommonResponseUtil.success(checkDto);
	        } else {
	            return CommonResponseUtil.success("无需重新巡检");
	        }
        } catch (Exception e) {
        	e.printStackTrace();
            // TODO Auto-generated catch block
        	log.error(e.getMessage());
            return CommonResponseUtil.failure("数据提交失败");
        }
    }

    @Async
    public void asyncTaskf(Long id){

    	 try {
			asyncTask.pushCheckInfoTo3D(id);
			asyncTask.pushCheckMessage(id);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

    }

    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "删除巡检记录", notes = "删除巡检记录")
    @RequestMapping(value = "/testPush", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    public CommonResponse deleteCheckById(@ApiParam(value = "巡检计划ID", required = true) @RequestBody Long id) {
        try {
        	asyncTask.pushCheckMessage(id);
            return CommonResponseUtil.success();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResponseUtil.failure("删除巡检记录失败");
        }
    }


    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "获取巡检日历数据<font color='blue'>手机app</font>", notes = "获取巡检日历数据<font color='blue'>手机app</font>")
    @PostMapping(value = "/checkCalendarNew", produces = "application/json;charset=UTF-8")
    public CommonResponse checkCalendarNew(
            @ApiParam(value = "查询条件", required = false) @RequestBody(required = false) List<CommonRequest> queryRequests) {
        try {
            ReginParams reginParams = getSelectedOrgInfo();
            // String loginOrgCode = getOrgCode(reginParams);

            String loginOrgCode =reginParams.getPersonIdentity().getBizOrgCode();
//            String roleTypeName = getRoleTypeName(reginParams);
            List<DaoCriteria> daoCriterias = buildDaoCriterias(queryRequests, false, null, null);

            DaoCriteria childCompDaoCriteria = new DaoCriteria();
            childCompDaoCriteria.setPropertyName("bizOrgCode");
            childCompDaoCriteria.setOperator(QueryOperatorEnum.LIKE.getName());
            childCompDaoCriteria.setValue(loginOrgCode);
            daoCriterias.add(childCompDaoCriteria);


            Map<String, Object> map = checkService.checkCalendar(CheckParamUtil.checkCalendar(daoCriterias));
            return CommonResponseUtil.success(map);
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResponseUtil.failure(e.getMessage());
        }

    }

    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "获取巡检日历数据<font color='blue'>手机app</font>", notes = "获取巡检日历数据<font color='blue'>手机app</font>")
    @GetMapping(value = "/checkCalendarForWx", produces = "application/json;charset=UTF-8")
    public ResponseModel<Object> checkCalendarForWx(
            @RequestParam(required = false) String checkTime,
            @RequestParam String type) {
        try {
            StopWatch stopWatch = new StopWatch();
            stopWatch.start();
            String userId = RequestContext.getExeUserId();
            ReginParams reginParams = getSelectedOrgInfo();

            String loginOrgCode = reginParams.getPersonIdentity().getBizOrgCode();
            stopWatch.stop();
            log.info("获取巡检日历数据=====> loginOrgCode time: {}", stopWatch.getTotalTimeSeconds());
            if(StringUtils.isBlank(checkTime)) {
                if(type.equals(String.valueOf(PlanTaskTypeStatusEnum.month.getName()))) {
                    checkTime = DateUtils.dateFormat(new Date(), DateUtils.YEAR_PATTERN);
                } else {
                    checkTime = DateUtils.dateFormat(new Date(), DateUtils.MONTH_PATTERN);
                }
            }
            stopWatch.start();
            Map<String, Object> map = checkService.checkCalendarNew(checkTime,loginOrgCode,String.valueOf(PlanTaskTypeStatusEnum.getValue(type)),userId);
            stopWatch.stop();
            log.info("获取巡检日历数据=====> sql map time: {}", stopWatch.getTotalTimeSeconds());
            return ResponseHelper.buildResponse(map);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseHelperUtil.buildErrorResponse(e.getMessage());
        }

    }


//    @TycloudOperation(ApiLevel = UserType.AGENCY)
//    @ApiOperation(value = "上传检查记录图片<font color='blue'>手机app</font>", notes = "上传检查记录图片<font color='blue'>手机app</font>")
//    @RequestMapping(value = "/uploadCheckImg", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
//    public CommonResponse uploadCheckImg(
//            @ApiParam(value = "检查图片", required = true) @RequestBody(required = true) MultipartFile file) {
//        CheckImgParam checkImgParam = new CheckImgParam();
//        checkImgParam.setCheckId(Long.parseLong(request.getParameter("checkId")));
//        if (!ObjectUtils.isEmpty(request.getParameter("inputItemId"))) {
//            checkImgParam.setInputItemId(Long.parseLong(request.getParameter("inputItemId")));
//        }
//        checkImgParam.setPointId(Long.parseLong(request.getParameter("pointId")));
//        checkImgParam.setName(request.getParameter("name"));
//        Point point = iPointService.queryPointById(checkImgParam.getPointId());
//       // LoginUserParam loginParam = CurUserCompanyCache.getInstance().getCurCompany(getUserId(), getToken());
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
//        ReginParams reginParams = getSelectedOrgInfo();
//		String loginOrgCode = getOrgCode(reginParams);
//        //String loginOrgCode = loginParam.getOrgCode();
//        String[] companys = loginOrgCode.split("\\*");
//
//        String path = XJConstant.UPLOAD_ROOT_PATH + File.separator + companys[companys.length - 1] + File.separator
//                + sdf.format(new Date()) + File.separator + point.getName() + File.separator
//                + checkImgParam.getCheckId();
//        String filePath = getRootPath() + path;
//        if (file.isEmpty()) {
//            return CommonResponseUtil.failure("上传文件失败");
//        }
//        String fileType = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."),
//                file.getOriginalFilename().length());
//        String fileName = ObjectUtils.isEmpty(checkImgParam.getName()) ? File.separator + file.getOriginalFilename()
//                : File.separator + checkImgParam.getName() + fileType;
//
//        try {
//            File dest = new File(filePath + File.separator + fileName);
//            if (!dest.exists()) {
//                if (dest.getParentFile() != null && !dest.getParentFile().exists()) {
//                    dest.getParentFile().mkdirs();
//                }
//                dest.createNewFile();
//            }
//            file.transferTo(dest);
//        } catch (IOException e) {
//            return CommonResponseUtil.failure("上传文件失败");
//        }
//
//        CheckShot img = new CheckShot();
//        String photoFile = path + fileName;
//        img.setPhotoData(photoFile);
//        img.setCheckId(Integer.valueOf(checkImgParam.getCheckId() + ""));
//        img.setOrgCode(loginOrgCode);
//        img.setCreateDate(new Date());
//        img.setPointName(checkImgParam.getName());
//        img.setCheckInputId(checkImgParam.getInputItemId());
//        img.setShotType("1".equals(point.getIsFixed()) ? "定点" : "普通");
//        checkService.saveCheckImg(img);
//        return CommonResponseUtil.success();
//    }
//
//    private String getRootPath() {
//        String localPath = "";
//        if ("\\".equals(File.separator)) {
//            localPath += winImgPath;
//        } else if ("/".equals(File.separator)) {
//            localPath += linuxImgPath;
//        }
//        return localPath.trim();
//    }

    /**
     * 巡检计划删除（支持批量）
     *
     * @param
     * @return
     */
    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "删除巡检记录", notes = "删除巡检记录")
    @RequestMapping(value = "/deleteCheckById", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    public CommonResponse deleteCheckById(@ApiParam(value = "巡检计划ID", required = true) @RequestBody List<Long> ids) {
        try {
            checkService.delCheckById(ids);
            return CommonResponseUtil.success();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResponseUtil.failure("删除巡检记录失败");
        }
    }





    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "获取巡检点巡检记录列表信息<font color='blue'>手机app</font>", notes = "获取巡检点巡检记录列表信息<font color='blue'>手机app</font>")
    @RequestMapping(value = "/queryCheckRecordNew", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    public CommonResponse queryRecordByPointIdNew(
            @ApiParam(value = "查询条件", required = false) @RequestBody(required = false) List<CommonRequest> queryRequests) {
        ReginParams reginParams = getSelectedOrgInfo();
//        String loginOrgCode = getOrgCode(reginParams);
//        String roleTypeName = getRoleTypeName(reginParams);
//        String departmentId = getDepartmentId(reginParams);
        HashMap<String, Object> req = CheckPageParamUtil.fillInfo(queryRequests);
        req.put("orgCode", reginParams.getPersonIdentity().getBizOrgCode());


//        if (XJConstant.ROLE_NAME_ADMIN.equals(roleTypeName.toUpperCase())
//                || XJConstant.ROLE_NAME_SUPERADMIN.equals(roleTypeName.toUpperCase())) {
//            req.put("orgCode", loginOrgCode);
//        } else if (XJConstant.ROLE_NAME_DEPTADMIN.equals(roleTypeName.toUpperCase())) {
//            req.put("departmentId",departmentId);
//        } else {
//            if(StringUtil.isNotEmpty(req.get("userId"))&&req.get("userId")==null){
//                req.put("userId", getUserId());
//            }
//        }
        Map<String, Object> map = checkService.queryRecordByPointId(req);
        return CommonResponseUtil.success(map);
    }



    /**
     * 根据检查项ID获取所有不合格检查项
     *
     * @param
     * @return
     */
    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "据检查项ID获取所有不合格检查项<font color='blue'>手机app</font>", notes = "据检查项ID获取所有不合格检查项<font color='blue'>手机app</font>")
    @RequestMapping(value = "/queryUnqualifiedInputItem", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
    public CommonResponse queryUnqualifiedInputItem(@RequestParam(required = true) int checkId) {
        try {
            List<Map> list = checkService.queryUnqualifiedInputItem(checkId);
            return CommonResponseUtil.success(list);
        } catch (Exception e) {
            return CommonResponseUtil.failure(e.getMessage());
        }

    }

    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "获取巡检计划巡检点(已完成或漏检的巡检点)详情信息<font color='blue'>手机app</font>", notes = "获取巡检计划巡检点(已完成或漏检的巡检点)详情信息<font color='blue'>手机app</font>")
    @RequestMapping(value = "/queryCheckPointDetail", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
    public CommonResponse queryCheckPointDetail(@RequestParam long checkId) {
        try {
            AppPointCheckRespone pointCheckRespone = checkService.queryCheckPointDetail(getToken(),getProduct(),getAppKey(),checkId);
            return CommonResponseUtil.success(pointCheckRespone);
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResponseUtil.failure(e.getMessage());
        }

    }

    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "获取巡检计划巡检点(已完成或漏检的巡检点)详情信息<font color='blue'>手机app</font>", notes = "获取巡检计划巡检点(已完成或漏检的巡检点)详情信息<font color='blue'>手机app</font>")
    @RequestMapping(value = "/v2/queryCheckPointDetail", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
    public CommonResponse queryCheckPointDetailInVersion2(@RequestParam long checkId) {
        try {
            AppPointCheckRespone pointCheckRespone = checkService.queryCheckPointDetailInVersion2(getToken(),getProduct(),getAppKey(),checkId, null , null);
            return CommonResponseUtil.success(pointCheckRespone);
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResponseUtil.failure(e.getMessage());
        }

    }

    /**
     * 获取巡检日历数据
     *
     * @param queryRequests
     * @return
     */
    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "获取巡检日历数据<font color='blue'>手机app</font>", notes = "获取巡检日历数据<font color='blue'>手机app</font>")
    @PostMapping(value = "/checkCalendar", produces = "application/json;charset=UTF-8")
    public CommonResponse checkCalendar(
            @ApiParam(value = "查询条件", required = false) @RequestBody(required = false) List<CommonRequest> queryRequests) {
        try {
        	ReginParams reginParams = getSelectedOrgInfo();
            String loginOrgCode = getOrgCode(reginParams);
            String roleTypeName = getRoleTypeName(reginParams);
            List<DaoCriteria> daoCriterias = buildDaoCriterias(queryRequests, true, loginOrgCode, roleTypeName);



            Map<String, Object> map = checkService.checkCalendar(CheckParamUtil.checkCalendar(daoCriterias));
            return CommonResponseUtil.success(map);
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResponseUtil.failure(e.getMessage());
        }

    }

    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "获取巡检点巡检记录列表信息<font color='blue'>手机app</font>", notes = "获取巡检点巡检记录列表信息<font color='blue'>手机app</font>")
    @RequestMapping(value = "/queryCheckRecord", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    public CommonResponse queryRecordByPointId(
            @ApiParam(value = "查询条件", required = false) @RequestBody(required = false) List<CommonRequest> queryRequests) {
         ReginParams reginParams = getSelectedOrgInfo();
         String loginOrgCode = getOrgCode(reginParams);
         String roleTypeName = getRoleTypeName(reginParams);
         String departmentId = getDepartmentId(reginParams);
        HashMap<String, Object> req = CheckPageParamUtil.fillInfo(queryRequests);
        if (XJConstant.ROLE_NAME_ADMIN.equals(roleTypeName.toUpperCase())
                || XJConstant.ROLE_NAME_SUPERADMIN.equals(roleTypeName.toUpperCase())) {
            req.put("orgCode", loginOrgCode);
        } else if (XJConstant.ROLE_NAME_DEPTADMIN.equals(roleTypeName.toUpperCase())) {
            req.put("departmentId",departmentId);
        } else {
           if(StringUtil.isNotEmpty(req.get("userId"))&&req.get("userId")==null){
              req.put("userId", getUserId());
           }
        }
        Map<String, Object> map = checkService.queryRecordByPointId(req);
        return CommonResponseUtil.success(map);
    }

    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "获取巡检记录详情信息<font color='blue'>手机app</font>", notes = "获取巡检记录详情信息<font color='blue'>手机app</font>")
    @RequestMapping(value = "/queryCheckDetail", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
    public CommonResponse queryRecordById(@RequestParam(required = true) int checkId) {
        try {
            Map<String, Object> map = checkService.queryRecordById(checkId);
            return CommonResponseUtil.success(map);
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResponseUtil.failure(e.getMessage());
        }
    }

    /**
     * 根据巡检记录ID获取巡检记录详情
     *
     * @param checkId
     * @return
     */
    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "根据巡检记录ID获取巡检记录详情", notes = "根据巡检记录ID获取巡检记录详情")
    @RequestMapping(value = "/queryCheckInfo", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
    public CommonResponse printTaskDetail(@ApiParam(value = "巡检记录ID") @RequestParam(required = true) int checkId) {
        Map<String, Object> map = checkService.queryRecordById(checkId);
        String xml = ToolUtils.map2Xml(map, "CheckInfo");
        if (ObjectUtils.isEmpty(xml)) {
            return CommonResponseUtil.failure();
        }
        InputStream inputStream = new ByteArrayInputStream(xml.getBytes());
        ;
        Source source = new StreamSource(inputStream);
        try {
            FileInputStream fis1 = new FileInputStream(
                    this.getClass().getResource("/").getPath() + "temp/checkTemplate.xsl");
            Source template = new StreamSource(fis1);
            Date date = new Date();
            String path = request.getSession().getServletContext().getRealPath("/");
            String dir = path.substring(0, path.indexOf(File.separator) + 1) + "check";
            String html = path.substring(0, path.indexOf(File.separator) + 1) + "check" + File.separator + "task_"
                    + date.getTime() + ".html";
            File dirFile = new File(dir);
            if (!dirFile.exists()) {
                dirFile.mkdirs();
            }

            Result result = new StreamResult(html);
            Transformer transformer = TransformerFactory.newInstance().newTransformer(template);

            transformer.transform(source, result);

            File htmlFile = new File(html);
            FileInputStream fis = new FileInputStream(htmlFile);
            String data = IOUtils.toString(fis, "utf-8");
            fis.close();
            if (htmlFile.exists()) {
                htmlFile.delete();
            }
            return new CommonResponse("SUCCESS", data, "查询成功");
        } catch (TransformerException | IOException e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 获取巡检点，巡检线路初始数据
     *
     * @return
     */
    //@Authorization(ingore=true)
    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "获取巡检点初始数据(<font color='blue'>release</font>)", notes = "获取巡检点初始数据")
    @RequestMapping(value = "/viewModule/initData", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public CommonResponse getViewModuleInitData() {
        try {
            GraphInitDataResponse graphInitDataResponse = checkService.getViewModuleInitData();
            return CommonResponseUtil.success(graphInitDataResponse);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage(), e);
            return CommonResponseUtil.failure();
        }
    }

    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "巡检情况统计分析", notes = "巡检情况统计分析")
    @RequestMapping(value = "/statisticalAnalysis", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public CommonResponse getCheckStatisticalAnalysis(
            @ApiParam(value = "查询条件", required = false) @RequestBody(required = false) CheckStatisticalParam queryRequests) {
    	 String userId = getUserId();
         ReginParams reginParams = getSelectedOrgInfo();
         String loginOrgCode = getOrgCode(reginParams);
         queryRequests.setOrgCode(loginOrgCode);
        List<CheckAnalysisVo> list = checkService.getCheckStatisticalAnalysis(getToken(),getProduct(),getAppKey(),queryRequests);
        return CommonResponseUtil.success(list);
    }

    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "导出巡检情况统计分析", notes = "导出巡检情况统计分析")
    @RequestMapping(value = "/exportStatisticalAnalysis", method = RequestMethod.POST, produces = "application/vnd.ms-excel;charset=UTF-8")
    public void exportStatisticalAnalysis(
            @ApiParam(value = "查询条件", required = false) @RequestBody(required = false) CheckStatisticalParam queryRequests,
            HttpServletResponse response) {
    	 String userId = getUserId();
         ReginParams reginParams = getSelectedOrgInfo();
         String loginOrgCode = getOrgCode(reginParams);
         queryRequests.setOrgCode(loginOrgCode);
        List<CheckAnalysisVo> list = checkService.getCheckStatisticalAnalysis(getToken(),getProduct(),getAppKey(),queryRequests);
        String fileName = "巡检记录" + new Date().getTime();
        FileHelper.exportExcel(list, "巡检情况统计分析\"", "巡检情况统计分析\"", CheckAnalysisVo.class, fileName + ".xls", response);
    }


    /**
     * 根据检查项ID和检查输入项ID查询图片， 如果输入项ID位0时，查询巡检现场照片， 如果不为0查询检查项照片
     *
     * @param checkId
     * @param checkInputId
     * @return
     */
    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "获取检查项照片URL(<font color='blue'>release</font>)", notes = "获取检查项照片URL")
    @RequestMapping(value = "/getCheckPic", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public CommonResponse getCheckPhotosByCheckAndInputId(
            @ApiParam(value = "巡检记录ID") @RequestParam(required = true) int checkId,
            @ApiParam(value = "检查输入项ID") @RequestParam(required = false) int checkInputId,
            @ApiParam(value = "分类ID") @RequestParam(required = false) int classifyId) {
        try {
            List<String> list = checkService.getCheckPhotosByCheckAndInputId(checkId, checkInputId,classifyId);
            return CommonResponseUtil.success(list);
        } catch (Exception e) {
            return CommonResponseUtil.failure(e.getMessage());
        }
    }

    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @RequestMapping(value = "/people/statistic", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public CommonResponse getPeopleStatistic(
            @RequestParam(required = false) String bizOrgCode,
            @RequestParam(required = false) String userId) {
        try {
            return CommonResponseUtil.success(checkService.getPeopleStatistic(bizOrgCode, userId));
        } catch (Exception e) {
            return CommonResponseUtil.failure(e.getMessage());
        }
    }

    @TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
    @RequestMapping(value = "/people/page", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public CommonResponse getPeoplePatrolPage(
            @RequestParam(required = false) String bizOrgCode,
            @RequestParam(required = false) String userId,
            int pageNumber,
            int pageSize) {
        CheckInfoPageParam param = new CheckInfoPageParam();
        param.setBizOrgCode(bizOrgCode);
        param.setUserId(userId);
        ReginParams reginParams = getSelectedOrgInfo();
        param.setOrderBy("checkDate desc");
        param.setBizOrgCode(ObjectUtils.isEmpty(param.getBizOrgCode()) ? reginParams.getPersonIdentity().getBizOrgCode() : param.getBizOrgCode());
        CommonPageable commonPageable = new CommonPageable();
        commonPageable.setPageNumber(pageNumber);
        commonPageable.setPageSize(pageSize);
        if(commonPageable !=null){
            param.setPageNumber(commonPageable.getPageNumber()-1);
            param.setPageSize(commonPageable.getPageSize());
        }

        Page<CheckInfoVo> list = checkService.getPeoplePatrolPage(param);
        return CommonResponseUtil.success(list);
    }
}
