package com.cyksj.mapper.manage.coupon;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cyksj.model.entity.CouponSku;
import com.cyksj.model.views.CouponSkuView;
import com.cyksj.model.views.GoodsDonSkuView;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/*
 *项目名: netflix
 *文件名: CouponSkuMapper
 *创建者: JavaZou
 *创建时间:2022/11/21 12:10
 */
public interface CouponSkuMapper extends BaseMapper<CouponSku> {

	@Update("update coupon_sku set deleted = false where coupon_id = #{id}")
	void deleteByCid(Long id);

	@Select("select GROUP_CONCAT(gd.title, ifnull(gdk.spec_val,'')) from `coupon_sku` ck left join `goods_don` gd on gd.id = ck.goods_id" +
			" left join `goods_don_sku` gdk on gdk.id = ck.sku_id where ck.coupon_id = #{couponId}")
	String selectGoodsSkuStr(Long couponId);

	@Select("select gd.id as goods_id, gd.title as goods_title, gdk.spec_val,gd.type from `coupon_sku` ck left join `goods_don` gd on gd.id = ck.goods_id" +
			" left join `goods_don_sku` gdk on gdk.id = ck.sku_id where ck.coupon_id = #{couponId}")
	List<GoodsDonSkuView> selectGoodsSkuViewList(Long couponId);

	@Delete("delete from coupon_sku where coupon_id = #{couponId}")
	void deleteRelationSku(Long couponId);

	@Select("select goods_id,sku_id from coupon_sku where coupon_id = #{couponId}")
	List<CouponSkuView> getGoodsSkuByCouponId(Long couponId);
}
