package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.ShopUserMapper;
import com.gxwebsoft.shop.service.ShopUserService;
import com.gxwebsoft.shop.entity.ShopUser;
import com.gxwebsoft.shop.param.ShopUserParam;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户记录表Service实现
 *
 * @author 科技小王子
 * @since 2026-02-10 00:37:07
 */
@Service
public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> implements ShopUserService {

    @Override
    public PageResult<ShopUser> pageRel(ShopUserParam param) {
        PageParam<ShopUser, ShopUserParam> page = new PageParam<>(param);
        page.setDefaultOrder("sort_number asc, create_time desc");
        List<ShopUser> list = baseMapper.selectPageRel(page, param);
        return new PageResult<>(list, page.getTotal());
    }

    @Override
    public List<ShopUser> listRel(ShopUserParam param) {
        List<ShopUser> list = baseMapper.selectListRel(param);
        // 排序
        PageParam<ShopUser, ShopUserParam> page = new PageParam<>();
        page.setDefaultOrder("sort_number asc, create_time desc");
        return page.sortRecords(list);
    }

    @Override
    public ShopUser getByIdRel(Integer userId) {
        ShopUserParam param = new ShopUserParam();
        param.setUserId(userId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
