package weaver.formmode.recruit.modeexpand.entrymanager;

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.formmode.customjavacode.AbstractModeExpandJavaCodeNew;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.soa.workflow.request.RequestInfo;

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

/**
 * @author:dxfeng
 * @createTime: 2023/11/20
 * @version: 1.0
 */
public class AddEntryModeExpand extends AbstractModeExpandJavaCodeNew {
    @Override
    public Map<String, String> doModeExpand(Map<String, Object> param) {
        Map<String, String> result = new HashMap<>(2);
        try {
            int billId;
            int modeId;
            RequestInfo requestInfo = (RequestInfo) param.get("RequestInfo");
            if (requestInfo != null) {
                User user = (User) param.get("user");
                billId = Util.getIntValue(requestInfo.getRequestid());
                modeId = Util.getIntValue(requestInfo.getWorkflowid());
                if (billId > 0 && modeId > 0) {
                    RecordSet rs = new RecordSet();
                    String pcId = Util.null2String(param.get("pcid"));
                    String offerId = Util.null2String(param.get("offerid"));
                    if (StringUtils.isNotBlank(pcId)) {
                        // 归档人才库，归档原因：待入职
                        ServiceUtil.getService(ApplicantResumeServiceImpl.class, user).archiveTalentPool(pcId, false, "13");
                        // 更新应聘批次为已归档
                        rs.executeUpdate("update uf_jcl_yppc set zt = ? where id = ? ", ApplicationStatusEnum.ARCHIVED.getValue(), pcId);
                    }
                    if (StringUtils.isNotBlank(offerId)) {
                        // 是否待入职，字段为是
                        rs.executeUpdate("update uf_jcl_offer set sfzdrz = 1 where id = ? ", offerId);
                    }
                }
            }
        } catch (Exception e) {
            new BaseBean().writeLog(e);
            result.put("errmsg", "自定义出错信息");
            result.put("flag", "false");
        }
        return result;
    }
}
