package com.fuyuanshen.web.controller.device.fence;

import java.util.List;

import com.fuyuanshen.equipment.domain.bo.DeviceFenceAccessRecordBo;
import com.fuyuanshen.equipment.domain.vo.DeviceFenceAccessRecordVo;
import com.fuyuanshen.equipment.service.IDeviceFenceAccessRecordService;
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.common.mybatis.core.page.TableDataInfo;

/**
 * 围栏进出记录
 *
 * @author Lion Li
 * @date 2025-09-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/equipment/fenceAccessRecord")
public class DeviceFenceAccessRecordController extends BaseController {

    private final IDeviceFenceAccessRecordService deviceFenceAccessRecordService;


    /**
     * 查询围栏进出记录列表
     */
    @SaCheckPermission("fys-equipment:fenceAccessRecord:list")
    @GetMapping("/list")
    public TableDataInfo<DeviceFenceAccessRecordVo> list(DeviceFenceAccessRecordBo bo, PageQuery pageQuery) {
        return deviceFenceAccessRecordService.queryPageList(bo, pageQuery);
    }


    /**
     * 导出围栏进出记录列表
     */
    @SaCheckPermission("fys-equipment:fenceAccessRecord:export")
    @Log(title = "导出围栏进出记录列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(DeviceFenceAccessRecordBo bo, HttpServletResponse response) {
        List<DeviceFenceAccessRecordVo> list = deviceFenceAccessRecordService.queryList(bo);
        ExcelUtil.exportExcel(list, "围栏进出记录", DeviceFenceAccessRecordVo.class, response);
    }


    /**
     * 获取围栏进出记录详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("fys-equipment:fenceAccessRecord:query")
    @GetMapping("/{id}")
    public R<DeviceFenceAccessRecordVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(deviceFenceAccessRecordService.queryById(id));
    }

    /**
     * 新增围栏进出记录
     */
    @SaCheckPermission("fys-equipment:fenceAccessRecord:add")
    @Log(title = "围栏进出记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody DeviceFenceAccessRecordBo bo) {
        return toAjax(deviceFenceAccessRecordService.insertByBo(bo));
    }

    /**
     * 修改围栏进出记录
     */
    @SaCheckPermission("fys-equipment:fenceAccessRecord:edit")
    @Log(title = "围栏进出记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody DeviceFenceAccessRecordBo bo) {
        return toAjax(deviceFenceAccessRecordService.updateByBo(bo));
    }

    /**
     * 删除围栏进出记录
     *
     * @param ids 主键串
     */
    @SaCheckPermission("fys-equipment:fenceAccessRecord:remove")
    @Log(title = "围栏进出记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(deviceFenceAccessRecordService.deleteWithValidByIds(List.of(ids), true));
    }


}
