Forráskód Böngészése

运行记录填报

yuanchao 3 hónapja
szülő
commit
9d5c523462

+ 14 - 0
yudao-module-pms/yudao-module-pms-biz/pom.xml

@@ -93,6 +93,20 @@
             <artifactId>druid-spring-boot-starter</artifactId>
             <version>1.2.6</version>
         </dependency>
+        <dependency>
+            <groupId>cn.iocoder.boot</groupId>
+            <artifactId>yudao-spring-boot-starter-biz-data-permission</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>cn.iocoder.boot</groupId>
+            <artifactId>yudao-spring-boot-starter-biz-data-permission</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>cn.iocoder.boot</groupId>
+            <artifactId>yudao-module-supplier-biz</artifactId>
+            <version>2.4.2-jdk8-SNAPSHOT</version>
+            <scope>compile</scope>
+        </dependency>
     </dependencies>
 
 </project>

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

@@ -36,6 +36,7 @@ import javax.validation.*;
 import javax.servlet.http.*;
 import java.math.BigDecimal;
 import java.sql.SQLException;
+import java.sql.Timestamp;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.LocalTime;
@@ -84,6 +85,8 @@ public class IotOpeationFillController {
         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();
@@ -93,7 +96,7 @@ public class IotOpeationFillController {
             deviceRunLogDO.setFillContent(fill.getFillContent());
             deviceRunLogDO.setPointCode(fill.getModelAttr());
             deviceRunLogDO.setDeptId(fill.getDeptId());
-            deviceRunLogDO.setCreateTime(LocalDateTime.now());
+            deviceRunLogDO.setCreateTime(LocalDateTime.of(fill.getCreateTime(),localTime));
             deviceRunLogDO.setPointName(fill.getPointName());
             if(logList.size()>0){
                 BigDecimal num1 = logList.get(0).getTotalRunTime();
@@ -120,14 +123,14 @@ public class IotOpeationFillController {
         List<IotOpeationFillRespVO> fillList1 = iotOpeationFillService.getFillList(respVO);
 
         boolean result = fillList1.stream().allMatch(e->e.getIsFill()==1);
-        boolean result1 = fillList1.stream().allMatch(e->e.getIsFill()==0);
 
-        if(result){
-
-        }else if(result1){
+        IotDeviceRunLogDO deviceRunLogDO = new IotDeviceRunLogDO();
+        deviceRunLogDO.setId(createReqVO.get(0).getId());
 
+        if(result){
+            iotOpeationFillService.updateFillOrder(deviceRunLogDO);
         }else{
-
+            iotOpeationFillService.updateFillOrder1(deviceRunLogDO);
         }
 
         return success(iotOpeationFillService.insertLog(logDO));
@@ -198,49 +201,90 @@ public class IotOpeationFillController {
     @Operation(summary = "获得PMS 功能优化 设备模板属性")
     @Parameter(name = "deviceCategoryName", description = "名称", required = true, example = "1024")
     public CommonResult<List<IotModelTemplateAttrsDO>> getModelAttrs(@Valid IotModelTemplateAttrsRespVO vo) throws SQLException{
+
         List<IotModelTemplateAttrsDO> list = iotOpeationFillService.getAttrsById(vo );
 
-        /**
-         * 根据设备名称和物属性名称查询时序数据库
-         * 1、数采有值,已填写
-         * 2、数采有值,未填写 满足
-         * 3、数采无值,已填写 满足
-         * 4、数采无值,未填写 满足
-         */
+
         List<YfDeviceDO> allDevice = yfDeviceService.getAllDevice();
 
+
+
+        LocalTime localTime = LocalTime.of(0,0,0);
+        LocalTime localTime1 = LocalTime.of(23,59,59);
+
+        LocalDateTime start = LocalDateTime.of(vo.getCreateTime(),localTime);
+        LocalDateTime end = LocalDateTime.of(vo.getCreateTime(),localTime1);
+
+        Timestamp startTime = Timestamp.valueOf(start);
+        Timestamp endTime = Timestamp.valueOf(end);
+
+
         boolean exists = allDevice.stream()
                 .anyMatch(yfDeviceDO -> yfDeviceDO.getSerialNumber().equals(vo.getDeviceCode()));
 
+
+        IotDeviceRunLogDO logDO1 = new IotDeviceRunLogDO();
+        logDO1.setDeviceId(vo.getDeviceId());
+        LocalTime local = LocalTime.of(12, 0);
+        logDO1.setCreateTime(LocalDateTime.of(vo.getCreateTime(),local));
+        List<IotDeviceRunLogDO> logList = iotOpeationFillService.getDeivceFillInfo(logDO1);
+
+
         if(exists){
             for (IotModelTemplateAttrsDO attrsDO:list) {
                 DeviceVO dv= new DeviceVO();
+
                 dv.setDeviceName(vo.getDeviceCode().toLowerCase());
                 dv.setColName(attrsDO.getModelAttr());
+                dv.setTs(startTime);
+                dv.setTs1(endTime);
+
                 DeviceVO deviceVO = iDeviceService.getYesInfo(dv);
-                if(!StringUtils.isEmpty(deviceVO)){
+
+                if(!StringUtils.isEmpty(deviceVO) && !deviceVO.getEarliestData().equals("0.0")){
                     attrsDO.setFillContent(
                             String.valueOf(Double.parseDouble(deviceVO.getLatestData())-Double.parseDouble(deviceVO.getEarliestData())));
                     attrsDO.setTotalRunTime(BigDecimal.valueOf(Double.parseDouble(deviceVO.getLatestData())));
+                    /**
+                     * 设置为数采
+                     */
+                    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);
+                            }
+
+                        }
+                    }
                 }
             }
-        }
-
-        IotDeviceRunLogDO logDO1 = new IotDeviceRunLogDO();
-        logDO1.setDeviceId(vo.getDeviceId());
-        LocalTime localTime = LocalTime.of(12, 0);
-        logDO1.setCreateTime(LocalDateTime.of(vo.getCreateTime(),localTime));
-        List<IotDeviceRunLogDO> logList = iotOpeationFillService.getDeivceFillInfo(logDO1);
-        if(logList.size()>0){
-            for (IotDeviceRunLogDO log:logList) {
+        }else{
+            if(logList.size()>0){
                 for (IotModelTemplateAttrsDO attrsDO:list) {
-                    if(log.getPointName().equals(attrsDO.getName())){
-                        attrsDO.setFillContent(log.getFillContent());
-                        attrsDO.setTotalRunTime(log.getTotalRunTime());
+                    for (IotDeviceRunLogDO log:logList) {
+                        if(log.getPointName().equals(attrsDO.getName())){
+                            attrsDO.setFillContent(log.getFillContent());
+                            attrsDO.setTotalRunTime(log.getTotalRunTime());
+                            /**
+                             * 设置为非数采
+                             */
+                            attrsDO.setIsCollection(0);
+                        }
+
                     }
-                }
+               }
             }
         }
+
+
+
         return success(BeanUtils.toBean(list,IotModelTemplateAttrsDO.class));
     }
 

+ 6 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/vo/DeviceVO.java

@@ -7,12 +7,16 @@ import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.ToString;
 import org.springframework.data.annotation.Transient;
+import org.springframework.format.annotation.DateTimeFormat;
 
 import java.math.BigDecimal;
 import java.sql.Timestamp;
+import java.time.LocalDate;
 import java.util.Date;
 import java.util.List;
 
+import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY;
+
 /**
  * 设备对象 iot_device
  *
@@ -247,5 +251,7 @@ public class DeviceVO extends PageParam {
 
     private Long timestamp;
     private Double value;
+    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY)
+    private LocalDate createTime;
 
 }

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

@@ -105,4 +105,5 @@ public class IotModelTemplateAttrsDO extends BaseDO {
     private String fillContent;
     private BigDecimal totalRunTime;
 
+
 }

+ 4 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/dataobject/iotopeationfill/IotOpeationFillDO.java

@@ -9,6 +9,9 @@ import java.time.LocalDateTime;
 import java.time.LocalDateTime;
 import com.baomidou.mybatisplus.annotation.*;
 import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY;
 
 /**
  * 运行记录填报 DO
@@ -91,6 +94,7 @@ public class IotOpeationFillDO extends BaseDO {
      */
     private LocalDate creDate;
 
+    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY)
     private LocalDateTime createTime;
 
     private int isFill;

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

@@ -10,6 +10,8 @@ import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 
 import java.sql.Timestamp;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
 import java.util.List;
 
 /**
@@ -71,13 +73,13 @@ public interface TDDeviceMapper extends BaseMapperX<TDDeviceDO> {
             "  LAST(log_value ) AS latest_data\n" +
             "FROM iot_log.device_${deviceName} \n" +
             "WHERE\n" +
-            "  ts >= NOW - 1d\n" +
+            "  ts BETWEEN #{ts}" +
+            "  and #{ts1}"+
             "  and identity = #{colName}\n" +
-            "  AND ts < NOW\n" +
             "  AND _c0 IS NOT NULL")
     @DS("tdengine")
     @TenantIgnore
-    DeviceVO getYesInfo(@Param("deviceName") String tableName,@Param("colName") String colName);
+    DeviceVO getYesInfo(@Param("deviceName") String tableName, @Param("colName") String colName, @Param("ts") Timestamp ts,@Param("ts1")Timestamp ts1);
 
 
     @Select("<script>" +

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

@@ -78,4 +78,7 @@ public interface IotOpeationFillMapper extends BaseMapperX<IotOpeationFillDO> {
     List<IotOpeationFillRespVO> getFillList(IotOpeationFillRespVO vo);
 
     List<IotDeviceRunLogDO> getDeivceFillInfo(IotDeviceRunLogDO vo);
+
+    int updateFillOrder(IotDeviceRunLogDO vo);
+    int updateFillOrder1(IotDeviceRunLogDO vo);
 }

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

@@ -49,7 +49,7 @@ public class DeviceServiceImpl implements IDeviceService {
 
     @Override
     public DeviceVO getYesInfo(DeviceVO deviceVO) {
-        return deviceMapper.getYesInfo(deviceVO.getDeviceName(), deviceVO.getColName());
+        return deviceMapper.getYesInfo(deviceVO.getDeviceName(), deviceVO.getColName(),deviceVO.getTs(),deviceVO.getTs1());
     }
 
 

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

@@ -98,4 +98,13 @@ public interface IotOpeationFillService {
 
     List<IotDeviceRunLogDO> getDeivceFillInfo(IotDeviceRunLogDO vo);
 
+    /**
+     * 更新工单状态
+     * @param vo
+     * @return
+     */
+    int updateFillOrder(IotDeviceRunLogDO vo);
+
+    int updateFillOrder1(IotDeviceRunLogDO vo);
+
 }

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

@@ -161,4 +161,14 @@ public class IotOpeationFillServiceImpl implements IotOpeationFillService {
         return iotOpeationFillMapper.getDeivceFillInfo(vo);
     }
 
+    @Override
+    public int updateFillOrder(IotDeviceRunLogDO vo) {
+        return iotOpeationFillMapper.updateFillOrder(vo);
+    }
+
+    @Override
+    public int updateFillOrder1(IotDeviceRunLogDO vo) {
+        return iotOpeationFillMapper.updateFillOrder1(vo);
+    }
+
 }

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

@@ -196,7 +196,7 @@
         update  rqiot.rq_iot_opeation_fill
          set is_fill = '1'
         where device_id = #{deviceId}
-        and DATE(create_time) = CURDATE()
+        and DATE(create_time) = DATE(#{createTime})
     </update>
 
     <select id="getFillList" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillRespVO"
@@ -228,7 +228,11 @@
         and
             create_time  = (SELECT MAX(create_time) FROM rq_iot_device_run_log WHERE
                 device_id = #{deviceId})-->
-        SELECT * FROM rq_iot_device_run_log
+        SELECT
+        point_name,
+        fill_content,
+        (select max(total_run_time) from rq_iot_device_run_log  where  device_id = #{deviceId})total_run_time
+        FROM rq_iot_device_run_log
         WHERE
         device_id = #{deviceId}
         and
@@ -238,4 +242,11 @@
         limit 1
     </select>
 
+    <update id="updateFillOrder" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
+        update rqiot.rq_iot_opeation_fill_order set order_status = 1 where id = #{id}
+    </update>
+    <update id="updateFillOrder1" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO">
+        update rqiot.rq_iot_opeation_fill_order set order_status = 0 where id = #{id}
+    </update>
+
 </mapper>