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.ProjectTaskScoreInfoDO;
import com.zcloud.domain.persistence.mapper.ProjectTaskScoreInfoMapper;
import com.zcloud.domain.persistence.repository.ProjectTaskScoreInfoRepository;
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:46
 */
@Service
@RequiredArgsConstructor
public class ProjectTaskScoreInfoRepositoryImpl extends BaseRepositoryImpl<ProjectTaskScoreInfoMapper, ProjectTaskScoreInfoDO> implements ProjectTaskScoreInfoRepository {
    private final ProjectTaskScoreInfoMapper projectTaskScoreInfoMapper;

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

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

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

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

