package com.zcloud.safetyDutyList.persistence.repository.impl.tasklist;

import com.alibaba.cola.dto.PageResponse;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jjb.saas.framework.repository.common.PageHelper;
import com.jjb.saas.framework.repository.repo.impl.BaseRepositoryImpl;
import com.zcloud.gbscommon.utils.Query;
import com.zcloud.safetyDutyList.persistence.dataobject.tasklist.TaskListIssueDO;
import com.zcloud.safetyDutyList.persistence.mapper.tasklist.TaskListIssueMapper;
import com.zcloud.safetyDutyList.persistence.repository.tasklist.TaskListIssueRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
@RequiredArgsConstructor
public class TaskListIssueRepositoryImpl extends BaseRepositoryImpl<TaskListIssueMapper, TaskListIssueDO> implements TaskListIssueRepository {

    private final TaskListIssueMapper taskListIssueMapper;

    @Override
    public PageResponse<TaskListIssueDO> listPage(Map<String, Object> params, String menuPath) {
        IPage<TaskListIssueDO> iPage = new Query<TaskListIssueDO>().getPage(params);
        IPage<TaskListIssueDO> result = taskListIssueMapper.listPage(iPage, params, menuPath);
        return PageHelper.pageToResponse(result, result.getRecords());
    }

    @Override
    public PageResponse<TaskListIssueDO> listPage(Map<String, Object> params) {
        IPage<TaskListIssueDO> iPage = new Query<TaskListIssueDO>().getPage(params);
        IPage<TaskListIssueDO> result = taskListIssueMapper.listPage(iPage, params, "");
        return PageHelper.pageToResponse(result, result.getRecords());
    }

    @Override
    public TaskListIssueDO getByTaskIssueId(String taskIssueId) {
        return taskListIssueMapper.getByTaskIssueId(taskIssueId);
    }

    @Override
    public List<TaskListIssueDO> listByTaskListId(String taskListId) {
        return taskListIssueMapper.listByTaskListId(taskListId);
    }

    @Override
    public List<TaskListIssueDO> listByIssueInfo(String taskListId, Long executeCorpId, Long executeDepartmentId, Long executeUserId,
                                                  java.time.LocalDateTime periodStartTime, java.time.LocalDateTime periodEndTime) {
        return taskListIssueMapper.listByIssueInfo(taskListId, executeCorpId, executeDepartmentId, executeUserId, periodStartTime, periodEndTime);
    }

    @Override
    public List<TaskListIssueDO> listExpiredInProgress() {
        return taskListIssueMapper.listExpiredInProgress();
    }

    @Override
    public List<TaskListIssueDO> listIssuedWithPeriod() {
        return taskListIssueMapper.listIssuedWithPeriod();
    }

    @Override
    public long countByExecuteUserId(Long executeUserId) {

        QueryWrapper<TaskListIssueDO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("execute_user_id", executeUserId);
        queryWrapper.eq("delete_enum", "FALSE");
        return taskListIssueMapper.selectCount(queryWrapper);
    }
}
