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

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.huashe.common.domain.AjaxResult;
import com.huashe.park.core.service.IBdFenceInfoService;
import com.huashe.park.domain.entity.BdFenceInfo;
import com.huashe.park.infrastructure.socket.server.UwbVideoTraceSocketServer;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 围栏基础信息Controller
 *
 * @author ruoyi
 * @date 2024-10-14
 */
@RestController
@RequestMapping("/bd/fenceInfo")
@CrossOrigin
@Anonymous
public class BdFenceInfoController extends BaseController {
    @Autowired
    private IBdFenceInfoService bdFenceInfoService;

    @Resource
    private UwbVideoTraceSocketServer uwbVideoTraceSocket;

    /**
     * 查询围栏基础信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BdFenceInfo bdFenceInfo) {
//        testSocket.sendMessage("test", JSON.parseObject(JSON.toJSONString(new BdFenceInfo() {{
//            setAltitude(22);
//        }})));
        startPage();
        List<BdFenceInfo> list = bdFenceInfoService.selectBdFenceInfoList(bdFenceInfo);
        return getDataTable(list);
    }

    /**
     * 导出围栏基础信息列表
     */
    @Log(title = "围栏基础信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BdFenceInfo bdFenceInfo) {
        List<BdFenceInfo> list = bdFenceInfoService.selectBdFenceInfoList(bdFenceInfo);
        ExcelUtil<BdFenceInfo> util = new ExcelUtil<BdFenceInfo>(BdFenceInfo.class);
        util.exportExcel(response, list, "围栏基础信息数据");
    }

    /**
     * 获取围栏基础信息详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(bdFenceInfoService.selectBdFenceInfoById(id));
    }

    /**
     * 新增围栏基础信息
     */
    @Log(title = "围栏基础信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BdFenceInfo bdFenceInfo) {
        return toAjax(bdFenceInfoService.insertBdFenceInfo(bdFenceInfo));
    }

    /**
     * 修改围栏基础信息
     */
    @Log(title = "围栏基础信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BdFenceInfo bdFenceInfo) {
        return toAjax(bdFenceInfoService.updateBdFenceInfo(bdFenceInfo));
    }

    /**
     * 删除围栏基础信息
     */
    @Log(title = "围栏基础信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bdFenceInfoService.deleteBdFenceInfoByIds(ids));
    }
}
