package com.ruoyi.demo.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.ruoyi.demo.entity.bo.OrderAddBo;
import lombok.Data;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

@Data
@TableName("dl_order")
public class Order {
    @TableField("order_id")
    private String orderId;

    @TableField("vendor_id")
    private String vendorId;
    @TableField("vendor_name")
    private String vendorName;

    @TableField("goods_id")
    private String goodsId;
    @TableField("goods_name")
    private String goodsName;
    @TableField("specs")
    private String specs;
    @TableField("goods_price")
    private Float goodsPrice;
    @TableField("total_price")
    private Float totalPrice;
    @TableField("state")
    private String state;
    @TableField("user_id")
    private String userId;
    @TableField("user_name")
    private String userName;
    @TableField("user_telephone")
    private String userTelephone;
    @TableField("appkey")
    private String appkey;
    @TableField("app_name")
    private String appName;
    @TableField("create_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    private LocalDateTime createTime;

    @TableField("deleted")
    private int deleted;

    public Order() {}
    public Order (OrderAddBo bo, App app){
        this.orderId = bo.getOrderId();
        this.vendorId = bo.getVendorId();
        this.vendorName = bo.getVendorName();
        this.goodsId = bo.getGoodsId();
        this.goodsName = bo.getGoodsName();
        this.goodsPrice = bo.getGoodsPrice();
        this.specs = bo.getSpecs();
        this.totalPrice = bo.getDealCount() * bo.getGoodsPrice();
        this.state = bo.getState();
        this.userId = bo.getUserId();
        this.userName = bo.getUserName();
        this.userTelephone = bo.getUserTelephone();
        this.appkey = bo.getAppkey();
        this.appName = app.getAppName();
        this.createTime = bo.getTime();
    }

}
