package cn.pluss.platform.entity;

import cn.pluss.platform.util.DateUtils;
import cn.pluss.platform.util.StringUtil;
import cn.pluss.platform.yt.YtStatusEnum;
import cn.pluss.platform.yt.YtUpdateInfo;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

/**
 * <p>
 * 商户订单物流详情
 * </p>
 *
 * @author crystal
 * @since 2022-03-24
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@NoArgsConstructor
@TableName("tb_pluss_merc_order_express_detail")
public class MercOrderExpressDetail implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;


    @TableField("orderNo")
    private String orderNo;


    /**
     * 物流供应商 YTO：圆通
     */
    @TableField("logisticProvider")
    private String logisticProvider;


    /**
     * 物流单号
     */
    @TableField("expressNo")
    private String expressNo;

    /**
     * 上送物流单号
     */
    @TableField("logistNo")
    private String logistNo;


    /**
     * 城市
     */
    @TableField("city")
    private String city;


    /**
     * 区域(县)
     */
    @TableField("district")
    private String district;


    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    @TableField("acceptTime")
    private Date acceptTime;

    /**
     *  开始时间
     */
    @TableField(exist = false, condition = "acceptTime &gt; #{%s}")
    private Date acceptTimeStart;

    /**
     *  截止时间
     */
    @TableField(exist = false, condition = "acceptTime &lt; #{%s}")
    private Date acceptTimeEnd;

    /**
     * 备注
     */
    @TableField("remark")
    private String remark;


    /**
     * empCode
     */
    @TableField("empCode")
    private String empCode;


    /**
     * empName
     */
    @TableField("empName")
    private String empName;


    /**
     * 信息
     */
    @TableField("info")
    private String info;


    /**
     * 重量(kg)
     */
    @TableField("weight")
    private BigDecimal weight;


    @TableField("contactInfo")
    private String contactInfo;


    /**
     * 失败原因
     */
    @TableField("questionCause")
    private String questionCause;


    /**
     * 派件员姓名
     */
    @TableField("deliveryName")
    private String deliveryName;


    @TableField("orgName")
    private String orgName;


    @TableField("orgCode")
    private String orgCode;


    @TableField("orgPhone")
    private String orgPhone;


    /**
     * 创建时间
     */
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    @TableField(value = "createTime", fill = FieldFill.INSERT)
    private Date createTime;

    /**
     * 创建时间 开始时间
     */
    @TableField(exist = false, condition = "createTime &gt; #{%s}")
    private Date createTimeStart;

    /**
     * 创建时间 截止时间
     */
    @TableField(exist = false, condition = "createTime &lt; #{%s}")
    private Date createTimeEnd;

    public MercOrderExpressDetail(YtUpdateInfo data,MercOrderExpress express) {
        this.orderNo = express.getOrderNo();
        this.logisticProvider = data.getLogisticProviderID();
        this.expressNo = express.getExpressNo();
        this.city = data.getCity();
        this.district = data.getDistrict();
        if(StringUtil.isNotEmpty(data.getAcceptTime())){
            if(data.getAcceptTime().contains("CST")){
                String acceptTime = data.getAcceptTime().replace("CST","");
                this.acceptTime = DateUtils.parse(acceptTime,"yyyy-MM-ddHH:mm:ss");
            }else{
                this.acceptTime = DateUtils.parse(data.getAcceptTime(),"yyyy-MM-ddHH:mm:ss");
            }
        }else{
            this.acceptTime = DateUtils.currentDate();
        }
        this.remark = data.getRemark();
        this.empCode = data.getEmpCode();
        this.empName = data.getEmpName();
//        String infoType = StringUtil.isNotEmpty(data.getInfoType()) ? data.getInfoType() : "";
//        String infoDesc = StringUtil.isNotEmpty(data.getInfoContent()) ? data.getInfoContent() : "";
        this.info = YtStatusEnum.getDescByCode(data.getInfoContent());
        this.weight = data.getWeight();
        this.contactInfo = data.getContactInfo();
        this.questionCause = data.getQuestionCause();
        this.deliveryName = data.getDeliveryName();
        this.orgName = data.getOrgName();
        this.orgCode = data.getOrgCode();
        this.orgPhone = data.getOrgPhone();
        this.logistNo = data.getTxLogisticID();
    }
}