lau572
9 months ago
7 changed files with 194 additions and 17 deletions
@ -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<DcDevice> dcDeviceList = dcDeviceService.listDevice(null); |
||||
|
if (dcDeviceList != null){ |
||||
|
|
||||
|
List<MdDevice> 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 + "秒"); |
||||
|
|
||||
|
} |
||||
|
} |
Loading…
Reference in new issue