package com.phm.manage.controller;

import com.phm.common.annotation.Log;
import com.phm.common.core.controller.BaseController;
import com.phm.common.core.domain.AjaxResult;
import com.phm.common.core.page.TableDataInfo;
import com.phm.common.enums.BusinessType;
import com.phm.common.utils.poi.ExcelUtil;
import com.phm.manage.domain.ForecastResult;
import com.phm.manage.service.IForecastResultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 预测结果Controller
 *
 * @author phm
 * @date 2023-08-31
 */
@RestController
@RequestMapping("/manage/forecastResult")
public class ForecastResultController extends BaseController {
    @Autowired
    private IForecastResultService forecastResultService;

    /**
     * 查询预测结果列表
     */
    @PreAuthorize("@ss.hasPermi('manage:forecastResult:list')")
    @GetMapping("/list")
    public TableDataInfo list(ForecastResult forecastResult) {
        startPage();
        List<ForecastResult> list = forecastResultService.selectForecastResultList(forecastResult);
        return getDataTable(list);
    }

    /**
     * 导出预测结果列表
     */
    @PreAuthorize("@ss.hasPermi('manage:forecastResult:export')")
    @Log(title = "预测结果", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ForecastResult forecastResult) {
        List<ForecastResult> list = forecastResultService.selectForecastResultList(forecastResult);
        ExcelUtil<ForecastResult> util = new ExcelUtil<ForecastResult>(ForecastResult.class);
        util.exportExcel(response, list, "预测结果数据");
    }

    /**
     * 获取预测结果详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:forecastResult:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(forecastResultService.selectForecastResultById(id));
    }

    /**
     * 新增预测结果
     */
    @PreAuthorize("@ss.hasPermi('manage:forecastResult:add')")
    @Log(title = "预测结果", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ForecastResult forecastResult) {
        return toAjax(forecastResultService.insertForecastResult(forecastResult));
    }

    /**
     * 修改预测结果
     */
    @PreAuthorize("@ss.hasPermi('manage:forecastResult:edit')")
    @Log(title = "预测结果", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ForecastResult forecastResult) {
        return toAjax(forecastResultService.updateForecastResult(forecastResult));
    }

    /**
     * 删除预测结果
     */
    @PreAuthorize("@ss.hasPermi('manage:forecastResult:remove')")
    @Log(title = "预测结果", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(forecastResultService.deleteForecastResultByIds(ids));
    }
}
