package com.yunzhi.marketing.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yunzhi.marketing.entity.TaBuildingDynamic;
import com.yunzhi.marketing.entity.TaPersonBuilding;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 项目动态表 Mapper 接口
 * </p>
 *
 * @author jobob
 * @since 2019-03-21
 */
@Mapper
public interface TaBuildingDynamicMapper extends BaseMapper<TaBuildingDynamic> {

    /**
     * 会员列列表
     * @param page
     * @param selected
     * @return
     */
    IPage<TaBuildingDynamic> buildingDynamicList(Page page, @Param("name") String name, @Param("buildingId") String buildingId, @Param("cityId") Integer cityId, @Param("isEnlist") String isEnlist, @Param("time") LocalDateTime time, @Param("title") String title, @Param("orgId") Integer orgId, @Param("activityStatus") String activityStatus,@Param("personBuildingList") List<TaPersonBuilding> personBuildingList,@Param("type") String type);

    /**
     * 详情
     * @param id
     * @return
     */
    TaBuildingDynamic iBuildingDynamicSelectId(@Param("id") String id);

    /**
     * 新增动态
     * @param buildingDynamic
     */
    void insertBuildingDynamic(TaBuildingDynamic buildingDynamic);

    /**
     * 修改动态
     * @param buildingDynamic
     */
    void buildingDynamicUpdate(TaBuildingDynamic buildingDynamic);

    /**
     * 某个字段值 +1
     * @param newsId
     * @param field
     * @param increment
     */
    @Update("UPDATE ta_building_dynamic  SET ${field} = IFNULL(${field}, 0) + #{increment}  WHERE dynamic_id = #{newsId}")
    void setFieldNum(@Param("newsId") String newsId, @Param("field") String field, @Param("increment") int increment);

    void updateTaBuildingDynamic(@Param("dynamicId") String dynamicId, @Param("sum") String sum);

    /**
     * 转化率 活动收藏 / 活动分享
     * @return
     */
    Map<String, Object> selectBuildingDynamicStatistical(@Param("orgId") Integer orgId, @Param("saveOrShare") String saveOrShare);

    /**
     * 转化率 活动报名
     * @return
     */
    Map<String, Object> selectBuildingDynamicEnlistStatistical(@Param("orgId") Integer orgId);

    /**
     * 更新未开始的活动
     */
    Integer updateActivityToUnStart(@Param("curTime") String curTime);

    /**
     * 更新未开始的活动
     */
    Integer updateUnStartActivity(@Param("curTime") String curTime);

    /**
     * 更新结束的活动
     */
    void updateProcessingActivity();

    IPage<TaBuildingDynamic> iBuildingDynamicSelectedList(Page<TaBuildingDynamic> page, String name, String buildingId, Integer cityId, String isEnlist, LocalDateTime time, String title, Integer orgId, String activityStatus,List<TaPersonBuilding> personBuildingList);
}
