Bläddra i källkod

运行记录填报

yuanchao 2 månader sedan
förälder
incheckning
757bab923e

+ 87 - 50
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotopeationfill/IotOpeationFillController.java

@@ -13,6 +13,7 @@ import cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.iotmodel.IotModelDO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.iotmodeltemplateattrs.IotModelTemplateAttrsDO;
+import cn.iocoder.yudao.module.pms.dal.dataobject.iotmodeltemplateattrs.IotModelTemplateAttrsDO1;
 import cn.iocoder.yudao.module.pms.dal.dataobject.iotmodeltemplateattrs.IotThingsModelDO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillOrderDO;
@@ -83,14 +84,41 @@ public class IotOpeationFillController {
     @Operation(summary = "创建运行记录填写信息")
     public CommonResult<Integer> insertLog(@Valid @RequestBody List<IotOpeationFillSaveReqVO>createReqVO) {
         List<IotOpeationFillSaveReqVO> fillList = createReqVO;
+
+        String fillContent = null;
+        for (IotOpeationFillSaveReqVO dayilyRun:fillList) {
+            if(dayilyRun.getPointName().equals("当日运转时间")){
+                fillContent = dayilyRun.getFillContent();
+                break;
+            }
+        }
+        for (IotOpeationFillSaveReqVO totalRun:fillList) {
+            if(totalRun.getPointName().equals("累计运转时间")||totalRun.getPointName().equals("累计运行时间")){
+                double total = Double.parseDouble(fillContent);
+                totalRun.setTotalRunTime(BigDecimal.valueOf(total).add(totalRun.getTotalRunTime()));
+                break;
+            }
+        }
+        fillContent = null;
+        for (IotOpeationFillSaveReqVO dayilyGas:fillList) {
+            if(dayilyGas.getPointName().equals("当日注气量")){
+                fillContent = dayilyGas.getFillContent();
+                break;
+            }
+        }
+        for (IotOpeationFillSaveReqVO totalGas:fillList) {
+            if(totalGas.getPointName().equals("累计注气量")){
+                double total = Double.parseDouble(fillContent);
+                totalGas.setTotalRunTime(BigDecimal.valueOf(total).add(totalGas.getTotalRunTime()));
+                break;
+            }
+        }
+
         List< IotDeviceRunLogDO > logDO = new ArrayList<>();
 
         for (IotOpeationFillSaveReqVO fill:fillList) {
-            IotDeviceRunLogDO logDO1 = new IotDeviceRunLogDO();
-            logDO1.setDeviceId(fill.getDeviceId());
+
             LocalTime localTime = LocalTime.of(0,0);
-            logDO1.setCreateTime(LocalDateTime.of(fill.getCreateTime(),localTime));
-            List<IotDeviceRunLogDO> logList = iotOpeationFillService.getDeivceFillInfo(logDO1);
 
             IotDeviceRunLogDO deviceRunLogDO = new IotDeviceRunLogDO();
 
@@ -101,23 +129,7 @@ public class IotOpeationFillController {
             deviceRunLogDO.setDeptId(fill.getDeptId());
             deviceRunLogDO.setCreateTime(LocalDateTime.of(fill.getCreateTime(),localTime));
             deviceRunLogDO.setPointName(fill.getPointName());
-            if(logList.size()>0){
-                if(createReqVO.get(0).getIsCollection()==1){
-                    deviceRunLogDO.setTotalRunTime(createReqVO.get(0).getTotalRunTime());
-                }else{
-                    BigDecimal num1 = logList.get(0).getTotalRunTime();
-                    BigDecimal num2 = new BigDecimal(fill.getFillContent());
-                    deviceRunLogDO.setTotalRunTime(num1.add(num2));
-                }
-            }else{
-                if(createReqVO.get(0).getIsCollection()==1){
-                    deviceRunLogDO.setTotalRunTime(createReqVO.get(0).getTotalRunTime());
-                }else{
-                    BigDecimal num2 = new BigDecimal(fill.getFillContent());
-                    deviceRunLogDO.setTotalRunTime(num2);
-                }
-
-            }
+            deviceRunLogDO.setTotalRunTime(fill.getTotalRunTime());
 
             logDO.add(deviceRunLogDO);
         }
@@ -132,6 +144,7 @@ public class IotOpeationFillController {
         IotOpeationFillRespVO respVO = new IotOpeationFillRespVO();
         respVO.setUserId(createReqVO.get(0).getUserId());
         respVO.setCreateTime(createReqVO.get(0).getCreateTime());
+        respVO.setOrderId(createReqVO.get(0).getId());
         List<IotOpeationFillRespVO> fillList1 = iotOpeationFillService.getFillList(respVO);
 
         boolean result = fillList1.stream().allMatch(e->e.getIsFill()==1);
@@ -244,7 +257,7 @@ public class IotOpeationFillController {
     @PermitAll
     @Operation(summary = "获得PMS 功能优化 设备模板属性")
     @Parameter(name = "deviceCategoryName", description = "名称", required = true, example = "1024")
-    public CommonResult<List<IotModelTemplateAttrsDO>> getModelAttrs(@Valid IotModelTemplateAttrsRespVO vo) throws SQLException{
+    public CommonResult<List<IotModelTemplateAttrsDO1>> getModelAttrs(@Valid IotModelTemplateAttrsRespVO vo) throws SQLException{
 
         List<IotModelTemplateAttrsDO> list = iotOpeationFillService.getAttrsById(vo );
 
@@ -272,9 +285,6 @@ public class IotOpeationFillController {
         LocalTime local = LocalTime.of(12, 0);
         logDO1.setCreateTime(LocalDateTime.of(vo.getCreateTime(),local));
 
-        List<IotDeviceRunLogDO> logList = iotOpeationFillService.getDeivceFillInfo(logDO1);
-        List<IotDeviceRunLogDO> maxLog = iotOpeationFillService.getMaxFillInfo(logDO1);
-
         if(exists){
             for (IotModelTemplateAttrsDO attrsDO:list) {
 
@@ -295,20 +305,31 @@ public class IotOpeationFillController {
                      */
                     attrsDO.setIsCollection(1);
                 }else{
-                    if(logList.size()>0){
-                        for (IotDeviceRunLogDO log:logList) {
-                            if(log.getPointName().equals(attrsDO.getName())){
-                                attrsDO.setFillContent(log.getFillContent());
-                                attrsDO.setTotalRunTime(log.getTotalRunTime());
-                                /**
-                                 * 设置为非数采
-                                 */
-                                attrsDO.setIsCollection(0);
-                            }
+                    logDO1.setPointName(attrsDO.getName());
+                    IotDeviceRunLogDO logInfo = iotOpeationFillService.getLogInfo(logDO1);
+                    IotDeviceRunLogDO maxLog = iotOpeationFillService.getMaxFillInfo(logDO1);
+                    if(!StringUtils.isEmpty(logInfo)){
+
+                        attrsDO.setFillContent(logInfo.getFillContent());
+
+                        if(StringUtils.isEmpty(maxLog)){
+                            attrsDO.setTotalRunTime(BigDecimal.valueOf(0));
+                        }else{
+                            attrsDO.setTotalRunTime(maxLog.getTotalRunTime());
                         }
+                        /**
+                         * 设置为非数采
+                         */
+                        attrsDO.setIsCollection(0);
+
+
                     }else{
                         attrsDO.setFillContent("0.0");
-                        attrsDO.setTotalRunTime(maxLog.get(0).getTotalRunTime());
+                        if(StringUtils.isEmpty(maxLog)){
+                            attrsDO.setTotalRunTime(BigDecimal.valueOf(0));
+                        }else{
+                            attrsDO.setTotalRunTime(maxLog.getTotalRunTime());
+                        }
                         /**
                          * 设置为非数采
                          */
@@ -319,23 +340,28 @@ public class IotOpeationFillController {
         }else{
 
             for (IotModelTemplateAttrsDO attrsDO:list) {
-                if(logList.size()>0){
-
-                    for (IotDeviceRunLogDO log:logList) {
-                        if(log.getPointName().equals(attrsDO.getName())){
-                            attrsDO.setFillContent(log.getFillContent());
-                            attrsDO.setTotalRunTime(log.getTotalRunTime());
-                            /**
-                             * 设置为非数采
-                             */
-                            attrsDO.setIsCollection(0);
-                        }
+                logDO1.setPointName(attrsDO.getName());
+                IotDeviceRunLogDO logInfo = iotOpeationFillService.getLogInfo(logDO1);
+                IotDeviceRunLogDO maxLog = iotOpeationFillService.getMaxFillInfo(logDO1);
+                if(!StringUtils.isEmpty(logInfo)){
+
+                    attrsDO.setFillContent(logInfo.getFillContent());
+                    attrsDO.setTotalRunTime(maxLog.getTotalRunTime());
+
+                    /**
+                     * 设置为非数采
+                     */
+                    attrsDO.setIsCollection(0);
 
-                    }
 
                 }else{
                     attrsDO.setFillContent("0.0");
-                    attrsDO.setTotalRunTime(maxLog.get(0).getTotalRunTime());
+                    if(StringUtils.isEmpty(maxLog)){
+                        attrsDO.setTotalRunTime(BigDecimal.valueOf(0));
+                    }else{
+                        attrsDO.setTotalRunTime(maxLog.getTotalRunTime());
+                    }
+
                     /**
                      * 设置为非数采
                      */
@@ -348,7 +374,18 @@ public class IotOpeationFillController {
         }
 
 
-        return success(BeanUtils.toBean(list,IotModelTemplateAttrsDO.class));
+        List<IotModelTemplateAttrsDO1> resut = new ArrayList<>();
+
+        List<IotModelTemplateAttrsDO> sumList = list.stream().filter(e->e.getIsSum()==1).collect(Collectors.toList());
+        List<IotModelTemplateAttrsDO> nonSumList = list.stream().filter(e->e.getIsSum()==0).collect(Collectors.toList());
+
+        IotModelTemplateAttrsDO1 sum = new IotModelTemplateAttrsDO1();
+        sum.setSumList(sumList);
+        sum.setNonSumList(nonSumList);
+
+        resut.add(sum);
+
+        return success(BeanUtils.toBean(resut,IotModelTemplateAttrsDO1.class));
     }
 
     @GetMapping("/getDeivceFillInfo")

+ 3 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/dataobject/iotmodeltemplateattrs/IotModelTemplateAttrsDO.java

@@ -11,6 +11,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.*;
 
 import java.math.BigDecimal;
+import java.util.List;
 
 /**
  * PMS 功能优化 运行记录模板属性 DO
@@ -108,4 +109,6 @@ public class IotModelTemplateAttrsDO extends BaseDO {
     private BigDecimal totalRunTime;
 
 
+
+
 }

+ 40 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/dataobject/iotmodeltemplateattrs/IotModelTemplateAttrsDO1.java

@@ -0,0 +1,40 @@
+package cn.iocoder.yudao.module.pms.dal.dataobject.iotmodeltemplateattrs;
+
+import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
+import cn.iocoder.yudao.module.pms.controller.admin.iotdevicetemplate.model.DeviceTemplateAttrs;
+import com.baomidou.mybatisplus.annotation.KeySequence;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
+import lombok.*;
+
+import java.math.BigDecimal;
+import java.util.List;
+
+/**
+ * PMS 功能优化 运行记录模板属性 DO
+ *
+ * @author 芋道源码
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@ToString(callSuper = true)
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class IotModelTemplateAttrsDO1 extends BaseDO {
+
+    /**
+     * 累计集合
+     */
+    List<IotModelTemplateAttrsDO> sumList;
+
+    /**
+     * 非累计集合
+     */
+    List<IotModelTemplateAttrsDO> nonSumList;
+
+
+
+}

+ 5 - 3
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/iotopeationfill/IotOpeationFillMapper.java

@@ -80,11 +80,13 @@ public interface IotOpeationFillMapper extends BaseMapperX<IotOpeationFillDO> {
     int insertLog(List<IotDeviceRunLogDO> logDO);
     @TenantIgnore
     int updateFill(IotOpeationFillSaveReqVO vo);
-
+    @TenantIgnore
     List<IotOpeationFillRespVO> getFillList(IotOpeationFillRespVO vo);
-
+    @TenantIgnore
     List<IotDeviceRunLogDO> getDeivceFillInfo(IotDeviceRunLogDO vo);
-    List<IotDeviceRunLogDO> getMaxFillInfo(IotDeviceRunLogDO vo);
+    @TenantIgnore
+    IotDeviceRunLogDO getLogInfo(IotDeviceRunLogDO vo);
+    IotDeviceRunLogDO getMaxFillInfo(IotDeviceRunLogDO vo);
 
     @TenantIgnore
     int updateFillOrder(IotDeviceRunLogDO vo);

+ 3 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotopeationfill/IotOpeationFillService.java

@@ -93,7 +93,9 @@ public interface IotOpeationFillService {
 
     List<IotDeviceRunLogDO> getDeivceFillInfo(IotDeviceRunLogDO vo);
 
-    List<IotDeviceRunLogDO> getMaxFillInfo(IotDeviceRunLogDO vo);
+    IotDeviceRunLogDO getLogInfo(IotDeviceRunLogDO vo);
+
+    IotDeviceRunLogDO getMaxFillInfo(IotDeviceRunLogDO vo);
 
     /**
      * 更新工单状态

+ 6 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotopeationfill/IotOpeationFillServiceImpl.java

@@ -166,7 +166,12 @@ public class IotOpeationFillServiceImpl implements IotOpeationFillService {
     }
 
     @Override
-    public List<IotDeviceRunLogDO> getMaxFillInfo(IotDeviceRunLogDO vo) {
+    public IotDeviceRunLogDO getLogInfo(IotDeviceRunLogDO vo) {
+        return iotOpeationFillMapper.getLogInfo(vo);
+    }
+
+    @Override
+    public IotDeviceRunLogDO getMaxFillInfo(IotDeviceRunLogDO vo) {
         return iotOpeationFillMapper.getMaxFillInfo(vo);
     }
 

+ 28 - 2
yudao-module-pms/yudao-module-pms-biz/src/main/resources/mapper/static/IotOpeationFillMapper.xml

@@ -307,7 +307,7 @@
         limit 1
     </select>
 
-    <select id="getMaxFillInfo" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO"
+    <select id="getLogInfo" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO"
             resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
         <!--SELECT * FROM rq_iot_device_run_log
         WHERE
@@ -315,9 +315,35 @@
         and
             create_time  = (SELECT MAX(create_time) FROM rq_iot_device_run_log WHERE
                 device_id = #{deviceId})-->
+        SELECT
+        *
+        FROM rq_iot_device_run_log
+        WHERE
+        device_id = #{deviceId}
+        and
+        point_name = #{pointName}
+        and
+        DATE(create_time)  = DATE(#{createTime})
+        order by id
+        desc
+        limit 1
+    </select>
 
-        select max(total_run_time)total_run_time from rq_iot_device_run_log  where  device_id = #{deviceId}
+    <select id="getMaxFillInfo" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO"
+            resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
+        <!--SELECT * FROM rq_iot_device_run_log
+        WHERE
+            device_id = #{deviceId}
+        and
+            create_time  = (SELECT MAX(create_time) FROM rq_iot_device_run_log WHERE
+                device_id = #{deviceId})-->
 
+        select max(total_run_time)total_run_time
+        from rq_iot_device_run_log
+        where
+        device_id = #{deviceId}
+        and
+        point_name=#{pointName}
     </select>
 
     <update id="updateFillOrder" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">