package com.goldenwater.web.controller.yjjt;

import java.util.List;
import java.util.Map;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.goldenwater.common.annotation.Log;
import com.goldenwater.common.core.controller.BaseController;
import com.goldenwater.common.core.domain.AjaxResult;
import com.goldenwater.common.core.page.TableDataInfo;
import com.goldenwater.common.enums.BusinessType;
import com.goldenwater.common.utils.poi.ExcelUtil;
import com.goldenwater.yjjt.domain.YjjtSlData;
import com.goldenwater.yjjt.service.IYjjtSlDataService;

/**
 * 引江济太水量数据Controller
 */
@RestController
@RequestMapping("/yjjt/sl/data")
public class YjjtSlDataController extends BaseController
{
    @Autowired
    private IYjjtSlDataService yjjtSlDataService;

    /**
     * 查询水量数据列表
     */
    @PreAuthorize("@ss.hasPermi('yjjt:sl:list')")
    @GetMapping("/list")
    public TableDataInfo list(YjjtSlData slData)
    {
        startPage();
        List<YjjtSlData> list = yjjtSlDataService.selectYjjtSlDataList(slData);
        return getDataTable(list);
    }

    /**
     * 导出水量数据
     */
    @PreAuthorize("@ss.hasPermi('yjjt:sl:export')")
    @Log(title = "引江济太水量数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YjjtSlData slData)
    {
        List<YjjtSlData> list = yjjtSlDataService.selectYjjtSlDataList(slData);
        ExcelUtil<YjjtSlData> util = new ExcelUtil<YjjtSlData>(YjjtSlData.class);
        util.exportExcel(response, list, "水量数据");
    }

    /**
     * 获取水量数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('yjjt:sl:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Long id)
    {
        return success(yjjtSlDataService.selectYjjtSlDataById(id));
    }

    /**
     * 新增水量数据
     */
    @PreAuthorize("@ss.hasPermi('yjjt:sl:add')")
    @Log(title = "引江济太水量数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YjjtSlData slData)
    {
        slData.setCreateBy(getUsername());
        return toAjax(yjjtSlDataService.insertYjjtSlData(slData));
    }

    /**
     * 修改水量数据
     */
    @PreAuthorize("@ss.hasPermi('yjjt:sl:edit')")
    @Log(title = "引江济太水量数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YjjtSlData slData)
    {
        slData.setUpdateBy(getUsername());
        return toAjax(yjjtSlDataService.updateYjjtSlData(slData));
    }

    /**
     * 删除水量数据
     */
    @PreAuthorize("@ss.hasPermi('yjjt:sl:remove')")
    @Log(title = "引江济太水量数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yjjtSlDataService.deleteYjjtSlDataByIds(ids));
    }

    /**
     * 获取河流名称列表（去重）
     */
    @PreAuthorize("@ss.hasPermi('yjjt:sl:list')")
    @GetMapping("/rvnmList")
    public AjaxResult rvnmList()
    {
        return success(yjjtSlDataService.selectDistinctRvnmList());
    }

    /**
     * 按日期范围统计数据量
     */
    @PreAuthorize("@ss.hasPermi('yjjt:sl:list')")
    @GetMapping("/countByDateRange")
    public AjaxResult countByDateRange(@RequestParam(required = false) String beginDate,
                                       @RequestParam(required = false) String endDate)
    {
        return success(yjjtSlDataService.selectCountByDateRange(beginDate, endDate));
    }

    /**
     * 今日/本周/本月数据统计
     */
    @PreAuthorize("@ss.hasPermi('yjjt:sl:list')")
    @GetMapping("/count")
    public AjaxResult count(@RequestParam(required = false) String addvcd)
    {
        return success(yjjtSlDataService.selectTodayWeekMonthCount(addvcd));
    }
}
