Bläddra i källkod

管网同步接口调整

xlr 8 månader sedan
förälder
incheckning
eb2d112604

+ 10 - 3
lysw-gis/src/main/java/com/tofly/xrtygis/custom/service/impl/CustomDisplayServiceImpl.java

@@ -1265,13 +1265,20 @@ public class CustomDisplayServiceImpl implements CustomDisplayService {
         }else {
             waterCruxIndexVo.setLastMonthUserWater(BigDecimal.ZERO);
         }
-
+try{
         //计算昨日供水量
-        waterCruxIndexVo.setYesterdaySupplyWater(customDisplayMapper.getYesterdaySupplyWater(codesChu,"1").divide(BigDecimal.valueOf(10000),2,RoundingMode.HALF_UP));
 
+    BigDecimal  yesterdaySupplyWater=customDisplayMapper.getYesterdaySupplyWater(codesChu,"1");
+   if(yesterdaySupplyWater!=null){
+       yesterdaySupplyWater=yesterdaySupplyWater.divide(BigDecimal.valueOf(10000),2,RoundingMode.HALF_UP);
+   }
+    waterCruxIndexVo.setYesterdaySupplyWater(yesterdaySupplyWater);
+    waterCruxIndexVo.setYesterdayUserWater(yesterdaySupplyWater);
         //计算昨日取水量
-        waterCruxIndexVo.setYesterdayUserWater(customDisplayMapper.getYesterdaySupplyWater(codesChu,"1").divide(BigDecimal.valueOf(10000),2,RoundingMode.HALF_UP));
 
+}catch (Exception e){
+
+}
         WisdomDisplayDto wisLastMonth = new WisdomDisplayDto();
         Calendar cc = Calendar.getInstance();
         cc.add(Calendar.MONTH, -1);

+ 83 - 78
lysw-scada/src/main/java/com/tofly/scada/service/impl/ScadaServiceImpl.java

@@ -774,97 +774,102 @@ public class ScadaServiceImpl extends ServiceImpl<ScadaMapper, Scada> implements
             DeviceArchiveManageVo vo = new DeviceArchiveManageVo();
             BeanUtils.copyProperties(deviceArchiveManage, vo);
             vo.setIsAlarm("0");
-            //查询绑定的指标
-            if (!CollectionUtils.isEmpty(allocations)) {
-                //获取符合设备绑定的指标
-                List<AllocationVo> allocationVos = new HashSet<>(allocations).stream().filter(allocation -> allocation.getDeviceId() != null &&
-                        allocation.getDeviceId().equals(vo.getId())).map(allocation -> {
-                    AllocationVo allocationVo = new AllocationVo();
-                    BeanUtils.copyProperties(allocation, allocationVo);
-                    Scada scadaBelong = null;
-                    //查询scada数据
-
-                    if (!CollectionUtils.isEmpty(scadas)) {
-                        List<Scada> scadaList = scadas.stream()
-                                .filter(scada -> scada.getCode() != null && scada.getCode().equals(allocation.getVariableCode()))
-                                .collect(Collectors.toList());
-                        if (!CollectionUtils.isEmpty(scadaList)) {
-                            scadaBelong = scadaList.get(0);
-                            Long accuracy= allocation.getAccuracy();
-                            //根据设置的精度保留小数位数
-                            if(accuracy==null){
-                                accuracy=2L;
-                            }
-                            //科学技术法处理,不要e哦
-                            BigDecimal bd = new BigDecimal(scadaBelong.getValue());
-                            double roundedNumber = bd.setScale(Integer.parseInt(accuracy+""), BigDecimal.ROUND_HALF_UP).doubleValue();
-                            NumberFormat nf = NumberFormat.getInstance();
-                            nf.setGroupingUsed(false);
-
-                            if(accuracy>0L){
-                                scadaBelong.setValue(nf.format(roundedNumber));
-                            }else{
-                                scadaBelong.setValue(nf.format((int)roundedNumber));
-                            }
-
-                            allocationVo.setScada(scadaBelong);
-                        }
-                    }
-                    //设置报警相关信息
-                    Set<Long> reportIdSets = getReportIdSets(Collections.singletonList(allocation));
-                    if (!CollectionUtils.isEmpty(scadaReports) && !CollectionUtils.isEmpty(reportIdSets)) {
-                        //筛选出报警信息列表
-                        List<ScadaReport> reportsList=new ArrayList<>();
-                        List<ScadaReport> reports = scadaReports.stream().filter(scadaReport -> scadaReport.getId() != null
-                                && reportIdSets.contains(scadaReport.getId())).collect(Collectors.toList());
-                        //设置指标报警状态为未报警
-                        allocationVo.setIsAlarm("0");
-                        //判断指标是否报警
-                        if (scadaBelong != null && scadaBelong.getValue() != null) {
-                            for (ScadaReport scadaReport : reports) {
-                                if (scadaReport.getReportLower() == null || scadaReport.getReportUpper() == null) {
-                                    continue;
-                                }
-                                if (!isNumber(scadaReport.getReportLower())
-                                        || !isNumber(scadaReport.getReportUpper())
-                                        || !isNumber(scadaBelong.getValue())) {
-                                    continue;
+            try {
+                //查询绑定的指标
+                if (!CollectionUtils.isEmpty(allocations)) {
+                    //获取符合设备绑定的指标
+                    List<AllocationVo> allocationVos = new HashSet<>(allocations).stream().filter(allocation -> allocation.getDeviceId() != null &&
+                            allocation.getDeviceId().equals(vo.getId())).map(allocation -> {
+                        AllocationVo allocationVo = new AllocationVo();
+                        BeanUtils.copyProperties(allocation, allocationVo);
+                        Scada scadaBelong = null;
+                        //查询scada数据
+
+                        if (!CollectionUtils.isEmpty(scadas)) {
+                            List<Scada> scadaList = scadas.stream()
+                                    .filter(scada -> scada.getCode() != null && scada.getCode().equals(allocation.getVariableCode()))
+                                    .collect(Collectors.toList());
+                            if (!CollectionUtils.isEmpty(scadaList)) {
+                                scadaBelong = scadaList.get(0);
+                                Long accuracy = allocation.getAccuracy();
+                                //根据设置的精度保留小数位数
+                                if (accuracy == null) {
+                                    accuracy = 2L;
                                 }
-                                Double lower = Double.parseDouble(scadaReport.getReportLower());
-                                Double upper = Double.parseDouble(scadaReport.getReportUpper());
-                                Double value = Double.parseDouble(scadaBelong.getValue());
-
-                                if (value.compareTo(upper) <= 0 && value.compareTo(lower) >= 0) {
-                                    allocationVo.setIsAlarm("1");
-                                    vo.setIsAlarm("1");
-                                    reportsList.add(scadaReport);
-                                    // break;
+                                //科学技术法处理,不要e哦
+                                BigDecimal bd = new BigDecimal(scadaBelong.getValue());
+                                double roundedNumber = bd.setScale(Integer.parseInt(accuracy + ""), BigDecimal.ROUND_HALF_UP).doubleValue();
+                                NumberFormat nf = NumberFormat.getInstance();
+                                nf.setGroupingUsed(false);
+
+                                if (accuracy > 0L) {
+                                    scadaBelong.setValue(nf.format(roundedNumber));
+                                } else {
+                                    scadaBelong.setValue(nf.format((int) roundedNumber));
                                 }
 
+                                allocationVo.setScada(scadaBelong);
                             }
                         }
-                        allocationVo.setScadaReports(reportsList);
-                    }
-                    return allocationVo;
-                }).collect(Collectors.toList());
+                        //设置报警相关信息
+                        Set<Long> reportIdSets = getReportIdSets(Collections.singletonList(allocation));
+                        if (!CollectionUtils.isEmpty(scadaReports) && !CollectionUtils.isEmpty(reportIdSets)) {
+                            //筛选出报警信息列表
+                            List<ScadaReport> reportsList = new ArrayList<>();
+                            List<ScadaReport> reports = scadaReports.stream().filter(scadaReport -> scadaReport.getId() != null
+                                    && reportIdSets.contains(scadaReport.getId())).collect(Collectors.toList());
+                            //设置指标报警状态为未报警
+                            allocationVo.setIsAlarm("0");
+                            //判断指标是否报警
+                            if (scadaBelong != null && scadaBelong.getValue() != null) {
+                                for (ScadaReport scadaReport : reports) {
+                                    if (scadaReport.getReportLower() == null || scadaReport.getReportUpper() == null) {
+                                        continue;
+                                    }
+                                    if (!isNumber(scadaReport.getReportLower())
+                                            || !isNumber(scadaReport.getReportUpper())
+                                            || !isNumber(scadaBelong.getValue())) {
+                                        continue;
+                                    }
+                                    Double lower = Double.parseDouble(scadaReport.getReportLower());
+                                    Double upper = Double.parseDouble(scadaReport.getReportUpper());
+                                    Double value = Double.parseDouble(scadaBelong.getValue());
+
+                                    if (value.compareTo(upper) <= 0 && value.compareTo(lower) >= 0) {
+                                        allocationVo.setIsAlarm("1");
+                                        vo.setIsAlarm("1");
+                                        reportsList.add(scadaReport);
+                                        // break;
+                                    }
 
+                                }
+                            }
+                            allocationVo.setScadaReports(reportsList);
+                        }
+                        return allocationVo;
+                    }).collect(Collectors.toList());
 
-                allocationVos = allocationVos.stream().sorted(Comparator.comparing(AllocationVo::getSortNumber)).collect(Collectors.toList());
 
-                vo.setAllocations(allocationVos);
-            }
-            if (org.apache.commons.lang3.StringUtils.isNotBlank(deviceQuery.getDeviceTypeIds())) {
-                List<String> deviceTypeList = Arrays.stream(deviceQuery.getDeviceTypeIds().split(",")).map(String::trim)
-                        .collect(Collectors.toList());
-                for (String s : deviceTypeList) {
-                    if (StringUtil.isNotEmpty(vo.getDeviceType()) && vo.getDeviceType().equals(s)) {
-                        return vo;
+                    allocationVos = allocationVos.stream().sorted(Comparator.comparing(AllocationVo::getSortNumber)).collect(Collectors.toList());
+
+                    vo.setAllocations(allocationVos);
+                }
+                if (org.apache.commons.lang3.StringUtils.isNotBlank(deviceQuery.getDeviceTypeIds())) {
+                    List<String> deviceTypeList = Arrays.stream(deviceQuery.getDeviceTypeIds().split(",")).map(String::trim)
+                            .collect(Collectors.toList());
+                    for (String s : deviceTypeList) {
+                        if (StringUtil.isNotEmpty(vo.getDeviceType()) && vo.getDeviceType().equals(s)) {
+                            return vo;
+                        }
                     }
+                    return null;
                 }
-                return null;
+            }catch (Exception e){
+
             }
             return vo;
         }).filter(Objects::nonNull).collect(Collectors.toList());
+
         return manageVos;
     }
 

+ 5 - 25
lysw-scada/src/main/java/com/tofly/spire/controller/SpireBigGridController.java

@@ -154,36 +154,16 @@ public class SpireBigGridController extends BaseController {
     }
 
 
-    /**
-     * 同步管网数据
-     *
-     * @param date  日期 yyyy-mm-dd
-     * @param clean 是否清空原始旧数据
-     * @param sn    设备sn
-     * @return 同步成功条数
-     */
-    @ApiOperation(value = "同步管网数据")
-    @ApiImplicitParams(value = {
-            @ApiImplicitParam(name = "date", value = "日期 yyyy-mm-dd"),
-            @ApiImplicitParam(name = "clean", value = "是否清空原始旧数据"),
-            @ApiImplicitParam(name = "sn", value = "设备号"),
-    })
-    @GetMapping("/async")
-    public ResultRespone getBulkMeterData(@RequestParam(required = false) String date,
-                                          @RequestParam(required = false) Boolean clean,
-                                          @RequestParam(required = false) String sn) {
-        return ResultRespone.success(spireBigGridService.getBulkMeterData(date, clean, sn));
-    }
 
-    @ApiOperation(value = "同步管网数据New")
+    @ApiOperation(value = "同步管网数据,多线程")
     @ApiImplicitParams(value = {
             @ApiImplicitParam(name = "date", value = "日期 yyyy-mm-dd"),
-           @ApiImplicitParam(name = "sn", value = "设备号"),
+            @ApiImplicitParam(name = "sn", value = "设备号,多个逗号"),
     })
     @GetMapping("/asyncBulkMeterData")
     public ResultRespone getBulkMeterDataNew(@RequestParam(required = false) String date,
-                                       @RequestParam(required = false) String sn) {
-        spireBigGridService.getBulkMeterDataNew(date, sn);
+                                             @RequestParam(required = false) String sn) {
+        spireBigGridService.synBulkMeterThread(date, sn);
         return ResultRespone.success(true);
     }
     /**
@@ -191,7 +171,7 @@ public class SpireBigGridController extends BaseController {
      *
      */
     @ApiOperation(value = "手动分发管网数据到历史表,指标表等")
-   @GetMapping("/asyncData")
+    @GetMapping("/asyncData")
     public ResultRespone synData() {
         return ResultRespone.success(spireBigGridService.synData());
     }

+ 81 - 0
lysw-scada/src/main/java/com/tofly/spire/handle/SpireHandle.java

@@ -0,0 +1,81 @@
+package com.tofly.spire.handle;
+
+import cn.hutool.core.date.DateUtil;
+import com.tofly.spire.service.SpireBigGridService;
+import com.xxl.job.core.biz.model.ReturnT;
+import com.xxl.job.core.handler.annotation.XxlJob;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.Calendar;
+import java.util.Date;
+
+/**
+ * @author HaiQiu
+ * @since 2023/3/24
+ */
+@Component
+public class SpireHandle {
+
+    @Autowired
+    private SpireBigGridService spireBigGridService;
+
+
+    /**
+     * 定时任务--同步管网数据分发到其它表里面,5分钟1
+     * @param params
+     * @return
+     */
+    @XxlJob("getBulkMSynData")
+    public ReturnT getBulkMSynData(String params) {
+        spireBigGridService.synData();
+        return ReturnT.SUCCESS;
+    }
+
+    /**
+     * 同步管网数据,昨天的
+     *
+     * @param params
+     * @return
+     */
+    @XxlJob("getBulkMeterDataLastDay")
+//    @Scheduled(cron = "0 0/1 * * * ?")
+    public ReturnT getBulkMeterDataLastDay(String params) {
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(new Date());
+        calendar.add(Calendar.DAY_OF_MONTH, -1);
+        String format = DateUtil.format(calendar.getTime(), "yyyy-MM-dd");
+        spireBigGridService.synBulkMeterThread(format, null);
+        return ReturnT.SUCCESS;
+    }
+
+    /**
+     * 同步管网数据,今天的
+     *
+     * @param params
+     * @return
+     */
+    @XxlJob("getBulkMeterData")
+//    @Scheduled(cron = "0 0/1 * * * ?")
+    public ReturnT getBulkMeterData(String params) {
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(new Date());
+        String format = DateUtil.format(calendar.getTime(), "yyyy-MM-dd");
+        spireBigGridService.synBulkMeterThread(format, null);
+        return ReturnT.SUCCESS;
+    }
+
+
+    /**
+     * 定时任务--同步管网基础数据,并且转换成高德地图坐标同步到设备表
+     * @param params
+     * @return
+     */
+    @XxlJob("getBulkMeterBigBaseData")
+    public ReturnT synBulkMeterBigBaseData(String params) {
+        spireBigGridService.getBulkMeterBigBaseData();
+        spireBigGridService.getMapGdDataNew();
+        spireBigGridService.synDeviceArchiveManage();
+        return ReturnT.SUCCESS;
+    }
+}

+ 10 - 8
lysw-scada/src/main/java/com/tofly/spire/service/SpireBigGridService.java

@@ -86,22 +86,22 @@ public interface SpireBigGridService extends IService<SpireBigGrid> {
     List<SpireBigGrid> allList(SpireBigGrid spireBigGrid);
 
 
-    /**
+    /* *//**
      * 同步管网数据
      * @param date 日期 yyyy-mm-dd
      * @param clean 是否清空原始旧数据
      * @param sn 设备sn
      * @return 同步成功条数
-     */
-    long getBulkMeterData(String date, Boolean clean, String sn);
+     *//*
+    long getBulkMeterData(String date, Boolean clean, String sn);*/
 
     /**
      * 同步管网数据
      * @param date 日期 yyyy-mm-dd
-    * @param sn 设备sn
+     * @param sn 设备sn
      * @return 同步成功条数
-     */
-    void getBulkMeterDataNew(String date, String sn);
+     *//*
+    void getBulkMeterDataNew(String date, String sn);*/
 
     /**
      * 同步大表管网实时基础数据
@@ -109,13 +109,15 @@ public interface SpireBigGridService extends IService<SpireBigGrid> {
     void  getBulkMeterBigBaseData();
 
 
-   void  getMapGdDataNew();
+    void  getMapGdDataNew();
 
-   void  synDeviceArchiveManage();
+    void  synDeviceArchiveManage();
     /**
      * 分发管网数据到历史表,指标表等
      * @return
      */
     long synData();
+
+    void synBulkMeterThread(String date, String sn);
 }
 

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 451 - 442
lysw-scada/src/main/java/com/tofly/spire/service/impl/SpireBigGridServiceImpl.java


+ 1 - 1
lysw-scada/src/main/resources/bootstrap-test.yml

@@ -25,7 +25,7 @@ spring:
         server-addr: 192.168.2.17:8848
   application:
     # 该应用在nacos配置中的名称
-    name: tofly-scada
+    name: tofly-scada-test
 
 logging:
   level:

+ 1 - 1
lysw-scada/src/main/resources/bootstrap.yml

@@ -1,3 +1,3 @@
 spring:
   profiles:
-    active: gs
+    active: test