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.DomainGroupUserDO;
import com.zcloud.domain.persistence.dataobject.ProjectTaskGroupUserDO;
import com.zcloud.domain.persistence.mapper.ProjectTaskGroupUserMapper;
import com.zcloud.domain.persistence.repository.ProjectTaskGroupUserRepository;
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-29 11:28:09
 */
@Service
@RequiredArgsConstructor
public class ProjectTaskGroupUserRepositoryImpl extends BaseRepositoryImpl<ProjectTaskGroupUserMapper, ProjectTaskGroupUserDO> implements ProjectTaskGroupUserRepository {
    private final ProjectTaskGroupUserMapper projectTaskGroupUserMapper;

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

    @Override
    public List<ProjectTaskGroupUserDO> getListByUserIdList(List<Long> userIdList) {
        return projectTaskGroupUserMapper.getListByUserIdList(userIdList);
    }

    @Override
    public List<ProjectTaskGroupUserDO> getListByTaskId(String projectTaskId) {
        return projectTaskGroupUserMapper.getListByTaskId(projectTaskId);
    }

    @Override
    public void deleteByProjectTaskId(String projectTaskId) {
        remove(new QueryWrapper<ProjectTaskGroupUserDO>().eq("project_task_id", projectTaskId));
    }
}

