package com.seeyon.apps.src_generalmatter.unit;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.seeyon.apps.ext.workflow.vo.FormDataVo;
import org.apache.commons.io.FileUtils;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.seeyon.apps.jync_file.kit.form.CAP4FormKit;
import com.seeyon.cap4.form.bean.FormDataMasterBean;
import com.seeyon.cap4.form.bean.FormDataSubBean;
import com.seeyon.ctp.common.AppContext;
import com.seeyon.ctp.common.SystemEnvironment;
import com.seeyon.ctp.common.ctpenumnew.manager.EnumManager;
import com.seeyon.v3x.dee.util.DateUtil;

public class ParamUtil {

	private  EnumManager enumManagerNew;
	
	public void setEnumManagerNew(EnumManager enumManagerNew) {
		this.enumManagerNew = enumManagerNew;
	}
	
	public EnumManager getEnumManagerNew() {
		if (enumManagerNew == null) {
			enumManagerNew = (EnumManager) AppContext.getBean("enumManagerNew");
		}
		return enumManagerNew;
	}
	
	/**
	 * 通用事项终止参数
	 * @param master
	 * @return
	 * @throws IOException
	 */
	public JSONObject getGeneralmatterStopParam(FormDataMasterBean master) throws IOException{
		JSONObject jsonObject = new JSONObject();
		System.out.println("设置通用事项终止参数");
		jsonObject.put("billcode", CAP4FormKit.getFieldStrValue(master, "来源单据主键"));
		jsonObject.put("notes", CAP4FormKit.getFieldStrValue(master, "说明事项"));
		jsonObject.put("status", "0");
		System.out.println("通用通用事项终止参数："+jsonObject);
		String str = SystemEnvironment.getApplicationFolder();
		String date = DateUtil.format(new Date(), "yyyyMMddHHmmss");
		FileUtils.writeStringToFile(new File(str+"/bipjson/"+date.substring(0,4)+"/"+date.substring(5,6)+"/"+date.substring(7,8)+"/TYSXZZ_" + date + ".json"), jsonObject.toString(), "UTF-8");
		return jsonObject;
	}
	
	
	
	/**
	 * 通用事项完成参数
	 * @param formDataVo
	 * @return
	 * @throws IOException
	 */
	public JSONObject getGeneralmatterFinishParam(FormDataVo formDataVo) throws NoSuchFieldException {
		JSONObject jsonObject = new JSONObject();
//		System.out.println("设置通用事项终止参数");
//		jsonObject.put("billcode", CAP4FormKit.getFieldStrValue(master, "来源单据主键"));
		jsonObject.put("billcode", formDataVo.getFieldData("来源单据主键")!=null?formDataVo.getFieldData("来源单据主键").getStringValue():"");
//		jsonObject.put("notes", CAP4FormKit.getFieldStrValue(master, "说明事项"));
		jsonObject.put("notes", formDataVo.getFieldData("说明事项")!=null?formDataVo.getFieldData("说明事项").getStringValue():"");
		jsonObject.put("status", "1");
//		System.out.println("通用通用事项终止参数："+jsonObject);
//		String str = SystemEnvironment.getApplicationFolder();
//		String date = DateUtil.format(new Date(), "yyyyMMddHHmmss");
//		FileUtils.writeStringToFile(new File(str+"/bipjson/"+date.substring(0,4)+"/"+date.substring(5,6)+"/"+date.substring(7,8)+"/TYSXJS_" + date + ".json"), jsonObject.toString(), "UTF-8");
		return jsonObject;
	}
	
	
}
