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.ForecastModel;
import com.phm.manage.service.IForecastModelService;
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-22
 */
@RestController
@RequestMapping("/manage/forecastModel")
public class ForecastModelController extends BaseController {
    @Autowired
    private IForecastModelService forecastModelService;

    /**
     * 查询预测模型信息列表
     */
    @PreAuthorize("@ss.hasPermi('manage:forecastModel:list')")
    @GetMapping("/list")
    public TableDataInfo list(ForecastModel forecastModel) {
        startPage();
        List<ForecastModel> list = forecastModelService.selectForecastModelList(forecastModel);
        return getDataTable(list);
    }

    /**
     * 导出预测模型信息列表
     */
    @PreAuthorize("@ss.hasPermi('manage:forecastModel:export')")
    @Log(title = "预测模型信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ForecastModel forecastModel) {
        List<ForecastModel> list = forecastModelService.selectForecastModelList(forecastModel);
        ExcelUtil<ForecastModel> util = new ExcelUtil<ForecastModel>(ForecastModel.class);
        util.exportExcel(response, list, "预测模型信息数据");
    }

    /**
     * 获取预测模型信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:forecastModel:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(forecastModelService.selectForecastModelById(id));
    }

    /**
     * 新增预测模型信息
     */
    @PreAuthorize("@ss.hasPermi('manage:forecastModel:add')")
    @Log(title = "预测模型信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ForecastModel forecastModel) {
        return toAjax(forecastModelService.insertForecastModel(forecastModel));
    }

    /**
     * 修改预测模型信息
     */
    @PreAuthorize("@ss.hasPermi('manage:forecastModel:edit')")
    @Log(title = "预测模型信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ForecastModel forecastModel) {
        return toAjax(forecastModelService.updateForecastModel(forecastModel));
    }

    /**
     * 删除预测模型信息
     */
    @PreAuthorize("@ss.hasPermi('manage:forecastModel:remove')")
    @Log(title = "预测模型信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(forecastModelService.deleteForecastModelByIds(ids));
    }
}
