package com.ruoyi.ss.feeRule.service.impl;

import com.ruoyi.common.utils.collection.CollectionUtils;
import com.ruoyi.ss.feeRule.domain.FeeRuleVO;
import com.ruoyi.ss.feeRule.service.IFeeRuleAssembler;
import com.ruoyi.ss.room.domain.RoomVO;
import com.ruoyi.ss.room.service.IRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author qzz
 * 2025/1/20
 */
@Service
public class FeeRuleAssemblerImpl implements IFeeRuleAssembler {


    @Autowired
    private IRoomService roomService;

    /**
     * 拼接房间信息
     * @param list 店铺列表
     */
    @Override
    public void assembleRoomInfo(List<FeeRuleVO> list) {
        if (CollectionUtils.isEmptyElement(list)) {
            return;
        }
        list.forEach(vo -> {
            List<RoomVO> rooms = roomService.selectIsExistRule(vo.getRuleId());
            if (rooms != null && !rooms.isEmpty()) {
                // 将RoomVO列表映射为房间名称列表
                List<String> roomNamesList = rooms.stream()
                        .map(RoomVO::getRoomName)
                        .collect(Collectors.toList());
                // 使用String.join将列表用逗号连接
                vo.setRoomNames(String.join(",", roomNamesList));
                // 将RoomVO列表映射为房间名称列表
                List<Long> roomIds = rooms.stream()
                        .map(RoomVO::getRoomId)
                        .collect(Collectors.toList());
                vo.setRoomIds(roomIds);
            } else {
                // 如果没有找到任何房间，可能需要设置roomNames为空字符串或其他默认值
                vo.setRoomNames("");
                vo.setRoomIds(null);
            }
        });
    }
}
