package com.huashe.park.application.web.controller.bd;

import com.huashe.park.core.service.IBdFenceVioEvtService;
import com.huashe.park.domain.entity.BdFenceVioEvt;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.huashe.common.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 围栏闯禁事件Controller
 *
 * @author ruoyi
 * @date 2024-10-14
 */
@RestController
@RequestMapping("/bd/fenceVioEvt")
@CrossOrigin
@Anonymous
public class BdFenceVioEvtController extends BaseController {
    @Autowired
    private IBdFenceVioEvtService bdFenceVioEvtService;

    /**
     * 查询围栏闯禁事件列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BdFenceVioEvt bdFenceVioEvt) {
        startPage();
        List<BdFenceVioEvt> list = bdFenceVioEvtService.selectBdFenceVioEvtList(bdFenceVioEvt);
        return getDataTable(list);
    }

    @GetMapping("/listAll")
    public TableDataInfo listAll(BdFenceVioEvt bdFenceVioEvt) {
        List<BdFenceVioEvt> list = bdFenceVioEvtService.selectBdFenceVioEvtList(bdFenceVioEvt);
        return getDataTable(list);
    }

    /**
     * 导出围栏闯禁事件列表
     */
    @Log(title = "围栏闯禁事件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BdFenceVioEvt bdFenceVioEvt) {
        List<BdFenceVioEvt> list = bdFenceVioEvtService.selectBdFenceVioEvtList(bdFenceVioEvt);
        ExcelUtil<BdFenceVioEvt> util = new ExcelUtil<BdFenceVioEvt>(BdFenceVioEvt.class);
        util.exportExcel(response, list, "围栏闯禁事件数据");
    }

    /**
     * 获取围栏闯禁事件详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(bdFenceVioEvtService.selectBdFenceVioEvtById(id));
    }

    /**
     * 新增围栏闯禁事件
     */
    @Log(title = "围栏闯禁事件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BdFenceVioEvt bdFenceVioEvt) {
        return toAjax(bdFenceVioEvtService.insertBdFenceVioEvt(bdFenceVioEvt));
    }

    /**
     * 修改围栏闯禁事件
     */
    @Log(title = "围栏闯禁事件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BdFenceVioEvt bdFenceVioEvt) {
        return toAjax(bdFenceVioEvtService.updateBdFenceVioEvt(bdFenceVioEvt));
    }

    /**
     * 删除围栏闯禁事件
     */
    @Log(title = "围栏闯禁事件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bdFenceVioEvtService.deleteBdFenceVioEvtByIds(ids));
    }
}
