package com.fuyuanshen.equipment.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.fuyuanshen.common.idempotent.annotation.RepeatSubmit;
import com.fuyuanshen.common.log.annotation.Log;
import com.fuyuanshen.common.web.core.BaseController;
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
import com.fuyuanshen.common.core.domain.R;
import com.fuyuanshen.common.core.validate.AddGroup;
import com.fuyuanshen.common.core.validate.EditGroup;
import com.fuyuanshen.common.log.enums.BusinessType;
import com.fuyuanshen.common.excel.utils.ExcelUtil;
import com.fuyuanshen.equipment.domain.vo.DeviceFenceStatusVo;
import com.fuyuanshen.equipment.domain.bo.DeviceFenceStatusBo;
import com.fuyuanshen.equipment.service.IDeviceFenceStatusService;
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;

/**
 * 设备进入围栏状态
 *
 * @author Lion Li
 * @date 2025-09-15
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/equipment/fenceStatus")
public class DeviceFenceStatusController extends BaseController {

    private final IDeviceFenceStatusService deviceFenceStatusService;

    /**
     * 查询设备进入围栏状态列表
     */
    @SaCheckPermission("equipment:fenceStatus:list")
    @GetMapping("/list")
    public TableDataInfo<DeviceFenceStatusVo> list(DeviceFenceStatusBo bo, PageQuery pageQuery) {
        return deviceFenceStatusService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出设备进入围栏状态列表
     */
    @SaCheckPermission("equipment:fenceStatus:export")
    @Log(title = "设备进入围栏状态", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(DeviceFenceStatusBo bo, HttpServletResponse response) {
        List<DeviceFenceStatusVo> list = deviceFenceStatusService.queryList(bo);
        ExcelUtil.exportExcel(list, "设备进入围栏状态", DeviceFenceStatusVo.class, response);
    }

    /**
     * 获取设备进入围栏状态详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("equipment:fenceStatus:query")
    @GetMapping("/{id}")
    public R<DeviceFenceStatusVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(deviceFenceStatusService.queryById(id));
    }

    /**
     * 新增设备进入围栏状态
     */
    @SaCheckPermission("equipment:fenceStatus:add")
    @Log(title = "设备进入围栏状态", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody DeviceFenceStatusBo bo) {
        return toAjax(deviceFenceStatusService.insertByBo(bo));
    }

    /**
     * 修改设备进入围栏状态
     */
    @SaCheckPermission("equipment:fenceStatus:edit")
    @Log(title = "设备进入围栏状态", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody DeviceFenceStatusBo bo) {
        return toAjax(deviceFenceStatusService.updateByBo(bo));
    }

    /**
     * 删除设备进入围栏状态
     *
     * @param ids 主键串
     */
    @SaCheckPermission("equipment:fenceStatus:remove")
    @Log(title = "设备进入围栏状态", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(deviceFenceStatusService.deleteWithValidByIds(List.of(ids), true));
    }
}
