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.auth.model.SSOUser;
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.domain.enums.MenuEnum;
import com.zcloud.safetyDutyList.persistence.dataobject.tasklist.CorpStatisticsDO;
import com.zcloud.safetyDutyList.persistence.dataobject.tasklist.EvaluationListDO;
import com.zcloud.safetyDutyList.persistence.dataobject.tasklist.IssueStatisticsDO;
import com.zcloud.safetyDutyList.persistence.dataobject.tasklist.TaskListDO;
import com.zcloud.safetyDutyList.persistence.mapper.tasklist.TaskListMapper;
import com.zcloud.safetyDutyList.persistence.repository.tasklist.TaskListRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

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

/**
 * 清单仓储实现类
 * <p>
 * 实现清单仓储接口，委托TaskListMapper完成实际的SQL操作。
 * 继承BaseRepositoryImpl获得MyBatis-Plus的基础CRUD能力。
 */
@Service
@RequiredArgsConstructor
public class TaskListRepositoryImpl extends BaseRepositoryImpl<TaskListMapper, TaskListDO> implements TaskListRepository {

    private final TaskListMapper taskListMapper;

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

    @Override
    public TaskListDO getInfoById(Long id) {
        return taskListMapper.getInfoById(id);
    }

    @Override
    public TaskListDO getByTaskListId(String taskListId) {
        return taskListMapper.getByTaskListId(taskListId);
    }

    @Override
    public TaskListDO getInfoByTaskListId(String taskListId) {
        return taskListMapper.getInfoByTaskListId(taskListId);
    }

    public Boolean existsByTaskListId(String taskListId) {
        QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("task_list_id", taskListId);
        return taskListMapper.exists(queryWrapper);
    }

    @Override
    public List<TaskListDO> list(Map<String, Object> params) {
        return taskListMapper.list(params);
    }

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

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

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