package weaver.formmode.recruit.modeexpand.record;

import com.engine.recruit.entity.record.ApplicantRecordPo;
import com.engine.recruit.enums.RecordOperateEnum;
import weaver.common.DateUtil;
import weaver.formmode.customjavacode.AbstractModeExpandJavaCodeNew;
import weaver.general.BaseBean;
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: 2023/11/03
 * @version: 1.0
 */
public class DeleteInterviewExpand extends AbstractModeExpandJavaCodeNew {
    @Override
    public Map<String, String> doModeExpand(Map<String, Object> params) {
        Map<String, String> result = new HashMap<>(2);
        try {
            //数据id
            int billId;
            //模块id
            int modeId;
            RequestInfo requestInfo = (RequestInfo) params.get("RequestInfo");
            User user = (User) params.get("user");
            if (requestInfo != null) {
                billId = Util.getIntValue(requestInfo.getRequestid());
                modeId = Util.getIntValue(requestInfo.getWorkflowid());
                if (billId > 0 && modeId > 0) {
                    MainTableInfo mainTableInfo = requestInfo.getMainTableInfo();
                    Property[] properties = mainTableInfo.getProperty();
                    Map<String, Object> mainDataMap = new HashMap<>();
                    for (Property property : properties) {
                        mainDataMap.put(property.getName(), property.getValue());
                    }
                    ApplicantRecordPo recordPo = ApplicantRecordPo.builder()
                            .billId(String.valueOf(billId))
                            .modeId(String.valueOf(modeId))
                            .operateTime(DateUtil.getDateTime())
                            .user(user)
                            .recordOperateType(RecordOperateEnum.DELETE_INTERVIEW)
                            .otherParam(mainDataMap)
                            .build();
                    recordPo.execute();

                }
            }
        } catch (Exception e) {
            new BaseBean().writeLog(e);
            result.put("errmsg", "自定义出错信息");
            result.put("flag", "false");
        }

        return result;
    }
}
