package com.ruoyi.monitoring.controller;

import com.ruoyi.monitoring.domain.CmcChannel;
import com.ruoyi.monitoring.service.ICmcChannelService;
import com.ruoyi.common.web.controller.BaseController;
import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Get;
import org.noear.solon.annotation.Inject;
import org.noear.solon.annotation.Mapping;

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

/**
 * 监测点位
 * @author cmc
 */
@Controller
@Mapping("monitoring/channel")
public class CmcChannelController extends BaseController {

    @Inject
    ICmcChannelService cmcChannelService;

    /**
     * 查询监测点位列表
     */
    @Get
    @Mapping("list")
    public List<CmcChannel> list(CmcChannel cmcChannel) {
        return cmcChannelService.listChannel(cmcChannel);
    }

    /**
     * 查询监测点位位置列表
     */
    @Get
    @Mapping("channelInfoList")
    public List<String> channelInfoList() {
        List<String> channelInfoList = new ArrayList<>();
        List<String> multiChannelInfoList = new ArrayList<>();
        List<CmcChannel> cmcChannelList = cmcChannelService.listChannel(new CmcChannel());
        cmcChannelList.forEach(channel -> {
            if (channel.getInfo() != null && !channel.getInfo().equals("")) {
                if (!channel.getInfo().contains("-"))
                    channelInfoList.add(channel.getInfo());
                else
                    multiChannelInfoList.add(channel.getInfo().split("-")[0]);
            }
        });
        channelInfoList.addAll(multiChannelInfoList.stream().distinct().collect(Collectors.toList()));
        return channelInfoList;
    }

}