package cn.reghao.bnt.web.devops.app.model.po.log;

import cn.reghao.bnt.common.msg.event.EvtAppStatResult;
import cn.reghao.bnt.web.devops.machine.model.po.MachineHost;
import cn.reghao.bnt.web.util.BaseEntity;
import cn.reghao.jutil.jdk.converter.DateTimeConverter;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import jakarta.persistence.*;
import java.time.LocalDateTime;

/**
 * 应用部署日志
 *
 * @author reghao
 * @date 2020-03-10 11:22:05
 */
@NoArgsConstructor
@Data
@EqualsAndHashCode(callSuper = false)
@Entity
@Table(name = "devops_deploy_log")
public class DeployLog extends BaseEntity {
    @ManyToOne(cascade = CascadeType.REFRESH)
    @JoinColumn(name = "build_log_id")
    private BuildLog buildLog;
    @ManyToOne(cascade = CascadeType.REFRESH)
    @JoinColumn(name = "machine_host_id")
    private MachineHost machineHost;
    private LocalDateTime deployTime;
    private Integer code;
    @Column(columnDefinition="text")
    private String msg;
    private String deployBy;

    public DeployLog(BuildLog buildLog, MachineHost machineHost, EvtAppStatResult deployResult) {
        this.buildLog = buildLog;
        this.machineHost = machineHost;
        this.deployTime = DateTimeConverter.localDateTime(deployResult.getResult().getTimestamp());
        this.code = deployResult.getResult().getCode();
        this.msg = deployResult.getResult().getMsg();
        this.deployBy = buildLog.getBuildBy();
    }
}
