package weaver.formmode.recruit.modeexpand.demandmanage;

import com.engine.recruit.enums.RecruitStatusEnum;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.formmode.customjavacode.AbstractModeExpandJavaCodeNew;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.soa.workflow.request.RequestInfo;
import weaver.workflow.workflow.WorkflowBillComInfo;

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

/**
 * <p>聚才林招聘</p>
 * 完成需求
 * <p>完成需求——更新状态为招聘完成，置空结束日期，完成日期取当前日期</p>
 *
 * @author:dxfeng
 * @createTime: 2023/09/13
 * @version: 1.0
 */
public class RecruitFinishModeExpand extends AbstractModeExpandJavaCodeNew {
    @Override
    public Map<String, String> doModeExpand(Map<String, Object> param) {
        Map<String, String> result = new HashMap<>();
        try {
            int billId;
            int modeId;
            RequestInfo requestInfo = (RequestInfo) param.get("RequestInfo");
            if (requestInfo != null) {
                billId = Util.getIntValue(requestInfo.getRequestid());
                modeId = Util.getIntValue(requestInfo.getWorkflowid());
                if (billId > 0 && modeId > 0) {
                    // 获取表单名称
                    String formId = Util.null2String(param.get("formid"));
                    String tableName = new WorkflowBillComInfo().getTablename(formId);
                    String sql = "update " + tableName + " set xqzt = ? ,jssj = ?,wcsj = ? where id = ?";
                    RecordSet rs = new RecordSet();
                    // 更新状态为招聘完成，置空结束日期，完成日期取当前日期
                    rs.executeUpdate(sql, RecruitStatusEnum.RECRUITMENT_COMPLETED.getValue(), null, DateUtil.getCurrentDate(), billId);
                    new BaseBean().writeLog("完成需求操作：billId=[" + billId + "]操作完成");
                }
            }
        } catch (Exception e) {
            new BaseBean().writeLog(e);
            result.put("errmsg", "完成需求操作失败");
            result.put("flag", "false");
        }
        return result;
    }
}
