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;
    }
}
