package com.goldenwater.slaj.hidd.controller;

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

@RestController
@RequestMapping("/hidd/count")
public class TBusiHiddCountController extends BaseController {
    @Autowired
    private ITBusiHiddCountService tBusiHiddCountService;

    @GetMapping("/list")
    public TableDataInfo list(TBusiHiddCountVo vo) {
        startPage();
        List<TBusiHiddCountVo> list = tBusiHiddCountService.selectTBusiHiddCountListWithCalc(vo);
        return getDataTable(list);
    }

    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return AjaxResult.success(tBusiHiddCountService.selectTBusiHiddCountById(id));
    }

    @PostMapping
    public AjaxResult add(@RequestBody TBusiHiddCount tBusiHiddCount) {
        return toAjax(tBusiHiddCountService.insertTBusiHiddCount(tBusiHiddCount));
    }

    @PutMapping
    public AjaxResult edit(@RequestBody TBusiHiddCount tBusiHiddCount) {
        return toAjax(tBusiHiddCountService.updateTBusiHiddCount(tBusiHiddCount));
    }

    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tBusiHiddCountService.deleteTBusiHiddCountByIds(ids));
    }

    @Log(title = "隐患统计", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('hidd:count:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, TBusiHiddCount tBusiHiddCount) {
        List<TBusiHiddCount> list = tBusiHiddCountService.selectTBusiHiddCountList(tBusiHiddCount);
        ExcelUtil<TBusiHiddCount> util = new ExcelUtil<>(TBusiHiddCount.class);
        util.exportExcel(response, list, "隐患统计数据");
    }

    @Log(title = "隐患统计", businessType = BusinessType.EXPORT)
    @PostMapping("/treeexport")
    public void treeExport(HttpServletResponse response, TBusiHiddCount tBusiHiddCount) {
        List<TBusiHiddCount> list = tBusiHiddCountService.selectTBusiHiddCountList(tBusiHiddCount);
        ExcelUtil<TBusiHiddCount> util = new ExcelUtil<>(TBusiHiddCount.class);
        util.exportExcel(response, list, "隐患统计数据");
    }

    @Log(title = "隐患统计", businessType = BusinessType.EXPORT)
    @PostMapping("/detailexport")
    public void detailExport(HttpServletResponse response, TBusiHiddCount tBusiHiddCount) {
        List<TBusiHiddCount> list = tBusiHiddCountService.selectTBusiHiddCountList(tBusiHiddCount);
        ExcelUtil<TBusiHiddCount> util = new ExcelUtil<>(TBusiHiddCount.class);
        util.exportExcel(response, list, "隐患统计数据");
    }

    /**
     * 隐患月报上报率柱状图数据
     */
    @GetMapping("/reportRateChart")
    public AjaxResult reportRateChart(@RequestParam(required = false) String repTime) {
        Map<String, Object> params = new java.util.HashMap<>();
        params.put("repTime", repTime);
        List<Map<String, Object>> list = tBusiHiddCountService.selectReportRateChart(params);
        return AjaxResult.success(list);
    }

    /**
     * 隐患整改率柱状图数据
     */
    @GetMapping("/rectifyRateChart")
    public AjaxResult rectifyRateChart(@RequestParam(required = false) String repTime) {
        Map<String, Object> params = new java.util.HashMap<>();
        params.put("repTime", repTime);
        List<Map<String, Object>> list = tBusiHiddCountService.selectRectifyRateChart(params);
        return AjaxResult.success(list);
    }
}
