package weaver.interfaces.workflow.action.javacode;


import weaver.conn.BatchRecordSet;
import weaver.conn.RecordSet;
import weaver.general.StringUtil;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.interfaces.workflow.action.Action;
import weaver.general.BaseBean;
import weaver.soa.workflow.request.RequestInfo;

import java.util.ArrayList;

/**
 * Online custom action interface
 */
public class Action20240719092616 extends BaseBean implements Action {

    @Override
    public String execute(RequestInfo request) {
        String requestId = request.getRequestid();
        String tablename = request.getRequestManager().getBillTableName();
        RecordSet rs = new RecordSet();
        rs.execute("select * from " + tablename + " where requestid =  " + requestId);
        rs.next();
        String hrmids = rs.getString("hrmids");
        String formid = rs.getString("formid");
        String sep = Util.getSeparator() + "";
        ArrayList<Integer> hrms = new ArrayList<>();
        ArrayList<String> insertParams = new ArrayList<>();
        String[] split = hrmids.split(",");
        for (String s : split) {
            if (!StringUtil.isEmpty(s)){
                hrms.add(Util.getIntValue(s));
            }
        }
        for (Integer hrm : hrms) {
            User user = new User(hrm);
            int userSubCompany1 = user.getUserSubCompany1();
            int userDepartment = user.getUserDepartment();
            String paramString = hrm+sep+userSubCompany1+sep+userDepartment+sep+formid;
            writeLog("paramString:"+paramString);
            insertParams.add(paramString);
        }
        String insertsql = "insert into uf_yddbmd (ryid ,fb,bm,FORMMODEID) VALUES (?,?,?,?)";
        BatchRecordSet brs = new BatchRecordSet();
        brs.executeSqlBatchNew(insertsql,insertParams);
        return Action.SUCCESS;
    }
}
