组态物料保养,维修,设备信息接口实现,相关数据同步

This commit is contained in:
shih
2026-04-23 16:41:32 +08:00
parent 424d290127
commit 299135275a
19 changed files with 680 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
package iot.lidee.iot.mapper.bygz;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import iot.lidee.framework.mybatis.mapper.BaseMapperX;
import iot.lidee.iot.model.bygz.ByManagementGd;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* 保养管理-保养工单Mapper接口
*
* @date 2026-03-20
*/
@Mapper
public interface ByManagementGdMapper extends BaseMapperX<ByManagementGd> {
default List<ByManagementGd> selectGdList(){
return this.selectList(new QueryWrapper<>());
}
}

View File

@@ -0,0 +1,23 @@
package iot.lidee.iot.mapper.bygz;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import iot.lidee.framework.mybatis.mapper.BaseMapperX;
import iot.lidee.iot.model.bygz.ByManagementJl;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* 保养管理-保养记录Mapper接口
*
* @date 2026-03-20
*/
@Mapper
public interface ByManagementJlMapper extends BaseMapperX<ByManagementJl> {
default List<ByManagementJl> selectJlList(){
return this.selectList(new QueryWrapper<>());
}
List<ByManagementJl> selectBygdByType(String devtype);
}

View File

@@ -0,0 +1,21 @@
package iot.lidee.iot.mapper.bygz;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import iot.lidee.framework.mybatis.mapper.BaseMapperX;
import iot.lidee.iot.model.bygz.ByManagementPlan;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* 保养管理-保养计划Mapper接口
*
* @date 2026-04-15
*/
@Mapper
public interface ByManagementPlanMapper extends BaseMapperX<ByManagementPlan> {
default List<ByManagementPlan> selectPlanList(){
return this.selectList(new QueryWrapper<>());
}
}

View File

@@ -0,0 +1,21 @@
package iot.lidee.iot.mapper.bygz;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import iot.lidee.framework.mybatis.mapper.BaseMapperX;
import iot.lidee.iot.model.bygz.ByManagementYs;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* 保养管理-保养验收Mapper接口
*
* @date 2026-03-20
*/
@Mapper
public interface ByManagementYsMapper extends BaseMapperX<ByManagementYs> {
default List<ByManagementYs> selectYsList(){
return this.selectList(new QueryWrapper<>());
}
}

View File

@@ -0,0 +1,21 @@
package iot.lidee.iot.mapper.bygz;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import iot.lidee.framework.mybatis.mapper.BaseMapperX;
import iot.lidee.iot.model.bygz.DevGzbxDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* demo相关
*/
@Mapper
public interface DevGzbxMapper extends BaseMapperX<DevGzbxDO> {
default List<DevGzbxDO> selectGzbxList(){
return this.selectList(new QueryWrapper<>());
}
}

View File

@@ -0,0 +1,26 @@
package iot.lidee.iot.mapper.bygz;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import iot.lidee.framework.mybatis.mapper.BaseMapperX;
import iot.lidee.iot.domain.Device;
import iot.lidee.iot.model.bygz.DevGzbxWxgdDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* demo相关
*/
@Mapper
public interface DevGzbxWxgdMapper extends BaseMapperX<DevGzbxWxgdDO> {
default List<DevGzbxWxgdDO> selectGzbxWxgdList(){
return this.selectList(new QueryWrapper<>());
}
List<DevGzbxWxgdDO> selectWxgdByType(String devtype);
List<Device> deviceList(String devtype);
}

View File

@@ -0,0 +1,20 @@
package iot.lidee.iot.mapper.bygz;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import iot.lidee.framework.mybatis.mapper.BaseMapperX;
import iot.lidee.iot.model.bygz.DevArchivesEntity;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* 设备档案
*/
@Mapper
public interface DeviceArchivesMapper extends BaseMapperX<DevArchivesEntity> {
default List<DevArchivesEntity> selectDeviceList(){
return this.selectList(new QueryWrapper<>());
}
}

View File

@@ -0,0 +1,16 @@
package iot.lidee.iot.mapper.bygz;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import iot.lidee.framework.mybatis.mapper.BaseMapperX;
import iot.lidee.iot.model.bygz.SblxDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface SblxMapper extends BaseMapperX<SblxDO> {
default List<SblxDO> selectScxList(){
return this.selectList(new QueryWrapper<>());
}
}

View File

@@ -0,0 +1,9 @@
package iot.lidee.iot.service;
import iot.lidee.iot.model.bygz.SyncDataContainer;
public interface IDeviceDataLoadService {
SyncDataContainer loadData();
}

View File

@@ -0,0 +1,9 @@
package iot.lidee.iot.service;
import iot.lidee.iot.model.bygz.SyncDataContainer;
public interface IDeviceDataSyncService {
void syncDataToMaster(SyncDataContainer syncData);
}

View File

@@ -0,0 +1,18 @@
package iot.lidee.iot.service;
import iot.lidee.iot.domain.Device;
import iot.lidee.iot.model.bygz.ByManagementJl;
import iot.lidee.iot.model.bygz.DevGzbxWxgdDO;
import java.util.List;
public interface IDeviceMaintenanceRepairService {
void syncDeviceMaintenanceRepairInfo();
List<ByManagementJl> maintenanceList(String devtype);
List<DevGzbxWxgdDO> repairList(String devtype);
List<Device> deviceList(String devtype);
}

View File

@@ -0,0 +1,81 @@
package iot.lidee.iot.service.impl;
import com.baomidou.dynamic.datasource.annotation.DS;
import iot.lidee.iot.mapper.bygz.*;
import iot.lidee.iot.model.bygz.*;
import iot.lidee.iot.service.IDeviceDataLoadService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@DS("maintenance_repair_data")
@Primary
@Service
@Slf4j
public class DeviceDataLoadServiceImpl implements IDeviceDataLoadService {
private static final Logger logger = LoggerFactory.getLogger(DeviceMaintenanceRepairServiceImpl.class);
@Resource
private ByManagementGdMapper byManagementGdMapper;
@Resource
private ByManagementJlMapper byManagementJlMapper;
@Resource
private ByManagementPlanMapper byManagementPlanMapper;
@Resource
private ByManagementYsMapper byManagementYsMapper;
@Resource
private DevGzbxMapper devGzbxMapper;
@Resource
private DevGzbxWxgdMapper devGzbxWxgdMapper;
@Resource
private DeviceArchivesMapper deviceArchivesMapper;
@Resource
private SblxMapper sblxMapper;
/**
* 加载设备维护相关数据
* 从数据库中查询各类设备和保养维修数据,封装到同步数据容器中
*
* @return 同步数据容器,包含设备档案、保养工单、保养记录、保养计划、保养验收、故障报修、维修工单、设备类型等数据
*/
@Override
public SyncDataContainer loadData() {
SyncDataContainer syncData = new SyncDataContainer();
// 获取源数据
List<DevArchivesEntity> devArchivesEntities = deviceArchivesMapper.selectDeviceList();
syncData.setDevices(devArchivesEntities);
List<ByManagementGd> byManagementGds = byManagementGdMapper.selectGdList();
syncData.setGdList(byManagementGds);
List<ByManagementJl> byManagementJls = byManagementJlMapper.selectJlList();
syncData.setJlList(byManagementJls);
List<ByManagementPlan> byManagementPlans = byManagementPlanMapper.selectPlanList();
syncData.setPlanList(byManagementPlans);
List<ByManagementYs> byManagementYs = byManagementYsMapper.selectYsList();
syncData.setYsList(byManagementYs);
List<DevGzbxDO> devGzbxDOS = devGzbxMapper.selectGzbxList();
syncData.setGzbxList(devGzbxDOS);
List<DevGzbxWxgdDO> devGzbxWxgdDOS = devGzbxWxgdMapper.selectGzbxWxgdList();
syncData.setWxgdList(devGzbxWxgdDOS);
List<SblxDO> sblxDOS = sblxMapper.selectScxList();
syncData.setSblxList(sblxDOS);
logger.info("源数据获取完成,开始同步数据");
return syncData;
}
}

View File

@@ -0,0 +1,98 @@
package iot.lidee.iot.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import iot.lidee.framework.mybatis.mapper.BaseMapperX;
import iot.lidee.iot.mapper.bygz.*;
import iot.lidee.iot.model.bygz.SyncDataContainer;
import iot.lidee.iot.service.IDeviceDataSyncService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
@Slf4j
public class DeviceDataSyncServiceImpl implements IDeviceDataSyncService {
private static final Logger logger = LoggerFactory.getLogger(DeviceMaintenanceRepairServiceImpl.class);
private static final int DEFAULT_BATCH_SIZE = 500;
@Resource
private ByManagementGdMapper byManagementGdMapper;
@Resource
private ByManagementJlMapper byManagementJlMapper;
@Resource
private ByManagementPlanMapper byManagementPlanMapper;
@Resource
private ByManagementYsMapper byManagementYsMapper;
@Resource
private DevGzbxMapper devGzbxMapper;
@Resource
private DevGzbxWxgdMapper devGzbxWxgdMapper;
@Resource
private DeviceArchivesMapper deviceArchivesMapper;
@Resource
private SblxMapper sblxMapper;
/**
* 同步数据到主数据库
* 将各类设备和保养维修数据从源数据库同步到主数据库,包括设备档案、保养工单、保养记录、保养计划、
* 保养验收、故障报修、维修工单、生产线等数据
*
* @param data 同步数据容器,包含待同步的各类数据列表
*/
@Override
public void syncDataToMaster(SyncDataContainer data) {
// 同步设备信息
syncData(deviceArchivesMapper, data.getDevices(), "设备信息");
// 同步保养信息
syncData(byManagementGdMapper, data.getGdList(), "保养工单");
syncData(byManagementJlMapper, data.getJlList(), "保养记录");
syncData(byManagementPlanMapper, data.getPlanList(), "保养计划");
syncData(byManagementYsMapper, data.getYsList(), "保养验收");
// 同步维修信息
syncData(devGzbxMapper, data.getGzbxList(), "故障报修");
syncData(devGzbxWxgdMapper, data.getWxgdList(), "维修工单");
// 同步生产线
syncData(sblxMapper, data.getSblxList(), "生产线");
}
/**
* 通用方法
* @param mapper 数据访问接口
* @param dataList 数据列表
* @param dataTypeName 数据类型名称(用于日志)
*/
public <T, M extends BaseMapperX<T>> void syncData(M mapper, List<T> dataList, String dataTypeName) {
if (dataList == null || dataList.isEmpty()) {
logger.warn("{}数据为空,跳过同步", dataTypeName);
return;
}
try {
logger.info("开始同步{},数据量:{}", dataTypeName, dataList.size());
mapper.delete(new QueryWrapper<>());
mapper.insertBatch(dataList, DEFAULT_BATCH_SIZE);
logger.info("{}同步完成", dataTypeName);
} catch (Exception e) {
logger.error("同步{}失败", dataTypeName, e);
throw e;
}
}
}

View File

@@ -0,0 +1,98 @@
package iot.lidee.iot.service.impl;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import iot.lidee.iot.domain.Device;
import iot.lidee.iot.mapper.bygz.ByManagementJlMapper;
import iot.lidee.iot.mapper.bygz.DevGzbxWxgdMapper;
import iot.lidee.iot.model.bygz.ByManagementJl;
import iot.lidee.iot.model.bygz.DevGzbxWxgdDO;
import iot.lidee.iot.model.bygz.SyncDataContainer;
import iot.lidee.iot.service.IDeviceDataLoadService;
import iot.lidee.iot.service.IDeviceDataSyncService;
import iot.lidee.iot.service.IDeviceMaintenanceRepairService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
public class DeviceMaintenanceRepairServiceImpl implements IDeviceMaintenanceRepairService {
private static final Logger logger = LoggerFactory.getLogger(DeviceMaintenanceRepairServiceImpl.class);
@Resource
private IDeviceDataLoadService loadService;
@Resource
private IDeviceDataSyncService syncService;
@Resource
private ByManagementJlMapper byManagementJlMapper;
@Resource
private DevGzbxWxgdMapper devGzbxWxgdMapper;
/**
* 同步设备维修保养信息
* 从源数据库加载设备维修保养相关数据并同步到主数据库,使用事务保证数据一致性
* 同步过程包括:加载源数据、同步到主库两个阶段
*/
@Override
@DSTransactional
public void syncDeviceMaintenanceRepairInfo() {
logger.info("开始同步设备维修保养信息");
try {
// 加载源数据
SyncDataContainer syncData = loadService.loadData();
// 同步数据到主数据库
syncService.syncDataToMaster(syncData);
logger.info("设备维修保养信息同步完成");
} catch (Exception e) {
logger.error("同步设备维修保养信息失败", e);
throw new RuntimeException("同步设备维修保养信息失败: " + e.getMessage(), e);
}
}
/**
* 查询保养记录列表
* 根据设备类型查询对应的保养记录信息
*
* @param devtype 设备类型
* @return 保养记录列表
*/
@Override
public List<ByManagementJl> maintenanceList(String devtype) {
return byManagementJlMapper.selectBygdByType(devtype);
}
/**
* 查询维修工单列表
* 根据设备类型查询对应的维修工单信息
*
* @param devtype 设备类型
* @return 维修工单列表
*/
@Override
public List<DevGzbxWxgdDO> repairList(String devtype) {
return devGzbxWxgdMapper.selectWxgdByType(devtype);
}
/**
* 查询设备列表
* 根据设备类型查询对应的设备信息
*
* @param devtype 设备类型
* @return 设备列表
*/
@Override
public List<Device> deviceList(String devtype) {
return devGzbxWxgdMapper.deviceList(devtype);
}
}

View File

@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="iot.lidee.iot.mapper.bygz.ByManagementJlMapper">
<select id="selectBygdByType" resultType="iot.lidee.iot.model.bygz.ByManagementJl">
SELECT
w.id,
w.order_id,
s.dev_name AS order_name,
w.equipment_info,
w.priority,
w.upkeep_level,
w.upkeep_time,
w.state,
w.executor,
w.ys_time,
w.tenant_id,
w.create_user,
w.create_time,
w.create_dept,
w.update_user,
w.update_time,
w.is_deleted,
w.equipment_code,
w.leader_user_id,
w.wbcjzr_user_id,
w.leader_ys_zt,
w.wbcjzr_ys_zt,
w.leader_ys_yj,
w.wbcjzr_ys_yj,
w.maintainer,
w.scheme_info
FROM
by_management_jl w
LEFT JOIN sys_device s ON s.id = w.equipment_info
WHERE
s.dev_type = #{devtype}
AND w.is_deleted = 0;
</select>
</mapper>

View File

@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="iot.lidee.iot.mapper.bygz.DevGzbxWxgdMapper">
<select id="selectWxgdByType" resultType="iot.lidee.iot.model.bygz.DevGzbxWxgdDO">
SELECT
w.id,
w.gzbx_id,
w.is_deleted,
w.update_time,
w.update_user,
w.create_dept,
w.create_time,
w.create_user,
w.create_user,
w.fault_type,
s.dev_name AS name,
w.dev_no,
w.dev_name,
w.priority,
w.type,
w.number,
w.fault_remark,
w.dev_type,
w.maintenance_person,
w.is_top,
w.is_filing,
w.reporter,
w.phone_number,
w.processing_status,
w.level,
w.completion_time,
w.acceptance_time,
w.create_user_name,
w.solution,
w.repair_date,
w.repair_time,
w.accessories,
w.leader_user_id,
w.assign_dept_id,
w.assign_dept_leader,
w.leader_user_yj,
w.leader_ys_zt,
w.assign_ys_zt,
w.leader_ys_yj,
w.assign_ys_yj
FROM
dev_gzbx_wxgd w
LEFT JOIN
sys_device s ON s.id = w.dev_name
WHERE
w.dev_type = #{devtype} AND w.is_deleted = 0
</select>
<select id="deviceList" resultType="iot.lidee.iot.domain.Device">
SELECT
*
FROM
iot_device w
WHERE
w.del_flag = 0
</select>
</mapper>