Browse Source

定时同步中间库设备

develop
lau572 9 months ago
parent
commit
54c476d702
  1. 2
      zc-business/src/main/java/com/zc/business/domain/MdDevice.java
  2. 9
      zc-business/src/main/java/com/zc/business/mapper/MiddleDatabaseMapper.java
  3. 9
      zc-business/src/main/java/com/zc/business/service/IMiddleDatabaseService.java
  4. 13
      zc-business/src/main/java/com/zc/business/service/impl/MiddleDatabaseServiceImpl.java
  5. 78
      zc-business/src/main/java/com/zc/business/task/MiddleDatabaseTask.java
  6. 2
      zc-business/src/main/resources/mapper/business/DcDeviceMapper.xml
  7. 98
      zc-business/src/main/resources/mapper/business/MiddleDatabaseMapper.xml

2
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();

9
zc-business/src/main/java/com/zc/business/mapper/MiddleDatabaseMapper.java

@ -49,6 +49,15 @@ public interface MiddleDatabaseMapper
*/
boolean deleteMiddleDatabaseDeviceInfoByIds(List<String> ids);
/**
* 批量更新中间库设备
* 有则修改,无则新增
*
* @param mdDeviceList 设备列表
* @return 结果
*/
boolean synchronizeMdDevice(List<MdDevice> mdDeviceList);
/**
* 更新中间库设备
*

9
zc-business/src/main/java/com/zc/business/service/IMiddleDatabaseService.java

@ -56,6 +56,15 @@ public interface IMiddleDatabaseService
*/
boolean deleteMiddleDatabaseDeviceInfoByIds(List<String> ids);
/**
* 批量更新中间库设备
* 有则修改,无则新增
*
* @param mdDeviceList 设备列表
* @return 结果
*/
boolean synchronizeMdDevice(List<MdDevice> mdDeviceList);
/**
* 更新中间库设备状态
*

13
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<MdDevice> mdDeviceList){
return middleDatabaseMapper.synchronizeMdDevice(mdDeviceList);
}
/**
* 更新中间库设备
*

78
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<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 + "秒");
}
}

2
zc-business/src/main/resources/mapper/business/DcDeviceMapper.xml

@ -62,7 +62,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectDcDeviceList" parameterType="dcDevice" resultMap="DcDevice">
select t1.id, t1.iot_device_id, t1.group_id, t1.product_id, t1.stake_mark, t1.direction, t1.device_name, t1.device_code, t1.device_type,
t1.installation_Date,t1.production_date,t1.durable_years,t1.installation_site,t1.use_state,t1.device_state,t1.other_config,t1.remark,t1.create_time,t1.update_time,
t2.longitude,t2.latitude
t1.facilities_type,t2.longitude,t2.latitude
from dc_device t1
left join dc_stake_mark t2 on t1.stake_mark = t2.stake_mark and t1.direction = t2.direction
<where>

98
zc-business/src/main/resources/mapper/business/MiddleDatabaseMapper.xml

@ -163,25 +163,93 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</trim>
</insert>
<insert id="synchronizeMdDevice" parameterType="java.util.List">
<foreach collection ="list" item="mdDevice" index= "index" separator =";">
insert into device
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="mdDevice.id != null">id,</if>
<if test="mdDevice.devNo != null">dev_no,</if>
<if test="mdDevice.devName != null">dev_name,</if>
<if test="mdDevice.stakeNum != null">stake_num,</if>
<if test="mdDevice.direction != null">direction,</if>
<if test="mdDevice.typeCode != null">type_code,</if>
<if test="mdDevice.facilitiesType != null">facilities_type,</if>
<if test="mdDevice.devStatus != null">dev_status,</if>
<if test="mdDevice.opmaManagerId != null">opma_manager_id,</if>
<if test="mdDevice.opmaManagerName != null">opma_manager_name,</if>
<if test="mdDevice.supplierName != null">supplier_name,</if>
<if test="mdDevice.sectionId != null">section_id,</if>
CreationTime,
<if test="mdDevice.creatorUserId != null">CreatorUserId,</if>
<if test="mdDevice.lastModificationTime != null">LastModificationTime,</if>
<if test="mdDevice.lastModifierUserId != null">LastModifierUserId,</if>
<if test="mdDevice.isDeleted != null">IsDeleted,</if>
<if test="mdDevice.deleterUserId != null">DeleterUserId,</if>
<if test="mdDevice.deletionTime != null">DeletionTime,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="mdDevice.id != null">#{mdDevice.id},</if>
<if test="mdDevice.devNo != null">#{mdDevice.devNo},</if>
<if test="mdDevice.devName != null">#{mdDevice.devName},</if>
<if test="mdDevice.stakeNum != null">#{mdDevice.stakeNum},</if>
<if test="mdDevice.direction != null">#{mdDevice.direction},</if>
<if test="mdDevice.typeCode != null">#{mdDevice.typeCode},</if>
<if test="mdDevice.facilitiesType != null">#{mdDevice.facilitiesType},</if>
<if test="mdDevice.devStatus != null">#{mdDevice.devStatus},</if>
<if test="mdDevice.opmaManagerId != null">#{mdDevice.opmaManagerId},</if>
<if test="mdDevice.opmaManagerName != null">#{mdDevice.opmaManagerName},</if>
<if test="mdDevice.supplierName != null">#{mdDevice.supplierName},</if>
<if test="mdDevice.sectionId != null">#{mdDevice.sectionId},</if>
now(),
<if test="mdDevice.creatorUserId != null">#{mdDevice.creatorUserId},</if>
<if test="mdDevice.lastModificationTime != null">#{mdDevice.lastModificationTime},</if>
<if test="mdDevice.lastModifierUserId != null">#{mdDevice.lastModifierUserId},</if>
<if test="mdDevice.isDeleted != null">#{mdDevice.isDeleted},</if>
<if test="mdDevice.deleterUserId != null">#{mdDevice.deleterUserId},</if>
<if test="mdDevice.deletionTime != null">#{mdDevice.deletionTime},</if>
</trim>
ON DUPLICATE KEY UPDATE
<trim suffixOverrides=",">
<if test="mdDevice.devNo != null">dev_no = #{mdDevice.devNo},</if>
<if test="mdDevice.devName != null">dev_name = #{mdDevice.devName},</if>
<if test="mdDevice.stakeNum != null">stake_num = #{mdDevice.stakeNum},</if>
<if test="mdDevice.direction != null">direction = #{mdDevice.direction},</if>
<if test="mdDevice.typeCode != null">type_code = #{mdDevice.typeCode},</if>
<if test="mdDevice.facilitiesType != null">facilities_type = #{mdDevice.facilitiesType},</if>
<if test="mdDevice.devStatus != null">dev_status = #{mdDevice.devStatus},</if>
<if test="mdDevice.opmaManagerId != null">opma_manager_id = #{mdDevice.opmaManagerId},</if>
<if test="mdDevice.opmaManagerName != null">opma_manager_name = #{mdDevice.opmaManagerName},</if>
<if test="mdDevice.supplierName != null">supplier_name = #{mdDevice.supplierName},</if>
<if test="mdDevice.sectionId != null">section_id = #{mdDevice.sectionId},</if>
LastModificationTime = now(),
<if test="mdDevice.lastModifierUserId != null">LastModifierUserId = #{mdDevice.lastModifierUserId},</if>
<if test="mdDevice.isDeleted != null">IsDeleted = #{mdDevice.isDeleted},</if>
<if test="mdDevice.deleterUserId != null">DeleterUserId = #{mdDevice.deleterUserId},</if>
<if test="mdDevice.deletionTime != null">DeletionTime = #{mdDevice.deletionTime},</if>
</trim>
</foreach>
</insert>
<update id="updateMiddleDatabaseDeviceInfo" parameterType="MdDevice">
update device
<set>
<if test="devNo != null">dev_no = #{devNo}</if>
<if test="devName != null">dev_name = #{devName}</if>
<if test="stakeNum != null">stake_num = #{stakeNum}</if>
<if test="direction != null">direction = #{direction}</if>
<if test="typeCode != null">type_code = #{typeCode}</if>
<if test="facilitiesType != null">facilities_type = #{facilitiesType}</if>
<if test="devStatus != null">dev_status = #{devStatus}</if>
<if test="opmaManagerId != null">opma_manager_id = #{opmaManagerId}</if>
<if test="opmaManagerName != null">opma_manager_name = #{opmaManagerName}</if>
<if test="supplierName != null">supplier_name = #{supplierName}</if>
<if test="sectionId != null">section_id = #{sectionId}</if>
<if test="devNo != null">dev_no = #{devNo},</if>
<if test="devName != null">dev_name = #{devName},</if>
<if test="stakeNum != null">stake_num = #{stakeNum},</if>
<if test="direction != null">direction = #{direction},</if>
<if test="typeCode != null">type_code = #{typeCode},</if>
<if test="facilitiesType != null">facilities_type = #{facilitiesType},</if>
<if test="devStatus != null">dev_status = #{devStatus},</if>
<if test="opmaManagerId != null">opma_manager_id = #{opmaManagerId},</if>
<if test="opmaManagerName != null">opma_manager_name = #{opmaManagerName},</if>
<if test="supplierName != null">supplier_name = #{supplierName},</if>
<if test="sectionId != null">section_id = #{sectionId},</if>
LastModificationTime = now(),
<if test="lastModifierUserId != null">LastModifierUserId = #{lastModifierUserId}</if>
<if test="isDeleted != null">IsDeleted = #{isDeleted}</if>
<if test="deleterUserId != null">DeleterUserId = #{deleterUserId}</if>
<if test="deletionTime != null">DeletionTime = #{deletionTime}</if>
<if test="lastModifierUserId != null">LastModifierUserId = #{lastModifierUserId},</if>
<if test="isDeleted != null">IsDeleted = #{isDeleted},</if>
<if test="deleterUserId != null">DeleterUserId = #{deleterUserId},</if>
<if test="deletionTime != null">DeletionTime = #{deletionTime},</if>
</set>
where id = #{id}
</update>

Loading…
Cancel
Save