package com.aucma.report.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.aucma.common.utils.DateUtils;
import com.aucma.report.domain.EnergyStatisticalReport;
import com.aucma.report.domain.ProductTraceabilityReport;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.aucma.common.annotation.Log;
import com.aucma.common.core.controller.BaseController;
import com.aucma.common.core.domain.AjaxResult;
import com.aucma.common.enums.BusinessType;
import com.aucma.report.domain.ReportDayDnb;
import com.aucma.report.service.IReportDayDnbService;
import com.aucma.common.utils.poi.ExcelUtil;
import com.aucma.common.core.page.TableDataInfo;

/**
 * 电日耗报Controller
 *
 * @author ruoyi
 * @date 2023-10-09
 */
@RestController
@RequestMapping("/report/DayDnb" )
public class ReportDayDnbController extends BaseController {
    @Autowired
    private IReportDayDnbService reportDayDnbService;

    /**
     * 查询电日耗报列表
     */
    @PreAuthorize("@ss.hasPermi('report:DayDnb:list')" )
    @GetMapping("/list" )
    public TableDataInfo list(ReportDayDnb reportDayDnb) {
        startPage();
        List<ReportDayDnb> list = reportDayDnbService.selectReportDayDnbList(reportDayDnb);
        return getDataTable(list);
    }

    /**
     * 导出电日耗报列表
     */
    @PreAuthorize("@ss.hasPermi('report:DayDnb:export')" )
    @Log(title = "电日耗报" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, ReportDayDnb reportDayDnb) {
        List<ReportDayDnb> list = reportDayDnbService.selectReportDayDnbList(reportDayDnb);
        ExcelUtil<ReportDayDnb> util = new ExcelUtil<ReportDayDnb>(ReportDayDnb. class);
        util.exportExcel(response, list, "电日耗报数据" );
    }

    /**
     * 获取电日耗报详细信息
     */
    @PreAuthorize("@ss.hasPermi('report:DayDnb:query')" )
    @GetMapping(value = "/{objId}" )
    public AjaxResult getInfo(@PathVariable("objId" ) Long objId) {
        return success(reportDayDnbService.selectReportDayDnbByObjId(objId));
    }

    /**
     * 新增电日耗报
     */
    @PreAuthorize("@ss.hasPermi('report:DayDnb:add')" )
    @Log(title = "电日耗报" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ReportDayDnb reportDayDnb) {
        reportDayDnb.setCreatedBy(getUsername());
        reportDayDnb.setCreatedTime(DateUtils.getNowDate());
        return toAjax(reportDayDnbService.insertReportDayDnb(reportDayDnb));
    }

    /**
     * 修改电日耗报
     */
    @PreAuthorize("@ss.hasPermi('report:DayDnb:edit')" )
    @Log(title = "电日耗报" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ReportDayDnb reportDayDnb) {
        reportDayDnb.setUpdatedBy(getUsername());
        reportDayDnb.setUpdatedTime(DateUtils.getNowDate());
        return toAjax(reportDayDnbService.updateReportDayDnb(reportDayDnb));
    }

    /**
     * 删除电日耗报
     */
    @PreAuthorize("@ss.hasPermi('report:DayDnb:remove')" )
    @Log(title = "电日耗报" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{objIds}" )
    public AjaxResult remove(@PathVariable Long[] objIds) {
        return toAjax(reportDayDnbService.deleteReportDayDnbByObjIds(objIds));
    }

    /**
     * 统计能耗报表
     * @param hashMap
     * @return
     */
    @GetMapping("/energyStatisticalReportList")
    public TableDataInfo energyStatisticalReportList(@RequestParam(required = false) Map hashMap) {
        startPage();
        List<EnergyStatisticalReport> list = reportDayDnbService.energyStatisticalReportList(hashMap);
        return getDataTable(list);
    }

    /**
     * 导出统计能耗报表
     */
    @PostMapping("/energyStatisticalReportList/export" )
    public void export(HttpServletResponse response, @RequestParam(required = false) Map hashMap) {
        List<EnergyStatisticalReport> list = reportDayDnbService.energyStatisticalReportList(hashMap);
        ExcelUtil<EnergyStatisticalReport> util = new ExcelUtil<>(EnergyStatisticalReport. class);
        util.exportExcel(response, list, "统计能耗报表" );
    }
}
