package com.engine.recruit.entity.record;

import com.engine.recruit.conn.ApplicantCommonInfo;
import com.engine.recruit.enums.RecordOperateEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import weaver.general.BaseBean;
import weaver.hrm.User;

import java.util.Map;

/**
 * @author:dxfeng
 * @createTime: 2023/11/02
 * @version: 1.0
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class ApplicantRecordPo {
    private String billId;
    private String modeId;
    private String formId;
    private String layoutId;
    private String operateTime;
    private User user;
    private String content;
    private String linkUrl;
    private Map<String, Object> otherParam;
    private String pcId;

    private RecordOperateEnum recordOperateType;

    public void autoCreateLink() {
        String url = "/spa/cube/index.html#/main/cube/card?billid={billId}&type=0&modeId={modeId}&formId={formId}&layoutid={layoutId}&guid=card";
        if (StringUtils.isBlank(layoutId)) {
            linkUrl = url.replace("{billId}", billId).replace("{modeId}", modeId).replace("{formId}", formId).replace("&layoutid={layoutId}", "");
        } else {
            linkUrl = url.replace("{billId}", billId).replace("{modeId}", modeId).replace("{formId}", formId).replace("{layoutId}", layoutId);
        }
    }

    public void execute() {
        if (null == recordOperateType) {
            return;
        }
        try {
            recordOperateType.createOperateRecord(this);
            ApplicantCommonInfo.createOperateRecord(this);
        } catch (Exception e) {
            new BaseBean().writeLog("应聘过程记录数据插入失败", e);
        }
    }
}
