package weaver.interfaces.recruit.action;

import com.engine.common.util.ServiceUtil;
import com.engine.recruit.enums.ApplicationStatusEnum;
import com.engine.recruit.service.impl.ApplicantResumeServiceImpl;
import org.apache.commons.lang3.StringUtils;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.MainTableInfo;
import weaver.soa.workflow.request.Property;
import weaver.soa.workflow.request.RequestInfo;

import java.util.HashMap;
import java.util.Map;

/**
 * @author:dxfeng
 * @createTime: 2024/12/12
 * @version: 1.0
 */
public class InterviewEvaluationAction implements Action {
    @Override
    public String execute(RequestInfo requestInfo) {
        RecordSet rs = new RecordSet();
        try {
            User user = requestInfo.getRequestManager().getUser();
            MainTableInfo mainTableInfo = requestInfo.getMainTableInfo();
            Map<String, Object> mainDataMap = new HashMap<>(16);

            String requestId = requestInfo.getRequestid();

            Property[] propertyArray = mainTableInfo.getProperty();
            for (Property property : propertyArray) {
                mainDataMap.put(property.getName(), property.getValue());
            }

            // 面试评价，录用状态
            String lyqk = Util.null2String(mainDataMap.get("lyqk"));
            if (StringUtils.isBlank(lyqk)) {
                requestInfo.getRequestManager().setMessagecontent("录用情况不能为空");
                return FAILURE_AND_CONTINUE;
            }

            if ("1".equals(lyqk)) {
                // 不录用
                String ypz = Util.null2String(mainDataMap.get("ypz"));
                ServiceUtil.getService(ApplicantResumeServiceImpl.class, user).archiveTalentPool(ypz, false,"18","面试评价流程未通过");

                // 更新应聘简历为已淘汰
                rs.executeUpdate("update uf_jcl_yppc set zt = ? where id = ?", ApplicationStatusEnum.OBSOLETE.getValue(), ypz);
            }

            // 更新录用状态，到面试台账
            rs.executeUpdate("update uf_jcl_ms set mspjjg = ? where mspjlc = ?", lyqk, requestId);


            return SUCCESS;
        } catch (Exception e) {
            rs.writeLog("InterviewEvaluationAction--error", e);
            requestInfo.getRequestManager().setMessagecontent(e.getMessage());
            return FAILURE_AND_CONTINUE;
        }
    }
}
