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

import com.jjb.saas.framework.repository.common.PageHelper;
import com.zcloud.basic.info.persistence.dataobject.RzUserRecordDO;
import com.zcloud.basic.info.persistence.mapper.RzUserRecordMapper;
import com.zcloud.basic.info.persistence.repository.RzUserRecordRepository;
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-05 14:00:37
 */
@Service
@RequiredArgsConstructor
public class RzUserRecordRepositoryImpl extends BaseRepositoryImpl<RzUserRecordMapper, RzUserRecordDO> implements RzUserRecordRepository {
    private final RzUserRecordMapper rzUserRecordMapper;

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

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

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

    @Override
    public void addBatch(List<RzUserRecordDO> rzUserRecordDOList) {
        this.saveBatch(rzUserRecordDOList);
    }
}

