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

import com.alibaba.cola.dto.PageResponse;
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.TaskDetailDO;
import com.zcloud.safetyDutyList.persistence.mapper.tasklist.TaskDetailMapper;
import com.zcloud.safetyDutyList.persistence.repository.tasklist.TaskDetailRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

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

/**
 * 任务详情仓储实现类
 * <p>
 * 实现任务详情仓储接口，委托TaskDetailMapper完成实际的SQL操作。
 * 继承BaseRepositoryImpl获得MyBatis-Plus的基础CRUD能力。
 */
@Service
@RequiredArgsConstructor
public class TaskDetailRepositoryImpl extends BaseRepositoryImpl<TaskDetailMapper, TaskDetailDO> implements TaskDetailRepository {

    /** 任务详情Mapper，用于SQL操作 */
    private final TaskDetailMapper taskDetailMapper;

    /**
     * 分页查询任务详情列表
     * <p>
     * 构建分页参数后调用Mapper的listPage方法，将结果转换为PageResponse
     */
    @Override
    public PageResponse<TaskDetailDO> listPage(Map<String, Object> params) {
        IPage<TaskDetailDO> iPage = new Query<TaskDetailDO>().getPage(params);
        IPage<TaskDetailDO> result = taskDetailMapper.listPage(iPage, params);
        return PageHelper.pageToResponse(result, result.getRecords());
    }

    /**
     * 根据清单业务ID查询该清单下所有任务详情
     */
    @Override
    public List<TaskDetailDO> listByTaskListId(String taskListId) {
        return taskDetailMapper.listByTaskListId(taskListId);
    }

    /**
     * 根据任务详情业务ID查询任务详情
     */
    @Override
    public TaskDetailDO getByTaskDetailId(String taskDetailId) {
        return taskDetailMapper.getByTaskDetailId(taskDetailId);
    }

    /**
     * 根据清单业务ID删除该清单下所有任务详情
     */
    @Override
    public Boolean deleteByTaskListId(String taskListId) {
        return taskDetailMapper.deleteByTaskListId(taskListId);
    }

    /**
     * 查询所有进行中的任务
     * <p>
     * 委托Mapper执行SQL：SELECT * FROM safety_accountability_task_detail WHERE task_status = 1
     */
    @Override
    public List<TaskDetailDO> listInProgress() {
        return taskDetailMapper.listInProgress();
    }
}
