package com.mosty.yjzl.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mosty.base.model.query.yjzl.TbYjmxQuery;
import com.mosty.base.model.vo.yjzl.TbYjmxAllVo;
import com.mosty.base.model.vo.yjzl.TbYjmxVo;
import com.mosty.common.base.domain.ResponseResult;
import com.mosty.common.base.entity.log.BusinessType;
import com.mosty.common.base.entity.log.Log;
import com.mosty.common.token.JwtSysUser;
import com.mosty.yjzl.service.TbYjmxService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;



@Api(tags = "预警模型接口")
@AllArgsConstructor
@RestController
@RequestMapping("/tbYjmx")
public class TbYjmxController {

    private TbYjmxService tbYjmxService;

    @ApiOperation("新增数据")
    @JwtSysUser
    @PostMapping
    @Log(title = "预警模型新增", businessType = BusinessType.INSERT)
    public ResponseResult<Integer> add(@RequestBody TbYjmxVo vo){
        return ResponseResult.success(tbYjmxService.insert(vo));
    }

    @ApiOperation("更新数据")
    @JwtSysUser
    @PutMapping
    @Log(title = "预警模型更新", businessType = BusinessType.UPDATE)
    public ResponseResult<Integer> edit(@RequestBody TbYjmxVo clVo){
        return ResponseResult.success(tbYjmxService.updateById(clVo));
    }

    @ApiOperation("分页查询")
    @JwtSysUser
    @GetMapping
    @Log(title = "分页查询", businessType = BusinessType.OTHER)
    public ResponseResult<IPage<TbYjmxVo>> getPage(TbYjmxQuery dto){
        return ResponseResult.success(tbYjmxService.getPage(dto));
    }

    @ApiOperation("删除数据")
    @JwtSysUser
    @DeleteMapping("/{id}")
    @Log(title = "预警模型删除", businessType = BusinessType.DELETE)
    public ResponseResult<Integer> update(@PathVariable("id") String id){
        return ResponseResult.success(tbYjmxService.deleteById(id));
    }

    @ApiOperation("启动、停止模型")
    @JwtSysUser
    @GetMapping("/{id}")
    @Log(title = "启动、停止模型", businessType = BusinessType.DELETE)
    public ResponseResult<Integer> start(@PathVariable("id") String id){
        return ResponseResult.success(tbYjmxService.startMx(id));
    }

    @ApiOperation("查询模型参数详情信息")
    @JwtSysUser
    @PostMapping("/getMxCs/{mxid}")
    public ResponseResult<TbYjmxAllVo> getMxCs(@PathVariable("mxid") String mxid){
        return ResponseResult.success(this.tbYjmxService.getMxCs(mxid));
    }
}
