package weaver.interfaces.htsc.hthy.action;

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.Date;
import java.util.HashMap;
import java.util.Map;

public class HthyHywjSaveModeExpand extends AbstractModeExpandJavaCodeNew {
    /**
     * 执行模块扩展动作
     * @param param
     *  param包含(但不限于)以下数据
     *  user 当前用户
     *  importtype 导入方式(仅在批量导入的接口动作会传输) 1 追加，2覆盖,3更新，获取方式(int)param.get("importtype")
     *  导入链接中拼接的特殊参数(仅在批量导入的接口动作会传输)，比如a=1，可通过param.get("a")获取参数值
     *  页面链接拼接的参数，比如b=2,可以通过param.get("b")来获取参数
     * @return
     */
    public Map<String, String> doModeExpand(Map<String, Object> param) {
        Map<String, String> result = new HashMap<String, String>();
        try {

            BaseBean bb = new BaseBean();
            User user = (User)param.get("user");
            int billid = -1;//数据id
            int modeid = -1;//模块id
            RequestInfo requestInfo = (RequestInfo)param.get("RequestInfo");
            if(requestInfo!=null){
                billid = Util.getIntValue(requestInfo.getRequestid());
                modeid = Util.getIntValue(requestInfo.getWorkflowid());
                if(billid>0&&modeid>0){
                    RecordSet rs = new RecordSet();

                    String wjqd = "" ;
                    String sql = " select wjqd from uf_hywh where id = "+billid;
                    bb.writeLog("sql:"+sql);
                    rs.execute(sql);
                    if (rs.next()){
                        wjqd = Util.null2String(rs.getString("wjqd"));
                    }

                    int errcount = 0;
                    if(!"".equals(wjqd)){
                        String[] wjqdArray = wjqd.split(",");
                        for(int i=0;i<wjqdArray.length;i++){
                            long uuid = System.currentTimeMillis() + Math.round(Math.random()*10000);
                            sql = " insert into uf_hywh_dt4(mainid,wjlx,wjid) values("+billid+","+wjqdArray[i]+",'"+uuid+"') " ;
                            boolean flag = rs.executeUpdate(sql);
                            if(!flag){
                                errcount++;
                            }
                        }
                    }
                    if(errcount > 0){
                        result.put("errmsg","新增会议文件出错");
                        result.put("flag", "false");
                    }
                }
            }
        } catch (Exception e) {
            result.put("errmsg","自定义出错信息");
            result.put("flag", "false");
        }
        return result;
    }
}
