|
@@ -335,44 +335,50 @@ public class ItemGroupServiceImpl implements ItemGroupService {
|
|
|
if (Blank.isEmpty(dataSource.getIpAddress(), dataSource.getIpUserName(), dataSource.getIpPassword())) {
|
|
|
throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "数据组配置的数据源的ip地址,帐户,密码都不能为空");
|
|
|
}
|
|
|
- Server server = null;
|
|
|
- try {
|
|
|
- server = OpcDaUtil.createServer(dataSource);
|
|
|
- if (Blank.isEmpty(server)) {
|
|
|
- return Result.no(ResultEnum.REQUEST_TIME_OUT.getRespCode(), "创建服务失败");
|
|
|
+ synchronized (this) {
|
|
|
+ Integer runNum = itemGroupDao.getRunItemGroupNum(dataSource.getIpAddress(), dataSource.getClsId(), ConstantStr.START_UP);
|
|
|
+ if (runNum >= ConstantStr.DATA_SOURCE_GROUP_NUM) {
|
|
|
+ return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "此驱动运行的数量超过5个,请先关闭一些不必要的数据组,再启动");
|
|
|
}
|
|
|
- server.connect();
|
|
|
- } catch (Exception e) {
|
|
|
- throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), OpcDaUtil.genException(e.getMessage()));
|
|
|
- } finally {
|
|
|
- if (Blank.isNotEmpty(server)) {
|
|
|
- server.dispose();
|
|
|
+ Server server = null;
|
|
|
+ try {
|
|
|
+ server = OpcDaUtil.createServer(dataSource);
|
|
|
+ if (Blank.isEmpty(server)) {
|
|
|
+ return Result.no(ResultEnum.REQUEST_TIME_OUT.getRespCode(), "创建服务失败");
|
|
|
+ }
|
|
|
+ server.connect();
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), OpcDaUtil.genException(e.getMessage()));
|
|
|
+ } finally {
|
|
|
+ if (Blank.isNotEmpty(server)) {
|
|
|
+ server.dispose();
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- redisUtil.set(ConstantStr.ITEM_GROUP + id, true);
|
|
|
- //新增定时器任务
|
|
|
- String cronId = Blank.isEmpty(itemGroup.getCronId()) ?
|
|
|
- UUID.randomUUID().toString().replace("-", "") :
|
|
|
- itemGroup.getCronId();
|
|
|
- String cron = "0 0 0 ? * ";
|
|
|
- if (Blank.isEmpty(readWeek)) {
|
|
|
- cron = cron + "MON,TUE,WED,THU,FRI,SAT,SUN";
|
|
|
- //立即执行一次Timer
|
|
|
- opcDaTask.opcDaTask(itemGroup, dataSource, cronId);
|
|
|
- } else {
|
|
|
- cron = cron + readWeek;
|
|
|
- for (String str : readWeek.split(",")) {
|
|
|
- if (str.equals(DateUtil.getCurrentWeekEn())) {
|
|
|
- //立即执行一次Timer
|
|
|
- opcDaTask.opcDaTask(itemGroup, dataSource, cronId);
|
|
|
- break;
|
|
|
+ redisUtil.set(ConstantStr.ITEM_GROUP + id, true);
|
|
|
+ //新增定时器任务
|
|
|
+ String cronId = Blank.isEmpty(itemGroup.getCronId()) ?
|
|
|
+ UUID.randomUUID().toString().replace("-", "") :
|
|
|
+ itemGroup.getCronId();
|
|
|
+ String cron = "0 0 0 ? * ";
|
|
|
+ if (Blank.isEmpty(readWeek)) {
|
|
|
+ cron = cron + "MON,TUE,WED,THU,FRI,SAT,SUN";
|
|
|
+ //立即执行一次Timer
|
|
|
+ opcDaTask.opcDaTask(itemGroup, dataSource, cronId);
|
|
|
+ } else {
|
|
|
+ cron = cron + readWeek;
|
|
|
+ for (String str : readWeek.split(",")) {
|
|
|
+ if (str.equals(DateUtil.getCurrentWeekEn())) {
|
|
|
+ //立即执行一次Timer
|
|
|
+ opcDaTask.opcDaTask(itemGroup, dataSource, cronId);
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ SchedulingRunnable task = new SchedulingRunnable(OpcDaTask.class, "opcDaTask", new Object[]{itemGroup, dataSource, cronId});
|
|
|
+ cronTaskRegister.addCronTask(task, cronId, cron);
|
|
|
+ itemGroupDao.runItemGroupById(id, runState, cronId);
|
|
|
+ return Result.ok("启动成功");
|
|
|
}
|
|
|
- SchedulingRunnable task = new SchedulingRunnable(OpcDaTask.class, "opcDaTask", new Object[]{itemGroup, dataSource, cronId});
|
|
|
- cronTaskRegister.addCronTask(task, cronId, cron);
|
|
|
- itemGroupDao.runItemGroupById(id, runState, cronId);
|
|
|
- return Result.ok("启动成功");
|
|
|
} else if (runState.equals(ConstantStr.STOP_IT)) {
|
|
|
redisUtil.set(ConstantStr.ITEM_GROUP + id, false);
|
|
|
itemGroupDao.stopItemGroupById(id, runState);
|