package cn.cecep.talroad.controller;

import cn.cecep.talroad.common.core.utils.poi.ExcelUtil;
import cn.cecep.talroad.common.core.web.controller.BasesController;
import cn.cecep.talroad.common.core.web.domain.AjaxResults;
import cn.cecep.talroad.common.log.annotation.Log;
import cn.cecep.talroad.common.log.enums.BusinessType;
import cn.cecep.talroad.domain.PcOutlet;
import cn.cecep.talroad.domain.SMainDynamicControl;
import cn.cecep.talroad.service.IPcOutletService;
import cn.cecep.talroad.service.ISMainDynamicControlService;
import cn.cecep.talroad.vo.query.SMainDynamicControlQuery;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.stream.Collectors;


/**
 * * 开发公司：中节能天融科技有限公司
 * 基本信息-废气、废水排口档案-动态管控信息Controller 控制层
 *
 * @author szhpt
 * @date 2023-02-02*/
@Api(tags = "基本信息-废气、废水排口档案-动态管控信息")
@RestController
@RequestMapping("/smainDynamicControl")
public class SMainDynamicControlController extends BasesController
{
    @Autowired
    private ISMainDynamicControlService sMainDynamicControlService;

    @Autowired
    private IPcOutletService pcOutletService;

    /**
     * 查询基本信息-废气、废水排口档案-动态管控信息列表
     */
    @ApiOperation(value = "查询基本信息-废气、废水排口档案-动态管控信息")
    @GetMapping("/list")
    public AjaxResults<IPage<SMainDynamicControl>> list(SMainDynamicControlQuery sMainDynamicControl)
    {
        Page<SMainDynamicControl> page = new Page<>(sMainDynamicControl.getPageNum(), sMainDynamicControl.getPageSize());

        List<PcOutlet> pcOutlets = pcOutletService.list(new QueryWrapper<PcOutlet>().eq("pollutant_type","4").eq("parent_outlet_id", sMainDynamicControl.getOutletId()));
        List<String> outLetIds = pcOutlets.stream().map(PcOutlet::getId).collect(Collectors.toList());
        if (outLetIds.isEmpty()) {
            return AjaxResults.success(page);
        }
        page = sMainDynamicControlService.page(page, new QueryWrapper<SMainDynamicControl>().in("outlet_id", outLetIds).orderByAsc("outlet_id", "id"));
        return AjaxResults.success(page);
    }
    

}
