package com.goldenwater.web.controller.yjjt;

import java.util.List;
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.YjjtSzData;
import com.goldenwater.yjjt.service.IYjjtSzDataService;

/**
 * 引江济太水质数据Controller
 */
@RestController
@RequestMapping("/yjjt/sz/data")
public class YjjtSzDataController extends BaseController
{
    @Autowired
    private IYjjtSzDataService yjjtSzDataService;

    /**
     * 查询水质数据列表
     */
    @PreAuthorize("@ss.hasPermi('yjjt:sz:list')")
    @GetMapping("/list")
    public TableDataInfo list(YjjtSzData szData)
    {
        startPage();
        List<YjjtSzData> list = yjjtSzDataService.selectYjjtSzDataList(szData);
        return getDataTable(list);
    }

    /**
     * 导出质数据
     */
    @PreAuthorize("@ss.hasPermi('yjjt:sz:export')")
    @Log(title = "引江济太水质数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YjjtSzData szData)
    {
        List<YjjtSzData> list = yjjtSzDataService.selectYjjtSzDataList(szData);
        ExcelUtil<YjjtSzData> util = new ExcelUtil<YjjtSzData>(YjjtSzData.class);
        util.exportExcel(response, list, "水质数据");
    }

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

    /**
     * 新增水质数据
     */
    @PreAuthorize("@ss.hasPermi('yjjt:sz:add')")
    @Log(title = "引江济太水质数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YjjtSzData szData)
    {
        szData.setCreateBy(getUsername());
        return toAjax(yjjtSzDataService.insertYjjtSzData(szData));
    }

    /**
     * 修改水质数据
     */
    @PreAuthorize("@ss.hasPermi('yjjt:sz:edit')")
    @Log(title = "引江济太水质数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YjjtSzData szData)
    {
        szData.setUpdateBy(getUsername());
        return toAjax(yjjtSzDataService.updateYjjtSzData(szData));
    }

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

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

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

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