package com.sptg.ad.biz.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.sptg.ad.api.dto.AdPushAppDto;
import com.sptg.ad.api.entity.AdPushApp;
import com.sptg.ad.biz.mapper.AdPushAppMapper;
import com.sptg.ad.biz.service.AdPushAppServiceInterface;
import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.core.beans.ResultEnum;
import com.sptg.common.core.constant.OperationConstant;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

/**
 * title: AdTypeServicelmpl
 * package: com.sptg.ad.biz.security.impl
 * description: 移动端广告-服务层实现类
 *
 *               
 *               
 */
@Service
public class AdPushAppServicelmpl extends ServiceImpl<AdPushAppMapper, AdPushApp> implements AdPushAppServiceInterface {


    @Override
    public ResultBean<Page<AdPushApp>> showList(AdPushAppDto dto) {
        //排序字段 时间降序
        dto.getPage().setOrderByField("t_create_date");
        dto.getPage().setAsc(false);
        //构建查询条件
        Wrapper<AdPushApp> wrapper = new EntityWrapper<>();
        //广告标题
        if(StringUtils.isNotBlank(dto.getAdTitle())){
            wrapper.like("s_ad_title", dto.getAdTitle());
        }
        //广告编号
        if(StringUtils.isNotBlank(dto.getAdCode())){
            wrapper.like("s_ad_code", dto.getAdCode());
        }
        //广告状态
        if (null != dto.getIsEnable()){
            wrapper.eq("i_is_enable", dto.getIsEnable());
        }
        //广告过期时间
        if (null != dto.getBeginDate()){
            wrapper.gt("d_expiration_time",dto.getBeginDate());
        }
        if (null != dto.getEndDate()){
            wrapper.lt("d_expiration_time",dto.getEndDate());
        }
        //排除删除的数据
        wrapper.notIn("i_status", OperationConstant.MINUS_ONE);
        wrapper.like("s_org_position", dto.getOrgPosition());
        return new ResultBean<>(ResultEnum.SUCCESS,this.selectPage(dto.getPage(), wrapper));
    }

    @Override
    public ResultBean<AdPushApp> getList(AdPushAppDto dto) {
        Wrapper<AdPushApp> wrapper = new EntityWrapper<>();
        //排除删除的数据
        wrapper.eq("i_status", OperationConstant.ZERO);
        wrapper.eq("i_is_enable", OperationConstant.ZERO);
        wrapper.orderBy("i_sort", false);
        return new ResultBean<>(ResultEnum.SUCCESS,this.selectList(wrapper));
    }

}
