package cn.estsh.i3plus.pojo.andon.bean;

import cn.estsh.i3plus.pojo.andon.model.BaseManageQueue;
import cn.estsh.i3plus.pojo.base.annotation.AnnoOutputColumn;
import cn.estsh.i3plus.pojo.base.bean.BaseBean;
import cn.estsh.i3plus.pojo.base.enumutil.AndonEnumUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.beanutils.BeanUtils;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description : 安灯队列
 * @Reference :
 * @Author : silliter.yuan
 * @CreateDate : 2019-05-10 17:16
 * @Modify:
 **/
@Data
@Entity
@Table(name="ANDON_MANAGE_QUEUE", indexes = {
        @Index(columnList = "WORK_CENTER_CODE", name = "ANDON_INDEX_WORK_CENTER_CODE"),
        @Index(columnList = "WORK_CELL_CODE", name = "ANDON_INDEX_WORK_CELL_CODE"),
        @Index(columnList = "ORGANIZE_CODE", name = "ANDON_INDEX_ORGANIZE_CODE"),
        @Index(columnList = "ANDON_ORDER_NO", name = "ANDON_INDEX_ANDON_ORDER_NO"),
        @Index(columnList = "ALARM_CODE", name = "ANDON_INDEX_ALARM_CODE"),
        @Index(columnList = "STATUS_CODE", name = "ANDON_INDEX_STATUS_CODE"),
        @Index(columnList = "ACTION_CODE", name = "ANDON_INDEX_ACTION_CODE"),
        @Index(columnList = "EQUIPMENT_CODE", name = "ANDON_INDEX_EQUIPMENT_CODE")
})
@DynamicInsert
@DynamicUpdate
@EqualsAndHashCode(callSuper = true)
@Api("安灯队列")
public class AndonManageQueue extends BaseManageQueue implements Serializable {

    private static final long serialVersionUID = 183865984747203897L;

    @Transient
    @ApiParam(value ="触发事件")
    private String triggerEvent;

    @Column(name = "ROUTE_CODE")
    @ApiParam(value = "流程代码")
    private String routeCode;

    @Column(name = "ROUTE_STATUS_CODE")
    @ApiParam(value = "状态点代码")
    private String routeStatusCode;

    @Column(name = "SEQ")
    @ApiParam(value = "序号", example = "1")
    private Double seq;

    @Transient
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @ApiParam(value="呼叫时间，查询开始时间", example = "2018-01-01 01:00:00")
    public String callTimeStart;

    @Transient
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @ApiParam(value="呼叫时间，查询结束时间", example = "2018-01-01 01:00:00")
    public String callTimeEnd;

    @Transient
    @ApiParam(value = "呼叫人名字")
    private String callUserName;

    @Transient
    @ApiParam(value = "响应人名字")
    private String confirmUserName;

    @Column(name = "SOURCE_TYPE")
    @ApiParam(value = "安灯来源类型")
    private String sourceType = AndonEnumUtil.ALARM_SOURCE_TYPE.SOFT.getValue();

    @Transient
    @ApiParam(value = "解决人名字")
    private String resetUserName;

    @Column(name = "IS_SHIFT_CALL")
    @ApiParam(value = "是否转呼", example = "1")
    private Integer isShiftCall;

    @Column(name="SHIFT_CALL_TIME")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @ApiParam(value="转呼时间",example = "2018-01-01 01:00:00")
    @AnnoOutputColumn(hidden = true)
    public String shiftCallTime;

    @Column(name = "RP_OBJECT_CODE")
    @ApiParam(value = "转呼对象代码")
    private String rpObjectCode;

    @Column(name = "SC_RESPONSE_CODE")
    @ApiParam(value = "转呼响应方式")
    private String scResponseCode;

    @Column(name = "SC_RP_LEVEL")
    @ApiParam(value = "转呼通知等级")
    private String scRpLevel;

    @Transient
    @ApiParam(value = "异常时长", example = "0")
    private Long execptionTime;

    @Transient
    @ApiParam(value = "响应时长", example = "0")
    private Long signTime;

    @Transient
    @ApiParam(value = "ANDON次数（用于报表统计）", example = "0")
    private Long andonCount;

    @Transient
    @ApiParam(value = "平均响应时长", example = "0")
    private Double avgSignTime;

    @Transient
    @ApiParam(value = "解决时长", example = "0")
    private Long resolveTime;

    @Transient
    @ApiParam(value = "平均解决时长", example = "0")
    private Double avgResolveTime;

    @Transient
    @ApiParam(value = "查询条件：ANDON状态")
    private List<Object> statusList;

    @Transient
    @ApiParam(value = "查询条件：ANDON状态")
    private List<Object> typeList;

    @Transient
    @ApiParam(value = "比例", example = "0")
    private Double proportion;

    @Transient
    @ApiParam(value = "当前比例（累加）", example = "0")
    private Double currentProportion;

    @Transient
    @ApiParam(value = "总次数（用于报表统计）", example = "0")
    private Integer sumCount;

    @Column(name = "SEND_FLAG")
    @ApiParam(value = "发送标志")
    private String sendFlag;

    @Column(name = "SIGN_SEND_FLAG")
    @ApiParam(value = "响应已通知标识")
    private String signSendFlag;

    /**
     * 1 = 是，2 = 否
     */
    @Transient
    @ApiParam(value = "是否勾选加入自处理问题库", example = "2")
    private Integer isDisposal;

    @Column(name = "ALARM_DETAIL_NAME_RDD")
    @ApiParam(value = "安灯子类型名称")
    private String alarmDetailNameRdd;

    @Column(name = "EPM_CODE")
    @ApiParam(value = "事件现象代码")
    private String epmCode;

    @Column(name = "EPM_NAME_RDD")
    @ApiParam(value = "事件现象描述")
    private String epmNameRdd;

    @Column(name = "IMPORTANCE_CODE")
    @ApiParam(value = "重要等级代码")
    private String importanceCode;

    @Column(name = "IMPORTANCE_NAME_RDD")
    @ApiParam(value = "重要等级名称")
    private String importanceNameRdd;

    @Column(name = "ORGANIZE_NAME_RDD")
    @ApiParam(value = "组织名称")
    private String organizeNameRdd;

    @Column(name = "REJECT_OPINION")
    @ApiParam(value = "驳回意见")
    private String rejectOpinion;

    @Column(name = "OPEN_INFO")
    @ApiParam(value = "放行说明")
    private String openInfo;

    @Column(name = "IS_OVER_TIME")
    @ApiParam(value = "是否超时")
    private Integer overTimeFlag;

    @Transient
    @ApiParam(value = "安灯状态集合")
    private List<String> statusCodeList;

    @Transient
    @ApiParam(value = "日发生次数")
    private int dayTime;

    @Transient
    @ApiParam(value = "周发生次数")
    private int weekendsTime;

    @Transient
    @ApiParam(value = "事件统计报表该事件描述的总次数")
    private int acCodeTime;

    @ApiParam(value = "操作来源")
    @Transient
    private String operationFlag;

    // 安灯附属表
    @Transient
    @ApiParam(value ="临时/纠正措施")
    private String tempCorrectMethod;

    @Transient
    @ApiParam(value ="预防/纠正措施")
    private String preCorrectMethod;

    @Transient
    @ApiParam(value ="客户")
    private String customer;

    @Transient
    @ApiParam(value ="零件号")
    private String partNo;

    @Transient
    @ApiParam(value ="零件名称")
    private String partName;

    @Transient
    @ApiParam(value ="报废数量")
    private Double scrapNum;

    @Transient
    @ApiParam(value ="批次")
    private String lot;

    @Transient
    @ApiParam(value ="零件数量")
    private Double partNum;

    @Transient
    @ApiParam(value ="设备名称")
    private String deviceName;

    @Transient
    @ApiParam(value ="是否更换备件")
    private Integer isChangeBackup;

    @Transient
    @ApiParam(value ="备件名称")
    private String backupPartName;

    @Transient
    @ApiParam(value ="规格型号")
    private String scale;

    @Transient
    @ApiParam(value ="当前件数")
    private Integer currentProdNum;

    @Transient
    @ApiParam(value ="生产累计件数")
    private Integer totalProdNum;

    @Transient
    @ApiParam(value ="安灯类型名称")
    private String alarmCodeName;

    @Transient
    @ApiParam(value ="响应时长-分钟")
    private Integer downtime;

    @Transient
    @ApiParam(value ="故障时长-分钟")
    private Integer brokenTime;

    @Transient
    @ApiParam(value ="故障字符串")
    private String faultStr;

    // 是否转呼
    public Integer getIsShiftCall() {
        return this.isShiftCall == null ? 0 : this.isShiftCall;
    }

    // 获取优先级别
    public Integer getPriorityLevel() {
        return this.priorityLevel == null ? 0 : this.priorityLevel;
    }

    /**
     * 工位统计 构造函数
     * @param workCenterCode
     * @param workCenterNameRdd
     * @param workCellCode
     * @param workCellNameRdd
     * @param equipmentCode
     * @param equipmentNameRdd
     * @param shiftCode
     * @param shiftNameRdd
     * @param alarmCode
     * @param andonCount
     */
    public AndonManageQueue(String workCenterCode,String workCenterNameRdd, String workCellCode,String workCellNameRdd,
                            String equipmentCode, String equipmentNameRdd, String shiftCode, String shiftNameRdd,
                            String alarmCode, Long andonCount,String callTime,String resetTime) {
        this.workCenterCode = workCenterCode;
        this.workCenterNameRdd = workCenterNameRdd;
        this.workCellNameRdd = workCellNameRdd;
        this.workCellCode = workCellCode;
        this.equipmentCode = equipmentCode;
        this.equipmentNameRdd = equipmentNameRdd;
        this.shiftCode = shiftCode;
        this.shiftNameRdd = shiftNameRdd;
        this.alarmCode = alarmCode;
        this.andonCount = andonCount;
        this.callTime = callTime;
        this.resetTime = resetTime;
    }

    /**
     * 原因统计 使用Java内存计算（获取原始数据）
     * @param acCode
     * @param acNameRdd
     * @param workCenterCode
     * @param workCenterNameRdd
     * @param workCellCode
     * @param workCellNameRdd
     * @param alarmCode
     * @param ecCode
     * @param ecNameRdd
     * @param emCode
     * @param emNameRdd
     * @param callTime
     * @param confirmTime
     * @param resetTime
     */
    public AndonManageQueue(String acCode, String acNameRdd, String workCenterCode,String workCenterNameRdd,String workCellCode,String workCellNameRdd,String alarmCode,String ecCode,String ecNameRdd,String emCode,String emNameRdd, String callTime,String confirmTime,String resetTime){
        this.acCode = acCode;
        this.acNameRdd = acNameRdd;
        this.workCenterCode = workCenterCode;
        this.workCenterNameRdd = workCenterNameRdd;
        this.workCellCode = workCellCode;
        this.workCellNameRdd = workCellNameRdd;
        this.alarmCode = alarmCode;
        this.ecCode = ecCode;
        this.ecNameRdd = ecNameRdd;
        this.emCode = emCode;
        this.emNameRdd = emNameRdd;
        this.callTime = callTime;
        this.confirmTime = confirmTime;
        this.resetTime = resetTime;
    }

    /**
     * 人员统计 使用Java内存计算（获取原始数据）
     * @param organizeCode
     * @param workCenterNameRdd
     * @param workCellCode
     * @param workCellNameRdd
     * @param resetUser
     * @param alarmCode
     * @param callTime
     * @param confirmTime
     * @param resetTime
     */
    public AndonManageQueue(String organizeCode,String workCenterNameRdd,String workCellCode,String workCellNameRdd,String resetUser,String alarmCode,String callTime, String confirmTime,String resetTime){
        this.organizeCode = organizeCode;
        this.workCenterNameRdd = workCenterNameRdd;
        this.workCellCode = workCellCode;
        this.workCellNameRdd = workCellNameRdd;
        this.resetUser = resetUser;
        this.alarmCode = alarmCode;
        this.callTime = callTime;
        this.confirmTime = confirmTime;
        this.resetTime = resetTime;
    }

    /**
     * 统计分析柏拉图 使用JAVA内存计算（获取原始数据）
     * @param workCenterNameRdd
     * @param alarmCode
     * @param ecCode
     * @param ecNameRdd
     * @param callTime
     * @param confirmTime
     * @param resetTime
     */
    public AndonManageQueue(String workCenterNameRdd,String alarmCode,String ecCode, String ecNameRdd, String callTime, String confirmTime,String resetTime){
        this.workCenterNameRdd = workCenterNameRdd;
        this.ecNameRdd = ecNameRdd;
        this.ecCode = ecCode;
        this.alarmCode = alarmCode;
        this.callTime = callTime;
        this.confirmTime = confirmTime;
        this.resetTime = resetTime;
    }

    public AndonManageQueue() {
    }

    /**
     * 安灯问题情况报表
     * @param organizeNameRdd
     * @param workCenterNameRdd
     * @param andonCount
     */
    public AndonManageQueue(String organizeNameRdd, String workCenterCode, String workCenterNameRdd, Long andonCount) {
        this.organizeNameRdd = organizeNameRdd;
        this.workCenterCode = workCenterCode;
        this.workCenterNameRdd = workCenterNameRdd;
        this.andonCount = andonCount;
    }

    public static void main(String[] args) {
        try {
            List ds = new ArrayList();
            ds.add(new AndonManageQueue());
            System.out.println(BeanUtils.describe(ds));
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
    }

}
