package com.product.data.sync.util;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.product.admin.service.SystemMenusService;
import com.product.common.lang.StringUtils;
import com.product.core.cache.DataPoolCacheImpl;
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.FieldMetaEntity;
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.FeDataDSService;
import com.product.data.sync.service.SyFeDataService;
import com.product.data.sync.service.media.GdMediaUtil;
import com.product.file.service.FileManagerService;
import com.product.util.BaseDaoServiceImpl;
import com.product.util.BaseUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.File;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.*;

/**
 * Copyright LX
 *
 * @Title: BusinessDataSync
 * @Project: product-server
 * @date: 2021-09-30 14:19
 * @author: lx
 * @Description: 绾跨▼鍚屾涓氬姟鏁版嵁
 */
public class BusinessDataSync extends AbstractBaseService implements Runnable {
    private static Logger logger = LoggerFactory.getLogger(SyFeDataService.class);
    @Autowired
    public BaseDao baseDao;

    @Override
    public BaseDao getBaseDao() {
        return baseDao;
    }

    @Override
    public void setBaseDao(BaseDao baseDao) {
        this.baseDao = baseDao;
    }
    @Autowired
    FileManagerService fileManagerService;
    public FileManagerService getFileManagerService() {
        return fileManagerService;
    }
    public void setFileManagerService(FileManagerService fileManagerService) {
        this.fileManagerService = fileManagerService;
    }

    @Autowired
    SystemMenusService systemMenusService;

    public SystemMenusService getSystemMenusService() {
        return systemMenusService;
    }

    public void setSystemMenusService(SystemMenusService systemMenusService) {
        this.systemMenusService = systemMenusService;
    }
    @Autowired
    private FeDataDSService feDataDSService;

    public FeDataDSService getFeDataDSService() {
        return feDataDSService;
    }

    public void setFeDataDSService(FeDataDSService feDataDSService) {
        this.feDataDSService = feDataDSService;
    }
    @Autowired
    public GdMediaUtil gdMediaUtil;

    public GdMediaUtil getGdMediaUtil() {
        return gdMediaUtil;
    }

    public void setGdMediaUtil(GdMediaUtil gdMediaUtil) {
        this.gdMediaUtil = gdMediaUtil;
    }

    //鍏徃fe id 瀵瑰簲 浜у搧uuid
    Map<String, FieldSetEntity> OrgIdUUIDmap = Maps.newHashMap();

    //fe 浜哄憳id 瀵瑰簲  userid
    private JSONObject userIdJson = new JSONObject();
    //user_id 涓庣鍚� uuid
    private JSONObject userIdSignature = new JSONObject();
    //鐢ㄦ埛userid 鍛樺伐Fse
    private JSONObject userIdStaffFse = new JSONObject();
    //fe 閮ㄩ棬id 瀵瑰簲 鏈烘瀯uuid
    private JSONObject groupJson = new JSONObject();
    //fe 閮ㄩ棬id 瀵瑰簲 鏈烘瀯鐨勫叕鍙竨uid
    private JSONObject orgLevelJson = new JSONObject();
    //瀛楁绫诲瀷鍏宠仈
    private JSONObject fieldTypeJson = new JSONObject();
    //娴佺▼nodes fe id 瀵瑰簲 浜у搧uuid
    private JSONObject nodesIdUUID = new JSONObject();
    //婧愭暟鎹〃鍚�  鏈暟鎹〃鍚�
    private JSONObject originalTable = new JSONObject();
    //婧愬姛鑳藉悕绉�
    private String functionName;
    //鍞竴瀛楁
    private String pk;
    //涓昏〃琛ㄥ悕
    private String masterTableName;
    //婧愯〃鍚嶄笌uuid
    private Map<String,String> originalUuid = Maps.newHashMap();
    //鍗忓悓鍔炲叕 婧愭祦绋嬫暟鎹甈ARENTGUID 瀵瑰簲鏈暟鎹�
    private Map<String,DataTableEntity>  parentGuidData = Maps.newHashMap();
    //琛ㄥ敮涓€鏍囪瘑   鍜屾湰琛╱uid
    private JSONObject pxMap = new JSONObject();
    //宀椾綅id 宀椾綅uuid
    private JSONObject postJson = new JSONObject();
    //闄勪欢瀛楁
    private String attachmentValue = "";
    //宸插紑鍙戝叕鍏卞姛鑳� 鍏憡绠$悊 闂嵎绠$悊  鑰冨嫟绠$悊 鍗忓悓鍔炲叕
    private List<String> funTable = Lists.newArrayList("FE_APP5.PUB_NOTICE","FE_BASE5.RESEARCH_TOPIC","FE_APP5.APP_KQLRB","FE_BASE5.SYS_COLLABORATIVE","FE_APP5.BS_MEETING_FLOW");

    private String clientUUID;

    public String getClientUUID() {
        return clientUUID;
    }

    public void setClientUUID(String clientUUID) {
        this.clientUUID = clientUUID;
    }
    //鏂规硶Code
    private String tricode_funs;

    public BusinessDataSync(String tricode_funs){
        this.tricode_funs = tricode_funs;
    }

    public String TSPath =  Global.getSystemConfig("new.filePackage","");

    public Boolean isStr(String str) {
        boolean a = false;
        for (int i = 0; i < this.funTable.size(); i++) {
            if (str.equals(this.funTable.get(i))) {
                a = true;
            }
        }
        return a;
    }
    /**
     * 灏佽鍗曚綅閮ㄩ棬 浜哄憳瀵瑰簲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"));
            //鐢ㄦ埛user_id 瀵瑰簲staffs uuid
            userIdStaffFse.put(staffsData.getString(i, "user_id"), staffsData.getFieldSetEntity(i));
        }
        //鏌ヨ鏈夌鍚嶇殑鐢ㄦ埛
        DataTableEntity userSignatureData = baseDao.listTable("SELECT * FROM product_sys_users WHERE user_signature is not null", new String[]{});
        for (int i = 0; i < userSignatureData.getRows(); i++) {
            userIdSignature.put(userSignatureData.getString(i,"user_id"),userSignatureData.getString(i,"user_signature"));
        }
        DataTableEntity orgData = baseDao.listTable("product_sys_org_levels");
        for (int i = 0; i < orgData.getRows(); i++) {
            //婧愭暟鎹甶d 閮ㄩ棬uuid
            groupJson.put(orgData.getString(i, "sequence"), orgData.getString(i, "uuid"));
            //鍏徃uuid
            orgLevelJson.put(orgData.getString(i, "sequence"), orgData.getString(i, "org_level_uuid"));
        }
        DataTableEntity postData = baseDao.listTable("product_sys_job_posts");
        for (int i = 0; i < orgData.getRows(); i++) {
            //宀椾綅id 宀椾綅uuid
            postJson.put(postData.getString(i, "sequence"), postData.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("\\.");
        try {
            this.syncTable(sf28s, !isStr(sf28), null, conn);
        }catch (Exception e){
            e.getStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
        }

        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(conn,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"));
            String publisher = this.userIdJson.getString(feFs.getString("publisher"));
            if(BaseUtil.strIsNull(publisher)){
                continue;
            }
            fs.setValue("created_by", publisher);
            fs.setValue("created_utc_datetime", feFs.getDate("publish_date"));

            String uuid = baseDao.add(fs);
//            //閲嶆柊鑾峰彇jdbc杩炴帴
//            Connection connection = null;
//            try {
//                connection = this.getJDBC();
//            } catch (ClassNotFoundException e) {
//                e.printStackTrace();
//            }
            DataTableEntity subFeFs = getSubDt(conn, "FE_APP5.PUB_NOTICE_RECEIVER", "NOTICE_ID", feFs.getString("id"));
            DataTableEntity subData = new DataTableEntity();
            FieldMetaEntity f = new FieldMetaEntity();
            f.setTableName(new String[]{"product_oa_announcement_role"});
            subData.setMeta(f);
            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);
                subData.addFieldSetEntity(fsSub);
            }
            baseDao.add(subData);
//            DataManipulationUtils.close(null, null, connection);
        }
    }

    /**
     * 鑾峰彇userId
     * 瑙f瀽澶氶€変汉鍛�,閮ㄩ棬,宀椾綅
     * @param receivers 瀛楁鍊�
     */
    public String getUserIds(Connection conn,String receivers){
        String[] receiversArr = receivers.split(",");
        Set<String> extentArr = new HashSet<>();
        try {
            //鏌ヨ鍏徃閮ㄩ棬琛ㄦ暟鎹�
            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());
        }
        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", 1);
            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", 1);
            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", 1);
            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", 1);
            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", 1);
            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")) {
            //涓や釜琛ㄥ缓绔嬪叧鑱�
            this.originalTable.put("PUB_NOTICE", "product_oa_announcement");
            syncNotice(conn, tableName);
            //淇敼宸插悓姝ラ檮浠� 娣诲姞 module_uuid function_uuid
            baseDao.executeUpdate(" UPDATE product_sys_attachments SET module_uuid = ?, function_uuid = ? WHERE attachment_data_table = ? AND function_uuid is null ",new String[]{"036ccacd-47da-4f6e-9cf7-972211717e6e", "ed86d09a-23be-4d8c-8cb2-be8622fe50f4", "product_oa_announcement"});
        }
        //鑰冨嫟琛� 闇€鍚屾鍏宠仈鏁版嵁濡傝鍋囪〃 澶栧嚭琛�
        if (tableName.equals("FE_APP5.APP_KQLRB")) {
            this.originalTable.put("APP_KQLRB", "product_oa_punch_record");
            this.originalTable.put("PLEASELEAVE", "product_oa_ask_for_leave");
            this.originalTable.put("FT_1_WCDJB00", "product_oa_business_trip");
            //鍚屾鑰冨嫟
            this.synchronousClock(conn);
            System.out.println("=================鑰冨嫟鍚屾鎴愬姛===============");
        }
        //鍗忓悓鍔炲叕
        if (tableName.equals("FE_BASE5.SYS_COLLABORATIVE")) {
            this.originalTable.put("SYS_COLLABORATIVE", "product_oa_cooperates");
            //鍗忓悓鍔炲叕鏁版嵁
            this.syncCcooperates(conn, tableName);
            //鍗忓悓妯℃澘鏁版嵁
            this.syncCollaborativeTemplate(conn);
            baseDao.executeUpdate(" UPDATE product_sys_attachments SET module_uuid = ?, function_uuid = ? WHERE attachment_data_table = ? AND function_uuid is null ",new String[]{"127c3f55-a7b4-4a77-a097-a65ba95b76f0", "6e587365-8ebd-4ab5-bade-dd3b1bf640f8", "product_oa_cooperates"});

            baseDao.executeUpdate(" UPDATE product_sys_attachments SET module_uuid = ?, function_uuid = ? WHERE attachment_data_table = ? AND function_uuid is null ",new String[]{"127c3f55-a7b4-4a77-a097-a65ba95b76f0", "6e587365-8ebd-4ab5-bade-dd3b1bf640f8", "product_oa_cooperate_flow_node"});

            baseDao.executeUpdate(" UPDATE product_sys_attachments SET module_uuid = ?, function_uuid = ? WHERE attachment_data_table = ? AND function_uuid is null ",new String[]{"127c3f55-a7b4-4a77-a097-a65ba95b76f0", "6e587365-8ebd-4ab5-bade-dd3b1bf640f8", "product_oa_cooperate_flow_reply"});
            System.out.println("=================鍗忓悓鍔炲叕鍚屾鎴愬姛===============");
        }
        //浼氳鍚屾
        if(tableName.equals("FE_APP5.BS_MEETING_FLOW")){
            //鍒ゆ柇鏄惁鏄凡缁忓悓姝ヨ繃鐨勮〃
            DataTableEntity dataTable = baseDao.listTable("product_oa_conference_room_config");
            if (!BaseUtil.dataTableIsEmpty(dataTable)) {
                return;
            }
            //浼氳瀹ゅ悓姝�
            Map<String, String> map = this.meetingRoomSync(conn,"FE_APP5.BS_MEETINGROOM");
            this.originalTable.put("BS_MEETINGROOM", "product_oa_conference_room_config");
            //浼氳鍚屾
            this.meetingSynchronous(conn,tableName,map);
            this.originalTable.put("BS_MEETING_FLOW", "product_oa_conference_apply");
            //鍗曠嫭鍚屾浼氳娴佺▼  寰呰皟鏁�
            FieldSetEntity user = baseDao.getFieldSetByFilter("product_sys_org_manager" , " manager_type = ? ", new String[]{"2"}, false);
            //鍚屾浼氳娴佺▼
            try {
                this.attachmentValue = ",attachment,";
                //杩佺Щ wf_model娴佺▼妯″潡琛�
                String typeCode = this.syncModel("035-411-000", conn, "24917f78-c672-4432-b7a8-a7a2dbc9f45a", "FE_APP5.BS_MEETING_FLOW", null, 1, null,false);
                //鏍规嵁瑕佹眰娴佺▼瑕佸悓姝ヤ袱娆� 鐩稿悓娴佺▼鐨則ypeCode鐩稿悓
                if(!BaseUtil.strIsNull(typeCode)){
                    this.syncModel("035-411-000", conn, "24917f78-c672-4432-b7a8-a7a2dbc9f45a", "FE_APP5.BS_MEETING_FLOW", "00000000-0000-0000-0000-000000000000", user.getInteger("user_id"), typeCode,true);
                }
                //mvc 浼氳椤甸潰缁戝畾鏂扮殑娴佺▼
                FieldSetEntity page = baseDao.getFieldSet("product_sys_mvc_page","5ab3ef19-ba6d-4d47-8082-3e21fa1f0a0f",false);
                page.setValue("flow_uuid",typeCode);
                baseDao.update(page);
            } catch (SQLException e) {
                e.printStackTrace();
            }
            System.out.println("=================浼氳绠$悊鍚屾鎴愬姛===============");
        }
    }

    /**
     * 鍚屾鑰冨嫟
     * @param conn
     * @throws SQLException
     */
    private void synchronousClock(Connection conn)throws SQLException{
        //鍚屾璇峰亣 PLEASELEAVE
        DataTableEntity pleaseleave = null;
        try {
            pleaseleave = BaseDaoServiceImpl.getDataTable(conn, "FE_APP5.PLEASELEAVE", "", new Object[]{});
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            throw e;
        }
        try {
            this.leaveApplyFor(pleaseleave);
        }catch (BaseException e){
            e.printStackTrace();
        }
        FieldSetEntity user = baseDao.getFieldSetByFilter("product_sys_org_manager" , " manager_type = ? ", new String[]{"2"}, false);
        //鍗曠嫭鍚屾璇峰亣娴佺▼
        try {
            this.attachmentValue = ",accessory_uuid,";
            //杩佺Щ wf_model娴佺▼妯″潡琛�
            String typeCode = this.syncModel("019-015-000", conn, "66a6ff4b-1c60-4dfe-a544-4bac81d17efe", "FE_APP5.PLEASELEAVE", null, 1, null,false);
            //鏍规嵁瑕佹眰娴佺▼瑕佸悓姝ヤ袱娆� 鐩稿悓娴佺▼鐨則ypeCode鐩稿悓
            if(!BaseUtil.strIsNull(typeCode)){
                this.syncModel("019-015-000", conn, "66a6ff4b-1c60-4dfe-a544-4bac81d17efe", "FE_APP5.PLEASELEAVE", "00000000-0000-0000-0000-000000000000", user.getInteger("user_id"), typeCode,true);
            }
            //mvc 浼氳椤甸潰缁戝畾鏂扮殑娴佺▼
            FieldSetEntity page = baseDao.getFieldSet("product_sys_mvc_page","77897853-4059-4b57-ac65-45ff8d6f4fe3",false);
            page.setValue("flow_uuid",typeCode);
            baseDao.update(page);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        //鍚屾澶栧嚭 FT_1_WCDJB00
        //鍚屾澶栧嚭閲岄潰鐨勬暟鎹� 鍚鍑� 鍑哄樊 璇峰亣
        DataTableEntity wcdj = null;
        try {
            wcdj = BaseDaoServiceImpl.getDataTable(conn, "SELECT TO_NUMBER(to_date(to_char(A.F1W09,'yyyymmdd'),'yyyymmdd')- to_date(to_char(A.F1W08,'yyyymmdd'),'yyyymmdd')) + 1 as DAY,A.* FROM FE_APP5.FT_1_WCDJB00 A",  new Object[]{});
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            throw e;
        }
        this.goOutApplyFor(wcdj);
        //鍚屾鑰冨嫟
        DataTableEntity clockDt = null;
        try {
            clockDt = BaseDaoServiceImpl.getDataTable(conn, "FE_APP5.APP_KQLRB", "", new Object[]{});
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            throw e;
        }
        this.synchronousClock(clockDt);
    }


    /**
     * 鍚屾璇峰亣鐢宠
     * @param pleaseleave 璇峰亣data鏁版嵁
     */
    private void leaveApplyFor(DataTableEntity pleaseleave) throws BaseException{
        //鍚屾璇峰亣鏁版嵁
        if(!BaseUtil.dataTableIsEmpty(pleaseleave)){
            for (int i = 0; i < pleaseleave.getRows(); i++) {
                FieldSetEntity leaveFse = pleaseleave.getFieldSetEntity(i);
                FieldSetEntity fieldSetEntity = new FieldSetEntity();
                fieldSetEntity.setTableName("product_oa_ask_for_leave");
                fieldSetEntity.setValue("id", leaveFse.getInteger("pl00"));
                //PL11	璇蜂紤鍋囧紑濮嬫椂闂�            fill_in_time	濉崟鏃堕棿
                String pl11 = leaveFse.getString("pl11");
                fieldSetEntity.setValue("fill_in_time",pl11);
                //PL11	璇蜂紤鍋囧紑濮嬫椂闂�                 start_time	寮€濮嬫椂闂�
                fieldSetEntity.setValue("start_time",pl11);
                //PL15	璇蜂紤鍋囩粨鏉熸椂闂�                end_time	缁撴潫鏃堕棿
                String pl15 = leaveFse.getString("pl15");
                if(BaseUtil.strIsNull(pl15)){
                    if(BaseUtil.strIsNull(pl11)){
                        continue;
                    }else {
                        pl15 = pl11;
                    }
                }
                fieldSetEntity.setValue("end_time",pl15);
                //PL12	璇蜂紤鍋囧ぉ鏁� day	璇峰亣澶╂暟
                fieldSetEntity.setValue("day",leaveFse.getString("pl12"));
                //PL09	璇蜂紤鍋囧師鍥� cause	璇峰亣鍘熷洜
                String pl09 = leaveFse.getString("pl09");
                //PL10	璇蜂紤鍋囩被鍒� leave_type	璇峰亣绫诲瀷
                String pl10 = leaveFse.getString("pl10");
                if(BaseUtil.strIsNull(pl09)){
                    if(BaseUtil.strIsNull(pl10)){
                        continue;
                    }else {
                        pl09 = pl10;
                    }
                }
                fieldSetEntity.setValue("cause",pl09);
                //PL01	鐢宠浜哄鍚� created_by	鍒涘缓浜�
                String userId = userIdJson.getString(leaveFse.getString("pl01"));
                if(BaseUtil.strIsNull(userId)){
                    continue;
                }
                fieldSetEntity.setValue("created_by",userId);
                //staff_uuid	鍛樺伐uuid
                FieldSetEntity staff = (FieldSetEntity)this.userIdStaffFse.get(userId);
                fieldSetEntity.setValue("staff_uuid",staff.getUUID());
                //PL14	绉戝 org_level_uuid	鍏徃uuid
                String dept = leaveFse.getString("pl14");
                String org_level_uuid = this.orgLevelJson.getString(dept);
                if(BaseUtil.strIsNull(org_level_uuid)){
                    continue;
                }
                fieldSetEntity.setValue("org_level_uuid",org_level_uuid);
                //閮ㄩ棬
                fieldSetEntity.setValue("department_uuid",this.groupJson.getString(dept));

                String leave_type;
                if(BaseUtil.strIsNull(pl10)){
                    //鏀逛负骞村亣
                    leave_type = "7";
                }else {
                    switch (pl10) {
                        case "浜у亣":
                            leave_type = "5";
                            break;
                            //鏀逛负骞村亣
                        case "浼戝亣":
                            leave_type = "7";
                            break;
                        case "浜嬪亣":
                            leave_type = "1";
                            break;
                        case "濠氬亣":
                            leave_type = "9";
                            break;
                        case "鐥呭亣":
                            leave_type = "2";
                            break;
                        default:
                            //浼戝亣  鏀逛负骞村亣
                            leave_type = "7";
                    }
                }
                fieldSetEntity.setValue("leave_type", leave_type);
                fieldSetEntity.setValue("flow_flag", leaveFse.getString("status"));
                String uuid = baseDao.add(fieldSetEntity);
                pxMap.put("PLEASELEAVE"+leaveFse.getString("pl00"),uuid);
            }
        }
    }

    /**
     * 鍚屾澶栧嚭鐢宠    鍒嗗埆鍚屾鍒板鍑虹敵璇�  鍑哄樊鐢宠 璇峰亣鐢宠
     * @param wcdj 澶栧嚭data鏁版嵁
     */
    private void goOutApplyFor(DataTableEntity wcdj) throws SQLException {
        if(!BaseUtil.dataTableIsEmpty(wcdj)){
            for (int i = 0; i < wcdj.getRows(); i++) {
                FieldSetEntity fse = wcdj.getFieldSetEntity(i);
                //F1W05	澶栧嚭绫诲瀷
                String f1w05 = fse.getString("f1w05");
                if(!BaseUtil.strIsNull(f1w05)) {
                    switch (f1w05) {
                        //鍑哄樊    鍚屾澶栧嚭閲岄潰鍑哄樊鏁版嵁
                        case "10":
                            this.syncEvection(fse);
                            break;
                        //澶栧嚭寮€浼� 鍚屾澶栧嚭閲岄潰澶栧嚭鏁版嵁
                        case "11":
                            this.synchronousOut(fse, "0");
                            break;
                        //澶栧嫟
                        case "12":
                            this.synchronousOut(fse, "1");
                            break;
                        //璋冧紤
                        case "13":
                            this.synchronizationLeave(fse, "4", "璋冧紤");
                            break;
                        //浼戝亣
                        case "14":
                            this.synchronizationLeave(fse, "11", "浼戝亣");
                            break;
                        //鐥呭亣
                        case "15":
                            this.synchronizationLeave(fse, "2", "鐥呭亣");
                            break;
                        //浜嬪亣
                        case "16":
                            this.synchronizationLeave(fse, "1", "浜嬪亣");
                            break;
                        default:
                            break;
                    }
                }
            }
        }
        //鍚屾澶栧嚭鏁版嵁
//        if(!BaseUtil.dataTableIsEmpty(qjsq)){
//            for (int i = 0; i < qjsq.getRows(); i++) {

//                F1W01	鐧昏浜�
//                F1W02	閫佸鏍囪瘑
//                F1W03	鍏徃缂栫爜
//                F1W04	鐢宠浜�

//                F1W06	澶栧嚭浜嬬敱
//                F1W07	鏄惁褰掓潵
//                F1W08	澶栧嚭鏃堕棿
//                F1W09	鍥炴潵鏃堕棿
//                F1W10	鏃舵
//                F1W11	绉戝
//                F1W12	澶囩敤
//                fieldSetEntity.setTableName("product_oa_business_trip");
//            }
//        }
    }

    /**
     * 澶栧嚭鏁版嵁鍚屾鍒拌鍋�
     * @param fse 璇峰亣鏁版嵁
     * @param type 璇峰亣绫诲瀷
     */
    private void synchronizationLeave(FieldSetEntity fse, String type, String typeString){
        FieldSetEntity fieldSetEntity = new FieldSetEntity();
        fieldSetEntity.setTableName("product_oa_ask_for_leave");
        String f1w08 = fse.getString("f1w08");
        //f1w08	璇蜂紤鍋囧紑濮嬫椂闂�    fill_in_time	濉崟鏃堕棿
        fieldSetEntity.setValue("fill_in_time",f1w08);
        //f1w08	璇蜂紤鍋囧紑濮嬫椂闂�                 start_time	寮€濮嬫椂闂�
        fieldSetEntity.setValue("start_time",f1w08);
        //f1w09	璇蜂紤鍋囩粨鏉熸椂闂�                end_time	缁撴潫鏃堕棿
        fieldSetEntity.setValue("end_time",fse.getString("f1w09"));
        //day	璇蜂紤鍋囧ぉ鏁� day	璇峰亣澶╂暟
        fieldSetEntity.setValue("day",fse.getString("day"));
        //f1w06	璇蜂紤鍋囧師鍥� cause	璇峰亣鍘熷洜
        String f1w06 = fse.getString("f1w06");
        //鑻ヨ鍋囧師鍥犱负绌哄氨鐢ㄨ鍋囩被鍨�
        if(BaseUtil.strIsNull(f1w06)){
            f1w06 = typeString;
        }
        fieldSetEntity.setValue("cause",f1w06);
        //f1w01	鐧昏浜� created_by	鍒涘缓浜�
        String userId = userIdJson.getString(fse.getString("f1w01"));
        if(BaseUtil.strIsNull(userId)){
             userId = userIdJson.getString(fse.getString("f1w04"));
             if(BaseUtil.strIsNull(userId)){
                 return;
             }
        }
        fieldSetEntity.setValue("created_by",userId);
        //staff_uuid	鍛樺伐uuid
        FieldSetEntity staff = (FieldSetEntity)this.userIdStaffFse.get(userId);
        fieldSetEntity.setValue("staff_uuid", staff.getUUID());
        //f1w11	绉戝 org_level_uuid	鍏徃uuid
        String dept = fse.getString("f1w11");
        String org_level_uuid = this.orgLevelJson.getString(dept);
        if(BaseUtil.strIsNull(org_level_uuid)){
            org_level_uuid = staff.getString("org_level_uuid");
        }
        fieldSetEntity.setValue("org_level_uuid",org_level_uuid);
        //閮ㄩ棬
        String dept_uuid = this.groupJson.getString(dept);
        if(BaseUtil.strIsNull(dept_uuid)){
            dept_uuid  = staff.getString("dept_uuid");
        }
        fieldSetEntity.setValue("department_uuid",dept_uuid);
        fieldSetEntity.setValue("leave_type", type);
        fieldSetEntity.setValue("flow_flag", fse.getString("f1w02"));
        try {
            baseDao.add(fieldSetEntity);
        }catch (BaseException e){
            e.printStackTrace();
        }
    }

    /**
     * 鍚屾鍑哄樊鏁版嵁
     * @param fse 鍑哄樊鏁版嵁
     */
    private void syncEvection(FieldSetEntity fse){
        FieldSetEntity fieldSetEntity = new FieldSetEntity();
        fieldSetEntity.setTableName("product_oa_business_trip");
        //applicant	鐢宠浜哄憳
        String user_id = this.userIdJson.getString(fse.getString("f1w01"));
        if(BaseUtil.strIsNull(user_id)){
            return;
        }
        fieldSetEntity.setValue("applicant",user_id);
        //鐢宠鏃ユ湡
        String f1w08 = fse.getString("f1w08");
        fieldSetEntity.setValue("application_time",f1w08);
        //budget	棰勭畻閲戦
        fieldSetEntity.setValue("budget",0);
        //缁撴潫鏃堕棿
        fieldSetEntity.setValue("business_last_time",fse.getString("f1w09"));
        //鍑哄樊鏃堕棿
        fieldSetEntity.setValue("business_start_time",f1w08);
        //business_trip_place	鍑哄樊鍦扮偣 绌�
        fieldSetEntity.setValue("business_trip_place","[鏃犲嚭宸湴鐐筣");
        //鍒涘缓浜�
        String f1w04 = this.userIdJson.getString(fse.getString("f1w04"));
        if(BaseUtil.strIsNull(f1w04)){
            f1w04 = user_id;
        }
        fieldSetEntity.setValue("created_by",f1w04);
        //鍒涘缓鏃堕棿
        fieldSetEntity.setValue("created_utc_datetime",f1w08);
        //	鐢宠閮ㄩ棬	string	1
        String dept = fse.getString("f1w11");
        String department = this.groupJson.getString(dept);
        FieldSetEntity staff = (FieldSetEntity)this.userIdStaffFse.get(user_id);
        if(BaseUtil.strIsNull(department)){
            department = staff.getString("dept_uuid");
        }
        fieldSetEntity.setValue("department",department);
        //documengt_number	鍗曟嵁缂栧彿
        fieldSetEntity.setValue("documengt_number","[鏃犲崟鎹紪鍙穄");
        //娴佺▼鏍囪瘑
        fieldSetEntity.setValue("flow_flag",fse.getString("f1w02"));
        //org_level_uuid	鍏宠仈鍏徃
        String org_level_uuid = this.orgLevelJson.getString(dept);
        if(BaseUtil.strIsNull(org_level_uuid)){
            org_level_uuid = staff.getString("org_level_uuid");
        }
        fieldSetEntity.setValue("org_level_uuid",org_level_uuid);
        //post	鑱屽姟锛堝叧鑱斿矖浣嶄俊鎭〃uuid锛�
        fieldSetEntity.setValue("post",staff.getString("job_post_uuid"));
        //鍑哄樊澶╂暟
        fieldSetEntity.setValue("total_days",fse.getString("day"));
        //F1W06	澶栧嚭浜嬬敱
        String f1w06 = fse.getString("f1w06");
        if(BaseUtil.strIsNull(f1w06)){
            f1w06 = "鍑哄樊";
        }
        fieldSetEntity.setValue("reasons_for_business",f1w06);
        try{
            baseDao.add(fieldSetEntity);
        }catch (BaseException e){
            e.printStackTrace();
        }
    }
    /**
     * 鍚屾澶栧嚭鏁版嵁
     * @param fse 澶栧嚭鏁版嵁
     */
    private void synchronousOut(FieldSetEntity fse, String out_type){
        FieldSetEntity fieldSetEntity = new FieldSetEntity();
        fieldSetEntity.setTableName("product_oa_go_out_application");
        //actual_start_time	瀹為檯寮€濮嬫椂闂�
        String f1w08 = fse.getString("f1w08");
        fieldSetEntity.setValue("actual_start_time",f1w08);
        //actual_end_time	瀹為檯缁撴潫鏃堕棿
        fieldSetEntity.setValue("actual_end_time",fse.getString("f1w09"));
        //applicant	鐢宠浜�
        String user_id = this.userIdJson.getString(fse.getString("f1w01"));
        //鎵句笉鍒板憳宸ョ洿鎺ラ€€鍑�
        if(BaseUtil.strIsNull(user_id)){
            return;
        }
        FieldSetEntity staff = (FieldSetEntity)this.userIdStaffFse.get(user_id);
        fieldSetEntity.setValue("applicant",user_id);
        //applicat_time 鐢宠鏃堕棿
        fieldSetEntity.setValue("applicat_time",f1w08);
        //atual_time 瀹為檯鐢ㄦ椂
        fieldSetEntity.setValue("applicat_time",fse.getString("day"));
        //created_by	鍒涘缓鑰咃紝lx_sys_users琛╱ser_id
        String f1w04 = this.userIdJson.getString(fse.getString("f1w04"));
        if(BaseUtil.strIsNull(f1w04)){
            f1w04 = user_id;
        }
        fieldSetEntity.setValue("created_by",f1w04);
        //created_utc_datetime	鍒涘缓鏃堕棿
        fieldSetEntity.setValue("created_utc_datetime",f1w08);
        //dept_uuid	閮ㄩ棬
        String dept = fse.getString("f1w11");
        String dept_uuid = this.groupJson.getString(dept);
        if(BaseUtil.strIsNull(dept_uuid)){
            dept_uuid  = staff.getString("dept_uuid");
        }
        fieldSetEntity.setValue("dept_uuid",dept_uuid);
        //flow_flag	娴佺▼閫佸姙榛樿瀛楁锛�0-寰呭彂锛�1-鍦ㄥ姙锛�2-鍔炵粨
        fieldSetEntity.setValue("flow_flag",fse.getString("f1w02"));
        //org_level_uuid	缁勭粐鏈烘瀯锛宭x_sys_org_levels琛╱uid
        String org_level_uuid = this.orgLevelJson.getString(dept);
        if(BaseUtil.strIsNull(org_level_uuid)){
            org_level_uuid  = staff.getString("org_level_uuid");
        }
        fieldSetEntity.setValue("org_level_uuid",org_level_uuid);
        fieldSetEntity.setValue("reason",fse.getString("f1w06"));
        fieldSetEntity.setValue("out_type", out_type);
        try{
            baseDao.add(fieldSetEntity);
        }catch (BaseException e){
            e.printStackTrace();
        }
    }
    /**
     * 鍚屾鑰冨嫟鏁版嵁
     * @param clockDt 澶栧嚭data鏁版嵁
     */
    private void synchronousClock(DataTableEntity clockDt) throws SQLException {
        //鍚屾鑰冨嫟鏁版嵁
        if(!BaseUtil.dataTableIsEmpty(clockDt)){
            DataTableEntity dataTableEntity = new DataTableEntity();
            FieldMetaEntity f = new FieldMetaEntity();
            f.setTableName(new String[]{"product_oa_punch_record"});
            dataTableEntity.setMeta(f);
            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");
                fieldSetEntity.setValue("dept_uuid",this.groupJson.getString(dept));
                String org_level_uuid = this.orgLevelJson.getString(dept);
                if(BaseUtil.strIsNull(org_level_uuid)){
                    org_level_uuid = this.groupJson.getString(dept);
                }
                //鍏徃uuid
                fieldSetEntity.setValue("org_level_uuid", org_level_uuid);
                //涓婂崍涓婄彮鎵撳崱鏃堕棿
                String swdksj = fse.getString("swdksj");
                fieldSetEntity.setValue("punch_time_one",swdksj);
                //榛樿涓婂崍涓嬬彮鎵撳崱鏃堕棿
                if(!BaseUtil.strIsNull(swdksj)) {
                    String defaultTime = swdksj.substring(0, 11) + "12:00:00";
                    fieldSetEntity.setValue("punch_time_three", defaultTime);
                }
                //涓婄彮鑰冨嫟缁撴灉
                fieldSetEntity.setValue("time_one_result",fse.getString("swkqjg"));
                //涓婂崍mac鍦板潃
                fieldSetEntity.setValue("mac_one",fse.getString("mac"));
                //涓嬪崍涓婄彮鎵撳崱鏃堕棿
                String xwdksj = fse.getString("xwdksj");
                fieldSetEntity.setValue("punch_time_three",xwdksj);
                //榛樿涓嬪崍涓嬬彮鎵撳崱鏃堕棿
                if(!BaseUtil.strIsNull(xwdksj)) {
                    String defaultTime = xwdksj.substring(0, 11) + "18:00:00";
                    fieldSetEntity.setValue("punch_time_four", defaultTime);
                }
                //涓嬪崍mac1鍦板潃
                fieldSetEntity.setValue("mac_two", fse.getString("mac1"));
                //濮撳悕
                String userId = userIdJson.getString(fse.getString("name"));
                if(BaseUtil.strIsNull(userId)){
                    continue;
                }
                fieldSetEntity.setValue("created_by", userId);
                //濮撳悕
                fieldSetEntity.setValue("created_utc_datetime", fse.getString("time01"));

                //涓婄彮鑰冨嫟缁撴灉
                fieldSetEntity.setValue("time_one_result",fse.getString("swkqjg"));
//                String swkqjg = fse.getString("swkqjg");
                //涓嬬彮鑰冨嫟缁撴灉
                fieldSetEntity.setValue("time_four_result",fse.getString("xwkqjg"));
//                String xwkqjg = fse.getString("xwkqjg");
                dataTableEntity.addFieldSetEntity(fieldSetEntity);
                if(dataTableEntity.getRows() == 1000){
                    baseDao.add(dataTableEntity);
                    dataTableEntity = new DataTableEntity();
                    dataTableEntity.setMeta(f);
                }
                //璇蜂紤鍋囨斁鍒拌鍋囪〃閲岄潰
//                switch (xwkqjg){
//                        //姝e父
//                    case "0":
//                        //杩熷埌
//                    case "1":
//                        //缂哄嫟
//                    case "2":
//                        break;
//                        //鍑哄樊 鍑哄樊琛�
//                    case "10":
//                        break;
//                        //澶栧嚭寮€浼� 澶栧嚭琛�
//                    case "11":
//                        //澶栧嫟 澶栧嚭琛�
//                    case "12":
//                        break;
//                        //璋冧紤 璇峰亣琛�
//                    case "13":
//                        //浼戝亣
//                    case "14":
//                        //鐥呭亣
//                    case "15":
//                        //浜嬪亣
//                    case "16":
//                        //璇峰亣
//                    case "3":
//                        //濠氬亣
//                    case "4":
//                        //浜у亣
//                    case "5":
//                        break;
//                }
            }
            if(!BaseUtil.dataTableIsEmpty(dataTableEntity)) {
                baseDao.add(dataTableEntity);
            }
        }
    }

    /**
     * 浼氳瀹ゅ悓姝�
     *
     * @param conn
     * @param tableName
     */
    private Map<String, String> meetingRoomSync(Connection conn, String tableName) throws SQLException {
        //鍒ゆ柇鏄惁鏄凡缁忓悓姝ヨ繃鐨勮〃
        DataTableEntity dataTable = baseDao.listTable("product_oa_conference_room_config");
        Map<String, String> map = Maps.newHashMap();
        if (!BaseUtil.dataTableIsEmpty(dataTable)) {
            return map;
        }
        DataTableEntity meetingRoomDt = null;
        try {
            meetingRoomDt = BaseDaoServiceImpl.getDataTable(conn, tableName, "", new Object[]{});
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            throw e;
        }
        if(!BaseUtil.dataTableIsEmpty(meetingRoomDt)) {
            for (int i = 0; i < meetingRoomDt.getRows(); i++) {
                FieldSetEntity fse = meetingRoomDt.getFieldSetEntity(i);
                FieldSetEntity fieldSet = new FieldSetEntity();
                fieldSet.setTableName("product_oa_conference_room_config");
                //ADDRESS 鍦板潃
                fieldSet.setValue("address",fse.getString("address"));
                String recorded_man = userIdJson.getString(fse.getString("recorded_man"));
                if(BaseUtil.strIsNull(recorded_man)){
                    continue;
                }
                //ADMIN	绠$悊鍛�                manager_user 绠$悊鍛�
                String admin = userIdJson.getString(fse.getString("admin"));
                if(BaseUtil.strIsNull(admin)){
                    admin = recorded_man;
                }
                fieldSet.setValue("manager_user", admin);
                //APPLY_TIME_LIMIT	浼氳瀹ょ敵璇锋椂闂撮檺鍒� 娌℃湁瀛楁
                fse.getString("apply_time_limit");
                //ENABLED_TIME	鍚敤鏃堕棿
                String enabled_time = fse.getString("enabled_time");
                fieldSet.setValue("available_start_time",enabled_time);
                //鍚敤鏃堕棿
                fieldSet.setValue("enabled_time",enabled_time);
                //EQUIPMENT	閰嶇疆淇℃伅
                fieldSet.setValue("equipment",fse.getString("equipment"));
                //ID	椤哄簭鍙�                id 涓婚敭
                String id = fse.getString("id");
                fieldSet.setValue("id",id);
                //RECORDED_DATE	褰曞叆鏃堕棿    鍒涘缓鏃堕棿
                fieldSet.setValue("created_utc_datetime",fse.getString("recorded_date"));
                //RECORDED_MAN	褰曞叆浜� created_by 鍒涘缓浜�
                fieldSet.setValue("created_by",recorded_man);
                //REMARK	澶囨敞  remark 澶囨敞
                fieldSet.setValue("remark",fse.getString("remark"));
                //ROOMNAME	浼氳瀹ゅ悕                 room_name 浼氳瀹ゅ悕绉�
                fieldSet.setValue("room_name",fse.getString("roomname"));
                //SEATS	搴т綅鏁�
                fieldSet.setValue("seats",fse.getString("seats"));
                //STATUS	浼氳瀹ょ姸鎬�
                int statusNum = 0;
                if("鍚敤".equals(fse.getString("status"))){
                    statusNum = 1;
                }
                fieldSet.setValue("status",statusNum);
                FieldSetEntity staff = (FieldSetEntity)userIdStaffFse.get(recorded_man);
                //org_level_uuid 鎵€灞炲叕鍙�
                fieldSet.setValue("org_level_uuid", staff.getString("org_level_uuid"));
                //available_end_time 鍚敤缁撴潫鏃堕棿
                String uuid = baseDao.add(fieldSet);
                map.put(id,uuid);

            }
        }
        return map;
    }

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

        Map<String, Integer> meetintTypeMap = Maps.newHashMap();
        meetintTypeMap.put("鍛ㄤ緥浼�", 1);
        meetintTypeMap.put("鍗忚皟浼�", 2);
        meetintTypeMap.put("搴ц皥浼�", 3);
        meetintTypeMap.put("鍩硅", 4);
        meetintTypeMap.put("渚嬩細", 5);
        meetintTypeMap.put("鐮旇浼�", 6);
        meetintTypeMap.put("娌熼€氫細", 7);
        meetintTypeMap.put("灞€鍔′細", 8);
        meetintTypeMap.put("寰佹眰鎰忚浼�", 9);
        meetintTypeMap.put("宸ヤ綔娲借皥浼�", 10);
        meetintTypeMap.put("椤圭洰瀵规帴浼�", 11);
        meetintTypeMap.put("鎷嗚縼绾犵悍鍗忚皟浼�", 12);
        meetintTypeMap.put("璁ㄨ", 13);
        meetintTypeMap.put("鐗╀笟绠$悊", 14);
        meetintTypeMap.put("鐪佸甯傝€冩牳", 15);
        meetintTypeMap.put("瀹夋帓宸ヤ綔", 16);
        meetintTypeMap.put("鍒涘煄鍗婂勾鐫f煡", 17);
        meetintTypeMap.put("涓庨儜宸炲競寰佹敹鍔炲伐浣滀氦娴佸骇璋�", 18);
        meetintTypeMap.put("淇¤宸ヤ綔浼氳", 19);
        meetintTypeMap.put("涓氬姟璁ㄨ", 20);
        meetintTypeMap.put("鍓嶆湡鐗╀笟鎷涙姇鏍�", 21);
        meetintTypeMap.put("浼氳銆佸涔�", 22);
        meetintTypeMap.put("浜ゅ姙浼�", 23);
        meetintTypeMap.put("瀹¤姹囨€�", 24);
        meetintTypeMap.put("鐗╀笟浼佷笟鏄熺骇鏈嶅姟搴ц皥浼�", 25);

        if(!BaseUtil.dataTableIsEmpty(meetingDt)){
            DataTableEntity dataTableEntity = new DataTableEntity();
            FieldMetaEntity f = new FieldMetaEntity();
            f.setTableName(new String[]{"product_oa_conference_apply"});
            dataTableEntity.setMeta(f);
            for (int i = 0; i < meetingDt.getRows(); i++) {
              FieldSetEntity fse = meetingDt.getFieldSetEntity(i);
              FieldSetEntity applyFse = new FieldSetEntity();
                applyFse.setTableName("product_oa_conference_apply");
                //闄勪欢
                String annex = fse.getString("annex");
                //濡傛灉闄勪欢瀛楁鏈夊€�  鍚屾闄勪欢
                if(!BaseUtil.strIsNull(annex)){
                    List<String> fileUuids = this.synchronizeCommonAccessories(conn, "attachment", "product_oa_conference_apply", annex);
                    //瀛樺叆闄勪欢uuid
                    applyFse.setValue("attachment", StringUtils.join(fileUuids, ","));
                }
                //participator	鍙傚姞鑰�
                String attendee = fse.getString("attendee");
                applyFse.setValue("participator",this.getUserIds(conn, attendee));
                //浼氳绠€瑕� 浼氳绾
                applyFse.setValue("meeting_minutes", fse.getString("cotent"));
                //缁撴潫鏃堕棿   	缁撴潫鏃堕棿
                applyFse.setValue("end_time", fse.getString("end_date"));
                //閫佸鏍囧織  	娴佺▼閫佸姙榛樿瀛楁锛�0-寰呭彂锛�1-鍦ㄥ姙锛�2-鍔炵粨
                applyFse.setValue("flow_flag", fse.getString("flag"));
                //椤哄簭鍙� id	涓婚敭
                String id = fse.getString("id");
                applyFse.setValue("id",id);
                //鍒涘缓浜�
                String userId = userIdJson.getString(fse.getString("recorded_man"));
                if(BaseUtil.strIsNull(userId)){
                    continue;
                }
                //鎵€灞為儴闂� 鏆傛棤瀛楁 鍙栧綋鍓嶄汉閮ㄩ棬
                FieldSetEntity staff = (FieldSetEntity)this.userIdStaffFse.get(userId);
                String id01 = fse.getString("id01");
                String dept_uuid  = groupJson.getString(id01);
                if(BaseUtil.strIsNull(dept_uuid)){
                    dept_uuid = staff.getString("dept_uuid");
                }
                //閮ㄩ棬uuid
                applyFse.setValue("dept_uuid", dept_uuid);
                //鐢宠浜�  	鍒涘缓浜�
                applyFse.setValue("created_by", userId);
                //澶栨潵鍙備細浜哄憳 鏆傛棤瀛楁
                applyFse.setValue("exotic_staff", fse.getString("id03"));
                //鐢宠浜篿d02
                applyFse.setValue("apply_user", userIdJson.getString(fse.getString("id02")));
                //涓绘寔浜� record_master 涓绘寔浜�
                applyFse.setValue("record_master", userIdJson.getString(fse.getString("meeting_master")));
                //浼氳瀹�
                applyFse.setValue("meeting_room",map.get(fse.getString("meeting_room")));
                //浼氳绫诲瀷 鏆傛棤瀛楁 缁勫悎涓哄弬鐓�
                applyFse.setValue("meetint_type", meetintTypeMap.get(fse.getString("meetint_type")));
                //褰曞叆鏃堕棿 created_utc_datetime	鍒涘缓鏃堕棿
                applyFse.setValue("created_utc_datetime", fse.getString("recorded_date"));
                //浼氳璁板綍浜� 璁板綍浜�
                applyFse.setValue("record_man",userIdJson.getString(fse.getString("record_man")));
                //鎻愰啋鏃堕棿  reminder_time	鎻愰啋鏃堕棿
                applyFse.setValue("reminder_time", fse.getString("remind_time"));
                //闇€瑕佽祫婧�
                applyFse.setValue("meeting_resource", fse.getString("res"));
                //寮€濮嬫椂闂�
                applyFse.setValue("start_time", fse.getString("start_date"));
                //浼氳鐘舵€� 0銆佸緟鍙� 1銆佸凡鍙�
                applyFse.setValue("status",fse.getString("status"));
                //浼氳涓婚
                applyFse.setValue("meeting_topic",fse.getString("topics"));
                //鎵€灞炲叕鍙�
                applyFse.setValue("org_level_uuid",staff.getString("org_level_uuid"));
                String uuid = baseDao.add(applyFse);
                pxMap.put("BS_MEETING_FLOW"+id,uuid);
            }

        }
    }



    //鍚屾鍗忓悓鍔炲叕
    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, " SELECT  A.*,(SELECT COUNT(*) FROM FE_BASE5.SYS_ATTACHMENT WHERE SA01 = A.RELATIONFLOW) AS FLOWS FROM FE_BASE5.SYS_COLLABORATIVE A ", new Object[]{});
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            throw e;
        }
        DataTableEntity accessoryData = this.getTableNameAttachment(conn, tableName);
        try {
            //鑾峰彇鎵╁睍娑堟伅
            DataTableEntity ideamanageDt = BaseDaoServiceImpl.getDataTable(conn, "SELECT * FROM FE_BASE5.IDEAMANAGE ORDER BY ID06", new Object[]{});
            Map<String, DataTableEntity> dataMap = Maps.newHashMap();
            for (int i = 0; i < ideamanageDt.getRows(); i++) {
                FieldSetEntity fse = ideamanageDt.getFieldSetEntity(i);
                String id06 = fse.getString("id06");
                DataTableEntity dataTableEntity1 = dataMap.get(id06);
                if(BaseUtil.dataTableIsEmpty(dataTableEntity1)){
                    DataTableEntity dataTableEntity2 = new DataTableEntity();
                    dataTableEntity2.addFieldSetEntity(fse);
                    dataMap.put(id06, dataTableEntity2);
                }else {
                    dataTableEntity1.addFieldSetEntity(fse);
                }
            }
            Map<String, FieldSetEntity> ccooperatesMaps = Maps.newHashMap();
            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", this.emergencyDegreeType(important));
            } else {
                //涓虹┖灏辨斁0
                fs.setValue("emergency_degree", 1);
            }
            //闄勪欢hiddenidea
            // fs.setValue("attachment",);
            //鍙戣捣鏃堕棿
            String stime = feFs.getString("stime");
            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.宸插彂锛�
             Integer spflag = feFs.getInteger("spflag");
            fs.setValue("status", (spflag == 0)?0:1);
            String sman = this.userIdJson.getString(feFs.getString("sman"));
            if(BaseUtil.strIsNull(sman)){
                continue;
            }
            //鏄惁鍏佽杞偖浠�
            fs.setValue("is_transfer_mail", 0);
            fs.setValue("created_by",sman);
            fs.setValue("created_utc_datetime", stime);
            Map<String, List<String>> fileMaps = this.synchronizationAttachments(conn, accessoryData, feFs, fs.getTableName(), "attachment");
            List<String> value = fileMaps.get("attachment");
            //瀛樺叆闄勪欢uuid
            fs.setValue("attachment", StringUtils.join(value, ","));
            String uuid = baseDao.add(fs);
            //淇濆瓨涓氬姟鏁版嵁id 涓庢湰琛╱uid
            String id = feFs.getString("id");
            pxMap.put("SYS_COLLABORATIVE" + id, uuid);
            ccooperatesMaps.put(id,fs);
            //鍚屾姝f枃琛ュ厖
            this.synchronizeTextSupplement(conn, id, uuid);
            String flowcode  = feFs.getString("flowcode");
            if(BaseUtil.strIsNull(flowcode)) {
                //铏氭嫙涓€涓妭鐐�
                FieldSetEntity subfse = new FieldSetEntity();
                //婧愯〃鍚�
                subfse.setTableName("product_oa_cooperate_flow_node");
                //鍔炵悊浜哄眰绾�
                subfse.setValue("grade", 1);
                //鍏宠仈鍗忓悓琛╱uid
                subfse.setValue("cooperate_uuid", uuid);
                //鎺ユ敹浜篒d
                subfse.setValue("receiver", sman);
                //鎺ユ敹浜哄鍚�
                FieldSetEntity staffFse = (FieldSetEntity)userIdStaffFse.get(sman);
                String show_name = staffFse.getString("show_name");
                subfse.setValue("receiver_name",show_name);
                //0:鏆傚瓨 1:鍔犵 2:杞彂 3:閫€鍥�4:閫佸姙 5:缁堟 6:鎾ら攢
                subfse.setValue("type", 0);
                subfse.setValue("sender", sman);
                subfse.setValue("sender_name", null);
                subfse.setValue("tricode",null);
                baseDao.add(subfse);
                //铏氭嫙涓€涓妭鐐�
                FieldSetEntity subfse2 = new FieldSetEntity();
                //婧愯〃鍚�
                subfse2.setTableName("product_oa_cooperate_flow_node");
                //鍔炵悊浜哄眰绾�
                subfse2.setValue("grade", 2);
                //鍏宠仈鍗忓悓琛╱uid
                subfse2.setValue("cooperate_uuid", uuid);
                //鎺ユ敹浜篒d
                subfse2.setValue("receiver", sman);
                //鎺ユ敹浜哄鍚�
                subfse2.setValue("receiver_name", show_name);
                //0:鏆傚瓨 1:鍔犵 2:杞彂 3:閫€鍥�4:閫佸姙 5:缁堟 6:鎾ら攢
                subfse2.setValue("type", 0);
                subfse2.setValue("sender", sman);
                subfse2.setValue("sender_name", show_name);
                subfse2.setValue("tricode",sman);
                baseDao.add(subfse2);
                continue;
            }
            //鍚屾鍗忓悓娴佺▼
            this.synchronousCooperator(conn, flowcode, uuid);
            //鍚屾infor
            DataTableEntity ccooperatesInforDt = null;
            ccooperatesInforDt = BaseDaoServiceImpl.getDataTable(conn, "SELECT * FROM FE_BASE5.WF_INFOR WHERE WI29 = ? AND WI28 = 'SYS_COLLABORATIVE' ORDER BY WI00",  new Object[]{id});
            Map<String, String[]> stateMap = this.syncCcooperatesInforDt(conn, ccooperatesInforDt, uuid, dataMap);
            //鍚屾娑堟伅
                if(stateMap != null && stateMap.size() > 0){
                    this.syncCollaborativeNews(conn, id, stateMap);
                }
            }
            //鍚屾鍏宠仈浜嬮」  淇敼鍗忓悓鏁版嵁
            //鑾峰彇鍏宠仈浜嬮」鐨勫崗鍚�
            DataTableEntity relevanceTask = BaseDaoServiceImpl.getDataTable(conn, "SELECT * FROM FE_BASE5.WF_TASK WHERE WT03 = 'SYS_COLLABORATIVE'", new Object[]{});
            Map<String, FieldSetEntity> task_maps = Maps.newHashMap();
            for (int i = 0; i < relevanceTask.getRows(); i++) {
                task_maps.put(relevanceTask.getString(i, "wt00"), relevanceTask.getFieldSetEntity(i));
            }
            //鑾峰彇宸插悓姝ユ祦绋媡ask鐨勫叧鑱斾簨椤�
            DataTableEntity flow_task = baseDao.listTable("select * from product_sys_flow_task", new String[]{});
            Map<String, FieldSetEntity> flow_task_maps = Maps.newHashMap();
            for (int i = 0; i < flow_task.getRows(); i++) {
                //k涓哄師 taskId
                flow_task_maps.put(flow_task.getString(i, "id"), flow_task.getFieldSetEntity(i));
            }
            for (int i = 0; i < ccooperatesDt.getRows(); i++) {
                Integer flows = ccooperatesDt.getInt(i,"flows");
                //鏈夊叧鑱斾簨椤�
                if (flows > 0) {
                    String relationflow = ccooperatesDt.getString(i,"relationflow");
                    String id = ccooperatesDt.getString(i,"id");
                    DataTableEntity relationflowData = BaseDaoServiceImpl.getDataTable(conn, "SELECT * FROM FE_BASE5.SYS_ATTACHMENT WHERE SA01 = ?", new Object[]{relationflow});
                    JSONArray relationJson = new JSONArray();
                    if (!BaseUtil.dataTableIsEmpty(relationflowData)) {
                        for (int j = 0; j < relationflowData.getRows(); j++) {
                            String sa02 = relationflowData.getString(j, "sa02");
                            //鏈簱娴佺▼task鏁版嵁
                            FieldSetEntity fse = flow_task_maps.get(sa02);
                            if(fse != null){
                                JSONObject relationObject = new JSONObject();
                                String uuid = fse.getUUID();
                                String title = fse.getString("title");
                                relationObject.put("type", 0);
                                relationObject.put("uuid", uuid);
                                relationObject.put("label", title);
                                relationJson.add(relationObject);
                            }
                            //鍗忓悓婧愭暟鎹�
                            FieldSetEntity fse2 = task_maps.get(sa02);
                            if(fse2 != null){
                                JSONObject relationObject = new JSONObject();
                                String wt04 = fse2.getString("wt04");
                                FieldSetEntity fieldSetEntity = ccooperatesMaps.get(wt04);
                                if(fieldSetEntity != null){
                                    String uuid = fieldSetEntity.getUUID();
                                    String title = fieldSetEntity.getString("title");
                                    relationObject.put("type", 1);
                                    relationObject.put("uuid", uuid);
                                    relationObject.put("label", title);
                                    relationJson.add(relationObject);
                                }
                            }
                        }
                        if(relationJson.size() > 0){
                            FieldSetEntity updateFse = ccooperatesMaps.get(id);
                            if(updateFse != null){
                                updateFse.setValue("related_items", relationJson.toString());
                                baseDao.update(updateFse);
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            e.getStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
        }
    }

    /**
     * 鍚屾鍗忓悓姝f枃琛ュ厖
     */
    public void synchronizeTextSupplement(Connection conn,String id, String cooperate_uuid)throws Exception{
        try {
            DataTableEntity dataTable = BaseDaoServiceImpl.getDataTable(conn, "SELECT * FROM FE_BASE5.WF_DOC_ADDITIONAL WHERE WDA05 = (SELECT WT00 FROM FE_BASE5.WF_TASK WHERE WT04 = ? AND WT03 = 'SYS_COLLABORATIVE')",  new Object[]{id});
            DataTableEntity cooperate_sub = new DataTableEntity();
            FieldMetaEntity f = new FieldMetaEntity();
            f.setTableName(new String[]{"product_oa_cooperate_sub"});
            cooperate_sub.setMeta(f);
            if(!BaseUtil.dataTableIsEmpty(dataTable)){
                DataTableEntity accessoryData = this.getTableNameAttachment(conn, "FE_BASE5.WF_DOC_ADDITIONAL");
                for (int i = 0; i < dataTable.getRows(); i++) {
                  FieldSetEntity fse = dataTable.getFieldSetEntity(i);
                  FieldSetEntity fieldSetEntity = new FieldSetEntity();
                    fieldSetEntity.setTableName("product_oa_cooperate_sub");
                    //鍐呭
                    String wda02 = fse.getString("wda02");
                    if(BaseUtil.strIsNull(wda02)){
                        wda02 = "绌�";
                    }
                    fieldSetEntity.setValue("contents", wda02);
//                    attachment	闄勪欢
                    Map<String, List<String>> fileMaps = this.synchronizationAttachments(conn, accessoryData, fse, fieldSetEntity.getTableName(), "attachment");
                    List<String> value = fileMaps.get("attachment");
                    //瀛樺叆闄勪欢uuid
                    fieldSetEntity.setValue("attachment", StringUtils.join(value, ","));
                    //涓昏〃uuid
                    fieldSetEntity.setValue("cooperate_uuid", cooperate_uuid);
                    String user_id = userIdJson.getString(fse.getString("wda01"));
                    if(BaseUtil.strIsNull(user_id)){
                        continue;
                    }
                    //鍒涘缓浜�
                    fieldSetEntity.setValue("created_by",user_id);
                    //鍒涘缓鏃堕棿
                    fieldSetEntity.setValue("created_utc_datetime", fse.getString("wda04"));
                    cooperate_sub.addFieldSetEntity(fieldSetEntity);
                }
                baseDao.add(cooperate_sub);
            }
        } catch (Exception e) {
                DataManipulationUtils.close(null, null, conn);
                e.getStackTrace();
                SpringMVCContextHolder.getSystemLogger().error(e);
        }
    }

    /**
     * 鍚屾鍗忓悓妯℃澘
     */
    public void syncCollaborativeTemplate(Connection conn) throws SQLException {
        try {
            DataTableEntity dataTable = BaseDaoServiceImpl.getDataTable(conn, "SELECT * FROM FE_BASE5.SYS_COLLABORATIVE_MOUDLE  WHERE COL_MDL_CONTENT_TYPE = 0", new Object[]{});
            if(!BaseUtil.dataTableIsEmpty(dataTable)){
                for (int i = 0; i < dataTable.getRows(); i++) {
                  FieldSetEntity fse = dataTable.getFieldSetEntity(i);
                  FieldSetEntity newFse = new FieldSetEntity();
                    newFse.setTableName("product_oa_cooperates_template");
                    //妯℃澘鍚嶇О 涔熶负鍗忓悓鍚嶇О
                    newFse.setValue("name",fse.getString("col_mdl_name"));
                    //鍒涘缓浜�
                    String col_mdl_userid = fse.getString("col_mdl_userid");
                    String user_id = "";
                    //鍒涘缓鏃堕棿
                    String created_time = fse.getString("col_mdl_time");
                    //鍏叡妯℃澘
                    if("1".equals(col_mdl_userid)){
                        newFse.setValue(CmnConst.CREATED_BY,1);
                        //鍒涘缓鏃堕棿
                        newFse.setValue(CmnConst.CREATED_UTC_DATETIME,created_time);
                        //妯℃澘html鍐呭
                        newFse.setValue("content",fse.getString("col_mdl_content"));
                        baseDao.add(newFse);
                    }else {
                         user_id = userIdJson.getString(col_mdl_userid);
                        if(BaseUtil.strIsNull(user_id)){
                            continue;
                        }
                        newFse.setValue(CmnConst.CREATED_BY,user_id);
                        newFse.setValue(CmnConst.CREATED_UTC_DATETIME,created_time);
                        //妯℃澘html鍐呭
                        newFse.setValue("content",fse.getString("col_mdl_content"));
                        //鍏变韩浜哄憳1 閮ㄩ棬2 宀椾綅3
                        String col_mdl_sharers = fse.getString("col_mdl_sharers");
                            if(!BaseUtil.strIsNull(col_mdl_sharers)){
                                Set<String> userSet = Sets.newHashSet();
                                String[] sharers = col_mdl_sharers.split(",");
                                for (int j = 0; j < sharers.length; j++) {
                                  String srt = sharers[j];
                                //浜哄憳
                                if(srt.contains("^_^1^_^")){
                                    String userId = srt.substring(0,srt.indexOf("^_^1^_^"));
                                    userId = userIdJson.getString(userId);
                                    if(!BaseUtil.strIsNull(userId)){
                                        userSet.add(userId);
                                    }
                                    //閮ㄩ棬鍗曚綅
                                }else if(srt.contains("^_^2^_^")){
                                    String levelId = srt.substring(0,srt.indexOf("^_^2^_^"));
                                    String deptUuid = groupJson.getString(levelId);
                                    DataTableEntity staffData = null;
                                    if(BaseUtil.strIsNull(deptUuid)){
                                        deptUuid = orgLevelJson.getString(levelId);
                                        if(!BaseUtil.strIsNull(deptUuid)){
                                            staffData = baseDao.listTable(CmnConst.PRODUCT_SYS_STAFFS, " org_level_uuid = ? ", new String[]{deptUuid});
                                        }
                                    }else {
                                        staffData = baseDao.listTable(CmnConst.PRODUCT_SYS_STAFFS, " dept_uuid = ? or org_level_uuid = ? ", new String[]{deptUuid,deptUuid});
                                    }
                                    if(!BaseUtil.dataTableIsEmpty(staffData)){
                                        for (int k = 0; k < staffData.getRows(); k++) {
                                            userSet.add(staffData.getString(k, "user_id"));
                                        }
                                    }
                                    //宀椾綅
                                }else if(srt.contains("^_^3^_^")){
                                    String postId = srt.substring(0,srt.indexOf("_|"));
                                    String postUuid = postJson.getString(postId);
                                   DataTableEntity staffData = baseDao.listTable(CmnConst.PRODUCT_SYS_STAFFS, " job_post_uuid = ? ", new String[]{postUuid});
                                    if(!BaseUtil.dataTableIsEmpty(staffData)){
                                        for (int k = 0; k < staffData.getRows(); k++) {
                                            userSet.add(staffData.getString(k, "user_id"));
                                        }
                                    }
                                }
                            }
                            if(userSet.size() > 0) {
                                //瑙f瀽骞跺瓨鍏ョ敤鎴�
                                newFse.setValue("share_user",StringUtils.join(userSet, ","));
                            }
                        }
                        String uuid = baseDao.add(newFse);
                        //鍏宠仈娴佺▼code
                        String col_mdl_flowcode = fse.getString("col_mdl_flowcode");
                        FieldSetEntity staffFse = (FieldSetEntity)userIdStaffFse.get(user_id);
                        String org_level_uuid = staffFse.getString("org_level_uuid");
                        if(!BaseUtil.strIsNull(col_mdl_flowcode) && !BaseUtil.strIsNull(org_level_uuid)){
                            //鍚屾鍗忓悓妯℃澘娴佺▼
                            this.synchronousTemplateCooperator(conn, col_mdl_flowcode, uuid, user_id, created_time, org_level_uuid);
                        }
                    }

                }
            }
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            e.getStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
        }
    }

    /**
     * 鍚屾鍗忓悓妯℃澘浜哄憳 宀椾綅 鏈烘瀯
     * @param conn jdbc杩炴帴
     * @param flowCode 娴佺▼鑺傜偣鏍囪瘑
     * @param uuid 鍗忓悓uuid
     * @return
     */
    public DataTableEntity synchronousTemplateCooperator(Connection conn, String flowCode, String uuid, String user_id, String created_time, String org_level_uuid) throws SQLException {
        DataTableEntity coNodeData = null;
        try {
            //flowcode 娴佺▼鏍囪瘑瀛楁
            coNodeData = BaseDaoServiceImpl.getDataTable(conn, "SELECT * FROM FE_BASE5.WF_CO_NODE WHERE MGUID = ? ORDER BY CREATETIME",  new Object[]{flowCode});

        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            throw e;
        }
        if(!BaseUtil.dataTableIsEmpty(coNodeData)) {
            FieldSetEntity fieldSetEntity = coNodeData.getFieldSetEntity(0);
            coNodeData.removeFieldSetEntity(0);
            DataTableEntity dataTable = new DataTableEntity();
            FieldMetaEntity f = new FieldMetaEntity();
            f.setTableName(new String[]{"product_oa_cooperate_flow_node_template"});
            dataTable.setMeta(f);
            String userId = userIdJson.getString(fieldSetEntity.getString("value"));
            if (BaseUtil.strIsNull(userId)) {
                return null;
            }
            FieldSetEntity subfse = new FieldSetEntity();
            //婧愯〃鍚�
            subfse.setTableName("product_oa_cooperate_flow_node_template");
            //鍔炵悊浜哄眰绾�
            subfse.setValue("grade", 1);
            //鍏宠仈鍗忓悓妯℃澘琛╱uid
            subfse.setValue("master_uuid", uuid);
            //鎺ユ敹浜篒d
            subfse.setValue("receiver", userId);
            subfse.setValue("sender", null);
            subfse.setValue("tricode",null);
            subfse.setValue("org_level_uuid", org_level_uuid);
            subfse.setValue(CmnConst.CREATED_BY, user_id);
            subfse.setValue(CmnConst.CREATED_UTC_DATETIME, created_time);
            dataTable.addFieldSetEntity(subfse);
            try {
                this.saveTemplateReceiver(fieldSetEntity, coNodeData, uuid, null, dataTable,2,user_id, created_time, org_level_uuid);
                baseDao.add(dataTable);
            }catch (Exception e){
                e.printStackTrace();
            }
            return dataTable;
        }
        return null;
    }

    /**
     * 閫掑綊寰幆鍚屾妯℃澘浜哄憳 閮ㄩ棬宀椾綅 鏁版嵁
     * @param fse 鍙戦€佷汉fse
     * @param dataTableEntity 鍓╀綑浜篋ata
     */
    private void saveTemplateReceiver(FieldSetEntity fse, DataTableEntity dataTableEntity, String uuid,String tricode, DataTableEntity dataTable, Integer grade,String user_id, String created_time, String org_level_uuid)throws Exception{
        DataTableEntity dataTableEntity1 = new DataTableEntity();
        DataTableEntity dataTableEntity2 = new DataTableEntity();
        String sender = "";
        //鍙戦€佺被鍨�
        String type2 = fse.getString("type");
        if("1".equals(type2)){
            sender = userIdJson.getString(fse.getString("value"));
            if(BaseUtil.strIsNull(sender)){
                return;
            }
        }
        for (int i = 0; i < dataTableEntity.getRows(); i++) {
            FieldSetEntity fieldSetEntity = dataTableEntity.getFieldSetEntity(i);
            String guid = fse.getString("guid");
            String parentguid = fieldSetEntity.getString("parentguid");
            if(guid.equals(parentguid)){
                dataTableEntity1.addFieldSetEntity(fieldSetEntity);
                FieldSetEntity subfs = new FieldSetEntity();
                //鍗忓悓鍔炲叕娴佺▼琛�
                subfs.setTableName("product_oa_cooperate_flow_node_template");
                subfs.setValue("grade", grade);
                //鍏宠仈鍗忓悓琛╱uid
                subfs.setValue("master_uuid", uuid);
                //鎺ユ敹浜猴紙鍏宠仈鐢ㄦ埛琛╥d锛�  鎺ユ敹浜轰竴浣嗘槸鏈烘瀯鎴栭儴闂ㄨ妭鐐�   閭e氨鏄渶鍚庤妭鐐�
                String type = fieldSetEntity.getString("type");
                //鍙戦€佷汉id
                subfs.setValue("sender", sender);
                //浜哄憳
                if("1".equals(type)){
                    String userId = userIdJson.getString(fieldSetEntity.getString("value"));
                    if(BaseUtil.strIsNull(userId)){
                        continue;
                    }
                    subfs.setValue("receiver", userId);
                    //鑻ヤ负閮ㄩ棬鍏徃
                }else if("2".equals(type)){
                    String orgUuid = orgLevelJson.getString(fieldSetEntity.getString("value"));
                    if(BaseUtil.strIsNull(orgUuid)){
                        continue;
                    }
                    if(!BaseUtil.strIsNull(orgUuid)){
                        DataTableEntity staff = baseDao.listTable(" product_sys_staffs ", " dept_uuid = ? ", new String[]{orgUuid});
                        if(BaseUtil.dataTableIsEmpty(staff)){
                            staff = baseDao.listTable(" product_sys_staffs ", " org_level_uuid = ? ", new String[]{orgUuid});
                        }
                        if(!BaseUtil.dataTableIsEmpty(staff)) {
                            tricode = dataTable.getString(dataTable.getRows()-1, "tricode");
                            if(BaseUtil.strIsNull(tricode)){
                                tricode = dataTable.getString(dataTable.getRows()-1, "receiver");
                            }
                            this.addUserTemplateFlowNode(staff, grade, uuid, tricode,sender,dataTable,user_id,created_time, org_level_uuid);
                        }
                        continue;
                    }
                    //宀椾綅
                }else if("3".equals(type)){
                    String postUuid = postJson.getString(fieldSetEntity.getString("value"));
                    if(BaseUtil.strIsNull(postUuid)){
                        continue;
                    }
                    if(!BaseUtil.strIsNull(postUuid)){
                        DataTableEntity staff = baseDao.listTable(" product_sys_staffs ", " job_post_uuid = ? ", new String[]{postUuid});
                        if(!BaseUtil.dataTableIsEmpty(staff)) {
                            tricode = dataTable.getString(dataTable.getRows()-1, "tricode");
                            if(BaseUtil.strIsNull(tricode)){
                                tricode = dataTable.getString(dataTable.getRows()-1, "receiver");
                            }
                            this.addUserTemplateFlowNode(staff, grade, uuid,  tricode,sender,dataTable,user_id,created_time, org_level_uuid);
                        }
                        continue;
                    }
                }
                //triCode
                if(BaseUtil.strIsNull(tricode)){
                    subfs.setValue("tricode",sender);
                    fieldSetEntity.setValue("tricode",sender);
                }else {
                    subfs.setValue("tricode",tricode + "-" + sender);
                    fieldSetEntity.setValue("tricode",tricode + "-" + sender);
                }

                //鍏徃uuid
                subfs.setValue("org_level_uuid", org_level_uuid);
                //鍒涘缓浜�
                subfs.setValue(CmnConst.CREATED_BY, user_id);
                //鍒涘缓鏃堕棿
                subfs.setValue(CmnConst.CREATED_UTC_DATETIME, created_time);
                dataTable.addFieldSetEntity(subfs);
            }else {
                dataTableEntity2.addFieldSetEntity(fieldSetEntity);
            }
        }

        //鍔炵悊浜哄眰绾�
        grade++;
        if(!BaseUtil.dataTableIsEmpty(dataTableEntity1) && !BaseUtil.dataTableIsEmpty(dataTableEntity2)) {
            for (int i = 0; i < dataTableEntity1.getRows(); i++) {
                this.saveTemplateReceiver(dataTableEntity1.getFieldSetEntity(i) ,dataTableEntity2, uuid, dataTableEntity1.getString(i, "tricode"),dataTable,grade, user_id, created_time, org_level_uuid);
            }
        }
    }

    /**
     * 瑙f瀽鍚屾鐨勫矖浣嶉儴闂� 瑙f瀽涓轰汉鍐嶆壒閲忎繚瀛�
     * @param staff 閫氳繃閮ㄩ棬宀椾綅  鏌ヨ鍑烘潵鐨勭敤鎴锋暟鎹�
     * @param grade 灞傜骇
     * @param uuid 涓昏〃uuid
     * @param tricode 鏈骇code
     * @param user_id 鍙戦€佷汉user_id
     */
    public void addUserTemplateFlowNode(DataTableEntity staff, Integer grade, String uuid, String tricode, String user_id,DataTableEntity data, String created_by, String created_time, String org_level_uuid){
        for (int f = 0; f < staff.getRows(); f++) {
            FieldSetEntity subfse = new FieldSetEntity();
            //婧愯〃鍚�
            subfse.setTableName("product_oa_cooperate_flow_node_template");
            //鍔炵悊浜哄眰绾�
            subfse.setValue("grade", grade);
            //鍏宠仈鍗忓悓琛╱uid
            subfse.setValue("master_uuid", uuid);
            //鎺ユ敹浜篿d
            subfse.setValue("receiver", staff.getString(f,"user_id"));
            //code
            subfse.setValue("tricode", tricode);
            //鍙戦€佷汉id
            subfse.setValue("sender", user_id);
            subfse.setValue(CmnConst.CREATED_BY, created_by);
            subfse.setValue(CmnConst.CREATED_UTC_DATETIME, created_time);
            data.addFieldSetEntity(subfse);
        }
    }

    /**
     * 鍚屾鍗忓悓娑堟伅
     * @param conn jdbc杩炴帴
     * @param id 鍗忓悓鏁版嵁id
     * @throws SQLException
     */
    public void syncCollaborativeNews(Connection conn, String id,  Map<String, String[]> stateMap) throws SQLException {
        try {
            DataTableEntity collaborativeNews = BaseDaoServiceImpl.getDataTable(conn, "SELECT * FROM FE_BASE5.MESSAGEINFOR WHERE ME14 IN ( SELECT WI00 FROM FE_BASE5.WF_INFOR WHERE  WI29 = ? AND WI28 = 'SYS_COLLABORATIVE' AND WI13 = 0 ) ORDER BY ME14",  new Object[]{id});
            if(!BaseUtil.dataTableIsEmpty(collaborativeNews)) {
                this.syncCollaborativeNews(collaborativeNews, stateMap, "product_oa_cooperates");
            }
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            e.getStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
        }

    }

    /**
     *     鍚屾鍗忓悓娴佺▼娑堟伅琛�
     */
    public void syncCollaborativeNews(DataTableEntity OrlDt, Map<String, String[]> stateMap, String tableName){
        String id = null;
        String message_uuid = null;
        String[] state = null;
        DataTableEntity dataTableEntity = new DataTableEntity();
        FieldMetaEntity f = new FieldMetaEntity();
        f.setTableName(new String[]{"product_sys_message_user"});
        dataTableEntity.setMeta(f);
        for (int i = 0; i < OrlDt.getRows(); i++) {
            FieldSetEntity fs = OrlDt.getFieldSetEntity(i);
            //娴佺▼鑺傜偣id
            String me14 = fs.getString("me14");
            //鑾峰彇褰撳墠鑺傜偣鐘舵€�
            state = stateMap.get(me14);
            if(state == null){
                continue;
            }
            String sendUserId;
            //鐩稿悓璇存槑鏄悓涓€娑堟伅  鍙戦€佸涓汉
            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涓鸿鍔�
                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  = state[2];
                    if(BaseUtil.strIsNull(sendUserId)){
                        continue;
                    }
                }
                message.setValue("send_user_id", sendUserId);
                //鍒涘缓浜哄強鍙戦€佷汉
                message.setValue("created_by", sendUserId);
                //	涓氬姟琛�
                message.setValue("source_table", tableName);
                //url 涓氬姟鍦板潃

                message.setValue("source_uuid", state[3]);

                //鏌ョ湅璇︽儏
                message.setValue("url", state[1]);
                message_uuid = baseDao.add(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[0])){
                message_user.setValue("read_type", 0);
            }else {
                message_user.setValue("read_type", 1);
            }
            //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);
            dataTableEntity.addFieldSetEntity(message_user);
        }
        baseDao.add(dataTableEntity);
    }

    /**
     * 鍚屾鍗忓悓鐣欒█鏁版嵁
     * @param ccooperatesInforDt infor鏁版嵁uuid
     */
    public Map<String, String[]> syncCcooperatesInforDt(Connection conn, DataTableEntity ccooperatesInforDt, String uuid, Map<String, DataTableEntity> dataMap)throws Exception{
        Map<String, String[]> stateMap = Maps.newHashMap();
        for (int i = 0; i < ccooperatesInforDt.getRows(); i++) {
          FieldSetEntity inforFse = ccooperatesInforDt.getFieldSetEntity(i);
          String userId = userIdJson.getString(inforFse.getString("wi05"));
            //wi62 涓庤妭鐐硅〃parentguid瀵瑰簲
            DataTableEntity dataTableEntity = parentGuidData.get(inforFse.getString("wi62"));
            if(BaseUtil.dataTableIsEmpty(dataTableEntity) || BaseUtil.strIsNull(userId)){
                continue;
            }
            for (int j = 0; j < dataTableEntity.getRows(); j++) {
              FieldSetEntity fieldSetEntity = dataTableEntity.getFieldSetEntity(j);
                String receiver = fieldSetEntity.getString("receiver");
                fieldSetEntity.setValue("accept_time",inforFse.getString("wi08")); //鎺ユ敹鏃堕棿
                //鐩稿悓灏辨槸涓€涓汉 璧嬪姙鐞嗙姸鎬�  鍜岀暀瑷€
                if(userId.equals(receiver)){
                    String wi00 = inforFse.getString("wi00");
                    String nodeState = nodeDealType(inforFse.getString("wi13"));
                    fieldSetEntity.setValue("status", nodeState);
                    String wi20 = inforFse.getString("wi20");
                    //宸插姙娑堟伅  骞朵笖娑堟伅涓虹┖ 鍔犱笂宸查槄
                    if(BaseUtil.strIsNull(wi20) && "2".equals(nodeState)){
                        wi20 = "宸查槄";
                    }
                    //鐣欒█娑堟伅
                    fieldSetEntity.setValue("opinion", wi20);
                    fieldSetEntity.setValue("accept_time",inforFse.getString("wi08")); //鎺ユ敹鏃堕棿
                    fieldSetEntity.setValue("handle_time", inforFse.getString("wi11")); //澶勭悊鏃堕棿
                    String flow_node_uuid = fieldSetEntity.getUUID();
                    String created_by = userIdJson.getString(inforFse.getString("wi15"));
                    //鎵╁睍鐣欒█娑堟伅
                    String wi21 = inforFse.getString("wi21");
                    String attachmentsValue = inforFse.getString("attachment");
                    //濡傛灉闄勪欢瀛楁鏈夊€�  鍚屾闄勪欢
                    if(!BaseUtil.strIsNull(attachmentsValue)){
                        List<String> fileUuids = this.synchronizeCommonAccessories(conn, "attachments", "product_oa_cooperate_flow_node", attachmentsValue);
                        //瀛樺叆闄勪欢uuid
                        fieldSetEntity.setValue("attachments", StringUtils.join(fileUuids, ","));
                    }
                    String url = "1623059056339697NPbV881?uuid="+uuid+"&flow_node_uuid="+flow_node_uuid;
                    DataTableEntity dataTableEntity1 = dataMap.get(wi21);
                    stateMap.put(wi00,new String[] {nodeState,url,created_by,uuid});
                    //鏈夋墿灞曠暀瑷€
                    if(!BaseUtil.dataTableIsEmpty(dataTableEntity1)) {
                        for (int k = 0; k < dataTableEntity1.getRows(); k++) {
                            FieldSetEntity ideFse = dataTableEntity1.getFieldSetEntity(k);
                            //鍚屾闄勪欢
                            String id08 = ideFse.getString("id08");
                            String reply_attachment = null;
                            String id07 = ideFse.getString("id07");
                            //鍥炲鍐呭
                            String id04 = ideFse.getString("id04");
                            //鏈夐檮浠� 涓嶇瓑浜�0璇存槑鏈澶栫暀瑷€
                            if (!BaseUtil.strIsNull(id08) && !"0".equals(id07)) {
                                // reply_attachment	鍥炲闄勪欢锛屽叧鑱旈檮浠惰〃uuid
                                List<String> attachment = this.synchronizeCommonAccessories(conn, "reply_attachment", "product_oa_cooperate_flow_reply", id08);
                                reply_attachment = StringUtils.join(attachment, ",");
                                //绛変簬0璇存槑 涓哄鐞嗘暟鎹�
                            }else if(!BaseUtil.strIsNull(id08) && "0".equals(id07)){
                                List<String> attachment = this.synchronizeCommonAccessories(conn, "attachments", "product_oa_cooperate_flow_node", id08);
                                reply_attachment = StringUtils.join(attachment, ",");
                                fieldSetEntity.setValue("opinion", id04);
                                fieldSetEntity.setValue("attachments", reply_attachment);
                                continue;
                            }
                            FieldSetEntity flowReply = new FieldSetEntity();
                            flowReply.setTableName("product_oa_cooperate_flow_reply");

                            //鍏宠仈lx_oa_cooperate_flow_node琛╱uid
                            flowReply.setValue("parent_uuid", fieldSetEntity.getUUID());
                            //鍥炲鍐呭
                            flowReply.setValue("reply_content",id04);
                            //鍥炲鏃堕棿
                            flowReply.setValue("reply_datetime", ideFse.getString("id03"));
                            //鍥炲浜猴紝鍏宠仈user琛╥d
                            String user_id = userIdJson.getString(ideFse.getString("id02"));
                            if (BaseUtil.strIsNull(user_id)) {
                                continue;
                            }
                            //鍥炲浜猴紝鍏宠仈user琛╥d
                            flowReply.setValue("reply_user", user_id);
                            //涓婄骇id
                            flowReply.setValue("superior_id", ideFse.getString("id01"));
                            flowReply.setValue("reply_attachment", reply_attachment);
                            baseDao.add(flowReply);
                        }
                    }
                    baseDao.update(fieldSetEntity);
                }
            }
        }
        return stateMap;
    }

    /**
     * 鍚屾鍗忓悓浜哄憳 宀椾綅 鏈烘瀯
     * @param conn jdbc杩炴帴
     * @param flowCode 娴佺▼鑺傜偣鏍囪瘑
     * @param uuid 鍗忓悓uuid
     * @return
     */
    public DataTableEntity synchronousCooperator(Connection conn, String flowCode, String uuid) throws SQLException {
        DataTableEntity coNodeData = null;
        try {
            //flowcode 娴佺▼鏍囪瘑瀛楁
            coNodeData = BaseDaoServiceImpl.getDataTable(conn, "SELECT * FROM FE_BASE5.WF_CO_NODE WHERE MGUID = ? ORDER BY CREATETIME",  new Object[]{flowCode});

        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            throw e;
        }
        if(!BaseUtil.dataTableIsEmpty(coNodeData)) {
            FieldSetEntity fieldSetEntity = coNodeData.getFieldSetEntity(0);
            coNodeData.removeFieldSetEntity(0);
            DataTableEntity dataTable = new DataTableEntity();
            FieldMetaEntity f = new FieldMetaEntity();
            f.setTableName(new String[]{"product_oa_cooperate_flow_node"});
            dataTable.setMeta(f);
                String userId = userIdJson.getString(fieldSetEntity.getString("value"));
                if (BaseUtil.strIsNull(userId)) {
                    return null;
                }
            FieldSetEntity subfse = new FieldSetEntity();
            //婧愯〃鍚�
            subfse.setTableName("product_oa_cooperate_flow_node");
            //鍔炵悊浜哄眰绾�
            subfse.setValue("grade", 1);
            //鍏宠仈鍗忓悓琛╱uid
            subfse.setValue("cooperate_uuid", uuid);
            //鎺ユ敹浜篒d
            subfse.setValue("receiver", userId);
            //鎺ユ敹浜哄鍚�
            subfse.setValue("receiver_name", fieldSetEntity.getString("name"));
            //0:鏆傚瓨 1:鍔犵 2:杞彂 3:閫€鍥�4:閫佸姙 5:缁堟 6:鎾ら攢
            subfse.setValue("type", 0);
            subfse.setValue("sender", null);
            subfse.setValue("sender_name", null);
            subfse.setValue("tricode",null);
            DataTableEntity newDataTable = new DataTableEntity();
            FieldMetaEntity f2 = new FieldMetaEntity();
            f2.setTableName(new String[]{"product_oa_cooperate_flow_node"});
            newDataTable.setMeta(f2);
            newDataTable.addFieldSetEntity(subfse);
            parentGuidData.put(fieldSetEntity.getString("guid"), newDataTable);
            dataTable.addFieldSetEntity(subfse);
            try {
                this.saveReceiver(fieldSetEntity, coNodeData, uuid, null, dataTable,2);
                baseDao.add(dataTable);
            }catch (Exception e){
                e.printStackTrace();
            }
            return dataTable;
        }
        return null;
    }

    /**
     * 閫掑綊寰幆鍚屾浜哄憳 閮ㄩ棬宀椾綅 鏁版嵁
     * @param fse 鍙戦€佷汉fse
     * @param dataTableEntity 鍓╀綑浜篋ata
     */
    private void saveReceiver(FieldSetEntity fse, DataTableEntity dataTableEntity, String uuid,String tricode, DataTableEntity dataTable, Integer grade)throws Exception{
        DataTableEntity dataTableEntity1 = new DataTableEntity();
        DataTableEntity dataTableEntity2 = new DataTableEntity();
        String sender = "";
        //鍙戦€佺被鍨�
        String type2 = fse.getString("type");
        if("1".equals(type2)){
            sender = userIdJson.getString(fse.getString("value"));
            if(BaseUtil.strIsNull(sender)){
                return;
            }
        }
        for (int i = 0; i < dataTableEntity.getRows(); i++) {
          FieldSetEntity fieldSetEntity = dataTableEntity.getFieldSetEntity(i);
          String guid = fse.getString("guid");
          String parentguid = fieldSetEntity.getString("parentguid");
            if(guid.equals(parentguid)){
                dataTableEntity1.addFieldSetEntity(fieldSetEntity);
                FieldSetEntity subfs = new FieldSetEntity();
                //鍗忓悓鍔炲叕娴佺▼琛�
                subfs.setTableName("product_oa_cooperate_flow_node");
                subfs.setValue("grade", grade);
                //鍏宠仈鍗忓悓琛╱uid
                subfs.setValue("cooperate_uuid", uuid);
                //鎺ユ敹浜猴紙鍏宠仈鐢ㄦ埛琛╥d锛�  鎺ユ敹浜轰竴浣嗘槸鏈烘瀯鎴栭儴闂ㄨ妭鐐�   閭e氨鏄渶鍚庤妭鐐�
                String type = fieldSetEntity.getString("type");
                //鍙戦€佷汉id
                subfs.setValue("sender", sender);
                //浜哄憳
                if("1".equals(type)){
                    String userId = userIdJson.getString(fieldSetEntity.getString("value"));
                    if(BaseUtil.strIsNull(userId)){
                        continue;
                    }
                    subfs.setValue("receiver", userId);
                    //鑻ヤ负閮ㄩ棬鍏徃
                }else if("2".equals(type)){
                    String orgUuid = orgLevelJson.getString(fieldSetEntity.getString("value"));
                    if(BaseUtil.strIsNull(orgUuid)){
                        continue;
                    }
                    if(!BaseUtil.strIsNull(orgUuid)){
                        DataTableEntity staff = baseDao.listTable(" product_sys_staffs ", " dept_uuid = ? ", new String[]{orgUuid});
                        if(BaseUtil.dataTableIsEmpty(staff)){
                            staff = baseDao.listTable(" product_sys_staffs ", " org_level_uuid = ? ", new String[]{orgUuid});
                        }
                        if(!BaseUtil.dataTableIsEmpty(staff)) {
                            tricode = dataTable.getString(dataTable.getRows()-1, "tricode");
                            if(BaseUtil.strIsNull(tricode)){
                                tricode = dataTable.getString(dataTable.getRows()-1, "receiver");
                            }
                            this.addUserFlowNode(staff, grade, uuid,fse, tricode, fieldSetEntity,sender,dataTable);
                        }
                        continue;
                    }
                    //宀椾綅
                }else if("3".equals(type)){
                    String postUuid = postJson.getString(fieldSetEntity.getString("value"));
                    if(BaseUtil.strIsNull(postUuid)){
                        continue;
                    }
                    if(!BaseUtil.strIsNull(postUuid)){
                        DataTableEntity staff = baseDao.listTable(" product_sys_staffs ", " job_post_uuid = ? ", new String[]{postUuid});
                        if(!BaseUtil.dataTableIsEmpty(staff)) {
                            tricode = dataTable.getString(dataTable.getRows()-1, "tricode");
                            if(BaseUtil.strIsNull(tricode)){
                                tricode = dataTable.getString(dataTable.getRows()-1, "receiver");
                            }
                            this.addUserFlowNode(staff, grade, uuid,fse,  tricode, fieldSetEntity,sender,dataTable);
                        }
                        continue;
                    }
                }
                //鎺ユ敹浜哄鍚�
                subfs.setValue("receiver_name", fieldSetEntity.getString("name"));
                //triCode
                if(BaseUtil.strIsNull(tricode)){
                    subfs.setValue("tricode",sender);
                    fieldSetEntity.setValue("tricode",sender);
                }else {
                    subfs.setValue("tricode",tricode + "-" + sender);
                    fieldSetEntity.setValue("tricode",tricode + "-" + sender);
                }

                //鍙戦€佷汉濮撳悕
                subfs.setValue("sender_name", fse.getString("name"));
                //0:鏆傚瓨 1:鍔犵 2:杞彂 3:閫€鍥�4:閫佸姙 5:缁堟 6:鎾ら攢
                subfs.setValue("type", 0);
                DataTableEntity newDataTable = new DataTableEntity();
                FieldMetaEntity f2 = new FieldMetaEntity();
                f2.setTableName(new String[]{"product_oa_cooperate_flow_node"});
                newDataTable.setMeta(f2);
                newDataTable.addFieldSetEntity(subfs);
                parentGuidData.put(fieldSetEntity.getString("guid"), newDataTable);
                dataTable.addFieldSetEntity(subfs);
            }else {
                dataTableEntity2.addFieldSetEntity(fieldSetEntity);
            }
        }

        //鍔炵悊浜哄眰绾�
        grade++;
        if(!BaseUtil.dataTableIsEmpty(dataTableEntity1) && !BaseUtil.dataTableIsEmpty(dataTableEntity2)) {
            for (int i = 0; i < dataTableEntity1.getRows(); i++) {
                this.saveReceiver(dataTableEntity1.getFieldSetEntity(i) ,dataTableEntity2, uuid, dataTableEntity1.getString(i, "tricode"),dataTable,grade);
            }
        }
    }

    /**
     * 瑙f瀽鍚屾鐨勫矖浣嶉儴闂� 瑙f瀽涓轰汉鍐嶆壒閲忎繚瀛�
     * @param staff 閫氳繃閮ㄩ棬宀椾綅  鏌ヨ鍑烘潵鐨勭敤鎴锋暟鎹�
     * @param grade 灞傜骇
     * @param uuid 涓昏〃uuid
     * @param fse 婧愭暟鎹彂閫佷汉淇℃伅
     * @param tricode 鏈骇code
     * @param fieldSetEntity 鎺ユ敹淇℃伅
     * @param user_id 鍙戦€佷汉user_id
     */
    public void addUserFlowNode(DataTableEntity staff, Integer grade, String uuid, FieldSetEntity fse, String tricode, FieldSetEntity fieldSetEntity,String user_id,DataTableEntity data){
        DataTableEntity newDataTable = new DataTableEntity();
        FieldMetaEntity f2 = new FieldMetaEntity();
        f2.setTableName(new String[]{"product_oa_cooperate_flow_node"});
        newDataTable.setMeta(f2);
        String guid = fieldSetEntity.getString("guid");
        for (int f = 0; f < staff.getRows(); f++) {
                FieldSetEntity subfse = new FieldSetEntity();
                //婧愯〃鍚�
                subfse.setTableName("product_oa_cooperate_flow_node");
                //鍔炵悊浜哄眰绾�
                subfse.setValue("grade", grade);
                //鍏宠仈鍗忓悓琛╱uid
                subfse.setValue("cooperate_uuid", uuid);
                //鎺ユ敹浜篿d
                subfse.setValue("receiver", staff.getString(f,"user_id"));
                //鎺ユ敹浜哄鍚�
                subfse.setValue("receiver_name", staff.getString(f,"show_name"));
                //code
                subfse.setValue("tricode", tricode);
                //鍙戦€佷汉濮撳悕
                subfse.setValue("sender_name", fse.getString("name"));
                //鍙戦€佷汉id
                subfse.setValue("sender", user_id);
                //0:鏈敹鏈姙 1:宸叉敹鏈� 2:宸叉敹宸插姙
                subfse.setValue("status", fieldSetEntity.getInteger("status") == 1 ? 2 : 0);
                //0:鏆傚瓨 1:鍔犵 2:杞彂 3:閫€鍥�4:閫佸姙 5:缁堟 6:鎾ら攢
                subfse.setValue("type", 0);
                //鐢ㄤ簬鍚庨潰鍏宠仈鍗忓悓娴佺▼
                newDataTable.addFieldSetEntity(subfse);
                data.addFieldSetEntity(subfse);
            }
        //鐢ㄤ簬鍚庨潰鍏宠仈鍗忓悓娴佺▼
        parentGuidData.put(guid, newDataTable);
    }

    public String emergencyDegreeType(String type) {
        String reType = "";
        switch (type) {
            case "骞充欢":
                reType = "1";
                break;
            case "鐗规€�":
                reType = "2";
                break;
            case "鍔犳€�":
                reType = "3";
                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 {
            StringBuffer sql = new StringBuffer();
            sql.append(" select spt.SPT00 FU01,sfu.FU04 from fe_base5.SYS_POPEDOM_TEMPLET spt ")
                    .append(" LEFT JOIN fe_base5.SYS_FUNCTION_USER sfu on spt.SPT00 = sfu.FU01 OR spt.SPT03 = sfu.FU05 ")
                    .append(" WHERE sfu.FU02 = ? AND sfu.FU03 = 'R' GROUP BY sfu.FU04,spt.SPT00 ");
            permissionDt = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new Object[]{funCode});
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            throw e;
        }
        //寰幆鍏宠仈鐨勮鑹叉潈闄�
        for (int i = 0; i < permissionDt.getRows(); i++) {
            FieldSetEntity permissionFs = permissionDt.getFieldSetEntity(i);
            //瑙掕壊id
            String fu01 = permissionFs.getString("fu01");
            //鑾峰彇瑙掕壊鏁版嵁
            FieldSetEntity roleFse = baseDao.getFieldSetEntityByFilter("product_sys_role", " sequence = ? ", new String[]{fu01}, true);
            //鏌ヤ笉鍒板氨璺宠繃
            if(roleFse == null){
                continue;
            }
            //婧愭暟鎹姛鑳藉嬀閫夊彿
            String fu04 = permissionFs.getString("fu04");
            //鑾峰彇鏉冮檺閲岀殑鎸夐挳
            this.buttonCheck(conn, funCode,funUUID,fu04,buttonMap,roleFse.getUUID());
        }
        //鍚屾鍏宠仈浜虹殑鏉冮檺
        this.createPersonalRights(conn,funCode,funUUID,buttonMap);
        //鍚屾姣忎釜鍔熻兘鏉冮檺鍚�   杩樿鍚屾瀹㈡埛鏉冮檺
//        this.customerPermission(funUUID, buttonMap);
    }
    /**
     * 娣诲姞鎸夐挳鍕鹃€�
     *
     * @param conn      JDBC杩炴帴
     * @param funCode   鍔熻兘code
     * @param funUUID   鏂规硶uuid
     * @param fu04      婧愭暟鎹姛鑳藉嬀閫夊彿
     * @param buttonMap 鎸夐挳map
     * @param roleUuid
     * @throws SQLException
     */
    private void buttonCheck(Connection conn,String funCode,String funUUID,String fu04,JSONObject buttonMap,String roleUuid) throws SQLException {
        List<String> buttonIdType = new ArrayList<>();
        buttonIdType.add(funCode);
        FieldSetEntity fs = new FieldSetEntity();
        fs.setTableName("product_sys_function_permission");
        fs.setValue("role_uuid",roleUuid);
        fs.setValue("function_uuid", funUUID);
        for (int j = 0; j < fu04.length(); j++) {
            String type = String.valueOf(fu04.charAt(j));
            if (type.equals("1")) {
                //鏀惧叆鍊肩殑涓嬫爣
                buttonIdType.add(this.buttonTypeRole(j));
            }
        }
        if (buttonIdType.size() == 1) {
            return;
        }
        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 = Lists.newArrayList();
        for (int j = 0; j < eventDt.getRows(); j++) {
            buttonId.add(buttonMap.getString(eventDt.getString(j, "se00")));
        }
        fs.setValue("button_uuid", StringUtils.join(buttonId, ","));
        fs.setValue("created_by", 1);
        fs.setValue("created_utc_datetime", new Date());
        try {
            baseDao.add(fs);
        }catch (BaseException e){
            e.printStackTrace();
        }
    }

    /**
     * 缁欏崟涓汉鏉冮檺鍗曠嫭鍒涘缓瑙掕壊
     * @param conn
     * @param funCode
     * @throws SQLException
     */
    public void createPersonalRights(Connection conn,String funCode,String funUUID,JSONObject buttonMap) throws SQLException {
        DataTableEntity usePermissionDt;
        try {
            usePermissionDt = BaseDaoServiceImpl.getDataTable(conn, "FE_BASE5.SYS_FUNCTION_USER", " FU02 = ? AND FU03 = 'U' ", new Object[]{funCode});
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            throw e;
        }
        if(!BaseUtil.dataTableIsEmpty(usePermissionDt)){
            String fu04 = usePermissionDt.getFieldSetEntity(0).getString("fu04");
            //鍒涘缓瑙掕壊
            FieldSetEntity lxRoleFs = new FieldSetEntity();
            lxRoleFs.setTableName("product_sys_role");
            lxRoleFs.setValue("org_level_uuid","00000000-0000-0000-0000-000000000000");
            lxRoleFs.setValue("role_name",  this.functionName+"鐨勪釜浜烘潈闄�");
            lxRoleFs.setValue("role_description", this.functionName+"鐨勪釜浜烘潈闄�");
            lxRoleFs.setValue("is_used", 1);
            lxRoleFs.setValue("created_by",1);
            lxRoleFs.setValue("created_utc_datetime",new Date());
            String uuid = baseDao.add(lxRoleFs);
            //鍚屾鏉冮檺鍏宠仈鐨勬寜閽�
            this.buttonCheck(conn, funCode,funUUID,fu04,buttonMap,uuid);
            //璇ユ潈闄愮鐞嗙殑鏄敤鎴疯〃锛圫YS_USERS锛�  骞堕潪瑙掕壊琛�
            List<String> userid = Lists.newArrayList();
            for (int i = 0; i < usePermissionDt.getRows(); i++) {
                FieldSetEntity permissionFs = usePermissionDt.getFieldSetEntity(i);
                //鐢ㄦ埛id
                String id = this.userIdJson.getString(permissionFs.getString("fu01"));
                if(!BaseUtil.strIsNull(id)){
                    userid.add(id);
                }
            }
            //浜哄憳缁戝畾璇ユ潈闄�
            if(userid.size() > 0){
                String[] user = new String[userid.size()];
                userid.toArray(user);
                String filter = BaseUtil.buildQuestionMarkFilter("user_id", user,true);
                baseDao.executeUpdate("UPDATE  product_sys_staffs SET role_uuids = CONCAT(role_uuids, ',"+uuid+"')  WHERE " + filter);
            }
        }
    }

    /**
     * 鍚屾瀹㈡埛鏉冮檺
     * @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", 1);
        fs.setValue("created_utc_datetime", new Date());
        try {
            baseDao.add(fs);
        }catch (BaseException e){
            e.printStackTrace();
        }

    }

    /**
     * 鍒涘缓涓€涓姛鑳戒笅鐨勮鑹�
     * 鎶婄洿鎺ュ叧鑱斿姛鑳界殑鐢ㄦ埛鏀惧叆瑙掕壊涓�
     *
     * @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(this.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", 1);
            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", 1);
            fs.setValue("created_utc_datetime", new Date());
            //浣嶇疆top
            fs.setValue("top_location", pageFs.getString("sp07") + "px");
            //浣嶇疆left
            fs.setValue("left_location", pageFs.getString("sp06") + "px");
            //琛ㄥ崟绫诲瀷 鍚嶇О甯︽湁鍒楄〃閮芥槸鍒楄〃绫诲瀷
            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", 1);
            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", 1);
            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 moduleUUID, String sf28) throws SQLException, ClassNotFoundException {
        if(!BaseUtil.strIsNull(funFs.getString("sf28"))){
            sf28 = funFs.getString("sf28");
        }
        FieldSetEntity product_sys_datamodel_table = new FieldSetEntity();
        String table = "";
        if(!BaseUtil.strIsNull(sf28)){
            table = sf28.split("\\.")[1].toLowerCase();
            product_sys_datamodel_table = baseDao.getFieldSetEntityByFilter("product_sys_datamodel_table", "table_name=?", new String[]{table}, false);
        }else {
            return;
        }

        //杩佺Щ鍔熻兘
        FieldSetEntity fs = new FieldSetEntity();
        fs.setTableName("product_sys_functions");
        //琛╱uid
        fs.setValue("table_uuid",product_sys_datamodel_table.getString("uuid"));
        //鍔熻兘鍚嶇О
        this.functionName =  funFs.getString("sf03");
        fs.setValue("function_name", this.functionName);
        //鍔熻兘鎻忚堪
        fs.setValue("function_description", this.functionName);
        //涓婄骇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", 1);
        fs.setValue("created_utc_datetime", new Date());
        fs.setValue("data_type", 1);
        String funUUID = "";
        try {
            funUUID = baseDao.add(fs);
        }catch (BaseException e){
            e.printStackTrace();
        }
        //淇敼宸插悓姝ラ檮浠� 娣诲姞 module_uuid function_uuid
        baseDao.executeUpdate(" UPDATE product_sys_attachments SET module_uuid = ?, function_uuid = ? WHERE attachment_data_table = ? AND function_uuid is null ",new String[]{moduleUUID, funUUID, table});
        String sf05 = funFs.getString("sf05");
        //鑾峰彇jdbc杩炴帴
        Connection conn = this.getJDBC();
        //杩佺ЩMVC
        JSONObject buttonMap = this.syncButtonsPage(conn, funUUID, sf05);
        //杩佺Щ鑿滃崟
        try {
            this.synchronizationMenu(conn, funFs.getString("sf05"), funUUID);
        }catch (Exception e){
            e.getStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
        }
        //杩佺Щ鍔熻兘鏉冮檺璁稿彲
        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);
            e.getStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
            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", 1);
            moduleFs.setValue("created_utc_datetime", new Date());
            moduleFs.setValue("data_type", 2);
            //鏂板涓€涓猣e杩佺Щ鎬绘ā鍧�
            try {
                moduleUUID = baseDao.add(moduleFs);
            }catch (BaseException e){
                e.printStackTrace();
            }
        } else {
            moduleCode = moduleFs.getString("tricode");
            moduleUUID = moduleFs.getUUID();
        }
        //鍚屾妯″潡涓嬬殑鍔熻兘
        try {
            this.syncFunctions(funFse, moduleCode, moduleUUID, 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);
            e.getStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
            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", "");
            try {
                baseDao.add(menuFieldSet);
            }catch (BaseException e){
                e.printStackTrace();
            }

        }else {
            menuCode = fieldSetEntity.getString("tricode");
        }
        //鐢熸垚鐨勮彍鍗曠紪鐮�
        fieldSet.setValue("tricode", CodeUtil.getNewCodeByTemp("product_sys_menus", "tricode", menuCode));
        //鐖剁骇缂栫爜
        fieldSet.setValue("tricode_parent", menuCode);
        try {
            baseDao.add(fieldSet);
        }catch (BaseException e){
            e.printStackTrace();
        }
    }

    /**
     * 杩佺Щ涓氬姟鏁版嵁琛�
     *
     * @param sf28s 搴撳悕鍜岃〃鍚�
     * @param conn  杩炴帴
     * @return
     * @throws SQLException
     */
    public void syncTable(String[] sf28s, boolean isNew, String subField, Connection conn) throws Exception {
        FieldSetEntity Orlfs;
        //琛ㄥ悕
        String taName = sf28s[1];
        //鑾峰彇涓昏〃鐨勮〃鍚�
        if (sf28s.length == 3) {
            this.masterTableName = sf28s[2];
        }
        try {
            Orlfs = BaseDaoServiceImpl.getFieldSet(conn, "fe_base5.SYS_TABLE", "ST03=?", new Object[]{taName});
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            e.getStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
            throw e;
        }
        Map<String, String> map = null;
        Boolean syncAttachments = false;
        DataTableEntity accessoryData;
        //鏄惁鏄柊琛�
        if (isNew) {
            //鍒ゆ柇鏄惁鏄凡缁忓悓姝ヨ繃鐨勮〃
            FieldSetEntity fieldSetEntity = baseDao.getFieldSetEntityByFilter("product_sys_datamodel_table", " table_name = ? ", new String[]{taName.toLowerCase()}, false);
            if (fieldSetEntity == null) {
                //鏌ヨ璇ヨ〃瀛楁湁娌℃湁闄勪欢瀛楁  media attachment
                accessoryData = this.getTableFieldAttachment(conn, Orlfs.getString("st00"));
                if (!BaseUtil.dataTableIsEmpty(accessoryData)) {
                    syncAttachments = true;
                    for (int i = 0; i < accessoryData.getRows(); i++) {
                        this.attachmentValue = this.attachmentValue + accessoryData.getString(i, "si04") + ",";
                    }
                    this.attachmentValue = "," + this.attachmentValue;
                }
                //鍚屾琛ㄧ粨鏋�  鍙婂瓧娈典俊鎭�
                map = this.syncTableField(conn, Orlfs, sf28s, subField);
                //鍒锋柊table 琛�
                DataPoolCacheImpl.getInstance().cacheDataByTable("product_sys_datamodel_table");;
                //鍒锋柊field 琛�
                DataPoolCacheImpl.getInstance().cacheDataByTable("product_sys_datamodel_field");
                try {
                    Thread.sleep(7000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    SpringMVCContextHolder.getSystemLogger().error(e);
                }
            } 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);
            e.printStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
            throw e;
        }

        //涓氬姟琛� 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(conn,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, tableFs.getTableName(), null);
                if (fileMaps.size() > 0) {
                    for (String fieldName : fileMaps.keySet()) {
                        List<String> value = fileMaps.get(fieldName);
                        tableFs.setValue(fieldName, StringUtils.join(value, ","));
                    }
                }
            }
            String uuid = "";
            try {
                uuid = baseDao.add(tableFs);
            }catch (BaseException e){
                e.printStackTrace();
                SpringMVCContextHolder.getSystemLogger().error(e);
            }
            //琛ㄥ敮涓€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[]{"%." + taName + ".%"});
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            SpringMVCContextHolder.getSystemLogger().error(e);
            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 String 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 IN ('[100001]', '[100000]') ");
            dataTable = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new String[]{fieldName, tableName});
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            SpringMVCContextHolder.getSystemLogger().error(e);
            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 C.SP02 = 'A11') OR (C.SP01 = 'prompt' AND C.SP02 IN ('[010001]','[010000]'))) ");

                dataTable = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new String[]{fieldName, tableName});
            } catch (Exception e) {
                DataManipulationUtils.close(null, null, conn);
                SpringMVCContextHolder.getSystemLogger().error(e);
                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[]{fieldName, tableName});
                } catch (Exception e) {
                    DataManipulationUtils.close(null, null, conn);
                    SpringMVCContextHolder.getSystemLogger().error(e);
                    throw e;
                }
                //濡傛灉鏄閫夋帶浠�
                if (!BaseUtil.dataTableIsEmpty(dataTable)) {
                    fieldTypeJson.put(fieldName.toLowerCase(), "USERSGROUPS");
                    return "800";
                }
            } else {
                fieldTypeJson.put(fieldName.toLowerCase(), "GROUP");
                //娣诲姞閮ㄩ棬鍏徃鍙傜収
                fieldSetEntity.setValue("field_reference", "levels");
                return "80";
            }
        } else {
            //娣诲姞浜哄憳鍙傜収
            fieldTypeJson.put(fieldName.toLowerCase(), "USER");
            fieldSetEntity.setValue("field_reference", "user_name_by_user_id");
        }
        return null;
    }

    /**
     * 鍚屾闄勪欢
     *
     * @param accessoryData 闄勪欢瀛楁data
     * @param tableFs       鏁版嵁鍊�
     */
    public Map<String, List<String>> synchronizationAttachments(Connection conn, DataTableEntity accessoryData, FieldSetEntity tableFs, String table,String myField) throws Exception {
        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(myField)){
                field = myField;
            }
            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)) {
                        //闄勪欢鍊�
                        Map<String, File> mediaFiles = gdMediaUtil.getMediaFiles(attachmentsValue);
                        for (String name : mediaFiles.keySet()) {
                            File sourceFile = mediaFiles.get(name);
                            String newPath = this.TSPath + File.separator + name;
                            File isField = new File(newPath);
                            //濡傛灉宸茬粡鏈夎鏂囦欢   鏀瑰彉鏂囦欢鐩綍
                            Integer fileNum = 0;
                            while (isField.exists()) {
                                fileNum++;
                                newPath = this.TSPath + fileNum + File.separator + name;
                                isField = new File(newPath);
                            }
                            //婧愮粷瀵硅矾寰�
                            String path = sourceFile.getAbsolutePath();
                            if (feDataDSService.copyFile(path, newPath)) {
                                RequestParameterEntity rpe = new RequestParameterEntity();
                                Map<String, File> fileMap = Maps.newHashMap();
                                //閫氳繃璺緞鑾峰彇File
                                File file = new File(newPath);
                                //鏂囦欢鍚�  鏂囦欢file
                                fileMap.put(name, file);
                                FieldSetEntity fieldSetEntity = new FieldSetEntity();
                                FieldMetaEntity f = new FieldMetaEntity();
                                f.setTableName(new String[]{table});
                                fieldSetEntity.setMeta(f);
                                fieldSetEntity.setValue(field, name);
                                fieldSetEntity.setValue("~field_name~", field);
                                //鏀惧叆瀹㈡埛uuid
                                fieldSetEntity.setValue("client_uuid", this.clientUUID);
                                rpe.setFiles(fileMap);
                                rpe.setFormData(fieldSetEntity);
                                try {
                                FieldSetEntity fileFse = fileManagerService.uploadFile(rpe);
                                fileUuids.add(fileFse.getString(field));
                                    }catch (Exception e){
                                        e.getStackTrace();
                                        SpringMVCContextHolder.getSystemLogger().error(e);
                                    }
                            }
                        }
                    }
                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 + File.separator + sa02;
                String newPath = this.TSPath + File.separator + sa03;
                File isField = new File(newPath);
                //濡傛灉宸茬粡鏈夎鏂囦欢   鏀瑰彉鏂囦欢鐩綍
                Integer fileNum = 0;
                while (isField.exists()){
                    fileNum++;
                    newPath = this.TSPath + fileNum + File.separator + sa03;
                    isField = new File(newPath);
                }
                //澶嶅埗鍒颁复鏃剁洰褰曚笅
                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();
                    FieldMetaEntity f = new FieldMetaEntity();
                    f.setTableName(new String[]{table});
                    fieldSetEntity.setMeta(f);
                    fieldSetEntity.setValue(field, sa03);
                    fieldSetEntity.setValue("~field_name~", field);
                    //鏀惧叆瀹㈡埛uuid
                    fieldSetEntity.setValue("client_uuid", this.clientUUID);
                    rpe.setFiles(fileMap);
                    rpe.setFormData(fieldSetEntity);
                    try {
                        FieldSetEntity fileFse = fileManagerService.uploadFile(rpe);
                        fileUuids.add(fileFse.getString(field));
                    }catch (Exception e){
                        e.getStackTrace();
                        SpringMVCContextHolder.getSystemLogger().error(e);
                    }

                    //鎴愬姛涔嬪悗鍒犻櫎涓存椂鏂囦欢
//                    feDataDSService.deleteFile(newPath);
                }
            }
            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 = ? ");
        dataTableEntity = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new Object[]{value});
        return dataTableEntity;
    }

    /**
     * 鑾峰彇閲戞牸闄勪欢淇℃伅
     *
     * @param value 闄勪欢鏍囪瘑
     * @return
     */
    public DataTableEntity getMediaSortInfo(Connection conn, String value) throws Exception {
        DataTableEntity dataTableEntity = null;
        StringBuffer sql = new StringBuffer();
        sql.append(" SELECT * FROM FE_APP5.WF_MEDIA_SORT WHERE WMS02 = ? ");
        dataTableEntity = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new Object[]{value});
        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(Connection conn,String tableId) throws Exception {
        DataTableEntity dataTableEntity = null;
        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});
        return dataTableEntity;
    }

    public Connection getJDBC() throws SQLException, ClassNotFoundException {
        //鑾峰彇jdbc杩炴帴
//        String diver = "oracle.jdbc.driver.OracleDriver";
//        String url = "jdbc:oracle:thin:@10.0.0.21:1521:orcl";
//        return DataManipulationUtils.getConnection(diver, url, "FE_BASE5", "fe123");
        //鑾峰彇jdbc杩炴帴
        String diver = Global.getSystemConfig("data.synchronism.function.jdbc.diver", "");
        String url = Global.getSystemConfig("data.synchronism.function.jdbc.url", "");
        String name = Global.getSystemConfig("data.synchronism.function.jdbc.name", "");
        String password = Global.getSystemConfig("data.synchronism.function.jdbc.password", "");
        return DataManipulationUtils.getConnection(diver, url, name, password);
    }

    /**
     * 杩佺Щ"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", 1);
        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);
            SpringMVCContextHolder.getSystemLogger().error(e);
            throw e;
        }
        DataTableEntity dt = new DataTableEntity();
        String table_uuid = tableFs.getString("uuid");
        //灏佽婧愯〃鍚嶄笌uuid
        originalUuid.put(table_name,table_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锛�
            String length = 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 sf03 = rowFs.getString("sf03");
            String type = this.fieldTypeFE(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(sf03)) {
                fieldFs.setValue("is_unique", 1);
            } else {
                fieldFs.setValue("is_unique", 0);
            }
            if ("NATIVE".equals(sf03)) {
                fieldFs.setValue("NATIVE", 1);
            }
            if ("UNITCODE".equals(sf03)) {
                fieldFs.setValue("UNITCODE", 1);
            }
            //濡傛灉鏄叧鑱斾富琛ㄥ瓧娈� 闀垮害鏀逛负64
            if (subField != null && subField.equals(sf01.toLowerCase())) {
                fieldFs.setValue("field_type", "string");
                fieldFs.setValue("field_length", 64);
            } else {
                //濡傛灉涓洪檮浠跺瓧娈甸暱搴�500
                if("ATTACHMENT".equals(sf01) || "IMAGE".equals(sf03) || "MEDIA".equals(sf03)){
                    fieldFs.setValue("field_length", 500);
                    //鏃堕棿瀛楁闀垮害璧�0
                }else if("datetime".equals(type)){
                    fieldFs.setValue("field_length",0);
                //澶氶€夋帶浠舵坊棰濆鍔犲瓧娈甸暱搴�
                }else if(!BaseUtil.strIsNull(length)){
                    fieldFs.setValue("field_length",length);
                }else {
                    fieldFs.setValue("field_length", rowFs.getString("sf04"));
                }
            }
            //鍖呭惈灏变负闄勪欢瀛楁
            if(!BaseUtil.strIsNull(this.attachmentValue) && this.attachmentValue.contains(","+sf01+",")){
                fieldFs.setValue("field_type", "file");
                fieldFs.setValue("field_length", 500);
            }
            //鐗规畩琛�  闄勪欢鎵╁ぇ
            if("FWGZ".equals(table_name) && "FW12".equals(sf01)){
                fieldFs.setValue("field_length", 5000);
            }
            fieldFs.setValue("field_unit", rowFs.getString("sf05"));
            fieldFs.setValue("is_required", 0);
            fieldFs.setValue("is_filter", 0);
            String sf10 = rowFs.getString("sf10");
            if(!BaseUtil.strIsNull(this.masterTableName)) {
                if (!BaseUtil.strIsNull(sf10) && sf10.contains(this.masterTableName)) {
                    fieldFs.setValue("field_type", "parentuuid");
                    fieldFs.setValue("field_relation_table", this.originalUuid.get(this.masterTableName));
                }
            }
            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 String syncModel(String tricode_funs, Connection conn, String module_uuid, String sf28, String org_level_uuid, int created_by, String typeCode,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);
            SpringMVCContextHolder.getSystemLogger().error(e);
            throw e;
        }
        if (Orlfs == null) {
            //閫氳繃
            Orlfs = BaseDaoServiceImpl.getFieldSet(conn, "fe_base5.wf_model", " WM04 = ? ", new Object[]{sf28});
            if(Orlfs == null){
                return null;
            }
        }
        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 null;
                }
            } catch (Exception e) {
                DataManipulationUtils.close(null, null, conn);
                SpringMVCContextHolder.getSystemLogger().error(e);
                throw e;
            }
            //濡傛灉鍔熻兘琛ㄥ拰娴佺▼琛ㄧ粦瀹氱殑鏁版嵁琛ㄤ笉鐩稿悓  浠ユ祦绋嬭〃涓轰富
        } else if (!wm04.equals(sf28)) {
            String[] wm04s = wm04.split("\\.");
            try {
                this.syncTable(wm04s, false, null, conn);
            }catch (Exception e){
                e.getStackTrace();
                SpringMVCContextHolder.getSystemLogger().error(e);
            }

        }

        String[] wm04s = wm04.split("\\.");
        //涓昏〃琛ㄥ悕
        modelFs.setValue("table_uuid",this.originalTable.getString(wm04s[1]));
        //鐢熸垚uuid
        if(BaseUtil.strIsNull(typeCode)){
            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);
        }


        String wm00 = Orlfs.getString("wm00");
        //杩佺ЩWF_NODES 娴佺▼鑺傜偣琛�
        JSONObject nodesUUID = this.syncNodes(wm00, conn, modelUuid);
        //杩佺ЩWF_NODES 娴佺▼鑺傜偣琛� 鍒�"product_sys_flow_processor 澶勭悊鍣ㄨ縼绉�
        this.syncProcessor(wm00, conn, modelUuid);
        //杩佺ЩWF_LINKS
        this.syncLinks(wm00, conn, modelUuid);
        if(flag) {
            try {
                //杩佺Щ WF_TASK
                Map<String, FieldSetEntity> taskFseMap = this.syncTask(tricode_funs, conn, modelUuid);
                //杩佺Щwf_infor 鑺傜偣浠诲姟澶勭悊鎯呭喌琛�
                Map<String, String> stateMap = this.syncDetail(tricode_funs, conn, nodesUUID, sf28, modelUuid, taskFseMap);
                //鍚屾娑堟伅
                try {
                    this.synchronizingProcessMessages(conn, tricode_funs, stateMap);
                } catch (BaseException e) {
                    e.printStackTrace();
                    SpringMVCContextHolder.getSystemLogger().error(e);
                }
            }catch (Exception e){
                e.getStackTrace();
                SpringMVCContextHolder.getSystemLogger().error(e);
            }
        }
        return typeCode;
    }

    /**
     * 杩佺Щ flow澶勭悊鍣�
     *
     * @throws SQLException
     */
    public void syncProcessor(String wm00, Connection conn, String modelUUID) throws SQLException {
        DataTableEntity OrlDt = null;
        try {
            OrlDt = BaseDaoServiceImpl.getDataTable(conn, "fe_base5.wf_nodes", " WN01= ? and WN04 ='5'", new Object[]{wm00
            });
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            SpringMVCContextHolder.getSystemLogger().error(e);
            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", 1);
            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);
        }
    }

    /**
     * 鍚屾娴佺▼鑺傜偣
     * @param wm00 娴佺▼涓昏〃id
     * @param conn
     * @param modelUUID 妯″潡uuid
     * @return
     * @throws SQLException
     */
    public JSONObject syncNodes(String wm00, Connection conn, String modelUUID) throws SQLException {
        DataTableEntity OrlDt = null;
        try {
            OrlDt = BaseDaoServiceImpl.getDataTable(conn, "fe_base5.wf_nodes", " WN01 = ? and WN04 !='5' ", new Object[]{wm00
            });
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            SpringMVCContextHolder.getSystemLogger().error(e);
            throw e;
        }
        JSONObject map = new JSONObject();
        nodesIdUUID = new JSONObject();
        try{
            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", 1);
                //鍒涘缓鏃堕棿
                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(conn,Orlfs);
                if (map1 != null && map1.size() > 0) {
                    String userSet = map1.get("userSet");
                    //浜哄憳id
                    if (!BaseUtil.strIsNull(userSet)) {
                        nodeFs.setValue("default_users", userSet);
                    }
                    String postSet = map1.get("postSet");
                    //宀椾綅uuid
                    if (!BaseUtil.strIsNull(postSet)) {
                        nodeFs.setValue("default_posts", postSet);
                    }
                    String deptSet = map1.get("deptList");
                    //鍗曚綅閮ㄩ棬uuid
                    if (!BaseUtil.strIsNull(deptSet)) {
                        nodeFs.setValue("default_depts", deptSet);
                    }
                }
                //闇€瑕佸湪鏁版嵁婧愯〃閲岄潰鎻掑叆涓€涓儴闂�  鎵€鏈夌洿鎺ュ叧鑱斿崟浣嶉兘鏀逛负杩欎釜閮ㄩ棬
                //鍧愭爣锛岃妭鐐瑰埌涓婅竟鐣岀殑鍨傜洿璺濈
                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);
                //鍏佽鎵撳嵃
                nodeFs.setValue("allow_print", 1);
                //濡傛灉鏈夐檮浠跺瓧娈� 娣诲姞涓嬭浇棰勮鏉冮檺
                if(!BaseUtil.strIsNull(this.attachmentValue)){
                    //鍏佽鍒犻櫎
                    nodeFs.setValue("allow_delete", 0);
                    //鍏佽涓嬭浇
                    nodeFs.setValue("allow_download", 1);
                    //鍏佽棰勮
                    nodeFs.setValue("allow_preview", 1);
                    //闄勪欢瀛楁
                    String field = this.attachmentValue.substring(1,this.attachmentValue.length()-1);
                    nodeFs.setValue("editable_field", field.toLowerCase());
                }
                String uuid = baseDao.add(nodeFs);
                //鑺傜偣鍞竴鍙�
                map.put(Orlfs.getString("wn53"), uuid);
                //椤哄簭鍙�
                nodesIdUUID.put(Orlfs.getString("wn00"), uuid);
            }
        }catch (BaseException e){
            e.printStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
        }
        return map;
    }

    /**
     * 鍚屾鑺傜偣閰嶇疆鐨勭粍缁囨灦鏋�
     *
     * @param fieldSetEntity
     */
    public Map<String, String> syncNodeInstitutions(Connection conn,FieldSetEntity fieldSetEntity) {
        String wn00 = fieldSetEntity.getString("wn00");
        DataTableEntity OrlDt = null;
        try {
            OrlDt = BaseDaoServiceImpl.getDataTable(conn, "fe_base5.WF_ROLES", " WR01 = ? ", new Object[]{wn00});
        } catch (Exception e) {
            e.getStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
        }
        if (BaseUtil.dataTableIsEmpty(OrlDt)) {
            return null;
        }
        //鐢ㄦ埛
        Set<String> userSet = Sets.newHashSet();
        //閮ㄩ棬
        Set<String> deptSet = Sets.newHashSet();
        //宀椾綅
        Set<String> postSet = Sets.newHashSet();
        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)) {
                userSet.add(wr03);
                //瑙掕壊 宀椾綅
            } else if ("Y".equals(wr04)) {
                postSet.add(wr03);
                //鏈烘瀯
            } else if ("Z".equals(wr04)) {
                deptSet.add(wr03);
            }
        }
        Map<String, String> map = Maps.newHashMap();
        //鏌ヨ浜哄憳
        if (userSet.size() > 0) {
            DataTableEntity staffData = baseDao.listTable("product_sys_staffs", BaseUtil.buildQuestionMarkFilter("remark", userSet.toArray(), true));
            if (!BaseUtil.dataTableIsEmpty(staffData)) {
                userSet.clear();
                for (int i = 0; i < staffData.getRows(); i++) {
                    userSet.add(staffData.getString(i, "user_id"));
                }
                map.put("userSet", StringUtils.join(userSet, ","));
            }
        }
        //鏌ヨ宀椾綅
        if (postSet.size() > 0) {
            DataTableEntity postData = baseDao.listTable("product_sys_job_posts", BaseUtil.buildQuestionMarkFilter("sequence", postSet.toArray(), true));
            if (!BaseUtil.dataTableIsEmpty(postData)) {
                //濡傛灉宀椾綅uuid鎬昏瓒呰繃2000灏卞彇鍑哄矖浣嶄笅鐨勪汉
                if((postData.getRows() * 37) > 2000){
                  DataTableEntity staffData = baseDao.listTable(" SELECT a.user_id FROM product_sys_staffs a LEFT JOIN product_sys_job_posts b on a.job_post_uuid = b.uuid where " +  BaseUtil.buildQuestionMarkFilter("b.sequence", postSet.toArray(), true), new String[]{});
                    postSet.clear();
                    if(!BaseUtil.dataTableIsEmpty(staffData)) {
                        for (int i = 0; i < staffData.getRows(); i++) {
                            userSet.add(staffData.getString(i, "user_id"));
                        }
                        map.put("userSet", StringUtils.join(userSet, ","));
                    }
                }else {
                    postSet.clear();
                    for (int i = 0; i < postData.getRows(); i++) {
                        postSet.add(postData.getString(i, "uuid"));
                    }
                    map.put("postSet", StringUtils.join(postSet, ","));
                }
            }
        }
        //鏌ヨ鏈烘瀯(鍗曚綅閮ㄩ棬)
        if (deptSet.size() > 0) {
            DataTableEntity orgData = baseDao.listTable("product_sys_org_levels", BaseUtil.buildQuestionMarkFilter("sequence", deptSet.toArray(), true));
            if (!BaseUtil.dataTableIsEmpty(orgData)) {
                deptSet.clear();
                for (int i = 0; i < orgData.getRows(); i++) {
                    deptSet.add(orgData.getString(i, "uuid"));
                }
                map.put("deptSet", StringUtils.join(deptSet, ","));
            }
        }
        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, Map<String, FieldSetEntity> taskFseMap) 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);
            SpringMVCContextHolder.getSystemLogger().error(e);
            throw e;
        }
        Map<String, String> stateMap = Maps.newHashMap();
        DataTableEntity DetailData = new DataTableEntity();
        FieldMetaEntity f = new FieldMetaEntity();
        f.setTableName(new String[]{"product_sys_flow_detail"});
        DetailData.setMeta(f);
        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"));
            }
            String wi00 = Orlfs.getString("wi00");
            //id涓€鑷�
            DetailFs.setValue("id",  wi00);
            //鑺傜偣鍚嶇О
            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);
            //鑺傜偣鏍囪瘑锛�0-鏅€氾紝1-鍔犵锛�2-閫€鍥烇級
            DetailFs.setValue("node_sign", 0);
            String node_uuid = UUIDMap.getString(Orlfs.getString("wi62"));
            if (BaseUtil.strIsNull(node_uuid)) {
                continue;
            }
            //婧恥uid锛屽叧鑱旀湰琛�
            String wi14 = Orlfs.getString("wi14");
            //涓虹┖琛ㄧず娌℃湁涓婁竴绾ц妭鐐�
            if(BaseUtil.strIsNull(wi14)){
                if(i > 0){
                  FieldSetEntity priorFes = OrlDt.getFieldSetEntity(i - 1);
                  String priorWi00 = priorFes.getString("wi00");
                  FieldSetEntity priorFieldSet = OrgIdUUIDmap.get(priorWi00);
                  if(priorFieldSet != null){
                      FieldSetEntity taskFse = taskFseMap.get(priorFes.getString("wi01"));
                      if(taskFse != null){
                          taskFse.setValue("cur_node_uuid",  node_uuid);
                          //娣诲姞褰撳墠鑺傜偣璁板綍
                          baseDao.update(taskFse);
                      }
                  }
                }
            }else {
                FieldSetEntity fieldSetEntity = OrgIdUUIDmap.get(wi14);
                if (fieldSetEntity != null) {
                    DetailFs.setValue("source_uuid", fieldSetEntity.getUUID());
                }
            }
            //鍒涘缓浜� 涓婁釜鑺傜偣澶勭悊浜�
            DetailFs.setValue("created_by", userIdJson.getString(Orlfs.getString("wi15")));

            //鍏宠仈鑺傜偣琛�
            DetailFs.setValue("node_uuid", node_uuid);
            //棰勬湡澶勭悊鏃堕棿锛堝皬鏃讹級
            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);
            //鎰忚
            String wi20 = Orlfs.getString("wi20");
            if("2".equals(nodeState)) {
                if(BaseUtil.strIsNull(wi20)){
                    DetailFs.setValue("opinion", "宸查槄");
                }else {
                    DetailFs.setValue("opinion", wi20);
                }
                //娣诲姞绛惧悕
                String sign = userIdSignature.getString(wi12);
                DetailFs.setValue("sign_attachment_uuid", sign);
            }
            //鍏宠仈琛�
            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);
            FieldSetEntity taskFse =  taskFseMap.get(Orlfs.getString("wi01"));
            if(taskFse == null){
                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", taskFse.getUUID());
            baseDao.add(DetailFs);
            OrgIdUUIDmap.put(wi00, DetailFs);
            stateMap.put(wi00, nodeState);
        }
        return stateMap;
    }


    /**
     * 鏌ヨ娴佺▼娑堟伅琛�
     * @param conn
     * @param tricode_funs
     * @param stateMap
     * @throws SQLException
     */
    public void synchronizingProcessMessages(Connection conn,String tricode_funs, Map<String, String> stateMap) throws SQLException {
        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");

            DataTableEntity OrlDt = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new String[]{tricode_funs});
            if(!BaseUtil.dataTableIsEmpty(OrlDt)) {
                this.synchronizingProcessMessages(OrlDt, stateMap,"product_sys_flow_detail");
            }
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            SpringMVCContextHolder.getSystemLogger().error(e);
            throw e;
        }

    }

    /**
     *     鍚屾娴佺▼娑堟伅琛�
     */
    public void synchronizingProcessMessages(DataTableEntity OrlDt, Map<String, String> stateMap, String tableName){
        String id = null;
        String message_uuid = null;
        String state = null;
        DataTableEntity dataTableEntity = new DataTableEntity();
        FieldMetaEntity f = new FieldMetaEntity();
        f.setTableName(new String[]{"product_sys_message"});
        dataTableEntity.setMeta(f);
        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涓鸿鍔�
                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");
                    if(BaseUtil.strIsNull(sendUserId)){
                        continue;
                    }
                }
                message.setValue("send_user_id", sendUserId);
                //鍒涘缓浜哄強鍙戦€佷汉
                message.setValue("created_by", sendUserId);
                //	涓氬姟琛�
                message.setValue("source_table", tableName);

                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 = baseDao.add(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);
            dataTableEntity.addFieldSetEntity(message_user);
            if(dataTableEntity.getRows() == 1000){
                baseDao.add(dataTableEntity);
                dataTableEntity = new DataTableEntity();
                dataTableEntity.setMeta(f);
            }
        }
        if(!BaseUtil.dataTableIsEmpty(dataTableEntity)) {
            baseDao.add(dataTableEntity);
        }
    }


    //杩佺ЩWF_LINKS  杩炵嚎琛�
    public void syncLinks(String wm00, 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= ? )");

            OrlDt = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new Object[]{wm00
            });
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            SpringMVCContextHolder.getSystemLogger().error(e);
            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", 1);
            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
            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 Map<String, FieldSetEntity> syncTask(String tricode_funs, Connection conn, String modelUUID) throws SQLException,BaseException {
        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);
            SpringMVCContextHolder.getSystemLogger().error(e);
            throw e;
        }
        Map<String, FieldSetEntity> map = Maps.newHashMap();

        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);
            //鍙戣捣鏃堕棿
            Date wt09 = Orlfs.getDate("wt09");
            taskFs.setValue("send_time", wt09);
            //缁撴潫鏃堕棿
            taskFs.setValue("finish_time", Orlfs.getDate("wt10"));
            //鍏宠仈娴佺▼琛�
            taskFs.setValue("flow_uuid", modelUUID);
            //瀹屾垚鏍囪瘑锛�1-鍦ㄥ姙锛�2-姝e父缁撴潫锛�3-缁堟锛�
            taskFs.setValue("finish_type", this.finishType(Orlfs.getString("wt16")));
            //鍏宠仈琛�
            String tbName = Orlfs.getString("wt03").split("\\.")[1];

            taskFs.setValue("table_name", this.originalTable.getString(tbName));
            //褰撳墠鐜妭鑺傜偣uuid
            taskFs.setValue("id", 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", id);
            taskFs.setValue("created_utc_datetime", wt09);
            baseDao.add(taskFs);
            map.put(Orlfs.getString("wt00"), taskFs);
        }
        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=utf8mb4 COLLATE=utf8mb4_bin 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 = "datetime";
                break;
            case "PROMPT":
                mysql_field_type = "string";
                break;
            case "SORT":
                mysql_field_type = "string";
                break;
            case "MEDIA":
                mysql_field_type = "file";
                break;
            case "SPFLAG":
                mysql_field_type = "flowsign";
                break;
            case "IMAGE":
                mysql_field_type = "file";
                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) {
            e.getStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
            throw new BaseException(SystemCode.SQL_START_FAILED.getValue(), SystemCode.SQL_START_FAILED.getText() + e.getMessage());
        }
    }

    @Override
    public void run() {
        //灏佽涓よ竟浜哄憳鍏宠仈鍜岄儴闂ㄥ叧鑱�
        this.packageDepartmentPersonnel();
        nodesIdUUID = new JSONObject();
        //鍚屾琛ㄥ強鍩虹鏁版嵁
        String sf28 = null;
        Connection conn = null;
        try {
            conn = this.getJDBC();
        } catch (SQLException e) {
            e.printStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
        }
        String moduleUUID = null;
        //鑻ュ凡鏈夎〃鍚屾  mvc鏍囪瘑 琛ㄧず浠庡姛鑳藉紑濮嬪悓姝�
        if(tricode_funs.indexOf("mvc") != -1){ //mvc 瑕佸甫涓婂悓琛ㄧ殑澶氫釜鍔熻兘
            //鍙悓姝vc
            String[] funs = this.tricode_funs.split("mvc");
            try {
                sf28 = this.synchronizeTablesData(conn, funs[0]);
                String tableName = sf28.split("\\.")[1];
                this.originalTable.put(tableName, tableName.toLowerCase());
                for (int i = 0; i < funs.length; i++) {
                    //褰撳墠鍔熻兘
                    this.tricode_funs = funs[i];
                    //鍚屾鍔熻兘
                    moduleUUID = this.synchronizationModuleName(conn, funs[i], sf28);
                    //琛ㄥ悕鏌ヨ鍔熻兘
                    FieldSetEntity fse =  baseDao.getFieldSetBySQL("SELECT a.* FROM product_sys_functions a LEFT JOIN product_sys_datamodel_table b on a.table_uuid = b.uuid WHERE b.table_name = ?", new String[]{ tableName.toLowerCase()}, false);
                    String functionUuid = fse.getUUID();
                    //淇敼宸插悓姝ラ檮浠� 娣诲姞 module_uuid function_uuid
                    baseDao.executeUpdate(" UPDATE product_sys_attachments SET module_uuid = ?, function_uuid = ? WHERE attachment_data_table = ? AND function_uuid is null ",new String[]{moduleUUID, functionUuid,  tableName.toLowerCase()});
                    //鍚屾娴佺▼
                    this.syncFlow(conn, moduleUUID, sf28);
                }

            } catch (SQLException e) {
                e.printStackTrace();
                SpringMVCContextHolder.getSystemLogger().error(e);
            }
        }else {
            try {
                sf28 = this.synchronizeTablesData(conn, this.tricode_funs);
            } catch (SQLException e) {
                e.printStackTrace();
                SpringMVCContextHolder.getSystemLogger().error(e);
            }
            String table_name = sf28.split("\\.")[1];
            String myTableName = this.originalTable.getString(table_name);
            if (!isStr(sf28)) {
                //鍚屾mvc
                try {
                    moduleUUID = this.synchronizationModuleName(conn, this.tricode_funs, sf28);
                } catch (SQLException e) {
                    e.printStackTrace();
                    SpringMVCContextHolder.getSystemLogger().error(e);
                }
            } 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[]{myTableName}, false);
                moduleUUID = fieldSetEntity.getUUID();
            }
            if (!isStr(sf28))  {
                this.syncFlow(conn, moduleUUID, sf28);
            }
            //琛ㄥ悕鏌ヨ鍔熻兘
            FieldSetEntity fse =  baseDao.getFieldSetBySQL("SELECT a.* FROM product_sys_functions a LEFT JOIN product_sys_datamodel_table b on a.table_uuid = b.uuid WHERE b.table_name = ?", new String[]{myTableName}, false);
            String functionUuid = fse.getUUID();
            //淇敼宸插悓姝ラ檮浠� 娣诲姞 module_uuid function_uuid
            baseDao.executeUpdate(" UPDATE product_sys_attachments SET module_uuid = ?, function_uuid = ? WHERE attachment_data_table = ? AND function_uuid is null ",new String[]{moduleUUID, functionUuid, myTableName});
        }
        try {
            DataManipulationUtils.close(null, null, conn);
        } catch (SQLException e) {
            e.printStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
        }
    }

    /**
     * 鍚屾娴佺▼
     * @param conn jdbc杩炴帴
     * @param moduleUUID 妯″潡uuid
     * @param sf28 琛ㄥ悕
     */
    public void syncFlow(Connection conn, String moduleUUID, String sf28){

        //鏌ヨ涓诲叕鍙竨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);
        try {
            //杩佺Щ wf_model娴佺▼妯″潡琛�
            String typeCode = this.syncModel(tricode_funs, conn, moduleUUID, sf28, null, 1, null,false);
            //鏍规嵁瑕佹眰娴佺▼瑕佸悓姝ヤ袱娆� 鐩稿悓娴佺▼鐨則ypeCode鐩稿悓
            if(!BaseUtil.strIsNull(typeCode)){
                this.syncModel(tricode_funs, conn, moduleUUID, sf28, fieldSetEntity.getUUID(), user.getInteger("user_id"), typeCode,true);
            }
        } catch (SQLException e) {
            e.printStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
        }
        //鍒濆鍖栬彍鍗曠紦瀛�
//        systemMenusService.initSystemMenu();
        System.out.println("================="+tricode_funs+"鍚屾鎴愬姛===============");
    }

}