package com.zcloud.domain.persistence.repository.impl;

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.domain.persistence.dataobject.ProjectTaskInfoDO;
import com.zcloud.domain.persistence.mapper.ProjectTaskInfoMapper;
import com.zcloud.domain.persistence.repository.ProjectTaskInfoRepository;
import com.zcloud.gbscommon.utils.PageQueryHelper;
import com.zcloud.gbscommon.utils.Query;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

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

/**
 * web-infrastructure
 *
 * @Author zhaokai
 * @Date 2026-01-27 11:30:30
 */
@Service
@RequiredArgsConstructor
public class ProjectTaskInfoRepositoryImpl extends BaseRepositoryImpl<ProjectTaskInfoMapper, ProjectTaskInfoDO> implements ProjectTaskInfoRepository {
    private final ProjectTaskInfoMapper projectTaskInfoMapper;

    @Override
    public PageResponse<ProjectTaskInfoDO> listPage(Map<String, Object> params) {
        IPage<ProjectTaskInfoDO> iPage = new Query<ProjectTaskInfoDO>().getPage(params);
        QueryWrapper<ProjectTaskInfoDO> queryWrapper = new QueryWrapper<>();
        queryWrapper = PageQueryHelper.createPageQueryWrapper(queryWrapper, params);
        queryWrapper.orderByDesc("create_time");
        IPage<ProjectTaskInfoDO> result = projectTaskInfoMapper.selectPage(iPage, queryWrapper);
        return PageHelper.pageToResponse(result, result.getRecords());
    }

    @Override
    public List<ProjectTaskInfoDO> getListByTaskId(String projectTaskId) {
        QueryWrapper<ProjectTaskInfoDO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("project_task_id", projectTaskId);
        queryWrapper.orderByDesc("create_time");
        return projectTaskInfoMapper.selectList(queryWrapper);
    }

    @Override
    public void deleteByProjectTaskId(String projectTaskId) {

        remove(new QueryWrapper<ProjectTaskInfoDO>().eq("project_task_id", projectTaskId));
    }
}

