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.DeriveParameter;
import com.phm.manage.service.IDeriveParameterService;
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/deriveParameter")
public class DeriveParameterController extends BaseController {
    @Autowired
    private IDeriveParameterService deriveParameterService;

    /**
     * 查询衍生参数信息列表
     */
    @PreAuthorize("@ss.hasPermi('manage:deriveParameter:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeriveParameter deriveParameter) {
        startPage();
        List<DeriveParameter> list = deriveParameterService.selectDeriveParameterList(deriveParameter);
        return getDataTable(list);
    }

    /**
     * 导出衍生参数信息列表
     */
    @PreAuthorize("@ss.hasPermi('manage:deriveParameter:export')")
    @Log(title = "衍生参数信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeriveParameter deriveParameter) {
        List<DeriveParameter> list = deriveParameterService.selectDeriveParameterList(deriveParameter);
        ExcelUtil<DeriveParameter> util = new ExcelUtil<DeriveParameter>(DeriveParameter.class);
        util.exportExcel(response, list, "衍生参数信息数据");
    }

    /**
     * 获取衍生参数信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:deriveParameter:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(deriveParameterService.selectDeriveParameterById(id));
    }

    /**
     * 新增衍生参数信息
     */
    @PreAuthorize("@ss.hasPermi('manage:deriveParameter:add')")
    @Log(title = "衍生参数信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeriveParameter deriveParameter) {
        return toAjax(deriveParameterService.insertDeriveParameter(deriveParameter));
    }

    /**
     * 修改衍生参数信息
     */
    @PreAuthorize("@ss.hasPermi('manage:deriveParameter:edit')")
    @Log(title = "衍生参数信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeriveParameter deriveParameter) {
        return toAjax(deriveParameterService.updateDeriveParameter(deriveParameter));
    }

    /**
     * 删除衍生参数信息
     */
    @PreAuthorize("@ss.hasPermi('manage:deriveParameter:remove')")
    @Log(title = "衍生参数信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(deriveParameterService.deleteDeriveParameterByIds(ids));
    }
}
