package com.starry.admin.modules.shop.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.starry.admin.modules.shop.mapper.PlayShopCarouselInfoMapper;
import com.starry.admin.modules.shop.module.entity.PlayShopCarouselInfoEntity;
import com.starry.admin.modules.shop.module.vo.PlayShopCarouselInfoQueryVo;
import com.starry.admin.modules.shop.service.IPlayShopCarouselInfoService;
import com.starry.common.utils.IdUtils;
import java.util.Arrays;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * 店铺首页轮播Service业务层处理
 *
 * @author admin
 * @since 2024-06-05
 */
@Service
public class PlayShopCarouselInfoServiceImpl extends ServiceImpl<PlayShopCarouselInfoMapper, PlayShopCarouselInfoEntity>
        implements
            IPlayShopCarouselInfoService {
    @Resource
    private PlayShopCarouselInfoMapper playCarouselInfoMapper;

    /**
     * 查询店铺首页轮播
     *
     * @param id
     *            店铺首页轮播主键
     * @return 店铺首页轮播
     */
    @Override
    public PlayShopCarouselInfoEntity selectPlayCarouselInfoById(String id) {
        return this.baseMapper.selectById(id);
    }

    @Override
    public List<PlayShopCarouselInfoEntity> selectHomeCarouselInfo() {
        LambdaQueryWrapper<PlayShopCarouselInfoEntity> lambdaWrapper = new LambdaQueryWrapper<>();
        lambdaWrapper.eq(PlayShopCarouselInfoEntity::getCarouselIndex, "0");
        lambdaWrapper.eq(PlayShopCarouselInfoEntity::getEnableState, "1");
        return this.baseMapper.selectList(lambdaWrapper);
    }

    @Override
    public IPage<PlayShopCarouselInfoEntity> selectByPage(PlayShopCarouselInfoQueryVo vo) {
        LambdaQueryWrapper<PlayShopCarouselInfoEntity> lambdaWrapper = new LambdaQueryWrapper<>();
        if (StrUtil.isNotBlank(vo.getCarouselIndex())) {
            lambdaWrapper.eq(PlayShopCarouselInfoEntity::getCarouselIndex, vo.getCarouselIndex());
        }
        if (StrUtil.isNotBlank(vo.getEnableState())) {
            lambdaWrapper.eq(PlayShopCarouselInfoEntity::getEnableState, vo.getEnableState());
        }
        if (vo.getAddTime() != null && vo.getAddTime().size() == 2) {
            lambdaWrapper.between(PlayShopCarouselInfoEntity::getAddTime, vo.getAddTime().get(0),
                    vo.getAddTime().get(1));
        }
        return this.baseMapper.selectPage(new Page<>(vo.getPageNum(), vo.getPageSize()), lambdaWrapper);

    }

    /**
     * 新增店铺首页轮播
     *
     * @param playCarouselInfo
     *            店铺首页轮播
     * @return 结果
     */
    @Override
    public boolean create(PlayShopCarouselInfoEntity playCarouselInfo) {
        if (StrUtil.isBlankIfStr(playCarouselInfo.getId())) {
            playCarouselInfo.setId(IdUtils.getUuid());
        }
        return save(playCarouselInfo);
    }

    /**
     * 修改店铺首页轮播
     *
     * @param playCarouselInfo
     *            店铺首页轮播
     * @return 结果
     */
    @Override
    public boolean update(PlayShopCarouselInfoEntity playCarouselInfo) {
        return updateById(playCarouselInfo);
    }

    /**
     * 批量删除店铺首页轮播
     *
     * @param ids
     *            需要删除的店铺首页轮播主键
     * @return 结果
     */
    @Override
    public int deletePlayCarouselInfoByIds(String[] ids) {
        return playCarouselInfoMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除店铺首页轮播信息
     *
     * @param id
     *            店铺首页轮播主键
     * @return 结果
     */
    @Override
    public int deletePlayCarouselInfoById(String id) {
        return playCarouselInfoMapper.deleteById(id);
    }
}
