package com.wms.utils.excel.vo;

import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.format.DateTimeFormat;
import com.wms.entity.table.Stock;
import com.wms.entity.table.TaskRecord;
import com.wms.utils.excel.convertor.TaskStatusConvertor;
import com.wms.utils.excel.convertor.TaskTypeConvertor;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 任务记录Excel对象
 */
@Data
public class TaskRecordExcelVo {
    /**
     * 任务号
     */
    @ExcelProperty("任务id")
    private String taskId;
    /**
     * 任务类型
     */
    @ExcelProperty(value = "任务类型", converter = TaskTypeConvertor.class)
    private Integer taskType;
    /**
     * 任务状态
     */
    @ExcelProperty(value = "任务类型", converter = TaskStatusConvertor.class)
    private Integer taskStatus;
    /**
     * 起点
     */
    @ExcelProperty("起点")
    private String origin;
    /**
     * 终点
     */
    @ExcelProperty("终点")
    private String destination;
    /**
     * 任务优先级
     */
    @ExcelProperty("优先级")
    private Integer taskPriority;
    /**
     * 任务组
     */
    @ExcelProperty("任务组")
    private String taskGroup;
    /**
     * 载具号
     */
    @ExcelProperty("料箱号")
    private String vehicleId;
    /**
     * 重量
     */
    @ExcelProperty("重量")
    private BigDecimal weight;
    /**
     * 载具尺寸
     */
    @ExcelProperty("载具尺寸")
    private Integer vehicleSize;
    /**
     * 创建时间
     */
    @ExcelProperty("创建时间")
    @DateTimeFormat("yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;
    /**
     * 完成时间
     */
    @ExcelProperty("完成时间")
    @DateTimeFormat("yyyy-MM-dd HH:mm:ss")
    private LocalDateTime finishTime;
    /**
     * 用户名
     */
    @ExcelProperty("用户名")
    private String userName;
    /**
     * 物料编号
     */
    @ExcelProperty("物料编号")
    private String goodsId;
    /**
     * 物料名称
     */
    @ExcelProperty("物料描述")
    private String goodsName;
    /**
     * 操作数量
     */
    @ExcelProperty("操作数量")
    private BigDecimal opNum;
    /**
     * 原库存剩余数量
     */
    @ExcelProperty("库存数量")
    private BigDecimal originNum;
    /**
     * 前置任务号
     */
    @ExcelProperty("前置任务")
    private String preTask;
    /**
     * 是否拣选
     */
    @ExcelProperty("是否拣选")
    private Integer isPicking;
    /**
     * 拣选站台
     */
    @ExcelProperty("拣选站台")
    private String pickStand;

    /**
     * 从数据库实体转换为excel对象
     * @param recordPo 数据库实体
     * @return excel对象
     */
    public static TaskRecordExcelVo of(TaskRecord recordPo) {
        TaskRecordExcelVo recordExcelVo = new TaskRecordExcelVo();
        recordExcelVo.setTaskId(recordPo.getTaskId());
        recordExcelVo.setTaskType(recordPo.getTaskType());
        recordExcelVo.setTaskStatus(recordPo.getTaskStatus());
        recordExcelVo.setOrigin(recordPo.getOrigin());
        recordExcelVo.setDestination(recordPo.getDestination());
        recordExcelVo.setTaskPriority(recordPo.getTaskPriority());
        recordExcelVo.setTaskGroup(recordPo.getTaskGroup());
        recordExcelVo.setVehicleId(recordPo.getVehicleId());
        recordExcelVo.setWeight(recordPo.getWeight());
        recordExcelVo.setVehicleSize(recordPo.getVehicleSize());
        recordExcelVo.setCreateTime(recordPo.getCreateTime());
        recordExcelVo.setFinishTime(recordPo.getFinishTime());
        recordExcelVo.setUserName(recordPo.getUserName());
        if (recordPo.getGoodsRelated() != null) {
            recordExcelVo.setGoodsId(recordPo.getGoodsRelated().getGoodsId());
            recordExcelVo.setGoodsName(recordPo.getGoodsRelated().getGoodsName());
            recordExcelVo.setOpNum(recordPo.getGoodsRelated().getOpNum());
            recordExcelVo.setOriginNum(recordPo.getGoodsRelated().getOriginNum());
        }
        recordExcelVo.setPreTask(recordPo.getPreTask());
        recordExcelVo.setIsPicking(recordPo.getIsPicking());
        recordExcelVo.setPickStand(recordPo.getPickStand());
        return recordExcelVo;
    }
}
