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

import cn.estsh.i3plus.pojo.base.annotation.AnnoOutputColumn;
import cn.estsh.i3plus.pojo.base.bean.BaseBean;
import cn.estsh.i3plus.pojo.base.enumutil.ImppEnumUtil;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Lob;
import javax.persistence.Table;

/**
 * @Description : 任务计划
 * @Reference :
 * @Author : wei.peng
 * @Date : 2018-10-22 16:58:43.952
 * @Modify :
 **/
@Data
@Entity
@DynamicInsert
@DynamicUpdate
@EqualsAndHashCode(callSuper = true)
@Table(name = "SYS_TASK_PLAN")
@Api(value = "任务计划", description = "任务计划")
public class SysTaskPlan extends BaseBean {

    private static final long serialVersionUID = -136675837627794707L;
    @Column(name = "NAME")
    @ApiParam(value = "名称")
    private String name;

    @Column(name = "GROUP_NAME")
    @ApiParam(value = "组名称")
    private String groupName;

    @Column(name = "TASK_CYCLE_ID")
    @ApiParam(value = "任务周期ID", example = "-1")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long taskCycleId;

    @Column(name = "TASK_CYCLE_NAME_RDD")
    @ApiParam(value = "任务周期名称")
    private String taskCycleNameRdd;

    @Column(name = "TASK_CYCLE_EXPS_RDD")
    @ApiParam(value = "任务周期表达式")
    private String taskCycleExpsRdd;

    @Column(name = "TASK_PLAN_EXEC_NUM")
    @ApiParam(value = "定时任务运行次数", example = "0")
    private Integer taskPlanExecNum;

    /**
     * 获取定时任务运行次数
     * @return 定时任务运行次数
     */
    public int getTaskPlanExecNumValue() {
        if (taskPlanExecNum == null) {
            return 0;
        } else {
            return taskPlanExecNum.intValue();
        }
    }

    // 枚举 ImppEnumUtil.TASK_METHOD_TYPE.CLASS_METHOD
    @Column(name = "TASK_METHOD_TYPE")
    @ApiParam(value = "任务执行类型", example = "-1")
    private Integer taskMethodType;

    @Column(name = "TASK_ID")
    @ApiParam(value = "定时任务id")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long taskId;

    @Column(name = "TASK_NAME_RDD")
    @ApiParam(value = "定时任务名称")
    private String taskNameRdd;

    @Column(name = "TASK_SOFT_TYPE_RDD")
    @ApiParam(value = "任务所属模块")
    private Integer taskSoftTypeRdd;

    @Column(name = "TASK_PLAN_PARAM")
    @ApiParam(value = "任务计划参数")
    private String taskPlanParam;

    @Column(name = "TASK_CYCLE_START_DATE_TIME_RDD")
    @ApiParam(value = "任务开始时间")
    private String taskCycleStartDateTimeRdd;

    @Column(name = "TASK_CYCLE_END_DATE_TIME_RDD")
    @ApiParam(value = "任务结束时间")
    private String taskCycleEndDateTimeRdd;

    @Column(name = "TASK_PLAN_DESCRIPTION")
    @ApiParam(value = "任务计划描述", access = "任务计划描述")
    private String taskPlanDescription;

    // 枚举 CommonEnumUtil.TRUE_OR_FALSE
    @Column(name = "TASK_PLAN_STATUS")
    @ApiParam(value = "任务状态", example = "1")
    private Integer taskPlanStatus;

    @Column(name = "LAST_RUN_DATE_TIME")
    @ApiParam(value = "最后运行时间", access = "最后运行时间")
    private String lastRunDateTime;

    // 枚举 CommonEnumUtil.TRUE_OR_FALSE
    @Column(name = "IS_NOTICE")
    @ApiParam(value = "是否通知", example = "1")
    private Integer isNotice;

    // 枚举 CommonEnumUtil.TRUE_OR_FALSE
    @Column(name = "IS_INTERNAL_USER")
    @ApiParam(value = "是否内部用户", example = "1")
    private Integer isInternalUser;

    // 枚举 ImppEnumUtil.MESSAGE_TYPE
    @Column(name = "NOTICE_METHOD")
    @ApiParam(value = "通知方式", example = "1")
    private Integer noticeMethod;

    @Lob
    @Column(name = "NOTICE_CHANNEL")
    @ApiParam(value = "通知渠道")
    private String noticeChannel;

    public int getTaskPlanStatusVal() {
        if(taskPlanStatus == null){
            return -1;
        }
        return taskPlanStatus.intValue();
    }

    // 枚举 ImppEnumUtil.MESSAGE_TYPE
    @Column(name = "LOG_LEVEL")
    @ApiParam(value = "日志等级")
    @AnnoOutputColumn(refClass = ImppEnumUtil.LOG_LEVEL.class)
    private Integer logLevel;

    public int getLogLevelVal() {
        return logLevel == null ? ImppEnumUtil.LOG_LEVEL.ERROR.getValue() : logLevel;
    }
}
