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

import com.jjb.saas.framework.repository.common.PageHelper;
import com.zcloud.basic.info.persistence.dataobject.RzUserDO;
import com.zcloud.basic.info.persistence.mapper.RzUserMapper;
import com.zcloud.basic.info.persistence.repository.RzUserRepository;
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 17:15:57
 */
@Service
@RequiredArgsConstructor
public class RzUserRepositoryImpl extends BaseRepositoryImpl<RzUserMapper, RzUserDO> implements RzUserRepository {
    private final RzUserMapper rzUserMapper;

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

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

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

    @Override
    public RzUserDO getByPhoneAndIdCardNumber(String phone, String idCardNumber) {
        QueryWrapper<RzUserDO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("phone_number", phone);
        queryWrapper.eq("id_card_number", idCardNumber);
        return this.getOne(queryWrapper);
    }
}

