package com.bonus.zlpt.equip.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.bonus.zlpt.common.core.utils.poi.ExcelUtil;
import com.bonus.zlpt.common.core.web.controller.BaseController;
import com.bonus.zlpt.common.core.web.domain.AjaxResult;
import com.bonus.zlpt.common.core.web.page.TableDataInfo;
import com.bonus.zlpt.common.log.annotation.Log;
import com.bonus.zlpt.common.log.enums.BusinessType;
import com.bonus.zlpt.common.security.annotation.RequiresPermissions;
import com.bonus.zlpt.equip.api.domain.TypeInfo;
import io.swagger.annotations.Api;
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.bonus.zlpt.equip.service.ITypeInfoService;

/**
 * 设备类型Controller
 * 
 * @author xsheng
 * @date 2023-12-02
 */
@Api(tags = "装备类型接口")
@RestController
@RequestMapping("/type")
public class TypeInfoController extends BaseController
{
    @Autowired
    private ITypeInfoService typeInfoService;

    /**
     * 查询设备类型列表
     */
    //@RequiresPermissions("equip:info:list")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody TypeInfo typeInfo) {
        startPage();
        List<TypeInfo> list = typeInfoService.selectTypeInfoList(typeInfo);
        return getDataTable(list);
    }

    /**
     * 导出设备类型列表
     */
    @RequiresPermissions("equip:info:export")
    @Log(title = "设备类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TypeInfo typeInfo)
    {
        List<TypeInfo> list = typeInfoService.selectTypeInfoList(typeInfo);
        ExcelUtil<TypeInfo> util = new ExcelUtil<TypeInfo>(TypeInfo.class);
        util.exportExcel(response, list, "设备类型数据");
    }

    /**
     * 获取设备类型详细信息
     */
    @RequiresPermissions("equip:info:query")
    @GetMapping(value = "/{typeId}")
    public AjaxResult getInfo(@PathVariable("typeId") Long typeId)
    {
        return success(typeInfoService.selectTypeInfoByTypeId(typeId));
    }

    /**
     * 新增设备类型
     */
    @RequiresPermissions("equip:info:add")
    @Log(title = "设备类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TypeInfo typeInfo)
    {
        return toAjax(typeInfoService.insertTypeInfo(typeInfo));
    }

    /**
     * 修改设备类型
     */
    @RequiresPermissions("equip:info:edit")
    @Log(title = "设备类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TypeInfo typeInfo)
    {
        return toAjax(typeInfoService.updateTypeInfo(typeInfo));
    }

    /**
     * 删除设备类型
     */
    @RequiresPermissions("equip:info:remove")
    @Log(title = "设备类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{typeIds}")
    public AjaxResult remove(@PathVariable Long[] typeIds)
    {
        return toAjax(typeInfoService.deleteTypeInfoByTypeIds(typeIds));
    }

    /**
     * 删除设备类型
     */
    @DeleteMapping("/remove/{typeId}")
    public AjaxResult remove(@PathVariable Long typeId)
    {
        return toAjax(typeInfoService.deleteTypeInfoByTypeId(typeId));
    }

    /**
     * 获取设备类型树结构
     * @return
     */
    @GetMapping("/treeSelect")
    public AjaxResult treeSelect(){

        return success(typeInfoService.treeSelect());
    }


}
