package shop.alien.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import shop.alien.entity.store.LifeBrowseRecord;

import java.util.List;
import java.util.Map;

@Mapper
public interface LifeBrowseRecordMapper extends BaseMapper<LifeBrowseRecord> {

    @Select("SELECT a.id,a.liulan_date liulanDate, b.store_type storeType, b.store_position storePosition, a.liulan_time liulanTime, " +
            "c.img_url image, b.store_name storeName, b.store_address storeDetailAddress, b.id storeId, a.created_time, d.img_url entranceImage, dict.dict_detail storeTypeStr,ROUND(b.score_avg, 2) scoreAvg,b.business_types_name businessTypesName " +
            "FROM life_browse_record a " +
            "LEFT JOIN store_info b ON a.store_id = b.id " +
            "LEFT JOIN store_img c on b.id = c.store_id and c.img_type = 11 and c.delete_flag = 0 " +
            "LEFT JOIN store_img d on b.id = d.store_id and d.img_type = 1 and d.delete_flag = 0 " +
            "left join store_dictionary dict on dict.type_name = 'storeType' and dict.dict_id = b.store_type and dict.delete_flag = 0 " +
            "WHERE a.user_id = #{userId} AND a.delete_flag = 0 AND b.delete_flag = 0 ORDER BY a.liulan_time desc")
    List<Map<String, Object>> getBrowseRecordByUserId(String userId);
    @Select("select lbr.id,lgbm.group_name groupName,lgbm.id couponId,si.id storeId,ROUND(b.score_avg, 2) scoreAvg, original_price originalPrice,preferential_price preferentialPrice,lbr.liulan_date liulanDate,si.store_name storeName,si2.img_url\n" +
            "from life_browse_record lbr \n" +
            "inner join life_group_buy_main lgbm on lgbm.id = lbr.coupon_id \n" +
            "and lgbm.delete_flag = 0 and lbr.delete_flag = 0\n" +
            "left join store_info si on si.id = lgbm.store_id and si.delete_flag = 0\n" +
            "left join store_img si2 on si2.id = SUBSTRING_INDEX(lgbm.image_id, ',', 1) and si2.delete_flag = 0\n" +
            "where lbr.user_id = #{userId} and lbr.coupon_id is not null\n" +
            "Order by lbr.liulan_time desc")
    List<Map<String, Object>> getGroupBuyBrowseRecordByUserId(String userId);

    @Select("select lbr.id,lud.*,lud.id dynamicsId,lbr.liulan_date liulanDate\n" +
            "from life_browse_record lbr \n" +
            "inner join life_user_dynamics lud on lud.id = lbr.dynamics_id \n" +
            "and lud.delete_flag = 0 and lbr.delete_flag = 0 \n" +
            "where lbr.user_id = #{userId} and lbr.dynamics_id is not null\n" +
            "Order by lbr.liulan_time desc")
    List<Map<String, Object>> getDynamicsBrowseRecordByUserId(String userId);
}