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.LifePartConfig;
import com.phm.manage.service.ILifePartConfigService;
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-23
 */
@RestController
@RequestMapping("/manage/lifePartConfig")
public class LifePartConfigController extends BaseController {
    @Autowired
    private ILifePartConfigService lifePartConfigService;

    /**
     * 查询寿命件配置库信息列表
     */
    @PreAuthorize("@ss.hasPermi('manage:lifePartConfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(LifePartConfig lifePartConfig) {
        startPage();
        List<LifePartConfig> list = lifePartConfigService.selectLifePartConfigList(lifePartConfig);
        return getDataTable(list);
    }

    /**
     * 导出寿命件配置库信息列表
     */
    @PreAuthorize("@ss.hasPermi('manage:lifePartConfig:export')")
    @Log(title = "寿命件配置库信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LifePartConfig lifePartConfig) {
        List<LifePartConfig> list = lifePartConfigService.selectLifePartConfigList(lifePartConfig);
        ExcelUtil<LifePartConfig> util = new ExcelUtil<LifePartConfig>(LifePartConfig.class);
        util.exportExcel(response, list, "寿命件配置库信息数据");
    }

    /**
     * 获取寿命件配置库信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:lifePartConfig:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(lifePartConfigService.selectLifePartConfigById(id));
    }

    /**
     * 新增寿命件配置库信息
     */
    @PreAuthorize("@ss.hasPermi('manage:lifePartConfig:add')")
    @Log(title = "寿命件配置库信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LifePartConfig lifePartConfig) {
        return toAjax(lifePartConfigService.insertLifePartConfig(lifePartConfig));
    }

    /**
     * 修改寿命件配置库信息
     */
    @PreAuthorize("@ss.hasPermi('manage:lifePartConfig:edit')")
    @Log(title = "寿命件配置库信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LifePartConfig lifePartConfig) {
        return toAjax(lifePartConfigService.updateLifePartConfig(lifePartConfig));
    }

    /**
     * 删除寿命件配置库信息
     */
    @PreAuthorize("@ss.hasPermi('manage:lifePartConfig:remove')")
    @Log(title = "寿命件配置库信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(lifePartConfigService.deleteLifePartConfigByIds(ids));
    }
}
