package weaver.interfaces.htsc.flowOpoinionUdpate;
import java.text.SimpleDateFormat;
import java.util.*;

import com.engine.workflowDesign.entity.xmlEntity.Array;
import org.apache.tools.ant.taskdefs.Tstamp;
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;


/**
 * 说明
 * 修改时
 * 类名要与文件名保持一致
 * class文件存放位置与路径保持一致。
 * 请把编译后的class文件，放在对应的目录中才能生效
 * 注意 同一路径下java名不能相同。
 * @author Administrator
 *
 */
public class ModeFlow 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 {

			User user = (User)param.get("user");
			RequestInfo requestInfo = (RequestInfo)param.get("RequestInfo");
			RecordSet rs = new RecordSet();
			Map<String,String> mapvalue=new HashMap<>();
			BaseBean bb = new BaseBean();
			bb.writeLog("修改审批过程信息-开始");
/*
			String operator=""; //修改人
			String operatedate="";//修改时间
			String operatetime="";
			String remark="";//意见
			String logtype="";//状态
			String annexdocids="";//附件*/
			String lc="";
			String jd="";
			String qzyj="";
			String sumsqlcount="";
			String xglx="";

		if(requestInfo!=null){
			int billid = Util.getIntValue(requestInfo.getRequestid());

			String sql="select lc,jd,qzyj,czrxgh,czrqxgh,czsjxgh,yjxgh,xgfjxgh,czlxxgh,xglx from uf_qzyjxg where id="+billid;
			bb.writeLog("查询当前建模表流程sql："+sql);
			rs.execute(sql);
			if(rs.next()){
				lc=Util.null2String(rs.getString("lc"));
				jd=Util.null2String(rs.getString("jd"));
				qzyj=Util.null2String(rs.getString("qzyj"));
                xglx=Util.null2String(rs.getString("xglx"));
	/*			remark=Util.null2String(rs.getString("yjxgh"));
				operator=Util.null2String(rs.getString("czrxgh"));
				operatedate=Util.null2String(rs.getString("czrqxgh"));
				operatetime=Util.null2String(rs.getString("czsjxgh"));
				logtype=Util.null2String(rs.getString("czlxxgh"));*/
				mapvalue.put("remark",Util.null2String(rs.getString("yjxgh")));
				mapvalue.put("operator",Util.null2String(rs.getString("czrxgh")));
				mapvalue.put("operatedate",Util.null2String(rs.getString("czrqxgh")));
				String operatedatetime=Util.null2String(rs.getString("czsjxgh"));
				if(operatedatetime.length()>0&&operatedatetime.length()<=5){
					operatedatetime+=":00";
				//如果使用系统当前秒的话下面方法
				//	operatedatetime+=new SimpleDateFormat("ss").format(new Date());
				}
				mapvalue.put("operatetime",operatedatetime);


				mapvalue.put("logtype",Util.null2String(rs.getString("czlxxgh")));
				mapvalue.put("annexdocids",Util.null2String(rs.getString("xgfjxgh")));

			}


			String sqlquestlog="select count(*) as sumconut from workflow_requestlog " +
					" where requestid='"+lc+"' and nodeid='"+jd+"' and logid='"+qzyj+"'";
			bb.writeLog("查询当前流程数量的sql："+sqlquestlog);
			rs.execute(sqlquestlog);

			if(rs.next()){
				sumsqlcount=Util.null2String(rs.getString("sumconut"));
			}
			if(sumsqlcount=="0"){
				result.put("flag", "false");
				result.put("errmsg","数据查询有误");
				return result;
			}
			String dttablename="";


            if("0".equals(xglx)){
                //修改操作
                List<String> Stringvalue=new ArrayList<>();
                for (Map.Entry<String, String> entry : mapvalue.entrySet())
                {
                    String fieldname = Util.null2String(entry.getKey());
                    String fieldvalue = Util.null2String(entry.getValue());
                   // if(fieldvalue != "" ){
                        dttablename += dttablename == "" ? fieldname+"=?" : "," + fieldname+"=?";
                        Stringvalue.add(fieldvalue);
                   // }
                }

                if(Stringvalue.size()>0){
                    String sqlupdate="update workflow_requestlog set 	"+dttablename+" where requestid='"+lc+"' and nodeid='"+jd+"' and logid='"+qzyj+"'";
                    rs.executeUpdate(sqlupdate,new Object[]{Stringvalue});
                }
            }else if("1".equals(xglx)){
                dttablename="requestid='-"+lc+"'";
                String sqlupdate="update workflow_requestlog set 	"+dttablename+" where requestid='"+lc+"' and nodeid='"+jd+"' and logid='"+qzyj+"'";
                rs.executeUpdate(sqlupdate);
            }


			result.put("flag", "true");


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

}