|
@@ -13,11 +13,13 @@ import com.example.opc_da.util.OpcDaUtil;
|
|
|
import com.example.opc_da.util.RedisUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.openscada.opc.dcom.da.OPCSERVERSTATE;
|
|
|
+import org.openscada.opc.dcom.da.OPCSERVERSTATUS;
|
|
|
import org.openscada.opc.lib.da.Item;
|
|
|
import org.openscada.opc.lib.da.*;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
|
|
import static com.example.opc_da.util.OpcDaUtil.getVal;
|
|
|
|
|
@@ -89,8 +91,8 @@ public class OpcDaChangeTask extends TimerTask {
|
|
|
Integer readModeType = itemGroup.getReadModeType();
|
|
|
Double modeValue = itemGroup.getModeValue();
|
|
|
Integer dataSourceId = dataSource.getId();
|
|
|
- SyncAccess access = null;
|
|
|
try {
|
|
|
+ AtomicReference<Long> index = new AtomicReference<>(0L);
|
|
|
server.connect();
|
|
|
server.addStateListener(connected -> {
|
|
|
if (!connected) {
|
|
@@ -130,337 +132,158 @@ public class OpcDaChangeTask extends TimerTask {
|
|
|
}
|
|
|
}, 60000);
|
|
|
}
|
|
|
- }
|
|
|
- });
|
|
|
- } catch (Exception e) {
|
|
|
- String message = OpcDaUtil.genException(e.getMessage());
|
|
|
- messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
|
|
|
- itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "运行失败",
|
|
|
- message,
|
|
|
- ConstantStr.NO_READ));
|
|
|
- if (Blank.isNotEmpty(server)) {
|
|
|
- server.dispose();
|
|
|
- }
|
|
|
- itemGroupDao.stopItemGroupById(itemGroup.getId(), ConstantStr.STOP_IT);
|
|
|
- cronTaskRegister.removeCronTask(cronId);
|
|
|
- timer.cancel();
|
|
|
- }
|
|
|
- try {
|
|
|
- Group group = server.addGroup();
|
|
|
- Map<String, org.openscada.opc.lib.da.Item> itemResult = group.addItems(items);
|
|
|
- Set itemSet = new HashSet(itemResult.values());
|
|
|
- org.openscada.opc.lib.da.Item[] itemArr = new org.openscada.opc.lib.da.Item[itemSet.size()];
|
|
|
- itemSet.toArray(itemArr);
|
|
|
- String sqlCurrentYmdh = "";
|
|
|
- Long index = 0L;
|
|
|
- while (true) {
|
|
|
- Boolean flage = (Boolean) redisUtil.get(ConstantStr.ITEM_GROUP + id);
|
|
|
- if (Blank.isEmpty(flage)) {
|
|
|
- flage = false;
|
|
|
- }
|
|
|
- if (!flage) {
|
|
|
- //执行组装数据库的数据,以及生成驱动报表
|
|
|
- sqlCurrentYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id));
|
|
|
- if (Blank.isNotEmpty(sqlCurrentYmdh)) {
|
|
|
- opcAsyncTask.packageRawDataList(itemList, dataSourceId, sqlCurrentYmdh);
|
|
|
- }
|
|
|
- redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id);
|
|
|
- if (Blank.isNotEmpty(server)) {
|
|
|
- server.dispose();
|
|
|
- }
|
|
|
- cronTaskRegister.removeCronTask(cronId);
|
|
|
- redisUtil.del(ConstantStr.ITEM_GROUP + id);
|
|
|
- timer.cancel();
|
|
|
- break;
|
|
|
- }
|
|
|
- if (System.currentTimeMillis() >= endTime) {
|
|
|
- //执行组装数据库的数据,以及生成驱动报表
|
|
|
- sqlCurrentYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id));
|
|
|
- if (Blank.isNotEmpty(sqlCurrentYmdh)) {
|
|
|
- opcAsyncTask.packageRawDataList(itemList, dataSourceId, sqlCurrentYmdh);
|
|
|
- }
|
|
|
- redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id);
|
|
|
- if (Blank.isNotEmpty(server)) {
|
|
|
- server.dispose();
|
|
|
- }
|
|
|
- timer.cancel();
|
|
|
- break;
|
|
|
- }
|
|
|
- try {
|
|
|
- Thread.sleep(1000);
|
|
|
- index++;
|
|
|
- Map<org.openscada.opc.lib.da.Item, ItemState> resultMap = group.read(true, itemArr);
|
|
|
- List<CursorRawData> cursorRawDataList = new ArrayList<>();
|
|
|
- for (Item key : resultMap.keySet()) {
|
|
|
- String keyId = key.getId();
|
|
|
- ItemState itemMap = resultMap.get(key);
|
|
|
- Map<String, Object> val = getVal(itemMap.getValue());
|
|
|
- String javaType = val.get("javaType").toString();
|
|
|
- Object value = val.get("value");
|
|
|
- Date time = itemMap.getTimestamp().getTime();
|
|
|
- String currentYmdh = DateUtil.dateChangeStr(time, timeFormat);
|
|
|
- String currentYmdhmss = DateUtil.dateChangeStrYmdhmss(time);
|
|
|
- if (Blank.isEmpty(sqlCurrentYmdh)) {
|
|
|
- sqlCurrentYmdh = currentYmdh;
|
|
|
- redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id, currentYmdh, ConstantStr.TWO_HOUR);
|
|
|
- } else {
|
|
|
- if (!sqlCurrentYmdh.equals(currentYmdh)) {
|
|
|
- //组装相应的原始数据
|
|
|
- opcAsyncTask.packageRawDataList(itemList, dataSourceId, sqlCurrentYmdh);
|
|
|
- sqlCurrentYmdh = currentYmdh;
|
|
|
+ }else{
|
|
|
+ try {
|
|
|
+ Group group = server.addGroup();
|
|
|
+ Map<String, org.openscada.opc.lib.da.Item> itemResult = group.addItems(items);
|
|
|
+ Set itemSet = new HashSet(itemResult.values());
|
|
|
+ org.openscada.opc.lib.da.Item[] itemArr = new org.openscada.opc.lib.da.Item[itemSet.size()];
|
|
|
+ itemSet.toArray(itemArr);
|
|
|
+ String sqlCurrentYmdh = "";
|
|
|
+ while (true) {
|
|
|
+ Boolean flage = (Boolean) redisUtil.get(ConstantStr.ITEM_GROUP + id);
|
|
|
+ if (Blank.isEmpty(flage)) {
|
|
|
+ flage = false;
|
|
|
}
|
|
|
- }
|
|
|
- if (!javaType.toLowerCase().equals("boolean")) {
|
|
|
- try {
|
|
|
- DataModel dm = map.get(keyId);
|
|
|
- if (Blank.isNotEmpty(dm) && dm.getModelType().equals(ConstantStr.VALUE_REPLACE)
|
|
|
- && dm.getOperationRule().equals(value.toString())) {
|
|
|
-
|
|
|
- } else {
|
|
|
- BigDecimal bigDecimal = JSON.parseObject(value.toString(), BigDecimal.class);
|
|
|
- BigDecimal dmData = Blank.isNotEmpty(dm) ? MathUtil.quadricOperation(dm, bigDecimal) : bigDecimal;
|
|
|
- Object oldValue = redisUtil.get(ConstantStr.VALUE + id + keyId);
|
|
|
- CursorRawData cursorRawData = new CursorRawData(id, dataSourceId, keyId, javaType, bigDecimal.toString(), dmData.toString(),
|
|
|
- currentYmdhmss, index, currentYmdh,
|
|
|
- ConstantStr.IS_RECORD, new Date());
|
|
|
- if (Blank.isEmpty(oldValue)) {
|
|
|
- cursorRawDataList.add(cursorRawData);
|
|
|
- } else {
|
|
|
- if ((MathUtil.isMeetChange((BigDecimal) oldValue,
|
|
|
- dmData, new BigDecimal(modeValue), readModeType)).equals(ConstantStr.IS_RECORD)) {
|
|
|
- cursorRawDataList.add(cursorRawData);
|
|
|
- }
|
|
|
- }
|
|
|
- redisUtil.set(ConstantStr.VALUE + id + keyId, dmData, ConstantStr.TWO_HOUR);
|
|
|
+ if (!flage) {
|
|
|
+ //执行组装数据库的数据,以及生成驱动报表
|
|
|
+ sqlCurrentYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id));
|
|
|
+ if (Blank.isNotEmpty(sqlCurrentYmdh)) {
|
|
|
+ opcAsyncTask.packageRawDataList(itemList, dataSourceId, sqlCurrentYmdh);
|
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
-
|
|
|
+ redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id);
|
|
|
+ if (Blank.isNotEmpty(server)) {
|
|
|
+ server.dispose();
|
|
|
+ }
|
|
|
+ cronTaskRegister.removeCronTask(cronId);
|
|
|
+ redisUtil.del(ConstantStr.ITEM_GROUP + id);
|
|
|
+ timer.cancel();
|
|
|
+ break;
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
- if (Blank.isNotEmpty(cursorRawDataList)) {
|
|
|
- opcAsyncTask.addCursorRawDataList(cursorRawDataList);
|
|
|
- cursorRawDataList = new ArrayList<>();
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- flage = (Boolean) redisUtil.get(ConstantStr.ITEM_GROUP + id);
|
|
|
- if (Blank.isEmpty(flage)) {
|
|
|
- flage = false;
|
|
|
- }
|
|
|
- if (!flage) {
|
|
|
- //执行组装数据库的数据,以及生成驱动报表
|
|
|
- sqlCurrentYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id));
|
|
|
- opcAsyncTask.packageRawDataList(itemList, dataSourceId, sqlCurrentYmdh);
|
|
|
- redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id);
|
|
|
- if (Blank.isNotEmpty(server)) {
|
|
|
- server.dispose();
|
|
|
- }
|
|
|
- itemGroupDao.stopItemGroupById(itemGroup.getId(), ConstantStr.STOP_IT);
|
|
|
- cronTaskRegister.removeCronTask(cronId);
|
|
|
- timer.cancel();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- Boolean flage = (Boolean) redisUtil.get(ConstantStr.ITEM_GROUP + id);
|
|
|
- if (Blank.isEmpty(flage)) {
|
|
|
- flage = false;
|
|
|
- }
|
|
|
- if (!flage) {
|
|
|
- //执行组装数据库的数据,以及生成驱动报表
|
|
|
- String sqlCurrentYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id));
|
|
|
- opcAsyncTask.packageRawDataList(itemList, dataSourceId, sqlCurrentYmdh);
|
|
|
- redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id);
|
|
|
- if (Blank.isNotEmpty(server)) {
|
|
|
- server.dispose();
|
|
|
- }
|
|
|
- itemGroupDao.stopItemGroupById(itemGroup.getId(), ConstantStr.STOP_IT);
|
|
|
- cronTaskRegister.removeCronTask(cronId);
|
|
|
- timer.cancel();
|
|
|
- }
|
|
|
- }
|
|
|
- try {
|
|
|
- access = new SyncAccess(server, 500);
|
|
|
- for (com.example.opc_common.entity.Item item : itemList) {
|
|
|
- String itemId = item.getItemReadName();
|
|
|
- access.addItem(itemId, new DataCallback() {
|
|
|
- private BigDecimal oldValue;
|
|
|
- private String sqlCurrentYmdh = "";
|
|
|
- private Long index = 0L;
|
|
|
-
|
|
|
- @Override
|
|
|
- public void changed(Item item1, ItemState itemState) {
|
|
|
- index++;
|
|
|
- try {
|
|
|
- Map<String, Object> val = OpcDaUtil.getVal(itemState.getValue());
|
|
|
- DataModel dm = map.get(itemId);
|
|
|
- //读取的值
|
|
|
- String javaType = String.valueOf(val.get("javaType"));
|
|
|
- Object value = val.get("value");
|
|
|
- //值对应取值的时间
|
|
|
- Date time = itemState.getTimestamp().getTime();
|
|
|
- String currentYmdh = DateUtil.dateChangeStr(time, timeFormat);
|
|
|
- String currentYmdhmss = DateUtil.dateChangeStrYmdhmss(time);
|
|
|
- if (Blank.isEmpty(sqlCurrentYmdh)) {
|
|
|
- sqlCurrentYmdh = currentYmdh;
|
|
|
- redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id, currentYmdh, ConstantStr.TWO_HOUR);
|
|
|
- } else {
|
|
|
- if (!sqlCurrentYmdh.equals(currentYmdh)) {
|
|
|
- //组装相应的原始数据
|
|
|
+ if (System.currentTimeMillis() >= endTime) {
|
|
|
+ //执行组装数据库的数据,以及生成驱动报表
|
|
|
+ sqlCurrentYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id));
|
|
|
+ if (Blank.isNotEmpty(sqlCurrentYmdh)) {
|
|
|
opcAsyncTask.packageRawDataList(itemList, dataSourceId, sqlCurrentYmdh);
|
|
|
- redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id, currentYmdh, ConstantStr.TWO_HOUR);
|
|
|
- sqlCurrentYmdh = currentYmdh;
|
|
|
}
|
|
|
+ redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id);
|
|
|
+ if (Blank.isNotEmpty(server)) {
|
|
|
+ server.dispose();
|
|
|
+ }
|
|
|
+ timer.cancel();
|
|
|
+ break;
|
|
|
}
|
|
|
- String valueStr = value.toString();
|
|
|
- if (javaType.toLowerCase().equals("boolean")) {
|
|
|
- Boolean data = JSON.parseObject(valueStr, Boolean.class);
|
|
|
- if (Blank.isNotEmpty(dm) && dm.getModelType().equals(ConstantStr.VALUE_REPLACE) && dm.getOperationRule().equals(valueStr)) {
|
|
|
- CursorRawData cursorRawData = new CursorRawData(id, dataSourceId, itemId, javaType, JSON.toJSONString(data), dm.getReplacingValue(),
|
|
|
- currentYmdhmss, index, currentYmdh, ConstantStr.NOT_RECORD, new Date());
|
|
|
- opcAsyncTask.addCursorRawData(cursorRawData);
|
|
|
- } else {
|
|
|
- CursorRawData cursorRawData = new CursorRawData(id, dataSourceId, itemId, javaType, JSON.toJSONString(data), JSON.toJSONString(data),
|
|
|
- currentYmdhmss, index, currentYmdh, ConstantStr.NOT_RECORD, new Date());
|
|
|
- opcAsyncTask.addCursorRawData(cursorRawData);
|
|
|
+ try {
|
|
|
+ Thread.sleep(1000);
|
|
|
+ OPCSERVERSTATUS serverState = server.getServerState();
|
|
|
+ if (Blank.isEmpty(serverState)){
|
|
|
+ break;
|
|
|
}
|
|
|
- } else {
|
|
|
- try {
|
|
|
- BigDecimal bigDecimal = JSON.parseObject(valueStr, BigDecimal.class);
|
|
|
- if (Blank.isNotEmpty(dm) && dm.getModelType().equals(ConstantStr.VALUE_REPLACE) && dm.getOperationRule().equals(valueStr)) {
|
|
|
- CursorRawData cursorRawData = new CursorRawData(id, dataSourceId, itemId, javaType, JSON.toJSONString(bigDecimal), dm.getReplacingValue(),
|
|
|
- currentYmdhmss, index, currentYmdh, ConstantStr.NOT_RECORD, new Date());
|
|
|
- opcAsyncTask.addCursorRawData(cursorRawData);
|
|
|
+ Map<org.openscada.opc.lib.da.Item, ItemState> resultMap = group.read(true, itemArr);
|
|
|
+ index.getAndSet(index.get() + 1);
|
|
|
+ List<CursorRawData> cursorRawDataList = new ArrayList<>();
|
|
|
+ for (Item key : resultMap.keySet()) {
|
|
|
+ String keyId = key.getId();
|
|
|
+ ItemState itemMap = resultMap.get(key);
|
|
|
+ Map<String, Object> val = getVal(itemMap.getValue());
|
|
|
+ String javaType = val.get("javaType").toString();
|
|
|
+ Object value = val.get("value");
|
|
|
+ Date time = itemMap.getTimestamp().getTime();
|
|
|
+ String currentYmdh = DateUtil.dateChangeStr(time, timeFormat);
|
|
|
+ String currentYmdhmss = DateUtil.dateChangeStrYmdhmss(time);
|
|
|
+ if (Blank.isEmpty(sqlCurrentYmdh)) {
|
|
|
+ sqlCurrentYmdh = currentYmdh;
|
|
|
+ redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id, currentYmdh, ConstantStr.TWO_HOUR);
|
|
|
} else {
|
|
|
- BigDecimal dmData = Blank.isNotEmpty(dm) ?
|
|
|
- MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) :
|
|
|
- bigDecimal;
|
|
|
- CursorRawData cursorRawData = new CursorRawData(id, dataSourceId, itemId, javaType, JSON.toJSONString(bigDecimal), JSON.toJSONString(dmData),
|
|
|
- currentYmdhmss, index, currentYmdh,
|
|
|
- Blank.isEmpty(oldValue) ? ConstantStr.IS_RECORD : MathUtil.isMeetChange(oldValue,
|
|
|
- dmData, new BigDecimal(modeValue), readModeType), new Date());
|
|
|
- opcAsyncTask.addCursorRawData(cursorRawData);
|
|
|
- oldValue = dmData;
|
|
|
+ if (!sqlCurrentYmdh.equals(currentYmdh)) {
|
|
|
+ //组装相应的原始数据
|
|
|
+ opcAsyncTask.packageRawDataList(itemList, dataSourceId, sqlCurrentYmdh);
|
|
|
+ sqlCurrentYmdh = currentYmdh;
|
|
|
+ }
|
|
|
}
|
|
|
-// BigDecimal dmData = Blank.isNotEmpty(dm) ?
|
|
|
-// MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) :
|
|
|
-// bigDecimal;
|
|
|
-// CursorRawData cursorRawData = new CursorRawData(id, dataSourceId, itemId, javaType, JSON.toJSONString(bigDecimal), JSON.toJSONString(dmData),
|
|
|
-// currentYmdhmss, index, currentYmdh,
|
|
|
-// Blank.isEmpty(oldValue) ? ConstantStr.IS_RECORD : MathUtil.isMeetChange(oldValue,
|
|
|
-// dmData, new BigDecimal(modeValue), readModeType), new Date());
|
|
|
-// opcAsyncTask.addCursorRawData(cursorRawData);
|
|
|
-// oldValue = dmData;
|
|
|
- } catch (Exception e) {
|
|
|
- if (Blank.isNotEmpty(dm) && dm.getModelType().equals(ConstantStr.VALUE_REPLACE) && dm.getOperationRule().equals(valueStr)) {
|
|
|
- CursorRawData cursorRawData = new CursorRawData(id, dataSourceId, itemId, javaType, valueStr, dm.getReplacingValue(),
|
|
|
- currentYmdhmss, index, currentYmdh, ConstantStr.NOT_RECORD, new Date());
|
|
|
- opcAsyncTask.addCursorRawData(cursorRawData);
|
|
|
- } else {
|
|
|
- CursorRawData cursorRawData = new CursorRawData(id, dataSourceId, itemId, javaType, valueStr, "".equals(valueStr) ? ConstantStr.STRING_EMPTY : valueStr,
|
|
|
- currentYmdhmss, index, currentYmdh, ConstantStr.NOT_RECORD, new Date());
|
|
|
- opcAsyncTask.addCursorRawData(cursorRawData);
|
|
|
+ if (!javaType.toLowerCase().equals("boolean")) {
|
|
|
+ try {
|
|
|
+ DataModel dm = map.get(keyId);
|
|
|
+ if (Blank.isNotEmpty(dm) && dm.getModelType().equals(ConstantStr.VALUE_REPLACE)
|
|
|
+ && dm.getOperationRule().equals(value.toString())) {
|
|
|
+
|
|
|
+ } else {
|
|
|
+ BigDecimal bigDecimal = JSON.parseObject(value.toString(), BigDecimal.class);
|
|
|
+ BigDecimal dmData = Blank.isNotEmpty(dm) ? MathUtil.quadricOperation(dm, bigDecimal) : bigDecimal;
|
|
|
+ Object oldValue = redisUtil.get(ConstantStr.VALUE + id + keyId);
|
|
|
+ CursorRawData cursorRawData = new CursorRawData(id, dataSourceId, keyId, javaType, bigDecimal.toString(), dmData.toString(),
|
|
|
+ currentYmdhmss, index.get(), currentYmdh,
|
|
|
+ ConstantStr.IS_RECORD, new Date());
|
|
|
+ if (Blank.isEmpty(oldValue)) {
|
|
|
+ cursorRawDataList.add(cursorRawData);
|
|
|
+ } else {
|
|
|
+ if ((MathUtil.isMeetChange((BigDecimal) oldValue,
|
|
|
+ dmData, new BigDecimal(modeValue), readModeType)).equals(ConstantStr.IS_RECORD)) {
|
|
|
+ cursorRawDataList.add(cursorRawData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ redisUtil.set(ConstantStr.VALUE + id + keyId, dmData, ConstantStr.TWO_HOUR);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ if (Blank.isNotEmpty(cursorRawDataList)) {
|
|
|
+ opcAsyncTask.addCursorRawDataList(cursorRawDataList);
|
|
|
+ cursorRawDataList = new ArrayList<>();
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ flage = (Boolean) redisUtil.get(ConstantStr.ITEM_GROUP + id);
|
|
|
+ if (Blank.isEmpty(flage)) {
|
|
|
+ flage = false;
|
|
|
+ }
|
|
|
+ if (!flage) {
|
|
|
+ //执行组装数据库的数据,以及生成驱动报表
|
|
|
+ sqlCurrentYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id));
|
|
|
+ opcAsyncTask.packageRawDataList(itemList, dataSourceId, sqlCurrentYmdh);
|
|
|
+ redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id);
|
|
|
+ if (Blank.isNotEmpty(server)) {
|
|
|
+ server.dispose();
|
|
|
+ }
|
|
|
+ itemGroupDao.stopItemGroupById(itemGroup.getId(), ConstantStr.STOP_IT);
|
|
|
+ cronTaskRegister.removeCronTask(cronId);
|
|
|
+ timer.cancel();
|
|
|
+ }
|
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
- //执行组装数据库的原始数据
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ Boolean flage = (Boolean) redisUtil.get(ConstantStr.ITEM_GROUP + id);
|
|
|
+ if (Blank.isEmpty(flage)) {
|
|
|
+ flage = false;
|
|
|
+ }
|
|
|
+ if (!flage) {
|
|
|
+ //执行组装数据库的数据,以及生成驱动报表
|
|
|
+ String sqlCurrentYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id));
|
|
|
opcAsyncTask.packageRawDataList(itemList, dataSourceId, sqlCurrentYmdh);
|
|
|
redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id);
|
|
|
-
|
|
|
- messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
|
|
|
- itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "运行停止",
|
|
|
- e.getMessage(),
|
|
|
- ConstantStr.NO_READ));
|
|
|
if (Blank.isNotEmpty(server)) {
|
|
|
server.dispose();
|
|
|
}
|
|
|
- itemGroupDao.stopItemGroupById(id, ConstantStr.STOP_IT);
|
|
|
+ itemGroupDao.stopItemGroupById(itemGroup.getId(), ConstantStr.STOP_IT);
|
|
|
cronTaskRegister.removeCronTask(cronId);
|
|
|
timer.cancel();
|
|
|
}
|
|
|
}
|
|
|
- });
|
|
|
- }
|
|
|
- access.bind();
|
|
|
- while (true) {
|
|
|
- Boolean flage = (Boolean) redisUtil.get(ConstantStr.ITEM_GROUP + id);
|
|
|
- if (Blank.isEmpty(flage)) {
|
|
|
- flage = false;
|
|
|
}
|
|
|
-// if (!access.isActive()) {
|
|
|
-// //执行组装数据库的数据,以及生成驱动报表
|
|
|
-// String sqlCurrentYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id));
|
|
|
-// opcAsyncTask.packageRawDataList(itemList, dataSourceId, sqlCurrentYmdh);
|
|
|
-// redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id);
|
|
|
-// messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
|
|
|
-// itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "运行失败",
|
|
|
-// "服务异常停止了",
|
|
|
-// ConstantStr.NO_READ));
|
|
|
-// if (Blank.isNotEmpty(access)) {
|
|
|
-// access.clear();
|
|
|
-// }
|
|
|
-// if (Blank.isNotEmpty(server)) {
|
|
|
-// server.dispose();
|
|
|
-// }
|
|
|
-// itemGroupDao.stopItemGroupById(id, ConstantStr.EXCEPT_STOP_UP);
|
|
|
-// cronTaskRegister.removeCronTask(cronId);
|
|
|
-// redisUtil.del(ConstantStr.ITEM_GROUP + id);
|
|
|
-// timer.cancel();
|
|
|
-// break;
|
|
|
-// }
|
|
|
- if (!flage) {
|
|
|
- //执行组装数据库的数据,以及生成驱动报表
|
|
|
- String sqlCurrentYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id));
|
|
|
- opcAsyncTask.packageRawDataList(itemList, dataSourceId, sqlCurrentYmdh);
|
|
|
- redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id);
|
|
|
- if (Blank.isNotEmpty(access)) {
|
|
|
- access.clear();
|
|
|
- }
|
|
|
- if (Blank.isNotEmpty(server)) {
|
|
|
- server.dispose();
|
|
|
- }
|
|
|
- cronTaskRegister.removeCronTask(cronId);
|
|
|
- redisUtil.del(ConstantStr.ITEM_GROUP + id);
|
|
|
- timer.cancel();
|
|
|
- break;
|
|
|
- }
|
|
|
- if (System.currentTimeMillis() >= endTime) {
|
|
|
- //执行组装数据库的数据,以及生成驱动报表
|
|
|
- String sqlCurrentYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id));
|
|
|
- opcAsyncTask.packageRawDataList(itemList, dataSourceId, sqlCurrentYmdh);
|
|
|
- redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id);
|
|
|
-
|
|
|
- if (Blank.isNotEmpty(access)) {
|
|
|
- access.clear();
|
|
|
- }
|
|
|
- if (Blank.isNotEmpty(server)) {
|
|
|
- server.dispose();
|
|
|
- }
|
|
|
- timer.cancel();
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
+ });
|
|
|
} catch (Exception e) {
|
|
|
- Boolean flage = (Boolean) redisUtil.get(ConstantStr.ITEM_GROUP + id);
|
|
|
- if (Blank.isEmpty(flage)) {
|
|
|
- flage = false;
|
|
|
- }
|
|
|
- if (!flage) {
|
|
|
- //执行组装数据库的数据,以及生成驱动报表
|
|
|
- String sqlCurrentYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id));
|
|
|
- opcAsyncTask.packageRawDataList(itemList, dataSourceId, sqlCurrentYmdh);
|
|
|
- redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id);
|
|
|
- if (Blank.isNotEmpty(access)) {
|
|
|
- access.clear();
|
|
|
- }
|
|
|
- if (Blank.isNotEmpty(server)) {
|
|
|
- server.dispose();
|
|
|
- }
|
|
|
- itemGroupDao.stopItemGroupById(itemGroup.getId(), ConstantStr.STOP_IT);
|
|
|
- cronTaskRegister.removeCronTask(cronId);
|
|
|
- timer.cancel();
|
|
|
+ String message = OpcDaUtil.genException(e.getMessage());
|
|
|
+ messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
|
|
|
+ itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "运行失败",
|
|
|
+ message,
|
|
|
+ ConstantStr.NO_READ));
|
|
|
+ if (Blank.isNotEmpty(server)) {
|
|
|
+ server.dispose();
|
|
|
}
|
|
|
+ itemGroupDao.stopItemGroupById(itemGroup.getId(), ConstantStr.STOP_IT);
|
|
|
+ cronTaskRegister.removeCronTask(cronId);
|
|
|
+ timer.cancel();
|
|
|
}
|
|
|
}
|
|
|
}
|