From 54c476d702de710a39fa8559a633e4de4afa49c9 Mon Sep 17 00:00:00 2001 From: lau572 <1010031226@qq.com> Date: Fri, 23 Feb 2024 16:03:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E6=97=B6=E5=90=8C=E6=AD=A5=E4=B8=AD?= =?UTF-8?q?=E9=97=B4=E5=BA=93=E8=AE=BE=E5=A4=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/zc/business/domain/MdDevice.java | 2 +- .../business/mapper/MiddleDatabaseMapper.java | 9 ++ .../service/IMiddleDatabaseService.java | 9 ++ .../impl/MiddleDatabaseServiceImpl.java | 13 +++ .../zc/business/task/MiddleDatabaseTask.java | 78 +++++++++++++++ .../mapper/business/DcDeviceMapper.xml | 2 +- .../mapper/business/MiddleDatabaseMapper.xml | 98 ++++++++++++++++--- 7 files changed, 194 insertions(+), 17 deletions(-) create mode 100644 zc-business/src/main/java/com/zc/business/task/MiddleDatabaseTask.java diff --git a/zc-business/src/main/java/com/zc/business/domain/MdDevice.java b/zc-business/src/main/java/com/zc/business/domain/MdDevice.java index f10d8964..c728ef66 100644 --- a/zc-business/src/main/java/com/zc/business/domain/MdDevice.java +++ b/zc-business/src/main/java/com/zc/business/domain/MdDevice.java @@ -303,7 +303,7 @@ public class MdDevice this.facilitiesType = dcDevice.getFacilitiesType(); } this.devStatus = dcDevice.getDeviceState(); - if (dcDevice.getGroupId() > 0){ + if (dcDevice.getGroupId() != null && dcDevice.getGroupId() > 0){ this.opmaManagerId = dcDevice.getGroupId().toString(); } this.supplierName = dcDevice.getManufacturer(); diff --git a/zc-business/src/main/java/com/zc/business/mapper/MiddleDatabaseMapper.java b/zc-business/src/main/java/com/zc/business/mapper/MiddleDatabaseMapper.java index 028a80a3..180700fb 100644 --- a/zc-business/src/main/java/com/zc/business/mapper/MiddleDatabaseMapper.java +++ b/zc-business/src/main/java/com/zc/business/mapper/MiddleDatabaseMapper.java @@ -49,6 +49,15 @@ public interface MiddleDatabaseMapper */ boolean deleteMiddleDatabaseDeviceInfoByIds(List ids); + /** + * 批量更新中间库设备 + * 有则修改,无则新增 + * + * @param mdDeviceList 设备列表 + * @return 结果 + */ + boolean synchronizeMdDevice(List mdDeviceList); + /** * 更新中间库设备 * diff --git a/zc-business/src/main/java/com/zc/business/service/IMiddleDatabaseService.java b/zc-business/src/main/java/com/zc/business/service/IMiddleDatabaseService.java index c6a30df9..96560db1 100644 --- a/zc-business/src/main/java/com/zc/business/service/IMiddleDatabaseService.java +++ b/zc-business/src/main/java/com/zc/business/service/IMiddleDatabaseService.java @@ -56,6 +56,15 @@ public interface IMiddleDatabaseService */ boolean deleteMiddleDatabaseDeviceInfoByIds(List ids); + /** + * 批量更新中间库设备 + * 有则修改,无则新增 + * + * @param mdDeviceList 设备列表 + * @return 结果 + */ + boolean synchronizeMdDevice(List mdDeviceList); + /** * 更新中间库设备状态 * diff --git a/zc-business/src/main/java/com/zc/business/service/impl/MiddleDatabaseServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/MiddleDatabaseServiceImpl.java index 88e733f8..7f5021de 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/MiddleDatabaseServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/MiddleDatabaseServiceImpl.java @@ -99,6 +99,19 @@ public class MiddleDatabaseServiceImpl implements IMiddleDatabaseService { return middleDatabaseMapper.deleteMiddleDatabaseDeviceInfoByIds(ids); } + /** + * 批量更新中间库设备 + * 有则修改,无则新增 + * + * @param mdDeviceList 设备列表 + * @return 结果 + */ + @Override + public boolean synchronizeMdDevice(List mdDeviceList){ + + return middleDatabaseMapper.synchronizeMdDevice(mdDeviceList); + } + /** * 更新中间库设备 * diff --git a/zc-business/src/main/java/com/zc/business/task/MiddleDatabaseTask.java b/zc-business/src/main/java/com/zc/business/task/MiddleDatabaseTask.java new file mode 100644 index 00000000..ebb74b25 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/task/MiddleDatabaseTask.java @@ -0,0 +1,78 @@ +package com.zc.business.task; + +import com.ruoyi.common.constant.HttpStatus; +import com.ruoyi.common.exception.ServiceException; +import com.ruoyi.common.utils.DateUtils; +import com.ruoyi.common.utils.spring.SpringUtils; +import com.zc.business.domain.DcDevice; +import com.zc.business.domain.DcProduct; +import com.zc.business.domain.MdDevice; +import com.zc.business.service.IDcDeviceService; +import com.zc.business.service.IDcProductService; +import com.zc.business.service.IMiddleDatabaseService; +import com.zc.business.service.impl.StatusService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Objects; + +/** + * 定时任务 + * + */ +@Component +public class MiddleDatabaseTask +{ + private IDcDeviceService dcDeviceService= SpringUtils.getBean(IDcDeviceService.class); + + private IMiddleDatabaseService middleDatabaseService= SpringUtils.getBean(IMiddleDatabaseService.class); + + private IDcProductService productService= SpringUtils.getBean(IDcProductService.class); + + + /** + * @Description 定时同步设备信息到中间库 + * + * @author liuwenge + * @date 2024/2/23 11:57 + * @param + * @return void + */ + public void synchronizeMdDevice(){ + Date startTime = new Date(); + + System.out.println("定时同步设备信息到中间库 开始-----------------------------"); + + List dcDeviceList = dcDeviceService.listDevice(null); + if (dcDeviceList != null){ + + List mdDeviceList = new ArrayList<>(); + + dcDeviceList.forEach(item -> { + + Long productId = item.getProductId(); + if (Objects.nonNull(productId)) { + //设备厂商 + DcProduct dcProduct = productService.getById(productId); + if (dcProduct != null) { + item.setManufacturer(dcProduct.getManufacturer()); + } + } + + MdDevice mdDevice = new MdDevice(item); + + mdDeviceList.add(mdDevice); + }); + + middleDatabaseService.synchronizeMdDevice(mdDeviceList); + } + Date endTime = new Date(); + + Long diff = (endTime.getTime() - startTime.getTime()) / 1000; + System.out.println("定时同步设备信息到中间库 结束-----------------------------用时" + diff + "秒"); + + } +} diff --git a/zc-business/src/main/resources/mapper/business/DcDeviceMapper.xml b/zc-business/src/main/resources/mapper/business/DcDeviceMapper.xml index 3b18ddad..938e1c93 100644 --- a/zc-business/src/main/resources/mapper/business/DcDeviceMapper.xml +++ b/zc-business/src/main/resources/mapper/business/DcDeviceMapper.xml @@ -62,7 +62,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"