package com.aucma.dms.controller;

import com.aucma.common.core.controller.BaseController;
import com.aucma.common.core.domain.AjaxResult;
import com.aucma.common.core.page.TableDataInfo;
import com.aucma.common.utils.poi.ExcelUtil;
import com.aucma.dms.domain.DmsBaseShutReason;
import com.aucma.dms.service.IDmsBaseShutReasonService;
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 Open Platform
 * @date 2024-01-12
 */
@RestController
@RequestMapping("/dms/shutReason")
public class DmsBaseShutReasonController extends BaseController
{
    @Autowired
    private IDmsBaseShutReasonService dmsBaseShutReasonService;

    /**
     * 查询停机原因信息列表
     */
    //@PreAuthorize("@ss.hasPermi('dms:shutReason:list')" )
    @GetMapping("/list")
    public TableDataInfo list(DmsBaseShutReason dmsBaseShutReason)
    {
        startPage();
        List<DmsBaseShutReason> list = dmsBaseShutReasonService.selectDmsBaseShutReasonList(dmsBaseShutReason);
        return getDataTable(list);
    }

    /**
     * 导出停机原因信息列表
     */
    //@PreAuthorize("@ss.hasPermi('dms:shutReason:export')" )
    ////@Log(title = "停机原因信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DmsBaseShutReason dmsBaseShutReason)
    {
        List<DmsBaseShutReason> list = dmsBaseShutReasonService.selectDmsBaseShutReasonList(dmsBaseShutReason);
        ExcelUtil<DmsBaseShutReason> util = new ExcelUtil<DmsBaseShutReason>(DmsBaseShutReason.class);
        util.exportExcel(response, list, "停机原因信息数据");
    }

    /**
     * 获取停机原因信息详细信息
     */
    //@PreAuthorize("@ss.hasPermi('dms:shutReason:remove')" )
    @GetMapping(value = "/{shutReasonId}")
    public AjaxResult getInfo(@PathVariable("shutReasonId") Long shutReasonId)
    {
        return success(dmsBaseShutReasonService.selectDmsBaseShutReasonByShutReasonId(shutReasonId));
    }

    /**
     * 新增停机原因信息
     */
    //@PreAuthorize("@ss.hasPermi('dms:shutReason:add')" )
    ////@Log(title = "停机原因信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DmsBaseShutReason dmsBaseShutReason)
    {
        return toAjax(dmsBaseShutReasonService.insertDmsBaseShutReason(dmsBaseShutReason));
    }

    /**
     * 修改停机原因信息
     */
    //@PreAuthorize("@ss.hasPermi('dms:shutReason:edit')" )
    ////@Log(title = "停机原因信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DmsBaseShutReason dmsBaseShutReason)
    {
        return toAjax(dmsBaseShutReasonService.updateDmsBaseShutReason(dmsBaseShutReason));
    }

    /**
     * 删除停机原因信息
     */
    //@PreAuthorize("@ss.hasPermi('dms:shutReason:remove')" )
    ////@Log(title = "停机原因信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{shutReasonIds}")
    public AjaxResult remove(@PathVariable Long[] shutReasonIds)
    {
        return toAjax(dmsBaseShutReasonService.deleteDmsBaseShutReasonByShutReasonIds(shutReasonIds));
    }

    /**
     * 不分页查询所有停机原因信息列表
     */
    //@PreAuthorize("@ss.hasPermi('dms:shutReason:list')" )
    @GetMapping("/selectDmsBaseShutReasonList")
    public AjaxResult selectDmsBaseShutReasonList(DmsBaseShutReason dmsBaseShutReason)
    {
        List<DmsBaseShutReason> list = dmsBaseShutReasonService.selectDmsBaseShutReasonList(dmsBaseShutReason);
        return AjaxResult.success(list);
    }

    /**
     * 查询停机原因树
     */
    @GetMapping("/tree")
    public AjaxResult tree(@RequestParam(value = "deviceId", required = false) Long deviceId)
    {
        return success(dmsBaseShutReasonService.selectShutReasonTree(deviceId));
    }

    /**
     * 查询推荐停机原因
     */
    @GetMapping("/recommend")
    public AjaxResult recommend(@RequestParam(value = "deviceId", required = false) Long deviceId)
    {
        return success(dmsBaseShutReasonService.selectRecommendShutReasonList(deviceId));
    }
    
}
