# ScheduleImportEmployeeFilterConfigServiceImpl.java

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

    import cloud.wconnect.commonlib.component.BeanMapper;
    import cloud.wconnect.commonlib.cons.BaseErrorCodeEnum;
    import cloud.wconnect.commonlib.cons.CommonErrorI18nConstant;
    import cloud.wconnect.commonlib.exception.BadRequestException;
    import cloud.wconnect.commonlib.pojo.dto.ListPagedDTO;
    import cloud.wconnect.commonlib.util.DateTimeUtils;
    import cloud.wconnect.workperformance.entity.schedule.ScheduleImportEmployeeFilterConfig;
    import cloud.wconnect.workperformance.mapper.schedule.ScheduleImportEmployeeFilterConfigMapper;
    import cloud.wconnect.workperformance.pojo.dto.schedule.ScheduleImportEmployeeFilterConfigDTO;
    import cloud.wconnect.workperformance.pojo.query.schedule.ImportEmployeeFilterConfigQuery;
    import cloud.wconnect.workperformance.service.schedule.IScheduleImportEmployeeFilterConfigService;
    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.lang3.StringUtils;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;

    import jakarta.annotation.Nullable;
    import java.text.MessageFormat;
    import java.util.List;
    import java.util.Objects;

    /**
     * <p>
     *  服务实现类
     * </p>
     *
     * @author yyt
     * @since 2023-07-11
     */
    @Service
    @DS("work_performance")
    public class ScheduleImportEmployeeFilterConfigServiceImpl extends ServiceImpl<ScheduleImportEmployeeFilterConfigMapper, ScheduleImportEmployeeFilterConfig> implements IScheduleImportEmployeeFilterConfigService {

        @Autowired
        private BeanMapper beanMapper;

        /**
         * 校验存在
         *
         * @param propertyId 资产 id
         * @param positionId position id
         * @param id         排除自身
         * @author yyt
         * @date 2023/7/11
         */
        @Override
        public void checkExist(Integer propertyId, String positionId, @Nullable Integer id) {
            ScheduleImportEmployeeFilterConfig config = getOne(new QueryWrapper<ScheduleImportEmployeeFilterConfig>().lambda()
                    .eq(ScheduleImportEmployeeFilterConfig::getPropertyId, propertyId)
                    .eq(ScheduleImportEmployeeFilterConfig::getPositionId, positionId)
                    .ne(Objects.nonNull(id), ScheduleImportEmployeeFilterConfig::getId, id));
            if (Objects.nonNull(config)) {
                throw new BadRequestException(CommonErrorI18nConstant.DATA_EXISTED,
                        BaseErrorCodeEnum.DATA_VALIDATION_ERROR.getCode(),
                        MessageFormat.format("the scheduleImportEmployeeFilterConfig is existing;positionId:{0},id:{1}", positionId, id));
            }
        }

        /**
         * 校验存在
         *
         * @param id 配置 id
         * @return 配置信息
         * @author yyt
         * @date 2023/7/11
         */
        @Override
        public ScheduleImportEmployeeFilterConfig checkExist(int id) {
            ScheduleImportEmployeeFilterConfig config = getById(id);
            if (Objects.isNull(config)) {
                throw new BadRequestException(CommonErrorI18nConstant.DATA_NOT_FOUND,
                        BaseErrorCodeEnum.DATA_VALIDATION_ERROR.getCode(), "the scheduleImportEmployeeFilterConfig is not found;id:" + id);
            }
            return config;
        }

        /**
         * 分页查询数据
         *
         * @param propertyId 资产 id
         * @param query      查询条件
         * @return 配置规则
         * @author yyt
         * @date 2024/11/22
         **/
        @Override
        public Page<ScheduleImportEmployeeFilterConfig> listPage(Integer propertyId, ImportEmployeeFilterConfigQuery query) {
            return page(new Page<>(query.getPage(), query.getSize()), new QueryWrapper<ScheduleImportEmployeeFilterConfig>().lambda()
                    .eq(ScheduleImportEmployeeFilterConfig::getPropertyId, propertyId)
                    .like(StringUtils.isNotEmpty(query.getPositionId()), ScheduleImportEmployeeFilterConfig::getPositionId,
                            query.getPositionId())
                    .orderByDesc(ScheduleImportEmployeeFilterConfig::getId));
        }

        /**
         * 查询数据
         *
         * @param propertyId 资产 id
         * @param query      查询条件
         * @return 配置规则
         * @author yyt
         * @date 2024/11/22
         **/
        @Override
        public List<ScheduleImportEmployeeFilterConfig> list(Integer propertyId, ImportEmployeeFilterConfigQuery query) {
            return list(new QueryWrapper<ScheduleImportEmployeeFilterConfig>().lambda()
                    .eq(ScheduleImportEmployeeFilterConfig::getPropertyId, propertyId)
                    .eq(ScheduleImportEmployeeFilterConfig::getPositionId, query.getPositionId()));
        }

        /**
         * 删除配置
         *
         * @param id 配置 id
         * @author yyt
         * @date 2024/11/22
         **/
        @Override
        public void delete(int id) {
            removeById(id);
        }

        /**
         * 获取配置列表信息
         *
         * @param propertyId 资产 id
         * @param query      查询条件
         * @return 配置列表信息
         * @author yyt
         * @date 2025/12/31
         **/
        @Override
        public ListPagedDTO<ScheduleImportEmployeeFilterConfigDTO> listDTO(Integer propertyId, ImportEmployeeFilterConfigQuery query) {
            long total;
            List<ScheduleImportEmployeeFilterConfig> list;
            if (Objects.nonNull(query.getPage()) && Objects.nonNull(query.getSize())) {
                Page<ScheduleImportEmployeeFilterConfig> page = listPage(propertyId, query);
                list = page.getRecords();
                total = page.getTotal();
            } else {
                list = list(propertyId, query);
                total = list.size();
            }

            return new ListPagedDTO<>(total, beanMapper.mapList(list, ScheduleImportEmployeeFilterConfigDTO.class));
        }

        /**
         * 新增配置
         *
         * @param propertyId      资产 id
         * @param filterConfigDTO 配置信息
         * @param userId          操作人
         * @author yyt
         * @date 2025/12/31
         **/
        @Override
        public void save(Integer propertyId, ScheduleImportEmployeeFilterConfigDTO filterConfigDTO, int userId) {
            save(new ScheduleImportEmployeeFilterConfig()
                    .setPropertyId(propertyId)
                    .setPositionId(filterConfigDTO.getPositionId())
                    .setUpdatedBy(userId)
                    .setUpdatedTime(DateTimeUtils.nowTimestamp()));
        }

        /**
         * 修改配置
         *
         * @param id              配置 id
         * @param filterConfigDTO 配置信息
         * @param userId          操作人
         * @author yyt
         * @date 2025/12/31
         **/
        @Override
        public void update(int id, ScheduleImportEmployeeFilterConfigDTO filterConfigDTO, int userId) {
            updateById(new ScheduleImportEmployeeFilterConfig()
                    .setId(id)
                    .setPositionId(filterConfigDTO.getPositionId())
                    .setUpdatedBy(userId)
                    .setUpdatedTime(DateTimeUtils.nowTimestamp()));
        }

    }