/**
 * Copyright (c) 2001-2017 泛微软件.
 * 泛微协同商务系统,版权所有.
 *
 */
package com.engine.kq.biz;

import com.engine.kq.log.KQLog;
import com.google.common.collect.Lists;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import weaver.conn.RecordSet;
import weaver.general.Util;

/**
 * 给流程组提供方法，即使是只读字段也可以入库的
 */
public class KQEditFieldInWorkflowBiz {

	/**
	 * 给流程组提供方法，即使是只读字段也可以入库的
	 * @param workflowParam 流程id之类的一些流程的基本信息
	 * @return
	 * @throws Exception
	 */
	public List<String> getEditFieldInWorkflow(Map<String,Object> workflowParam) {
    KQLog kqLog = new KQLog();

    List<String> fieldList = Lists.newArrayList();
	  try{
      String workflowid = Util.null2String(workflowParam.get("workflowid"));
      if(workflowid.length() > 0 && Util.getIntValue(workflowid) > 0){
        String editField = "duration";
        Map<String, Object> result = new HashMap<String, Object>();
        RecordSet rs = new RecordSet();
        String sql = "select * from kq_att_proc_relation where field002 in(select id from kq_att_proc_fields where field002 like '%"+editField+"%') and field001 in(select id from kq_att_proc_set where field001="+workflowid+" and field005 =1) ";
        rs.executeQuery(sql);
        while (rs.next()){
          String workflowFieldid = rs.getString("field003");
          String fieldid = workflowFieldid;
          fieldList.add(fieldid);
        }
      }
    }catch (Exception e){
      StringWriter errorsWriter = new StringWriter();
      e.printStackTrace(new PrintWriter(errorsWriter));
      kqLog.info("getEditFieldInWorkflow :"+errorsWriter.toString());
    }

		return fieldList;
	}
}
