package com.railway.web.controller.business.safetool;


import com.railway.business.safetool.domain.vo.SecExpAddParmVo;
import com.railway.business.safetool.domain.vo.SecExpEndParmVo;
import com.railway.business.safetool.domain.vo.SecExpInfoVo;
import com.railway.business.safetool.domain.vo.SecExpListParmVo;
import com.railway.business.safetool.domain.vo.SecExpListVo;
import com.railway.business.safetool.domain.vo.SecExpNQParmVo;
import com.railway.business.safetool.service.ISecExperimentService;
import com.railway.common.core.controller.BaseController;
import com.railway.common.core.domain.AjaxResult;
import com.railway.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lijie
 */
@Api(value = "rest/safetool/sec/experiment", tags = "安全工具 - 送检记录表")
@RestController
@Validated
@RequestMapping(value = "business/safetool/sec/experiment")
public class SecExperimentController extends BaseController {

  private final ISecExperimentService secExperimentService;

  public SecExperimentController(ISecExperimentService secExperimentService) {
    this.secExperimentService = secExperimentService;
  }

  @ApiOperation(value = "新增")
  @PostMapping("/add")
  public AjaxResult add(@Validated @RequestBody SecExpAddParmVo secExpAddParmVo) {
    return toAjax(secExperimentService.create(secExpAddParmVo));
  }

  @ApiOperation(value = "完成实验")
  @PostMapping("/expEnd")
  public AjaxResult expEnd(@RequestBody @Valid SecExpEndParmVo p) {
    return toAjax(secExperimentService.setExperimentState(p));
  }

  @ApiOperation(value = "设置安全工具是否合格")
  @PostMapping("/setToolNQ")
  public AjaxResult setToolNQ(@RequestBody @Valid SecExpNQParmVo p) {
    return toAjax(secExperimentService.setToolTestState(p));
  }

  @ApiOperation(value = "送检记录详情")
  @GetMapping(value = {"/", "/{id}"})
  public AjaxResult getInfo(@PathVariable String id) {
    SecExpInfoVo info = secExperimentService.getInfo(id);
    AjaxResult ajax = AjaxResult.success();
    ajax.put("info", info);
    return ajax;
  }

  @ApiOperation(value = "送检记录列表")
  @GetMapping(value = "list")
  public TableDataInfo getList(SecExpListParmVo secExperiment) {
    startPage();
    List<SecExpListVo> list = secExperimentService.getList(secExperiment);
    return getDataTable(list);
  }

}
