package org.jeecg.modules.apiService.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.apiBean.PageBean;
import org.jeecg.modules.apiService.IndexApiService;
import org.jeecg.modules.hanHaiMember.service.IHanHaiMemberService;
import org.jeecg.modules.travelAddress.entity.TravelAddress;
import org.jeecg.modules.travelAddress.service.ITravelAddressService;
import org.jeecg.modules.travelAdvance.entity.TravelAdvance;
import org.jeecg.modules.travelAdvance.service.ITravelAdvanceService;
import org.jeecg.modules.travelAmusement.entity.TravelAmusement;
import org.jeecg.modules.travelAmusement.service.ITravelAmusementService;
import org.jeecg.modules.travelArea.entity.TravelArea;
import org.jeecg.modules.travelArea.service.ITravelAreaService;
import org.jeecg.modules.travelArticle.entity.TravelArticle;
import org.jeecg.modules.travelArticle.service.ITravelArticleService;
import org.jeecg.modules.travelCategory.entity.TravelCategory;
import org.jeecg.modules.travelCategory.service.ITravelCategoryService;
import org.jeecg.modules.travelCertification.service.ITravelCertificationService;
import org.jeecg.modules.travelExperience.entity.TravelExperience;
import org.jeecg.modules.travelExperience.service.ITravelExperienceService;
import org.jeecg.modules.travelImage.entity.TravelImage;
import org.jeecg.modules.travelImage.service.ITravelImageService;
import org.jeecg.modules.travelOrder.entity.TravelOrder;
import org.jeecg.modules.travelOrder.service.ITravelOrderService;
import org.jeecg.modules.travelRole.service.ITravelRoleService;
import org.jeecg.modules.travelRoleInfo.entity.TravelRoleInfo;
import org.jeecg.modules.travelRoleInfo.service.ITravelRoleInfoService;
import org.jeecg.modules.travelSpot.entity.TravelSpot;
import org.jeecg.modules.travelSpot.service.ITravelSpotService;
import org.jeecg.modules.travelTime.entity.TravelTime;
import org.jeecg.modules.travelTime.service.ITravelTimeService;
import org.jeecg.modules.travelVideo.entity.TravelVideo;
import org.jeecg.modules.travelVideo.service.ITravelVideoService;
import org.jeecg.modules.travelVolunteer.entity.TravelVolunteer;
import org.jeecg.modules.travelVolunteer.service.ITravelVolunteerService;
import org.jeecg.modules.travelWares.entity.TravelWares;
import org.jeecg.modules.travelWares.service.ITravelWaresService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class IndexApiServiceImpl implements IndexApiService {

    //获取小程序任一文章或服务

    //用户表
    @Resource
    private IHanHaiMemberService hanHaiMemberService;
    //角色表
    @Resource
    private ITravelRoleService travelRoleService;
    //角色信息表
    @Resource
    private ITravelRoleInfoService travelRoleInfoService;
    //景区表
    @Resource
    private ITravelAreaService travelAreaService;
    //景点表
    @Resource
    private ITravelSpotService travelSpotService;
    //分类表
    @Resource
    private ITravelCategoryService travelCategoryService;
    //图片表
    @Resource
    private ITravelImageService travelImageService;
    //文章表
    @Resource
    private ITravelArticleService travelArticleService;
    //视频表
    @Resource
    private ITravelVideoService travelVideoService;
    //游玩项目表
    @Resource
    private ITravelAmusementService travelAmusementService;

    //非遗体验表
    @Resource
    private ITravelExperienceService travelExperienceService;

    //收货地址表
    @Resource
    private ITravelAddressService travelAddressService;

    //预约时段表
    @Resource
    private ITravelTimeService travelTimeService;

    //预约订单表
    @Resource
    private ITravelOrderService travelOrderService;

    //商品表
    @Resource
    private ITravelWaresService travelWaresService;

    //建议表
    @Resource
    private ITravelAdvanceService travelAdvanceService;

    //志愿者表
    @Resource
    private ITravelVolunteerService travelVolunteerService;





    //证件表
    @Resource
    private ITravelCertificationService travelCertificationService;


    //获取轮播图列表
    @Override
    public Result<?> queryBannerList(String bannerCategoryId) {

        //0-首页 1-遗产路径 2-我要跟拍 3-非遗体验 4-无忧服务
        if(null != bannerCategoryId){
            switch (bannerCategoryId){
                case "0": bannerCategoryId = "1836222983394902017";
                    break;
                case "1": bannerCategoryId = "1838473006392385538";
                    break;
                case "2": bannerCategoryId = "1838473106556559361";
                    break;
                case "3": bannerCategoryId = "1838473306209624065";
                    break;
                case "4": bannerCategoryId = "1838473405736263682";
                    break;
                case "5": bannerCategoryId = "1836253741344075777";
                    break;
                default: bannerCategoryId = null;
            }
        }

        List<TravelImage> list = null;
        if(null != bannerCategoryId){
            list = travelImageService
                    .lambdaQuery()
                    .eq(TravelImage::getCategoryId, bannerCategoryId)
                    .orderByAsc(TravelImage::getOrderId)
                    .list();
        }else {
            list = travelImageService
                    .lambdaQuery()
                    .orderByAsc(TravelImage::getOrderId)
                    .list();
        }

        return Result.OK("轮播图列表", list);
    }

    //获取视频列表带分页
    @Override
    public Result<?> queryVideoList(PageBean pageBean) {
        Page<TravelVideo> page = new Page<TravelVideo>(pageBean.getPageNo(), pageBean.getPageSize());
        Page<TravelVideo> pageList = travelVideoService
                .lambdaQuery()
                .orderByDesc(TravelVideo::getCreateTime)
                .page(page);

        return Result.OK("视频列表", pageList);
    }

    //获取文章列表带分页
    @Override
    public Result<?> queryArticleList(PageBean pageBean) {
        Page<TravelArticle> page = new Page<TravelArticle>(pageBean.getPageNo(), pageBean.getPageSize());
        Page<TravelArticle> pageList = travelArticleService
                .lambdaQuery()
                .orderByDesc(TravelArticle::getCreateTime)
                .page(page);

        return Result.OK("文章列表", pageList);
    }

    //根据文章类型获取文章列表带分页
    @Override
    public Result<?> queryArticleListByType(String articleType, PageBean pageBean) {

        //0-申遗历程 1-申遗缘由 2-遗产价值
        if(null != articleType){
            switch (articleType){
                case "0": articleType = "1836253741344075777";
                    break;
                case "1": articleType = "1836253813855203330";
                    break;
                case "2": articleType = "1836253884822827009";
                    break;
                default: articleType = null;
            }
        }

        Page<TravelArticle> page = new Page<TravelArticle>(pageBean.getPageNo(), pageBean.getPageSize());
        Page<TravelArticle> pageList =null;

        if(null != articleType){

            pageList = travelArticleService
                    .lambdaQuery()
                    .eq(TravelArticle::getCategoryId, articleType)
                    .orderByDesc(TravelArticle::getCreateTime)
                    .page(page);
        }else {
            pageList = travelArticleService
                    .lambdaQuery()
                    .orderByDesc(TravelArticle::getCreateTime)
                    .page(page);
        }

        return Result.OK("文章列表", pageList);
    }

    //根据文章id获取文章详情
    @Override
    public Result<?> queryArticleById(String articleId) {
        TravelArticle one = travelArticleService
                .lambdaQuery()
                .eq(TravelArticle::getId, articleId)
                .one();

        return Result.OK("文章详情", one);
    }

    //获取景区列表带分页
    @Override
    public Result<?> queryAreaList(PageBean pageBean) {

        Page<TravelArea> page = new Page<TravelArea>(pageBean.getPageNo(), pageBean.getPageSize());
        Page<TravelArea> pageList = travelAreaService
                .lambdaQuery()
                .page(page);

        return Result.OK("景区列表", pageList);
    }

    //根据id获取景区详情
    @Override
    public Result<?> queryAreaListById(String areaId) {
        TravelArea one = travelAreaService
                .lambdaQuery()
                .eq(TravelArea::getId, areaId)
                .one();

        return Result.OK("景区详情", one);
    }

    //根据景区id获取该景区下的地点列表-景点/厕所/美食店铺/民宿带分页
    @Override
    public Result<?> querySpotList(String areaId, String categoryId, PageBean pageBean) {

        //0-瓷都镇区 1-湖田片区 2-高岭片区 3-瑶里片区 4-蛟潭片区
        if(null != areaId){
            switch (areaId){
                case "0": areaId = "1835255148875296770";
                    break;
                case "1": areaId = "1835296270515376130";
                    break;
                case "2": areaId = "1835296379189792769";
                    break;
                case "3": areaId = "1835296552271941634";
                    break;
                case "4": areaId = "1835296680814776322";
                    break;
                default: areaId = null;
            }
        }

        //0-景点 1-美食店铺 2-民宿 3-厕所
        if(null != categoryId){
            switch (categoryId){
                case "0": categoryId = "1835297869300174849";
                    break;
                case "1": categoryId = "1835298116864774146";
                    break;
                case "2": categoryId = "1835298190902628353";
                    break;
                case "3": categoryId = "1835297932831297538";
                    break;
                default: categoryId = null;
            }
        }

        Page<TravelSpot> page = new Page<TravelSpot>(pageBean.getPageNo(), pageBean.getPageSize());
        Page<TravelSpot> pageList = null;
        if(null != areaId && null != categoryId){
            pageList = travelSpotService
                    .lambdaQuery()
                    .eq(TravelSpot::getAreaId, areaId)
                    .eq(TravelSpot::getCategoryId, categoryId)
                    .page(page);
        }else if(null != areaId){
            pageList = travelSpotService
                    .lambdaQuery()
                    .eq(TravelSpot::getAreaId, areaId)
                    .page(page);
        }else if(null != categoryId){
            pageList = travelSpotService
                    .lambdaQuery()
                    .eq(TravelSpot::getCategoryId, categoryId)
                    .page(page);
        }else {
            pageList = travelSpotService
                    .lambdaQuery()
                    .page(page);
        }

        return Result.OK("景点列表", pageList);
    }

    //根据角色类型获取角色信息列表
    @Override
    public Result<?> queryRoleInfoList(String roleId, String level, String spot, PageBean pageBean) {

        //roleId: 0-讲解员，1-达人，2-摄影师
        if(null != roleId){
            switch (roleId){
                case "0":
                    roleId = "1835298310465458178";
                    break;
                case "1":
                    roleId = "1835298364374847490";
                    break;
                case "2":
                    roleId = "1835298430967812098";
                    break;
                default: roleId = null;
            }
        }

        Page<TravelRoleInfo> page = new Page<TravelRoleInfo>(pageBean.getPageNo(), pageBean.getPageSize());
        Page<TravelRoleInfo> pageList = null;

        if(null != roleId &&null != level && null != spot){
            pageList = travelRoleInfoService
                    .lambdaQuery()
                    .eq(TravelRoleInfo::getRoleId, roleId)
                    .eq(TravelRoleInfo::getRoleLevel, level)
                    .like(TravelRoleInfo::getSkill, spot)
                    .page(page);
        }else if(null != roleId && null != level){
            pageList = travelRoleInfoService
                    .lambdaQuery()
                    .eq(TravelRoleInfo::getRoleId, roleId)
                    .eq(TravelRoleInfo::getRoleLevel, level)
                    .page(page);
        }else if(null != roleId && null != spot){
            pageList = travelRoleInfoService
                    .lambdaQuery()
                    .eq(TravelRoleInfo::getRoleId, roleId)
                    .like(TravelRoleInfo::getSkill, spot)
                    .page(page);
        }else if(null != level && null != spot){
            pageList = travelRoleInfoService
                    .lambdaQuery()
                    .eq(TravelRoleInfo::getRoleLevel, level)
                    .like(TravelRoleInfo::getSkill, spot)
                    .page(page);
        }else if(null != roleId){
            pageList = travelRoleInfoService
                    .lambdaQuery()
                    .eq(TravelRoleInfo::getRoleId, roleId)
                    .page(page);
        }else if(null != level){
            pageList = travelRoleInfoService
                    .lambdaQuery()
                    .eq(TravelRoleInfo::getRoleLevel, level)
                    .page(page);
        }else if(null != spot){
            pageList = travelRoleInfoService
                    .lambdaQuery()
                    .like(TravelRoleInfo::getSkill, spot)
                    .page(page);
        }else{
            pageList = travelRoleInfoService
                    .lambdaQuery()
                    .page(page);
        }

        return Result.OK("角色列表", pageList);
    }

    //根据角色id获取角色详情
    @Override
    public Result<?> queryRoleInfoById(String roleInfoId) {
        TravelRoleInfo one = travelRoleInfoService
                .lambdaQuery()
                .eq(TravelRoleInfo::getId, roleInfoId)
                .one();

        return Result.OK("角色详情", one);
    }

    //获取视频列表
    @Override
    public Result<?> queryVedioById(String roleInfoId, PageBean pageBean) {

        Page<TravelVideo> page = new Page<TravelVideo>(pageBean.getPageNo(), pageBean.getPageSize());
        Page<TravelVideo> pageList;

        if(null != roleInfoId){
            pageList = travelVideoService
                    .lambdaQuery()
                    .eq(TravelVideo::getCreateBy, roleInfoId)
                    .orderByDesc(TravelVideo::getCreateTime)
                    .page(page);
        }else {
            pageList = travelVideoService
                    .lambdaQuery()
                    .orderByDesc(TravelVideo::getCreateTime)
                    .page(page);
        }


        return Result.OK("视频列表", pageList);
    }

    //获取游玩项目列表
    @Override
    public Result<?> queryAmusementList(String amusementType, String isPay, PageBean pageBean) {
        Page<TravelAmusement> page = new Page<TravelAmusement>(pageBean.getPageNo(), pageBean.getPageSize());
        Page<TravelAmusement> pageList;

        if(null != amusementType && null != isPay){
            pageList = travelAmusementService
                    .lambdaQuery()
                    .eq(TravelAmusement::getAmusementType, amusementType)
                    .eq(TravelAmusement::getIsPay, isPay)
                    .page(page);
        }else if(null != amusementType){
            pageList = travelAmusementService
                    .lambdaQuery()
                    .eq(TravelAmusement::getAmusementType, amusementType)
                    .page(page);
        }else if(null != isPay){
            pageList = travelAmusementService
                    .lambdaQuery()
                    .eq(TravelAmusement::getIsPay, isPay)
                    .page(page);
        }else {
            pageList = travelAmusementService
                    .lambdaQuery()
                    .page(page);
        }


        return Result.OK("游玩项目列表/详情", pageList);
    }

    //获取游玩项目详情
    @Override
    public Result<?> queryAmusementById(String amusementId) {
        TravelAmusement one = travelAmusementService
                .lambdaQuery()
                .eq(TravelAmusement::getId, amusementId)
                .one();

        return Result.OK("游玩项目详情", one);
    }

    //获取非遗体验列表
    @Override
    public Result<?> queryExperienceList(PageBean pageBean) {

        Page<TravelExperience> page = new Page<TravelExperience>(pageBean.getPageNo(), pageBean.getPageSize());
        Page<TravelExperience> pageList = travelExperienceService
                .lambdaQuery()
                .page(page);

        return Result.OK("非遗体验列表", pageList);
    }

    //获取非遗体验详情
    @Override
    public Result<?> queryExperienceById(String experienceId) {

        TravelExperience one = travelExperienceService
                .lambdaQuery()
                .eq(TravelExperience::getId, experienceId)
                .one();

        return Result.OK("非遗体验详情", one);
    }

    @Override
    public Result<?> queryCollection(String collectionType, PageBean pageBean) {

        return null;
    }


    @Override
    public Result<?> queryPreOrder(String collectionType, PageBean pageBean) {
        return null;
    }

    //获取地址列表
    @Override
    public Result<?> queryAddress(TravelAddress travelAddress, PageBean pageBean) {
        Page<TravelAddress> page = new Page<TravelAddress>(pageBean.getPageNo(), pageBean.getPageSize());
        Page<TravelAddress> pageList;

        if(null != travelAddress.getMemberId()){
            pageList = travelAddressService
                    .lambdaQuery()
                    .eq(TravelAddress::getMemberId,travelAddress.getMemberId())
                    .orderByDesc(TravelAddress::getCreateTime)
                    .page(page);
        }else {
            pageList = travelAddressService
                    .lambdaQuery()
                    .orderByDesc(TravelAddress::getCreateTime)
                    .page(page);
        }

        return Result.OK("地址列表", pageList);
    }

    //新增地址
    @Override
    public Result<?> addAddress(TravelAddress travelAddress) {
        boolean flag = travelAddressService.save(travelAddress);
        if(flag){
            return Result.OK("新增地址成功！");
        }else {
            return Result.OK("新增地址失败！");
        }
    }

    //删除地址
    @Override
    public Result<?> deleteAddress(String addressId) {
        boolean flag = travelAddressService.removeById(addressId);
        if(flag){
            return Result.OK("删除地址成功！");
        }else {
            return Result.OK("删除地址失败！");
        }
    }

    //修改地址
    @Override
    public Result<?> updateAddress(TravelAddress travelAddress) {
        boolean flag = travelAddressService.updateById(travelAddress);
        if(flag){
            return Result.OK("修改地址成功！");
        }else {
            return Result.OK("修改地址失败！");
        }
    }

    //查询预约时间段
    @Override
    public Result<?> queryOrderTime(TravelTime travelTime) {
        List<TravelTime> list;

        if(null != travelTime.getTimeType()){
            list = travelTimeService
                    .lambdaQuery()
                    .eq(TravelTime::getTimeType, travelTime.getTimeType())
                    .orderByAsc(TravelTime::getTimeOrder)
                    .list();
        }else {
            list = travelTimeService
                    .lambdaQuery()
                    .orderByAsc(TravelTime::getTimeOrder)
                    .list();
        }
        return Result.OK("时段列表", list);
    }

    //查询预约订单列表
    @Override
    public Result<?> queryOrderList(TravelOrder travelOrder, PageBean pageBean) {
        Page<TravelOrder> page = new Page<TravelOrder>(pageBean.getPageNo(), pageBean.getPageSize());
        Page<TravelOrder> pageList;

        if(null != travelOrder.getOrderType()){
            pageList = travelOrderService
                    .lambdaQuery()
                    .eq(TravelOrder::getOrderType, travelOrder.getOrderType())
                    .orderByDesc(TravelOrder::getCreateTime)
                    .page(page);
        }else {
            pageList = travelOrderService
                    .lambdaQuery()
                    .orderByDesc(TravelOrder::getCreateTime)
                    .page(page);
        }
        return Result.OK("订单列表", pageList);
    }

    //获取文创好物列表
    public Result<?> queryWaresList(PageBean pageBean) {
        Page<TravelWares> page = new Page<TravelWares>(pageBean.getPageNo(), pageBean.getPageSize());
        Page<TravelWares> pageList;

        pageList = travelWaresService
                .lambdaQuery()
                .orderByDesc(TravelWares::getCreateTime)
                .page(page);

        return Result.OK("文创好物列表", pageList);
    }

    //根据Id获取文创好物详情
    @Override
    public Result<?> queryWaresById(String waresId) {

        TravelWares one = travelWaresService
                .lambdaQuery()
                .eq(TravelWares::getId, waresId)
                .one();

        return Result.OK("文创好物详情", one);
    }


    //我要帮助-添加建议
    @Override
    public Result<?> addAdvice(TravelAdvance travelAdvance) {
        boolean flag = travelAdvanceService.save(travelAdvance);
        if(flag){
            return Result.OK("新增建议成功！");
        }else {
            return Result.OK("新增建议失败！");
        }
    }

    //添加志愿者
    @Override
    public Result<?> addVolunteer(TravelVolunteer travelVolunteer) {
        boolean flag = travelVolunteerService.save(travelVolunteer);
        if(flag){
            return Result.OK("新增志愿者成功！");
        }else {
            return Result.OK("新增志愿者失败！");
        }
    }
}
