package com.hw.system.common.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

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.hw.common.log.annotation.Log;
import com.hw.common.log.enums.BusinessType;
import com.hw.common.security.annotation.RequiresPermissions;
import com.hw.system.common.domain.HwPrinterInfo;
import com.hw.system.common.service.IHwPrinterInfoService;
import com.hw.common.core.web.controller.BaseController;
import com.hw.common.core.web.domain.AjaxResult;
import com.hw.common.core.utils.poi.ExcelUtil;
import com.hw.common.core.web.page.TableDataInfo;

/**
 * 打印机信息Controller
 *
 * @author Yinq
 * @date 2024-03-25
 */
@RestController
@RequestMapping("/hwPrinterInfo")
public class HwPrinterInfoController extends BaseController {
    @Autowired
    private IHwPrinterInfoService hwPrinterInfoService;

    /**
     * 查询打印机信息列表
     */
    @RequiresPermissions("system:hwPrinterInfo:list")
    @GetMapping("/list")
    public TableDataInfo list(HwPrinterInfo hwPrinterInfo) {
        startPage();
        List<HwPrinterInfo> list = hwPrinterInfoService.selectHwPrinterInfoList(hwPrinterInfo);
        return getDataTable(list);
    }

    /**
     * 导出打印机信息列表
     */
    @RequiresPermissions("system:hwPrinterInfo:export")
    @Log(title = "打印机信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HwPrinterInfo hwPrinterInfo) {
        List<HwPrinterInfo> list = hwPrinterInfoService.selectHwPrinterInfoList(hwPrinterInfo);
        ExcelUtil<HwPrinterInfo> util = new ExcelUtil<HwPrinterInfo>(HwPrinterInfo.class);
        util.exportExcel(response, list, "打印机信息数据");
    }

    /**
     * 获取打印机信息详细信息
     */
    @RequiresPermissions("system:hwPrinterInfo:query")
    @GetMapping(value = "/{printerInfoId}")
    public AjaxResult getInfo(@PathVariable("printerInfoId") Long printerInfoId) {
        return success(hwPrinterInfoService.selectHwPrinterInfoByPrinterInfoId(printerInfoId));
    }

    /**
     * 新增打印机信息
     */
    @RequiresPermissions("system:hwPrinterInfo:add")
    @Log(title = "打印机信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HwPrinterInfo hwPrinterInfo) {
        return toAjax(hwPrinterInfoService.insertHwPrinterInfo(hwPrinterInfo));
    }

    /**
     * 修改打印机信息
     */
    @RequiresPermissions("system:hwPrinterInfo:edit")
    @Log(title = "打印机信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HwPrinterInfo hwPrinterInfo) {
        return toAjax(hwPrinterInfoService.updateHwPrinterInfo(hwPrinterInfo));
    }

    /**
     * 删除打印机信息
     */
    @RequiresPermissions("system:hwPrinterInfo:remove")
    @Log(title = "打印机信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{printerInfoIds}")
    public AjaxResult remove(@PathVariable Long[] printerInfoIds) {
        return toAjax(hwPrinterInfoService.deleteHwPrinterInfoByPrinterInfoIds(printerInfoIds));
    }
}
