许鹏程
2024-05-28 e6720f333268682d11aedb3b3308fa2f2c3a40df
product-server-data-sync/src/main/java/com/product/data/sync/service/FeDataDSService.java
@@ -45,245 +45,256 @@
@Component
public class FeDataDSService extends AbstractBaseService {
    @Autowired
    public BaseDao baseDao;
    @Autowired
    private UserService userService;
    @Autowired
    private CodeService codeService;
    @Autowired
    private SystemOrgLevelsService systemOrgLevelsService;
   @Autowired
   public BaseDao baseDao;
   @Autowired
   private UserService userService;
   @Autowired
   private CodeService codeService;
   @Autowired
   private SystemOrgLevelsService systemOrgLevelsService;
    @Autowired
    public FunctionSynchrService functionSynchrService;
    @Autowired
    FileManagerService fileManagerService;
   @Autowired
   public FunctionSynchrService functionSynchrService;
   @Autowired
   FileManagerService fileManagerService;
    //临时文件路径
    private static String TSPath = Global.getSystemConfig("new.filePackage","");
    private static String testString = "^(\\d{0,4}`)|(\\d{0,3}\\^\\d{0,4}`)";
    private static String startWith = "FE#ENC#";
    private int[] intPosition = new int[64];
    //我们产品的功能权限
    private String[] functionCode = {"001-004-000-000","001-004-000-001","001-004-000-002","001-004-000-003","001-004-000-004",
            "001-006-006-000","001-006-002-000","001-006-000-000","001-006-001-000",
            "001-006-001-001","001-006-000-001", "001-006-002-001" ,"001-006-002-002","001-006-004-000",
            "001-006-003-000","001-006-002-003","001-006-003-001","001-006-003-002","001-006-003-003",
            "001-006-004-001","001-006-003-004","001-006-003-005","001-006-003-006","001-006-006-001",
            "001-006-008-000","001-006-008-001","001-006-008-002", "001-006-008-003","001-006-008-004",
            "001-006-008-005","001-006-008-006", "001-006-000-003", "001-006-011-000","001-006-011-001",
            "001-008-001-001","001-008-001-000","001-008-001-003"};
   //临时文件路径
   private static String TSPath = Global.getSystemConfig("new.filePackage", "");
   private static String testString = "^(\\d{0,4}`)|(\\d{0,3}\\^\\d{0,4}`)";
   private static String startWith = "FE#ENC#";
   private int[] intPosition = new int[64];
   //我们产品的功能权限
   private String[] functionCode = {"001-004-000-000", "001-004-000-001", "001-004-000-002", "001-004-000-003", "001-004-000-004",
         "001-006-006-000", "001-006-002-000", "001-006-000-000", "001-006-001-000",
         "001-006-001-001", "001-006-000-001", "001-006-002-001", "001-006-002-002", "001-006-004-000",
         "001-006-003-000", "001-006-002-003", "001-006-003-001", "001-006-003-002", "001-006-003-003",
         "001-006-004-001", "001-006-003-004", "001-006-003-005", "001-006-003-006", "001-006-006-001",
         "001-006-008-000", "001-006-008-001", "001-006-008-002", "001-006-008-003", "001-006-008-004",
         "001-006-008-005", "001-006-008-006", "001-006-000-003", "001-006-011-000", "001-006-011-001",
         "001-008-001-001", "001-008-001-000", "001-008-001-003"};
    private Integer sort = 0;
    //公司和部门map   key 为公司或部门全称
    Map<String, FieldSetEntity> institutionMap = Maps.newHashMap();
    public Connection getJDBC() throws SQLException, ClassNotFoundException {
        //获取jdbc连接
   private Integer sort = 0;
   //公司和部门map   key 为公司或部门全称
   Map<String, FieldSetEntity> institutionMap = Maps.newHashMap();
   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);
    }
      //获取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);
   }
    public String FEDataMigration(){
        String clientUUID = "";
        try {
            //admin初始化客户及角色
            clientUUID = this.initializeClients();
            //同步公司部门
            this.syncDepartmentCompany();
            //封装公司部门map
            this.packInstitutionMap();
            //同步岗位等级和岗位
            this.synchronousPost();
            //同步角色
            this.synchronousRole();
            //同步管理员
            this.syncManager(clientUUID);
            //同步人员
            this.addEmployees(clientUUID);
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return clientUUID;
    }
   public String FEDataMigration() {
      String clientUUID = "";
      try {
         //admin初始化客户及角色
         clientUUID = this.initializeClients();
         //同步公司部门
         this.syncDepartmentCompany();
         //封装公司部门map
         this.packInstitutionMap();
         //同步岗位等级和岗位
         this.synchronousPost();
//            //同步角色
//            this.synchronousRole();
         //同步管理员
//         this.syncManager(clientUUID);
         //同步人员
         this.addEmployees(clientUUID);
      } catch (SQLException e) {
         logger.error("FEDataMigration", e);
         e.printStackTrace();
      } catch (ClassNotFoundException e) {
         logger.error("FEDataMigration", e);
         e.printStackTrace();
      }
      return clientUUID;
   }
    /**
     *    初始化客户及客户角色(修改客户为FE的客户名称)
     * @return
     * @throws SQLException
     * @throws ClassNotFoundException
     */
    public String initializeClients() throws SQLException, ClassNotFoundException {
        FieldSetEntity grouoFs = null;
        Connection conn = this.getJDBC();
        try {
            grouoFs = BaseDaoServiceImpl.getFieldSet(conn, "fe_base5.SYS_GROUP", "SG10=1", new Object[]{});
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            throw e;
        }
        //查询原客户  改为西宁
        FieldSetEntity tableFs = baseDao.getFieldSetEntityByFilter("product_sys_clients", " client_code = ? ", new String[]{"001"},false);
        if (tableFs==null) {
   /**
    * 初始化客户及客户角色(修改客户为FE的客户名称)
    *
    * @return
    * @throws SQLException
    * @throws ClassNotFoundException
    */
   public String initializeClients() throws SQLException, ClassNotFoundException {
      FieldSetEntity grouoFs = null;
      Connection conn = this.getJDBC();
      try {
         grouoFs = BaseDaoServiceImpl.getFieldSet(conn, "fe_base5.SYS_GROUP", "SG10=1", new Object[]{});
      } catch (Exception e) {
         DataManipulationUtils.close(null, null, conn);
         throw e;
      }
      //查询原客户  改为西宁
      FieldSetEntity tableFs = baseDao.getFieldSetEntityByFilter("product_sys_clients", " client_code = ? ", new String[]{"001"}, false);
      if (tableFs == null) {
         throw new BaseException("500", "客户表没有001的数据");
      }
        //原客户名称
        String clientName = tableFs.getString("client_name");
        tableFs.setValue("client_name", grouoFs.getString("sg01"));
        String clientUUID = tableFs.getUUID();
        //查询原客户的角色  改为西宁
        FieldSetEntity roleFs = baseDao.getFieldSetEntityByFilter("product_sys_role", " role_name = ? ", new String[]{clientName}, false);
        roleFs.setValue("role_name", grouoFs.getString("sg01"));
        //修改角色
        baseDao.update(roleFs);
        //修改客户
      //原客户名称
      String clientName = tableFs.getString("client_name");
      tableFs.setValue("client_name", grouoFs.getString("sg01"));
      String clientUUID = tableFs.getUUID();
      //查询原客户的角色  改为西宁
      FieldSetEntity roleFs = baseDao.getFieldSetEntityByFilter("product_sys_role", " role_name = ? ", new String[]{clientName}, false);
      roleFs.setValue("role_name", grouoFs.getString("sg01"));
      //修改角色
      baseDao.update(roleFs);
      //修改客户
//        tableFs.setCodeFieldUpdateFlat("client_code", true);
        baseDao.update(tableFs);
        return clientUUID;
    }
      baseDao.update(tableFs);
      return clientUUID;
   }
    /**
     * 同步单位管理员
     */
    public void syncManager(String clientUUID) throws SQLException, ClassNotFoundException {
        Connection conn = this.getJDBC();
        DataTableEntity managerData;
        try {
            //获取岗位 修改/ 为> 方便适配我们数据表
            StringBuffer sql = new StringBuffer();
            sql.append(" SELECT A.*,REPLACE(REPLACE(REPLACE(A.SU03, '/西宁市住房保障和房产管理局', ''),  ")
                    .append(" '西宁市住房保障和房产管理局/局属各单位/','西宁市住房保障和房产管理局/'),'/','>') ASU03 FROM  ")
                    .append(" FE_BASE5.SYS_USERS A WHERE A.SU31 = 2 ");
            //人员数据
            managerData = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new Object[]{});
            this.syncManager(managerData, clientUUID);
        } catch (Exception e) {
            throw e;
        }
    }
   /**
    * 同步单位管理员
    */
   public void syncManager(String clientUUID) throws SQLException, ClassNotFoundException {
      Connection conn = this.getJDBC();
      DataTableEntity managerData;
      try {
         //获取岗位 修改/ 为> 方便适配我们数据表
         StringBuffer sql = new StringBuffer();
         sql.append(" SELECT A.*,REPLACE(REPLACE(REPLACE(A.SU03, '/西宁市住房保障和房产管理局', ''),  ")
               .append(" '西宁市住房保障和房产管理局/局属各单位/','西宁市住房保障和房产管理局/'),'/','>') ASU03 FROM  ")
               .append(" FE_BASE5.SYS_USERS A WHERE A.SU31 = 2 ");
         //人员数据
         managerData = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new Object[]{});
         this.syncManager(managerData, clientUUID);
      } catch (Exception e) {
         throw e;
      }
   }
    /**
     *  同步管理员
     * @param managerData 管理员用户数据
     */
    public void syncManager(DataTableEntity managerData,String clientUUID){
        if(!BaseUtil.dataTableIsEmpty(managerData)) {
            for (int i = 0; i < managerData.getRows(); i++) {
                FieldSetEntity userFs = new FieldSetEntity();
                FieldSetEntity fse = managerData.getFieldSetEntity(i);
                userFs.setTableName("product_sys_users");
                String su01 = fse.getString("su01");
                userFs.setValue("user_name", su01);
                userFs.setValue("user_account",su01);
                userFs.setValue("gender", 1);
                userFs.setValue("user_pwd", userService.createPassWord(su01, "123"));
                userFs.setValue("is_manager", 1);
                userFs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id());
                userFs.setValue("created_utc_datetime", new Date());
                userFs.setValue("status", 1);
   /**
    * 同步管理员
    *
    * @param managerData 管理员用户数据
    */
   public void syncManager(DataTableEntity managerData, String clientUUID) {
      if (!BaseUtil.dataTableIsEmpty(managerData)) {
         for (int i = 0; i < managerData.getRows(); i++) {
            FieldSetEntity userFs = new FieldSetEntity();
            FieldSetEntity fse = managerData.getFieldSetEntity(i);
            userFs.setTableName("product_sys_users");
            String su01 = fse.getString("su01");
            userFs.setValue("user_name", su01);
            userFs.setValue("user_account", su01);
            userFs.setValue("gender", 1);
            userFs.setValue("user_pwd", userService.createPassWord(su01, "123"));
            userFs.setValue("is_manager", 1);
            userFs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id());
            userFs.setValue("created_utc_datetime", new Date());
            userFs.setValue("status", 1);
                //新增管理员
                String usersUUID = baseDao.add(userFs);
                FieldSetEntity users = baseDao.getFieldSetEntity("product_sys_users", usersUUID, false);
                FieldSetEntity managerFs = new FieldSetEntity();
                managerFs.setTableName("product_sys_org_manager");
                managerFs.setValue("user_id", users.getString("user_id"));
                //企业管理员
                managerFs.setValue("manager_type", "2");
                managerFs.setValue("role_uuids", "eabb00f3-2118-4165-967b-a7d88f472f67-notchange");
                managerFs.setValue("is_used", 1);
                managerFs.setValue("clients_uuid", clientUUID);
                managerFs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id());
                managerFs.setValue("created_utc_datetime", new Date());
                //重新组装后的组织全称
                String uuid = this.getSuperiorCompanyUuid(fse.getString("asu03"));
                managerFs.setValue("org_level_uuid", uuid);
                baseDao.add(managerFs);
            }
            //新增管理员
            String usersUUID = baseDao.add(userFs);
            FieldSetEntity users = baseDao.getFieldSetEntity("product_sys_users", usersUUID, false);
            FieldSetEntity managerFs = new FieldSetEntity();
            managerFs.setTableName("product_sys_org_manager");
            managerFs.setValue("user_id", users.getString("user_id"));
            //企业管理员
            managerFs.setValue("manager_type", "2");
            managerFs.setValue("role_uuids", "eabb00f3-2118-4165-967b-a7d88f472f67-notchange");
            managerFs.setValue("is_used", 1);
            managerFs.setValue("clients_uuid", clientUUID);
            managerFs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id());
            managerFs.setValue("created_utc_datetime", new Date());
            //重新组装后的组织全称
            String uuid = this.getSuperiorCompanyUuid(fse.getString("asu03"));
            managerFs.setValue("org_level_uuid", uuid);
            baseDao.add(managerFs);
         }
        }
    }
      }
   }
    /**
     * 同步公司部门
     */
    public void syncDepartmentCompany() throws SQLException, ClassNotFoundException {
   /**
    * 同步公司部门
    */
   public void syncDepartmentCompany() throws SQLException, ClassNotFoundException {
       //同步组织机构数据存放集合
        DataTableEntity groupLeadersFs;
        Connection conn = this.getJDBC();
        try {
            StringBuffer sql = new StringBuffer();
            sql.append("SELECT A.*,REPLACE(REPLACE(A.SG03, '/西宁市住房保障和房产管理局', ''), '西宁市住房保障和房产管理局/局属各单位/','西宁市住房保障和房产管理局/') ASG03 FROM ( ")
                   .append( "SELECT * FROM FE_BASE5.SYS_GROUP WHERE length(SG10) > 3 or SG10 = '001'  ORDER BY SG10) A ORDER BY SG10");
            //获取需要同步的组织机构
            groupLeadersFs = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new Object[]{});
        } catch (Exception e) {
            throw e;
        }
        DataManipulationUtils.close(null, null, conn);
        //创建顶级公司
        //获取FE顶级公司
        FieldSetEntity topCompanies = groupLeadersFs.getFieldSetEntity(0);
        //获取产品001顶级公司
        FieldSetEntity field = baseDao.getFieldSetEntityByFilter("product_sys_org_levels", " org_level_code = 001 ", null,false);
        //更新公司名称,公司短编码,公司排序
        field.setValue("org_level_name", topCompanies.getString("sg01"));
        field.setValue("org_level_shortcode",  topCompanies.getString("sg10"));
        field.setValue("sequence",  topCompanies.getString("sg00"));
      //同步组织机构数据存放集合
      DataTableEntity groupLeadersFs;
      Connection conn = this.getJDBC();
      try {
         StringBuffer sql = new StringBuffer();
         sql.append("SELECT A.*,REPLACE(REPLACE(A.SG03, '/西宁市住房保障和房产管理局', ''), '西宁市住房保障和房产管理局/局属各单位/','西宁市住房保障和房产管理局/') ASG03 FROM ( ")
               .append("SELECT * FROM FE_BASE5.SYS_GROUP WHERE length(SG10) > 3 or SG10 = '001'  ORDER BY SG10) A ORDER BY SG10");
         //获取需要同步的组织机构
         groupLeadersFs = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new Object[]{});
      } catch (Exception e) {
         throw e;
      }
      DataManipulationUtils.close(null, null, conn);
      //创建顶级公司
      //获取FE顶级公司
      FieldSetEntity topCompanies = groupLeadersFs.getFieldSetEntity(0);
      //获取产品001顶级公司
      FieldSetEntity field = baseDao.getFieldSetEntityByFilter("product_sys_org_levels", " org_level_code = 001 ", null, false);
      //更新公司名称,公司短编码,公司排序
      field.setValue("org_level_name", topCompanies.getString("sg01"));
      field.setValue("org_level_shortcode", topCompanies.getString("sg10"));
      field.setValue("sequence", topCompanies.getString("sg00"));
//      field.setCodeFieldUpdateFlat("org_level_code", true);
        //事物调用,保存公司信息
        ISystemOrgLevelsService service=(ISystemOrgLevelsService) getProxyInstance(systemOrgLevelsService);
        service.updateCompany(field);
      //事物调用,保存公司信息
      ISystemOrgLevelsService service = (ISystemOrgLevelsService) getProxyInstance(systemOrgLevelsService);
      service.updateCompany(field);
//        FieldSetEntity topField = this.addCompany(topCompanies,null, null);
        institutionMap.put(field.getString("org_level_all"),field);
        //遍历fe架构数据 存入组织架构信息表
        for (int i = 1; i < groupLeadersFs.getRows(); i++) {
            FieldSetEntity levelFs = groupLeadersFs.getFieldSetEntity(i);
            //获取FE表组织机构全称
            String asg03 = levelFs.getString("asg03");
            //截取为上级公司相同的全称
            String level_all = asg03.substring(0,asg03.lastIndexOf("/"));
            //替换为一样的符号方便对比
            level_all = level_all.replace("/", ">");
            //获取上级公司或部门
            FieldSetEntity fieldSet = institutionMap.get(level_all);
            //上级公司uuid
            String org_level_uuid = this.getSuperiorCompanyUuid(level_all);
            if(fieldSet == null){
                throw new BaseException("上级为空","无法获取上级code");
            }
            if(org_level_uuid == null){
                throw new BaseException("上级公司为空","上级公司uuid");
            }
            //上级公司code
            String org_level_code = fieldSet.getString("org_level_code");
            FieldSetEntity fse;
      institutionMap.put(field.getString("org_level_all"), field);
      //遍历fe架构数据 存入组织架构信息表
      for (int i = 1; i < groupLeadersFs.getRows(); i++) {
         FieldSetEntity levelFs = groupLeadersFs.getFieldSetEntity(i);
         //获取FE表组织机构全称
         String asg03 = levelFs.getString("asg03");
         String levelAll = asg03.replaceAll("/", ">");
         levelFs = baseDao.getFieldSetByFilter("product_sys_org_levels", "org_level_all=?", new Object[]{levelAll}, false);
         if (levelFs != null && !StringUtils.isEmpty(levelFs.getUUID())) {
            institutionMap.put(levelFs.getString("org_level_all"), levelFs);
            continue;
         }
         //截取为上级公司相同的全称
         String level_all = asg03.substring(0, asg03.lastIndexOf("/"));
         //替换为一样的符号方便对比
         level_all = level_all.replace("/", ">");
         //获取上级公司或部门
         FieldSetEntity fieldSet = institutionMap.get(level_all);
         //上级公司uuid
         String org_level_uuid = this.getSuperiorCompanyUuid(level_all);
         if (fieldSet == null) {
            throw new BaseException("上级为空", "无法获取上级code");
         }
         if (org_level_uuid == null) {
            throw new BaseException("上级公司为空", "上级公司uuid");
         }
         //上级公司code
         String org_level_code = fieldSet.getString("org_level_code");
         FieldSetEntity fse;
//            levelFs.setCodeFieldUpdateFlat("org_level_code", true);
            //进入新增公司方法
            if(levelFs.getInteger("sg14") == 1){
                fse = this.addCompany(levelFs,org_level_code,org_level_uuid);
            //进入新增部门方法
            }else {
                fse = this.addDepartment(levelFs, org_level_code, org_level_uuid);
            }
            institutionMap.put(fse.getString("org_level_all"), fse);
        }
         //进入新增公司方法
         if (levelFs.getInteger("sg14") == 1) {
            fse = this.addCompany(levelFs, org_level_code, org_level_uuid);
            //进入新增部门方法
         } else {
            fse = this.addDepartment(levelFs, org_level_code, org_level_uuid);
         }
         institutionMap.put(fse.getString("org_level_all"), fse);
      }
//        //创建西宁市住房保障和房产管理局下部门(办公室)
//        FieldSetEntity fse = new FieldSetEntity();
@@ -295,374 +306,395 @@
//        FieldSetEntity fieldSet = institutionMap.get("西宁市住房保障和房产管理局");
//        FieldSetEntity fs = this.addDepartment(fse,fieldSet.getString("org_level_code"), fieldSet.getUUID());
//        institutionMap.put(fs.getString("org_level_all"), fs);
    }
   }
    /**
     * 同步岗位和岗位等级
     */
    public void synchronousPost() throws SQLException, ClassNotFoundException {
   /**
    * 同步岗位和岗位等级
    */
   public void synchronousPost() throws SQLException, ClassNotFoundException {
        Connection conn = this.getJDBC();
        DataTableEntity groupLeadersFs;
        try {
            //获取岗位 修改/ 为> 方便适配我们数据表
            StringBuffer sql = new StringBuffer();
            sql.append(" SELECT SR00,SR01,SR02,SR10, SR15, ")
                    .append(" REPLACE(REPLACE(REPLACE(SR03, '/西宁市住房保障和房产管理局', ''),  ")
                    .append(" '西宁市住房保障和房产管理局/局属各单位/','西宁市住房保障和房产管理局/'),'/','>') ASR03 FROM fe_base5.SYS_ROLE  ");
            //1为公司
            groupLeadersFs = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new Object[]{});
        } catch (Exception e) {
      Connection conn = this.getJDBC();
      DataTableEntity groupLeadersFs;
      try {
         //获取岗位 修改/ 为> 方便适配我们数据表
         StringBuffer sql = new StringBuffer();
         sql.append(" SELECT SR00,SR01,SR02,SR10, SR15, ")
               .append(" REPLACE(REPLACE(REPLACE(SR03, '/西宁市住房保障和房产管理局', ''),  ")
               .append(" '西宁市住房保障和房产管理局/局属各单位/','西宁市住房保障和房产管理局/'),'/','>') ASR03 FROM fe_base5.SYS_ROLE  ");
         //1为公司
         groupLeadersFs = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new Object[]{});
      } catch (Exception e) {
            throw e;
        }
        DataManipulationUtils.close(null, null, conn);
        //同步岗位等级
        this.postGrades(groupLeadersFs);
        this.addPost(groupLeadersFs);
    }
         throw e;
      }
      DataManipulationUtils.close(null, null, conn);
      //同步岗位等级
      this.postGrades(groupLeadersFs);
      this.addPost(groupLeadersFs);
   }
    /**
     * 同步角色
     */
    public void synchronousRole()throws  SQLException, ClassNotFoundException{
        Connection conn = this.getJDBC();
        DataTableEntity roleData;
        try {
            //获取岗位 修改/ 为> 方便适配我们数据表
            StringBuffer sql = new StringBuffer();
            sql.append(" select * from fe_base5.SYS_POPEDOM_TEMPLET a left join fe_base5.SYS_POPEDOM_TEMP_SUB b on  a.SPT00=b.STS01 ");
            //人员数据
            roleData = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new Object[]{});
   /**
    * 同步角色
    */
   public void synchronousRole() throws SQLException, ClassNotFoundException {
      Connection conn = this.getJDBC();
      DataTableEntity roleData;
      try {
         //获取岗位 修改/ 为> 方便适配我们数据表
         StringBuffer sql = new StringBuffer();
         sql.append(" select * from fe_base5.SYS_POPEDOM_TEMPLET a left join fe_base5.SYS_POPEDOM_TEMP_SUB b on  a.SPT00=b.STS01 ");
         //人员数据
         roleData = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new Object[]{});
        } catch (Exception e) {
            throw e;
        }
        DataManipulationUtils.close(null, null, conn);
        this.synchronousRole(roleData);
      } catch (Exception e) {
         throw e;
      }
      DataManipulationUtils.close(null, null, conn);
      this.synchronousRole(roleData);
    }
   }
    /**
     * 初始化基本权限
     */
    public void packageButton(String role_uuid){
        StringBuffer sql = new StringBuffer();
        String tricodeIn = BaseUtil.buildQuestionMarkFilter("tricode", this.functionCode, true);
        sql.append(" SELECT function_uuid,group_concat(uuid SEPARATOR ',') button_uuid FROM  product_sys_function_buttons WHERE function_uuid IN ( ")
                .append(" SELECT uuid FROM product_sys_functions WHERE ")
                .append(tricodeIn).append(" ) GROUP BY function_uuid ");
        DataTableEntity dataTableEntity = baseDao.listTable(sql.toString(),new String[]{});
        for (int i = 0; i < dataTableEntity.getRows(); i++) {
            FieldSetEntity fieldSetEntity = new FieldSetEntity();
            fieldSetEntity.setTableName("product_sys_function_permission");
            fieldSetEntity.setValue("function_uuid", dataTableEntity.getString(i,"function_uuid"));
            fieldSetEntity.setValue("button_uuid", dataTableEntity.getString(i,"button_uuid"));
            fieldSetEntity.setValue("role_uuid", role_uuid);
            baseDao.add(fieldSetEntity);
        }
    }
   /**
    * 初始化基本权限
    */
   public void packageButton(String role_uuid) {
      StringBuffer sql = new StringBuffer();
      String tricodeIn = BaseUtil.buildQuestionMarkFilter("tricode", this.functionCode, true);
      sql.append(" SELECT function_uuid,group_concat(uuid SEPARATOR ',') button_uuid FROM  product_sys_function_buttons WHERE function_uuid IN ( ")
            .append(" SELECT uuid FROM product_sys_functions WHERE ")
            .append(tricodeIn).append(" ) GROUP BY function_uuid ");
      DataTableEntity dataTableEntity = baseDao.listTable(sql.toString(), new String[]{});
      for (int i = 0; i < dataTableEntity.getRows(); i++) {
         FieldSetEntity fieldSetEntity = new FieldSetEntity();
         fieldSetEntity.setTableName("product_sys_function_permission");
         fieldSetEntity.setValue("function_uuid", dataTableEntity.getString(i, "function_uuid"));
         fieldSetEntity.setValue("button_uuid", dataTableEntity.getString(i, "button_uuid"));
         fieldSetEntity.setValue("role_uuid", role_uuid);
         baseDao.add(fieldSetEntity);
      }
   }
    /**
     * 同步人员
     */
    public void addEmployees(String clientUUID) throws SQLException, ClassNotFoundException {
   /**
    * 同步人员
    */
   public void addEmployees(String clientUUID) throws SQLException, ClassNotFoundException {
        Connection conn = this.getJDBC();
        DataTableEntity personnelData;
        try {
            //获取岗位 修改/ 为> 方便适配我们数据表
            StringBuffer sql = new StringBuffer();
      Connection conn = this.getJDBC();
      DataTableEntity personnelData;
      try {
         //获取岗位 修改/ 为> 方便适配我们数据表
         StringBuffer sql = new StringBuffer();
//            sql.append(" SELECT A.*,REPLACE(REPLACE(REPLACE(A.SU03, '/西宁市住房保障和房产管理局', ''),  ")
//                    .append(" '西宁市住房保障和房产管理局/局属各单位/','西宁市住房保障和房产管理局/'),'/','>') ASU03 FROM  ")
//                    .append(" FE_BASE5.SYS_USERS A WHERE A.SU39 is not null and A.SU35 is not null AND A.SU03 IS NOT NULL ");
            sql.append(" SELECT A.*,REPLACE(REPLACE(REPLACE(A.SU03, '/西宁市住房保障和房产管理局', ''),  ")
            .append(" '西宁市住房保障和房产管理局/局属各单位/','西宁市住房保障和房产管理局/'),'/','>') ASU03 FROM  ")
            .append(" FE_BASE5.SYS_USERS A WHERE SU39 IS NOT NULL");
            //人员数据
            personnelData = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new Object[]{});
        } catch (Exception e) {
            throw e;
        }
        DataManipulationUtils.close(null, null, conn);
        this.addEmployees(personnelData,clientUUID);
    }
         sql.append(" SELECT A.*,REPLACE(REPLACE(REPLACE(A.SU03, '/西宁市住房保障和房产管理局', ''),  ")
               .append(" '西宁市住房保障和房产管理局/局属各单位/','西宁市住房保障和房产管理局/'),'/','>') ASU03 FROM  ")
               .append(" FE_BASE5.SYS_USERS A WHERE SU39 IS NOT NULL");
         //人员数据
         personnelData = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new Object[]{});
      } catch (Exception e) {
         throw e;
      }
      DataManipulationUtils.close(null, null, conn);
      this.addEmployees(personnelData, clientUUID);
   }
    /**
     * 递归获取上级公司uuid
     * @param level_all 上级公司全称
     * @return 保存后返回保存后的 fse
     */
    public String getSuperiorCompanyUuid(String level_all){
        FieldSetEntity fieldSet = institutionMap.get(level_all);
        if(fieldSet == null){
            return null;
        }
        //上级为公司
        if("0".equals(fieldSet.getString("org_level_type"))){
            return fieldSet.getUUID();
        }else {
            Integer index = level_all.lastIndexOf(">");
            if(index == -1){
                return null;
            }
            level_all = level_all.substring(0,index);
            return this.getSuperiorCompanyUuid(level_all);
        }
    }
   /**
    * 递归获取上级公司uuid
    *
    * @param level_all 上级公司全称
    * @return 保存后返回保存后的 fse
    */
   public String getSuperiorCompanyUuid(String level_all) {
      FieldSetEntity fieldSet = institutionMap.get(level_all);
      if (fieldSet == null) {
         return null;
      }
      //上级为公司
      if ("0".equals(fieldSet.getString("org_level_type"))) {
         return fieldSet.getUUID();
      } else {
         Integer index = level_all.lastIndexOf(">");
         if (index == -1) {
            return null;
         }
         level_all = level_all.substring(0, index);
         return this.getSuperiorCompanyUuid(level_all);
      }
   }
    /**
     * 保存公司
     * @param fse 公司fes
     * @param code_parent 公司上级code
     * @return 保存后返回保存后的 fse
     */
    public FieldSetEntity addCompany(FieldSetEntity fse, String code_parent, String org_level_uuid){
        FieldSetEntity levelsFs = new FieldSetEntity();
        levelsFs.setTableName("product_sys_org_levels");
        //部门名称,,
        levelsFs.setValue("org_level_name", fse.getString("sg01"));
   /**
    * 保存公司
    *
    * @param fse         公司fes
    * @param code_parent 公司上级code
    * @return 保存后返回保存后的 fse
    */
   public FieldSetEntity addCompany(FieldSetEntity fse, String code_parent, String org_level_uuid) {
      FieldSetEntity levelsFs = new FieldSetEntity();
      levelsFs.setTableName("product_sys_org_levels");
      //部门名称,,
      levelsFs.setValue("org_level_name", fse.getString("sg01"));
        //公司段编码
        levelsFs.setValue("org_level_shortcode",  fse.getString("sg10"));
        //公司排序
        levelsFs.setValue("sequence", ++sort);
        //放入上级code  生成code
        levelsFs.setValue("org_level_code_parent", code_parent);
        //上级公司uuid
        levelsFs.setValue("org_level_uuid", org_level_uuid);
        ISystemOrgLevelsService service=(ISystemOrgLevelsService) getProxyInstance(systemOrgLevelsService);
      //公司段编码
      levelsFs.setValue("org_level_shortcode", fse.getString("sg10"));
      //公司排序
      levelsFs.setValue("sequence", ++sort);
      //放入上级code  生成code
      levelsFs.setValue("org_level_code_parent", code_parent);
      //上级公司uuid
      levelsFs.setValue("org_level_uuid", org_level_uuid);
      ISystemOrgLevelsService service = (ISystemOrgLevelsService) getProxyInstance(systemOrgLevelsService);
//        levelsFs.setCodeFieldUpdateFlat("org_level_code", true);
        service.addCompany(levelsFs);
        return levelsFs;
    }
      service.addCompany(levelsFs);
      return levelsFs;
   }
    /**
     * 保存部门
     * @param fse 公司fes
     * @param code_parent 公司上级code
     * @return 保存后返回保存后的 fse
     */
    public FieldSetEntity addDepartment(FieldSetEntity fse, String code_parent, String org_level_uuid){
        FieldSetEntity levelsFs = new FieldSetEntity();
        levelsFs.setTableName("product_sys_org_levels");
        //部门名称,,
        levelsFs.setValue("org_level_name", fse.getString("sg01"));
        //部门编码
        levelsFs.setValue("org_level_shortcode",  fse.getString("sg10"));
        //公司排序
        levelsFs.setValue("sequence", fse.getString("sg00"));
        //放入上级code  生成code
        levelsFs.setValue("org_level_code_parent", code_parent);
        //上级公司uuid
        levelsFs.setValue("org_level_uuid", org_level_uuid);
        ISystemOrgLevelsService service=(ISystemOrgLevelsService) getProxyInstance(systemOrgLevelsService);
   /**
    * 保存部门
    *
    * @param fse         公司fes
    * @param code_parent 公司上级code
    * @return 保存后返回保存后的 fse
    */
   public FieldSetEntity addDepartment(FieldSetEntity fse, String code_parent, String org_level_uuid) {
      FieldSetEntity levelsFs = new FieldSetEntity();
      levelsFs.setTableName("product_sys_org_levels");
      //部门名称,,
      levelsFs.setValue("org_level_name", fse.getString("sg01"));
      //部门编码
      levelsFs.setValue("org_level_shortcode", fse.getString("sg10"));
      //公司排序
      levelsFs.setValue("sequence", fse.getString("sg00"));
      //放入上级code  生成code
      levelsFs.setValue("org_level_code_parent", code_parent);
      //上级公司uuid
      levelsFs.setValue("org_level_uuid", org_level_uuid);
      ISystemOrgLevelsService service = (ISystemOrgLevelsService) getProxyInstance(systemOrgLevelsService);
//        levelsFs.setCodeFieldUpdateFlat("org_level_code", true);
        service.addDepartment(levelsFs);
        return levelsFs;
    }
    /**
     * 封装公司部门全称 Map
     */
    public void packInstitutionMap()throws BaseException {
      DataTableEntity dataTableEntity = baseDao.listTable("SELECT * FROM product_sys_org_levels WHERE org_level_code like ? ", new String[]{"%001%"});
      if(!BaseUtil.dataTableIsEmpty(dataTableEntity)) {
          for (int i = 0; i < dataTableEntity.getRows(); i++) {
              FieldSetEntity fieldSetEntity = dataTableEntity.getFieldSetEntity(i);
              String org_level_all = fieldSetEntity.getString("org_level_all");
              institutionMap.put(org_level_all, fieldSetEntity);
          }
      }else {
          throw new BaseException("未查询到单位部门数据", "未查询到单位部门数据");
      }
    }
      service.addDepartment(levelsFs);
      return levelsFs;
   }
    /**
     * 同步角色
     */
    public void synchronousRole(DataTableEntity data){
        for (int i = 0; i < data.getRows(); i++) {
            FieldSetEntity rolesFs = data.getFieldSetEntity(i);
            String sts02s = rolesFs.getString("sts02");
            FieldSetEntity levelsField = baseDao.getFieldSetEntityByFilter("product_sys_org_levels", " org_level_shortcode = ? ", new String[]{sts02s}, false);
            //有些角色关联的单位或部门已经被删除掉,但是角色还保留他的编码   直接跳过
            if(levelsField == null){
                continue;
            }
            FieldSetEntity lxRoleFs = new FieldSetEntity();
            lxRoleFs.setTableName("product_sys_role");
            lxRoleFs.setValue("org_level_uuid",levelsField.getUUID());
            lxRoleFs.setValue("role_name", rolesFs.getString("spt01"));
            lxRoleFs.setValue("role_description", rolesFs.getString("spt02"));
            lxRoleFs.setValue("is_used", 1);
            lxRoleFs.setValue("sequence", rolesFs.getInteger("spt00"));
            this.userAndTime(lxRoleFs);
            String role_uuid = baseDao.add(lxRoleFs);
   /**
    * 封装公司部门全称 Map
    */
   public void packInstitutionMap() throws BaseException {
      DataTableEntity dataTableEntity = baseDao.listTable("SELECT * FROM product_sys_org_levels WHERE org_level_code like ? ", new String[]{"%001%"});
      if (!BaseUtil.dataTableIsEmpty(dataTableEntity)) {
         for (int i = 0; i < dataTableEntity.getRows(); i++) {
            FieldSetEntity fieldSetEntity = dataTableEntity.getFieldSetEntity(i);
            String org_level_all = fieldSetEntity.getString("org_level_all");
            institutionMap.put(org_level_all, fieldSetEntity);
         }
      } else {
         throw new BaseException("未查询到单位部门数据", "未查询到单位部门数据");
      }
   }
            //该角色初始化权限
            this.packageButton(role_uuid);
        }
    }
    /**
     * 添加用户和员工
     */
    public void addEmployees(DataTableEntity data,String clientUUID){
        //fe 人员id 对应  userid
        JSONObject idUserMap = new JSONObject();
        //获取客户uuid
        FieldSetEntity fieldSetEntity = baseDao.getFieldSetEntityByFilter("product_sys_org_levels", " org_level_code = ? ", new String[]{"001"}, false);
        String client_uuid = fieldSetEntity.getString("client_uuid");
        Map<String, FieldSetEntity> staffsMap = Maps.newHashMap();
        for (int i = 0; i < data.getRows(); i++) {
            FieldSetEntity userFs = data.getFieldSetEntity(i);
            FieldSetEntity usersFs = new FieldSetEntity();
            //创建 user 数据
            usersFs.setTableName("product_sys_users");
            //用户名
            usersFs.setValue("user_name", userFs.getString("su02"));
            //描述
            usersFs.setValue("user_account", userFs.getString("su01"));
            //邮箱
            usersFs.setValue("user_primary_email", userFs.getString("su11"));
            //性别转换
            String su16 = userFs.getString("su16");
            String sex = null;
            if (su16 != null) {
                sex = su16.equals("男") ? "0" : "1";
            }
            usersFs.setValue("gender", sex);
            //用户电话
            usersFs.setValue("user_mobile_number", userFs.getString("su10"));
            //内线电话
            usersFs.setValue("inside_phone", userFs.getString("su13"));
            //地址
            usersFs.setValue("contact_address", userFs.getString("su18"));
            //初始化用户密码
            usersFs.setValue("user_pwd", userService.createPassWord(userFs.getString("su01"), "123"));
            //是否是管理员 0:否 1:是
            usersFs.setValue("is_manager", 0);
            //办公电话
            usersFs.setValue("office_phone", userFs.getString("su09"));
            this.userAndTime(usersFs);
            //状态  0:禁用   1:正常
            usersFs.setValue("status",  userFs.getString("su08"));
            //签名
            String su23 = userFs.getString("su23");
            if (!BaseUtil.strIsNull(su23)) {
                    usersFs.setValue("user_signature", this.signatureAndThumbnail(su23, clientUUID,"user_signature"));
            }
            //头像
            String su28 = userFs.getString("su28");
            if (!BaseUtil.strIsNull(su28)) {
                usersFs.setValue("thumbnail_img", this.signatureAndThumbnail(su28, clientUUID,"thumbnail_img"));
            }
            String usersUUID = baseDao.add(usersFs);
            FieldSetEntity users = baseDao.getFieldSetEntity("product_sys_users", usersUUID, false);
            //fe用户id  关联系统表"product_sys_users)user_id
            idUserMap.put(userFs.getString("su00"), users.getString("user_id"));
            if (BaseUtil.strIsNull(userFs.getString("su03")) || BaseUtil.strIsNull(userFs.getString("su35")) || BaseUtil.strIsNull(userFs.getString("su39"))) {
   /**
    * 同步角色
    */
   public void synchronousRole(DataTableEntity data) {
      for (int i = 0; i < data.getRows(); i++) {
         FieldSetEntity rolesFs = data.getFieldSetEntity(i);
         String sts02s = rolesFs.getString("sts02");
         FieldSetEntity levelsField = baseDao.getFieldSetEntityByFilter("product_sys_org_levels", " org_level_shortcode = ? ", new String[]{sts02s}, false);
         //有些角色关联的单位或部门已经被删除掉,但是角色还保留他的编码   直接跳过
         if (levelsField == null) {
            continue;
         }
            FieldSetEntity staffsFs = new FieldSetEntity();
            //员工表
            staffsFs.setTableName("product_sys_staffs");
            //用户表id
            staffsFs.setValue("user_id", users.getString("user_id"));
            //显示名称
            staffsFs.setValue("show_name", userFs.getString("su02"));
            //员工名
            staffsFs.setValue("given_name", userFs.getString("su02"));
            //员工姓
            staffsFs.setValue("family_name", userFs.getString("su02"));
            //邮箱
            staffsFs.setValue("email_address", userFs.getString("su11"));
            //移动电话
            staffsFs.setValue("mobile_phone", userFs.getString("su10"));
            //办公电话
            staffsFs.setValue("office_telephone", userFs.getString("su09"));
         FieldSetEntity lxRoleFs = new FieldSetEntity();
         lxRoleFs.setTableName("product_sys_role");
         lxRoleFs.setValue("org_level_uuid", levelsField.getUUID());
         lxRoleFs.setValue("role_name", rolesFs.getString("spt01"));
         lxRoleFs.setValue("role_description", rolesFs.getString("spt02"));
         lxRoleFs.setValue("is_used", 1);
         lxRoleFs.setValue("sequence", rolesFs.getInteger("spt00"));
         this.userAndTime(lxRoleFs);
         String role_uuid = baseDao.add(lxRoleFs);
            //员工性别
            staffsFs.setValue("sex",  sex);
            //员工邮箱
            String su11 = userFs.getString("su11");
            //邮箱为空先覆1
            if(BaseUtil.strIsNull(su11)){
                su11 = "1";
            }
            staffsFs.setValue("staff_email", su11);
            //状态:0准备入职   1试用   2准备转正   3在职   4停职   5准备离职   6离职   7退休
            staffsFs.setValue("staff_status", 3);
         //该角色初始化权限
         this.packageButton(role_uuid);
      }
   }
            staffsFs.setValue("client_uuid", client_uuid);
            //重新组装后的组织全称
            FieldSetEntity fieldSet = institutionMap.get(userFs.getString("asu03"));
            String uuid = this.getSuperiorCompanyUuid(userFs.getString("asu03"));
            //公司uuid
            staffsFs.setValue("org_level_uuid", uuid);
            //部门uuid
            staffsFs.setValue("dept_uuid", fieldSet.getUUID());
            if (null == userFs.getString("su34")) {
                //岗位uuid
                staffsFs.setValue("job_post_uuid", 1);
                //岗位等级uuid
                staffsFs.setValue("job_post_grade_uuid",1);
            } else {
                //通过岗位id查询岗位
                String su34 = userFs.getString("su34");
                FieldSetEntity fsePosts = baseDao.getFieldSetEntityByFilter("product_sys_job_posts", " sequence = ? ", new Integer[]{Integer.parseInt(su34)}, false);
                if(fsePosts != null) {
                    staffsFs.setValue("job_post_uuid", fsePosts.getUUID());
                    staffsFs.setValue("job_post_grade_uuid", fsePosts.getString("job_post_grades_uuid"));
                }else {
                    throw new BaseException("未查询到岗位","未查询到岗位");
                }
            }
            //su35关联权限id,  关联多个逗号分隔
            String su35 = userFs.getString("su35");
            String[] su35s = null;
            if(!BaseUtil.strIsNull(su35)){
                su35s = su35.split(",");
                for (int j = 0; j < su35s.length; j++) {
                  FieldSetEntity fse = baseDao.getFieldSetEntityByFilter("product_sys_role", " sequence = ? ", new Integer[]{Integer.parseInt(su35s[j])}, false);
                    su35s[j] = fse.getUUID();
                }
            }
            //直属领导
            String su40 = userFs.getString("su40");
            //为空就放空
            if(BaseUtil.strIsNull(su40)){
                su40 = "";
            }else {
                //多个直属领导   就取第一个
                if(su40.contains(",")){
                    su40 = su40.substring(0,su40.indexOf(","));
                }
            }
            staffsFs.setValue("direct_leader_code",su40);
            if(su35s != null) {
                staffsFs.setValue("role_uuids", StringUtils.join(su35s, ","));
            }
            //员工上下级编码
            staffsFs.setValue("leader_tricode", codeService.createFixCode(CmnConst.PRODUCT_SYS_STAFFS, CmnConst.LEADER_TRICODE, ""));
            //员工编码  员工原本id   存为编码
            staffsFs.setValue("tricode",codeService.createFixCode(CmnConst.PRODUCT_SYS_STAFFS, CmnConst.TRICODE, fieldSet.getString("org_level_code")));
            String su00 = userFs.getString("su00");
            staffsFs.setValue("sequence", su00);
            staffsFs.setValue("remark", su00);
            this.userAndTime(staffsFs);
            baseDao.add(staffsFs);
            staffsMap.put(su00, staffsFs);
        }
        //sql修改直属领导
        baseDao.executeUpdate(" UPDATE product_sys_staffs a INNER JOIN product_sys_staffs b ON a.remark = b.direct_leader_code SET b.direct_leader_code = a.tricode ");
        //循环同步直属领导,  若有两个直属领导  只取第一个
   /**
    * 添加用户和员工
    */
   public void addEmployees(DataTableEntity data, String clientUUID) {
      //fe 人员id 对应  userid
      JSONObject idUserMap = new JSONObject();
      //获取客户uuid
      FieldSetEntity fieldSetEntity = baseDao.getFieldSetEntityByFilter("product_sys_org_levels", " org_level_code = ? ", new String[]{"001"}, false);
      String client_uuid = fieldSetEntity.getString("client_uuid");
      Map<String, FieldSetEntity> staffsMap = Maps.newHashMap();
      for (int i = 0; i < data.getRows(); i++) {
         FieldSetEntity userFs = data.getFieldSetEntity(i);
         FieldSetEntity usersFs = new FieldSetEntity();
         //创建 user 数据
         usersFs.setTableName("product_sys_users");
         //用户名
         usersFs.setValue("user_name", userFs.getString("su02"));
         //描述
         usersFs.setValue("user_account", userFs.getString("su01"));
         FieldSetEntity fieldSetByFilter = baseDao.getFieldSetByFilter("product_sys_users", "user_account=?", new Object[]{userFs.getString("su01")}, false);
         if (!FieldSetEntity.isEmpty(fieldSetByFilter)) {
            fieldSetByFilter.setValue("status", userFs.getString("su08"));
            //签名
            String su23 = userFs.getString("su23");
            if (!BaseUtil.strIsNull(su23)) {
               usersFs.setValue("user_signature", this.signatureAndThumbnail(su23, clientUUID, "user_signature"));
            }
            //头像
            String su28 = userFs.getString("su28");
            if (!BaseUtil.strIsNull(su28)) {
               usersFs.setValue("thumbnail_img", this.signatureAndThumbnail(su28, clientUUID, "thumbnail_img"));
            }
            baseDao.executeUpdate("update product_sys_staffs set staff_status=? where user_id=?", new Object[]{userFs.getString("su08"), fieldSetByFilter.getString("user_id")});
            baseDao.saveFieldSetEntity(fieldSetByFilter);
            continue;
         }
         //邮箱
         usersFs.setValue("user_primary_email", userFs.getString("su11"));
         //性别转换
         String su16 = userFs.getString("su16");
         String sex = null;
         if (su16 != null) {
            sex = su16.equals("男") ? "0" : "1";
         }
         usersFs.setValue("gender", sex);
         //用户电话
         usersFs.setValue("user_mobile_number", userFs.getString("su10"));
         //内线电话
         usersFs.setValue("inside_phone", userFs.getString("su13"));
         //地址
         usersFs.setValue("contact_address", userFs.getString("su18"));
         //初始化用户密码
         usersFs.setValue("user_pwd", userService.createPassWord(userFs.getString("su01"), "123"));
         //是否是管理员 0:否 1:是
         usersFs.setValue("is_manager", 0);
         //办公电话
         usersFs.setValue("office_phone", userFs.getString("su09"));
         this.userAndTime(usersFs);
         //状态  0:禁用   1:正常
         usersFs.setValue("status", userFs.getString("su08"));
         //签名
         String su23 = userFs.getString("su23");
         if (!BaseUtil.strIsNull(su23)) {
            usersFs.setValue("user_signature", this.signatureAndThumbnail(su23, clientUUID, "user_signature"));
         }
         //头像
         String su28 = userFs.getString("su28");
         if (!BaseUtil.strIsNull(su28)) {
            usersFs.setValue("thumbnail_img", this.signatureAndThumbnail(su28, clientUUID, "thumbnail_img"));
         }
         String usersUUID = baseDao.add(usersFs);
         FieldSetEntity users = baseDao.getFieldSetEntity("product_sys_users", usersUUID, false);
         //fe用户id  关联系统表"product_sys_users)user_id
         idUserMap.put(userFs.getString("su00"), users.getString("user_id"));
         if (BaseUtil.strIsNull(userFs.getString("su03")) || BaseUtil.strIsNull(userFs.getString("su35")) || BaseUtil.strIsNull(userFs.getString("su39"))) {
            continue;
         }
         FieldSetEntity staffsFs = new FieldSetEntity();
         //员工表
         staffsFs.setTableName("product_sys_staffs");
         //用户表id
         staffsFs.setValue("user_id", users.getString("user_id"));
         //显示名称
         staffsFs.setValue("show_name", userFs.getString("su02"));
         //员工名
         staffsFs.setValue("given_name", userFs.getString("su02"));
         //员工姓
         staffsFs.setValue("family_name", userFs.getString("su02"));
         //邮箱
         staffsFs.setValue("email_address", userFs.getString("su11"));
         //移动电话
         staffsFs.setValue("mobile_phone", userFs.getString("su10"));
         //办公电话
         staffsFs.setValue("office_telephone", userFs.getString("su09"));
         //员工性别
         staffsFs.setValue("sex", sex);
         //员工邮箱
         String su11 = userFs.getString("su11");
         //邮箱为空先覆1
         if (BaseUtil.strIsNull(su11)) {
            su11 = "1";
         }
         staffsFs.setValue("staff_email", su11);
         //状态:0准备入职   1试用   2准备转正   3在职   4停职   5准备离职   6离职   7退休
         staffsFs.setValue("staff_status", 3);
         staffsFs.setValue("client_uuid", client_uuid);
         //重新组装后的组织全称
         FieldSetEntity fieldSet = institutionMap.get(userFs.getString("asu03"));
         String uuid = this.getSuperiorCompanyUuid(userFs.getString("asu03"));
         //公司uuid
         staffsFs.setValue("org_level_uuid", uuid);
         //部门uuid
         staffsFs.setValue("dept_uuid", fieldSet.getUUID());
         if (null == userFs.getString("su34")) {
            //岗位uuid
            staffsFs.setValue("job_post_uuid", 1);
            //岗位等级uuid
            staffsFs.setValue("job_post_grade_uuid", 1);
         } else {
            //通过岗位id查询岗位
            String su34 = userFs.getString("su34");
            FieldSetEntity fsePosts = baseDao.getFieldSetEntityByFilter("product_sys_job_posts", " sequence = ? ", new Integer[]{Integer.parseInt(su34)}, false);
            if (fsePosts != null) {
               staffsFs.setValue("job_post_uuid", fsePosts.getUUID());
               staffsFs.setValue("job_post_grade_uuid", fsePosts.getString("job_post_grades_uuid"));
            } else {
               throw new BaseException("未查询到岗位", "未查询到岗位");
            }
         }
         //su35关联权限id,  关联多个逗号分隔
         String su35 = userFs.getString("su35");
         String[] su35s = null;
         if (!BaseUtil.strIsNull(su35)) {
            su35s = su35.split(",");
            for (int j = 0; j < su35s.length; j++) {
               FieldSetEntity fse = baseDao.getFieldSetEntityByFilter("product_sys_role", " sequence = ? ", new Integer[]{Integer.parseInt(su35s[j])}, false);
               su35s[j] = fse.getUUID();
            }
         }
         //直属领导
         String su40 = userFs.getString("su40");
         //为空就放空
         if (BaseUtil.strIsNull(su40)) {
            su40 = "";
         } else {
            //多个直属领导   就取第一个
            if (su40.contains(",")) {
               su40 = su40.substring(0, su40.indexOf(","));
            }
         }
         staffsFs.setValue("direct_leader_code", su40);
         if (su35s != null) {
            staffsFs.setValue("role_uuids", StringUtils.join(su35s, ","));
         }
         //员工上下级编码
         staffsFs.setValue("leader_tricode", codeService.createFixCode(CmnConst.PRODUCT_SYS_STAFFS, CmnConst.LEADER_TRICODE, ""));
         //员工编码  员工原本id   存为编码
         staffsFs.setValue("tricode", codeService.createFixCode(CmnConst.PRODUCT_SYS_STAFFS, CmnConst.TRICODE, fieldSet.getString("org_level_code")));
         String su00 = userFs.getString("su00");
         staffsFs.setValue("sequence", su00);
         staffsFs.setValue("remark", su00);
         this.userAndTime(staffsFs);
         baseDao.add(staffsFs);
         staffsMap.put(su00, staffsFs);
      }
      //sql修改直属领导
      baseDao.executeUpdate(" UPDATE product_sys_staffs a INNER JOIN product_sys_staffs b ON a.remark = b.direct_leader_code SET b.direct_leader_code = a.tricode ");
      //循环同步直属领导,  若有两个直属领导  只取第一个
//        for(String su00 : staffsMap.keySet()){
//            FieldSetEntity staffsFs = staffsMap.get(su00);
//            //获取直属领导
@@ -687,242 +719,268 @@
//                }
//            }
//        }
    }
   }
    public String signatureAndThumbnail(String su,String clientUUID, String field){
        try {
            String[] path = su.split("=");
            String filePath = path[1];
            String fileName = StringUtils.isEmpty(filePath) ? "" : filePath.substring(filePath.lastIndexOf("/") + 1);
            String newPath = this.TSPath + File.separator + fileName;
            File isField = new File(newPath);
            //如果已经有该文件   改变文件目录
            Integer fileNum = 0;
            while (isField.exists()) {
                fileNum++;
                newPath = this.TSPath + fileNum + File.separator + fileName;
                isField = new File(newPath);
            }
            //复制到临时目录下
            if (this.copyFile(filePath, newPath)) {
                RequestParameterEntity rpe = new RequestParameterEntity();
                Map<String, File> fileMap = Maps.newHashMap();
                //通过路径获取File
                File file = new File(newPath);
                //文件名  文件file
                fileMap.put(fileName, file);
                FieldSetEntity fieldSet = new FieldSetEntity();
                FieldMetaEntity f = new FieldMetaEntity();
                f.setTableName(new String[]{"product_sys_users"});
                fieldSet.setMeta(f);
                fieldSet.setValue(field, fileName);
                fieldSet.setValue("~field_name~", field);
                //放入客户uuid
                fieldSet.setValue("client_uuid", clientUUID);
                rpe.setFiles(fileMap);
                rpe.setFormData(fieldSet);
                try {
                    FieldSetEntity fileFse = fileManagerService.uploadFile(rpe);
                    return fileFse.getString(field);
                } catch (Exception e) {
                    e.getStackTrace();
                    SpringMVCContextHolder.getSystemLogger().error(e);
                }
            }
        }catch (Exception e){
            e.getStackTrace();
        }
        return null;
    }
   public String signatureAndThumbnail(String su, String clientUUID, String field) {
      try {
         String[] path = su.split("=");
         String filePath = path[1];
         String fileName = StringUtils.isEmpty(filePath) ? "" : filePath.substring(filePath.lastIndexOf("/") + 1);
         String newPath = this.TSPath + File.separator + fileName;
         File isField = new File(newPath);
         //如果已经有该文件   改变文件目录
         Integer fileNum = 0;
         while (isField.exists()) {
            fileNum++;
            newPath = this.TSPath + fileNum + File.separator + fileName;
            isField = new File(newPath);
         }
         //复制到临时目录下
         if (this.copyFile(filePath, newPath)) {
            RequestParameterEntity rpe = new RequestParameterEntity();
            Map<String, File> fileMap = Maps.newHashMap();
            //通过路径获取File
            File file = new File(newPath);
            //文件名  文件file
            fileMap.put(fileName, file);
            FieldSetEntity fieldSet = new FieldSetEntity();
            FieldMetaEntity f = new FieldMetaEntity();
            f.setTableName(new String[]{"product_sys_users"});
            fieldSet.setMeta(f);
            fieldSet.setValue(field, fileName);
            fieldSet.setValue("~field_name~", field);
            //放入客户uuid
            fieldSet.setValue("client_uuid", clientUUID);
            rpe.setFiles(fileMap);
            rpe.setFormData(fieldSet);
            try {
               FieldSetEntity fileFse = fileManagerService.uploadFile(rpe);
               return fileFse.getString(field);
            } catch (Exception e) {
               e.getStackTrace();
               SpringMVCContextHolder.getSystemLogger().error(e);
            }
         }
      } catch (Exception e) {
         e.getStackTrace();
      }
      return null;
   }
    /**
     * 添加岗位
     */
    public void addPost(DataTableEntity data){
        DataTableEntity dataTableEntity = new DataTableEntity();
        dataTableEntity.getMeta().setTableName(new String[]{"product_sys_job_posts"});
        for (int i = 0; i < data.getRows(); i++) {
            FieldSetEntity fieldSetEntity = data.getFieldSetEntity(i);
            FieldSetEntity field = new FieldSetEntity();
            field.setTableName("product_sys_job_posts");
            field.setValue("is_used", 1);
            field.setValue("job_post_name", fieldSetEntity.getString("sr01"));
            field.setValue("job_post_description", fieldSetEntity.getString("sr02"));
            //通过全称获取单位和部门uuid
            String org_level_all = fieldSetEntity.getString("asr03");
            FieldSetEntity fieldSetEntity1 = institutionMap.get(org_level_all);
            //公司uuid
            String org_level_uuid = this.getSuperiorCompanyUuid(org_level_all);
            field.setValue("org_level_uuid",org_level_uuid);
            //机构类型  0 公司  1部门
            String orgLevelType = fieldSetEntity1.getString("org_level_type");
            //查询岗位等级
            String sr15 = fieldSetEntity.getString("sr15");
            FieldSetEntity fieldSet = baseDao.getFieldSetEntityByFilter("product_sys_job_post_grades", " org_level_uuid = ? and  job_grade_class = ? ", new String[]{org_level_uuid,sr15},false);
            //岗位等级
            String postGradesUuid = fieldSet.getUUID();
            field.setValue("job_post_grades_uuid", postGradesUuid);
            //排序暂时存岗位id  方便人员查询到岗位id
            Integer sequence = fieldSetEntity.getInteger("sr00");
            field.setValue("sequence",sequence);
            this.userAndTime(field);
            String org_uuid = fieldSetEntity1.getUUID();
            String code = fieldSetEntity1.getString("org_level_code");
            //0为公司  若为公司就创建多个相同岗位来关联公司下所有部门
            if("0".equals(orgLevelType)){
              DataTableEntity dataTable = baseDao.listTable("product_sys_org_levels", " org_level_type = 1 and org_level_uuid = ? ", new String[]{org_uuid});
              if(!BaseUtil.dataTableIsEmpty(dataTable)) {
                  for (int j = 0; j < dataTable.getRows(); j++) {
                      field.setValue("dept_uuid",dataTable.getString(j, "uuid"));
                      field.remove("uuid");
                      //通过新增方法添加岗位
                      String uuid = baseDao.add(field);
                      //添加岗位与岗位等级关系映射数据表
                      FieldSetEntity postsAndClass = new FieldSetEntity();
                      postsAndClass.setTableName("product_sys_job_posts_grades_mapping");
                      //岗位等级uuid
                      postsAndClass.setValue("job_grade_uuid", postGradesUuid);
                      //岗位uuid
                      postsAndClass.setValue("job_post_uuid", uuid);
                      this.userAndTime(postsAndClass);
                      baseDao.add(postsAndClass);
                  }
              }else {
                  //单位下若没有部门  创建一个虚拟部门
                  FieldSetEntity departmentFse = new FieldSetEntity();
                  departmentFse.setTableName("product_sys_org_levels");
                  //部门名称
                  departmentFse.setValue("sg01", fieldSetEntity1.getString("org_level_name") + "下部门");
                  //部门编码
                  departmentFse.setValue("sg10", fieldSetEntity1.getString("org_level_shortcode") + "01");
                  //排序
                  departmentFse.setValue("sg00", fieldSetEntity1.getString("sequence") + "01");
                  //保存后的部门
                  FieldSetEntity newDeptFse = this.addDepartment(departmentFse,code,org_uuid);
                  //放入部门uuid
                  field.setValue("dept_uuid",newDeptFse.getUUID());
                  //通过新增方法添加岗位
                  String uuid = baseDao.add(field);
                  //添加岗位与岗位等级关系映射数据表
                  FieldSetEntity postsAndClass = new FieldSetEntity();
                  postsAndClass.setTableName("product_sys_job_posts_grades_mapping");
                  //岗位等级uuid
                  postsAndClass.setValue("job_grade_uuid", postGradesUuid);
                  //岗位uuid
                  postsAndClass.setValue("job_post_uuid", uuid);
                  this.userAndTime(postsAndClass);
                  baseDao.add(postsAndClass);
              }
              //1为部门
            }else{
                field.setValue("dept_uuid",org_uuid);
                //通过新增方法添加岗位
                String uuid = baseDao.add(field);
                //添加岗位与岗位等级关系映射数据表
                FieldSetEntity postsAndClass = new FieldSetEntity();
                postsAndClass.setTableName("product_sys_job_posts_grades_mapping");
                //岗位等级uuid
                postsAndClass.setValue("job_grade_uuid", postGradesUuid);
                //岗位uuid
                postsAndClass.setValue("job_post_uuid", uuid);
                this.userAndTime(postsAndClass);
                baseDao.add(postsAndClass);
            }
        }
    }
   /**
    * 添加岗位
    */
   public void addPost(DataTableEntity data) {
      DataTableEntity dataTableEntity = new DataTableEntity();
      dataTableEntity.getMeta().setTableName(new String[]{"product_sys_job_posts"});
      for (int i = 0; i < data.getRows(); i++) {
         FieldSetEntity fieldSetEntity = data.getFieldSetEntity(i);
         FieldSetEntity field = new FieldSetEntity();
         field.setTableName("product_sys_job_posts");
         field.setValue("is_used", 1);
         field.setValue("job_post_name", fieldSetEntity.getString("sr01"));
         field.setValue("job_post_description", fieldSetEntity.getString("sr02"));
         //通过全称获取单位和部门uuid
         String org_level_all = fieldSetEntity.getString("asr03");
         FieldSetEntity fieldSetEntity1 = institutionMap.get(org_level_all);
         //公司uuid
         String org_level_uuid = this.getSuperiorCompanyUuid(org_level_all);
         field.setValue("org_level_uuid", org_level_uuid);
         //判断系统中是否有该角色
    /**
     * 添加创建人和创建时间
     * @param fieldSetEntity
     */
    public void userAndTime(FieldSetEntity fieldSetEntity){
        fieldSetEntity.setValue("created_by",SpringMVCContextHolder.getCurrentUserId());
        fieldSetEntity.setValue("created_utc_datetime",new Date());
    }
    /**
     * 添加岗位等级
     */
    public void postGrades(DataTableEntity data){
        //公司uuid 岗位层级集
        Map<String,String> postHierarchyMap = Maps.newHashMap();
        //通过公司uuid来划分岗位等级
        for (int i = 0; i < data.getRows(); i++) {
           FieldSetEntity fieldSetEntity = data.getFieldSetEntity(i);
            FieldSetEntity field = new FieldSetEntity();
            field.setTableName("product_sys_job_post_grades");
            //岗位层级  越小等级越大
            String sr15 = fieldSetEntity.getString("sr15");
            //转换后部门或公司全称
            String dcName = fieldSetEntity.getString("asr03");
            //获取公司的uuid
            String companyUuid = this.getSuperiorCompanyUuid(dcName);
            String value = postHierarchyMap.get(companyUuid);
            if(!BaseUtil.strIsNull(value)){
                if(value.contains(sr15)) {
                    continue;
                }else {
                    postHierarchyMap.put(companyUuid, value+","+sr15);
                }
            }else {
                postHierarchyMap.put(companyUuid, sr15);
            }
            FieldSetEntity levelsSet = baseDao.getFieldSetEntity("product_sys_org_levels",companyUuid,false);
            //公司名称
            String levelName = levelsSet.getString("org_level_name");
            //上级公司uuid
            field.setValue("org_level_uuid",companyUuid);
            //岗位等级
            field.setValue("job_grade_class", sr15);
            field.setValue("is_used", 1);
            //名称
            field.setValue("job_grade_name",sr15+"级岗位");
            //级别短编码
            field.setValue("job_grade_shortcode", sr15);
            //说明
            field.setValue("remark", levelName+"下的"+sr15+"级岗位");
            field.setValue("sequence", sr15);
            this.userAndTime(field);
            baseDao.add(field);
        }
    }
    /** 复制单个文件
     * @param oldPath String 原文件路径 如:c:/fqf.txt
     * @param newPath String 复制后路径 如:f:/fqf.txt
     * @return boolean
     */
    public Boolean copyFile(String oldPath, String newPath) {
        Boolean status = false;
        try {
            BufferedInputStream in = FileUtil.getInputStream(oldPath);
            BufferedOutputStream out = FileUtil.getOutputStream(newPath);
            IoUtil.copy(in, out, IoUtil.DEFAULT_BUFFER_SIZE);
            status = true;
            out.close();
            in.close();
        }catch (Exception e){
            e.getStackTrace();
        }finally {
            return status;
        }
    }
    /** 删除单个文件
     * @param   fileName    被删除文件的文件名
     * @return 单个文件删除成功返回true,否则返回false
     */
    public Boolean deleteFile(String fileName){
        File file = new File(fileName);
        if(file.isFile()){
            file.delete();
            System.out.println("删除单个文件"+fileName+"成功!");
            return true;
        }else{
            System.out.println("删除单个文件"+fileName+"失败!");
            return false;
        }
    }
         //机构类型  0 公司  1部门
         String orgLevelType = fieldSetEntity1.getString("org_level_type");
         //查询岗位等级
         String sr15 = fieldSetEntity.getString("sr15");
         FieldSetEntity fieldSet = baseDao.getFieldSetEntityByFilter("product_sys_job_post_grades", " org_level_uuid = ? and  job_grade_class = ? ", new String[]{org_level_uuid, sr15}, false);
         //岗位等级
         String postGradesUuid = fieldSet.getUUID();
         field.setValue("job_post_grades_uuid", postGradesUuid);
         //排序暂时存岗位id  方便人员查询到岗位id
         Integer sequence = fieldSetEntity.getInteger("sr00");
         field.setValue("sequence", sequence);
         this.userAndTime(field);
         String org_uuid = fieldSetEntity1.getUUID();
         String code = fieldSetEntity1.getString("org_level_code");
         //0为公司  若为公司就创建多个相同岗位来关联公司下所有部门
         if ("0".equals(orgLevelType)) {
            DataTableEntity dataTable = baseDao.listTable("product_sys_org_levels", " org_level_type = 1 and org_level_uuid = ? ", new String[]{org_uuid});
            if (!BaseUtil.dataTableIsEmpty(dataTable)) {
               for (int j = 0; j < dataTable.getRows(); j++) {
                  field.setValue("dept_uuid", dataTable.getString(j, "uuid"));
                  field.remove("uuid");
                  FieldSetEntity fieldSetByFilter = baseDao.getFieldSetByFilter("product_sys_job_posts", " job_post_name = ? and org_level_uuid = ?  and dept_uuid=?", new String[]{fieldSetEntity.getString("sr01"), org_level_uuid, field.getString("dept_uuid")}, false);
                  if (fieldSetByFilter != null && !StringUtils.isEmpty(fieldSetByFilter.getUUID())) {
                     continue;
                  }
                  //通过新增方法添加岗位
                  String uuid = baseDao.add(field);
                  //添加岗位与岗位等级关系映射数据表
                  FieldSetEntity postsAndClass = new FieldSetEntity();
                  postsAndClass.setTableName("product_sys_job_posts_grades_mapping");
                  //岗位等级uuid
                  postsAndClass.setValue("job_grade_uuid", postGradesUuid);
                  //岗位uuid
                  postsAndClass.setValue("job_post_uuid", uuid);
                  this.userAndTime(postsAndClass);
                  baseDao.add(postsAndClass);
               }
            } else {
               //单位下若没有部门  创建一个虚拟部门
               String orgLevelName = fieldSetEntity1.getString("org_level_name") + "下部门";
               FieldSetEntity newDeptFse = baseDao.getFieldSetByFilter("product_sys_org_levels", "org_level_name = ? and org_level_type = 1 and org_level_uuid = ?", new String[]{orgLevelName, org_uuid}, false);
               if (FieldSetEntity.isEmpty(newDeptFse)) {
                  FieldSetEntity departmentFse = new FieldSetEntity();
                  departmentFse.setTableName("product_sys_org_levels");
                  //部门名称
                  departmentFse.setValue("sg01", fieldSetEntity1.getString("org_level_name") + "下部门");
                  //部门编码
                  departmentFse.setValue("sg10", fieldSetEntity1.getString("org_level_shortcode") + "01");
                  //排序
                  departmentFse.setValue("sg00", fieldSetEntity1.getString("sequence") + "01");
                  //保存后的部门
                  newDeptFse = this.addDepartment(departmentFse, code, org_uuid);
               }
               //放入部门uuid
               field.setValue("dept_uuid", newDeptFse.getUUID());
               FieldSetEntity fieldSetByFilter = baseDao.getFieldSetByFilter("product_sys_job_posts", " job_post_name = ? and org_level_uuid = ?  and dept_uuid=?", new String[]{fieldSetEntity.getString("sr01"), org_level_uuid, field.getString("dept_uuid")}, false);
               if (fieldSetByFilter != null && !StringUtils.isEmpty(fieldSetByFilter.getUUID())) {
                  continue;
               }
               //通过新增方法添加岗位
               String uuid = baseDao.add(field);
               //添加岗位与岗位等级关系映射数据表
               FieldSetEntity postsAndClass = new FieldSetEntity();
               postsAndClass.setTableName("product_sys_job_posts_grades_mapping");
               //岗位等级uuid
               postsAndClass.setValue("job_grade_uuid", postGradesUuid);
               //岗位uuid
               postsAndClass.setValue("job_post_uuid", uuid);
               this.userAndTime(postsAndClass);
               baseDao.add(postsAndClass);
            }
            //1为部门
         } else {
            field.setValue("dept_uuid", org_uuid);
            FieldSetEntity fieldSetByFilter = baseDao.getFieldSetByFilter("product_sys_job_posts", " job_post_name = ? and org_level_uuid = ?  and dept_uuid=?", new String[]{fieldSetEntity.getString("sr01"), org_level_uuid, field.getString("dept_uuid")}, false);
            if (fieldSetByFilter != null && !StringUtils.isEmpty(fieldSetByFilter.getUUID())) {
               continue;
            }
            //通过新增方法添加岗位
            String uuid = baseDao.add(field);
            //添加岗位与岗位等级关系映射数据表
            FieldSetEntity postsAndClass = new FieldSetEntity();
            postsAndClass.setTableName("product_sys_job_posts_grades_mapping");
            //岗位等级uuid
            postsAndClass.setValue("job_grade_uuid", postGradesUuid);
            //岗位uuid
            postsAndClass.setValue("job_post_uuid", uuid);
            this.userAndTime(postsAndClass);
            baseDao.add(postsAndClass);
         }
      }
   }
    public static void main(String[] args) {
   /**
    * 添加创建人和创建时间
    *
    * @param fieldSetEntity
    */
   public void userAndTime(FieldSetEntity fieldSetEntity) {
      fieldSetEntity.setValue("created_by", SpringMVCContextHolder.getCurrentUserId());
      fieldSetEntity.setValue("created_utc_datetime", new Date());
   }
   /**
    * 添加岗位等级
    */
   public void postGrades(DataTableEntity data) {
      //公司uuid 岗位层级集
      Map<String, String> postHierarchyMap = Maps.newHashMap();
      //通过公司uuid来划分岗位等级
      for (int i = 0; i < data.getRows(); i++) {
         FieldSetEntity fieldSetEntity = data.getFieldSetEntity(i);
         FieldSetEntity field = new FieldSetEntity();
         field.setTableName("product_sys_job_post_grades");
         //岗位层级  越小等级越大
         String sr15 = fieldSetEntity.getString("sr15");
         //转换后部门或公司全称
         String dcName = fieldSetEntity.getString("asr03");
         //获取公司的uuid
         String companyUuid = this.getSuperiorCompanyUuid(dcName);
         String value = postHierarchyMap.get(companyUuid);
         if (!BaseUtil.strIsNull(value)) {
            if (value.contains(sr15)) {
               continue;
            } else {
               postHierarchyMap.put(companyUuid, value + "," + sr15);
            }
         } else {
            postHierarchyMap.put(companyUuid, sr15);
         }
         FieldSetEntity levelsSet = baseDao.getFieldSetEntity("product_sys_org_levels", companyUuid, false);
         //公司名称
         String levelName = levelsSet.getString("org_level_name");
         //上级公司uuid
         field.setValue("org_level_uuid", companyUuid);
         //岗位等级
         field.setValue("job_grade_class", sr15);
         field.setValue("is_used", 1);
         //名称
         field.setValue("job_grade_name", sr15 + "级岗位");
         //级别短编码
         field.setValue("job_grade_shortcode", sr15);
         //说明
         field.setValue("remark", levelName + "下的" + sr15 + "级岗位");
         field.setValue("sequence", sr15);
         this.userAndTime(field);
         baseDao.add(field);
      }
   }
   /**
    * 复制单个文件
    *
    * @param oldPath String 原文件路径 如:c:/fqf.txt
    * @param newPath String 复制后路径 如:f:/fqf.txt
    * @return boolean
    */
   public Boolean copyFile(String oldPath, String newPath) {
      Boolean status = false;
      try {
         BufferedInputStream in = FileUtil.getInputStream(oldPath);
         BufferedOutputStream out = FileUtil.getOutputStream(newPath);
         IoUtil.copy(in, out, IoUtil.DEFAULT_BUFFER_SIZE);
         status = true;
         out.close();
         in.close();
      } catch (Exception e) {
         e.getStackTrace();
      } finally {
         return status;
      }
   }
   /**
    * 删除单个文件
    *
    * @param fileName 被删除文件的文件名
    * @return 单个文件删除成功返回true, 否则返回false
    */
   public Boolean deleteFile(String fileName) {
      File file = new File(fileName);
      if (file.isFile()) {
         file.delete();
         System.out.println("删除单个文件" + fileName + "成功!");
         return true;
      } else {
         System.out.println("删除单个文件" + fileName + "失败!");
         return false;
      }
   }
   public static void main(String[] args) {
//        File file = new File("D:\\filePackage\\西宁市住房保障和房屋管理局需求整理V1.0.docx");
//        File file2 = new File("D:\\filePackage\\西宁市住房保障和房屋管理.docx");
//        System.out.println(file.exists());
@@ -930,88 +988,85 @@
//        FeDataDSService feDataDSService = new FeDataDSService();
//        feDataDSService.copyFile("D:\\OA\\FEGOV\\Media\\2021\\12\\15\\20211215401901\\1`FE#ENC#DA126AF35BB8E57F55C2429BDF7DC7240DF6CC6E227B0B8E", "D:\\filePackage\\????????????????????????.doc");
//        feDataDSService.getFilesFolder("D:\\OA\\FEGOV\\Media\\2021\\12\\15\\20211215401901");
    }
   }
    /**
     * 获取文件名称  最新修改时间 map
     * @param path
     * @return
     */
    public Map<String, String> getFilesFolder(String path){
        File file = new File(path);      //获取其file对象
        File[] fs = file.listFiles();
        if(fs == null){
            logger.info("未找到附件直接返回null");
            return null;
        }
        Map<String, String> fileTimeName = Maps.newHashMap();
        for(File f:fs)
        {
            if(f.isFile())
            {
                String fileName = f.toString().replace(path+"\\","");
                fileTimeName.put(this.set_fileInfo(f.toString()),fileName);
            }
        }
        return fileTimeName;
    }
   /**
    * 获取文件名称  最新修改时间 map
    *
    * @param path
    * @return
    */
   public Map<String, String> getFilesFolder(String path) {
      File file = new File(path);        //获取其file对象
      File[] fs = file.listFiles();
      if (fs == null) {
         logger.info("未找到附件直接返回null");
         return null;
      }
      Map<String, String> fileTimeName = Maps.newHashMap();
      for (File f : fs) {
         if (f.isFile()) {
            String fileName = f.toString().replace(path + "\\", "");
            fileTimeName.put(this.set_fileInfo(f.toString()), fileName);
         }
      }
      return fileTimeName;
   }
    /**
     * 获取文件最近修改时间
     * @param file_name 文件全路径
     * @return
     */
    public String set_fileInfo(String file_name)
    {
        Path path = Paths.get(file_name);
        BasicFileAttributeView basicview = Files.getFileAttributeView(path, BasicFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
        BasicFileAttributes attr;
        String time = null;
        try
        {
   /**
    * 获取文件最近修改时间
    *
    * @param file_name 文件全路径
    * @return
    */
   public String set_fileInfo(String file_name) {
      Path path = Paths.get(file_name);
      BasicFileAttributeView basicview = Files.getFileAttributeView(path, BasicFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
      BasicFileAttributes attr;
      String time = null;
      try {
            attr = basicview.readAttributes();
            //创建时间
            Date CreateTimeDate= new Date(attr.creationTime().toMillis());
            //上次修改时间 *
            Date lastmodfiyTimeDate=new Date(attr.lastModifiedTime().toMillis());
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            time = df.format(lastmodfiyTimeDate);
        } catch (Exception e)
        {
            e.printStackTrace();
        }
        return time;
    }
         attr = basicview.readAttributes();
         //创建时间
         Date CreateTimeDate = new Date(attr.creationTime().toMillis());
         //上次修改时间 *
         Date lastmodfiyTimeDate = new Date(attr.lastModifiedTime().toMillis());
         SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         time = df.format(lastmodfiyTimeDate);
      } catch (Exception e) {
         e.printStackTrace();
      }
      return time;
   }
    public void clearJobList(){
      DataTableEntity dataTableEntity = baseDao.listTable("product_sys_flow_node","  default_posts is not null AND default_posts != '' ",new String[]{});
        for (int i = 0; i < dataTableEntity.getRows(); i++) {
           FieldSetEntity fse = dataTableEntity.getFieldSetEntity(i);
           String default_posts = fse.getString("default_posts");
           if(!BaseUtil.strIsNull(default_posts)){
               String[] postUuids = default_posts.split(",");
               Set<String> postSet = Sets.newHashSet();
   public void clearJobList() {
      DataTableEntity dataTableEntity = baseDao.listTable("product_sys_flow_node", "  default_posts is not null AND default_posts != '' ", new String[]{});
      for (int i = 0; i < dataTableEntity.getRows(); i++) {
         FieldSetEntity fse = dataTableEntity.getFieldSetEntity(i);
         String default_posts = fse.getString("default_posts");
         if (!BaseUtil.strIsNull(default_posts)) {
            String[] postUuids = default_posts.split(",");
            Set<String> postSet = Sets.newHashSet();
//             Set<String> postSet = Arrays.stream(postUuids).collect(Collectors.toSet());
               for (int j = 0; j < postUuids.length; j++) {
                 DataTableEntity staffsData = baseDao.listTable("product_sys_staffs","  job_post_uuid = ? ",new String[]{postUuids[j]});
                 //有人就保留岗位uuid
                   if(!BaseUtil.dataTableIsEmpty(staffsData)){
                       postSet.add(postUuids[j]);
                   }
               }
               if(postSet.size() > 0){
                   fse.setValue("default_posts", StringUtils.join(postSet, ","));
               }else {
                   fse.setValue("default_posts", null);
               }
               baseDao.update(fse);
           }
        }
        //清空多余的岗位数据
        baseDao.executeUpdate("DELETE FROM product_sys_job_posts WHERE uuid not in (SELECT job_post_uuid FROM product_sys_staffs);");
        //岗位关联
        baseDao.executeUpdate("DELETE FROM product_sys_job_posts_grades_mapping WHERE job_post_uuid not in (SELECT job_post_uuid FROM product_sys_staffs);");
    }
            for (int j = 0; j < postUuids.length; j++) {
               DataTableEntity staffsData = baseDao.listTable("product_sys_staffs", "  job_post_uuid = ? ", new String[]{postUuids[j]});
               //有人就保留岗位uuid
               if (!BaseUtil.dataTableIsEmpty(staffsData)) {
                  postSet.add(postUuids[j]);
               }
            }
            if (postSet.size() > 0) {
               fse.setValue("default_posts", StringUtils.join(postSet, ","));
            } else {
               fse.setValue("default_posts", null);
            }
            baseDao.update(fse);
         }
      }
      //清空多余的岗位数据
      baseDao.executeUpdate("DELETE FROM product_sys_job_posts WHERE uuid not in (SELECT job_post_uuid FROM product_sys_staffs);");
      //岗位关联
      baseDao.executeUpdate("DELETE FROM product_sys_job_posts_grades_mapping WHERE job_post_uuid not in (SELECT job_post_uuid FROM product_sys_staffs);");
   }
}