package com.hw.ems.report.controller;


import com.hw.common.core.utils.poi.ExcelUtil;
import com.hw.common.core.web.controller.BaseController;
import com.hw.common.core.web.domain.AjaxResult;
import com.hw.common.core.web.page.TableDataInfo;
import com.hw.common.log.annotation.Log;
import com.hw.common.log.enums.BusinessType;
import com.hw.common.security.annotation.RequiresPermissions;
import com.hw.ems.record.domain.RecordDnbInstant;
import com.hw.ems.record.domain.vo.RecordDnbInstantDataVo;
import com.hw.ems.report.domain.ReportPointDnb;
import com.hw.ems.report.domain.ReportPointDnbDTO;
import com.hw.ems.report.service.IReportPointDnbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

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

/**
 * 电整点数据Controller
 *
 * @author YinQ
 * @date 2023-04-05
 */
@Controller
@RequestMapping("/report/pointDnb")
public class ReportPointDnbController extends BaseController {
    private String prefix = "report/pointDnb";

    @Autowired
    private IReportPointDnbService reportPointDnbService;

    @RequiresPermissions("report:pointDnb:view")
    @GetMapping()
    public String pointDnb()
    {
        return prefix + "/pointDnb";
    }

    /**
     * 查询电整点数据列表
     */
    @RequiresPermissions("report:pointDnb:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ReportPointDnb reportPointDnb)
    {
        startPage();
        List<ReportPointDnb> list = reportPointDnbService.selectReportPointDnbList(reportPointDnb);
        return getDataTable(list);
    }
    /**
     * 查询电实时数据列表
     */
    @RequiresPermissions("record:dnbInstant:list")
    @PostMapping("/lists")
    @ResponseBody
    public TableDataInfo lists(@RequestBody ReportPointDnb reportPointDnb)
    {
        startPage();
        List<ReportPointDnb> list = reportPointDnbService.selectReportPointDnbList(reportPointDnb);
        return getDataTable(list);
    }


    /**
     * 日月年电数据List
     * @param reportPointDnb
     * @return
     */
    @PostMapping("/datePointDnbList")
    @ResponseBody
    public TableDataInfo datePointDnbList(@RequestBody ReportPointDnb reportPointDnb)
    {
        startPage();
        List<ReportPointDnbDTO> list = reportPointDnbService.datePointDnbList(reportPointDnb);
        return getDataTable(list);
    }

    /**
     * 导出电整点数据列表
     */
    @RequiresPermissions("report:pointDnb:export")
    @Log(title = "电整点数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public void export(HttpServletResponse response,ReportPointDnb reportPointDnb)
    {
        if (reportPointDnb.getDateType().equals("hour")){
            List<ReportPointDnb> list = reportPointDnbService.selectReportPointDnbList(reportPointDnb);
            ExcelUtil<ReportPointDnb> util = new ExcelUtil<ReportPointDnb>(ReportPointDnb.class);
            util.exportExcel(response,list, "电整点数据数据");
        } else {
            List<ReportPointDnbDTO> list = reportPointDnbService.datePointDnbList(reportPointDnb);
            ExcelUtil<ReportPointDnbDTO> util = new ExcelUtil<ReportPointDnbDTO>(ReportPointDnbDTO.class);
            util.exportExcel(response,list, "电整点数据数据");
        }
    }

    /**
     * 新增电整点数据
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存电整点数据
     */
    @RequiresPermissions("report:pointDnb:add")
    @Log(title = "电整点数据", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ReportPointDnb reportPointDnb)
    {
        return toAjax(reportPointDnbService.insertReportPointDnb(reportPointDnb));
    }

    /**
     * 修改电整点数据
     */
    @RequiresPermissions("report:pointDnb:edit")
    @GetMapping("/edit/{objid}")
    public String edit(@PathVariable("objid") Long objid, ModelMap mmap)
    {
        ReportPointDnb reportPointDnb = reportPointDnbService.selectReportPointDnbByObjid(objid);
        mmap.put("reportPointDnb", reportPointDnb);
        return prefix + "/edit";
    }

    /**
     * 修改保存电整点数据
     */
    @RequiresPermissions("report:pointDnb:edit")
    @Log(title = "电整点数据", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ReportPointDnb reportPointDnb)
    {
        return toAjax(reportPointDnbService.updateReportPointDnb(reportPointDnb));
    }

    /**
     * 删除电整点数据
     */
    @RequiresPermissions("report:pointDnb:remove")
    @Log(title = "电整点数据", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(reportPointDnbService.deleteReportPointDnbByObjids(ids));
    }



}
