package com.cyksj.model.views;

import com.ejlchina.searcher.bean.DbField;
import com.ejlchina.searcher.bean.DbIgnore;
import com.ejlchina.searcher.bean.SearchBean;
import lombok.Data;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author zwhui
 * @date 2023/9/14 14:20
 */
@Data
@SearchBean(tables = "goods_don g left join goods_don_category_relate gcr on gcr.goods_id = g.id left join goods_don_category gc on gc.id = gcr.category",
		where = "g.type = 1 and g.status = true and g.deleted = true and g.is_distribute is true",
		groupBy = "g.id,g.title")
public class YhShopGoodsRateView {
    @DbField("g.id")
    private Long goodsId;

    @DbField("g.title")
    private String title;

    @DbField("group_concat(gc.name)")
    private String categoryName;

    @DbIgnore
    private List<YhShopGoodsSkuRateView> list;

    @Data
    @SearchBean(tables = "goods_don_sku gs left join yh_shop_goods_rate ysgr on gs.id = ysgr.sku_id",
            where = "gs.status = true ")
    public static class YhShopGoodsSkuRateView{
        @DbField("ysgr.id")
        private Long id;

        @DbField("gs.goods_id")
        private Long goodsId;
        @DbField("gs.id")
        private Long skuId;

        /**
         * 商品规格 value
         */
        @DbField("gs.spec_val")
        private String specVal;

        @DbField("ysgr.rate")
        private Integer rate;

        @DbField("gs.price")
        private BigDecimal price;

        @DbField("IFNULL(CAST((gs.price - gs.price * (ysgr.rate / 100)) as SIGNED),gs.price)")
        private BigDecimal minPrice;

        @DbField("IFNULL(CAST((gs.price + gs.price * (ysgr.rate / 100)) as SIGNED),gs.price)")
        private BigDecimal maxPrice;

    }
}
