package weaver.formmode.recruit.modeexpand.departmentscreening;

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.Util;
import weaver.hrm.User;
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/03
 * @version: 1.0
 */
public class ScreeningFeedbackExpand extends AbstractModeExpandJavaCodeNew {
    @Override
    public Map<String, String> doModeExpand(Map<String, Object> param) {
        Map<String, String> result = new HashMap<>();
        RecordSet rs = new RecordSet();
        try {
            RequestInfo requestInfo = (RequestInfo) param.get("RequestInfo");
            if (requestInfo != null) {
                User user = (User) param.get("user");
                Map<String, Object> mainDataMap = new HashMap<>();
                MainTableInfo mainTableInfo = requestInfo.getMainTableInfo();
                Property[] properties = mainTableInfo.getProperty();
                for (Property property : properties) {
                    mainDataMap.put(property.getName(), property.getValue());
                }

                String jg = Util.null2String(mainDataMap.get("jg"));
                if(StringUtils.isNotBlank(jg) && "1".equals(jg)) {
                    // 用人部门简历筛选如果不通过，需要填写原因，保存后可直接加入人才库，同时推送消息给企管部招聘负责人；
                    String pj = Util.null2String(mainDataMap.get("pj"));
                    String ypz = Util.null2String(mainDataMap.get("ypz"));
                    ServiceUtil.getService(ApplicantResumeServiceImpl.class, user).archiveTalentPool(ypz, false,"17",pj);

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


            }
        } catch (Exception e) {
            rs.writeLog(e);
            result.put("errmsg", e.getMessage());
            result.put("flag", "false");
        }
        return result;
    }
}
