package cn.cecep.talroad.controller;

import cn.cecep.talroad.common.core.exception.CommonException;
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.common.security.annotation.RequiresPermissions;
import cn.cecep.talroad.domain.BMainProductionInorgGas;
import cn.cecep.talroad.service.IBMainProductionInorgGasService;
import cn.cecep.talroad.service.IProductionManageService;
import cn.cecep.talroad.vo.BMainProductionInorgGasVo;
import cn.cecep.talroad.vo.query.BMainProductionInorgGasQuery;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
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.*;

import javax.servlet.http.HttpServletResponse;
import java.security.InvalidParameterException;
import java.util.Arrays;
import java.util.List;


/**
 * * 开发公司：中节能天融科技有限公司
 * 废气无组织排放产治排信息Controller 控制层
 *
 * @author szhpt
 * @date 2023-02-08*/
@Api(tags = "废气无组织排放产治排信息")
@RestController
@RequestMapping("/bmainProductionInorgGas")
public class BMainProductionInorgGasController extends BasesController
{
    @Autowired
    private IBMainProductionInorgGasService bMainProductionInorgGasService;

    /**
     * 查询废气无组织排放产治排信息列表
     */
    @ApiOperation(value = "查询废气无组织排放产治排信息")
    @GetMapping("/list")
    public AjaxResults<IPage<BMainProductionInorgGas>> list(BMainProductionInorgGasQuery bMainProductionInorgGas)
    {
        Page<BMainProductionInorgGas> page = new Page<>(bMainProductionInorgGas.getPageNum(), bMainProductionInorgGas.getPageSize());
        IPage<BMainProductionInorgGas> list = bMainProductionInorgGasService.page(page, BMainProductionInorgGasQuery.createLambdaQueryWrapper(bMainProductionInorgGas));
        return AjaxResults.success(list);
    }
    

    /**
     * 导出废气无组织排放产治排信息列表
     */
    @ApiOperation(value = "导出废气无组织排放产治排信息")
    @Log(title = "废气无组织排放产治排信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response,@RequestBody BMainProductionInorgGas bMainProductionInorgGas)
    {
        List<BMainProductionInorgGas> list = bMainProductionInorgGasService.selectBMainProductionInorgGasList(bMainProductionInorgGas);
        ExcelUtil<BMainProductionInorgGas> util = new ExcelUtil<>(BMainProductionInorgGas.class);
        util.exportExcel(response, list, "废气无组织排放产治排信息数据");
    }

    /**
     * 获取废气无组织排放产治排信息详细信息
     */
    @ApiOperation(value = "获取废气无组织排放产治排信息详细信息")
    @PostMapping(value = "/{id}")
    public AjaxResults<BMainProductionInorgGas> getInfo(@PathVariable("id") Integer id) {
        return AjaxResults.success(bMainProductionInorgGasService.getById(id));
    }
    /**
     * 新增废气无组织排放产治排信息
     */
    @ApiOperation(value = "新增废气无组织排放产治排信息")
    @Log(title = "废气无组织排放产治排信息", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public AjaxResults<Boolean> add(@RequestBody BMainProductionInorgGas bMainProductionInorgGas) {
        return toAjax(bMainProductionInorgGasService.save(bMainProductionInorgGas));
    }
    /**
     * 修改废气无组织排放产治排信息
     */
    @ApiOperation(value = "修改废气无组织排放产治排信息")
    @Log(title = "废气无组织排放产治排信息", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/edit")
    public AjaxResults<Boolean> edit(@RequestBody BMainProductionInorgGasVo bMainProductionInorgGasVo) {
        if(ObjectUtil.isEmpty(bMainProductionInorgGasVo)){
            throw new InvalidParameterException("参数为空");
        }
        if(ObjectUtil.isEmpty(bMainProductionInorgGasVo.getId())){
            throw new InvalidParameterException("参数id为空");
        }
        BMainProductionInorgGas bMainProductionInorgGas = bMainProductionInorgGasService.getById(bMainProductionInorgGasVo.getId());
        if(ObjectUtil.isEmpty(bMainProductionInorgGas)){
            throw new CommonException(StrUtil.format("根据id{}查询不到数据", bMainProductionInorgGasVo.getId()));
        }
        //赋值
        BeanUtil.copyProperties(bMainProductionInorgGasVo,bMainProductionInorgGas);
        return toAjax(bMainProductionInorgGasService.saveOrUpdate(bMainProductionInorgGas));
    }

    /**
     * 删除废气无组织排放产治排信息
     */
    @ApiOperation(value = "删除废气无组织排放产治排信息")
    @RequiresPermissions("talroad:bmainProductionInorgGas:remove")
    @Log(title = "废气无组织排放产治排信息", businessType = BusinessType.DELETE)
    @PostMapping("/{ids}")
    public AjaxResults<Boolean> remove(@PathVariable String[] ids) {
        return toAjax(bMainProductionInorgGasService.removeByIds(Arrays.asList(ids)));
    }

    @ApiOperation(value = "获取弹框数据（数据趋势、视频监控）")
    @GetMapping("/frameData")
    public AjaxResults<IProductionManageService.FrameDataVo> frameData(
            @RequestParam("id") String id,
            @RequestParam("startTime") String startTime,
            @RequestParam("endTime") String endTime,
            @RequestParam("pageNum") Long pageNum,
            @RequestParam("pageSize") Long pageSize
    ) {
        IProductionManageService.FrameDataVo data = bMainProductionInorgGasService.getFrameData(id, startTime, endTime, pageNum, pageSize);
        return AjaxResults.success(data);
    }
}
