package com.project.zcustom.controller.backManager.engineering;

import com.project.common.annotation.Log;
import com.project.common.core.controller.BaseController;
import com.project.common.core.domain.AjaxResult;
import com.project.common.enums.BusinessType;
import com.project.common.utils.poi.ExcelUtil;
import com.project.zcustom.domain.addional.LargeCamera;
import com.project.zcustom.service.unit.ILargeCameraService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 摄像头Controller
 *
 * @author change
 * @date 2024-12-30
 */
@RestController
@RequestMapping("/zcustom/camera")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class LargeCameraController extends BaseController {

    private final ILargeCameraService largeCameraService;

    @GetMapping("/list")
    public AjaxResult list(LargeCamera entity) {
        return AjaxResult.success("查询成功", largeCameraService.pagingLargeCameraList(entity));
    }

    @GetMapping("/listAll")
    public AjaxResult listAll(LargeCamera entity) {
        return AjaxResult.success("查询成功", largeCameraService.selectLargeCameraList(entity));
    }

    @Log(title = "摄像头", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LargeCamera entity) {
        List<LargeCamera> list = largeCameraService.selectLargeCameraList(entity);
        ExcelUtil<LargeCamera> util = new ExcelUtil<>(LargeCamera.class);
        util.exportExcel(response, list, "摄像头数据");
    }

    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success("查询成功", largeCameraService.getById(id));
    }

    @PreAuthorize("@ss.hasPermi('zcustom:camera:add')")
    @Log(title = "摄像头", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody LargeCamera entity) {
        return toAjax(largeCameraService.save(entity));
    }

    @PreAuthorize("@ss.hasPermi('zcustom:camera:edit')")
    @Log(title = "摄像头", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody LargeCamera entity) {
        return toAjax(largeCameraService.updateById(entity));
    }

    @PreAuthorize("@ss.hasPermi('zcustom:camera:remove')")
    @Log(title = "摄像头", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(largeCameraService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }


    /**
     * 某项目已接入摄像头
     */
    @GetMapping("/getConnectCameraNumByProject/{projectId}")
    public AjaxResult getConnectCameraNumByProject(@PathVariable Long projectId){
        return AjaxResult.success("查询成功", largeCameraService.getConnectCameraNumByProject(projectId));
    }

    /**
     * 在线摄像头数量
     */
    @GetMapping("/getConnectOnlineCameraNum")
    public AjaxResult getConnectOnlineCameraNum() {
        return AjaxResult.success("查询成功", largeCameraService.getConnectOnlineCameraNum());
    }
}
