package cn.cecep.talroad.controller.analysis;

import cn.cecep.talroad.common.core.exception.CommonException;
import cn.cecep.talroad.common.core.utils.poi.ExcelUtil;
import cn.cecep.talroad.common.core.web.domain.AjaxResults;
import cn.cecep.talroad.domain.analysis.SRaRealTimeAnalysicComsitMonitor;
import cn.cecep.talroad.service.analysis.ISRaRealTimeAnalysicComsitMonitorService;
import cn.cecep.talroad.vo.analysis.SRaRealTimeAnalysicComsitMonitorVo;
import cn.cecep.talroad.vo.query.analysis.SRaRealTimeAnalysicComsitMonitorQuery;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;

import cn.hutool.core.util.StrUtil;
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 java.math.BigInteger;
import java.security.InvalidParameterException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Arrays;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
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.common.core.web.controller.BasesController;


/**
 * * 开发公司：中节能天融科技有限公司
 * 关联分析系统-企业生产过程分析-监测点位对比分析-分组关联点位Controller 控制层
 *
 * @author szhpt
 * @date 2023-07-14*/
@Api(tags = "关联分析系统-企业生产过程分析-监测点位对比分析-分组关联点位")
@RestController
@RequestMapping("/comsit/monitor")
public class SRaRealTimeAnalysicComsitMonitorController extends BasesController
{
    @Autowired
    private ISRaRealTimeAnalysicComsitMonitorService sRaRealTimeAnalysicComsitMonitorService;

    /**
     * 查询关联分析系统-企业生产过程分析-监测点位对比分析-分组关联点位列表
     */
    @ApiOperation(value = "查询关联分析系统-企业生产过程分析-监测点位对比分析-分组关联点位")
    @GetMapping("/list")
    public AjaxResults<IPage<SRaRealTimeAnalysicComsitMonitor>> list(SRaRealTimeAnalysicComsitMonitorQuery sRaRealTimeAnalysicComsitMonitor)
    {
        Page<SRaRealTimeAnalysicComsitMonitor> page = new Page<>(sRaRealTimeAnalysicComsitMonitor.getPageNum(), sRaRealTimeAnalysicComsitMonitor.getPageSize());
        IPage<SRaRealTimeAnalysicComsitMonitor> list = sRaRealTimeAnalysicComsitMonitorService.page(page, SRaRealTimeAnalysicComsitMonitorQuery.createLambdaQueryWrapper(sRaRealTimeAnalysicComsitMonitor));
        return AjaxResults.success(list);
    }
    

    /**
     * 导出关联分析系统-企业生产过程分析-监测点位对比分析-分组关联点位列表
     */
    @ApiOperation(value = "导出关联分析系统-企业生产过程分析-监测点位对比分析-分组关联点位")
    @Log(title = "关联分析系统-企业生产过程分析-监测点位对比分析-分组关联点位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SRaRealTimeAnalysicComsitMonitor sRaRealTimeAnalysicComsitMonitor)
    {
        List<SRaRealTimeAnalysicComsitMonitor> list = sRaRealTimeAnalysicComsitMonitorService.selectSRaRealTimeAnalysicComsitMonitorList(sRaRealTimeAnalysicComsitMonitor);
        ExcelUtil<SRaRealTimeAnalysicComsitMonitor> util = new ExcelUtil<SRaRealTimeAnalysicComsitMonitor>(SRaRealTimeAnalysicComsitMonitor.class);
        util.exportExcel(response, list, "关联分析系统-企业生产过程分析-监测点位对比分析-分组关联点位数据");
    }

    /**
     * 新增关联分析系统-企业生产过程分析-监测点位对比分析-分组关联点位
     */
    @ApiOperation(value = "监测点位对比分析-添加关联点位")
    @Log(title = "关联分析系统-企业生产过程分析-监测点位对比分析-分组关联点位", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public AjaxResults<Boolean> add(@RequestBody SRaRealTimeAnalysicComsitMonitor sRaRealTimeAnalysicComsitMonitor) {
        return  sRaRealTimeAnalysicComsitMonitorService.addComsitMonitor(sRaRealTimeAnalysicComsitMonitor);
    }
    /**
     * 修改关联分析系统-企业生产过程分析-监测点位对比分析-分组关联点位
     */
    @ApiOperation(value = "修改关联分析系统-企业生产过程分析-监测点位对比分析-分组关联点位")
    @Log(title = "关联分析系统-企业生产过程分析-监测点位对比分析-分组关联点位", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/edit")
    public AjaxResults<Boolean> edit(@RequestBody SRaRealTimeAnalysicComsitMonitorVo sRaRealTimeAnalysicComsitMonitorVo) {
        if(ObjectUtil.isEmpty(sRaRealTimeAnalysicComsitMonitorVo)){
            throw new InvalidParameterException("参数为空");
        }
        if(ObjectUtil.isEmpty(sRaRealTimeAnalysicComsitMonitorVo.getDataId())){
            throw new InvalidParameterException("参数id为空");
        }
        SRaRealTimeAnalysicComsitMonitor sRaRealTimeAnalysicComsitMonitor = sRaRealTimeAnalysicComsitMonitorService.getById(sRaRealTimeAnalysicComsitMonitorVo.getDataId());
        if(ObjectUtil.isEmpty(sRaRealTimeAnalysicComsitMonitor)){
            throw new CommonException(StrUtil.format("根据id{}查询不到数据", sRaRealTimeAnalysicComsitMonitorVo.getDataId()));
        }
        //赋值
        BeanUtil.copyProperties(sRaRealTimeAnalysicComsitMonitorVo,sRaRealTimeAnalysicComsitMonitor);
        return toAjax(sRaRealTimeAnalysicComsitMonitorService.saveOrUpdate(sRaRealTimeAnalysicComsitMonitor));
    }

    /**
     * 删除关联分析系统-企业生产过程分析-监测点位对比分析-分组关联点位
     */
    @ApiOperation(value = "监测点位对比分析-删除分组关联点位")
    @Log(title = "关联分析系统-企业生产过程分析-监测点位对比分析-分组关联点位", businessType = BusinessType.DELETE)
    @PostMapping("/{dataIds}")
    public AjaxResults<Boolean> remove(@PathVariable BigInteger dataIds) {
        return AjaxResults.success(sRaRealTimeAnalysicComsitMonitorService.removeById(dataIds));
    }
}
