# ScheduleInfoImportLogServiceImpl.java

    package cloud.wconnect.workperformance.service.schedule.impl;

    import cloud.wconnect.commonlib.component.BeanMapper;
    import cloud.wconnect.commonlib.pojo.dto.ListPagedDTO;
    import cloud.wconnect.commonlib.redis.PropertyI18nRedisService;
    import cloud.wconnect.commonlib.service.UserInternalService;
    import cloud.wconnect.workperformance.entity.schedule.ScheduleInfoImportLog;
    import cloud.wconnect.workperformance.mapper.schedule.ScheduleInfoImportLogMapper;
    import cloud.wconnect.workperformance.pojo.dto.schedule.ScheduleImportLogDTO;
    import cloud.wconnect.workperformance.pojo.query.schedule.ImportScheduleLogQuery;
    import cloud.wconnect.workperformance.service.schedule.IScheduleInfoImportLogService;
    import com.baomidou.dynamic.datasource.annotation.DS;
    import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
    import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
    import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
    import org.apache.commons.collections.CollectionUtils;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;

    import java.util.Collections;
    import java.util.Map;
    import java.util.Objects;
    import java.util.Set;
    import java.util.stream.Collectors;

    /**
     * <p>
     * 排版导入记录 服务实现类
     * </p>
     *
     * @author yyt
     * @since 2023-06-28
     */
    @Service
    @DS("work_performance")
    public class ScheduleInfoImportLogServiceImpl extends ServiceImpl<ScheduleInfoImportLogMapper, ScheduleInfoImportLog> implements IScheduleInfoImportLogService {

        @Autowired
        private PropertyI18nRedisService propertyI18nRedisService;
        @Autowired
        private UserInternalService userInternalService;
        @Autowired
        private BeanMapper beanMapper;

        /**
         * 分页查询数据
         *
         * @param propertyId 资产 id
         * @param query      查询条件
         * @return 导入记录
         * @author yyt
         * @date 2024/11/22
         **/
        @Override
        public Page<ScheduleInfoImportLog> listPage(Integer propertyId, ImportScheduleLogQuery query) {
            return page(new Page<>(query.getPage(), query.getSize()), new QueryWrapper<ScheduleInfoImportLog>().lambda()
                    .eq(ScheduleInfoImportLog::getPropertyId, propertyId)
                    .in(CollectionUtils.isNotEmpty(query.getStatus()), ScheduleInfoImportLog::getStatus, query.getStatus())
                    .between(Objects.nonNull(query.getStartFromDataDate()) && Objects.nonNull(query.getStartToDataDate()),
                            ScheduleInfoImportLog::getFromDate, query.getStartFromDataDate(), query.getStartToDataDate())
                    .between(Objects.nonNull(query.getEndFromDataDate()) && Objects.nonNull(query.getEndToDataDate()),
                            ScheduleInfoImportLog::getToDate, query.getEndFromDataDate(), query.getEndToDataDate())
                    .between(Objects.nonNull(query.getStartOperationDate()) && Objects.nonNull(query.getEndOperationDate()),
                            ScheduleInfoImportLog::getCreatedTime, query.getStartOperationDate(), query.getEndOperationDate())
                    .orderByDesc(ScheduleInfoImportLog::getCreatedTime));
        }

        /**
         * 获取导入记录
         *
         * @param propertyId 资产 id
         * @param query      查询条件
         * @return 导入记录
         * @author yyt
         * @date 2025/12/31
         **/
        @Override
        public ListPagedDTO<ScheduleImportLogDTO> listScheduleImportLog(Integer propertyId, ImportScheduleLogQuery query) {
            Page<ScheduleInfoImportLog> page = listPage(propertyId, query);

            Map<Integer, String> userNameById = Collections.emptyMap();
            if (CollectionUtils.isNotEmpty(page.getRecords())) {
                Set<Integer> userIds = page.getRecords().stream().map(ScheduleInfoImportLog::getCreatedBy)
                        .collect(Collectors.toSet());
                userNameById = userInternalService.getNameMapByIds(propertyI18nRedisService.get(propertyId).getTenantId(), userIds);
            }

            Map<Integer, String> finalUserNameById = userNameById;
            return new ListPagedDTO<>(page.getTotal(), beanMapper.mapList(page.getRecords(), ScheduleImportLogDTO.class,
                    item -> item.setCreatedName(finalUserNameById.get(item.getCreatedBy()))));
        }

    }