package com.trade.service.trade.salesorder.domain;

import java.math.BigDecimal;
import java.util.Optional;

import com.alibaba.fastjson2.util.DateUtils;
import com.baomidou.mybatisplus.annotation.TableName;
import com.trade.common.core.domain.BizBaseEntity;

import com.trade.service.thirdparty.xiaotu.dto.CustomsDeclarationResponse;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * <p>
 * 报关单信息
 * </p>
 *
 * @author zhangchenm
 * @since 2024-09-19
 */
@Getter
@Setter
@TableName("customs_declaration")
@NoArgsConstructor
public class CustomsDeclaration extends BizBaseEntity {

    private static final long serialVersionUID = 1L;
    /**
     * 销售订单no,对应小图合同号
     */
    private String saleOrderNo;

    /**
     * 是否已关联入账
     */
    private Boolean relatedEntryInd;
    /**
     * 报关申报状态代码
     */
    private String bgsbztDm;
    /**
     * 报关单海关编号
     */
    private String bgdhgbh;
    /**
     * 海关企业代码
     */
    private String hgqyDm;
    /**
     * 出口日期
     */
    private String ckrq1;
    /**
     * 申报海关关区（口岸）代码
     */
    private String sbhggqkaDm;
    /**
     * 申报海关关区（口岸）简称
     */
    private String sbhggqkajc;
    /**
     * 运费金额
     */
    private BigDecimal yfje;
    /**
     * 运费海关货币字母代码
     */
    private String yfhghbzmDm;
    /**
     * 保费金额
     */
    private BigDecimal bfje;
    /**
     * 保费海关货币字母代码
     */
    private String bfhghbzmDm;
    /**
     * 杂费金额
     */
    private BigDecimal zfje1;
    /**
     * 杂费海关货币字母代码
     */
    private String zfhghbzmDm;
    /**
     * 件数
     */
    private BigDecimal js1;
    /**
     * 毛重（千克）
     */
    private BigDecimal mz2;
    /**
     * 净重（千克）
     */
    private BigDecimal jz;
    /**
     * 海关出口货物报关单申报日期
     */
    private String hgckhwbgdsbrq;
    /**
     * 申报单位名称
     */
    private String sbdwmc;
    /**
     * 集装箱号
     */
    private String jzxh;

    public CustomsDeclaration(CustomsDeclarationResponse customsDeclarationResponse){
        setSaleOrderNo(customsDeclarationResponse.getCkhth());// 销售订单号 = 小图合同号
        setBgsbztDm(customsDeclarationResponse.getBgsbztDm());
        // 时间戳转换为“yyyy-MM-dd”格式
        setCkrq1(Optional.ofNullable(customsDeclarationResponse.getCkrq1())
                .map(e -> DateUtils.format(Long.parseLong(e)).substring(0, 10)).orElse(null));
        setBfhghbzmDm(customsDeclarationResponse.getBfhghbzmDm());
        setBgdhgbh(customsDeclarationResponse.getBgdhgbh());
        setHgckhwbgdsbrq(Optional.ofNullable(customsDeclarationResponse.getHgckhwbgdsbrq())
                .map(e -> DateUtils.format(Long.parseLong(e)).substring(0, 10)).orElse(null));
        setHgqyDm(customsDeclarationResponse.getHgqyDm());
        setZfhghbzmDm(customsDeclarationResponse.getZfhghbzmDm());
        setSbdwmc(customsDeclarationResponse.getSbdwmc());
        setSbhggqkajc(customsDeclarationResponse.getSbhggqkajc());
        setSbhggqkaDm(customsDeclarationResponse.getSbhggqkaDm());
        setYfhghbzmDm(customsDeclarationResponse.getYfhghbzmDm());
    }
}
