package org.jeecg.modules.itdmGongDan.dto;


import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.jeecg.common.aspect.annotation.Dict;
import org.jeecg.modules.itdmGongDan.entity.ItdmGongdanMaster;
import org.jeecg.modules.itdmGongDan.entity.ItdmTestPlan;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;

@Data
@Accessors(chain = true)
public class ItdmXMJLAddOrUpdateDTO {

    /**委托id*/
    @Excel(name = "委托id", width = 15)
    @ApiModelProperty(value = "委托id")
    private String weituoId;
    /**样品id*/
    @Excel(name = "样品id", width = 15)
    @ApiModelProperty(value = "样品id")
    private String yangpinId;
    /**检测项目id*/
    @Excel(name = "检测项目id", width = 15)
    @ApiModelProperty(value = "检测项目id")
    private java.lang.String testItemsId;
    /**检测项目*/
    @Excel(name = "检测项目", width = 15)
    @ApiModelProperty(value = "检测项目")
    private String testItems;
    /**试验计划id*/
    @Excel(name = "试验计划id", width = 15)
    @ApiModelProperty(value = "试验计划id")
    private String testPlanId;
    /**设备id*/
    @Excel(name = "设备id", width = 15)
    @ApiModelProperty(value = "设备id")
    private java.lang.String shebeiId;
    /**项目经理*/
    @Excel(name = "项目经理", width = 15)
    @ApiModelProperty(value = "项目经理")
    private java.lang.String pm;
    /**计划开始日期*/
    @Excel(name = "计划开始日期", width = 15, format = "yyyy-MM-dd")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern="yyyy-MM-dd")
    @ApiModelProperty(value = "计划开始日期")
    private java.util.Date jihuaStartDate;
    /**计划结束日期*/
    @Excel(name = "计划结束日期", width = 15, format = "yyyy-MM-dd")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern="yyyy-MM-dd")
    @ApiModelProperty(value = "计划结束日期")
    private java.util.Date jihuaEndDate;
    /**状态*/
    @Excel(name = "状态", width = 15, dicCode = "test_plan_status")
    @Dict(dicCode = "test_plan_status")
    @ApiModelProperty(value = "状态")
    private java.lang.Integer status;
    /**报告编号*/
    @Excel(name = "报告编号", width = 15)
    @ApiModelProperty(value = "报告编号")
    private java.lang.String reportNo;
    /**传感器id*/
    @Excel(name = "传感器id", width = 20)
    @ApiModelProperty(value = "传感器id")
    private java.lang.String chuanganqi;
    /**委托编号*/
    @Excel(name = "委托编号", width = 15)
    @ApiModelProperty(value = "委托编号")
    private String weituoNo;
    /**样品名称*/
    @Excel(name = "样品名称", width = 15)
    @ApiModelProperty(value = "样品名称")
    private java.lang.String sampleName;
    /**设备名称*/
    @Excel(name = "设备名称", width = 15)
    @ApiModelProperty(value = "设备名称")
    private java.lang.String deviceName;
    /**父id*/
    @Excel(name = "父id", width = 20)
    @ApiModelProperty(value = "父id")
    private java.lang.String parent;
    /**持续时间*/
    @Excel(name = "持续时间", width = 20)
    @ApiModelProperty(value = "持续时间")
    private java.lang.Integer lastTime;
    /**试验类型*/
    @Excel(name = "试验类型", width = 15)
    @ApiModelProperty(value = "试验类型")
    private java.lang.String shiiyanType;
    /**试验员*/
    @Excel(name = "试验员", width = 15)
    @ApiModelProperty(value = "试验员")
    private java.lang.String worker;
    /**委托样品数量*/
    @Excel(name = "委托样品数量", width = 15)
    @ApiModelProperty(value = "委托样品数量")
    private java.lang.Integer yangpinCount;
    /**内容*/
    @Excel(name = "内容", width = 15)
    @ApiModelProperty(value = "内容")
    private java.lang.String neirong;
    /**status转化*/
    @Excel(name = "status转化", width = 15)
    @ApiModelProperty(value = "status转化")
    private java.lang.String statusC;
    /**实绩开始日期*/
    @Excel(name = "实绩开始日期", width = 15, format = "yyyy-MM-dd")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern="yyyy-MM-dd")
    @ApiModelProperty(value = "实绩开始日期")
    private java.util.Date shijiStartDate;
    /**试验计划id或工单master的id*/
    @Excel(name = "试验计划id或工单master的id", width = 15)
    @ApiModelProperty(value = "试验计划id或工单master的id")
    private String id;
    /**传感器数组*/
    @Excel(name = "传感器数组", width = 15)
    @ApiModelProperty(value = "传感器数组")
    private java.lang.String[] chuanganqiArray;
    /**试验类型数组*/
    @Excel(name = "试验类型数组", width = 15)
    @ApiModelProperty(value = "试验类型数组")
    private java.lang.String[] shiiyanTypeArray;


    /**
     * 将二级对象转化为工单master，用于新增或修改
     * */
    public static ItdmGongdanMaster toItdmGongdanMaster(ItdmXMJLAddOrUpdateDTO vo){
        ItdmGongdanMaster m = new ItdmGongdanMaster();
//        m.setId(vo.getId());//如果用于新增，为空
        m.setJihuaShiyanId(vo.getTestPlanId());
        m.setTestItemsId(vo.getTestItemsId());
        m.setWeituoYangpinId(vo.getYangpinId());
        m.setShebeiId(vo.getShebeiId());
        m.setShiiyanType(vo.getShiiyanType());
        m.setWorker(vo.getWorker());
        m.setYangpinCount(vo.getYangpinCount());

        m.setStartDate(vo.getJihuaStartDate());
        int lastTime = vo.getLastTime();//通过持续时间计算结束时间，注意开始时间2023-5-21,持续时间1，则结束时间为2023-5-21
        Date endDate = new Date(vo.getJihuaStartDate().getTime() + (lastTime-1)*1000*3600*24);
        m.setEndDate(endDate);

        m.setShijiStartDate(vo.getShijiStartDate());//如果用于新增，为空
        m.setNeirong(vo.getNeirong());

        String[] arr = vo.getChuanganqiArray();
        String chuanganqi = "";
        for (int i = 0; i < arr.length; i++) {
            if(i==0) chuanganqi = arr[i];
            else chuanganqi = chuanganqi + ","+ arr[i];
        }
        m.setChuanganqi(chuanganqi);

        String[] shiyanTypeArr = vo.getShiiyanTypeArray();
        String shiyanType = "";
        if (shiyanTypeArr != null && shiyanTypeArr.length > 0) {
            for (int i = 0; i < shiyanTypeArr.length; i++) {
                if(i==0) shiyanType = shiyanTypeArr[i];
                else shiyanType = shiyanType + ","+ shiyanTypeArr[i];
            }
        }
        m.setShiiyanType(shiyanType);
        return m;
    }

    /**转化成试验计划对象——项目经理修改试验计划*/
    public static ItdmTestPlan toItdmTestPlan(ItdmXMJLAddOrUpdateDTO vo){
        ItdmTestPlan itdmTestPlan = new ItdmTestPlan();
        itdmTestPlan.setId(vo.getTestPlanId());
        itdmTestPlan.setWeituoId(vo.getWeituoId());
        itdmTestPlan.setTestItemsId(vo.getTestItemsId());
        itdmTestPlan.setWeituoYangpinId(vo.getYangpinId());
        itdmTestPlan.setShebeiId(vo.getShebeiId());
        itdmTestPlan.setPm(vo.getPm());

        itdmTestPlan.setJihuaStartDate(vo.getJihuaStartDate());
        int lastTime = vo.getLastTime();//通过持续时间计算结束时间，注意开始时间2023-5-21,持续时间1，则结束时间为2023-5-1
        Date jihuaEndTime = new Date(vo.getJihuaStartDate().getTime() + (lastTime-1)*1000*3600*24);
        itdmTestPlan.setJihuaEndDate(jihuaEndTime);

        itdmTestPlan.setReportNo(vo.getReportNo());
        itdmTestPlan.setChuanganqi(vo.getChuanganqi());
        itdmTestPlan.setStatus(vo.getStatus());

        String[] arr = vo.getChuanganqiArray();
        String chuanganqi = "";
        for (int i = 0; i < arr.length; i++) {
            if(i==0) chuanganqi = arr[i];
            else chuanganqi = chuanganqi + ","+ arr[i];
        }
        itdmTestPlan.setChuanganqi(chuanganqi);

        return  itdmTestPlan;
    }


}
