package com.sptg.ad.biz.mapper;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.pagination.Pagination;
import com.sptg.ad.api.entity.AdPushTask;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * title: AdPushTaskMapper
 * package: com.sptg.ad.biz.mapper
 * description: 广告内容-DAO接口
 *
 *               
 *                 
 */
public interface AdPushTaskMapper extends BaseMapper<AdPushTask> {

    /**
     * 功能描述:获取当前设备发布的有效广告数量
     * @param deviceId 设备id
     * @return int
     *                
     *                     
     */
    @Select("select sum(i_content_count) from ad_push_task where t_begin_date<now() and t_end_date>now() " +
            "and l_id in( select l_task_id from  ad_push_device_details where l_device_id=#{deviceId})")
    Integer getValidAdPushCountDevice(@Param(value = "deviceId")Long deviceId);

    /**
     * 功能描述:更新记录机构位置
     * @param oldPosition 旧机构位置
     * @param newPosition 新机构位置
     *               
     *                      
     */
    @Update("update ad_push_task set s_org_position=#{newPosition} where s_org_position=#{oldPosition}")
    int updateOrgPosition(@Param(value = "oldPosition")String oldPosition, @Param(value = "newPosition") String newPosition);

    /**
     * 功能描述:分页
     * @param  wrapper 查询条件
     * @param  page 分页条件
     * @return
     *               
     *                      
     */
    List<AdPushTask> showList(@Param(value = "ew") Wrapper<AdPushTask> wrapper, @Param(value = "page")Pagination page);

}
