王苗苗 3 tygodni temu
rodzic
commit
888ad7a86f

+ 4 - 0
ruoyi-quartz/pom.xml

@@ -34,6 +34,10 @@
             <groupId>com.ruoyi</groupId>
             <artifactId>ruoyi-common</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.ruoyi</groupId>
+            <artifactId>ruoyi-system</artifactId>
+        </dependency>
 
     </dependencies>
 

+ 106 - 0
ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RyTask.java

@@ -1,14 +1,34 @@
 package com.ruoyi.quartz.task;
 
+import cn.hutool.http.HttpUtil;
+import com.alibaba.fastjson2.JSON;
+import com.ruoyi.business.domain.BizDevice;
+import com.ruoyi.business.mapper.BizDeviceMapper;
+import com.ruoyi.business.mapper.ZAssayMapper;
+import com.ruoyi.business.mapper.ZAssayResultMapper;
+import com.ruoyi.common.utils.DateUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 import com.ruoyi.common.utils.StringUtils;
 
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+import java.util.Optional;
+
+import static com.ruoyi.common.constant.Constants.HTTP_GET_TIME_OUT_MILLION_SECONDS;
+import static com.ruoyi.common.constant.Constants.SQL_SERVER_REMOTE_INTERFACE_ADDR;
+
 /**
  * 定时任务调度测试
  * 
  * @author ruoyi
  */
 @Component("ryTask")
+@Slf4j
 public class RyTask
 {
     public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i)
@@ -25,4 +45,90 @@ public class RyTask
     {
         System.out.println("执行无参方法");
     }
+
+
+    @Autowired
+    private BizDeviceMapper bizDeviceMapper;
+
+    @Autowired
+    private ZAssayMapper assayMapper;
+
+    @Autowired
+    private ZAssayResultMapper assayResultMapper;
+
+    /**
+     *
+     * 同步化验设备的状态
+     */
+    public void syncDevice(){
+        //获取本地的所有设备信息
+        List<BizDevice> bizDevices = this.bizDeviceMapper.selectBizDeviceList(null);
+        if(CollectionUtils.isEmpty(bizDevices)){
+            log.error("同步设备信息的时候,没有查询到本地的设备信息,无法同步");
+            return;
+        }
+
+        //获取SqlServer数据库的设备实时信息
+        String result;
+        List<BizDevice> remoteList;
+        try {
+            result = HttpUtil.get(SQL_SERVER_REMOTE_INTERFACE_ADDR + "/bizDeviceList", HTTP_GET_TIME_OUT_MILLION_SECONDS);
+            log.info("调用同步设备接口返回的结果为{}", result);
+            remoteList = JSON.parseArray(result, BizDevice.class);
+        } catch (Exception e) {
+            throw new RuntimeException("调用同步设备接口异常,异常信息为:" + e.getMessage());
+        }
+        log.info("调用同步设备接口转换完对象以后,获取到的需要同步的数据为{}", JSON.toJSONString(remoteList));
+        if(CollectionUtils.isEmpty(remoteList)){
+            log.error("同步设备信息的时候,没有查询到SqlServer数据库的设备信息,无法同步");
+            return;
+        }
+
+        //匹配数据 更新状态
+        for (BizDevice bizDevice : bizDevices) {
+            //使用设备编号进行匹配
+            String deviceNo = bizDevice.getDeviceNo();
+            Optional<BizDevice> optional = remoteList.stream().filter(r -> r.getDeviceNo().equals(deviceNo)).findAny();
+            if(optional.isPresent()){
+                BizDevice bizDeviceNew = optional.get();
+                //只需要更新化验状态即可
+                bizDevice.setAssayStatus(bizDeviceNew.getAssayStatus());
+                bizDevice.setAssayTime(bizDeviceNew.getAssayTime());
+                bizDevice.setUpdateBy("task-job");
+                bizDevice.setUpdateTime(DateUtils.getNowDate());
+                this.bizDeviceMapper.updateBizDevice(bizDevice);
+            }else {
+                log.error("通过设备编号{}去匹配SqlServer设备数据时,没有查询到", deviceNo);
+            }
+        }
+    }
+
+
+    /**
+     * 定时任务 同步化验信息
+     */
+    public void syncAssay(){
+        log.info("进入了定时任务:同步化验信息逻辑处理");
+        //获取同步的最新的ID
+        Long id = this.assayMapper.selectMaxId();
+        //查询待同步的数据
+
+        //同步数据并插入到数据库
+
+    }
+
+
+    /**
+     * 定时任务 同步化验结果明细信息
+     */
+    public void syncAssayResult(){
+        log.info("进入了定时任务:同步化验结果明细信息逻辑处理");
+        //获取同步的最新的ID
+        Long id = this.assayResultMapper.selectMaxId();
+        //查询待同步的数据
+
+        //同步数据并插入到数据库
+    }
+
+
 }

+ 2 - 0
ruoyi-system/src/main/java/com/ruoyi/business/mapper/ZAssayMapper.java

@@ -67,4 +67,6 @@ public interface ZAssayMapper
     int getDistinctCountsByDeviceNoAndDate(@Param("assayDate") String assayDate, @Param("deviceNo") String deviceNo);
 
     List<AssayDetailRes> assayPageListByDeviceNoAndDate(AssayReq assayReq);
+
+    Long selectMaxId();
 }

+ 2 - 0
ruoyi-system/src/main/java/com/ruoyi/business/mapper/ZAssayResultMapper.java

@@ -64,4 +64,6 @@ public interface ZAssayResultMapper
     List<ContinuousAssayBasic> continuousAssayCountByDates(AssayReq assayReq);
 
     List<ZAssayResult> assayCountListByDates(AssayReq assayReq);
+
+    Long selectMaxId();
 }

+ 4 - 0
ruoyi-system/src/main/resources/mapper/business/ZAssayMapper.xml

@@ -186,4 +186,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         AND za.assay_date between #{timeBegin} and #{timeEnd}
         <if test="deviceNo != null  and deviceNo != ''"> and za.device_no = #{deviceNo}</if>
     </select>
+
+    <select id="selectMaxId" resultType="java.lang.Long">
+        SELECT MAX(assay_id) FROM z_assay
+    </select>
 </mapper>

+ 4 - 0
ruoyi-system/src/main/resources/mapper/business/ZAssayResultMapper.xml

@@ -267,4 +267,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <if test="timeBegin != null  and timeBegin != ''"> and sr.result_date &gt;= #{timeBegin}</if>
         <if test="timeEnd != null  and timeEnd != ''"> and sr.result_date &lt;= #{timeEnd}</if>
     </select>
+
+    <select id="selectMaxId" resultType="java.lang.Long">
+        SELECT MAX(result_id) FROM z_assay_result
+    </select>
 </mapper>