package com.ruoyi.demo.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
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 com.ruoyi.demo.entity.bo.StatisticsAddBo;
import lombok.Data;

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

@Data
@TableName("dl_statistics")
public class Statistics {
    @TableId(value = "statistics_id",type = IdType.ASSIGN_ID)
    private String statisticsId;

    @TableField("appkey")
    private String appkey;
    @TableField("equipment_id")
    private String equipmentId;
    @TableField("equipment_name")
    private String equipmentName;
    @TableField("equipment_code")
    private String equipmentCode;

    @TableField("addr_info")
    private String addrInfo;

    @TableField("goods_id")
    private String goodsId;
    @TableField("goods_name")
    private String goodsName;
    @TableField("vendor_id")
    private String vendorId;
    @TableField("vendor_name")
    private String vendorName;

    @TableField("deal_tool_count")
    private Integer dealToolCount;
    @TableField("deal_tool_price")
    private Float dealToolPrice;
    @TableField("user_id")
    private String userId;
    @TableField("user_name")
    private String userName;
    @TableField("user_telephone")
    private String userTelephone;
    @TableField("behavior")
    private Integer behavior;
    @TableField("time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    private LocalDateTime time;

    @TableField("deleted")
    private int deleted;

    public Statistics (){}
    // 客户扫码时调用
    public Statistics (StatisticsAddBo bo, Equipment equipment){
        this.appkey = bo.getAppkey();
        this.equipmentId = equipment.getEquipmentId();
        this.equipmentCode = bo.getEquipmentCode();
        this.equipmentName = equipment.getEquipmentName();
        this.addrInfo = equipment.getAddrInfo();
        this.goodsId = bo.getGoodsId();
        this.goodsName = bo.getGoodsName();
        this.vendorId = bo.getVendorId();
        this.vendorName = bo.getVendorName();
        this.dealToolCount = 0;
        this.dealToolPrice = Float.valueOf(0);
        this.userId = bo.getUserId();
        this.userName = bo.getUserName();
        this.userTelephone = bo.getUserTelephone();
        this.behavior = 0;
        this.time = bo.getTime();
    }
    // 客户交易时调用
    public Statistics (OrderAddBo bo, Equipment equipment){
        this.appkey = bo.getAppkey();
        this.equipmentId = equipment.getEquipmentId();
        this.equipmentCode = bo.getEquipmentCode();
        this.equipmentName = equipment.getEquipmentName();
        this.addrInfo = equipment.getAddrInfo();
        this.goodsId = bo.getGoodsId();
        this.goodsName = bo.getGoodsName();
        this.vendorId = bo.getVendorId();
        this.vendorName = bo.getVendorName();
        this.dealToolCount = bo.getDealCount();
        this.dealToolPrice = bo.getGoodsPrice() * bo.getDealCount();
        this.userId = bo.getUserId();
        this.userName = bo.getUserName();
        this.userTelephone = bo.getUserTelephone();
        this.behavior = 1;
        this.time = bo.getTime();
    }
}
