package com.ruoyi.model.controller;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.model.domain.License;
import com.ruoyi.model.service.ILicenseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 执照Controller
 * 
 * @author ruoyi
 * @date 2025-03-05
 */
@RestController
@RequestMapping("/model/license")
public class LicenseController extends BaseController
{
    @Autowired
    private ILicenseService licenseService;

    /**
     * 查询执照列表
     */
    @PreAuthorize("@ss.hasPermi('model:license:list')")
    @GetMapping("/list")
    public TableDataInfo list(License license)
    {
        startPage();
        List<License> list = licenseService.selectLicenseList(license);
        return getDataTable(list);
    }

    /**
     * 导出执照列表
     */
    @PreAuthorize("@ss.hasPermi('model:license:export')")
    @Log(title = "执照", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, License license) throws IOException {
        List<License> list = licenseService.selectLicenseList(license);
        ExcelUtil<License> util = new ExcelUtil<License>(License.class);
        util.exportExcel(response, list, "执照数据");
    }

    /**
     * 获取执照详细信息
     */
    @PreAuthorize("@ss.hasPermi('model:license:query')")
    @GetMapping(value = "/{licenseId}")
    public AjaxResult getInfo(@PathVariable("licenseId") Long licenseId)
    {
        return success(licenseService.selectLicenseByLicenseId(licenseId));
    }

    /**
     * 新增执照
     */
    @PreAuthorize("@ss.hasPermi('model:license:add')")
    @Log(title = "执照", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody License license)
    {
        return toAjax(licenseService.insertLicense(license));
    }

    /**
     * 修改执照
     */
    @PreAuthorize("@ss.hasPermi('model:license:edit')")
    @Log(title = "执照", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody License license)
    {
        return toAjax(licenseService.updateLicense(license));
    }

    /**
     * 删除执照
     */
    @PreAuthorize("@ss.hasPermi('model:license:remove')")
    @Log(title = "执照", businessType = BusinessType.DELETE)
	@DeleteMapping("/{licenseIds}")
    public AjaxResult remove(@PathVariable Long[] licenseIds)
    {
        return toAjax(licenseService.deleteLicenseByLicenseIds(licenseIds));
    }
}
