/**
 * 20241029 ©WANGKANG 1686617586@qq.com
 */

package com.taais.biz.controller;

import com.taais.biz.domain.bo.ToInfraredBo;
import com.taais.biz.domain.vo.ToInfraredVo;
import com.taais.biz.service.IToInfraredService;
import com.taais.common.core.core.page.PageResult;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.taais.common.core.core.domain.CommonResult;
import com.taais.common.excel.utils.ExcelUtil;
import com.taais.common.log.annotation.Log;
import com.taais.common.log.enums.BusinessType;
import com.taais.common.web.annotation.RepeatSubmit;
import com.taais.common.web.core.BaseController;
import jakarta.annotation.Resource;

import java.io.IOException;
import java.util.List;

/**
 * 可见光转红外Controller
 *
 * @author 0
 * 2024-09-20
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/demo/toInfrared")
public class ToInfraredController extends BaseController {
    @Resource
    private IToInfraredService toInfraredService;
    private Long ossId;

    /**
     * 查询可见光转红外列表
     */
    @SaCheckPermission("demo:toInfrared:list")
    @GetMapping("/list")
    public CommonResult<PageResult<ToInfraredVo>> list(ToInfraredBo toInfraredBo) {
        return CommonResult.success(toInfraredService.selectPage(toInfraredBo));
    }

    /**
     * 导出可见光转红外列表
     */
    @SaCheckPermission("demo:toInfrared:export")
    @Log(title = "可见光转红外", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ToInfraredBo toInfraredBo) {
        List<ToInfraredVo> list = toInfraredService.selectList(toInfraredBo);
        ExcelUtil.exportExcel(list, "可见光转红外", ToInfraredVo.class, response);
    }

    /**
     * 获取可见光转红外详细信息
     */
    @SaCheckPermission("demo:toInfrared:query")
    @GetMapping(value = "/{id}")
    public CommonResult<ToInfraredVo> getInfo(@PathVariable Long id) {
        return CommonResult.success(toInfraredService.selectById(id));
    }

    /**
     * 新增可见光转红外
     */
    @SaCheckPermission("demo:toInfrared:add")
    @Log(title = "可见光转红外", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping
    public CommonResult<Void> add(@Validated @RequestBody ToInfraredBo toInfraredBo) {
        boolean inserted = toInfraredService.insert(toInfraredBo);
        if (!inserted) {
            return CommonResult.fail("新增可见光转红外记录失败！");
        }
        return CommonResult.success();
    }

    /**
     * 修改可见光转红外
     */
    @SaCheckPermission("demo:toInfrared:edit")
    @Log(title = "可见光转红外", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping
    public CommonResult<Void> edit(@Validated @RequestBody ToInfraredBo toInfraredBo) {
        Boolean updated = toInfraredService.update(toInfraredBo);
        if (!updated) {
            return CommonResult.fail("修改可见光转红外记录失败!");
        }
        return CommonResult.success();
    }

    /**
     * 删除可见光转红外
     */
    @SaCheckPermission("demo:toInfrared:remove")
    @Log(title = "可见光转红外", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public CommonResult<Void> remove(@PathVariable Long[] ids) {
        boolean deleted = toInfraredService.deleteByIds(ids);
        if (!deleted) {
            return CommonResult.fail("删除可见光转红外记录失败!");
        }
        return CommonResult.success();
    }

    @GetMapping("/start/{id}")
    public CommonResult start(@PathVariable("id") Long id) {
        return toInfraredService.start(id);
    }

    @GetMapping("/stop/{id}")
    public CommonResult stop(@PathVariable("id") Long id) {
        return toInfraredService.stop(id);
    }

    @GetMapping("/zip/{id}")
    public ResponseEntity<org.springframework.core.io.Resource> zipFolder(@PathVariable("id") Long id) throws IOException {
        /**
         * 传VideoImage的ID
         */
        return toInfraredService.zipImages(id);
    }

    @GetMapping("/log/{id}")
    public CommonResult getLog(@PathVariable("id") Long id) {
        return toInfraredService.getLog(id);
    }

    @GetMapping("/model/{id}")
    public CommonResult getModelList(@PathVariable("id") Long id) {
        return toInfraredService.getModelList(id);
    }

    @GetMapping("/previewPredictResult/{id}")
    public CommonResult previewPredictResult(@PathVariable("id") Long id) {
        return toInfraredService.previewPredictResult(id);
    }
}
