package com.cyl.manager.oth.service;
import java.util.Arrays;
import java.util.List;
import java.time.LocalDateTime;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cyl.manager.oth.domain.entity.ScenicSpotInfo;
import com.cyl.manager.oth.domain.query.ScenicSpotInfoQuery;
import com.cyl.manager.oth.mapper.ScenicSpotInfoMapper;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
/**
 * 展馆&景点信息Service业务层处理
 *
 *
 * @author zcc
 */
@Service
public class ScenicSpotInfoService {
    @Autowired
    private ScenicSpotInfoMapper scenicSpotInfoMapper;

    /**
     * 查询展馆&景点信息
     *
     * @param id 展馆&景点信息主键
     * @return 展馆&景点信息
     */
    public ScenicSpotInfo selectById(Long id) {
        return scenicSpotInfoMapper.selectById(id);
    }

    /**
     * 查询展馆&景点信息列表
     *
     * @param query 查询条件
     * @param page 分页条件
     * @return 展馆&景点信息
     */
    public List<ScenicSpotInfo> selectList(ScenicSpotInfoQuery query, Pageable page) {
        if (page != null) {
            PageHelper.startPage(page.getPageNumber() + 1, page.getPageSize());
        }
        QueryWrapper<ScenicSpotInfo> qw = new QueryWrapper<>();
        qw.eq("del_flag","0");
        String showType = query.getShowType();
        if (!StringUtils.isEmpty(showType)) {
            qw.eq("show_type", showType);
        }
        String nameLike = query.getNameLike();
        if (!StringUtils.isEmpty(nameLike)) {
            qw.like("name", nameLike);
        }
        Integer orderNum = query.getOrderNum();
        if (orderNum != null) {
            qw.eq("order_num", orderNum);
        }
        String backUrl = query.getBackUrl();
        if (!StringUtils.isEmpty(backUrl)) {
            qw.eq("back_url", backUrl);
        }
        String coverUrl = query.getCoverUrl();
        if (!StringUtils.isEmpty(coverUrl)) {
            qw.eq("cover_url", coverUrl);
        }
        String introduce = query.getIntroduce();
        if (!StringUtils.isEmpty(introduce)) {
            qw.eq("introduce", introduce);
        }
        qw.orderByAsc("order_num");
        return scenicSpotInfoMapper.selectList(qw);
    }

    /**
     * 新增展馆&景点信息
     *
     * @param scenicSpotInfo 展馆&景点信息
     * @return 结果
     */
    public int insert(ScenicSpotInfo scenicSpotInfo) {
        scenicSpotInfo.setDelFlag("0");
        scenicSpotInfo.setCreateTime(LocalDateTime.now());
        return scenicSpotInfoMapper.insert(scenicSpotInfo);
    }

    /**
     * 修改展馆&景点信息
     *
     * @param scenicSpotInfo 展馆&景点信息
     * @return 结果
     */
    public int update(ScenicSpotInfo scenicSpotInfo) {
        return scenicSpotInfoMapper.updateById(scenicSpotInfo);
    }

    /**
     * 批量删除展馆&景点信息
     *
     * @param ids 需要删除的展馆&景点信息主键
     * @return 结果
     */
    public int deleteByIds(Long[] ids) {
        return scenicSpotInfoMapper.updateDelFlagByIds(ids);
    }

    /**
     * 删除展馆&景点信息信息
     *
     * @param id 展馆&景点信息主键
     * @return 结果
     */
    public int deleteById(Long id) {
        Long[] ids = {id};
        return scenicSpotInfoMapper.updateDelFlagByIds(ids);
    }
}
