package com.product.data.sync.service;

import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.product.admin.config.CmnCode;
import com.product.admin.service.CodeService;
import com.product.admin.service.OrganizationCacheService;
import com.product.admin.service.SystemMenusService;
import com.product.common.lang.StringUtils;
import com.product.core.cache.DataPoolRefreshCache;
import com.product.core.config.Global;
import com.product.core.connection.ConnectionManager;
import com.product.core.dao.BaseDao;
import com.product.core.entity.DataTableEntity;
import com.product.core.entity.FieldSetEntity;
import com.product.core.entity.RequestParameterEntity;
import com.product.core.exception.BaseException;
import com.product.core.service.support.AbstractBaseService;
import com.product.core.spring.context.SpringMVCContextHolder;
import com.product.core.util.CodeUtil;
import com.product.data.sync.config.CmnConst;
import com.product.data.sync.config.SystemCode;
import com.product.data.sync.service.ide.ISyFeDataService;
import com.product.data.sync.service.media.GdMediaUtil;
import com.product.data.sync.util.BatchAddData;
import com.product.data.sync.util.BusinessDataSync;
import com.product.data.sync.util.DataManipulationUtils;
import com.product.file.service.FileManagerService;
import com.product.file.util.CreateDocumentIndexThread;
import com.product.module.sys.service.UserService;
import com.product.util.BaseDaoServiceImpl;
import com.product.util.BaseUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.File;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;

/**
 * Copyright LX
 *
 * @Title: SyFeDataService
 * @Project: product-server
 * @date: 2021-09-30 14:19
 * @author: zm
 * @Description: fe鏁版嵁绉绘鍒颁骇鍝�
 */
@Service
public class SyFeDataService extends AbstractBaseService implements ISyFeDataService {
	private static Logger logger = LoggerFactory.getLogger(SyFeDataService.class);
	@Autowired
	public BaseDao baseDao;
	@Autowired
	public FunctionSynchrService functionSynchrService;
	@Autowired
	FileManagerService fileManagerService;
	@Autowired
	SystemMenusService systemMenusService;
	@Autowired
	GdMediaUtil gdMediaUtil;
	//鍏徃fe id 瀵瑰簲 浜у搧uuid
	Map<String, FieldSetEntity> OrgIdUUIDmap = Maps.newHashMap();
	//閲戞牸涓荤洰褰�
	String jinGePath = "D:\\OA\\FEGOV\\Media";
	//鏆傚瓨鏂囦欢鐩綍
	String TSPath = "D:\\filePackage";
	@Autowired
	private UserService userService;
	@Autowired
	private CodeService codeService;
	@Autowired
	private FeDataDSService feDataDSService;
	//fe 浜哄憳id 瀵瑰簲  userid
	private JSONObject userIdJson = new JSONObject();
	//fe 鍏徃閮ㄩ棬id 瀵瑰簲 鏈烘瀯uuid
	private JSONObject groupJson = new JSONObject();
	//瀛楁绫诲瀷鍏宠仈
	private JSONObject fieldTypeJson = new JSONObject();
	//娴佺▼nodes fe id 瀵瑰簲 浜у搧uuid
	private JSONObject nodesIdUUID = new JSONObject();
	//婧愭暟鎹〃鍚�  鏈暟鎹〃鍚�
	private JSONObject originalTable = new JSONObject();
	//鍞竴瀛楁
	private String pk;
	//琛ㄥ敮涓€鏍囪瘑   鍜屾湰琛╱uid
	private JSONObject pxMap = new JSONObject();
	//宸插紑鍙戝叕鍏卞姛鑳� 鍏憡绠$悊 绯荤粺鍙傛暟(娌℃湁)  闂嵎绠$悊  鑰冨嫟绠$悊 杞﹁締绠$悊  鍗忓悓鍔炲叕
	private String[] funTable = {"FE_APP5.PUB_NOTICE", "FE_BASE5.RESEARCH_TOPIC", "FE_APP5.HR_ATTENDANCE", "FE_APP5.CAR_INFO", "FE_BASE5.SYS_COLLABORATIVE"};
	//鎴戜滑浜у搧鐨勫姛鑳芥潈闄�
	private String[] functionCode = {"001-004-000-000", "001-004-000-001", "001-004-000-002"};
	//鏈骇鍝佹寜閽畊uid
	private List<String> buttonUuid = Lists.newArrayList();

	//宸插悓姝ヨ〃缁撴瀯
	private JSONObject dataTableObject = new JSONObject();
	@Autowired
	private BatchAddData batchAddData;

	public Boolean isStr(String str) {
		boolean a = false;
		for (int i = 0; i < funTable.length; i++) {
			if (str.equals(funTable[i])) {
				a = true;
			}
		}
		return a;
	}


	private Set<String> clearTable = new HashSet<>();

	//鍏憡绠$悊1  绯荤粺鍙傛暟  闂嵎绠$悊  鑰冨嫟绠$悊  杞﹁締绠$悊  鍗忓悓鍔炲叕
	@Override
	public String saveSyncFedata(FieldSetEntity fs) throws SQLException, ClassNotFoundException {
		//鍚屾缁勭粐鏋舵瀯
		DataTableEntity dataTableEntity = baseDao.listTable("product_sys_users");
		String clientUUID = "4d4679ed-c4c3-41b8-abfe-451a66fd4043";
//		if (dataTableEntity.getRows() < 10) {
//			//杩佺Щ缁勭粐鏋舵瀯
		String uuid = feDataDSService.FEDataMigration();
		if (!BaseUtil.strIsNull(uuid)) {
			clientUUID = uuid;
		}
//		}
		//灏佽涓よ竟浜哄憳鍏宠仈鍜岄儴闂ㄥ叧鑱�
		packageDepartmentPersonnel();
		String tricode_fun = fs.getString("function_code");
		if (StringUtils.isEmpty(tricode_fun)) {
			tricode_fun = fs.getString("function_code");
		}
		if (BaseUtil.strIsNull(tricode_fun)) {
			return null;
		}
		String[] split = tricode_fun.split(";");
		for (String s : split) {
			saveSyncFeData(s.split(","), clientUUID);
		}
		return "ok";
	}

	public void flowPermission() {
		DataTableEntity oldOrg = baseDao.listTable("product_sys_org_levels_copy1");
		DataTableEntity orgDataStatic = baseDao.listTable("product_sys_org_levels");
		Map<String, String> systemOrgMap = Maps.newHashMap();
		for (int i = 0; i < orgDataStatic.getRows(); i++) {
			systemOrgMap.put(orgDataStatic.getString(i, com.product.admin.config.CmnConst.ORG_LEVEL_ALL), orgDataStatic.getFieldSetEntity(i).getUUID());
		}
		Map<String, String> oldMapping = Maps.newHashMap();
		for (int i = 0; i < oldOrg.getRows(); i++) {
			String orgLevelAll = oldOrg.getString(i, com.product.admin.config.CmnConst.ORG_LEVEL_ALL);
			String newUid = systemOrgMap.get(orgLevelAll);
			if (StringUtils.isEmpty(newUid)) {
				continue;
			}
			oldMapping.put(oldOrg.getFieldSetEntity(i).getUUID(), newUid);
//			oldSystemOrgMap.put(oldOrg.getFieldSetEntity(i).getUUID(), oldOrg.getString(i, com.product.admin.config.CmnConst.ORG_LEVEL_ALL));
		}
		DataTableEntity dataTableEntity = baseDao.listTable("product_sys_job_posts_copy1");
		DataTableEntity systemPosts = baseDao.listTable("product_sys_job_posts");
		//鏃у矖浣島uid 瀵瑰簲 鏂板矖浣島uid
		Map<String, String> postMapping = new HashMap<>();
		for (int i = 0; i < dataTableEntity.getRows(); i++) {
			String postName = dataTableEntity.getString(i, com.product.admin.config.CmnConst.JOB_POST_NAME);
			String orgLevel = dataTableEntity.getString(i, com.product.admin.config.CmnConst.DEPT_UUID);
			String uuid = dataTableEntity.getFieldSetEntity(i).getUUID();
			String newOrgUid = oldMapping.get(orgLevel);
			if (StringUtils.isEmpty(newOrgUid)) {
				continue;
			}
			for (int j = 0; j < systemPosts.getRows(); j++) {
				String postName1 = systemPosts.getString(j, com.product.admin.config.CmnConst.JOB_POST_NAME);
				String orgLevel1 = systemPosts.getString(j, com.product.admin.config.CmnConst.DEPT_UUID);
				if (postName1.equals(postName) && newOrgUid.equals(orgLevel1)) {
					postMapping.put(uuid, systemPosts.getFieldSetEntity(j).getUUID());
					break;
				}
			}
		}

		dataTableEntity = baseDao.listTable("product_sys_users_copy1");
		DataTableEntity systemUser = baseDao.listTable("product_sys_users");
		Map<String, String> userMapping = Maps.newHashMap();
		for (int i = 0; i < dataTableEntity.getRows(); i++) {
			String userAccount = dataTableEntity.getString(i, com.product.admin.config.CmnConst.USER_ACCOUNT);
			String userId = dataTableEntity.getFieldSetEntity(i).getString(CmnConst.USER_ID);
			for (int j = 0; j < systemUser.getRows(); j++) {
				String userAccount1 = systemUser.getString(j, com.product.admin.config.CmnConst.USER_ACCOUNT);
				if (userAccount.equals(userAccount1)) {
					userMapping.put(userId, systemUser.getFieldSetEntity(j).getString(CmnConst.USER_ID));
					break;
				}
			}
		}

		DataTableEntity nodes = baseDao.listTable("product_sys_flow_node", "length(default_posts)>0 or length(default_users)>0 or length(default_depts)>0");
		for (int i = 0; i < nodes.getRows(); i++) {
			FieldSetEntity node = nodes.getFieldSetEntity(i);
			String defaultPosts = node.getString("default_posts");
			String defaultUsers = node.getString("default_users");
			String defaultDepts = node.getString("default_depts");
			String arr[];
			if (!StringUtils.isEmpty(defaultDepts)) {
				arr = defaultDepts.split(",");
				for (int j = 0; j < arr.length; j++) {
					String uid = arr[j];
					String uuid = oldMapping.get(uid);
					if (StringUtils.isEmpty(uuid)) {
						arr[j] = null;
						continue;
					}
					arr[j] = uuid;
				}
				//杩囨护arr涓殑null骞惰浆涓哄瓧绗︿覆鐢ㄩ€楀彿鍒嗛殧
				defaultDepts = Arrays.stream(arr).filter(Objects::nonNull).collect(Collectors.joining(","));
			}
			if (!StringUtils.isEmpty(defaultPosts)) {
				arr = defaultPosts.split(",");
				for (int j = 0; j < arr.length; j++) {
					String uid = arr[j];
					String uuid = postMapping.get(uid);
					if (StringUtils.isEmpty(uuid)) {
						arr[j] = null;
						continue;
					}
					arr[j] = uuid;
				}
				//杩囨护arr涓殑null骞惰浆涓哄瓧绗︿覆鐢ㄩ€楀彿鍒嗛殧
				defaultPosts = Arrays.stream(arr).filter(Objects::nonNull).collect(Collectors.joining(","));
			}
			if (!StringUtils.isEmpty(defaultUsers)) {
				arr = defaultUsers.split(",");
				for (int j = 0; j < arr.length; j++) {
					String uid = arr[j];
					String uuid = userMapping.get(uid);
					if (StringUtils.isEmpty(uuid)) {
						arr[j] = null;
						continue;
					}
					arr[j] = uuid;
				}
				//杩囨护arr涓殑null骞惰浆涓哄瓧绗︿覆鐢ㄩ€楀彿鍒嗛殧
				defaultUsers = Arrays.stream(arr).filter(Objects::nonNull).collect(Collectors.joining(","));
			}
			node.setValue("default_posts", defaultPosts);
			node.setValue("default_users", defaultUsers);
			node.setValue("default_depts", defaultDepts);

		}

		baseDao.update(nodes);
	}

	public String saveSyncFeData(String[] tricodeFunction, String clientUUID) {
		String[] tricode_funs = tricodeFunction;
//        String[] tricode_funs = fs.getString("tricode_fun").split(",");
		//灏佽鏈骇鍝侀渶璧嬫潈闄愮殑鎸夐挳uuid
//        this.packageButton();
//        ConnectionInterface conn = functionSynchrService.getConnection(fs);
		//閫氳繃绾跨▼寰幆娣诲姞鍔熻兘淇℃伅
		ExecutorService exec = Executors.newFixedThreadPool(1);
		List<Set<String>> clearAttachmentSets = new ArrayList<>();
		for (int i = 0; i < tricode_funs.length; i++) {
			//鑾峰彇jdbc杩炴帴
			BusinessDataSync async = new BusinessDataSync(tricode_funs[i]);
			async.setBaseDao(baseDao);
			async.setClearTable(clearTable);
			async.setFileManagerService(fileManagerService);
			async.setSystemMenusService(systemMenusService);
			async.setFeDataDSService(feDataDSService);
			async.setGdMediaUtil(gdMediaUtil);
			async.setClientUUID(clientUUID);
			async.setBatchAddData(batchAddData);
			Set<String> clearAttachment = async.getClearAttachment();
			if (clearAttachment != null) {
				clearAttachmentSets.add(clearAttachment);
			}
			Thread t = new Thread(async);
			//璋冪敤绾跨▼run鏂规硶
			exec.submit(t);
//            nodesIdUUID = new JSONObject();
//            //鍚屾琛ㄥ強鍩虹鏁版嵁
//            String sf28 = this.synchronizeTablesData(conn, tricode_funs[i]);
//            String table_name = sf28.split("\\.")[1];
//            String moduleUUID;
//            if (!isStr(sf28)) {
//                //鍚屾mvc
//                moduleUUID = this.synchronizationModuleName(conn, tricode_funs[i], sf28);
//            } else {
//                //宸叉湁鍔熻兘鐨勮〃灏变笉鍚屾mvc  鏌ヨ璇ュ姛鑳界殑妯″潡uuid
//                StringBuffer sql = new StringBuffer();
//                sql.append(" tricode = (\n")
//                        .append("SELECT tricode_parent FROM product_sys_functions a LEFT JOIN \n")
//                        .append("product_sys_datamodel_table b on a.table_uuid = b.uuid \n")
//                        .append("WHERE b.table_name = ? GROUP BY tricode_parent\n")
//                        .append(") AND function_type_uuid = 0");
//                FieldSetEntity fieldSetEntity = baseDao.getFieldSetEntityByFilter("product_sys_functions", sql.toString(), new String[]{this.originalTable.getString(table_name)}, false);
//                moduleUUID = fieldSetEntity.getUUID();
//            }
//            //杩佺Щ wf_model娴佺▼妯″潡琛�
////            this.syncModel(tricode_funs[i], conn, moduleUUID, sf28, null, SpringMVCContextHolder.getCurrentUser().getUser_id(), false);
//            //鏍规嵁瑕佹眰娴佺▼瑕佸悓姝ヤ袱娆�
//            //鏌ヨ涓诲叕鍙竨uid
//            FieldSetEntity fieldSetEntity = baseDao.getFieldSetByFilter(CmnConst.PRODUCT_SYS_ORG_LEVELS, " org_level_code = ? ", new String[]{"001"},false);
//            FieldSetEntity user = baseDao.getFieldSetByFilter("product_sys_org_manager" , " manager_type = ? ", new String[]{"2"}, false);
//            this.syncModel(tricode_funs[i], conn, moduleUUID, sf28, fieldSetEntity.getUUID(), user.getInteger("user_id"), true);
		}
		//鍚屾椂寮€濮嬫墽琛�
		exec.shutdown();
		while (true) {
			if (exec.isTerminated()) {
				//System.out.println("鎵€鏈夌殑瀛愮嚎绋嬮兘缁撴潫浜嗭紒");
				break;
			}
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		systemMenusService.initSystemMenu();
		//鍚屾
		System.out.println("=================鍚屾鎴愬姛===============");

		return "OK";
	}

	/**
	 * 闄勪欢娣诲姞绱㈠紩
	 */
	public void dataSyncCreateIndexUtil() {
		String sql = "SELECT uuid attachment_uuid,function_uuid FROM product_sys_attachments WHERE function_uuid IS NOT NULL AND function_uuid!=''";
		DataTableEntity dtAttachment = baseDao.listTable(sql, new Object[]{});
		if (!BaseUtil.dataTableIsEmpty(dtAttachment)) {
			for (int i = 0; i < dtAttachment.getRows(); i++) {
				FieldSetEntity fseAttachment = dtAttachment.getFieldSetEntity(i);
				CreateDocumentIndexThread.getInstance().appendAttaInfo(fseAttachment);
			}
		}
	}

	/**
	 * 灏佽鍗曚綅閮ㄩ棬 浜哄憳瀵瑰簲Json
	 */
	public void packageDepartmentPersonnel() {
		DataTableEntity staffsData = baseDao.listTable("product_sys_staffs");
		for (int i = 0; i < staffsData.getRows(); i++) {
			//鏁版嵁婧愮敤鎴穒d
			userIdJson.put(staffsData.getString(i, "remark"), staffsData.getString(i, "user_id"));
		}
		DataTableEntity orgData = baseDao.listTable("product_sys_org_levels");
		for (int i = 0; i < orgData.getRows(); i++) {
			//婧愭暟鎹甶d
			groupJson.put(orgData.getString(i, "sequence"), orgData.getString(i, "uuid"));
		}
	}

	/**
	 * 灏佽鏈骇鍝佺殑鎸夐挳uuid
	 */
	public void packageButton() {
		StringBuffer sql = new StringBuffer();
		String tricodeIn = BaseUtil.buildQuestionMarkFilter("tricode", this.functionCode, true);
		sql.append(" SELECT uuid FROM product_sys_function_buttons WHERE function_uuid IN ( ")
				.append(" SELECT uuid FROM product_sys_functions WHERE ")
				.append(tricodeIn).append(" ) ");
		DataTableEntity dataTableEntity = baseDao.listTable(sql.toString(), new String[]{});
		for (int i = 0; i < dataTableEntity.getRows(); i++) {
			this.buttonUuid.add(dataTableEntity.getString(i, "uuid"));
		}
	}

	/**
	 * 鍚屾琛ㄥ強琛ㄦ暟鎹�
	 *
	 * @param conn    杩炴帴
	 * @param funCode 鍔熻兘code
	 * @throws SQLException
	 */
	private String synchronizeTablesData(Connection conn, String funCode) throws SQLException {
		FieldSetEntity Orlfs = null;
		try {
			logger.info("鍔熻兘code" + funCode);
			Orlfs = BaseDaoServiceImpl.getFieldSet(conn, "fe_base5.SYS_FUNCTION", "SF05=?", new Object[]{funCode});
		} catch (Exception e) {
			DataManipulationUtils.close(null, null, conn);
			throw e;
		}
		String sf28 = Orlfs.getString("sf28");
		//鍔熻兘濡傛灉鏈叧鑱斿熀纭€琛� 鏌ヨ娴佺▼琛�
		if (BaseUtil.strIsNull(sf28) || sf28.indexOf(".") == -1) {
			FieldSetEntity modelFse;
			try {
				//鏌ヨ娴佺▼鏄惁缁戝畾琛�
				modelFse = BaseDaoServiceImpl.getFieldSet(conn, "fe_base5.wf_model", "wm05=(SELECT se16  FROM fe_base5.SYS_EVENT where se01=? and se08 = 1)", new Object[]{funCode
				});
			} catch (Exception e) {
				DataManipulationUtils.close(null, null, conn);
				throw e;
			}
			if (modelFse == null) {
				return null;
			}
			String wm04 = modelFse.getString("wm04");
			if (BaseUtil.strIsNull(wm04) || wm04.indexOf(".") == -1) {
				return null;
			} else {
				sf28 = wm04;
			}
		}
		//鍒ゆ柇鏄惁瀛樺湪宸插紑鍙戝姛鑳界殑琛�
		//濡傛灉鏄凡寮€鍙戝姛鑳藉畾涔� 閫氳繃鑷繁瀹氫箟鐨勬暟鎹叧鑱� 鍚屾鏁版嵁
		String[] sf28s = sf28.split("\\.");
		boolean flag = true;
		if (isStr(sf28)) {
			flag = false;
		}
		this.syncTable(sf28s, flag, null, conn);
		return sf28;
	}

	/**
	 * 鍚屾鍏憡琛ㄦ暟鎹�
	 *
	 * @param conn
	 * @param tableName
	 * @throws SQLException
	 */
	private void syncNotice(Connection conn, String tableName) throws SQLException {
		//鍒ゆ柇鏄惁鏄凡缁忓悓姝ヨ繃鐨勮〃
		DataTableEntity dataTable = baseDao.listTable("product_oa_announcement");
		if (!BaseUtil.dataTableIsEmpty(dataTable)) {
			return;
		}
		DataTableEntity noticeDt = null;
		try {
			noticeDt = BaseDaoServiceImpl.getDataTable(conn, tableName, "", new Object[]{});
		} catch (Exception e) {
			DataManipulationUtils.close(null, null, conn);
			throw e;
		}
		for (int i = 0; i < noticeDt.getRows(); i++) {
			FieldSetEntity feFs = noticeDt.getFieldSetEntity(i);
			FieldSetEntity fs = new FieldSetEntity();
			fs.setTableName("product_oa_announcement");
			fs.setValue("title", feFs.getString("title"));
			fs.setValue("content", feFs.getString("content"));
			fs.setValue("type", feFs.getString("notice_category"));
			//Set 杞崲涓哄瓧绗︿覆閫楀彿鍒嗛殧
			//鍐欐柟娉曞垽鏂槸澶氫汉杩樻槸閮ㄩ棬锛岃嫢鏄儴闂ㄨ浆鎹负浜�
			fs.setValue("extent", this.getUserIds(feFs.getString("receivers")));
			fs.setValue("expiration_date", feFs.getDate("displayed_date"));
			fs.setValue("status", feFs.getString("is_reminded"));
			fs.setValue("publish_status", feFs.getString("status"));
			fs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id());
			fs.setValue("created_utc_datetime", new Date());

			String uuid = baseDao.add(fs);
			//閲嶆柊鑾峰彇jdbc杩炴帴
			Connection connection = null;
			try {
				connection = feDataDSService.getJDBC();
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			}
			DataTableEntity subFeFs = getSubDt(connection, "FE_APP5.PUB_NOTICE_RECEIVER", "NOTICE_ID", feFs.getString("id"));
			for (int j = 0; j < subFeFs.getRows(); j++) {
				FieldSetEntity fsSubFe = subFeFs.getFieldSetEntity(j);
				FieldSetEntity fsSub = new FieldSetEntity();
				fsSub.setTableName("product_oa_announcement_role");
				String userId = userIdJson.getString(fsSubFe.getString("receiver"));
				if (null == userId) {
					continue;
				}
				fsSub.setValue("user_id", userId);
				fsSub.setValue("status", fsSubFe.getString("readed"));
				fsSub.setValue("announcement_uuid", uuid);
				baseDao.add(fsSub);
			}
			DataManipulationUtils.close(null, null, connection);
		}
	}

	/**
	 * 鑾峰彇userId
	 *
	 * @param receivers 瀛楁鍊�
	 */
	public String getUserIds(String receivers) throws SQLException {
		String[] receiversArr = receivers.split(",");
		Connection conn = null;
		Set<String> extentArr = new HashSet<>();
		try {
			//鏌ヨ鍏徃閮ㄩ棬琛ㄦ暟鎹�
			conn = feDataDSService.getJDBC();
			for (int j = 0; j < receiversArr.length; j++) {
				if (receiversArr[j].contains("[")) {
					String companyId = receiversArr[j].replace("[", "").replace("]", "");
					StringBuffer sql = new StringBuffer();
					sql.append(" SELECT * FROM FE_BASE5.sys_users WHERE SU03 like CONCAT(CONCAT('%',(SELECT SG03 FROM fe_base5.sys_group WHERE SG00 = " + companyId + ")), '%') ");
					//浜哄憳鏁版嵁
					DataTableEntity dataTableEntity = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new Object[]{});
					String[] remark = new String[dataTableEntity.getRows()];
					for (int i = 0; i < dataTableEntity.getRows(); i++) {
						remark[i] = dataTableEntity.getString(i, "su00");
					}

					DataTableEntity userData = baseDao.listTable("product_sys_staffs", BaseUtil.buildQuestionMarkFilter("remark", remark.length, true), remark);

					if (!BaseUtil.dataTableIsEmpty(userData)) {
						for (int i = 0; i < userData.getRows(); i++) {
							extentArr.add(userData.getString(i, "user_id"));
						}
					}
					//{宀椾綅}
				} else if (receiversArr[j].contains("{")) {
					String postId = receiversArr[j].replace("{", "").replace("}", "");
					StringBuffer sql = new StringBuffer();
					sql.append(" SELECT * FROM FE_BASE5.sys_users WHERE SU34 = " + postId);
					//浜哄憳鏁版嵁
					DataTableEntity dataTableEntity = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new Object[]{});
					String[] remark = new String[dataTableEntity.getRows()];
					for (int i = 0; i < dataTableEntity.getRows(); i++) {
						remark[i] = dataTableEntity.getString(i, "su00");
					}

					DataTableEntity userData = baseDao.listTable("product_sys_staffs", BaseUtil.buildQuestionMarkFilter("remark", remark.length, true), remark);

					if (!BaseUtil.dataTableIsEmpty(userData)) {
						for (int i = 0; i < userData.getRows(); i++) {
							extentArr.add(userData.getString(i, "user_id"));
						}
					}
				} else {
					String userId = userIdJson.getString(receiversArr[j]);
					if (null == userId) {
						continue;
					}
					extentArr.add(userId);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			throw new BaseException(e.getMessage(), e.toString());
		}
		DataManipulationUtils.close(null, null, conn);
		return StringUtils.join(extentArr, ",");
	}

	/**
	 * 鏌ヨ瀛愯〃淇℃伅
	 *
	 * @param conn
	 * @param subTableName 瀛愯〃鍚�
	 * @param fieldName    瀛楁鍚�
	 * @param field        瀛楁鍊�
	 * @return
	 * @throws SQLException
	 */
	private DataTableEntity getSubDt(Connection conn, String subTableName, String fieldName, String field) throws SQLException {
		DataTableEntity noticeDt = null;
		try {
			noticeDt = BaseDaoServiceImpl.getDataTable(conn, subTableName, fieldName + "=?", new Object[]{field});
		} catch (Exception e) {
			DataManipulationUtils.close(null, null, conn);
			throw e;
		}
		return noticeDt;
	}

	/**
	 * 鍚屾闂嵎璋冩煡 0
	 *
	 * @param conn
	 * @param tableName
	 * @throws SQLException
	 */
	private void syncResearchTopic(Connection conn, String tableName) throws SQLException {
		//鍒ゆ柇鏄惁鏄凡缁忓悓姝ヨ繃鐨勮〃
		DataTableEntity dataTable = baseDao.listTable("product_oa_questionnaire");
		if (!BaseUtil.dataTableIsEmpty(dataTable)) {
			return;
		}
		DataTableEntity researchTopicDt = null;
		try {
			researchTopicDt = BaseDaoServiceImpl.getDataTable(conn, tableName, "", new Object[]{});
		} catch (Exception e) {
			DataManipulationUtils.close(null, null, conn);
			throw e;
		}
		JSONObject qSubIdUUIDMap = new JSONObject();
		JSONObject qSubOptionIdUUIDMap = new JSONObject();

		for (int i = 0; i < researchTopicDt.getRows(); i++) {
			FieldSetEntity feFs = researchTopicDt.getFieldSetEntity(i);
			FieldSetEntity fs = new FieldSetEntity();
			//闂嵎绠$悊
			fs.setTableName("product_oa_questionnaire");
			//闂嵎鏍囬
			fs.setValue("questionnaire_title", feFs.getString("rt01"));
			//闂嵎璇存槑
			fs.setValue("questionnaire_explain", feFs.getString("rt01"));
			//闂嵎鍐呭
			fs.setValue("questionnaire_content", feFs.getString("rt02"));
			//鏄惁鍖垮悕锛�1.鏄€�0.鍚︼級
			fs.setValue("is_anonymous", feFs.getString("rt06"));
			String[] RT13Arr = feFs.getString("rt13").split(",");
			ArrayList<String> votersArr = new ArrayList<>();
			for (int j = 0; j < RT13Arr.length; j++) {
				RT13Arr[j] = RT13Arr[j].replace("[", "");
				RT13Arr[j] = RT13Arr[j].replace("]", "");
				String userId = userIdJson.getString(RT13Arr[j]);
			}
			if (votersArr.size() == 0) {
				continue;
			}
			//鍙備笌鎶曠エ浜�
			fs.setValue("voters", StringUtils.join(votersArr, ","));
			//璋冩煡鎴鏃ユ湡
			fs.setValue("deadline", feFs.getString("rt04"));
			String[] RT15Arr = feFs.getString("rt15").split(",");
			String[] resultViewerArr = new String[RT15Arr.length];
			for (int j = 0; j < RT15Arr.length; j++) {
				resultViewerArr[j] = userIdJson.getString(RT15Arr[j]);
			}
			//缁撴灉鏌ョ湅浜�
			fs.setValue("result_viewer", StringUtils.join(resultViewerArr, ","));
			//鍙戝竷浜�
			fs.setValue("publisher", userIdJson.getString(feFs.getString("rt08")));
			//鍙戝竷鏃堕棿
			fs.setValue("pubdate", feFs.getDate("rt03"));
			//鏄惁鍙戝竷
			fs.setValue("is_publish", feFs.getString("rt05"));
			fs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id());
			fs.setValue("created_utc_datetime", new Date());
			//涓昏〃uuid
			String uuid = baseDao.add(fs);
			DataTableEntity subFeFs = getSubDt(conn, "FE_BASE5.RESEARCH_SUB", "RS01", feFs.getString("rt00"));
			for (int j = 0; j < subFeFs.getRows(); j++) {
				FieldSetEntity feSubFs = subFeFs.getFieldSetEntity(i);
				FieldSetEntity subFs = new FieldSetEntity();
				//闂嵎绠$悊瀛愯〃
				subFs.setTableName("product_oa_questionnaire_sub");
				// 涓昏〃uuid
				subFs.setValue("questionnaire_uuid", uuid);
				//鍐呭绫诲瀷锛�1.鍗曢€夐鐩€�2.澶嶉€夐鐩€�3.绠€绛旈锛�
				subFs.setValue("content_type", feSubFs.getInteger("rs04") + 1);
				//閫夐」棰樼洰
				subFs.setValue("option_topic", feSubFs.getString("rs02"));
				//棰樼洰璇存槑
				subFs.setValue("title_description", feSubFs.getString("rs03"));
				//澶氶€夋嫨绫诲瀷锛�1.鏈€澶氥€�2.鏈€灏戙€�3.蹇呴€夛級
				subFs.setValue("option_type", feSubFs.getString("rs07"));
				//鍙€夋嫨椤规暟
				subFs.setValue("option_num", feSubFs.getString("rs06"));
				String subUUID = baseDao.add(subFs);
				qSubIdUUIDMap.put(subUUID, feSubFs.getString("rs00"));
				if (feSubFs.getInteger("rs04") != 2) {
					DataTableEntity subFeFsto = getSubDt(conn, "fe_base5.RESEARCH_OPTION", "RO01", feSubFs.getString("RS00"));
					for (int k = 0; k < subFeFsto.getRows(); k++) {
						FieldSetEntity feSubFsto = subFeFsto.getFieldSetEntity(i);
						FieldSetEntity subFsto = new FieldSetEntity();
						subFsto.setTableName("product_oa_questionnaire_sub_option");
						//闂嵎绠$悊瀛愯〃uuid
						subFsto.setValue("parent_uuid", subUUID);
						//閫夐」鍐呭
						subFsto.setValue("option_content", feSubFsto.getString("ro02"));
						//鏄惁鍙~锛�1.鏄€�0.鍚︼級
						subFsto.setValue("is_write", feSubFsto.getString("ro04"));
						//閫夐」搴忓彿
						subFsto.setValue("option_num", numberToLetter(k + 1));
						String subUUIDto = baseDao.add(subFsto);
						qSubOptionIdUUIDMap.put(feSubFsto.getString("ro00"), subUUIDto);
					}
				}
			}
			DataTableEntity vFeFs = getSubDt(conn, "fe_base5.RESEARCH_VOTER", "rv01", feFs.getString("rt00"));
			for (int j = 0; j < vFeFs.getRows(); j++) {
				FieldSetEntity feSubFs = vFeFs.getFieldSetEntity(j);
				FieldSetEntity subFs = new FieldSetEntity();
				subFs.setTableName("product_oa_questionnaire_mine");
				subFs.setValue("questionnaire_uuid", uuid);
				subFs.setValue("voting_status", feSubFs.getString("rv06"));
				logger.info("鐢ㄦ埛user_id:" + userIdJson.getString(feSubFs.getString("rv04")));
				subFs.setValue("vote_user", userIdJson.getString(feSubFs.getString("rv04")));
				subFs.setValue("subject_uuid", qSubIdUUIDMap.getString(feSubFs.getString("rv02")));
				subFs.setValue("option_answer_uuid", qSubOptionIdUUIDMap.getString(feSubFs.getString("rv03")));
				subFs.setValue("answer_contents", feSubFs.getString("rv07"));
				baseDao.add(subFs);
			}
		}
	}

	//鏁板瓧杞瓧姣� 1-26 锛� A-Z
	private String numberToLetter(int num) {
		if (num <= 0) {
			return null;
		}
		String letter = "";
		num--;
		do {
			if (letter.length() > 0) {
				num--;
			}
			letter = ((char) (num % 26 + (int) 'A')) + letter;
			num = (int) ((num - num % 26) / 26);
		} while (num > 0);

		return letter;
	}

	//杞﹁締鍩烘湰淇℃伅琛�
	private void syncCarInfo(Connection conn, String tableName) throws SQLException {
		//鍒ゆ柇鏄惁鏄凡缁忓悓姝ヨ繃鐨勮〃
		DataTableEntity dataTable = baseDao.listTable("product_oa_car_driver_info");
		if (!BaseUtil.dataTableIsEmpty(dataTable)) {
			return;
		}
		//鍚屾鍙告満淇℃伅
		DataTableEntity driverInfoDt = null;
		try {
			driverInfoDt = BaseDaoServiceImpl.getDataTable(conn, "fe_app5.CHAUFFEUR_INFO", "", new Object[]{});
		} catch (Exception e) {
			DataManipulationUtils.close(null, null, conn);
			throw e;
		}

		JSONObject driverIdUUIDMap = new JSONObject();

		for (int i = 0; i < driverInfoDt.getRows(); i++) {
			FieldSetEntity fsFe = driverInfoDt.getFieldSetEntity(i);
			FieldSetEntity fs = new FieldSetEntity();
			fs.setTableName("product_oa_car_driver_info");
			fs.setValue("name", fsFe.getString("CHAUFFEUR_NAME"));
			fs.setValue("driver_license_num", fsFe.getString("LICENCE_NO"));
			fs.setValue("IDCard_num", fsFe.getString("IDENTITY_CARD_NO"));
			fs.setValue("driving_model", carType(fsFe.getString("DRIVE_CAR_MODEL")));
			fs.setValue("driving_experience", fsFe.getString("DRIVE_YEAR"));
			fs.setValue("phone_num", fsFe.getString("HANDSET_NO"));
			fs.setValue("address", fsFe.getString("ADDRESS"));
			fs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id());
			fs.setValue("created_utc_datetime", new Date());
			String uuid = baseDao.add(fs);
			driverIdUUIDMap.put("ID", uuid);
		}
		//鍚屾杞﹁締鍩烘湰淇℃伅
		DataTableEntity researchTopicDt = null;
		try {
			researchTopicDt = BaseDaoServiceImpl.getDataTable(conn, tableName, "", new Object[]{});
		} catch (Exception e) {
			DataManipulationUtils.close(null, null, conn);
			throw e;
		}
		JSONObject carBrandUUIDMap = new JSONObject();
		JSONObject carIdUUIDMap = new JSONObject();

		for (int i = 0; i < researchTopicDt.getRows(); i++) {
			FieldSetEntity fsFe = researchTopicDt.getFieldSetEntity(i);
			FieldSetEntity fs = new FieldSetEntity();
			fs.setTableName("product_oa_car_info");
			fs.setValue("plate_number", fsFe.getString("CAR_BRAND_NO"));
			fs.setValue("vehicle_status", fsFe.getString("CAR_STATE"));
//            fs.setValue("org_level_uuid", OrgIdUUIDmap.getString(fsFe.getString("CAR_BRAND_NO")));
			fs.setValue("vehicle_type", carType(fsFe.getString("CAR_TYPE")));
			fs.setValue("leaders", userIdJson.getString(fsFe.getString("FROM_LEADER")));
			fs.setValue("purchase_date", fsFe.getDate("BUY_DATE"));
			fs.setValue("brand_series", fsFe.getString("ROAD_BRIDGE_CHARGE"));
			fs.setValue("purchase_price", fsFe.getString("BUY_PRICE"));
			fs.setValue("vehicle_use", fsFe.getString("OIL_CHARGE"));
			fs.setValue("seats_num", fsFe.getString("SEAT_AMOUNT"));
			fs.setValue("fuel_type", fsFe.getString("OIL_TYPE"));
			fs.setValue("owner_name", fsFe.getString("MASTER_NAME"));
			fs.setValue("vehicle_certificate", fsFe.getString("CAR_PAPER"));
			//闄勪欢
//            fs.setValue("attachment_uuid",);
			if (!fsFe.getString("DRIVER").isEmpty()) {
				fs.setValue("driver_id", driverIdUUIDMap.getString(fsFe.getString("DRIVER")));
			}
			fs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id());
			fs.setValue("created_utc_datetime", new Date());
			String uuid = baseDao.add(fs);
			carBrandUUIDMap.put(fsFe.getString("CAR_BRAND_NO"), uuid);
			carIdUUIDMap.put(fsFe.getString("ID"), uuid);
		}
		//鍚屾杞﹁締鍑洪櫓浜嬫晠淇℃伅琛�
		DataTableEntity carSlipDt = null;
		try {
			carSlipDt = BaseDaoServiceImpl.getDataTable(conn, "fe_app5.CAR_SLIP", "", new Object[]{});
		} catch (Exception e) {
			DataManipulationUtils.close(null, null, conn);
			throw e;
		}
		for (int i = 0; i < carSlipDt.getRows(); i++) {
			FieldSetEntity fsFe = carSlipDt.getFieldSetEntity(i);
			FieldSetEntity fs = new FieldSetEntity();
			fs.setTableName("product_oa_car_accident_record");
			fs.setValue("vehicle_info_uuid", carBrandUUIDMap.getString(fsFe.getString("CAR_BRAND_NO")));
			fs.setValue("accident_time", fsFe.getDate("SLIP_DATE"));
			fs.setValue("driver_info_uuid", driverIdUUIDMap.getString(fsFe.getString("DRIVE_PERSON")));
			fs.setValue("accident_location", fsFe.getDate("SLIP_ADDRESS"));
			fs.setValue("accident_cause", fsFe.getDate("SLIP_REASON"));
			fs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id());
			fs.setValue("created_utc_datetime", new Date());
			fs.setValue("flow_flag", 2);
			baseDao.add(fs);
		}
		//鍚屾杞﹁締鐢宠淇℃伅琛�
		DataTableEntity carApplicationDt = null;
		try {
			carApplicationDt = BaseDaoServiceImpl.getDataTable(conn, "fe_app5.CAR_APPLICATION", "", new Object[]{});
		} catch (Exception e) {
			DataManipulationUtils.close(null, null, conn);
			throw e;
		}
		for (int i = 0; i < carApplicationDt.getRows(); i++) {
			FieldSetEntity fsFe = carApplicationDt.getFieldSetEntity(i);
			FieldSetEntity fs = new FieldSetEntity();
			fs.setTableName("product_oa_car_application");
			fs.setValue("applicant", userIdJson.getString(fsFe.getString("PROPOSER")));
//            fs.setValue("org_level_uuid", OrgIdUUIDmap.getString(fsFe.getString("SECTION_DEPARTMENT")));
			fs.setValue("applicattion_time", fsFe.getDate("APPLICATION_DATE"));
			fs.setValue("start_place", fsFe.getString("START_END_ADDRESS"));
			fs.setValue("person_board", fsFe.getString("FOLLOW_PERSON"));
			fs.setValue("vehicle_line", fsFe.getString("CAR_LINE"));
			fs.setValue("scheduled_start_time", fsFe.getDate("USE_START_DATE"));
			fs.setValue("scheduled_end_time", fsFe.getDate("USE_END_DATE"));
			fs.setValue("project_name", fsFe.getString("USE_END_DATE"));
			fs.setValue("use_reason", fsFe.getString("USE_REASON"));
			if (!fsFe.getString("DRIVER").isEmpty()) {
				fs.setValue("driver_info_uuid", driverIdUUIDMap.getString(fsFe.getString("DRIVER")));
			}
			fs.setValue("status", fsFe.getString("STATUS"));
			fs.setValue("driving_time", fsFe.getString("START_DATE"));
			fs.setValue("return_time", fsFe.getString("RETURN_DATE"));
			fs.setValue("actual_line", fsFe.getString("FACT_WAY"));
			fs.setValue("repair_cost", fsFe.getString("id04"));
			fs.setValue("fuel_charge", fsFe.getString("OIL_CHARGE"));
			fs.setValue("toll", fsFe.getString("id05"));
			fs.setValue("other_expenses", fsFe.getString("id01"));
			fs.setValue("total_cost", fsFe.getString("id02"));
			fs.setValue("manager_confirmation", fsFe.getString("id08"));
			fs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id());
			fs.setValue("created_utc_datetime", new Date());
			fs.setValue("flow_flag", 2);
			baseDao.add(fs);
		}
	}

	private String carType(String type) {
		String reType = "";
		switch (type) {
			case "杞胯溅":
				reType = "1";
				break;
			case "璐ц溅":
				reType = "2";
				break;
			default:
				reType = "3";
		}
		return reType;
	}

	/**
	 * 鍚屾宸插紑鍙戝姛鑳芥暟鎹�
	 *
	 * @param tableName 琛ㄥ悕
	 * @return
	 * @throws SQLException
	 */
	private void syncFunTable(Connection conn, String tableName) throws SQLException {
		//鍏憡琛�
		if (tableName.equals("FE_APP5.PUB_NOTICE")) {
			syncNotice(conn, tableName);
			//涓や釜琛ㄥ缓绔嬪叧鑱�
			this.originalTable.put("PUB_NOTICE", "product_oa_announcement");
		}
		//鍚屾闂嵎璋冩煡
		if (tableName.equals("FE_BASE5.RESEARCH_TOPIC")) {
			syncResearchTopic(conn, tableName);
			this.originalTable.put("RESEARCH_TOPIC", "product_oa_questionnaire");
		}
		//鑰冨嫟琛�
		if (tableName.equals("FE_APP5.APP_KQLRB")) {
			this.synchronousClock(conn, tableName);
		}
		//杞﹁締鍩烘湰淇℃伅琛�  涓虹┖
		if (tableName.equals("FE_APP5.CAR_INFO")) {
			syncCarInfo(conn, tableName);
			this.originalTable.put("CAR_INFO", "product_oa_car_driver_info");
		}
		//鍗忓悓鍔炲叕  涓嶇
		if (tableName.equals("FE_BASE5.SYS_COLLABORATIVE")) {
			syncCcooperates(conn, tableName);
			this.originalTable.put("SYS_COLLABORATIVE", "product_oa_cooperates");
		}

		//浼氳瀹ょ敵璇�
		if (tableName.equals("FE_APP5.BS_MEETING_FLOW")) {

		}
		//浼氳瀹ょ鐞�
		if (tableName.equals("FE_APP5.BS_MEETINGROOM")) {

		}
	}

	/**
	 * 鍚屾鑰冨嫟鏁版嵁
	 */
	private void synchronousClock(Connection conn, String tableName) throws SQLException {
		DataTableEntity clockDt = null;
		try {
			clockDt = BaseDaoServiceImpl.getDataTable(conn, tableName, "", new Object[]{});
		} catch (Exception e) {
			DataManipulationUtils.close(null, null, conn);
			throw e;
		}
		if (!BaseUtil.dataTableIsEmpty(clockDt)) {
			for (int i = 0; i < clockDt.getRows(); i++) {
				FieldSetEntity fse = clockDt.getFieldSetEntity(i);
				FieldSetEntity fieldSetEntity = new FieldSetEntity();
				fieldSetEntity.setTableName("product_oa_punch_record");
				//鍏徃閮ㄩ棬id
				String dept = fse.getString("dept");

				//mac鍦板潃
				String mac = fse.getString("mac");
			}
		}

	}

	/**
	 * 浼氳瀹ょ敵璇�
	 *
	 * @param conn
	 * @param tableName
	 */
	private void ConferenceRoomApplication(Connection conn, String tableName) throws SQLException {
		//鍒ゆ柇鏄惁鏄凡缁忓悓姝ヨ繃鐨勮〃
		DataTableEntity dataTable = baseDao.listTable("product_oa_conference_apply");
		if (!BaseUtil.dataTableIsEmpty(dataTable)) {
			return;
		}
		DataTableEntity ccooperatesDt = null;
		try {
			ccooperatesDt = BaseDaoServiceImpl.getDataTable(conn, tableName, "", new Object[]{});
		} catch (Exception e) {
			DataManipulationUtils.close(null, null, conn);
			throw e;
		}
	}

	//鍚屾鍗忓悓鍔炲叕
	private void syncCcooperates(Connection conn, String tableName) throws SQLException {
		//鍒ゆ柇鏄惁鏄凡缁忓悓姝ヨ繃鐨勮〃
		DataTableEntity dataTable = baseDao.listTable("product_oa_cooperates");
		if (!BaseUtil.dataTableIsEmpty(dataTable)) {
			return;
		}
		DataTableEntity ccooperatesDt = null;
		try {
			ccooperatesDt = BaseDaoServiceImpl.getDataTable(conn, tableName, "", new Object[]{});
		} catch (Exception e) {
			DataManipulationUtils.close(null, null, conn);
			throw e;
		}

		DataTableEntity accessoryData = this.getTableNameAttachment(conn, tableName);
		for (int i = 0; i < ccooperatesDt.getRows(); i++) {
			FieldSetEntity feFs = ccooperatesDt.getFieldSetEntity(i);
			FieldSetEntity fs = new FieldSetEntity();
			fs.setTableName("product_oa_cooperates");
			//鏍囬
			fs.setValue("title", feFs.getString("title"));
			String content = feFs.getString("content");
			if (BaseUtil.strIsNull(content)) {
				content = "";
			}
			//鍐呭
			fs.setValue("content", content);
			String important = feFs.getString("important");
			if (!BaseUtil.strIsNull(important)) {
				//绱ф€ョ▼搴︼紙1.骞充欢銆�2.鎬ヤ欢銆�3.鐗规€ャ€�4.鐗规彁锛�
				fs.setValue("emergency_degree", emergencyDegreeType(important));
			} else {
				//涓虹┖灏辨斁0
				fs.setValue("emergency_degree", 0);
			}
			//闄勪欢hiddenidea
			// fs.setValue("attachment",);
			//鍙戣捣鏃堕棿
			fs.setValue("start_time", feFs.getString("stime"));
			//鏄惁鍏佽杞彂锛�1.鏄€�0.鍚︼級
			fs.setValue("is_forward", feFs.getString("repeating"));
			//鏄惁鍏佽鍔犵锛�1.鏄€�0.鍚︼級
			fs.setValue("is_countersign", feFs.getString("modifyflow"));
			//鏄惁鍏佽璺熻釜锛�1.鏄€�0.鍚︼級
			fs.setValue("is_track", feFs.getString("track"));
			//鏄惁闅愯棌鍥炲鎰忚锛�1.鏄€�0.鍚︼級
			fs.setValue("is_hide_comments", feFs.getString("hiddenidea"));
			//鐘舵€侊紙0.寰呭彂銆�1.宸插彂锛�
			fs.setValue("status", 1);
			fs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id());
			fs.setValue("created_utc_datetime", new Date());
			Map<String, List<String>> fileMaps = this.synchronizationAttachments(conn, accessoryData, feFs, fs.getTableName());
			List<String> value = fileMaps.get("COL_MDL_CONTENT_MEDIA");
			//瀛樺叆闄勪欢uuid
			fs.setValue("attachment", StringUtils.join(value, ","));
			String uuid = baseDao.add(fs);

			DataTableEntity coNodeDt = null;
			try {
				//flowcode 娴佺▼瀛楁
				coNodeDt = BaseDaoServiceImpl.getDataTable(conn, "SELECT a.NAME receiver_name,a.VALUE receiver,b.NAME sender_name,b.VALUE sender,a.STATUS ,a.PARENTGUID PARENTGUID ,a.MGUID MGUID FROM WF_CO_NODE a LEFT JOIN WF_CO_NODE b on a.PARENTGUID=b.GUID where a.MGUID=?", new Object[]{feFs.getString("flowcode")});
			} catch (Exception e) {
				DataManipulationUtils.close(null, null, conn);
				throw e;
			}
			JSONObject grade = new JSONObject();
			for (int j = 0; j < coNodeDt.getRows(); j++) {
				FieldSetEntity subfsFe = coNodeDt.getFieldSetEntity(j);
				FieldSetEntity subfs = new FieldSetEntity();
				//鍗忓悓鍔炲叕娴佺▼琛�
				subfs.setTableName("product_oa_cooperate_flow_node");
				grade.put(subfsFe.getString("guid"), 1);
				//鍔炵悊浜哄眰绾�
				subfs.setValue("grade", 1);
				//鍏宠仈鍗忓悓琛╱uid
				subfs.setValue("cooperate_uuid", uuid);
				//鎺ユ敹浜猴紙鍏宠仈鐢ㄦ埛琛╥d锛�
				subfs.setValue("receiver", subfsFe.getString("receiver"));
				//鎺ユ敹浜哄鍚�
				subfs.setValue("receiver_name", subfsFe.getString("receiver_name"));
				//鍙戦€佷汉锛堝叧鑱旂敤鎴疯〃id锛�
				subfs.setValue("sender", subfsFe.getString("sender"));
				//鍙戦€佷汉濮撳悕
				subfs.setValue("sender_name", subfsFe.getString("sender_name"));
				//0:鏈敹鏈姙 1:宸叉敹鏈� 2:宸叉敹宸插姙
				subfs.setValue("status", subfsFe.getInteger("status") == 1 ? 2 : 0);
				//0:鏆傚瓨 1:鍔犵 2:杞彂 3:閫€鍥�4:閫佸姙 5:缁堟 6:鎾ら攢
				subfs.setValue("type", 0);


				String uuids = baseDao.add(subfs);
//                DataTableEntity IDEAMANAGEDt = null;
//                try {
//                    IDEAMANAGEDt = BaseDaoServiceImpl.getDataTable(conn, "select c.ID02 ID02,c.ID03 ID03,c.ID04 ID04,c.ID08 ID08 from FE_BASE5.WF_TASK a  JOIN FE_BASE5.WF_INFOR b  on a.WT00=b.WI01  JOIN  FE_BASE5.IDEAMANAGE c on b.WI21= c.ID06  where a. WT13=? ", new Object[]{subfsFe.getString("mguid")});
//                } catch (Exception e) {
//                    DataManipulationUtils.close(null, null, conn);
//                    throw e;
//                }
//                for (int k = 0; k < IDEAMANAGEDt.getRows(); k++) {
//                    FieldSetEntity subfsFeto = coNodeDt.getFieldSetEntity(i);
//                    FieldSetEntity subfsto = new FieldSetEntity();
//                    //鍗忓悓鍔炲叕鐣欒█琛�
//                    subfsto.setTableName("product_oa_cooperate_flow_reply");
//                    //鍏宠仈product_oa_cooperate_flow_node琛╱uid
//                    subfsto.setValue("parent_uuid", uuids);
//                    //鍥炲鍐呭
//                    subfsto.setValue("reply_content", subfsFeto.getString("id04"));
//                    //鍥炲鏃堕棿
//                    subfsto.setValue("reply_datetime", subfsFeto.getString("id03"));
//                    //鍥炲浜猴紝鍏宠仈user琛╥d
//                    subfsto.setValue("reply_user", this.getUserId(subfsFeto.getInteger("id02")));
//                    baseDao.add(subfsto);
//                    //闄勪欢
////                    subfsto.setValue("reply_attachment",);
//                }
			}
		}
	}

	private String emergencyDegreeType(String type) {
		String reType = "";
		switch (type) {
			case "骞充欢":
				reType = "1";
				break;
			case "鍔犳€�":
				reType = "2";
				break;
			case "鐗规€�":
				reType = "3";
				break;
			case "鐗规彁":
				reType = "4";
				break;
			default:
				throw new BaseException(SystemCode.FIELD_TYPE_FIAL.getValue(), SystemCode.FIELD_TYPE_FIAL.getText() + "_" + type);

		}
		return reType;
	}

	/**
	 * 杩佺Щ鍔熻兘鏉冮檺璁稿彲
	 *
	 * @param conn      JDBC杩炴帴
	 * @param funUUID   鏂规硶uuid
	 * @param funCode   鍔熻兘code
	 * @param buttonMap 鎸夐挳map
	 * @throws SQLException
	 */
	public void syncFunctionPermission(Connection conn, String funUUID, String funCode, JSONObject buttonMap) throws SQLException {
		DataTableEntity permissionDt = null;
		try {
			permissionDt = BaseDaoServiceImpl.getDataTable(conn, "fe_base5.SYS_FUNCTION_USER", "FU02=?", new Object[]{funCode});
		} catch (Exception e) {
			DataManipulationUtils.close(null, null, conn);
			throw e;
		}
		Map<String, DataTableEntity> funUsers = Maps.newHashMap();
		for (int i = 0; i < permissionDt.getRows(); i++) {
			FieldSetEntity permissionFs = permissionDt.getFieldSetEntity(i);
			FieldSetEntity fs = new FieldSetEntity();
			fs.setTableName("product_sys_function_permission");
			fs.setValue("function_uuid", funUUID);
			//瑙掕壊id
			String fu01 = permissionFs.getString("fu01");
			//璇ユ潈闄愮鐞嗙殑鏄敤鎴疯〃锛圫YS_USERS锛�  骞堕潪瑙掕壊琛�
			if ("U".equals(permissionFs.getString("fu03"))) {
				String fu04 = permissionFs.getString("fu04");
				DataTableEntity data = funUsers.get(fu04);
				if (BaseUtil.dataTableIsEmpty(data)) {
					data = new DataTableEntity();
				}
				data.addFieldSetEntity(permissionFs);
				funUsers.put(fu04, data);
				continue;
			}
			//鑾峰彇瑙掕壊鏁版嵁
			FieldSetEntity roleFse = baseDao.getFieldSetEntityByFilter("product_sys_role", " sequence = ? ", new String[]{fu01}, true);
//            String orgLevelUuid = roleFse.getString("org_level_uuid");
			fs.setValue("role_uuid", roleFse.getUUID());
			String fu04 = permissionFs.getString("fu04");
			//鑾峰彇鏉冮檺閲岀殑鎸夐挳
			List<String> buttonIdType = new ArrayList<>();
			buttonIdType.add(funCode);
			for (int j = 0; j < fu04.length(); j++) {
				String type = String.valueOf(fu04.charAt(j));
				if (type.equals("1")) {
					//鏀惧叆鍊肩殑涓嬫爣
					buttonIdType.add(buttonTypeRole(j));
				}
			}
			if (buttonIdType.size() == 1) {
				continue;
			}
			DataTableEntity eventDt = null;
			try {
				StringBuffer where = new StringBuffer();
				where.append(" SE01=? ").append(" and ( ").append(BaseUtil.buildQuestionMarkFilter("SE12", buttonIdType.size() - 1, true)).append(" or SE08=1) ");
				eventDt = BaseDaoServiceImpl.getDataTable(conn, "fe_base5.SYS_EVENT", where.toString(), buttonIdType.toArray());
			} catch (Exception e) {
				DataManipulationUtils.close(null, null, conn);
				throw e;
			}
			List<String> buttonId = new ArrayList<>();
			for (int j = 0; j < eventDt.getRows(); j++) {
				buttonId.add(buttonMap.getString(eventDt.getString(j, "se00")));
			}
			buttonId.addAll(this.buttonUuid);
			fs.setValue("button_uuid", StringUtils.join(buttonId, ","));
			fs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id());
			fs.setValue("created_utc_datetime", new Date());
			baseDao.add(fs);
		}
		//鍚屾姣忎釜鍔熻兘鏉冮檺鍚�   杩樿鍚屾瀹㈡埛鏉冮檺
		this.customerPermission(funUUID, buttonMap);
	}

	/**
	 * 鍚屾瀹㈡埛鏉冮檺
	 *
	 * @param funUUID   鍔熻兘鏉冮檺
	 * @param buttonMap 妗堜緥uuid map
	 */
	public void customerPermission(String funUUID, JSONObject buttonMap) {
		FieldSetEntity fs = new FieldSetEntity();
		fs.setTableName("product_sys_function_permission");
		fs.setValue("function_uuid", funUUID);
		//瀹㈡埛uuid
		fs.setValue("role_uuid", "8dddd416-a790-4a4e-8418-8c032d5f2394");
		List<String> buttonUuid = new ArrayList<>();
		for (String key : buttonMap.keySet()) {
			buttonUuid.add(buttonMap.getString(key));
		}
		//鑻ユ病鏈夋寜閽� 鐩存帴閫€鍑�
		if (buttonUuid.size() == 0) {
			return;
		}
		fs.setValue("button_uuid", StringUtils.join(buttonUuid, ","));
		fs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id());
		fs.setValue("created_utc_datetime", new Date());
		baseDao.add(fs);
	}

	/**
	 * 鍒涘缓涓€涓姛鑳戒笅鐨勮鑹�
	 * 鎶婄洿鎺ュ叧鑱斿姛鑳界殑鐢ㄦ埛鏀惧叆瑙掕壊涓�
	 *
	 * @param conn         杩炴帴
	 * @param map          k 涓烘寜閽潈闄愶紝u 涓哄叧鑱旂敤鎴锋潈闄愮殑data
	 * @param funUUID      鍔熻兘uuid
	 * @param funCode      鍔熻兘code
	 * @param buttonJson   鎸夐挳json
	 * @param orgLevelUuid 鍏徃uuid
	 */
	public void newFunctionRole(Connection conn, Map<String, DataTableEntity> map, String funUUID, String funCode, JSONObject buttonJson, String orgLevelUuid) {
		for (Map.Entry<String, DataTableEntity> m : map.entrySet()) {
			List<String> buttonIdType = new ArrayList<>();
			buttonIdType.add(funCode);
			String key = m.getKey();
			for (int j = 0; j < key.length(); j++) {
				String type = String.valueOf(key.charAt(j));
				if (type.equals("1")) {
					//鏀惧叆鍊肩殑涓嬫爣
					buttonIdType.add(buttonTypeRole(j));
				}
			}
			//鏌ヨ杩欐潯鍔熻兘鏁版嵁
			FieldSetEntity funFse = baseDao.getFieldSetEntity("product_sys_function", funUUID, false);
			//鍔熻兘鍚嶇О
			String functionName = funFse.getString("function_name");
			//鍒涘缓瑙掕壊
			FieldSetEntity lxRoleFs = new FieldSetEntity();
			lxRoleFs.setTableName("product_sys_role");
			if (BaseUtil.strIsNull(orgLevelUuid)) {
				orgLevelUuid = SpringMVCContextHolder.getCurrentUser().getOrg_level_uuid();
			}
			lxRoleFs.setValue("org_level_uuid", orgLevelUuid);

			String name = functionName + "鍔熻兘涓嬭鑹�";
			lxRoleFs.setValue("role_name", name);
			lxRoleFs.setValue("role_description", name);
			lxRoleFs.setValue("is_used", 1);
			feDataDSService.userAndTime(lxRoleFs);
			baseDao.add(lxRoleFs);
			FieldSetEntity fs = new FieldSetEntity();
			fs.setTableName("product_sys_function_permission");
			fs.setValue("function_uuid", funUUID);
			StringBuffer where = new StringBuffer();
			where.append(" SE01=? ").append(" and ( ").append(BaseUtil.buildQuestionMarkFilter("SE12", buttonIdType.size() - 1, true)).append(" or SE08=1) ");
			DataTableEntity eventDt = BaseDaoServiceImpl.getDataTable(conn, "fe_base5.SYS_EVENT", where.toString(), buttonIdType.toArray());
			List<String> buttonId = new ArrayList<>();
			for (int j = 0; j < eventDt.getRows(); j++) {
				buttonId.add(buttonJson.getString(eventDt.getString(j, "se00")));
			}
			fs.setValue("button_uuid", StringUtils.join(buttonId, ","));
			fs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id());
			fs.setValue("created_utc_datetime", new Date());
			//鍒涘缓瑙掕壊
			String uuid = baseDao.add(fs);
			//瑙掕壊鍏宠仈鐢ㄦ埛uuid
			DataTableEntity dataTableEntity = map.get(key);
			//鑾峰彇鍏宠仈鐢ㄦ埛
			for (int i = 0; i < dataTableEntity.getRows(); i++) {
				String userId = dataTableEntity.getString(i, "fu01");
				//鑾峰彇鐢ㄦ埛
				FieldSetEntity fieldSetEntity = baseDao.getFieldSetEntityByFilter("product_sys_staffs", " remark = ? ", new String[]{userId}, false);
				String roleUuids = fieldSetEntity.getString("role_uuids");
				if (BaseUtil.strIsNull(roleUuids)) {
					fieldSetEntity.setValue("role_uuids", uuid);
				} else {
					roleUuids = roleUuids + "," + uuid;
					fieldSetEntity.setValue("role_uuids", roleUuids);
				}
				//淇濆瓨淇敼瑙掕壊鏉冮檺鍚庣殑鐢ㄦ埛
				baseDao.add(fieldSetEntity);
			}

		}
	}

	private String buttonTypeRole(int type) {
		String button_category_uuid = "";
		switch (type) {
			case 0:
				button_category_uuid = "01";
				break;
			case 1:
				button_category_uuid = "02";
				break;
			case 2:
				button_category_uuid = "03";
				break;
			case 3:
				button_category_uuid = "04";
				break;
			case 4:
				button_category_uuid = "05";
				break;
			case 5:
				button_category_uuid = "06";
				break;
			case 6:
				button_category_uuid = "07";
				break;
			case 7:
				button_category_uuid = "08";
				break;
			case 8:
				button_category_uuid = "09";
				break;
			case 9:
				button_category_uuid = "10";
				break;
			case 10:
				button_category_uuid = "11";
				break;
			case 11:
				button_category_uuid = "12";
				break;
			default:
				throw new BaseException(SystemCode.FIELD_TYPE_FIAL.getValue(), SystemCode.FIELD_TYPE_FIAL.getText() + "_" + type);
		}
		return button_category_uuid;
	}

	/**
	 * 杩佺Щ鍔熻兘涓嬬殑鎸夐挳椤甸潰
	 *
	 * @param conn
	 * @param funUUID
	 * @param funCode
	 * @throws SQLException
	 */
	public JSONObject syncButtonsPage(Connection conn, String funUUID, String funCode) throws SQLException {
		DataTableEntity buttonsDt = null;
		try {//鑾峰彇鏄剧ず鎸夐挳
			buttonsDt = BaseDaoServiceImpl.getDataTable(conn, "fe_base5.SYS_EVENT", "SE30 = '1' AND SE01= ? ", new Object[]{funCode});
		} catch (Exception e) {
			DataManipulationUtils.close(null, null, conn);
			throw e;
		}
		String flow_uuid = null;
		String sendButton = null;
		JSONObject map = new JSONObject();
		//鍚嶅瓧涓簁 鐨刯son
		Map<String, FieldSetEntity> nameButtonMap = Maps.newHashMap();
		for (int i = 0; i < buttonsDt.getRows(); i++) {
			FieldSetEntity buttonsFs = buttonsDt.getFieldSetEntity(i);
			FieldSetEntity fs = new FieldSetEntity();
			//椤甸潰琛�
			fs.setTableName("product_sys_function_buttons");
			fs.setValue("function_uuid", funUUID);
			//鎸夐挳鍚嶇О
			fs.setValue("button_name", buttonsFs.getString("se02"));
			//鎸夐挳鏍囬 濡傛灉涓虹┖  灏辩敤鎻忚堪
			String buttonsFsString = buttonsFs.getString("se31");
			if (BaseUtil.strIsNull(buttonsFsString) || " ".equals(buttonsFsString)) {
				buttonsFsString = buttonsFs.getString("se09");
			}
			fs.setValue("button_title", buttonsFsString);
			//鎸夐挳鎻忚堪
			fs.setValue("button_description", buttonsFs.getString("se09"));
			//鐐瑰嚮瑙﹀彂鎸夐挳浜嬩欢鐨勭被鍨嬶細1: 鍏ュ彛锛�2:鏅€氭寜閽�  鑻ヤ负鍏ュ彛鍙兘浼氱粦瀹氭祦绋�
			if (buttonsFs.getInteger("se08") == 1) {
				fs.setValue("button_type", 1);
				//缁戝畾鐨勬祦绋�
				String se16 = buttonsFs.getString("se16");
				//涓嶄负绌� 鍗曠嫭澶勭悊娴佺▼鍏宠仈
				if (!BaseUtil.strIsNull(se16)) {
					flow_uuid = se16;
				}
			} else {
				fs.setValue("button_type", 2);
			}
			fs.setValue("button_type", buttonsFs.getInteger("se08") == 1 ? 1 : 2);
			//鏄惁鍚敤
			fs.setValue("status_uuid", 1);
			String type;
			if (buttonsFs.getInteger("se08") == 1) {
				//鏄惁涓哄姛鑳藉叆鍙o紝1=鏄紝0=鍚�
				fs.setValue("is_main", 1);
				type = "main";
			} else {
				type = buttonType(buttonsFs.getString("se12"));
				fs.setValue("is_main", 0);
			}
			//鎸夐挳鍒嗙被锛氬叧鑱斿瓧鍏歌〃(鏂板锛屼慨鏀癸紝鍒犻櫎锛屾煡鐪嬶紝鍒楄〃锛屽鍏ワ紝瀵煎嚭锛岄€佸)

			fs.setValue("button_category_uuid", type);
			//鏄垹闄ゆ寜閽�   閮藉閫�
			if ("delete".equals(type)) {
				//鏄惁澶氶€�  1 鏄�
				fs.setValue("multiple_choice", 1);
				//鏄惁鎻愰啋
				fs.setValue("is_warn", 1);
			} else {
				//鏄惁澶氶€�  1 鏄�
				fs.setValue("multiple_choice", 0);
				fs.setValue("is_warn", 0);
			}
			//瀹㈡埛绔被鍨嬶細鍏宠仈鏁版嵁瀛楀吀
			fs.setValue("client_type_uuid", "Web");
			//浣嶇疆top
			fs.setValue("top_location", buttonsFs.getInteger("se11") + "px");
			//浣嶇疆left
			fs.setValue("left_location", buttonsFs.getInteger("se10") + "px");
			//浜嬩欢鍓� fron_event 1000
			fs.setValue("fron_event", buttonsFs.getString("se03"));
			//閫昏緫鏂规硶 logical_method  800
			fs.setValue("logical_method", buttonsFs.getString("se04"));
			//浜嬩欢鍚� event_after  900
			fs.setValue("event_after", buttonsFs.getString("se05"));
			//鑴氭湰绫诲瀷 event_type 250
			fs.setValue("event_type", buttonsFs.getString("se15"));
			//寮曞叆鑴氭湰 script_method 鏆備笉鎻掑叆
//            System.out.println("se14:" + buttonsFs.getString("se14"));
//            fs.setValue("script_method", buttonsFs.getString("se14"));
			//璺敱鍚嶇О
			fs.setValue("route_name", BaseUtil.getPageCode());
			String uuid = baseDao.add(fs);
			//09涓洪€佸姙鎸夐挳
			if ("09".equals(buttonsFs.getString("se12")) && !BaseUtil.strIsNull(buttonsFs.getString("se14"))) {
				sendButton = uuid;
			}
			map.put(buttonsFs.getString("se00"), uuid);
			//鍚嶅瓧鍞竴
			nameButtonMap.put(buttonsFs.getString("se09"), fs);
		}

		DataTableEntity pageDt = null;
		try {
			pageDt = BaseDaoServiceImpl.getDataTable(conn, "fe_base5.SYS_PAGE", "SP01=?", new Object[]{funCode});
		} catch (Exception e) {
			DataManipulationUtils.close(null, null, conn);
			throw e;
		}
		JSONObject pageMap = new JSONObject();
		Map<String, FieldSetEntity> pageNameMap = Maps.newHashMap();
		for (int i = 0; i < pageDt.getRows(); i++) {
			FieldSetEntity pageFs = pageDt.getFieldSetEntity(i);
			FieldSetEntity fs = new FieldSetEntity();
			//椤甸潰琛�
			fs.setTableName("product_sys_mvc_page");
			fs.setValue("function_uuid", funUUID);
			//椤甸潰鍚嶇О
			String sp02 = pageFs.getString("sp02");
			fs.setValue("page_name", sp02);
			//绂佺敤椤甸潰鍏冪礌
			fs.setValue("page_element_disabled", 0);
			fs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id());
			fs.setValue("created_utc_datetime", new Date());
			//浣嶇疆top
			fs.setValue("top_location", pageFs.getString("sp07"));
			//浣嶇疆left
			fs.setValue("left_location", pageFs.getString("sp06"));
			//琛ㄥ崟绫诲瀷 鍚嶇О甯︽湁鍒楄〃閮芥槸鍒楄〃绫诲瀷
			if (sp02.contains("鍒楄〃")) {
				fs.setValue("page_type", 1);
			} else {
				fs.setValue("page_type", 0);
			}
			//椤甸潰鏄惁鍙慨鏀�
			fs.setValue("page_element_disabled", pageFs.getInteger("sp08") == 1 ? 0 : 1);
			//椤甸潰璺緞鏆傚瓨   fe寮曞叆js浠g爜璺緞
			fs.setValue("page_url", pageFs.getString("sp09"));
			//鍏堝瓨鍏ユ祦绋媔d    杩佺Щ娴佺▼鍚庡啀鏇挎崲
			fs.setValue("flow_uuid", pageFs.getString("sp09"));
			//鎵撳紑鏂瑰紡
			fs.setValue("page_open_with", 0);
			String uuid = baseDao.add(fs);
			pageMap.put(pageFs.getString("sp00"), uuid);
			pageNameMap.put(sp02, fs);
		}
		DataTableEntity pageButtonDt = null;
		try {
			pageButtonDt = BaseDaoServiceImpl.getDataTable(conn, "fe_base5.SYS_EVENT_PAGE", "SEP06=?", new Object[]{funCode});
		} catch (Exception e) {
			DataManipulationUtils.close(null, null, conn);
			throw e;
		}
		for (int i = 0; i < pageButtonDt.getRows(); i++) {
			FieldSetEntity pageButtonFs = pageButtonDt.getFieldSetEntity(i);
			FieldSetEntity fs = new FieldSetEntity();
			fs.setTableName("product_sys_link");
			fs.setValue("function_uuid", funUUID);
			//杩炵嚎绫诲瀷
			fs.setValue("link_type", 0);
			//璧峰uuid
			String pageUuid = pageMap.getString(pageButtonFs.getString("sep01"));
			fs.setValue("line_from", pageUuid);
			//璧峰绫诲瀷 椤甸潰
			fs.setValue("from_type", 2);
			//鎴uuid
			String buttonUuid = map.getString(pageButtonFs.getString("sep02"));
			//涓虹┖琛ㄧず鍏宠仈澶辨晥鐨勬寜閽�  锛屽氨涓嶆惉
			if (BaseUtil.strIsNull(buttonUuid)) {
				continue;
			}
			fs.setValue("line_to", buttonUuid);
			//鐩哥瓑璇存槑涓洪€佸姙   鎵惧埌椤甸潰uuid瀛樺叆娴佺▼
			if (!BaseUtil.strIsNull(flow_uuid) && buttonUuid != null && buttonUuid.equals(sendButton)) {
				if (pageUuid != null) {
					FieldSetEntity fse = baseDao.getFieldSetEntity("product_sys_mvc_page", pageUuid, false);
					fse.setValue("flow_uuid", flow_uuid);
					baseDao.update(fse);
				}
			}
			//鎴绫诲瀷
			fs.setValue("to_type", 1);
			fs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id());
			fs.setValue("created_utc_datetime", new Date());

			baseDao.add(fs);
		}
		DataTableEntity buttonPageDt = null;
		try {
			//鎸夐挳杩為〉闈�   鎸夐挳杩炴寜閽�
			buttonPageDt = BaseDaoServiceImpl.getDataTable(conn, "fe_base5.SYS_REDIRECT", "SR06=?", new Object[]{funCode});
		} catch (Exception e) {
			DataManipulationUtils.close(null, null, conn);
			throw e;
		}
		for (int i = 0; i < buttonPageDt.getRows(); i++) {
			FieldSetEntity buttonPageFs = buttonPageDt.getFieldSetEntity(i);
			FieldSetEntity fs = new FieldSetEntity();
			fs.setTableName("product_sys_link");
			fs.setValue("function_uuid", funUUID);
			fs.setValue("link_type", 0);
			//鎸夐挳涓庨〉闈㈡垨鑰呮寜閽笌椤甸潰鍏崇郴瀛楁
			String sr05 = buttonPageFs.getString("sr05");
			String[] sr05s = sr05.split("-->");
			FieldSetEntity buttonFse = nameButtonMap.get(sr05s[0]);
			if (buttonFse == null) {
				continue;
			}
			//鍒ゆ柇鏄惁鏄叆鍙�
			if (1 == buttonFse.getInteger("is_main")) {
				//璧峰绫诲瀷 0 鍏ュ彛 1 鎸夐挳 2 椤甸潰
				fs.setValue("from_type", 0);
			} else {
				//璧峰绫诲瀷 0 鍏ュ彛 1 鎸夐挳 2 椤甸潰
				fs.setValue("from_type", 1);
			}
			fs.setValue("line_from", buttonFse.getUUID());
			//鑾峰彇鎸夐挳淇℃伅
			//杩炴帴绫诲瀷  1鎸夐挳杩炴寜閽�   0鎸夐挳杩為〉闈�
			Integer sr02 = buttonPageFs.getInteger("sr02");
			//杩炴帴鐨勬槸鎸夐挳
			if (1 == sr02) {
				//鑾峰彇鎸夐挳fse 1
				FieldSetEntity buttonFse2 = nameButtonMap.get(sr05s[1]);
				if (buttonFse2 == null) {
					continue;
				}
				//鍒ゆ柇鏄惁鏄叆鍙�
				if (1 == buttonFse2.getInteger("is_main")) {
					//缁撴潫绫诲瀷 0 鍏ュ彛 1 鎸夐挳 2 椤甸潰
					fs.setValue("to_type", 0);
				} else {
					fs.setValue("to_type", 1);
				}
				fs.setValue("line_to", buttonFse2.getUUID());
			} else {
				//杩炴帴鐨勬槸椤甸潰
				//鑾峰彇椤甸潰fse 0
				FieldSetEntity pageFse = pageNameMap.get(sr05s[1]);
				if (pageFse == null) {
					continue;
				}
				//椤甸潰绫诲瀷
				fs.setValue("to_type", 2);
				//椤甸潰uuid
				fs.setValue("line_to", pageFse.getUUID());
			}
			fs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id());
			fs.setValue("created_utc_datetime", new Date());

			baseDao.add(fs);
		}
		return map;
	}

	/**
	 * 鎸夐挳绫诲瀷杞崲
	 *
	 * @param type
	 * @return
	 */
	private String buttonType(String type) {
		String button_category_uuid = "";
		if (type == null) {
			button_category_uuid = "main";
			return button_category_uuid;
		}
		switch (type) {
			case "01":
				button_category_uuid = "add";
				break;
			case "02":
				button_category_uuid = "update";
				break;
			case "03":
				button_category_uuid = "delete";
				break;
			case "04":
				button_category_uuid = "view";
				break;
			case "05":
				button_category_uuid = "print";
				break;
			case "06":
				button_category_uuid = "import";
				break;
			case "07":
				button_category_uuid = "custom";
				break;
			case "08":
				button_category_uuid = "custom";
				break;
			case "09":
				button_category_uuid = "audit";
				break;
			case "10":
				button_category_uuid = "custom";
				break;
			case "11":
				button_category_uuid = "custom";
				break;
			case "12":
				button_category_uuid = "custom";
				break;
			default:
				button_category_uuid = "custom";

		}
		return button_category_uuid;
	}

	/**
	 * @param funFs
	 * @param moduleCode 妯″潡code
	 * @throws SQLException
	 */
	public void syncFunctions(FieldSetEntity funFs, String moduleCode, String sf28) throws SQLException, ClassNotFoundException {
		System.out.println(funFs.getString("sf28"));
		if (!BaseUtil.strIsNull(funFs.getString("sf28"))) {
			sf28 = funFs.getString("sf28");
		}
		String table = sf28.split("\\.")[1].toLowerCase();
		FieldSetEntity product_sys_datamodel_table = baseDao.getFieldSetEntityByFilter("product_sys_datamodel_table", "table_name=?", new String[]{table}, false);
		//杩佺Щ鍔熻兘
		FieldSetEntity fs = new FieldSetEntity();
		fs.setTableName("product_sys_functions");
		//琛╱uid
		fs.setValue("table_uuid", product_sys_datamodel_table.getString("uuid"));
		//鍔熻兘鍚嶇О
		fs.setValue("function_name", funFs.getString("sf03"));
		//鍔熻兘鎻忚堪
		fs.setValue("function_description", funFs.getString("sf03"));
		//涓婄骇code    涓婄骇妯″潡code
		fs.setValue("tricode_parent", moduleCode);
		//鍔熻兘code
		String funCode = CodeUtil.getNewCodeByTemp(CmnConst.PRODUCT_SYS_FUNCTIONS, CmnConst.TRICODE, moduleCode);
		fs.setValue("tricode", funCode);
		//鍔熻兘鐭紪鐮�
		fs.setValue("function_shortcode", "feqy");
		fs.setValue("status_uuid", "1");
		fs.setValue("function_type_uuid", "1");
		fs.setValue("client_type_uuid", "Web");
		fs.setValue("version_uuid", "001");
		fs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id());
		fs.setValue("created_utc_datetime", new Date());
		fs.setValue("data_type", 1);
		String funUUID = baseDao.add(fs);

		String sf05 = funFs.getString("sf05");
		//鑾峰彇jdbc杩炴帴
		Connection conn = feDataDSService.getJDBC();
		//杩佺ЩMVC
		JSONObject buttonMap = this.syncButtonsPage(conn, funUUID, sf05);
		//杩佺Щ鑿滃崟
		try {
			this.synchronizationMenu(conn, funFs.getString("sf05"), funUUID);
		} catch (Exception e) {
			e.getStackTrace();
		}
		//杩佺Щ鍔熻兘鏉冮檺璁稿彲
		this.syncFunctionPermission(conn, funUUID, sf05, buttonMap);
		//鍏抽棴杩炴帴
		DataManipulationUtils.close(null, null, conn);
	}

	/**
	 * 鍚屾妯″潡鍚嶇О
	 *
	 * @param conn    杩炴帴
	 * @param funCode 鍔熻兘code
	 */
	public String synchronizationModuleName(Connection conn, String funCode, String sf28) throws SQLException {
		FieldSetEntity funFse = null;
		try {
			//閫氳繃
			funFse = BaseDaoServiceImpl.getFieldSet(conn, "fe_base5.SYS_FUNCTION", "  SF05 = ? ", new Object[]{funCode});
		} catch (Exception e) {
			DataManipulationUtils.close(null, null, conn);
			throw e;
		}
		if (funFse == null) {
			return null;
		}
		//妯″潡鍚嶇О
		String sf01 = funFse.getString("sf01");

		//鍚屾妯″潡鍚嶇О
		FieldSetEntity moduleFs = baseDao.getFieldSetEntityByFilter("product_sys_functions", " function_name = ? ", new String[]{sf01}, false);
		String moduleCode = null;
		String moduleUUID = null;
		if (moduleFs == null) {
			moduleFs = new FieldSetEntity();
			moduleFs.setTableName("product_sys_functions");
			//浜у搧uuid
			moduleFs.setValue("table_uuid", "ff44dc40-5fa6-4b99-a0c6-463fd5fb5c5b85");
			moduleFs.setValue("function_name", sf01);
			moduleFs.setValue("function_description", sf01);
			//浜у搧code
			moduleFs.setValue("tricode_parent", "001");
			moduleCode = CodeUtil.getNewCodeByTemp(CmnConst.PRODUCT_SYS_FUNCTIONS, CmnConst.TRICODE, "001");
			moduleFs.setValue("tricode", moduleCode);
			moduleFs.setValue("function_shortcode", "feqymk");
			moduleFs.setValue("status_uuid", "1");
			moduleFs.setValue("function_type_uuid", "0");
			moduleFs.setValue("function_icon", "0");
			moduleFs.setValue("client_type_uuid", "Web");
			moduleFs.setValue("version_uuid", "001");
			moduleFs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id());
			moduleFs.setValue("created_utc_datetime", new Date());
			moduleFs.setValue("data_type", 2);
			//鏂板涓€涓猣e杩佺Щ鎬绘ā鍧�
			moduleUUID = baseDao.add(moduleFs);
		} else {
			moduleCode = moduleFs.getString("tricode");
			moduleUUID = moduleFs.getUUID();
		}
		//鍚屾妯″潡涓嬬殑鍔熻兘
		try {
			this.syncFunctions(funFse, moduleCode, sf28);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		//鍚屾鑿滃崟
		return moduleUUID;
	}

	/**
	 * 鍚屾鑿滃崟 濡傛灉娌℃湁涓婄骇鐩綍 鍒涘缓涓婄骇鐩綍
	 *
	 * @param conn    jdbc杩炴帴
	 * @param funCode 鍚屾code
	 */
	public void synchronizationMenu(Connection conn, String funCode, String funUUID) throws SQLException, BaseException {
		//鏍规嵁鍔熻兘code鑾峰彇鑿滃崟
		FieldSetEntity menuFse = null;
		try {
			//鑿滃崟淇℃伅
			menuFse = BaseDaoServiceImpl.getFieldSet(conn, "FE_BASE5.DESKTOP_MENU_MANAGEMENT", "  URL = ? ", new Object[]{funCode});
		} catch (Exception e) {
			DataManipulationUtils.close(null, null, conn);
			throw e;
		}
		//鏌ヨ鏄惁鏈夎彍鍗曞拰鐩綍鍚嶇О
		FieldSetEntity fieldSetEntity = baseDao.getFieldSetEntityByFilter("product_sys_menus", " menu_name = ? ", new String[]{menuFse.getString("temp")}, false);
		//鍒涘缓鑿滃崟
		FieldSetEntity fieldSet = new FieldSetEntity();
		fieldSet.setTableName("product_sys_menus");
		//鏄惁鐩綍 0鍚︺€�1鏄�
		fieldSet.setValue("is_catalog", 0);
		//鏄惁鏄剧ず 0:涓嶆樉绀恒€� 1:鏄剧ず
		fieldSet.setValue("is_show", "1");
		//鍏宠仈鍔熻兘
		fieldSet.setValue("function_uuid", funUUID);
		//鑿滃崟鎻忚堪
		fieldSet.setValue("menu_description", menuFse.getString("name"));
		//鑿滃崟鍚嶇О
		fieldSet.setValue("menu_name", menuFse.getString("name"));
		//鎺掑垪椤哄簭 鏂规簮鑿滃崟id
		fieldSet.setValue("sequence", menuFse.getString("id"));
		//鍥炬爣
		fieldSet.setValue("menu_icon", "form");
		String menuCode;
		//娌℃湁灏卞垱寤鸿彍鍗曠洰褰�
		if (fieldSetEntity == null) {
			FieldSetEntity menuFieldSet = new FieldSetEntity();
			menuFieldSet.setTableName("product_sys_menus");
			//鏄惁鐩綍 0鍚︺€�1鏄�
			menuFieldSet.setValue("is_catalog", 1);
			//鏄惁鏄剧ず 0:涓嶆樉绀恒€� 1:鏄剧ず
			menuFieldSet.setValue("is_show", "1");
			//鍏宠仈鍔熻兘涓虹┖
			menuFieldSet.setValue("function_uuid", "");
			//鍥炬爣
			menuFieldSet.setValue("menu_icon", "clipboard");
			//鑿滃崟鎻忚堪
			menuFieldSet.setValue("menu_description", menuFse.getString("temp"));
			//鑿滃崟鍚嶇О
			menuFieldSet.setValue("menu_name", menuFse.getString("temp"));
			//鎺掑垪椤哄簭 鏂规簮鑿滃崟鐩綍id
			menuFieldSet.setValue("sequence", menuFse.getString("fatherid"));
			menuCode = CodeUtil.getNewCodeByTemp("product_sys_menus", "tricode", "");
			//缂栫爜
			menuFieldSet.setValue("tricode", menuCode);
			//鐖剁骇缂栫爜
			menuFieldSet.setValue("tricode_parent", "");
			baseDao.add(menuFieldSet);
		} else {
			menuCode = fieldSetEntity.getString("tricode");
		}
		//鐢熸垚鐨勮彍鍗曠紪鐮�
		fieldSet.setValue("tricode", CodeUtil.getNewCodeByTemp("product_sys_menus", "tricode", menuCode));
		//鐖剁骇缂栫爜
		fieldSet.setValue("tricode_parent", menuCode);
		baseDao.add(fieldSet);
	}

	/**
	 * 杩佺Щ涓氬姟鏁版嵁琛�
	 *
	 * @param sf28s 搴撳悕鍜岃〃鍚�
	 * @param conn  杩炴帴
	 * @return
	 * @throws SQLException
	 */
	public void syncTable(String[] sf28s, boolean isNew, String subField, Connection conn) throws SQLException {
		FieldSetEntity Orlfs;
		//琛ㄥ悕
		String taName = sf28s[1];
		String masterTableName = "";
		//鑾峰彇涓昏〃鐨勮〃鍚�
		if (sf28s.length == 3) {
			masterTableName = sf28s[2];
		}
		try {
			Orlfs = BaseDaoServiceImpl.getFieldSet(conn, "fe_base5.SYS_TABLE", "ST03=?", new Object[]{taName});
		} catch (Exception e) {
			DataManipulationUtils.close(null, null, conn);
			throw e;
		}
		Map<String, String> map = null;

		//鏄惁鏄柊琛�
		if (isNew) {
			//鍒ゆ柇鏄惁鏄凡缁忓悓姝ヨ繃鐨勮〃
			FieldSetEntity fieldSetEntity = baseDao.getFieldSetEntityByFilter("product_sys_datamodel_table", " table_name = ? ", new String[]{taName.toLowerCase()}, false);
			if (fieldSetEntity == null) {
				//鍚屾琛ㄧ粨鏋�  鍙婂瓧娈典俊鎭�
				map = this.syncTableField(conn, Orlfs, sf28s, subField);
				//鍒锋柊table 琛�
				DataPoolRefreshCache.getInstance().put("product_sys_datamodel_table");
				//鍒锋柊field 琛�
				DataPoolRefreshCache.getInstance().put("product_sys_datamodel_field");
				try {
					Thread.sleep(7000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			} else {
				return;
			}
		} else {
			//宸叉湁琛�
			this.syncFunTable(conn, sf28s[0] + '.' + sf28s[1]);
			return;
		}
		//杩佺Щ琛ㄩ噷闈㈡暟鎹�
		DataTableEntity dataDt = null;
		try {
			dataDt = BaseDaoServiceImpl.getDataTable(conn, sf28s[0] + "." + sf28s[1], null, new String[]{});
		} catch (Exception e) {
			DataManipulationUtils.close(null, null, conn);
			throw e;
		}
		//鏌ヨ璇ヨ〃瀛楁湁娌℃湁闄勪欢瀛楁  media attachment
		DataTableEntity accessoryData = this.getTableFieldAttachment(Orlfs.getString("st00"));
		Boolean syncAttachments = false;
		if (!BaseUtil.dataTableIsEmpty(accessoryData)) {
			syncAttachments = true;
		}

		//涓氬姟琛� fe鐨刬d  瀵瑰簲UUID
		for (int i = 0; i < dataDt.getRows(); i++) {
			FieldSetEntity dataFs = dataDt.getFieldSetEntity(i);
			FieldSetEntity tableFs = new FieldSetEntity();
			tableFs.setTableName(this.originalTable.getString(taName));
			//key 涓烘湰琛ㄥ瓧娈�   value 涓烘暟鎹簮瀛楁
			for (String key : map.keySet()) {
				//鍗曞叧鑱旂殑鐢ㄦ埛user_id
				if ("USER".equals(fieldTypeJson.getString(key))) {
					tableFs.setValue(key, userIdJson.getString(dataFs.getString(map.get(key))));
					//鍗曞叧鑱旂殑缁勭粐鏋舵瀯uuid
				} else if ("GROUP".equals(fieldTypeJson.getString(key))) {
					tableFs.setValue(key, groupJson.get(dataFs.getString(map.get(key))));
					//澶氶€夌粍缁囨灦鏋�  杞崲涓虹敤鎴穟ser_ids
				} else if ("USERSGROUPS".equals(fieldTypeJson.getString(map.get(key)))) {
					tableFs.setValue(key, this.getUserIds(dataFs.getString(map.get(key))));
				} else {
					//鏄惁鏈夊瓧娈靛叧鑱斾富琛�
					if (subField != null && subField.equals(map.get(key))) {
						//琛ㄥ悕鍔犱笅鏍� 鍞竴
						tableFs.setValue(key, pxMap.getString(masterTableName + dataFs.getString(map.get(key))));
					} else {
						tableFs.setValue(key, dataFs.getString(map.get(key)));
					}
				}
			}
			//鍚屾闄勪欢
			if (syncAttachments) {
				Map<String, List<String>> fileMaps = this.synchronizationAttachments(conn, accessoryData, dataFs, taName);
				if (fileMaps.size() > 0) {
					for (String fieldName : fileMaps.keySet()) {
						List<String> value = fileMaps.get(fieldName);
						tableFs.setValue(fieldName, StringUtils.join(value, ","));
					}
				}
			}
//            if("app_notice_urge".equals(tableFs.getTableName())){
//                try {
//                    Thread.sleep(1000);
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
//            }
			String uuid = baseDao.add(tableFs);
			//琛ㄥ敮涓€id  瀵瑰簲uuid
			pxMap.put(taName + dataFs.getString(this.pk), uuid);
		}
		//鍚屾瀹屼竴寮犺〃鏁版嵁鍚庢竻绌簀son鏁版嵁
		fieldTypeJson.clear();
		DataTableEntity subTble = null;
		try {
			//鏌ヨ鏄惁鏈夊瓙琛�
			subTble = BaseDaoServiceImpl.getDataTable(conn, "SELECT  a.SF01, a.SF10,b.ST02 ST02,b.ST03 ST03 FROM FE_BASE5.SYS_FIELD a INNER JOIN FE_BASE5.SYS_TABLE b on a.SF00=b.ST00 WHERE a.SF10 LIKE ? ", new String[]{"%" + sf28s[1] + "%"});
		} catch (Exception e) {
			DataManipulationUtils.close(null, null, conn);
			throw e;
		}
		for (int i = 0; i < subTble.getRows(); i++) {
			FieldSetEntity sf = subTble.getFieldSetEntity(i);
			String a[] = {sf.getString("st02"), sf.getString("st03"), taName};
			if (isStr(sf.getString("st02") + "\\." + sf.getString("st03"))) {
				isNew = false;
			}
			this.syncTable(a, isNew, sf.getString("sf01").toLowerCase(), conn);
		}
	}

	/**
	 * 鍒ゆ柇鏄惁鏄紩鐢ㄦ暟鎹� 鏄氨瑕佽浆鎹紙濡備汉鍛榠d锛屾満鏋刬d锛�
	 *
	 * @param tableName 琛ㄥ悕鐐�.瀛楁鍚�
	 * @return
	 */
	public void transformReferenceData(Connection conn, String tableName, String fieldName, FieldSetEntity fieldSetEntity) throws SQLException {
		DataTableEntity dataTable;
		try {
			StringBuffer sql = new StringBuffer();
			sql.append(" SELECT * FROM fe_base5.SYS_FACEITEM A FULL JOIN fe_base5.SYS_FACE B ")
					.append(" ON A.SI01 = B.SF00 LEFT JOIN FE_BASE5.SYS_FACECTRLPROP C ON A.SI00 = C.SP00 ")
					.append(" WHERE SI04 = ? AND B.SF01 = ( SELECT st00 FROM fe_base5.sys_table WHERE st03 = ?) AND C.SP01 = 'prompt' AND SP02 = '[100001]' ");
			dataTable = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new String[]{fieldName, tableName});
		} catch (Exception e) {
			DataManipulationUtils.close(null, null, conn);
			throw e;
		}
		//鏄惁鏄叧鑱斿崟涓汉鍛樻帶浠�
		if (BaseUtil.dataTableIsEmpty(dataTable)) {
			try {
				//鏄惁鏄叧鑱斿崟涓崟浣嶉儴闂ㄦ帶浠�
				StringBuffer sql = new StringBuffer();
				sql.append(" SELECT * FROM fe_base5.SYS_FACEITEM A FULL JOIN fe_base5.SYS_FACE B ")
						.append(" ON A.SI01 = B.SF00 LEFT JOIN FE_BASE5.SYS_FACECTRLPROP C ON A.SI00 = C.SP00 ")
						.append(" WHERE SI04 = ? AND B.SF01 = ( SELECT st00 FROM fe_base5.sys_table WHERE st03 = ?) AND C.SP01 = 'orgtype' AND SP02 = 'A11' ");

				dataTable = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new String[]{tableName, fieldName});
			} catch (Exception e) {
				DataManipulationUtils.close(null, null, conn);
				throw e;
			}
			if (BaseUtil.dataTableIsEmpty(dataTable)) {
				try {
					//鏄惁鏄叧鑱旈儴闂ㄥ矖浣嶄汉鍛樺閫夋帶浠�
					StringBuffer sql = new StringBuffer();
					sql.append(" SELECT * FROM fe_base5.SYS_FACEITEM A FULL JOIN fe_base5.SYS_FACE B ")
							.append(" ON A.SI01 = B.SF00 LEFT JOIN FE_BASE5.SYS_FACECTRLPROP C ON A.SI00 = C.SP00 ")
							.append(" WHERE SI04 = ? AND B.SF01 = ( SELECT st00 FROM fe_base5.sys_table WHERE st03 = ?) AND C.SP01 = 'prompt' AND SP02 = '[111110]' ");

					dataTable = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new String[]{tableName, fieldName});
				} catch (Exception e) {
					DataManipulationUtils.close(null, null, conn);
					throw e;
				}
				//濡傛灉鏄閫夋帶浠�
				if (!BaseUtil.dataTableIsEmpty(dataTable)) {
					fieldTypeJson.put(fieldName.toLowerCase(), "USERSGROUPS");
				}
			} else {
				fieldTypeJson.put(fieldName.toLowerCase(), "GROUP");
			}
		} else {
			fieldTypeJson.put(fieldName.toLowerCase(), "USER");
			fieldSetEntity.setValue("field_reference", "user_name_by_user_id");
		}
	}

	/**
	 * 鍚屾闄勪欢
	 *
	 * @param accessoryData 闄勪欢瀛楁data
	 * @param tableFs       鏁版嵁鍊�
	 */
	public Map<String, List<String>> synchronizationAttachments(Connection conn, DataTableEntity accessoryData, FieldSetEntity tableFs, String table) {
		Map<String, List<String>> filesMap = Maps.newHashMap();
		for (int i = 0; i < accessoryData.getRows(); i++) {
			//绫诲瀷
			String type = accessoryData.getString(i, "si02");
			//瀛楁
			String field = accessoryData.getString(i, "si04").toLowerCase();
			//鑾峰彇闄勪欢鍊�
			String attachmentsValue = tableFs.getString(field);
			if (!BaseUtil.strIsNull(attachmentsValue)) {
				List<String> fileUuids = Lists.newArrayList();
				//鏅€氶檮浠�
				if ("attachment".equals(type)) {
					//鍙栧嚭闄勪欢琛ㄦ暟鎹�
					fileUuids = this.synchronizeCommonAccessories(conn, field, table, attachmentsValue);
					//閲戞牸闄勪欢
				} else if ("media".equals(type)) {
					//闄勪欢鍊�
					//閫氳繃閲戞牸鏍囪瘑鎷艰鍏ㄨ矾寰則his.jinGePath
					String path1 = attachmentsValue.substring(0, 4);
					String path2 = attachmentsValue.substring(4, 6);
					String path3 = attachmentsValue.substring(6, 8);
					String path4 = attachmentsValue.substring(0, 14);
					StringBuffer fullPath = new StringBuffer();
					fullPath.append(this.jinGePath).append("\\")
							.append(path1).append("\\")
							.append(path2).append("\\")
							.append(path3).append("\\")
							.append(path4);
					Map<String, String> fileTimeName = feDataDSService.getFilesFolder(fullPath.toString());
					if (fileTimeName == null) {
						//鏈壘鍒伴檮浠剁洿鎺ヨ烦杩�
						continue;
					}
					DataTableEntity mediaSortInfo = this.getMediaSortInfo(attachmentsValue);
					//寰幆閲戞牸鎺т欢琛ㄦ暟鎹�   涓庢枃浠舵暟鎹厤缃�
					if (!BaseUtil.dataTableIsEmpty(mediaSortInfo)) {
						fileUuids = Lists.newArrayList();
						for (int j = 0; j < mediaSortInfo.getRows(); j++) {
							//鏈€鏂颁慨鏀规椂闂�
							String time = mediaSortInfo.getString(j, "wms04");
							//鍒涘缓鏃堕棿
							String name = mediaSortInfo.getString(j, "wms01");
							//鑾峰彇瑕佺Щ鍔ㄧ殑鏂囦欢鍚嶇О
							String fileName = fileTimeName.get(time);
							if (BaseUtil.strIsNull(fileName)) {
								continue;
							}
							String filePath = fullPath.toString() + "\\" + fileName;
							String newPath = this.TSPath + "\\" + name;
							//澶嶅埗鍒颁复鏃剁洰褰曚笅
							if (feDataDSService.copyFile(filePath, newPath)) {
								//閫氳繃璺緞鑾峰彇File
								File file = new File(newPath);
								RequestParameterEntity rpe = new RequestParameterEntity();
								Map<String, File> fileMap = Maps.newHashMap();
								//鏂囦欢鍚�  鏂囦欢file
								fileMap.put(name, file);
								FieldSetEntity fieldSetEntity = new FieldSetEntity();
								fieldSetEntity.setTableName(tableFs.getTableName());
								fieldSetEntity.setValue(field, name);
								rpe.setFiles(fileMap);
								rpe.setFormData(fieldSetEntity);
								FieldSetEntity fileFse = fileManagerService.uploadFile(rpe);
								fileUuids.add(fileFse.getUUID());
							}
						}
					}
				}
				if (fileUuids != null && fileUuids.size() > 0) {
					filesMap.put(field, fileUuids);
				}

			}
		}
		return filesMap;
	}

	/**
	 * 鍚屾鏅€氶檮浠舵柟娉�
	 *
	 * @param conn             杩炴帴
	 * @param field            鏈瓧娈靛悕
	 * @param table            鏈〃鍚�
	 * @param attachmentsValue 婧愬叧鑱斿€�
	 * @return
	 */
	public List<String> synchronizeCommonAccessories(Connection conn, String field, String table, String attachmentsValue) {
		//鍙栧嚭闄勪欢琛ㄦ暟鎹�
		DataTableEntity attachmentsData = this.getOrdinaryAttachments(conn, attachmentsValue);
		if (!BaseUtil.dataTableIsEmpty(attachmentsData)) {
			List<String> fileUuids = Lists.newArrayList();
			for (int j = 0; j < attachmentsData.getRows(); j++) {
				//淇濆瓨鍚嶇О
				String sa02 = attachmentsData.getString(j, "sa02");
				//鏄剧ず鍚嶇О
				String sa03 = attachmentsData.getString(j, "sa03");
				//淇濆瓨璺緞
				String sa04 = attachmentsData.getString(j, "sa04");
				String filePath = sa04 + "\\" + sa02;
				String newPath = this.TSPath + "\\" + sa03;
				//澶嶅埗鍒颁复鏃剁洰褰曚笅
				if (feDataDSService.copyFile(filePath, newPath)) {
					RequestParameterEntity rpe = new RequestParameterEntity();
					Map<String, File> fileMap = Maps.newHashMap();
					//閫氳繃璺緞鑾峰彇File
					File file = new File(newPath);
					//鏂囦欢鍚�  鏂囦欢file
					fileMap.put(sa03, file);
					FieldSetEntity fieldSetEntity = new FieldSetEntity();
					fieldSetEntity.setTableName(table);
					fieldSetEntity.setValue(field, sa03);
					rpe.setFiles(fileMap);
					rpe.setFormData(fieldSetEntity);
					FieldSetEntity fileFse = fileManagerService.uploadFile(rpe);
					fileUuids.add(fileFse.getUUID());
				}
			}
			return fileUuids;
		} else {
			return null;
		}
	}

	/**
	 * 鑾峰彇鏅€氶檮浠朵俊鎭�
	 *
	 * @param value 闄勪欢鏍囪瘑
	 * @return
	 */
	public DataTableEntity getOrdinaryAttachments(Connection conn, String value) {
		DataTableEntity dataTableEntity = null;
		StringBuffer sql = new StringBuffer();
		sql.append(" SELECT * FROM FE_BASE5.SYS_ATTACHMENT WHERE SA01 = ? ");
		System.out.println(value);
		dataTableEntity = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new Object[]{value});
		return dataTableEntity;
	}

	/**
	 * 鑾峰彇閲戞牸闄勪欢淇℃伅
	 *
	 * @param value 闄勪欢鏍囪瘑
	 * @return
	 */
	public DataTableEntity getMediaSortInfo(String value) {
		DataTableEntity dataTableEntity = null;
		Connection conn = null;
		try {
			conn = feDataDSService.getJDBC();
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		StringBuffer sql = new StringBuffer();
		sql.append(" SELECT * FROM FE_APP5.WF_MEDIA_SORT WHERE WMS02 = ? ");
		dataTableEntity = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new Object[]{value});
		try {
			DataManipulationUtils.close(null, null, conn);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return dataTableEntity;
	}

	/**
	 * 閫氳繃琛ㄥ悕鑾峰彇鍚屾鐨勯檮浠跺瓧娈�
	 *
	 * @param tableName 琛ㄥ悕
	 * @return
	 */
	public DataTableEntity getTableNameAttachment(Connection conn, String tableName) {
		DataTableEntity dataTableEntity = null;
		String[] names = tableName.split("\\.");
		StringBuffer sql = new StringBuffer();
		sql.append(" SELECT A.SI02,A.SI04 FROM fe_base5.SYS_FACEITEM A FULL JOIN fe_base5.SYS_FACE B ")
				.append(" ON A.SI01 = B.SF00 WHERE B.SF01 = ( SELECT st00 FROM fe_base5.sys_table WHERE st03 = ?) ")
				.append("AND (A.SI02 = 'media' OR A.SI02 = 'attachment') GROUP BY A.SI04,A.SI02 ");

		dataTableEntity = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new Object[]{names[1]});
		return dataTableEntity;
	}

	/**
	 * 閫氳繃琛╥d鑾峰彇鍚屾鐨勯檮浠跺瓧娈�
	 *
	 * @param tableId 琛╥d
	 * @return
	 */
	public DataTableEntity getTableFieldAttachment(String tableId) {
		DataTableEntity dataTableEntity = null;
		Connection conn = null;
		try {
			conn = feDataDSService.getJDBC();
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		StringBuffer sql = new StringBuffer();
		sql.append(" SELECT A.SI02,A.SI04 FROM fe_base5.SYS_FACEITEM A FULL JOIN fe_base5.SYS_FACE B ")
				.append(" ON A.SI01 = B.SF00 WHERE B.SF01 = ? AND (A.SI02 = 'media' OR A.SI02 = 'attachment') GROUP BY A.SI04,A.SI02 ");
		dataTableEntity = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new Object[]{tableId});
		try {
			DataManipulationUtils.close(null, null, conn);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return dataTableEntity;
	}

	/**
	 * 杩佺Щ"product_sys_datamodel_field 鍜�"product_sys_datamodel_table琛�
	 *
	 * @throws SQLException
	 */
	public Map<String, String> syncTableField(Connection conn, FieldSetEntity Orlfs, String[] tableName, String subField) throws SQLException {
		Map<String, String> map = Maps.newHashMap();
		FieldSetEntity tableFs = new FieldSetEntity();
		tableFs.setTableName("product_sys_datamodel_table");
		String table_name = Orlfs.getString("st03");
		this.originalTable.put(table_name, table_name.toLowerCase());
		tableFs.setValue("table_name", table_name.toLowerCase());
		tableFs.setValue("table_description", Orlfs.getString("st04"));
		tableFs.setValue("table_primary_key", "uuid");
		tableFs.setValue("table_type", "1");
		tableFs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id());
		tableFs.setValue("created_utc_datetime", new Date());
		tableFs.setValue("sequence", 1);
		baseDao.saveFieldSetEntity(tableFs);
		DataTableEntity Orldt = null;
		try {
			Orldt = BaseDaoServiceImpl.getDataTable(conn, "select a.*,b.DATA_TYPE from SYS_FIELD a LEFT JOIN (select * from all_tab_columns where TABLE_NAME=? and OWNER =?) b on a.SF01=b.COLUMN_NAME where SF00=(select ST00 from SYS_TABLE where ST03=?)", new String[]{tableName[1], tableName[0], tableName[1]});
		} catch (Exception e) {
			DataManipulationUtils.close(null, null, conn);
			throw e;
		}
		DataTableEntity dt = new DataTableEntity();
		String table_uuid = tableFs.getString("uuid");
		boolean is_pk = false;
		for (int i = 0; i < Orldt.getRows(); i++) {
			FieldSetEntity rowFs = Orldt.getFieldSetEntity(i);
			FieldSetEntity fieldFs = new FieldSetEntity();
			fieldFs.setTableName("product_sys_datamodel_field");
			fieldFs.setValue("table_uuid", table_uuid);
			//鍒ゆ柇瀛楁鏄惁寮曠敤浜嗙敤鎴峰瓧娈�  鎴� 鍗曚綅閮ㄩ棬瀛楁
			String sf01 = rowFs.getString("sf01");
			// 鍒ゆ柇鏄惁鏄紩鐢ㄦ暟鎹� 鏄氨瑕佽浆鎹紙濡備汉鍛榠d锛屾満鏋刬d锛�
			transformReferenceData(conn, table_name, sf01, fieldFs);
			map.put(sf01.toLowerCase(), sf01.toLowerCase());
			fieldFs.setValue("field_name", sf01.toLowerCase());
			fieldFs.setValue("field_description", rowFs.getString("sf02"));
			fieldFs.setValue("field_show_name", rowFs.getString("sf02"));
			String type = this.fieldTypeFE(rowFs.getString("sf03"));
			//鏄惁鏈夊瓧娈靛叧鑱斾富琛�
			if ("pk".equals(type)) {
				//濡傛灉宸茬粡鏈塸k
				if (is_pk) {
					type = "string";
				} else {
					this.pk = sf01.toLowerCase();
					is_pk = true;
				}
			}
			fieldFs.setValue("field_type", type);
			if ("GUID".equals(rowFs.getString("sf03"))) {
				fieldFs.setValue("is_unique", 1);
			} else {
				fieldFs.setValue("is_unique", 0);
			}
			if ("NATIVE".equals(rowFs.getString("sf03"))) {
				fieldFs.setValue("NATIVE", 1);
			}
			if ("UNITCODE".equals(rowFs.getString("sf03"))) {
				fieldFs.setValue("UNITCODE", 1);
			}
			//濡傛灉鏄叧鑱斾富琛ㄥ瓧娈� 闀垮害鏀逛负64
			if (subField != null && subField.equals(sf01.toLowerCase())) {
				fieldFs.setValue("field_type", "string");
				fieldFs.setValue("field_length", 64);
			} else {
				fieldFs.setValue("field_length", rowFs.getString("sf04"));
			}
			fieldFs.setValue("field_unit", rowFs.getString("sf05"));
			fieldFs.setValue("is_required", 0);
			fieldFs.setValue("is_filter", 1);
			if (null != rowFs.getString("sf10") && "".equals(rowFs.getString("sf10"))) {
				fieldFs.setValue("field_type", "parentuuid");
				fieldFs.setValue("field_relation_table", rowFs.getString("sf10").split("\\.")[1]);
			}
			baseDao.saveFieldSetEntity(fieldFs);
			dt.addFieldSetEntity(fieldFs);
		}
		//濡傛灉娌℃湁鑷涓婚敭  鍒涘缓涓€涓�
		if (!is_pk) {
			//娣诲姞鑷涓婚敭
			FieldSetEntity fieldFs = new FieldSetEntity();
			fieldFs.setTableName("product_sys_datamodel_field");
			fieldFs.setValue("table_uuid", table_uuid);
			fieldFs.setValue("field_name", tableFs.getString("table_name") + "_id");
			fieldFs.setValue("field_description", "鑷涓婚敭");
			fieldFs.setValue("field_type", "pk");
			fieldFs.setValue("field_length", 11);
			fieldFs.setValue("is_required", 0);
			fieldFs.setValue("is_unique", 1);
			fieldFs.setValue("is_international", 0);
			fieldFs.setValue("created_by", 1);
			fieldFs.setValue("created_utc_datetime", new Date());
			fieldFs.setValue("field_show_name", "鑷涓婚敭");
			baseDao.saveFieldSetEntity(fieldFs);
			dt.addFieldSetEntity(fieldFs);
		}
		//娣诲姞uuid鍞竴鏍囪瘑
		FieldSetEntity fieldFs = new FieldSetEntity();
		fieldFs.setTableName("product_sys_datamodel_field");
		fieldFs.setValue("table_uuid", table_uuid);
		fieldFs.setValue("field_name", "uuid");
		fieldFs.setValue("field_description", "鍞竴鏍囪瘑");
		fieldFs.setValue("field_type", "string");
		fieldFs.setValue("field_length", 80);
		fieldFs.setValue("field_unit", 0);
		fieldFs.setValue("is_required", 0);
		fieldFs.setValue("is_unique", 0);
		fieldFs.setValue("is_international", 0);
		fieldFs.setValue("created_by", 1);
		fieldFs.setValue("created_utc_datetime", new Date());
		fieldFs.setValue("field_show_name", "鍞竴鏍囪瘑");

		baseDao.saveFieldSetEntity(fieldFs);
		dt.addFieldSetEntity(fieldFs);
		//鍒涘缓琛ㄦ柟娉�
		StringBuilder createStatement = createTable(createFields(dt), Orlfs.getString("st03"), Orlfs.getString("st04"));
		//鍒涘缓琛ㄦ柟娉�
		execute(createStatement.toString());
		return map;
	}

	/**
	 * //杩佺Щ wf_model娴佺▼妯″潡琛�
	 *
	 * @param conn
	 * @throws SQLException
	 */
	public void syncModel(String tricode_funs, Connection conn, String module_uuid, String sf28, String org_level_uuid, int created_by, boolean flag) throws SQLException {
		FieldSetEntity Orlfs = null;
		try {
			//閫氳繃
			Orlfs = BaseDaoServiceImpl.getFieldSet(conn, "fe_base5.wf_model", "wm05=(SELECT se16  FROM fe_base5.SYS_EVENT where se01=? and se08 = 1)", new Object[]{tricode_funs
			});
		} catch (Exception e) {
			DataManipulationUtils.close(null, null, conn);
			throw e;
		}
		if (Orlfs == null) {
			return;
		}
		FieldSetEntity modelFs = new FieldSetEntity();
		//flow娴佺▼琛�
		modelFs.setTableName("product_sys_flow_model");
		//鍚嶇О
		modelFs.setValue("title", Orlfs.getString("wm01"));
		//鎻忚堪
		modelFs.setValue("flow_model_describe", Orlfs.getString("wm02"));
		//鍏宠仈妯″潡琛�
		modelFs.setValue("module_uuid", module_uuid);
		//娴佺▼鍏宠仈涓昏〃鍚嶇О
		String wm04 = Orlfs.getString("wm04");
		//娴佺▼琛ㄦ病鏈夊氨浠庡姛鑳借〃閲岄潰鏌ヨ
		if (BaseUtil.strIsNull(wm04) || wm04.indexOf(".") == -1) {
			try {
				//閫氳繃
				FieldSetEntity funFse = BaseDaoServiceImpl.getFieldSet(conn, "fe_base5.SYS_FUNCTION", "  SF05 = ? ", new Object[]{tricode_funs});
				wm04 = funFse.getString("sf28");
				if (BaseUtil.strIsNull(wm04) || wm04.indexOf(".") == -1) {
					return;
				}
			} catch (Exception e) {
				DataManipulationUtils.close(null, null, conn);
				throw e;
			}
			//濡傛灉鍔熻兘琛ㄥ拰娴佺▼琛ㄧ粦瀹氱殑鏁版嵁琛ㄤ笉鐩稿悓  浠ユ祦绋嬭〃涓轰富
		} else if (!wm04.equals(sf28)) {
			String[] wm04s = wm04.split("\\.");
			this.syncTable(wm04s, false, null, conn);
		}

		String[] wm04s = wm04.split("\\.");
		String table_name = wm04s[1].toLowerCase();
		//涓昏〃琛ㄥ悕
		modelFs.setValue("table_uuid", table_name);
		//鐢熸垚uuid
		String typeCode = UUID.randomUUID().toString();
		modelFs.setValue("type_code", typeCode);

		modelFs.setValue("org_level_uuid", org_level_uuid);
		modelFs.setValue("created_by", created_by);
		modelFs.setValue("created_utc_datetime", new Date());
		String modelUuid = baseDao.add(modelFs);
		//wm05 涓烘祦绋嬬紪鐮�    鏌ヨ瀛樻湁缂栫爜鐨刴vc椤甸潰   鏀逛负娴佺▼uuid
		String wm05 = Orlfs.getString("wm05");
		FieldSetEntity mvcPageFse = baseDao.getFieldSetEntityByFilter("product_sys_mvc_page", " flow_uuid = ?", new String[]{wm05}, false);
		if (mvcPageFse != null) {
			//mvc椤甸潰缁戝畾娴佺▼uuid
			mvcPageFse.setValue("flow_uuid", typeCode);
			baseDao.update(mvcPageFse);
		}

		//杩佺ЩWF_NODES 娴佺▼鑺傜偣琛�
		JSONObject nodesUUID = this.syncNodes(tricode_funs, conn, modelUuid);
		//杩佺ЩWF_NODES 娴佺▼鑺傜偣琛� 鍒�"product_sys_flow_processor 澶勭悊鍣ㄨ縼绉�
		this.syncProcessor(tricode_funs, conn, modelUuid);
		//杩佺ЩWF_LINKS
		this.syncLinks(tricode_funs, conn, modelUuid);
		if (flag) {
			//杩佺Щ WF_TASK
			JSONObject taskIdUUID = this.syncTask(tricode_funs, conn, modelUuid);
			//杩佺Щwf_infor 鑺傜偣浠诲姟澶勭悊鎯呭喌琛�
			Map<String, String> stateMap = this.syncDetail(tricode_funs, conn, nodesUUID, sf28, modelUuid, taskIdUUID);
			//鍚屾娑堟伅
			try {
				this.synchronizingProcessMessages(conn, tricode_funs, stateMap);
			} catch (Exception e) {
				e.printStackTrace();
			}
			//婧愭暟鎹甶d 涓� 鏈暟鎹畊uid 鍏宠仈
			pxMap.clear();
		}
	}

	/**
	 * 杩佺Щ flow澶勭悊鍣�
	 *
	 * @throws SQLException
	 */
	public void syncProcessor(String tricode_funs, Connection conn, String modelUUID) throws SQLException {
		DataTableEntity OrlDt = null;
		try {
			OrlDt = BaseDaoServiceImpl.getDataTable(conn, "fe_base5.wf_nodes", " WN01=(select wm00 from fe_base5.wf_model where wm05=(SELECT se16  FROM fe_base5.SYS_EVENT where se01=? and se08 = 1)) and WN04 ='5'", new Object[]{tricode_funs
			});
		} catch (Exception e) {
			DataManipulationUtils.close(null, null, conn);
			throw e;
		}
		for (int i = 0; i < OrlDt.getRows(); i++) {
			FieldSetEntity Orlfs = OrlDt.getFieldSetEntity(i);
			FieldSetEntity processorFs = new FieldSetEntity();
			// flow澶勭悊鍣�
			processorFs.setTableName("product_sys_flow_processor");
			processorFs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id());
			processorFs.setValue("created_utc_datetime", new Date());
			//鏍囬
			processorFs.setValue("title", Orlfs.getString("wn02"));
			//绫诲瀷锛�1-java锛�2-sql     WN47   1 sql   2 java
			processorFs.setValue("processor_type", Orlfs.getInteger("wn47") == 1 ? 2 : 1);
			//璇︾粏鍐呭
			processorFs.setValue("content", Orlfs.getString("wn48"));
			//鍏宠仈"product_sys_flow_model
			processorFs.setValue("flow_uuid", modelUUID);
			//鍧愭爣锛岃妭鐐瑰埌涓婅竟鐣岀殑鍨傜洿璺濈
			processorFs.setValue("location_top", Orlfs.getInteger("wn38") + "px");
			//鍧愭爣锛岃妭鐐瑰埌宸﹁竟鐣岀殑鍨傜洿璺濈
			processorFs.setValue("location_left", Orlfs.getInteger("wn37") + "px");
			String uuid = baseDao.add(processorFs);
			//椤哄簭鍙�
			nodesIdUUID.put(Orlfs.getString("wn00"), uuid);
		}
	}

	public JSONObject syncNodes(String tricode_funs, Connection conn, String modelUUID) throws SQLException {
		DataTableEntity OrlDt = null;
		try {
			OrlDt = BaseDaoServiceImpl.getDataTable(conn, "fe_base5.wf_nodes", " WN01=(select wm00 from fe_base5.wf_model where wm05=(SELECT se16  FROM fe_base5.SYS_EVENT where se01=? and se08 = 1)) and WN04 !='5'", new Object[]{tricode_funs
			});
		} catch (Exception e) {
			DataManipulationUtils.close(null, null, conn);
			throw e;
		}
		JSONObject map = new JSONObject();
		nodesIdUUID = new JSONObject();

		for (int i = 0; i < OrlDt.getRows(); i++) {
			FieldSetEntity Orlfs = OrlDt.getFieldSetEntity(i);
			FieldSetEntity nodeFs = new FieldSetEntity();


//            WN62 鍏宠仈琛ㄥ崟瀛楁  WN63 1 浜哄憳  2宀椾綅
			//flow鑺傜偣琛�
			nodeFs.setTableName("product_sys_flow_node");
			//鍒涘缓浜�
			nodeFs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id());
			//鍒涘缓鏃堕棿
			nodeFs.setValue("created_utc_datetime", new Date());
			//鏍囬
			nodeFs.setValue("title", Orlfs.getString("wn02"));
			//鎻忚堪
			nodeFs.setValue("flow_node_describe", Orlfs.getString("wn03"));
			//缁勪欢绫诲瀷锛�1-寮€濮嬭妭鐐癸紝2-澶勭悊鑺傜偣锛�0-缁撴潫鑺傜偣
			//1寮€濮� 99缁撴潫; 3鏅€� 4瀛愪换鍔�  5澶勭悊鍣� 6鎴栧鐞�7涓庡鐞�8 浼氱
			String module_type = "2";
			if ("1".equals(Orlfs.getString("wn04"))) {
				module_type = "1";
			} else if ("99".equals(Orlfs.getString("wn04"))) {
				module_type = "0";
			}
			nodeFs.setValue("module_type", module_type);
			//鏄惁澶氫汉澶勭悊
			String wn26 = Orlfs.getString("wn26");
			nodeFs.setValue("is_multiperson", wn26);
			if ("1".equals(wn26)) {
				//澶勭悊绫诲瀷
				String wn25 = Orlfs.getString("wn25");
				// 绫诲瀷锛�0-绛夊緟澶勭悊锛�1-绔炰簤澶勭悊锛�2-椤哄簭澶勭悊 鍏圓 鍚巄  銆傘€傘€備笅涓€涓妭鐐�
				//  WN25 0 鏃�  1澶氫汉鍔炵悊绛夊緟   2 绔炰簤澶勭悊
				if (!BaseUtil.strIsNull(wn25)) {
					if ("2".equals(wn25)) {
						nodeFs.setValue("deal_type", 1);
					} else {
						nodeFs.setValue("deal_type", 0);
					}
				}
			} else if ("0".equals(wn26)) {
				nodeFs.setValue("deal_type", 0);
			}

			//榛樿閫佺洿灞為瀵�
			nodeFs.setValue("is_default_direct_supervisor", Orlfs.getString("wn34"));
			//鏄惁鍏佽鍔犵
			nodeFs.setValue("is_allow_add", Orlfs.getString("wn15"));
			//鏄惁鍏佽閫€鍥�
			nodeFs.setValue("is_allow_back", Orlfs.getString("wn13"));

			//wn48 缁撴潫鑺傜偣璋冪敤鐨勬柟娉�
			String wn48 = Orlfs.getString("wn48");
			if (!BaseUtil.strIsNull(wn48)) {
				//鍏朵粬娑堟伅鎺ㄩ€佹柟娉曪紝璋冪敤java浠g爜   鏆傚瓨浜庢
				nodeFs.setValue("msg_push_sp_func", wn48);
			}
			//鑺傜偣鏉冮檺鍏宠仈琛ㄥ崟瀛楁鍚屾
			//WN62 鍏宠仈琛ㄥ崟瀛楁
			String wn62 = Orlfs.getString("wn62");
			if (!BaseUtil.strIsNull(wn62)) {
				//WN63 1 浜哄憳  2宀椾綅
				String wn63 = Orlfs.getString("wn63");
				if (BaseUtil.strIsNull(wn63)) {
					if ("1".equals(wn63)) {
						//浜哄憳
						nodeFs.setValue("default_form_field_user", wn62.toLowerCase());
					} else {
						//宀椾綅
						nodeFs.setValue("default_form_field_post", wn62.toLowerCase());
					}
				}
			}
			//鑾峰彇浜哄憳宀椾綅鍗曚綅閮ㄩ棬   瀛樺叆娴佺▼鑺傜偣鐨勪汉鍛� 宀椾綅 鍗曚綅閮ㄩ棬鏉冮檺璁剧疆
			Map<String, String> map1 = this.syncNodeInstitutions(Orlfs);
			if (map1 != null && map1.size() > 0) {
				String userList = map1.get("userList");
				//浜哄憳id
				if (!BaseUtil.strIsNull(userList)) {
					nodeFs.setValue("default_users", userList);
				}
				String postList = map1.get("postList");
				//宀椾綅uuid
				if (!BaseUtil.strIsNull(postList)) {
					nodeFs.setValue("default_posts", postList);
				}
				String deptList = map1.get("deptList");
				//鍗曚綅閮ㄩ棬uuid
				if (!BaseUtil.strIsNull(deptList)) {
					nodeFs.setValue("default_depts", deptList);
				}
			}
			//闇€瑕佸湪鏁版嵁婧愯〃閲岄潰鎻掑叆涓€涓儴闂�  鎵€鏈夌洿鎺ュ叧鑱斿崟浣嶉兘鏀逛负杩欎釜閮ㄩ棬
			//鍧愭爣锛岃妭鐐瑰埌涓婅竟鐣岀殑鍨傜洿璺濈
			nodeFs.setValue("location_top", Orlfs.getInteger("wn38") + "px");
			//鍧愭爣锛岃妭鐐瑰埌宸﹁竟鐣岀殑姘村钩璺濈
			nodeFs.setValue("location_left", Orlfs.getInteger("wn37") + "px");
			//鍏宠仈"product_sys_flow_model
			nodeFs.setValue("flow_uuid", modelUUID);
			//鍏宠仈闄勪欢
			nodeFs.setValue("node_attachment_upload", 1);
			//涓嬭浇闄勪欢
			nodeFs.setValue("node_attachment_download", 0);
			//棰勮闄勪欢
			nodeFs.setValue("node_attachment_preview", 1);
			String uuid = baseDao.add(nodeFs);
			//鑺傜偣鍞竴鍙�
			map.put(Orlfs.getString("wn53"), uuid);
			//椤哄簭鍙�
			nodesIdUUID.put(Orlfs.getString("wn00"), uuid);
		}
		return map;
	}

	/**
	 * 鍚屾鑺傜偣閰嶇疆鐨勭粍缁囨灦鏋�
	 *
	 * @param fieldSetEntity
	 */
	public Map<String, String> syncNodeInstitutions(FieldSetEntity fieldSetEntity) {
		String wn00 = fieldSetEntity.getString("wn00");
		DataTableEntity OrlDt = null;
		try {
			Connection conn = feDataDSService.getJDBC();
			OrlDt = BaseDaoServiceImpl.getDataTable(conn, "fe_base5.WF_ROLES", " WR01 = ? ", new Object[]{wn00});
			DataManipulationUtils.close(null, null, conn);
		} catch (Exception e) {
			e.getStackTrace();
		}
		if (BaseUtil.dataTableIsEmpty(OrlDt)) {
			return null;
		}
		//鐢ㄦ埛
		List<String> userList = Lists.newArrayList();
		//閮ㄩ棬
		List<String> deptList = Lists.newArrayList();
		//宀椾綅
		List<String> postList = Lists.newArrayList();
		for (int i = 0; i < OrlDt.getRows(); i++) {
			FieldSetEntity fse = OrlDt.getFieldSetEntity(i);
			String wr04 = fse.getString("wr04");
			String wr03 = fse.getString("wr03");
			//鐢ㄦ埛
			if ("X".equals(wr04)) {
				userList.add(wr03);
				//瑙掕壊 宀椾綅
			} else if ("Y".equals(wr04)) {
				postList.add(wr03);
				//鏈烘瀯
			} else if ("Z".equals(wr04)) {
				deptList.add(wr03);
			}
		}
		Map<String, String> map = Maps.newHashMap();
		//鏌ヨ浜哄憳
		if (userList.size() > 0) {
			DataTableEntity staffData = baseDao.listTable("product_sys_staffs", BaseUtil.buildQuestionMarkFilter("remark", userList.toArray(), true));
			if (!BaseUtil.dataTableIsEmpty(staffData)) {
				userList.clear();
				for (int i = 0; i < staffData.getRows(); i++) {
					userList.add(staffData.getString(i, "user_id"));
				}
				map.put("userList", StringUtils.join(userList, ","));
			}
		}
		//鏌ヨ宀椾綅
		if (postList.size() > 0) {
			DataTableEntity postData = baseDao.listTable("product_sys_job_posts", BaseUtil.buildQuestionMarkFilter("sequence", postList.toArray(), true));
			if (!BaseUtil.dataTableIsEmpty(postData)) {
				postList.clear();
				for (int i = 0; i < postData.getRows(); i++) {
					postList.add(postData.getString(i, "uuid"));
				}
				map.put("postList", StringUtils.join(postList, ","));
			}
		}
		//鏌ヨ鏈烘瀯(鍗曚綅閮ㄩ棬)
		if (deptList.size() > 0) {
			DataTableEntity orgData = baseDao.listTable("product_sys_org_levels", BaseUtil.buildQuestionMarkFilter("sequence", deptList.toArray(), true));
			if (!BaseUtil.dataTableIsEmpty(orgData)) {
				deptList.clear();
				for (int i = 0; i < orgData.getRows(); i++) {
					deptList.add(orgData.getString(i, "uuid"));
				}
				map.put("deptList", StringUtils.join(deptList, ","));
			}
		}
		return map;
	}

	/**
	 * @param conn
	 * @param UUIDMap   娴佺▼鑺傜偣node琛╢e uuid 瀵瑰簲 浜у搧uuid
	 * @param tableName 琛ㄥ悕
	 * @return
	 * @throws SQLException
	 */
	public Map<String, String> syncDetail(String tricode_funs, Connection conn, JSONObject UUIDMap, String tableName, String modelUUID, JSONObject taskIdUUID) throws SQLException {
		tableName = tableName.split("\\.")[1];
		OrgIdUUIDmap = Maps.newHashMap();
		DataTableEntity OrlDt = null;

		try {
			StringBuffer sql = new StringBuffer();
			sql.append(" SELECT * FROM fe_base5.wf_infor where WI01 in (SELECT WT00 FROM fe_base5.wf_task where WT13= " +
					"(SELECT se16 FROM fe_base5.SYS_EVENT WHERE SE08 = 1 AND SE01 = ?))  ORDER BY WI01,WI00 ");
			OrlDt = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new String[]{tricode_funs});
		} catch (Exception e) {
			DataManipulationUtils.close(null, null, conn);
			throw e;
		}
		Map<String, String> stateMap = Maps.newHashMap();
		for (int i = 0; i < OrlDt.getRows(); i++) {
			FieldSetEntity Orlfs = OrlDt.getFieldSetEntity(i);
			FieldSetEntity DetailFs = new FieldSetEntity();
			//flow鏄庣粏琛�
			DetailFs.setTableName("product_sys_flow_detail");

			if (null == Orlfs.getString("wi02")) {
				//鏍囬
				DetailFs.setValue("title", "鏃犳爣棰�");
			} else {
				DetailFs.setValue("title", Orlfs.getString("wi02"));
			}
			//鑺傜偣鍚嶇О
			DetailFs.setValue("node_title", Orlfs.getString("wi04"));
			//棰勬湡澶勭悊浜�
			DetailFs.setValue("expect_person", userIdJson.getString(Orlfs.getString("wi05")));
			//鎺ユ敹鏃堕棿
			Date wi08 = Orlfs.getDate("wi08");
			DetailFs.setValue("accept_time", wi08);
			//鍒涘缓鏃堕棿
			DetailFs.setValue("created_utc_datetime", wi08);
			String wi12 = userIdJson.getString(Orlfs.getString("wi12"));
			//瀹為檯澶勭悊浜�
			DetailFs.setValue("actual_person", wi12);
			//淇敼浜轰负瀹為檯澶勭悊浜�
			DetailFs.setValue("updated_by", wi12);
			//澶勭悊鏃堕棿
			Date wi11 = Orlfs.getDate("wi11");
			DetailFs.setValue("deal_time", wi11);
			DetailFs.setValue("updated_utc_datetime", wi11);
			//婧恥uid锛屽叧鑱旀湰琛�
			FieldSetEntity fieldSetEntity = OrgIdUUIDmap.get(Orlfs.getString("wi14"));
			if (fieldSetEntity != null) {
				DetailFs.setValue("source_uuid", fieldSetEntity.getUUID());
			}
			//鍒涘缓浜� 涓婁釜鑺傜偣澶勭悊浜�
			DetailFs.setValue("created_by", userIdJson.getString(Orlfs.getString("wi15")));
			//鑺傜偣鏍囪瘑锛�0-鏅€氾紝1-鍔犵锛�2-閫€鍥烇級
			DetailFs.setValue("node_sign", 0);
			String node_uuid = UUIDMap.getString(Orlfs.getString("wi62"));
			if (BaseUtil.strIsNull(node_uuid)) {
				continue;
			}
			//鍏宠仈鑺傜偣琛�
			DetailFs.setValue("node_uuid", node_uuid);
			//鎰忚
			DetailFs.setValue("opinion", Orlfs.getString("wi20"));
			//棰勬湡澶勭悊鏃堕棿锛堝皬鏃讹級
			DetailFs.setValue("expect_deal_time", Orlfs.getString("wi09"));
			//瀹屾垚鏍囪瘑锛�0-鏈敹锛�1-宸叉敹鏈姙锛�2-宸插姙锛�3-缁堟锛�4-绔炰簤澶辫触锛�
//            DetailFs.setValue("node_deal_sign", nodeDealType(Orlfs.getString("wi07")));
			//鍔炵悊鐘舵€侊紙0-鏈敹锛�1-宸叉敹鏈姙锛�2-宸插姙锛�3-缁堟锛�4-绔炰簤澶辫触锛�
			String nodeState = nodeDealType(Orlfs.getString("wi13"));
			DetailFs.setValue("node_deal_sign", nodeState);
			//鍏宠仈琛�
			DetailFs.setValue("table_name", this.originalTable.getString(tableName));
			//鍏宠仈涓氬姟UUID
			DetailFs.setValue("record_uuid", this.pxMap.getString(tableName + Orlfs.getString("wi29")));
			//鍏宠仈娴佺▼琛╱uid
			DetailFs.setValue("flow_uuid", modelUUID);
			String task_uuid = taskIdUUID.getString(Orlfs.getString("wi01"));
			if (BaseUtil.strIsNull(task_uuid)) {
				continue;
			}
			String attachmentsValue = Orlfs.getString("attachment");
			//濡傛灉闄勪欢瀛楁鏈夊€�  鍚屾闄勪欢
			if (!BaseUtil.strIsNull(attachmentsValue)) {
				List<String> fileUuids = this.synchronizeCommonAccessories(conn, "flow_attachment", DetailFs.getTableName(), attachmentsValue);
				//瀛樺叆闄勪欢uuid
				DetailFs.setValue("flow_attachment", StringUtils.join(fileUuids, ","));
			}
			//鍏宠仈娴佺▼浠诲姟琛�
			DetailFs.setValue("task_uuid", task_uuid);
			baseDao.add(DetailFs);
			String wi00 = Orlfs.getString("wi00");
			OrgIdUUIDmap.put(wi00, DetailFs);
			stateMap.put(wi00, nodeState);
		}
		return stateMap;
	}

	/**
	 * 鍚屾娴佺▼娑堟伅琛�
	 */
	public void synchronizingProcessMessages(Connection conn, String tricode_funs, Map<String, String> stateMap) throws Exception {
		DataTableEntity OrlDt = null;
		try {
			StringBuffer sql = new StringBuffer();
			sql.append(" SELECT * FROM FE_BASE5.MESSAGEINFOR WHERE ME14 IN ( ")
					.append("SELECT WI00 FROM fe_base5.wf_infor where WI01 in (SELECT WT00 FROM fe_base5.wf_task where WT13= ")
					.append("(SELECT se16 FROM fe_base5.SYS_EVENT WHERE SE08 = 1 AND SE01 = ?))) ORDER BY ME14");

			OrlDt = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new String[]{tricode_funs});
		} catch (Exception e) {
			DataManipulationUtils.close(null, null, conn);
			throw e;
		}
		String id = null;
		String message_uuid = null;
		String state = null;
		DataTableEntity dt = new DataTableEntity();
		DataTableEntity dt1 = new DataTableEntity();
		for (int i = 0; i < OrlDt.getRows(); i++) {
			FieldSetEntity fs = OrlDt.getFieldSetEntity(i);
			//娴佺▼鑺傜偣id
			String me14 = fs.getString("me14");
			String sendUserId;
			//涓氬姟uuid
			FieldSetEntity fieldSet = OrgIdUUIDmap.get(fs.getString("me14"));
			String source_uuid = null;
			if (fieldSet != null) {
				source_uuid = fieldSet.getUUID();
			} else {
				continue;
			}
			if (!me14.equals(id)) {
				//涓嶄竴鏍峰垱寤烘秷鎭富琛�
				id = me14;
				FieldSetEntity message = new FieldSetEntity();
				//娑堟伅涓昏〃
				message.setTableName("product_sys_message");
				//娑堟伅涓婚
				message.setValue("title", fs.getString("me01"));
				//娑堟伅鍐呭
				message.setValue("content", fs.getString("me02"));
				//鏄惁闇€瑕佸彂閫侀偖浠�
				message.setValue("is_send_mail", 0);
				//娑堟伅绫诲瀷21 娴佺▼娑堟伅閮戒负浠诲姟娑堟伅
				message.setValue("message_type", 21);
				//鏄惁闇€瑕佸彂閫佺煭淇� 0涓嶅彂;1涓哄己鍒�;2涓鸿鍔�
				System.out.println(fs.getString("me20"));
				message.setValue("is_send_sms", "0".equals(fs.getString("me20")) ? 0 : 1);
				//鍙戦€佹椂闂�
				String me07 = fs.getString("me07");
				message.setValue("send_time", me07);
				//鍒涘缓鏃堕棿
				message.setValue("created_utc_datetime", me07);
				//鍙戦€佷汉
				sendUserId = userIdJson.getString(fs.getString("me03"));
				if (BaseUtil.strIsNull(sendUserId)) {
					//娴佺▼infor 鏁版嵁鍒涘缓浜轰负鍙戦€佷汉
					sendUserId = fieldSet.getString("created_by");
				}
				message.setValue("send_user_id", sendUserId);
				//鍒涘缓浜哄強鍙戦€佷汉
				message.setValue("created_by", sendUserId);
				//	涓氬姟琛�
				message.setValue("source_table", "product_sys_flow_detail");

				message.setValue("source_uuid", source_uuid);
				//url 涓氬姟鍦板潃
				//鑾峰彇褰撳墠鑺傜偣鐘舵€�
				state = stateMap.get(fs.getString("me14"));
				//鍔炵悊椤甸潰
				if ("0".equals(state) || "1".equals(state)) {
					message.setValue("url", "162132180172861usZ0N439?uuid=" + source_uuid);
					//鏌ヨ鍘熸枃椤甸潰
				} else if ("2".equals(state)) {
					message.setValue("url", "1621321824686868oKWL726?uuid=" + source_uuid);
				}

				message_uuid = UUID.randomUUID().toString();
				message.setValue("uuid", message_uuid);
				dt1.addFieldSetEntity(message);
			}

			FieldSetEntity message_user = new FieldSetEntity();
			message_user.setTableName("product_sys_message_user");
			//鍏宠仈lx_sys_message琛║UID
			message_user.setValue("message_uuid", message_uuid);
			//mail_send	鏄惁鍙戦€侀偖浠�
			message_user.setValue("mail_send", 0);
			// 	鏄惁闃呰  鑺傜偣鐘舵€佷负鏈
			//0鏈
			if ("0".equals(state)) {
				message_user.setValue("read_type", 0);
			} else {
				message_user.setValue("read_type", 1);
			}
			//read_time	闃呰鏃堕棿 鏆傛椂涓虹┖

			//receive_time	鎺ユ敹鏃堕棿 鏃犲瓧娈�
			//sms_send	鏄惁鍙戦€佺煭淇�
			message_user.setValue("sms_send", 0);
			//user_id	娑堟伅鎺ユ敹浜�
			String user_id = userIdJson.getString(fs.getString("me05"));
			//鎵句笉鍒板彂閫佷汉灏辨斁鎺ユ敹浜�
			if (BaseUtil.strIsNull(user_id)) {
				user_id = userIdJson.getString(fs.getString("me03"));
				if (BaseUtil.strIsNull(user_id)) {
					continue;
				}
			}
			message_user.setValue("user_id", user_id);
//			baseDao.add(message_user);
			dt.addFieldSetEntity(message_user);

			if (dt1.getRows() > 50000) {
				batchAddData.add(dt1);
				dt1 = new DataTableEntity();
			}
			if (dt.getRows() > 50000) {
				batchAddData.add(dt);
				dt = new DataTableEntity();
			}
		}
		batchAddData.add(dt1);
		batchAddData.add(dt);
	}


	//杩佺ЩWF_LINKS  杩炵嚎琛�
	public void syncLinks(String tricode_funs, Connection conn, String modelUUID) throws SQLException {
		DataTableEntity OrlDt = null;
		try {
			StringBuilder sql = new StringBuilder();
			sql.append("select a.WL04 WL04,a.WL05 WL05,a.WL06 WL06,(SELECT WN04 FROM fe_base5.WF_NODES where WN00=a.WL05) source_type,");
			sql.append("(select wa01 from fe_base5.WF_ACTION  where wa00=a.WL03) WL03S,(SELECT WN04 FROM fe_base5.WF_NODES where WN00=(select wa01 from fe_base5.WF_ACTION  where wa00=a.WL03)) ");
			sql.append(" target_type from fe_base5.wf_links a  where WL05 in (select wn00 from fe_base5.wf_nodes where WN01=(select wm00 from fe_base5.wf_model where wm05=(SELECT se16  FROM fe_base5.SYS_EVENT where se01=? and se08 = 1)))");

			OrlDt = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new Object[]{tricode_funs
			});
		} catch (Exception e) {
			DataManipulationUtils.close(null, null, conn);
			throw e;
		}
		for (int i = 0; i < OrlDt.getRows(); i++) {
			FieldSetEntity Orlfs = OrlDt.getFieldSetEntity(i);
			FieldSetEntity linksFs = new FieldSetEntity();
			linksFs.setTableName("product_sys_flow_link");
			linksFs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id());
			linksFs.setValue("created_utc_datetime", new Date());
			//鏍囬
			linksFs.setValue("title", Orlfs.getString("wl04"));
			//杩炵嚎璧峰浣嶇疆uuid"product_sys_flow_node uuid 鑻ヤ负绌哄垯璺宠繃
			if (Orlfs.getString("wl03s") == null) {
				continue;
			}
			linksFs.setValue("source_uuid", nodesIdUUID.getString(Orlfs.getString("wl03s")));
			//杩炵嚎璧风偣绫诲瀷锛�1-鑺傜偣锛�2-澶勭悊鍣�
			linksFs.setValue("source_type", "5".equals(Orlfs.getString("target_type")) ? 2 : 1);
			//杩炵嚎鎴浣嶇疆uuid"product_sys_flow_node uuid
			System.out.println(Orlfs.getString("wl05"));
			System.out.println(nodesIdUUID.getString(Orlfs.getString("wl05")));
			linksFs.setValue("target_uuid", nodesIdUUID.getString(Orlfs.getString("wl05")));
			//杩炵嚎鎴绫诲瀷锛�1-鑺傜偣锛�2-澶勭悊鍣�
			linksFs.setValue("target_type", "5".equals(Orlfs.getString("source_type")) ? 2 : 1);
			//绾跨殑鍒ゅ畾鏉′欢
			linksFs.setValue("judge", Orlfs.getString("wl06"));
			//鍏宠仈"product_sys_flow_model
			linksFs.setValue("flow_uuid", modelUUID);
			baseDao.add(linksFs);
		}
	}

	/**
	 * 閫氳繃鏁版嵁婧愯〃搴忓垪鍙�   鑾峰彇褰撳墠鍛樺伐user_id
	 */
//    public Integer getUserId(Integer id){
//        FieldSetEntity userFse = baseDao.getFieldSetEntityByFilter("product_sys_staffs", " remark = ? ",new Integer[]{id},false);
//        if(userFse == null){
//            return null;
//        }
//        return userFse.getInteger("user_id");
//    }

	/**
	 * 鍚屾task 琛�
	 *
	 * @param conn
	 * @param modelUUID 娴佺▼妯″潡uuid
	 * @return
	 * @throws SQLException
	 */
	public JSONObject syncTask(String tricode_funs, Connection conn, String modelUUID) throws SQLException {
		DataTableEntity OrlDt = null;
		try {
			OrlDt = BaseDaoServiceImpl.getDataTable(conn, "fe_base5.WF_TASK", "WT13=(SELECT se16  FROM fe_base5.SYS_EVENT where se01=? and se08 = 1)", new Object[]{tricode_funs
			});
		} catch (Exception e) {
			DataManipulationUtils.close(null, null, conn);
			throw e;
		}
		JSONObject map = new JSONObject();

		for (int i = 0; i < OrlDt.getRows(); i++) {
			FieldSetEntity Orlfs = OrlDt.getFieldSetEntity(i);
			FieldSetEntity taskFs = new FieldSetEntity();
			taskFs.setTableName("product_sys_flow_task");
			if (null == Orlfs.getString("wt05")) {
				//鏍囬
				taskFs.setValue("title", "鏃犳爣棰�");
			} else {
				taskFs.setValue("title", Orlfs.getString("wt05"));
			}
			// 鍙戣捣浜�
			//wt07鐢ㄦ埛id  鑾峰彇鐢ㄦ埛id
			String id = userIdJson.getString(Orlfs.getString("wt07"));
			//鍙戦€佷汉涓虹┖   灏辫烦杩�
			if (id == null) {
				continue;
			}
			taskFs.setValue("sender", id);
			//鍙戣捣鏃堕棿
			taskFs.setValue("send_time", Orlfs.getDate("wt09"));
			//缁撴潫鏃堕棿
			taskFs.setValue("finish_time", Orlfs.getDate("wt10"));
			//鍏宠仈娴佺▼琛�
			taskFs.setValue("flow_uuid", modelUUID);
			//瀹屾垚鏍囪瘑锛�1-鍦ㄥ姙锛�2-姝e父缁撴潫锛�3-缁堟锛�
			taskFs.setValue("finish_type", finishType(Orlfs.getString("wt16")));
			//鍏宠仈琛�
			String tbName = Orlfs.getString("wt03").split("\\.")[1];

			taskFs.setValue("table_name", this.originalTable.getString(tbName));
			//褰撳墠鐜妭鑺傜偣uuid
			taskFs.setValue("cur_node_uuid", Orlfs.getString("wt00"));
			//鍏宠仈涓氬姟UUID
			String record_uuid = pxMap.getString(tbName + Orlfs.getString("wt04"));
			if (BaseUtil.strIsNull(record_uuid)) {
				continue;
			}
			taskFs.setValue("record_uuid", record_uuid);
			taskFs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id());
			taskFs.setValue("created_utc_datetime", new Date());
			String uuid = baseDao.add(taskFs);
			map.put(Orlfs.getString("wt00"), uuid);
		}
		return map;
	}

	/**
	 * 鍒涘缓琛ㄨ鍙�
	 *
	 * @param sb
	 * @param table_name
	 * @param table_description
	 * @return
	 * @throws BaseException
	 */
	private StringBuilder createTable(StringBuilder sb, String table_name, String table_description) throws BaseException {
		StringBuilder createStatement = new StringBuilder();
		createStatement.append(" create table `" + table_name + "` ( ");
		createStatement.append("\n");
		createStatement.append(sb);
		createStatement.append("\n");
		createStatement.append(" ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='" + table_description + "'");
		return createStatement;
	}

	/**
	 * 缁勮瀛楁淇℃伅
	 *
	 * @param dt
	 * @throws BaseException
	 */
	private StringBuilder createFields(DataTableEntity dt) throws BaseException {
		StringBuilder table = new StringBuilder();
		if (!BaseUtil.dataTableIsEmpty(dt)) {
			for (int i = 0; i < dt.getRows(); i++) {
				FieldSetEntity fse = dt.getFieldSetEntity(i);
				//瀛楁绫诲瀷
				String field_type = fse.getString(CmnConst.FIELD_TYPE);
				//瀛楁鍚�
				String field_name = fse.getString(CmnConst.FIELD_NAME);
				//瀛楁鎻忚堪
				String field_description = fse.getString(CmnConst.FIELD_DESCRIPTION);
				//瀛楁闀垮害
				Integer field_length = fse.getInteger(CmnConst.FIELD_LENGTH);
				//灏忔暟浣嶆暟
				Integer field_unit = fse.getInteger(CmnConst.FIELD_UNIT);
				//鏄惁蹇呭~
				Boolean is_required = fse.getBoolean(CmnConst.IS_REQUIRED);
				//鏄惁鍞竴
				Boolean is_unique = fse.getBoolean(CmnConst.IS_UNIQUE);

				//鏄惁涓轰富閿�
				Boolean is_primary_key = "pk".equals(field_type) ? true : false;
				String field = newField(field_name, field_description, field_type, is_required, field_length, field_unit, is_primary_key, is_unique);
				if (table.length() > 0) {
					table.append(",\n\t");
				}
				table.append(field);
			}
		}
		return table;
	}

	/**
	 * 鏂板瓧娈电粍瑁�
	 *
	 * @param field_name        瀛楁鍚嶇О
	 * @param field_description 瀛楁鎻忚堪
	 * @param field_type        瀛楁绫诲瀷
	 * @param is_required       鏄惁蹇呭~
	 * @param field_length      瀛楁闀垮害
	 * @param field_unit        灏忔暟闀垮害
	 * @param is_primary_key    鏄惁鑷涓婚敭
	 * @param is_unique         鏄惁鍞竴
	 * @return
	 */
	private String newField(String field_name, String field_description, String field_type, boolean is_required, Integer field_length, Integer field_unit, boolean is_primary_key, boolean is_unique) {
		StringBuilder sql = new StringBuilder();
		sql.append(" `" + field_name + "` ");
		sql.append(" " + fieldType(field_type));
		sql.append(" (" + field_length);
		if ("decimal".equals(field_type) && field_unit != null && field_unit > 0) {
			sql.append("," + field_unit);
		}
		sql.append(") " + (!is_required && !is_primary_key ? " DEFAULT NULL " : " NOT NULL "));
		if (is_primary_key) {
			sql.append(" AUTO_INCREMENT ");
		}
		sql.append(" COMMENT '" + (field_description == null ? "" : field_description)).append("'");
		if (is_primary_key) {
			sql.append(" ,\t\n PRIMARY KEY (`" + field_name + "`) USING BTREE ");
		} else if (CmnConst.UUID.equals(field_name) || is_unique) {
			sql.append(" ,\t\nUNIQUE KEY `" + field_name + "` (`" + field_name + "`) USING BTREE");
		}
		return sql.toString();
	}

	/**
	 * 娴佺▼鑺傜偣绫诲瀷 1銆佸紑濮� 2銆佸鐞嗚妭鐐� 0銆佺粨鏉�
	 *
	 * @param field_type
	 * @return
	 */
	private String nodeType(String field_type) {
		String type = "";
		switch (field_type) {
			case "1":
				type = "1";
				break;
			case "99":
				type = "0";
				break;
			case "5":
				type = "2";
				break;
			case "3":
				type = "3";
			case "4":
				type = "3";
				break;
			case "6":
				type = "3";
				break;
			case "7":
				type = "3";
				break;
			case "8":
				type = "3";
				break;
			default:
				throw new BaseException(SystemCode.FIELD_TYPE_FIAL.getValue(), SystemCode.FIELD_TYPE_FIAL.getText() + "_" + field_type);
		}
		return type;
	}

	/**
	 * 娴佺▼瀹屾垚鐘舵€�
	 *
	 * @param field_type
	 * @return
	 */
	private String finishType(String field_type) {
		String finishType = "";
		switch (field_type) {
			case "0":
				finishType = "1";
				break;
			case "1":
				finishType = "2";
				break;
			case "2":
				finishType = "3";
				break;
			case "3":
				finishType = "3";
				break;

			default:
				throw new BaseException(SystemCode.FIELD_TYPE_FIAL.getValue(), SystemCode.FIELD_TYPE_FIAL.getText() + "_" + field_type);
		}
		return finishType;
	}

	/**
	 * 鍔炵悊鐘舵€�
	 *
	 * @param field_type
	 * @return
	 */
	private String nodeDealType(String field_type) {
		//婧愭暟鎹�        0锛氬凡鍔烇紱1锛氬凡鏀跺湪鍔烇紱2锛氭湭鏀舵湭鍔�;3 缁堟;4 鍐荤粨
		//鏈暟鎹� 瀹屾垚鏍囪瘑锛�0-鏈敹锛�1-宸叉敹鏈姙锛�2-宸插姙锛�3-缁堟锛�4-绔炰簤澶辫触锛�
		String finishType = "";
		switch (field_type) {
			case "0":
				finishType = "2";
				break;
			case "1":
				finishType = "1";
				break;
			case "2":
				finishType = "0";
				break;
			case "3":
				finishType = "3";
				break;
			case "4":
				finishType = "3";
				break;
			default:
				throw new BaseException(SystemCode.FIELD_TYPE_FIAL.getValue(), SystemCode.FIELD_TYPE_FIAL.getText() + "_" + field_type);
		}
		return finishType;
	}

	/**
	 * 瀛楁绫诲瀷瀵圭収
	 *
	 * @param field_type
	 * @return
	 */
	private String fieldType(String field_type) {
		String mysql_field_type = "";
		switch (field_type) {
			case "string":
				mysql_field_type = "varchar";
				break;
			case "code":
				mysql_field_type = "varchar";
				break;
			case "flowsign":
				mysql_field_type = "int";
				break;
			case "datetime":
				mysql_field_type = "datetime";
				break;
			case "file":
				mysql_field_type = "varchar";
				break;
			case "int":
				mysql_field_type = "int";
				break;
			case "pk":
				mysql_field_type = "bigint";
				break;
			case "parentuuid":
				mysql_field_type = "varchar";
				break;
			case "uuid":
				mysql_field_type = "varchar";
				break;
			case "userid":
				mysql_field_type = "bigint";
				break;
			case "orgUuid":
				mysql_field_type = "varchar";
				break;
			case "number":
				mysql_field_type = "decimal";
				break;
			case "serialNumber":
				mysql_field_type = "varchar";
				break;
			case "email":
				mysql_field_type = "varchar";
				break;
			case "idcard":
				mysql_field_type = "int";
				break;
			case "url":
				mysql_field_type = "varchar";
				break;
			case "mac":
				mysql_field_type = "varchar";
				break;
			case "table_name":
				mysql_field_type = "varchar";
				break;
			case "field_name":
				mysql_field_type = "varchar";
				break;
			case "text":
				mysql_field_type = "text";
				break;
			default:
				throw new BaseException(SystemCode.FIELD_TYPE_FIAL.getValue(), SystemCode.FIELD_TYPE_FIAL.getText() + "_" + field_type);
		}
		return mysql_field_type;
	}

	/**
	 * 瀛楁绫诲瀷瀵圭収
	 *
	 * @param field_type
	 * @return
	 */
	private String fieldTypeFE(String field_type) {
		String mysql_field_type = "";
		switch (field_type) {
			//涓婚敭涓嶈鍞竴涓嶈垗蹇呭~
			case "AUTO":
				mysql_field_type = "pk";
				break;
			case "NUMERIC":
				mysql_field_type = "number";
				break;
			case "DATETIME":
				mysql_field_type = "datetime";
				break;
			case "STRING":
				mysql_field_type = "string";
				break;
			case "NATIVE":
				mysql_field_type = "string";
				break;
			case "CDATETIME":
				mysql_field_type = "string";
				break;
			case "PROMPT":
				mysql_field_type = "string";
				break;
			case "SORT":
				mysql_field_type = "string";
				break;
			case "MEDIA":
				mysql_field_type = "string";
				break;
			case "SPFLAG":
				mysql_field_type = "flowsign";
				break;
			case "IMAGE":
				mysql_field_type = "text";
				break;
			case "TEXT":
				mysql_field_type = "text";
				break;
			case "UNITCODE":
				mysql_field_type = "string";
				break;
			case "FLOWCODE":
				mysql_field_type = "string";
				break;
			case "GUID":
				mysql_field_type = "string";
				break;
			default:
				throw new BaseException(SystemCode.FIELD_TYPE_FIAL.getValue(), SystemCode.FIELD_TYPE_FIAL.getText() + "_" + field_type);
		}
		return mysql_field_type;
	}

	private synchronized void execute(String sql) throws BaseException {
		try {
			Connection connection = ConnectionManager.getInstance().getConnection();
			PreparedStatement preparedStatement = connection.prepareStatement(sql);
			preparedStatement.execute();
		} catch (Exception e) {
			SpringMVCContextHolder.getSystemLogger().error(e);
			throw new BaseException(SystemCode.SQL_START_FAILED.getValue(), SystemCode.SQL_START_FAILED.getText() + e.getMessage());
		}
	}
}