package cn.ysk.cashier.mybatis.service.impl;

import cn.ysk.cashier.dto.shop.TbShopSongQueryCriteria;
import cn.ysk.cashier.mybatis.entity.TbShopSong;
import cn.ysk.cashier.mybatis.mapper.TbShopSongMapper;
import cn.ysk.cashier.mybatis.service.TbShopSongService;
import cn.ysk.cashier.utils.PageUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * (TbShopSong)表服务实现类
 *
 * @author ww
 * @since 2024-07-06 14:49:47
 */
@Service("tbShopSongService")
public class TbShopSongServiceImpl extends ServiceImpl<TbShopSongMapper, TbShopSong> implements TbShopSongService {
    @Autowired
    private TbShopSongMapper songMapper;

    @Override
    public Map<String, Object> queryAll(TbShopSongQueryCriteria criteria) {
        Page<TbShopSong> page = new Page<>(criteria.getPage(),criteria.getSize());
        QueryWrapper<TbShopSong> wrapper = new QueryWrapper<>();
        wrapper.eq("shop_id", criteria.getShopId());
        if (StringUtils.isNotBlank(criteria.getName())) {
            wrapper.and(w -> w.like("name", criteria.getName())
                    .or()
                    .like("singer", criteria.getName())
                    .or()
                    .like("origin_singer", criteria.getName()));
        }
        wrapper.orderByAsc("sort");
        wrapper.orderByDesc("create_time");
        Page<TbShopSong> tbShopSongPage = songMapper.selectPage(page, wrapper);
        return PageUtil.toPage(tbShopSongPage.getRecords(), tbShopSongPage.getTotal());
    }
}

