package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.shop.entity.UserLike;
import com.gxwebsoft.shop.mapper.UserLikeMapper;
import com.gxwebsoft.shop.param.UserLikeParam;
import com.gxwebsoft.shop.service.UserLikeService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 点赞记录表Service实现
 *
 * @author 科技小王子
 * @since 2023-07-06 17:51:04
 */
@Service
public class UserLikeServiceImpl extends ServiceImpl<UserLikeMapper, UserLike> implements UserLikeService {

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

    @Override
    public List<UserLike> listRel(UserLikeParam param) {
        List<UserLike> list = baseMapper.selectListRel(param);

        // 排序
        PageParam<UserLike, UserLikeParam> page = new PageParam<>();
        page.setDefaultOrder("create_time desc");
        return page.sortRecords(list);
    }

    @Override
    public UserLike getByIdRel(Integer logId) {
        UserLikeParam param = new UserLikeParam();
        param.setLogId(logId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
