# HotelKpiCommentServiceImpl.java

    package cloud.wconnect.workperformance.service.hotelkpi.impl.old;

    import cloud.wconnect.commonlib.component.BeanMapper;
    import cloud.wconnect.commonlib.pojo.dto.ListPagedDTO;
    import cloud.wconnect.commonlib.pojo.dto.PropertyDTO;
    import cloud.wconnect.commonlib.pojo.dto.UserDTO;
    import cloud.wconnect.commonlib.service.UserInternalService;
    import cloud.wconnect.workperformance.entity.hotelkpi.old.HotelKpiComment;
    import cloud.wconnect.workperformance.mapper.hotelkpi.old.HotelKpiCommentMapper;
    import cloud.wconnect.workperformance.pojo.dto.hotelkpi.old.kpi.HotelKpiCommentDTO;
    import cloud.wconnect.workperformance.pojo.query.hotelkpi.old.HotelKpiCommentQuery;
    import cloud.wconnect.workperformance.service.hotelkpi.old.IHotelKpiCommentService;
    import com.baomidou.dynamic.datasource.annotation.DS;
    import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
    import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
    import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
    import org.springframework.stereotype.Service;

    import jakarta.annotation.Resource;
    import java.util.List;
    import java.util.Map;
    import java.util.Set;
    import java.util.stream.Collectors;

    /**
     * <p>
     * Hotel KPI Comment 服务实现类
     * </p>
     *
     * @author zc
     * @since 2024-06-24
     */
    @Service("hotelKpiCommentServiceImpl_old")
    @DS("work_performance")
    public class HotelKpiCommentServiceImpl extends ServiceImpl<HotelKpiCommentMapper, HotelKpiComment> implements IHotelKpiCommentService {

        @Resource
        private UserInternalService userInternalService;
        @Resource
        private BeanMapper beanMapper;

        /**
         * 获取酒店KPI评论
         *
         * @param propertyDTO 资产
         * @param date        日期(yyyyMMdd)
         * @param query       查询条件
         * @return HotelKpiCommentDTO 集合
         * @author zc
         * @date 2024/6/27
         */
        @Override
        public ListPagedDTO<HotelKpiCommentDTO> list(PropertyDTO propertyDTO, long date, HotelKpiCommentQuery query) {
            Page<HotelKpiComment> commentPage = page(new Page<>(query.getPage(), query.getSize()), new LambdaQueryWrapper<HotelKpiComment>()
                    .eq(HotelKpiComment::getWeek, date)
                    .eq(HotelKpiComment::getPropertyId, propertyDTO.getId())
                    .orderByDesc(HotelKpiComment::getUpdatedTime));

            List<HotelKpiComment> commentList = commentPage.getRecords();

            // 获取用户信息
            Set<Integer> userIds = commentList.stream().map(HotelKpiComment::getUpdatedBy).collect(Collectors.toSet());
            Map<Integer, UserDTO> userId2User = userInternalService.getUserMapByIds(propertyDTO.getTenantId(), userIds);

            return new ListPagedDTO<>(commentPage.getTotal(), beanMapper.mapList(commentList, HotelKpiCommentDTO.class, (comment, dto) -> {
                UserDTO userDTO = userId2User.getOrDefault(comment.getUpdatedBy(), new UserDTO());
                dto.setUpdatedName(userDTO.getName());
                dto.setAvatar(userDTO.getAvatar());
            }));
        }
    }