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.SoftwareConfig;
import com.phm.manage.service.ISoftwareConfigService;
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/softwareConfig")
public class SoftwareConfigController extends BaseController {
    @Autowired
    private ISoftwareConfigService softwareConfigService;

    /**
     * 查询软件配置库信息列表
     */
    @PreAuthorize("@ss.hasPermi('manage:softwareConfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(SoftwareConfig softwareConfig) {
        startPage();
        List<SoftwareConfig> list = softwareConfigService.selectSoftwareConfigList(softwareConfig);
        return getDataTable(list);
    }

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

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

    /**
     * 新增软件配置库信息
     */
    @PreAuthorize("@ss.hasPermi('manage:softwareConfig:add')")
    @Log(title = "软件配置库信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SoftwareConfig softwareConfig) {
        return toAjax(softwareConfigService.insertSoftwareConfig(softwareConfig));
    }

    /**
     * 修改软件配置库信息
     */
    @PreAuthorize("@ss.hasPermi('manage:softwareConfig:edit')")
    @Log(title = "软件配置库信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SoftwareConfig softwareConfig) {
        return toAjax(softwareConfigService.updateSoftwareConfig(softwareConfig));
    }

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