# ScheduleBeoServiceImpl.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.UserDTO;
    import cloud.wconnect.commonlib.redis.PropertyI18nRedisService;
    import cloud.wconnect.commonlib.service.UserInternalService;
    import cloud.wconnect.commonlib.util.DateTimeUtils;
    import cloud.wconnect.commonlib.util.I18nMessageUtils;
    import cloud.wconnect.workperformance.entity.schedule.ScheduleBeo;
    import cloud.wconnect.workperformance.mapper.schedule.ScheduleBeoMapper;
    import cloud.wconnect.workperformance.pojo.dto.schedule.ScheduleBeoDTO;
    import cloud.wconnect.workperformance.pojo.query.schedule.ScheduleQuery;
    import cloud.wconnect.workperformance.service.schedule.IScheduleBeoService;
    import com.baomidou.dynamic.datasource.annotation.DS;
    import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
    import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
    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.Comparator;
    import java.util.List;
    import java.util.Map;
    import java.util.stream.Collectors;

    /**
     * <p>
     * 宴会编排表 服务实现类
     * </p>
     *
     * @author yyt
     * @since 2023-06-28
     */
    @Service
    @DS("work_performance")
    public class ScheduleBeoServiceImpl extends ServiceImpl<ScheduleBeoMapper, ScheduleBeo> implements IScheduleBeoService {

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

        /**
         * 获取 beo
         *
         * @param id beo id
         * @return beo
         * @author yyt
         * @date 2023/6/29
         */
        @Override
        public ScheduleBeo getBeoById(int id) {
            ScheduleBeo scheduleBeo = getById(id);
            if (scheduleBeo == null) {
                throw new BadRequestException(CommonErrorI18nConstant.DATA_NOT_EXIST,
                        i18nMessageUtils.getErrorParamMapNotNeedTranslate("beo"),
                        BaseErrorCodeEnum.DATA_VALIDATION_ERROR.getCode(), "the beo is not found;id:" + id);
            }
            return scheduleBeo;
        }

        /**
         * 查询 beo
         *
         * @param propertyId 资产 id
         * @param query      查询条件
         * @return beo
         * @author yyt
         * @date 2023/6/29
         */
        @Override
        public List<ScheduleBeo> list(Integer propertyId, ScheduleQuery query) {
            return list(new QueryWrapper<ScheduleBeo>().lambda()
                    .eq(ScheduleBeo::getPropertyId, propertyId)
                    .between(ScheduleBeo::getTheDate, query.getStartDate(), query.getEndDate()));
        }

        /**
         * 查询 beo
         *
         * @param propertyId    资产 id
         * @param scheduleQuery 查询条件
         * @return beo
         * @author yyt
         * @date 2025/12/31
         **/
        @Override
        public List<ScheduleBeoDTO> listDTO(int propertyId, ScheduleQuery scheduleQuery) {
            List<ScheduleBeo> beos = list(propertyId, scheduleQuery);
            beos.sort(Comparator.comparing(ScheduleBeo::getTheDate));

            Map<Integer, UserDTO> userById = Collections.emptyMap();
            if (CollectionUtils.isNotEmpty(beos)) {
                List<Integer> userIds = beos.stream().map(ScheduleBeo::getUpdatedBy).distinct().collect(Collectors.toList());

                userById = userInternalService.getUsers(propertyI18nRedisService.get(propertyId).getTenantId(), userIds)
                        .stream().collect(Collectors.toMap(UserDTO::getId, v -> v));
            }

            Map<Integer, UserDTO> finalUserById = userById;
            return beanMapper.mapList(beos, ScheduleBeoDTO.class, item -> {
                UserDTO userDTO = finalUserById.get(item.getUpdatedBy());
                item.setUpdatedName(userDTO.getName());
                item.setAvatar(userDTO.getAvatar());
            });
        }

        /**
         * 保存 beo
         *
         * @param propertyId     资产 id
         * @param scheduleBeoDTO beo
         * @param userId         操作人
         * @author yyt
         * @date 2023/6/29
         */
        @Override
        public void save(Integer propertyId, ScheduleBeoDTO scheduleBeoDTO, int userId) {
            ScheduleBeo scheduleBeo = new ScheduleBeo(null, propertyId, scheduleBeoDTO.getTheDate(),
                    scheduleBeoDTO.getContent(), userId, DateTimeUtils.nowTimestamp());
            save(scheduleBeo);
        }

        /**
         * 更新 beo
         *
         * @param id             beo id
         * @param scheduleBeoDto beo
         * @param userId         操作人
         * @author yyt
         * @date 2025/12/31
         */
        @Override
        public void updateBeo(int id, ScheduleBeoDTO scheduleBeoDto, int userId) {
            update(new UpdateWrapper<ScheduleBeo>().lambda()
                    .eq(ScheduleBeo::getId, id)
                    .set(ScheduleBeo::getContent, scheduleBeoDto.getContent())
                    .set(ScheduleBeo::getUpdatedBy, userId)
                    .set(ScheduleBeo::getUpdatedTime, DateTimeUtils.nowTimestamp()));
        }

        /**
         * 删除 beo
         *
         * @param id beo id
         * @author yyt
         * @date 2025/12/31
         */
        @Override
        public void delete(int id) {
            removeById(id);
        }

    }