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.report.domain.ReportPointWater;
import com.hw.ems.report.domain.ReportPointWaterDTO;
import com.hw.ems.report.service.IReportPointWaterService;
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-09
 */
@Controller
@RequestMapping("/report/pointWater")
public class ReportPointWaterController extends BaseController
{
    private String prefix = "report/pointWater";

    @Autowired
    private IReportPointWaterService reportPointWaterService;

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

    /**
     * 查询水整点数据列表
     */
    @RequiresPermissions("report:pointWater:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ReportPointWater reportPointWater)
    {
        startPage();
        List<ReportPointWater> list = reportPointWaterService.selectReportPointWaterList(reportPointWater);
        return getDataTable(list);
    }

    /**
     * 日月年电数据List
     * @param reportPointWater
     * @return
     */
    @PostMapping("/datePointWaterList")
    @ResponseBody
    public TableDataInfo datePointWaterList(ReportPointWater reportPointWater)
    {
        startPage();
        List<ReportPointWaterDTO> list = reportPointWaterService.datePointWaterList(reportPointWater);
        return getDataTable(list);
    }


    /**
     * 导出水整点数据列表
     */
    @RequiresPermissions("report:pointWater:export")
    @Log(title = "水整点数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public void export(HttpServletResponse response,ReportPointWater reportPointWater)
    {
        if (reportPointWater.getDateType().equals("hour")){
            List<ReportPointWater> list = reportPointWaterService.selectReportPointWaterList(reportPointWater);
            ExcelUtil<ReportPointWater> util = new ExcelUtil<ReportPointWater>(ReportPointWater.class);
            util.exportExcel(response,list, "水整点数据数据");
        }else {
            List<ReportPointWaterDTO> list = reportPointWaterService.datePointWaterList(reportPointWater);
            ExcelUtil<ReportPointWaterDTO> util = new ExcelUtil<ReportPointWaterDTO>(ReportPointWaterDTO.class);
            util.exportExcel(response,list, "水整点数据数据");
        }
    }

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

    /**
     * 新增保存水整点数据
     */
    @RequiresPermissions("report:pointWater:add")
    @Log(title = "水整点数据", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ReportPointWater reportPointWater)
    {
        return toAjax(reportPointWaterService.insertReportPointWater(reportPointWater));
    }

    /**
     * 修改水整点数据
     */
    @RequiresPermissions("report:pointWater:edit")
    @GetMapping("/edit/{objid}")
    public String edit(@PathVariable("objid") Long objid, ModelMap mmap)
    {
        ReportPointWater reportPointWater = reportPointWaterService.selectReportPointWaterByObjid(objid);
        mmap.put("reportPointWater", reportPointWater);
        return prefix + "/edit";
    }

    /**
     * 修改保存水整点数据
     */
    @RequiresPermissions("report:pointWater:edit")
    @Log(title = "水整点数据", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ReportPointWater reportPointWater)
    {
        return toAjax(reportPointWaterService.updateReportPointWater(reportPointWater));
    }

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