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

import com.jjb.saas.framework.repository.common.PageHelper;
import com.zcloud.basic.info.persistence.dataobject.UserChangeRecordDO;
import com.zcloud.basic.info.persistence.mapper.UserChangeRecordMapper;
import com.zcloud.basic.info.persistence.repository.UserChangeRecordRepository;
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-02 14:08:19
 */
@Service
@RequiredArgsConstructor
public class UserChangeRecordRepositoryImpl extends BaseRepositoryImpl<UserChangeRecordMapper, UserChangeRecordDO> implements UserChangeRecordRepository {
    private final UserChangeRecordMapper userChangeRecordMapper;

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

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

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

    @Override
    public UserChangeRecordDO getChangerRecordInfoById(Long userId, Long corpinfoId, Integer status) {
        return userChangeRecordMapper.getChangerRecordInfoById(userId, corpinfoId, status);
    }
}

