package com.ruoyi.system.controller;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.PageDomain;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.EpsTaskStatistics;
import com.ruoyi.system.service.IEpsTaskStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 业务95值计算任务Controller
 *
 * @author gyt
 * @date 2025-10-29
 */
@RestController
@RequestMapping("/taskStatistics")
public class EpsTaskStatisticsController extends BaseController
{
    @Autowired
    private IEpsTaskStatisticsService epsTaskStatisticsService;

    /**
     * 查询业务95值计算任务列表
     */
    @RequiresPermissions("system:taskStatistics:list")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody EpsTaskStatistics epsTaskStatistics)
    {
        PageDomain pageDomain = new PageDomain();
        pageDomain.setPageNum(epsTaskStatistics.getPageNum());
        pageDomain.setPageSize(epsTaskStatistics.getPageSize());
        startPage(pageDomain);
        List<EpsTaskStatistics> list = epsTaskStatisticsService.selectEpsTaskStatisticsList(epsTaskStatistics);
        return getDataTable(list);
    }

    /**
     * 导出业务95值计算任务列表
     */
    @RequiresPermissions("system:taskStatistics:export")
    @Log(title = "业务95值计算任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EpsTaskStatistics epsTaskStatistics)
    {
        List<EpsTaskStatistics> list = epsTaskStatisticsService.selectEpsTaskStatisticsList(epsTaskStatistics);
        ExcelUtil<EpsTaskStatistics> util = new ExcelUtil<EpsTaskStatistics>(EpsTaskStatistics.class);
        util.showColumn(epsTaskStatistics.getProperties());
        util.exportExcel(response, list, "业务95值计算任务数据");
    }

    /**
     * 获取业务95值计算任务详细信息
     */
    @RequiresPermissions("system:taskStatistics:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(epsTaskStatisticsService.selectEpsTaskStatisticsById(id));
    }

    /**
     * 新增业务95值计算任务
     */
    @RequiresPermissions("system:taskStatistics:add")
    @Log(title = "业务95值计算任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EpsTaskStatistics epsTaskStatistics)
    {
        return toAjax(epsTaskStatisticsService.insertEpsTaskStatistics(epsTaskStatistics));
    }

    /**
     * 修改业务95值计算任务
     */
    @RequiresPermissions("system:taskStatistics:edit")
    @Log(title = "业务95值计算任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EpsTaskStatistics epsTaskStatistics)
    {
        return toAjax(epsTaskStatisticsService.updateEpsTaskStatistics(epsTaskStatistics));
    }

    /**
     * 删除业务95值计算任务
     */
    @RequiresPermissions("system:taskStatistics:remove")
    @Log(title = "业务95值计算任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(epsTaskStatisticsService.deleteEpsTaskStatisticsByIds(ids));
    }
    /**
     * 相关数据查询
     */
    @RequiresPermissions("system:taskStatistics:list")
    @PostMapping("/getRelateData")
    public TableDataInfo getRelateData(@RequestBody EpsTaskStatistics epsTaskStatistics)
    {
        PageInfo<?> list = epsTaskStatisticsService.getRelateData(epsTaskStatistics);
        return getDataTable(list.getList(), list.getTotal());
    }
    /**
     * 修改相关数据
     * @param epsTaskStatistics
     * @return
     */
    @RequiresPermissions("system:taskStatistics:edit")
    @PostMapping("/updateRelateData")
    public AjaxResult updateRelateData(@RequestBody EpsTaskStatistics epsTaskStatistics)
    {
        int rows = epsTaskStatisticsService.updateRelateData(epsTaskStatistics);
        return toAjax(rows);
    }
    /**
     * 重新计算
     */
    @RequiresPermissions("system:taskStatistics:list")
    @PostMapping("/recaculate")
    public AjaxResult recaculate(@RequestBody EpsTaskStatistics epsTaskStatistics)
    {
        int rows = epsTaskStatisticsService.recaculate(epsTaskStatistics);
        return toAjax(rows);
    }
    /**
     * 图形查看
     */
    @RequiresPermissions("system:taskStatistics:list")
    @PostMapping("/getRraphicalMsg")
    public AjaxResult getRraphicalMsg(@RequestBody EpsTaskStatistics epsTaskStatistics)
    {
        Map echartsMap = epsTaskStatisticsService.getRraphicalMsg(epsTaskStatistics);
        return success(echartsMap);
    }

    /**
     * 获取月均日95值的日列表
     * @param epsTaskStatistics
     * @return
     */
    @RequiresPermissions("system:taskStatistics:list")
    @PostMapping("/getAvgTimeList")
    public AjaxResult getAvgTimeList(@RequestBody EpsTaskStatistics epsTaskStatistics)
    {
        List<String> avgTimeList = epsTaskStatisticsService.getAvgTimeList(epsTaskStatistics);
        return success(avgTimeList);
    }
}
