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.Date;
import java.util.List;

/**
 * @author zwhui
 * @date 2023/9/15 09:42
 */
@Data
@SearchBean(tables = "yh_shop_goods_sku ysgs left join goods_don g on g.id = ysgs.goods_id" +
        " left join goods_don_sku sku on sku.id = ysgs.sku_id",
        where = "ysgs.deleted is true and g.status is true and g.deleted is true and sku.status is true and g.is_distribute is true"
        , groupBy = "g.id,g.title,g.category,ysgs.status,ysgs.user_id")
public class YhShopGoodsView {
    @DbField("g.id")
    private Long goodsId;

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

    @DbField("select group_concat(gc.name) from goods_don_category_relate gcr left join goods_don_category gc on gc.id = gcr.category where goods_id = g.id")
    private String categoryName;

    @DbField("ysgs.status")
    private Boolean status;

    @DbField("ysgs.user_id")
    private Long userId;

    @DbField("group_concat(sku.spec_val,cast((ysgs.price/100) as decimal(10,2)),'元')")
    private String skuDetail;

    @DbField("any_value(ysgs.created_time)")
    private Date createdTime;

    @DbField("any_value(ysgs.update_time)")
    private Date updateTime;

    @DbIgnore
    private List<YhShopGoodsSkuView> list;

    @Data
    @SearchBean(tables = "goods_don_sku gs inner join yh_shop_goods_rate ysgr on gs.id = ysgr.sku_id left join yh_shop_goods_sku ysgs on gs.id = ysgs.sku_id and ysgs.deleted is true :uid:",
            where = "gs.status = true",
            orderBy = "gs.months")
    public static class YhShopGoodsSkuView{
        @DbField("ysgs.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("gs.price")
        private BigDecimal price;

        @DbField("ysgs.price")
        private BigDecimal shopSkuPrice;

        @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;
    }
}
