package com.ruoyi.business.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.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.business.domain.HwFenceTarget;
import com.ruoyi.business.service.IHwFenceTargetService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 电子围栏目标Controller
 * 
 * @author xins
 * @date 2023-09-04
 */
@RestController
@RequestMapping("/fenceTarget")
public class HwFenceTargetController extends BaseController
{
    @Autowired
    private IHwFenceTargetService hwFenceTargetService;

    /**
     * 查询电子围栏目标列表
     */
    @RequiresPermissions("business:fenceTarget:list")
    @GetMapping("/list")
    public TableDataInfo list(HwFenceTarget hwFenceTarget)
    {
        startPage();
        List<HwFenceTarget> list = hwFenceTargetService.selectHwFenceTargetList(hwFenceTarget);
        return getDataTable(list);
    }

    /**
     * 导出电子围栏目标列表
     */
    @RequiresPermissions("business:fenceTarget:export")
    @Log(title = "电子围栏目标", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HwFenceTarget hwFenceTarget)
    {
        List<HwFenceTarget> list = hwFenceTargetService.selectHwFenceTargetList(hwFenceTarget);
        ExcelUtil<HwFenceTarget> util = new ExcelUtil<HwFenceTarget>(HwFenceTarget.class);
        util.exportExcel(response, list, "电子围栏目标数据");
    }

    /**
     * 获取电子围栏目标详细信息
     */
    @RequiresPermissions("business:fenceTarget:query")
    @GetMapping(value = "/{targetId}")
    public AjaxResult getInfo(@PathVariable("targetId") Long targetId)
    {
        return success(hwFenceTargetService.selectHwFenceTargetByTargetId(targetId));
    }

    /**
     * 新增电子围栏目标
     */
    @RequiresPermissions("business:fenceTarget:add")
    @Log(title = "电子围栏目标", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HwFenceTarget hwFenceTarget)
    {
        return toAjax(hwFenceTargetService.insertHwFenceTarget(hwFenceTarget));
    }

    /**
     * 修改电子围栏目标
     */
    @RequiresPermissions("business:fenceTarget:edit")
    @Log(title = "电子围栏目标", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HwFenceTarget hwFenceTarget)
    {
        return toAjax(hwFenceTargetService.updateHwFenceTarget(hwFenceTarget));
    }

    /**
     * 删除电子围栏目标
     */
    @RequiresPermissions("business:fenceTarget:remove")
    @Log(title = "电子围栏目标", businessType = BusinessType.DELETE)
	@DeleteMapping("/{targetIds}")
    public AjaxResult remove(@PathVariable Long[] targetIds)
    {
        return toAjax(hwFenceTargetService.deleteHwFenceTargetByTargetIds(targetIds));
    }
}
