|
@@ -53,11 +53,29 @@ public class IScadaDtuSyncImpl implements ScadaDtuSyncService {
|
|
|
private String companyId;
|
|
|
|
|
|
|
|
|
- * 绵阳公司id
|
|
|
+ * 重庆公司id
|
|
|
*/
|
|
|
@Value("${scada.cq.companyId}")
|
|
|
private String cqCompanyId;
|
|
|
|
|
|
+
|
|
|
+ * 富平公司id
|
|
|
+ */
|
|
|
+ @Value("${scada.fp.companyId}")
|
|
|
+ private String fpCompanyId;
|
|
|
+
|
|
|
+
|
|
|
+ * 富平公司密匙
|
|
|
+ */
|
|
|
+ @Value("${scada.fp.appSecret}")
|
|
|
+ private String fpAppSecret;
|
|
|
+
|
|
|
+
|
|
|
+ * 富平公司id
|
|
|
+ */
|
|
|
+ @Value("${scada.fp.clientId}")
|
|
|
+ private String fpClientId;
|
|
|
+
|
|
|
|
|
|
* 对接密匙
|
|
|
*/
|
|
@@ -369,4 +387,141 @@ public class IScadaDtuSyncImpl implements ScadaDtuSyncService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void scadaDtuSyncFPList() throws Exception {
|
|
|
+ Map<String, Object> resultMap;
|
|
|
+ HttpClient client = HttpClients.createDefault();
|
|
|
+
|
|
|
+ String url = ip + getDtuList;
|
|
|
+ long timeStamp = System.currentTimeMillis();
|
|
|
+
|
|
|
+ HttpGet request = new HttpGet(url);
|
|
|
+ request.setHeader("User-Agent", "Apipost client Runtime/+https://www.apipost.cn/");
|
|
|
+ request.setHeader("Clientid", fpClientId);
|
|
|
+ request.setHeader("Companyid", fpCompanyId);
|
|
|
+ request.setHeader("Timestamp", timeStamp + "");
|
|
|
+ request.setHeader("Sign", SingUtil.getSing(getDtuList, fpCompanyId, timeStamp, fpAppSecret));
|
|
|
+
|
|
|
+ org.apache.http.HttpResponse res = client.execute(request);
|
|
|
+
|
|
|
+ String response = EntityUtils.toString(res.getEntity());
|
|
|
+ if (res.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
|
|
|
+
|
|
|
+ resultMap = JSONObject.parseObject(response, new TypeReference<Map<String, Object>>() {
|
|
|
+ });
|
|
|
+
|
|
|
+ Integer code = (Integer) resultMap.get("code");
|
|
|
+ if (HttpStatus.SC_UNAUTHORIZED == code) {
|
|
|
+ log.error("获取站点信息列表,鉴权失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (0 == code) {
|
|
|
+ List<ScadaDtuListVo> data = JSONObject.parseArray(JSON.toJSONString(resultMap.get("data")), ScadaDtuListVo.class);
|
|
|
+ Long companyId = 2L;
|
|
|
+ data.forEach(info->{
|
|
|
+ info.setCompanyId(companyId);
|
|
|
+ String dtuId = info.getDtuId();
|
|
|
+ info.getFieldList().forEach(i -> {
|
|
|
+ i.setCompanyId(companyId);
|
|
|
+ i.setDtuId(dtuId);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ synchronized (this) {
|
|
|
+
|
|
|
+ Map<String, ScadaDtuListVo> collect = data.stream().collect(Collectors.toMap(ScadaDtuListVo::getDtuId, a -> a, (k1, k2) -> k1));
|
|
|
+ Collection<ScadaDtuListVo> values = collect.values();
|
|
|
+
|
|
|
+ scadaDtuService.deleteCompany(companyId);
|
|
|
+ List<ScadaDtu> scadaDtuList = JSONObject.parseArray(JSON.toJSONString(values), ScadaDtu.class);
|
|
|
+ scadaDtuService.saveBatch(scadaDtuList);
|
|
|
+ List<ScadaDtuParModel> list = new ArrayList<>();
|
|
|
+ values.forEach(info-> list.addAll(info.getFieldList()));
|
|
|
+
|
|
|
+ scadaDtuParModelService.deleteCompany(companyId);
|
|
|
+ scadaDtuParModelService.saveBatch(list);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void scadaDtuSynFPData() throws Exception {
|
|
|
+ Map<String, Object> resultMap;
|
|
|
+ HttpClient client = HttpClients.createDefault();
|
|
|
+
|
|
|
+ String url = ip + getRealTimeDataList;
|
|
|
+ long timeStamp = System.currentTimeMillis();
|
|
|
+
|
|
|
+ HttpGet request = new HttpGet(url);
|
|
|
+ request.setHeader("User-Agent", "Apipost client Runtime/+https://www.apipost.cn/");
|
|
|
+ request.setHeader("Clientid", fpClientId);
|
|
|
+ request.setHeader("Companyid", fpCompanyId);
|
|
|
+ request.setHeader("Timestamp", timeStamp + "");
|
|
|
+ request.setHeader("Sign", SingUtil.getSing(getRealTimeDataList, fpCompanyId, timeStamp, fpAppSecret));
|
|
|
+
|
|
|
+ org.apache.http.HttpResponse res = client.execute(request);
|
|
|
+
|
|
|
+ String response = EntityUtils.toString(res.getEntity());
|
|
|
+ if (res.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
|
|
|
+
|
|
|
+ resultMap = JSONObject.parseObject(response, new TypeReference<Map<String, Object>>() {
|
|
|
+ });
|
|
|
+
|
|
|
+ Integer code = (Integer) resultMap.get("code");
|
|
|
+ if (HttpStatus.SC_UNAUTHORIZED == code) {
|
|
|
+ log.error("获取站点实时数据列表,鉴权失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (0 == code) {
|
|
|
+ List<ScadaDtuDataVo> data = JSONObject.parseArray(JSON.toJSONString(resultMap.get("data")), ScadaDtuDataVo.class);
|
|
|
+ data.forEach(info->{
|
|
|
+ String dtuId = info.getDtuId();
|
|
|
+ info.getFieldValueList().forEach(i -> i.setDtuId(dtuId));
|
|
|
+ });
|
|
|
+ List<ScadaDyuData> originalList = new ArrayList<>();
|
|
|
+
|
|
|
+ data.forEach(info-> originalList.addAll(info.getFieldValueList()));
|
|
|
+ List<ScadaDyuData> list = originalList.stream()
|
|
|
+ .sorted(Comparator.comparing(ScadaDyuData::getCollectTime).reversed())
|
|
|
+ .collect(Collectors.collectingAndThen(Collectors.toCollection(() ->
|
|
|
+ new TreeSet<>(Comparator.comparing(o -> o.getDtuId() + "-" + o.getFieldName() + "-" + DateUtil.getDateFormat(o.getCollectTime(), "yyyyMMddHHmm")))), ArrayList::new));
|
|
|
+ for (ScadaDyuData scadaDyuData : list) {
|
|
|
+ try {
|
|
|
+ scadaDyuDataService.save(scadaDyuData);
|
|
|
+ } catch (Exception ignored) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Set<String> dtuIdSet = list.stream().map(ScadaDyuData::getDtuId).collect(Collectors.toSet());
|
|
|
+ Set<String> fieldNameSet = list.stream().map(ScadaDyuData::getFieldName).collect(Collectors.toSet());
|
|
|
+ List<ScadaDyuDataReal> dataReals = scadaDyuDataRealService.list(new QueryWrapper<ScadaDyuDataReal>().lambda().in(ScadaDyuDataReal::getDtuId, dtuIdSet).in(ScadaDyuDataReal::getFieldName, fieldNameSet));
|
|
|
+ if(null!=dataReals && dataReals.size()>0) {
|
|
|
+ dataReals.forEach(info -> {
|
|
|
+ String dtuId = info.getDtuId();
|
|
|
+ String fieldName = info.getFieldName();
|
|
|
+ list.forEach(da -> {
|
|
|
+ if(dtuId.equals(da.getDtuId()) && fieldName.equals(da.getFieldName())) {
|
|
|
+ scadaDyuDataRealService.update(new UpdateWrapper<ScadaDyuDataReal>().lambda()
|
|
|
+ .eq(ScadaDyuDataReal::getDtuId,dtuId)
|
|
|
+ .eq(ScadaDyuDataReal::getFieldName,fieldName)
|
|
|
+ .set(ScadaDyuDataReal::getUpdateTime,da.getUpdateTime())
|
|
|
+ .set(ScadaDyuDataReal::getCollectTime,da.getCollectTime())
|
|
|
+ .set(ScadaDyuDataReal::getFieldValue,da.getFieldValue()));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }else {
|
|
|
+ List<ScadaDyuDataReal> scadaDyuDataRealList = JSONArray.parseArray(JSON.toJSONString(list), ScadaDyuDataReal.class);
|
|
|
+ scadaDyuDataRealService.saveBatch(scadaDyuDataRealList);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|