@Override
 public void updateState(int id, int state, int type) {
   WorldServer worldServer = this.get(id);
   if (type == 0) { // 0为更新运行状态
     CacheService.getWorldServerById(id).setState(state);
     worldServer.setState(state);
   } else if (type == 1) { // 1为更新部署状态
     CacheService.getWorldServerById(id).setIsDeploy(state);
     worldServer.setIsDeploy(state);
   }
   this.update(worldServer);
 }
 /** 同步配置信息 */
 @Override
 public void synchronizeConfig(String worldIds) {
   String[] ids = worldIds.split(",");
   for (int i = 0; i < ids.length; i++) {
     Map<String, String> configMap =
         SshxcuteUtils.getConfigMap(
             CacheService.getWorldServerById(Integer.valueOf(ids[i])),
             Global.CONFIG_WORLD_PROPERTIES);
     this.updateWorldByMap(Integer.valueOf(ids[i]), configMap);
   }
 }
 /** 迁移当前机子的数据到其他机子 */
 public String updateCfgToOtherServer(ChangeServerVo changeServerVo) {
   String result = "success";
   try {
     WorldServer worldServer = CacheService.getWorldServerById(changeServerVo.getId());
     changeServerVo.setRemark("修改" + worldServer.getName() + "数据库配置中");
     if (changeServerVo.getServerId() == worldServer.getServerId()) {
       changeServerVo.setRemark("服务已在当前服务器,请确认目标服务器是否正确");
       result = "服务已在当前服务器,请确认目标服务器是否正确";
       return result;
     }
     int serverId = changeServerVo.getServerId(); // 迁移目标serverId
     Server server = CacheService.getServerById(serverId);
     String publicip = server.getServerName().trim(); // 目标机子公共ip
     // 获取排好序的world列表(port倒序)
     List<WorldServer> worldServerList = worldServerDao.getWorldServerListByServerId(serverId);
     if (worldServerList != null && worldServerList.size() > 0) {
       WorldServer worldServerTemp = worldServerList.get(0); // 获取port最大的WorldServer
       // 判断目标机子上是否已经存在改端口
       if (worldServerDao.get(
               new String[] {"port", "serverId"},
               new Object[] {worldServerTemp.getPort() + 1, serverId})
           != null) {
         result = "world存在相同的port,生成失败";
         System.out.println("world存在相同的port,生成失败");
         return result;
       }
       worldServer.setPort(worldServerTemp.getPort() + 1);
       worldServer.setAdminport(worldServerTemp.getAdminport() + 1);
       worldServer.setHttpport(worldServerTemp.getHttpport() + 1);
     } else { // 如果该机子没有记录,则设置初设值
       worldServer.setPort(6860);
       worldServer.setAdminport(28960);
       worldServer.setHttpport(6660);
     }
     worldServer.setServerId(serverId);
     worldServer.setAccountId(CacheService.getAccountServerByServerId(serverId).getId());
     worldServer.setPublicip(publicip);
     this.saveOrUpdate(worldServer);
     CacheService.initWorldServer();
   } catch (Exception e) {
     e.printStackTrace();
   }
   return result;
 }
 /**
  * 關閉world
  *
  * @param batchOpearVo 操作vo
  * @param dispatchServerIds 已開啟的dispatch服務Id
  * @param worldId worldID
  */
 public boolean closeWorld(
     BatchOpearVo batchOpearVo,
     WorldServer worldServer,
     List<Integer> dispatchServerIds,
     ServerService serverService)
     throws Exception {
   boolean closeResult = false;
   batchOpearVo.setRemark(worldServer.getName() + "正在关闭");
   WorldServerService worldServerService = Application.getBean(WorldServerService.class);
   Server server = serverService.get(worldServer.getServerId());
   // worldServer已关闭的情况
   if (worldServer.getState() == CommanConstant.STATE_STOP) {
     boolean result =
         SshxcuteUtils.progressIsExistNew(server, worldServer.getPath(), Global.WORLD_PID_FILE);
     if (!result) {
       return true;
     }
   }
   if (dispatchServerIds != null && dispatchServerIds.size() > 0) {
     // System.out.println("=====dispatchServerIds=====" + dispatchServerIds.toArray().toString());
     boolean dispatchCloseIsSuccess =
         worldServerService.dispatchCloseIsSuccess(
             dispatchServerIds, worldServer, server, CommanConstant.STATE_STOP);
     // 检测Dispatch服务是否关闭完成,若未完成则不关闭world服务
     if (!dispatchCloseIsSuccess) {
       batchOpearVo.isFail("分发服关闭未完成,请关闭再试");
       return closeResult;
     }
   }
   Object[] killResult = SshxcuteUtils.killExec(server, worldServer.getPath());
   if (killResult != null
       && killResult.length > 0
       && (Integer) killResult[0] != CommanConstant.RESULT_TRUE_STATE) {
     batchOpearVo.isFail(worldServer.getName() + "world关闭出错");
     return closeResult;
   }
   worldServer.setState(CommanConstant.STATE_STOP);
   worldServerService.update(worldServer);
   CacheService.getWorldServerById(worldServer.getId()).setState(CommanConstant.STATE_STOP);
   batchOpearVo.isSUCCESS(worldServer.getName() + "world关闭成功");
   closeResult = true;
   return closeResult;
 }
 /** 根据worldIds获取所对应的ACCOUNT中未开启的accountId */
 public StringBuilder getAccountState(String worldIds) {
   StringBuilder sb = new StringBuilder();
   try {
     String[] worldIdArray = worldIds.split(",");
     for (int i = 0; i < worldIdArray.length; i++) {
       AccountServer accountServer =
           CacheService.getAccountServerById(
               CacheService.getWorldServerById(Integer.valueOf(worldIdArray[i])).getAccountId());
       // 检测ACCOUNT服务是否开启
       if (accountServer.getState() == CommanConstant.STATE_STOP) {
         sb.append(accountServer.getId()).append(",");
       }
     }
   } catch (Exception e) {
     sb.append(e.getMessage());
     e.printStackTrace();
   }
   return sb;
 }
 /**
  * 获取运行结果信息
  *
  * @author:LKJ
  */
 public String getStdout(Server server, WorldServer worldServer, HttpSession session)
     throws Exception {
   boolean successResult = false;
   boolean exceptionResult = false;
   String result = "";
   Object[] stdResult = SshxcuteUtils.showStdout(server, worldServer.getPath());
   String successStr = Global.WORLD_SUCCESS_RESULT;
   String exceptionStr = "Exception";
   if (stdResult != null && stdResult.length > 0 && stdResult[1] != null) {
     successResult = CommonUtil.Pattern(successStr, stdResult[1].toString());
     exceptionResult = CommonUtil.Pattern(exceptionStr, stdResult[1].toString());
   }
   if (exceptionResult) {
     result = "false";
     SystemLogService.worldServerLog(
         session, ":" + worldServer.getId() + "," + stdResult[1].toString());
   } else if (successResult) {
     result = "true";
     CacheService.getWorldServerById(worldServer.getId()).setState(CommanConstant.STATE_START);
     worldServer.setState(CommanConstant.STATE_START);
     Application.getBean(WorldServerService.class).update(worldServer);
   }
   return result;
 }
 /**
  * 获取通配信息
  *
  * @param worldServerModel
  * @return
  */
 @Override
 public String getWildcard(int worldId) {
   StringBuffer sb = new StringBuffer();
   WorldServer worldServer = CacheService.getWorldServerById(worldId);
   if (worldServer != null && worldServer.getId() > 0) {
     sb.append(worldServer.getLocalip())
         .append(",")
         .append(worldServer.getPort())
         .append(",")
         .append(worldServer.getAdminip())
         .append(",")
         .append(worldServer.getAdminport())
         .append(",")
         .append(worldServer.getHttpip())
         .append(",")
         .append(worldServer.getPublicip())
         .append(",")
         .append(worldServer.getHttpport())
         .append(",")
         .append(worldServer.getAuthip())
         .append(",")
         .append(worldServer.getAuthport())
         .append(",")
         .append(worldServer.getAreaid())
         .append(",")
         .append(worldServer.getMachinecode())
         .append(",")
         .append(worldServer.getServerType())
         .append(",")
         .append(worldServer.getBattleip())
         .append(",")
         .append(worldServer.getBattleport())
         .append(",");
   }
   return sb.toString();
 }