package com.ruoyi.doubledefense.service.impl;

import java.util.Date;
import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.constant.DeletedEnum;
import com.ruoyi.doubledefense.domain.CheckTaskInventory;
import com.ruoyi.doubledefense.dto.CheckTaskInventoryStatisticsDTO;
import com.ruoyi.doubledefense.dto.CheckTaskInventoryStatisticsPCDTO;
import com.ruoyi.doubledefense.dto.res.CheckUserCountStatisticsDTO;
import com.ruoyi.doubledefense.dtoGov.CheckTaskInventoryRecordDTOGov;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.doubledefense.mapper.CheckTaskInventoryRecordMapper;
import com.ruoyi.doubledefense.domain.CheckTaskInventoryRecord;
import com.ruoyi.doubledefense.service.ICheckTaskInventoryRecordService;

/**
 * 巡查记录Service业务层处理
 *
 * @author ruoyi
 * @date 2023-08-03
 */
@Service
public class CheckTaskInventoryRecordServiceImpl extends ServiceImpl<CheckTaskInventoryRecordMapper, CheckTaskInventoryRecord> implements ICheckTaskInventoryRecordService {
    @Autowired
    private CheckTaskInventoryRecordMapper checkTaskInventoryRecordMapper;

    /**
     * 重预防汇聚计算节点
     * 查询巡检打卡记录
     *
     * @param checkTaskInventoryRecordDTOGov
     * @return
     */
    @Override
    public PageInfo<CheckTaskInventoryRecordDTOGov> govSelectCheckTaskInventoryRecordList(CheckTaskInventoryRecordDTOGov checkTaskInventoryRecordDTOGov) {
        PageHelper.startPage(checkTaskInventoryRecordDTOGov.getPageNo(), checkTaskInventoryRecordDTOGov.getPageSize());

        List<CheckTaskInventoryRecordDTOGov> govSelectCheckTaskInventoryRecordList = checkTaskInventoryRecordMapper.govSelectCheckTaskInventoryRecordList(checkTaskInventoryRecordDTOGov);
        PageInfo<CheckTaskInventoryRecordDTOGov> pageInfo = new PageInfo<>(govSelectCheckTaskInventoryRecordList);
        return pageInfo;
    }

    /**
     * 查询巡查记录
     *
     * @param id 巡查记录主键
     * @return 巡查记录
     */
    @Override
    public CheckTaskInventoryRecord selectCheckTaskInventoryRecordById(String id) {
        return checkTaskInventoryRecordMapper.selectCheckTaskInventoryRecordById(id);
    }

    /**
     * 查询巡查记录列表
     *
     * @param checkTaskInventoryRecord 巡查记录
     * @return 巡查记录
     */
    @Override
    public List<CheckTaskInventoryRecord> selectCheckTaskInventoryRecordList(CheckTaskInventoryRecord checkTaskInventoryRecord) {
        return checkTaskInventoryRecordMapper.selectCheckTaskInventoryRecordList(checkTaskInventoryRecord);
    }

    /**
     * 新增巡查记录
     *
     * @param checkTaskInventoryRecord 巡查记录
     * @return 结果
     */
    @Override
    public int insertCheckTaskInventoryRecord(CheckTaskInventoryRecord checkTaskInventoryRecord) {
        if (checkTaskInventoryRecord.getIsDel() == null)
            checkTaskInventoryRecord.setIsDel(DeletedEnum.VALID.getValue());
        if (checkTaskInventoryRecord.getCreateDate() == null)
            checkTaskInventoryRecord.setCreateDate(new Date());
        if (checkTaskInventoryRecord.getUpdateDate() == null)
            checkTaskInventoryRecord.setUpdateDate(new Date());
        return checkTaskInventoryRecordMapper.insertCheckTaskInventoryRecord(checkTaskInventoryRecord);
    }

    /**
     * 修改巡查记录
     *
     * @param checkTaskInventoryRecord 巡查记录
     * @return 结果
     */
    @Override
    public int updateCheckTaskInventoryRecord(CheckTaskInventoryRecord checkTaskInventoryRecord) {
        return checkTaskInventoryRecordMapper.updateCheckTaskInventoryRecord(checkTaskInventoryRecord);
    }

    /**
     * 批量删除巡查记录
     *
     * @param ids 需要删除的巡查记录主键
     * @return 结果
     */
    @Override
    public int deleteCheckTaskInventoryRecordByIds(String[] ids) {
        return checkTaskInventoryRecordMapper.deleteCheckTaskInventoryRecordByIds(ids);
    }

    /**
     * 删除巡查记录信息
     *
     * @param id 巡查记录主键
     * @return 结果
     */
    @Override
    public int deleteCheckTaskInventoryRecordById(String id) {
        return checkTaskInventoryRecordMapper.deleteCheckTaskInventoryRecordById(id);
    }

    /**
     * 批量添加任务清单记录表
     *
     * @param recordList
     * @return
     */
    @Override
    public int batchInsertCheckTaskInventoryRecord(List<CheckTaskInventoryRecord> recordList) {
        return checkTaskInventoryRecordMapper.batchInsertCheckTaskInventoryRecord(recordList);
    }

    /**
     * 查询分析单元下排查任务清单列表(已完成清单记录表)
     *
     * @param riskUnitId
     * @return
     */
    @Override
    public List<CheckTaskInventoryRecord> selectCheckTaskInventoryRecordListByRistUnitId(String riskUnitId, Integer status) {
        return checkTaskInventoryRecordMapper.selectCheckTaskInventoryRecordListByRistUnitId(riskUnitId, status);
    }

    /**
     * 巡检完成率
     * APP首页
     *
     * @return
     */
    @Override
    public CheckTaskInventoryStatisticsDTO checkTaskInventoryStatistics(CheckTaskInventoryRecord checkTaskInventoryRecord) {
        CheckTaskInventoryStatisticsDTO dto = checkTaskInventoryRecordMapper.checkTaskInventoryStatistics(checkTaskInventoryRecord);
        if (dto == null) {
            dto = new CheckTaskInventoryStatisticsDTO();
        }
        return dto;
    }

    /**
     * 巡检清单统计：已巡检、应巡检(总数)
     * PC首页
     *
     * @param checkTaskInventoryRecord
     * @return
     */
    @Override
    public CheckTaskInventoryStatisticsPCDTO checkTaskInventoryStatisticsPC(CheckTaskInventoryRecord checkTaskInventoryRecord) {
        CheckTaskInventoryStatisticsPCDTO dto = checkTaskInventoryRecordMapper.checkTaskInventoryStatisticsPC(checkTaskInventoryRecord);
        if (dto == null) {
            dto = new CheckTaskInventoryStatisticsPCDTO();
        }
        return dto;
    }

    /**
     * 统计巡检人数
     *
     * @param checkTimeStatr 巡检时间范围：开始时间
     * @param checkTimeEnd   巡检时间范围：结束时间
     * @return
     */
    @Override
    public List<CheckUserCountStatisticsDTO> checkUserCountStatistics(Date checkTimeStatr, Date checkTimeEnd) {
        return checkTaskInventoryRecordMapper.checkUserCountStatistics(checkTimeStatr, checkTimeEnd);
    }
}
