package cn.iocoder.yudao.module.order.vo.orderItem;

import cn.iocoder.yudao.module.order.vo.order.WarehouseCheckInfoVO;
import cn.iocoder.yudao.module.order.vo.order.WarehouseInInfoVO;
import cn.iocoder.yudao.module.order.vo.orderException.ExceptionTypeResultVO;
import cn.iocoder.yudao.module.product.vo.coupon.CouponInfoVO;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.TableField;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Objects;

import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;

/**
* 订单项 Response VO
* @author 系统管理员
*/
@Data
@ApiModel("管理后台 - 订单项 Response VO")
public class OrderItemBackVO {

    @ExcelProperty("主键ID")
    @ApiModelProperty(value = "主键ID", required = true)
    private Long orderItemId;

    @ExcelProperty("订单ID")
    @ApiModelProperty(value = "订单ID", required = true)
    private Long orderId;

    @ExcelProperty("订单编号")
    @ApiModelProperty(value = "订单编号", required = true)
    private String orderNo;

    @ExcelProperty("订单编号")
    @ApiModelProperty(value = "订单类型：1 普货 2 重货 3 泡货")
    private Integer orderItemType;

    @ExcelProperty("运输方式id")
    @ApiModelProperty(value = "运输方式id", required = true)
    private Integer transportId;

    @ExcelProperty("线路ID")
    @ApiModelProperty(value = "线路ID", required = true)
    private Long lineId;

    @ExcelProperty("渠道ID")
    @ApiModelProperty(value = "渠道ID")
    private Long channelId;

    @ExcelProperty("订单项状态详情见字典")
    @ApiModelProperty(value = "订单项状态详情见字典")
    private Integer itemStatus;

    @ExcelProperty("商品ID")
    @ApiModelProperty(value = "商品ID", required = true)
    private Long prodId;

    @ExcelProperty("产品类型")
    @ApiModelProperty(value = "产品类型")
    private Integer prodType;

    @ExcelProperty("产品中文标题")
    @ApiModelProperty(value = "产品中文标题")
    private String prodTitleZh;

    @ExcelProperty("产品英文标题")
    @ApiModelProperty(value = "产品英文标题")
    private String prodTitleEn;

    @ExcelProperty("商品第三方链接")
    @ApiModelProperty(value = "商品第三方链接")
    private String link;

    @ExcelProperty("品牌ID")
    @ApiModelProperty(value = "品牌ID", required = true)
    private Long brand;

    @ExcelProperty("品牌名称")
    @ApiModelProperty(value = "品牌名称")
    private String brandName;

    @ExcelProperty("0 无牌 1 有牌 2 中性")
    @ApiModelProperty(value = "0 无牌 1 有牌 2 中性", required = true)
    private Integer brandType;

    @ExcelProperty("费用模式")
    @ApiModelProperty(value = "费用模式：无牌价0，有牌价1，中性品牌价2", required = true)
    private Integer feeType;

    @ApiModelProperty(value = "是否预付：0 到付 1 预付")
    private Integer isPayAdvance;

    @ApiModelProperty(value = "计费方式：0 运费/清关费 1 全包价")
    private Integer charging;

    @ApiModelProperty(value = "数量")
    private Integer quantity;

    @ExcelProperty("件数")
    @ApiModelProperty(value = "件数", required = true)
    private Integer num;

    @ExcelProperty("单位")
    @ApiModelProperty(value = "单位", required = true)
    private String unit;

    @ExcelProperty("箱规")
    @ApiModelProperty(value = "箱规")
    private String boxGauge;

    @ExcelProperty("体积")
    @ApiModelProperty(value = "体积")
    private BigDecimal volume;

    @ExcelProperty("重量")
    @ApiModelProperty(value = "重量")
    private BigDecimal weight;

    @ExcelProperty("货值")
    @ApiModelProperty(value = "货值")
    private BigDecimal worth;

    @ExcelProperty("货值金额单位ID")
    @ApiModelProperty(value = "货值金额单位ID")
    private Integer worthCurrency;

    @ExcelProperty("商品特性(可选多个特性ID)")
    @ApiModelProperty(value = "商品特性(可选多个特性ID)")
    private String prodAttrIds;

    @ApiModelProperty(value = "商品特性名称列表")
    private List<String> attrNameList;

    @ExcelProperty("入仓商品特性(可选多个特性ID)")
    @ApiModelProperty(value = "入仓商品特性(可选多个特性ID)")
    private String warehouseInProdAttrIds;

    @ExcelProperty(value = "结果")
    @ApiModelProperty(value = "结果")
    private String result;

    @ExcelProperty("结果状态(多个以逗号拼接，状态详情")
    @ApiModelProperty(value = "结果状态(多个以逗号拼接，状态详情")
    private String resultStatus;

    @ApiModelProperty(value = "是否特价")
    private Boolean specialPriceType;

    @ApiModelProperty(value = "是否拆单自定义价格")
    private Boolean splitCustomPriceType;
    /**
     * 是否为渠道/单询手动定价
     */
    @ApiModelProperty(value = "是否为确认渠道/单询手动定价/重量超限异常定价")
    private Boolean channelManualPricing;

    @ExcelProperty("运费单价(成交/销售)")
    @ApiModelProperty(value = "运费单价")
    private BigDecimal oneSeaFreight = BigDecimal.ZERO;

    @ExcelProperty("旧运费单价(成交/销售)")
    @ApiModelProperty(value = "旧运费单价")
    private BigDecimal oldOneSeaFreight = BigDecimal.ZERO;

    @ApiModelProperty(value = "特价列表中的原价(原始价格(无牌无液无电)+特殊加价-优惠)")
    private BigDecimal originalCostSeaFreight;

    @ExcelProperty("成本运费")
    @ApiModelProperty(value = "成本运费(成本)")
    private BigDecimal costSeaFreight;

    @ExcelProperty("运费(小计)")
    @ApiModelProperty(value = "运费(小计)")
    private BigDecimal seaFreight;

    @ExcelProperty("原来运费")
    @ApiModelProperty(value = "原来运费(原始无牌无液无电价格)")
    private BigDecimal originalSeaFreight;

    @ExcelProperty("运费货币单位ID")
    @ApiModelProperty(value = "运费货币单位ID")
    private Integer seaFreightCurrency;

    @ExcelProperty("运费体积单位")
    @ApiModelProperty(value = "运费体积单位")
    private Long seaFreightVolume;

    @ApiModelProperty(value = "清关费单价(成交)")
    private BigDecimal oneClearanceFreight = BigDecimal.ZERO;

    @ApiModelProperty(value = "旧清关费单价(成交)")
    private BigDecimal oldOneClearanceFreight = BigDecimal.ZERO;

    @ApiModelProperty(value = "清关费(小计)")
    private BigDecimal clearanceFreight;

    @ApiModelProperty(value = "原清关费(原始无牌无液无电价格)")
    private BigDecimal originalClearanceFreight;

    @ApiModelProperty(value = "特价列表中的原价(原始价格(无牌无液无电)+特殊加价-优惠)")
    private BigDecimal originalCostClearanceFreight;

    @ExcelProperty("成本清关费")
    @ApiModelProperty(value = "成本清关费(成本)")
    private BigDecimal costClearanceFreight;

    @ExcelProperty("清关费货币单位ID")
    @ApiModelProperty(value = "清关费货币单位ID")
    private Integer clearanceFreightCurrency;

    @ExcelProperty("清关费体积单位")
    @ApiModelProperty(value = "清关费体积单位")
    private Long clearanceFreightVolume;

    @ExcelProperty("创建时间")
    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    @ApiModelProperty(value = "创建时间", required = true)
    private Date createTime;

    @ExcelProperty("快递单号")
    @ApiModelProperty("快递单号")
    private String expressNo;

    @ApiModelProperty(value = "重货体积")
    private String wVolume;

    @ApiModelProperty(value = "泡货重量")
    private String vWeight;

    @ApiModelProperty(value = "实际收费数量")
    private String qQuantity;


    @ApiModelProperty(value = "转换使用重货体积")
    private BigDecimal weVolume;

    @ApiModelProperty(value = "转换使用泡货重量")
    private BigDecimal voWeight;

    @ApiModelProperty(value = "重货标准基数")
    private BigDecimal weightUnit;

    @ApiModelProperty(value = "泡货标准基数")
    private BigDecimal volumeUnit;


    @ApiModelProperty(value = "最小计量重量")
    private BigDecimal minMeteringWeight = BigDecimal.ZERO;

    @ApiModelProperty(value = "最小计量体积")
    private BigDecimal minMeteringVolume  = BigDecimal.ZERO;

    @ApiModelProperty(value = "最小计量个数")
    private BigDecimal minMeteringQuantity  = BigDecimal.ZERO;

    @ApiModelProperty(value = "收费重量")
    private BigDecimal chargeWeight;

    @ApiModelProperty(value = "收费体积")
    private BigDecimal chargeVolume;

    @ApiModelProperty(value = "收费个数")
    private BigDecimal chargeQuantity;

    @ApiModelProperty(value = "初始收费重量")
    private BigDecimal initialChargeWeight;

    @ApiModelProperty(value = "初始收费体积")
    private BigDecimal initialChargeVolume;

    @ApiModelProperty(value = "初始收费个数")
    private BigDecimal initialChargeQuantity;

    @ApiModelProperty(value = "订单项属性：1 普货 2 重货 3 泡货")
    private Integer itemType;

    @ApiModelProperty(value = "货比-重货的订单比(不计算普货订单项)")
    private BigDecimal weightRatio;

    @ApiModelProperty(value = "货比-泡货的订单比(不计算普货订单项)")
    private BigDecimal volumeRatio;

    @ApiModelProperty(value = "应收运费(成本) = 应收单价 * 原始重泡货标准的收费数据")
    private BigDecimal receivableSeaFreight;

    @ApiModelProperty(value = "应收清关费(成本) = 应收单价 * 原始重泡货标准的收费数据")
    private BigDecimal receivableClearanceFreight;

    @ApiModelProperty(value = "应收收费数量")
    private BigDecimal orgChargeQuantity = BigDecimal.ZERO;

    @ApiModelProperty(value = "应收收费件数")
    private Integer orgChargeNum = 0;

    @ApiModelProperty(value = "应收收费体积")
    private BigDecimal orgChargeVolume = BigDecimal.ZERO;

    @ApiModelProperty(value = "应收收费重量")
    private BigDecimal orgChargeWeight = BigDecimal.ZERO;

    @ApiModelProperty(value = "是否处理了渠道特性异常")
    private Boolean handlerChannelAttrException;
    /**
     * 入仓信息json
     */
    @ApiModelProperty(value = "入仓信息VO")
    @TableField(exist = false)
    private WarehouseInInfoVO warehouseInInfoVO;
    /**
     * 是否仓库入仓新品
     */
    @ApiModelProperty(value = "是否仓库入仓新品 0 下单货物  1 非下单货物-即新品 ")
    private Boolean isWarehouseInAdd;

    /**
     * 入仓信息json
     */
    @ApiModelProperty(value = "入仓信息json")
    private String warehouseInInfo;
    /**
     * 材质
     */
    @ApiModelProperty(value = "材质")
    private String material;

    @ApiModelProperty("用途")
    private String usageIds;

    /**
     * 材质
     */
    @ApiModelProperty(value = "更新时间")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;

    @ApiModelProperty(value = "佣金类型：0 无 1 明佣 2 暗佣 3 明+暗")
    private Integer commissionType;

    @ApiModelProperty("明佣金额")
    private BigDecimal plainCommission = BigDecimal.ZERO;

    @ApiModelProperty("暗佣金额")
    private BigDecimal hiddenCommission = BigDecimal.ZERO;

    @ApiModelProperty(value = "活动优惠运费金额(原始单价上进行优惠)")
    private BigDecimal discountFreightPrice = BigDecimal.ZERO;

    @ApiModelProperty(value = "活动优惠运费总金额")
    private BigDecimal discountFreightTotalPrice = BigDecimal.ZERO;

    @ApiModelProperty(value = "活动优惠清关费金额(原始单价上进行优惠)")
    private BigDecimal discountClearanceFeePrice = BigDecimal.ZERO;

    @ApiModelProperty(value = "活动优惠清关费总金额")
    private BigDecimal discountClearanceFeeTotalPrice = BigDecimal.ZERO;

    @ApiModelProperty(value = "是否已定价")
    private Boolean isPriced = Boolean.FALSE;

    @ApiModelProperty(value = "液体清关费单价")
    private BigDecimal liquidClearanceFeePrice = BigDecimal.ZERO;

    @ApiModelProperty(value = "液体运费单价")
    private BigDecimal liquidFreightPrice = BigDecimal.ZERO;

    @ApiModelProperty(value = "带电清关费单价")
    private BigDecimal electrifiedClearanceFeePrice = BigDecimal.ZERO;

    @ApiModelProperty(value = "带电运费单价")
    private BigDecimal electrifiedFreightPrice = BigDecimal.ZERO;

    @ApiModelProperty(value = "品牌清关费单价")
    private BigDecimal brandClearanceFeePrice = BigDecimal.ZERO;

    @ApiModelProperty(value = "品牌运费单价")
    private BigDecimal brandFreightPrice = BigDecimal.ZERO;

    @ApiModelProperty(value = "包装清关费单价")
    private BigDecimal packagingClearanceFeePrice = BigDecimal.ZERO;

    @ApiModelProperty(value = "包装运费单价")
    private BigDecimal packagingFreightPrice = BigDecimal.ZERO;

    @ApiModelProperty(value = "是否特价佣金设置")
    private Boolean specialCommission = Boolean.FALSE;

    @ApiModelProperty(value = "使用的优惠信息")
    private String couponInfo;


    @ApiModelProperty(value = "原订单项id")
    private Long orgItemId;

    @ApiModelProperty(value = "'空运加价运费单价'")
    private BigDecimal markupSeaFreight = BigDecimal.ZERO;

    @ApiModelProperty(value = "'空运加价清关费单价'")
    private BigDecimal markupClearanceFreight = BigDecimal.ZERO;

    @ApiModelProperty(value = "空运清关费来源：1 商品 2 渠道")
    private Integer airClearanceSource;

    @ApiModelProperty(value = "'空运清关费来源数据详情'")
    private String airClearanceInfo;

    @ApiModelProperty(value = "使用的优惠详情列表")
    private List<CouponInfoVO> couponInfoVOList;

    @ApiModelProperty(value = "优惠后运费单价")
    private BigDecimal afterDiscountSeaFreight = BigDecimal.ZERO;

    @ApiModelProperty(value = "优惠后清关费单价")
    private BigDecimal afterDiscountClearanceFreight = BigDecimal.ZERO;

    @ApiModelProperty(value = "是否需要单询，0-否，1-是")
    private Integer needOrderInquiry;

    @ApiModelProperty(value = "是否处理过单询异常")
    private Boolean isHandlerOrderInquiryException;

    @ApiModelProperty(value = "订单项入仓影像列表")
    private List<String> pictureUrls;

    @ApiModelProperty(value = "入仓类型，多个用逗号分隔")
    private String warehouseType ;

    @ApiModelProperty(value = "入仓包装单位，多个用逗号分隔")
    private String specificationType ;

    @ApiModelProperty(value = "入仓记录备注，多个用逗号分隔")
    private String warehouseRecordRemark ;

    @ApiModelProperty(value = "到仓商品ID")
    private Long checkProdId;

    @ApiModelProperty(value = "到仓产品类型")
    private Integer checkProdType;

    @ApiModelProperty(value = "到仓产品中文标题")
    private String checkProdTitleZh;

    @ApiModelProperty(value = "到仓产品英文标题")
    private String checkProdTitleEn;

    @ApiModelProperty(value = "到仓材质")
    private String checkMaterial;

    @ApiModelProperty(value = "到仓商品特性(可选多个特性ID)")
    private String warehouseCheckProdAttrIds;

    @ApiModelProperty(value = "到仓品牌")
    private Long checkBrand;

    @ApiModelProperty(value = "到仓：0 无牌 1 有牌 2 中性")
    private Integer checkBrandType;
    /**
     * 到仓信息json
     */
    @ApiModelProperty(value = "到仓信息json")
    private String warehouseCheckInfo;

    /**
     * 到仓信息json
     */
    @ApiModelProperty(value = "到仓信息VO")
    private WarehouseCheckInfoVO warehouseCheckInfoVO;

    @ExcelProperty("到仓品牌名称")
    @ApiModelProperty(value = "到仓品牌名称")
    private String checkBrandName;

    @ApiModelProperty(value = "订单项到仓影像列表")
    private List<String> checkPictureUrls;

    @ApiModelProperty(value = "订单项到仓异常登记列表")
    private List<ExceptionTypeResultVO> itemExceptionList;

    public void setWarehouseCheckInfo(String warehouseCheckInfo) {
        this.warehouseCheckInfo = warehouseCheckInfo;
        if (StringUtils.isNotBlank(warehouseCheckInfo)) {
            this.warehouseCheckInfoVO = JSONObject.parseObject(warehouseCheckInfo, WarehouseCheckInfoVO.class);
        }
    }

    public void setWarehouseCheckInfoVO(WarehouseCheckInfoVO warehouseCheckInfoVO) {
        this.warehouseCheckInfoVO = warehouseCheckInfoVO;
        if (Objects.nonNull(warehouseCheckInfoVO)) {
            this.warehouseCheckInfo = JSONObject.toJSONString(warehouseCheckInfoVO);
        }
    }


    public void setCouponInfo(String couponInfo) {
        this.couponInfo = couponInfo;
        if (StringUtils.isNotBlank(couponInfo)){
            this.couponInfoVOList = JSONObject.parseArray(couponInfo, CouponInfoVO.class);
        }
    }

    public void setWarehouseInInfo(String warehouseInInfo) {
        this.warehouseInInfo = warehouseInInfo;
        this.warehouseInInfoVO = JSONObject.parseObject(warehouseInInfo, WarehouseInInfoVO.class);

    }

    public void setWarehouseInInfoVO(WarehouseInInfoVO warehouseInInfoVO) {
        this.warehouseInInfoVO = warehouseInInfoVO;
        if (Objects.nonNull(warehouseInInfoVO)) {
            this.warehouseInInfo = JSONObject.toJSONString(warehouseInInfoVO);
        }
    }

//    public void setItemStatus(Integer itemStatus) {
//        this.itemStatus = itemStatus;
//        if(itemStatus == -1){
//            this.isPayAdvance = null;
//        }
//    }
//
//    public void setIsPayAdvance(Integer isPayAdvance) {
//        this.isPayAdvance = isPayAdvance;
//        if(itemStatus == null) return;
//        if (-1 == itemStatus){
//            this.isPayAdvance = null;
//        }
//    }



    /**
     * 初始价：线路无牌无液无电价
     * 特性加价：有牌+有液+带电+中性加价
     * 优惠金额：优惠活动减免
     * 原价=初始价+特性加价-优惠金额
     * 成本价=原价-暗佣佣金
     * 销售价=原价+明佣佣金
     * 佣金返点=销售价-成本价=暗佣+明佣
     **/
//    public void setOriginalSeaFreight(BigDecimal originalSeaFreight) {
//        this.originalSeaFreight = originalSeaFreight;
//        if (Objects.nonNull(this.hiddenCommission)) {
//            // 成本价=原价-暗佣佣金
//            this.costSeaFreight = originalSeaFreight.subtract(this.hiddenCommission);
//        }
//    }


//    public void setOneSeaFreight(BigDecimal oneSeaFreight) {
//        this.oneSeaFreight = oneSeaFreight;
//        if (Objects.nonNull(oneSeaFreight) && Objects.nonNull(this.plainCommission) && Objects.nonNull(this.hiddenCommission)) {
//            // 原价=销售价-明佣
//            this.originalCostSeaFreight = this.oneSeaFreight.subtract(this.plainCommission);
//            // 成本价=原价-暗佣
//            this.costSeaFreight = this.originalCostSeaFreight.subtract(hiddenCommission);
//        }
//    }
//
//    public void setPlainCommission(BigDecimal plainCommission) {
//        this.plainCommission = plainCommission;
//        if (Objects.nonNull(this.originalSeaFreight) && && Objects.nonNull(this.hiddenCommission)) {
//            // 原价= 原始价格(无牌无液无电)+特殊加价-优惠
//            this.originalCostSeaFreight = this.oneSeaFreight.subtract(this.plainCommission);
//            // 成本价=原价-暗佣
//            this.costSeaFreight = this.originalCostSeaFreight.subtract(this.plainCommission).subtract(hiddenCommission);
//        }
//    }
//
//    public void setHiddenCommission(BigDecimal hiddenCommission) {
//        this.hiddenCommission = hiddenCommission;
//        if (Objects.nonNull(this.oneSeaFreight) && Objects.nonNull(this.plainCommission) && Objects.nonNull(hiddenCommission)) {
//            // 原价=销售价-明佣
//            this.originalCostSeaFreight = this.oneSeaFreight.subtract(this.plainCommission);
//            // 成本价=原价-暗佣
//            this.costSeaFreight = this.oneSeaFreight.subtract(this.plainCommission).subtract(hiddenCommission);
//        }
//    }
}
