lipenghui 1 month ago
parent
commit
4ddb3048b9

+ 18 - 0
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/number/NumberUtils.java

@@ -94,4 +94,22 @@ public class NumberUtils {
         return numberStr.isEmpty() ? 0 : Long.parseLong(numberStr);
     }
 
+
+    public static String formatNumber(String numberStr) {
+        // 检查字符串是否包含小数点
+        if (numberStr.contains(".")) {
+            // 包含小数点,转换为double后保留一位小数
+            try {
+                double number = Double.parseDouble(numberStr);
+                // 使用String.format保留一位小数
+                return String.format("%.1f", number);
+            } catch (NumberFormatException e) {
+                // 如果转换失败,返回原字符串
+                return numberStr;
+            }
+        } else {
+            // 不包含小数点,直接返回原字符串
+            return numberStr;
+        }
+    }
 }

+ 51 - 21
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/stat/IotStaticController.java

@@ -8,6 +8,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.framework.common.pojo.Pms;
 import cn.iocoder.yudao.framework.common.util.date.DateUtils;
+import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
 import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
 import cn.iocoder.yudao.module.pms.controller.admin.failure.vo.IotFailureReportPageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.inspect.order.vo.IotInspectOrderPageReqVO;
@@ -18,6 +19,7 @@ import cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeati
 import cn.iocoder.yudao.module.pms.controller.admin.iotoutbound.vo.IotOutboundPageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.maintain.vo.IotMaintainPageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.stat.vo.OrderVo;
+import cn.iocoder.yudao.module.pms.controller.admin.stat.vo.YearTotalGas;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.DeviceVO;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDevicePageReqVO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO;
@@ -732,10 +734,12 @@ public class IotStaticController {
                                 if (totalObj instanceof Number) {
                                     return ((Number) totalObj).longValue();
                                 } else if (totalObj instanceof String) {
-                                    return Long.parseLong((String) totalObj);
+                                    String value = String.valueOf(totalObj).replace(".00","");
+                                    return Long.parseLong(value);
                                 } else {
-                                    System.err.println("total字段格式错误: " + totalObj);
-                                    return 0L;
+//                                    System.err.println("total字段格式错误: " + totalObj);
+                                    String value = String.valueOf(totalObj).replaceAll(".00","");
+                                    return Long.parseLong(value);
                                 }
                             } catch (Exception e) {
                                 System.err.println("处理total字段出错: " + e.getMessage());
@@ -916,26 +920,26 @@ public class IotStaticController {
             fillData.add(v);
         });
 
-        iotDeviceRunLogPageReqVO.setPointName("当日注水量");
-        List<Map<String, Object>> waters = iotDeviceRunLogMapper.selectListByCreateTimeAndDeptList(iotDeviceRunLogPageReqVO).stream().map(e -> {
-            Map<String, Object> abc = new HashMap<>();
-            abc.put("id", e.getId());
-            abc.put("createTime", e.getCreateTime());
-            abc.put("total", e.getTotalRunTime());
-            abc.put("today", e.getFillContent());
-            return abc;
-        }).collect(Collectors.toList());
-        LinkedHashMap<String, Long> waterMap = sumTotalByDate(waters, 7,"today");
-        LinkedList<Object> waterxAxis = new LinkedList<>();
-        LinkedList<Object> waterData = new LinkedList<>();
-        waterMap.forEach( (k,v)->{
-            waterxAxis.add(k);
-            waterData.add(v);
-        });
+//        iotDeviceRunLogPageReqVO.setPointName("当日注水量");
+//        List<Map<String, Object>> waters = iotDeviceRunLogMapper.selectListByCreateTimeAndDeptList(iotDeviceRunLogPageReqVO).stream().map(e -> {
+//            Map<String, Object> abc = new HashMap<>();
+//            abc.put("id", e.getId());
+//            abc.put("createTime", e.getCreateTime());
+//            abc.put("total", e.getTotalRunTime());
+//            abc.put("today", e.getFillContent());
+//            return abc;
+//        }).collect(Collectors.toList());
+//        LinkedHashMap<String, Long> waterMap = sumTotalByDate(waters, 7,"today");
+//        LinkedList<Object> waterxAxis = new LinkedList<>();
+//        LinkedList<Object> waterData = new LinkedList<>();
+//        waterMap.forEach( (k,v)->{
+//            waterxAxis.add(k);
+//            waterData.add(v);
+//        });
 
         ImmutableMap<String, Serializable> fillResult = ImmutableMap.of("name", "当日注气量~~en**daily gas injection", "data", fillData);
-        ImmutableMap<String, Serializable> waterResult = ImmutableMap.of("name", "当日注水量~~en**daily water injection", "data", waterData);
-        return success(ImmutableMap.of("xAxis", xAxis, "series", ImmutableList.of(fillResult, waterResult)));
+//        ImmutableMap<String, Serializable> waterResult = ImmutableMap.of("name", "当日注水量~~en**daily water injection", "data", waterData);
+        return success(ImmutableMap.of("xAxis", xAxis, "series", ImmutableList.of(fillResult)));
 
     }
 
@@ -989,5 +993,31 @@ public class IotStaticController {
             return success(formattedResult);
         }
     }
+
+
+    @PermitAll
+    @GetMapping("/year/total/gas/{dept}")
+    public CommonResult<ImmutableMap> getYearTotalGas(@PathVariable("dept") String dept) {
+        Set<Long> ids = getDeptIds(dept);
+        //获取近一年的月份
+        List<String> lastYearMonthRanges = getLastYearMonthRanges().stream().map(MonthRange::getYearMonth).collect(Collectors.toList());
+        IotDeviceRunLogPageReqVO iotDeviceRunLogPageReqVO = new IotDeviceRunLogPageReqVO();
+        iotDeviceRunLogPageReqVO.setDeptIds(new ArrayList<>(ids));
+        iotDeviceRunLogPageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
+        iotDeviceRunLogPageReqVO.setPointName("当日注气量");
+        List<YearTotalGas> yearTotalGases = iotDeviceRunLogMapper.selectYearTotalGas(iotDeviceRunLogPageReqVO);
+        LinkedList<String> result = new LinkedList<>();
+        lastYearMonthRanges.forEach(lastYearMonthRange -> {
+            YearTotalGas yearTotalGas = yearTotalGases.stream().filter(e -> e.getMonth().equals(lastYearMonthRange)).findAny().orElse(null);
+            if (Objects.isNull(yearTotalGas)) {
+                result.add("0");
+            } else {
+                result.add(NumberUtils.formatNumber(yearTotalGas.getTotalGas()));
+            }
+        });
+        ImmutableMap<String, Serializable> fillResult = ImmutableMap.of("name", "累计注气量~~en**cumulative gas injection", "data", result);
+        return success(ImmutableMap.of("xAxis", lastYearMonthRanges, "series", ImmutableList.of(fillResult)));
+
+    }
 }
 

+ 9 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/stat/vo/YearTotalGas.java

@@ -0,0 +1,9 @@
+package cn.iocoder.yudao.module.pms.controller.admin.stat.vo;
+
+import lombok.Data;
+
+@Data
+public class YearTotalGas {
+    private String month;
+    private String totalGas;
+}

+ 4 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/iotdevicerunlog/IotDeviceRunLogMapper.java

@@ -7,6 +7,8 @@ import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
 import cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogPageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogRespVO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO;
+import cn.iocoder.yudao.module.pms.controller.admin.stat.IotStaticController;
+import cn.iocoder.yudao.module.pms.controller.admin.stat.vo.YearTotalGas;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
@@ -68,4 +70,6 @@ public interface IotDeviceRunLogMapper extends BaseMapperX<IotDeviceRunLogDO> {
 
     @TenantIgnore
     List<IotDeviceRunLogRespVO> selectListByCreateTimeAndDeptList(IotDeviceRunLogPageReqVO reqVO);
+    @TenantIgnore
+    List<YearTotalGas> selectYearTotalGas(IotDeviceRunLogPageReqVO reqVO);
 }

+ 1 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/failure/IotFailureReportServiceImpl.java

@@ -140,7 +140,7 @@ public class IotFailureReportServiceImpl implements IotFailureReportService {
         for (String s : iotFailureReportDO.getApprovalId().split(",")) {
             approvalIds.add(Long.parseLong(s));
         }
-        assigness.put(PROCESS_KEY, approvalIds);
+        assigness.put("failure_approval", approvalIds);
         String processInstanceId = processInstanceApi.createProcessInstance(SecurityFrameworkUtils.getLoginUserId(),
                 new BpmProcessInstanceCreateReqDTO().setProcessDefinitionKey(PROCESS_KEY).setBusinessKey(String.valueOf(id)).setStartUserSelectAssignees(assigness));
         // 将流程实例id 更新到 供应商主数据表

+ 22 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/resources/mapper/static/IotDeviceRunLogMapper.xml

@@ -65,6 +65,28 @@
         </if>
     </select>
 
+    <select id="selectYearTotalGas" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogPageReqVO"
+            resultType="cn.iocoder.yudao.module.pms.controller.admin.stat.vo.YearTotalGas">
+        SELECT
+            DATE_FORMAT(create_time, '%Y-%m') AS month,
+    SUM(IFNULL(fill_content, 0)) AS total_gas
+        FROM
+            rq_iot_device_run_log a
+        WHERE
+            a.create_time >= DATE_SUB(NOW(), INTERVAL 1 YEAR)
+          AND a.fill_content IS NOT NULL
+          and a.point_name = #{pointName}
+        <if test="deptIds != null and deptIds.size &gt; 0">
+            AND a.dept_id IN
+            <foreach collection="deptIds" index="index" item="key" open="(" separator="," close=")">
+                #{key}
+            </foreach>
+        </if>
+        GROUP BY
+            month
+        ORDER BY
+            month ASC;
+    </select>
 
     <!-- 查询指定设备 指定运行模板属性的累计时长 累计公里数 -->
     <select id="multipleAccumulatedData"