package com.zcloud.basic.info.persistence.repository.impl;

import com.jjb.saas.framework.repository.common.PageHelper;
import com.zcloud.basic.info.persistence.dataobject.ProblemFeedbackDO;
import com.zcloud.basic.info.persistence.mapper.ProblemFeedbackMapper;
import com.zcloud.basic.info.persistence.repository.ProblemFeedbackRepository;
import com.alibaba.cola.dto.SingleResponse;
import com.alibaba.cola.dto.PageResponse;
import com.zcloud.gbscommon.utils.PageQueryHelper;
import com.zcloud.gbscommon.utils.Query;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jjb.saas.framework.repository.repo.impl.BaseRepositoryImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

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

/**
 * web-infrastructure
 *
 * @Author SondonYong
 * @Date 2025-12-06 11:26:35
 */
@Service
@RequiredArgsConstructor
public class ProblemFeedbackRepositoryImpl extends BaseRepositoryImpl<ProblemFeedbackMapper, ProblemFeedbackDO> implements ProblemFeedbackRepository {
    private final ProblemFeedbackMapper problemFeedbackMapper;

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

    @Override
    public List<ProblemFeedbackDO> list(Map<String, Object> params) {
        QueryWrapper<ProblemFeedbackDO> queryWrapper = new QueryWrapper<>();
        queryWrapper = PageQueryHelper.createPageQueryWrapper(queryWrapper, params);
        queryWrapper.orderByDesc("create_time");
        List<ProblemFeedbackDO> result = problemFeedbackMapper.selectList(queryWrapper);
        return result;
    }

    @Override
    public SingleResponse<ProblemFeedbackDO> getInfoById(Long id) {
        return SingleResponse.of(problemFeedbackMapper.selectById(id));
    }
}

