瀏覽代碼

数据接受策略优化

Tong 3 年之前
父節點
當前提交
320462e198

+ 2 - 11
ruoyi-system/src/main/java/com/ruoyi/system/domain/BusDeviceRunning.java

@@ -1,5 +1,6 @@
 package com.ruoyi.system.domain;
 
+import com.ruoyi.common.core.domain.BaseEntity;
 import org.apache.commons.lang3.builder.ToStringBuilder;
 import org.apache.commons.lang3.builder.ToStringStyle;
 import com.ruoyi.common.annotation.Excel;
@@ -12,7 +13,7 @@ import java.io.Serializable;
  * @author zsl
  * @date 2022-06-17
  */
-public class BusDeviceRunning implements Serializable
+public class BusDeviceRunning extends BaseEntity implements Serializable
 {
     private static final long serialVersionUID = 1L;
 
@@ -25,16 +26,6 @@ public class BusDeviceRunning implements Serializable
 
     private String status;
 
-    private String createTime;
-
-    public String getCreateTime() {
-        return createTime;
-    }
-
-    public void setCreateTime(String createTime) {
-        this.createTime = createTime;
-    }
-
     public void setId(Long id) {
         this.id = id;
     }

+ 3 - 0
ruoyi-system/src/main/java/com/ruoyi/system/mapper/BusDeviceNewsMapper.java

@@ -27,6 +27,9 @@ public interface BusDeviceNewsMapper
      */
     public List<BusDeviceNews> selectBusDeviceNewsList(BusDeviceNews busDeviceNews);
 
+
+    public List<BusDeviceNews> selectBusDeviceNewsListByDIdAndCreateTime(BusDeviceNews busDeviceNews);
+
     /**
      * 新增news
      * 

+ 32 - 1
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/BusDeviceRunningServiceImpl.java

@@ -1,6 +1,7 @@
 package com.ruoyi.system.service.impl;
 
 import java.text.SimpleDateFormat;
+import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
 
@@ -122,7 +123,7 @@ public class BusDeviceRunningServiceImpl implements IBusDeviceRunningService
             busDeviceNews.setBloodVolumeReturn(json.getBody().getCurrentValue().getBloodVolumeReturn());
             busDeviceNews.setRateBpReal(json.getBody().getCurrentValue().getRateBPReal());
         }
-        SimpleDateFormat sm = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
+        SimpleDateFormat sm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         String createTime =sm.format(new Date());
 
         List<BusDeviceHistory> historyList =  busDeviceHistoryMapper.selectBusDeviceByDeviceId(deviceId);
@@ -133,10 +134,26 @@ public class BusDeviceRunningServiceImpl implements IBusDeviceRunningService
                 busDeviceHistoryMapper.updateBusDeviceHistory(deviceHistory);
             }
             busDeviceNews.setHistoryId(deviceHistory.getId());
+
+            BusDeviceNews findNewsByDIdAndCreateTime = new BusDeviceNews();
+            SimpleDateFormat fm =new SimpleDateFormat("yyyy-MM-dd");
+            String NDate = fm.format(new Date());
+            findNewsByDIdAndCreateTime.setDeviceId(deviceId);
+            findNewsByDIdAndCreateTime.setTime(this.addHour(busDeviceNews.getTime(),-3));
+            List<BusDeviceNews> newsLists = busDeviceNewsMapper.selectBusDeviceNewsListByDIdAndCreateTime(findNewsByDIdAndCreateTime);
+            System.out.println("newsLists.size()::::::::::::::"+newsLists.size());
+            if(newsLists!=null && newsLists.size()>0){
+                for(int i = 0; i<newsLists.size(); i++){
+                    BusDeviceNews upHis = newsLists.get(i);
+                    upHis.setHistoryId(deviceHistory.getId());
+                    this.busDeviceNewsMapper.updateBusDeviceNews(upHis);
+                }
+            }
         }else{
             busDeviceRunning.setStatus("0");
         }
         busDeviceNews.setCreateTime(createTime);
+
         busDeviceNewsMapper.insertBusDeviceNews(busDeviceNews);
         return busDeviceRunningMapper.insertBusDeviceRunning(busDeviceRunning);
     }
@@ -176,4 +193,18 @@ public class BusDeviceRunningServiceImpl implements IBusDeviceRunningService
     {
         return busDeviceRunningMapper.deleteBusDeviceRunningById(id);
     }
+
+    /**
+     * 在原日期的基础上增加小时数
+     * @param date
+     * @param i
+     * @return
+     */
+    public static Date addHour(Date date,int i){
+        Calendar c = Calendar.getInstance();
+        c.setTime(date);
+        c.add(Calendar.HOUR_OF_DAY, i);
+        Date newDate = c.getTime();
+        return newDate;
+    }
 }

+ 11 - 2
ruoyi-system/src/main/resources/mapper/system/BusDeviceNewsMapper.xml

@@ -80,7 +80,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="bloodVolumeReturn != null  and bloodVolumeReturn != ''"> and blood_volume_return = #{bloodVolumeReturn}</if>
             <if test="rateBpReal != null  and rateBpReal != ''"> and rate_BP_real = #{rateBpReal}</if>
             <if test="historyId != null "> and history_id = #{historyId}</if>
-            <if test="createTime != null "> and create_time = #{createTime}</if>
+            <if test="createTime != null "> and create_time like %#{createTime}%</if>
         </where>
     </select>
     
@@ -88,7 +88,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <include refid="selectBusDeviceNewsVo"/>
         where id = #{id}
     </select>
-        
+
+    <select id="selectBusDeviceNewsListByDIdAndCreateTime" parameterType="BusDeviceNews" resultMap="BusDeviceNewsResult">
+        <include refid="selectBusDeviceNewsVo"/>
+        <where>
+            <if test="deviceId != null "> and device_id = #{deviceId}</if>
+            <if test="time != null "> and time > #{time}</if>
+            and ISNULL(history_id)
+        </where>
+    </select>
+
     <insert id="insertBusDeviceNews" parameterType="BusDeviceNews" useGeneratedKeys="true" keyProperty="id">
         insert into bus_device_news
         <trim prefix="(" suffix=")" suffixOverrides=",">