package com.hw.dms.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.dms.domain.DmsBaseDeviceType;
import com.hw.dms.service.IDmsBaseDeviceTypeService;
import com.hw.common.core.web.controller.BaseController;
import com.hw.common.core.web.domain.AjaxResult;
import com.hw.common.core.utils.poi.ExcelUtil;

/**
 * 设备类型信息Controller
 *
 * @author xins
 * @date 2023-12-27
 */
@RestController
@RequestMapping("/devicetype")
public class DmsBaseDeviceTypeController extends BaseController
{
    @Autowired
    private IDmsBaseDeviceTypeService dmsBaseDeviceTypeService;

    /**
     * 查询设备类型信息列表
     */
    @RequiresPermissions("dms:devicetype:list")
    @GetMapping("/list")
    public AjaxResult list(DmsBaseDeviceType dmsBaseDeviceType)
    {
        List<DmsBaseDeviceType> list = dmsBaseDeviceTypeService.selectDmsBaseDeviceTypeList(dmsBaseDeviceType);
        return success(list);
    }

    /**
     * 导出设备类型信息列表
     */
    @RequiresPermissions("dms:devicetype:export")
    @Log(title = "设备类型信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DmsBaseDeviceType dmsBaseDeviceType)
    {
        List<DmsBaseDeviceType> list = dmsBaseDeviceTypeService.selectDmsBaseDeviceTypeList(dmsBaseDeviceType);
        ExcelUtil<DmsBaseDeviceType> util = new ExcelUtil<DmsBaseDeviceType>(DmsBaseDeviceType.class);
        util.exportExcel(response, list, "设备类型信息数据");
    }

    /**
     * 获取设备类型信息详细信息
     */
    @RequiresPermissions("dms:devicetype:query")
    @GetMapping(value = "/{deviceTypeId}")
    public AjaxResult getInfo(@PathVariable("deviceTypeId") Long deviceTypeId)
    {
        return success(dmsBaseDeviceTypeService.selectDmsBaseDeviceTypeByDeviceTypeId(deviceTypeId));
    }

    /**
     * 新增设备类型信息
     */
    @RequiresPermissions("dms:devicetype:add")
    @Log(title = "设备类型信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DmsBaseDeviceType dmsBaseDeviceType)
    {
        return toAjax(dmsBaseDeviceTypeService.insertDmsBaseDeviceType(dmsBaseDeviceType));
    }

    /**
     * 修改设备类型信息
     */
    @RequiresPermissions("dms:devicetype:edit")
    @Log(title = "设备类型信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DmsBaseDeviceType dmsBaseDeviceType)
    {
        return toAjax(dmsBaseDeviceTypeService.updateDmsBaseDeviceType(dmsBaseDeviceType));
    }

    /**
     * 删除设备类型信息
     */
    @RequiresPermissions("dms:devicetype:remove")
    @Log(title = "设备类型信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deviceTypeIds}")
    public AjaxResult remove(@PathVariable Long[] deviceTypeIds)
    {
        return toAjax(dmsBaseDeviceTypeService.deleteDmsBaseDeviceTypeByDeviceTypeIds(deviceTypeIds));
    }
    @RequiresPermissions("dms:devicetype:list")
    @GetMapping("/selectDevicetypeByDeviceId")
    public AjaxResult selectDevicetypeByDeviceId(Long deviceId)
    {
        List<DmsBaseDeviceType> list = dmsBaseDeviceTypeService.selectDevicetypeByDeviceId(deviceId);
        return success(list);
    }

}
