package com.artfess.rescue.patrol.controller;


import com.artfess.base.annotation.ApiGroup;
import com.artfess.base.constants.ApiGroupConsts;
import com.artfess.base.enums.ResponseErrorEnums;
import com.artfess.base.model.CommonResult;
import com.artfess.base.query.PageList;
import com.artfess.base.query.QueryFilter;
import com.artfess.base.query.QueryOP;
import com.artfess.base.valid.AddGroup;
import com.artfess.base.valid.UpdateGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.quartz.SchedulerException;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.artfess.base.controller.BaseController;
import com.artfess.rescue.patrol.model.BizInspectionVideoConf;
import com.artfess.rescue.patrol.manager.BizInspectionVideoConfManager;


/**
 * 视频巡检任务表 前端控制器
 *
 * @author 系统管理员
 * @since 2024-11-27
 */
@RestController
@RequestMapping("/bizInspectionVideoConf/v1/")
@Api(tags = "视频巡检配置表")
@ApiGroup(group = {ApiGroupConsts.GROUP_BIZ_RESCUE})
public class BizInspectionVideoConfController extends BaseController<BizInspectionVideoConfManager, BizInspectionVideoConf> {

    @PostMapping("/saveOrUpdate")
    @ApiOperation("添加或修改巡检任务")
    public CommonResult<String> saveOrUpdate(@ApiParam(name = "model", value = "巡检任务") @Validated({AddGroup.class, UpdateGroup.class}) @RequestBody BizInspectionVideoConf videoConf) throws Exception {
         return baseService.saveOrUpdateInfo(videoConf);
    }

    @PostMapping(value = "/toggleTriggerRun")
    @ApiOperation(value = "启用或停止配置", httpMethod = "POST", notes = "启用或停止培训配置")
    public CommonResult<String> start(@ApiParam(name = "id", value = "配置id", required = false) @RequestParam String id) throws Exception {
        boolean result = baseService.toggleTriggerRun(id);
        if (result) {
            return new CommonResult<>("操作成功！");
        } else {
            return new CommonResult<>(ResponseErrorEnums.FAIL_OPTION, "操作失败！");
        }
    }

    @PostMapping(value = "/executeJob")
    @ApiOperation(value = "执行定时配置", httpMethod = "POST", notes = "执行定时配置")
    public CommonResult<String> executeJob(@ApiParam(name = "id", value = "配置id", required = true) @RequestParam String id) throws SchedulerException {
        boolean result = baseService.executeJob(id);
        if (result) {
            return new CommonResult<>("执行配置成功！");
        } else {
            return new CommonResult<>(ResponseErrorEnums.FAIL_OPTION, "执行配置失败！");
        }
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询实体")
    @Override
    public BizInspectionVideoConf getById(@ApiParam(name = "id", value = "实体id") @PathVariable String id) {
        return baseService.getInfoById(id);
    }

    @PostMapping(value = "/query", produces = {"application/json; charset=utf-8"})
    @ApiOperation("分页查询结果")
    @Override
    public PageList<BizInspectionVideoConf> query(@ApiParam(name = "queryFilter", value = "分页查询信息") @RequestBody QueryFilter<BizInspectionVideoConf> queryFilter) {
        // 非系统管理员自能查询自己部门的任务，本级的人员可以看全部
//        if (!baseContext.getCurrentOrgId().equals(SystemConstants.SYS_ORG_ID) && !baseContext.isAdmin()) {
//            permissionControllerUtils.addDeptPermission(queryFilter);
//        }
        queryFilter.addFilter("is_dele_","0", QueryOP.EQUAL);
        return baseService.queryInfo(queryFilter);
    }


}
