package com.hw.ems.record.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.RecordWaterInstant;
import com.hw.ems.record.service.IRecordWaterInstantService;
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-08
 */
@Controller
@RequestMapping("/record/waterInstant")
public class RecordWaterInstantController extends BaseController
{
    private String prefix = "record/waterInstant";

    @Autowired
    private IRecordWaterInstantService recordWaterInstantService;

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

    /**
     * 点钞数据
     * @return
     */
    @GetMapping("/waterCountingData")
    public String waterCountingData()
    {
        return prefix + "/waterCountingData";
    }


    @GetMapping("/waterHistoryData")
    public String waterHistoryData()
    {
        return prefix + "/waterHistoryData";
    }

    /**
     * 手动抄表
     * @return
     */
    @GetMapping("/waterMeterReading")
    public String waterMeterReading()
    {
        return prefix + "/waterMeterReading";
    }


    /**
     * 查询水实时数据列表
     */
    @RequiresPermissions("record:waterInstant:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RecordWaterInstant recordWaterInstant)
    {
        startPage();
        List<RecordWaterInstant> list = recordWaterInstantService.selectRecordWaterInstantList(recordWaterInstant);
        return getDataTable(list);
    }

    /**
     * 导出水实时数据列表
     */
    @RequiresPermissions("record:waterInstant:export")
    @Log(title = "水实时数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public void export(HttpServletResponse response,RecordWaterInstant recordWaterInstant)
    {
        List<RecordWaterInstant> list = recordWaterInstantService.selectRecordWaterInstantList(recordWaterInstant);
        ExcelUtil<RecordWaterInstant> util = new ExcelUtil<RecordWaterInstant>(RecordWaterInstant.class);
        util.exportExcel(response,list, "水实时数据数据");
    }

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

    /**
     * 新增保存水实时数据
     */
    @RequiresPermissions("record:waterInstant:add")
    @Log(title = "水实时数据", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RecordWaterInstant recordWaterInstant)
    {
        return toAjax(recordWaterInstantService.insertRecordWaterInstant(recordWaterInstant));
    }

    /**
     * 修改水实时数据
     */
    @RequiresPermissions("record:waterInstant:edit")
    @GetMapping("/edit/{objid}")
    public String edit(@PathVariable("objid") Long objid, ModelMap mmap)
    {
        RecordWaterInstant recordWaterInstant = recordWaterInstantService.selectRecordWaterInstantByObjid(objid);
        mmap.put("recordWaterInstant", recordWaterInstant);
        return prefix + "/edit";
    }

    /**
     * 修改保存水实时数据
     */
    @RequiresPermissions("record:waterInstant:edit")
    @Log(title = "水实时数据", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RecordWaterInstant recordWaterInstant)
    {
        return toAjax(recordWaterInstantService.updateRecordWaterInstant(recordWaterInstant));
    }

    /**
     * 删除水实时数据
     */
    @RequiresPermissions("record:waterInstant:remove")
    @Log(title = "水实时数据", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(recordWaterInstantService.deleteRecordWaterInstantByObjids(ids));
    }

    /**
     * 获取最新实时电数据
     */
    @PostMapping("/selectRealTimeList")
    @ResponseBody
    public TableDataInfo selectRealTimeParentList(RecordWaterInstant recordWaterInstant)
    {
        List<RecordWaterInstant> list = recordWaterInstantService.selectRealTimeParentList(recordWaterInstant);
        return getDataTable(list);
    }

    /**
     * 实时数据
     * @param recordWaterInstant
     * @return
     */
    @GetMapping("/instantList")
    @ResponseBody
    public TableDataInfo instantList(RecordWaterInstant recordWaterInstant)
    {
        List<RecordWaterInstant> list = recordWaterInstantService.instantList(recordWaterInstant);
        return getDataTable(list);
    }

    /**
     * 表具实时状态
     * @param waterInstant
     * @return
     */
    @PostMapping( "/tablewareDetailsInfo")
    @ResponseBody
    public RecordWaterInstant tablewareDetailsInfo(RecordWaterInstant waterInstant){
        RecordWaterInstant recordWaterInstant = recordWaterInstantService.tablewareDetailsInfo(waterInstant);
        return recordWaterInstant;
    }

}
