123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- 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)
- {
- System.out.println(StringUtils.format("执行多参方法: 字符串类型{},布尔类型{},长整型{},浮点型{},整形{}", s, b, l, d, i));
- }
- public void ryParams(String params)
- {
- System.out.println("执行有参方法:" + params);
- }
- public void ryNoParams()
- {
- 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();
- //查询待同步的数据
- //同步数据并插入到数据库
- }
- }
|