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.SRaRealTimeAnalysicComsitSt;
import cn.cecep.talroad.domain.analysis.SRaRealTimeAnalysicComsit;
import cn.cecep.talroad.service.SRaRealTimeAnalysicComsitStService;
import cn.cecep.talroad.service.analysis.ISRaRealTimeAnalysicComsitService;
import cn.cecep.talroad.vo.EChartsVO;
import cn.cecep.talroad.vo.analysis.SRaRealTimeAnalysicComsitMonitorVo;
import cn.cecep.talroad.vo.analysis.SRaRealTimeAnalysicComsitVo;
import cn.cecep.talroad.vo.query.analysis.SRaRealTimeAnalysicComsitMonitorQuery;
import cn.cecep.talroad.vo.query.analysis.SRaRealTimeAnalysicComsitQuery;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.IdUtil;
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.Date;
import java.util.List;
import java.util.Arrays;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
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")
public class SRaRealTimeAnalysicComsitController extends BasesController
{
    @Autowired
    private ISRaRealTimeAnalysicComsitService sRaRealTimeAnalysicComsitService;

    @Autowired
    private SRaRealTimeAnalysicComsitStService sRaRealTimeAnalysicComsitStService;

    /**
     * 查询关联分析系统-企业生产过程分析-监测点位对比分析-分组列表
     */
    @ApiOperation(value = "查询监测点位对比分析-分组维护")
    @GetMapping("/list")
    public AjaxResults<IPage<SRaRealTimeAnalysicComsit>> list(SRaRealTimeAnalysicComsitQuery sRaRealTimeAnalysicComsit)
    {
        IPage<SRaRealTimeAnalysicComsit> list = sRaRealTimeAnalysicComsitService.selectSRaRealTimeAnalysicComsitListBys(sRaRealTimeAnalysicComsit);
        return AjaxResults.success(list);
    }

    @ApiOperation(value = "编辑查询监测点位对比分析-分组维护")
    @GetMapping("/editList")
    public AjaxResults<IPage<SRaRealTimeAnalysicComsitMonitorVo>> editList(SRaRealTimeAnalysicComsitMonitorVo sRaRealTimeAnalysicComsit)
    {
        IPage<SRaRealTimeAnalysicComsitMonitorVo> list = sRaRealTimeAnalysicComsitService.selectSRaRealTimeAnalysicComsitListBy(sRaRealTimeAnalysicComsit);
        return AjaxResults.success(list);
    }
    @ApiOperation(value = "监测点位名称下拉框")
    @GetMapping("/editListDropdown")
    public AjaxResults<List<Map<String, Object>>> editListDropdown(SRaRealTimeAnalysicComsitMonitorVo sRaRealTimeAnalysicComsit)
    {
        List<Map<String, Object>> list = sRaRealTimeAnalysicComsitService.editListDropdown(sRaRealTimeAnalysicComsit);
        return AjaxResults.success(list);
    }

    @ApiOperation(value = "查询监测点位对比分析-分组查看详情异常")
    @GetMapping("/abnormalList")
    public AjaxResults<IPage<SRaRealTimeAnalysicComsitMonitorVo>> abnormalList(SRaRealTimeAnalysicComsitMonitorVo sRaRealTimeAnalysicComsit)
    {
        IPage<SRaRealTimeAnalysicComsitMonitorVo> list = sRaRealTimeAnalysicComsitService.abnormalList(sRaRealTimeAnalysicComsit);
        return AjaxResults.success(list);
    }
    @ApiOperation(value = "查询监测点位对比分析-查看详情对比箱型图")
    @GetMapping("/abnormalEcharts")
    public AjaxResults<EChartsVO.DiagramVo> abnormalEcharts(SRaRealTimeAnalysicComsitMonitorVo sRaRealTimeAnalysicComsit)
    {
        EChartsVO.DiagramVo list = sRaRealTimeAnalysicComsitService.abnormalEcharts(sRaRealTimeAnalysicComsit);
        return AjaxResults.success(list);
    }
    @ApiOperation(value = "导出监测点位对比分析-分组查看详情异常")
    @PostMapping("/abnormalExport")
    public void abnormalExport(HttpServletResponse response, @RequestBody SRaRealTimeAnalysicComsitMonitorVo sRaRealTimeAnalysicComsit)
    {
        List<SRaRealTimeAnalysicComsitMonitorVo> list = sRaRealTimeAnalysicComsitService.abnormalExport(sRaRealTimeAnalysicComsit);
        ExcelUtil<SRaRealTimeAnalysicComsitMonitorVo> util = new ExcelUtil<SRaRealTimeAnalysicComsitMonitorVo>(SRaRealTimeAnalysicComsitMonitorVo.class);
        util.exportExcel(response, list, "监测点位对比分析异常数据");
    }

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

    /**
     * 新增关联分析系统-企业生产过程分析-监测点位对比分析-分组
     */
    @ApiOperation(value = "新增监测点位对比分析-分组维护")
    @Log(title = "关联分析系统-企业生产过程分析-监测点位对比分析-分组维护", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public AjaxResults<Boolean> add( @Validated @RequestBody SRaRealTimeAnalysicComsit sRaRealTimeAnalysicComsit) {
        int count = sRaRealTimeAnalysicComsitService.count(
                new QueryWrapper<SRaRealTimeAnalysicComsit>().eq("sectionalization_name",sRaRealTimeAnalysicComsit.getSectionalizationName())
        );
        if(count>0){
           return  AjaxResults.error("分组名称重复请重新输入");
        }
        sRaRealTimeAnalysicComsit.setCreateTime(new Date());
        sRaRealTimeAnalysicComsit.setDataId(BigInteger.valueOf(IdUtil.getSnowflakeNextId()));
        return AjaxResults.success(sRaRealTimeAnalysicComsitService.save(sRaRealTimeAnalysicComsit));
    }

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



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

    /**
     * 工序options
     */
    @ApiOperation(value = "参数名称options")
    @GetMapping("/pullParam")
    public AjaxResults<List<Map<String, Object>>> pullParam() {
        return AjaxResults.success(sRaRealTimeAnalysicComsitService.pullParam());
    }

}
