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


import com.railway.business.safetool.domain.SecScheduled;
import com.railway.business.safetool.domain.vo.*;
import com.railway.business.safetool.service.ISecScheduledService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.WebDataBinder;
import com.railway.common.core.controller.BaseController;
import com.railway.common.core.domain.AjaxResult;
import com.railway.common.core.page.TableDataInfo;
import javax.validation.Valid;
import java.util.List;

import javax.validation.Valid;

@Api(value = "rest/safetool/sec/scheduled", tags = "安全工具-计划")
@RestController
@Validated
@RequestMapping(value = "business/safetool/sec/scheduled")
public class SecScheduledController extends BaseController {
    @Autowired
    private ISecScheduledService secScheduledService;

    @ApiOperation(value = "新增")
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody SecScheduledListVo secScheduled) {
        try {
            return toAjax(secScheduledService.create(secScheduled));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return toAjax(0);
    }

    @ApiOperation(value = "删除计划")
    @DeleteMapping("/{ids}")
    public AjaxResult delete(@RequestParam String[] ids) {
        return toAjax(secScheduledService.delete(ids));
    }

//    @ApiOperation(value = "更新")
    @PutMapping("/update")
    public AjaxResult update(@RequestBody @Valid SecScheduled secScheduled) {
        return toAjax(secScheduledService.update(secScheduled));
    }

    @ApiOperation(value = "查询详情")
    @GetMapping(value = {"/", "/{id}"})
    public AjaxResult getInfo(String id) {
        List<SecScheduledDetailVo> info = secScheduledService.getInfo(id);
        AjaxResult ajax = AjaxResult.success();
        ajax.put("info",info);
        return ajax;
    }

    @ApiOperation(value = "查询列表")
    @GetMapping(value = "list")
    public TableDataInfo getList(SecScheduledListParmVo secScheduled) {
        startPage();
        List<SecScheduledListVo2> list = secScheduledService.getList(secScheduled);
        return getDataTable(list);
    }


    @ApiOperation(value = "删除计划中的安全工具")
    @DeleteMapping(value = "delTools")
    public AjaxResult delTools(SecScheduledToolsAddVo secScheduled) {
        try {
            return toAjax(secScheduledService.delTools(secScheduled));
        } catch (Exception e) {
            return toAjax(0);
        }

    }

    @ApiOperation(value = "增加计划中的安全工具")
    @PostMapping(value = "addTools")
    public AjaxResult addTools(SecScheduledToolsAddVo secScheduled) {
        try {
            return toAjax(secScheduledService.addTools(secScheduled));
        } catch (Exception e) {
            return toAjax(0);
        }

    }
}
