package com.gyee.frame.controller.health;

import com.github.pagehelper.PageInfo;
import com.gyee.frame.common.conf.AjaxStatus;
import com.gyee.frame.common.domain.AjaxResult;
import com.gyee.frame.model.auto.Alertrule2;
import com.gyee.frame.model.custom.Tablepar;
import com.gyee.frame.service.Alertrule2ervice;
import com.gyee.frame.util.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("/earlyWarnKnowledge")
@Api(value = "预警知识" ,tags =  "预警知识")
public class EarlyWarnKnowledgeController {

    @Resource
    private Alertrule2ervice alertrule2ervice;


    @PostMapping("/earlyWarnKnowledgeList")
    @ResponseBody
    @ApiOperation(value = "预警知识列表", notes = "预警知识列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tablepar", value = "分页排序对象", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "预警名称", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "category", value = "预警类型", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "rank", value = "预警级别", required = true, dataType = "string", paramType = "query")})
    public AjaxResult earlyWarnKnowledgeList(Tablepar tablepar, String name, String category, String rank) {


        PageInfo<Alertrule2> pageInfo = new PageInfo<>();


        pageInfo = alertrule2ervice.getAlertruleList(tablepar, name, category, rank);

        if (null!=pageInfo) {
            return AjaxResult.successData(AjaxStatus.success.code, pageInfo);
        } else {
            return AjaxResult.successData(AjaxStatus.error.code, pageInfo);
        }

    }

    @PostMapping("/findFaultknowledge")
    @ResponseBody
    @ApiOperation(value = "通过主键查询预警知识", notes = "通过主键查询预警知识")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "编号", required = true, dataType = "string", paramType = "query")})
    public AjaxResult findFaultknowledge(String id) {


        Alertrule2  po = new Alertrule2();

        po = alertrule2ervice.findAlertrule2ById(id);

        if (null!=po) {
            return AjaxResult.successData(AjaxStatus.success.code, po);
        } else {
            return AjaxResult.successData(AjaxStatus.error.code, po);
        }

    }
    @PostMapping("/updateFaultknowledge")
    @ResponseBody
    @ApiOperation(value = "修改预警知识", notes = "修改预警知识")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "po", value = "预警知识对象", required = true, dataType = "string", paramType = "query")})
    public AjaxResult updateFaultknowledge(Alertrule2 po) {

        int result =-1;
        if(StringUtils.notEmp(po) && StringUtils.notEmp(po.getId()))
        {
            result =alertrule2ervice.updateAlertrule2(po);
        }
        if (result!=-1) {
            return AjaxResult.successData(AjaxStatus.success.code, result);
        } else {
            return AjaxResult.successData(AjaxStatus.error.code, result);
        }
    }
    @PostMapping("/insertFaultknowledge")
    @ResponseBody
    @ApiOperation(value = "新增预警知识", notes = "新增预警知识")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "po", value = "预警知识对象", required = true, dataType = "string", paramType = "query")})

    public AjaxResult insertFaultknowledge(Alertrule2 po) {

        int result =-1;
        if(StringUtils.notEmp(po) )
        {
            result = alertrule2ervice.insertAlertrule2(po);
        }
        if (result!=-1) {
            return AjaxResult.successData(AjaxStatus.success.code, result);
        } else {
            return AjaxResult.successData(AjaxStatus.error.code, result);
        }

    }
    @PostMapping("/deleteFaultknowledge")
    @ResponseBody
    @ApiOperation(value = "删除预警知识", notes = "删除预警知识")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "预警知识编号", required = true, dataType = "string", paramType = "query")})

    public AjaxResult deleteFaultknowledge(String id) {

        int result =-1;
        if(StringUtils.notEmp(id))
        {
            result =alertrule2ervice.deleteAlertrule2(id);
        }
        if (result!=-1) {
            return AjaxResult.successData(AjaxStatus.success.code, result);
        } else {
            return AjaxResult.successData(AjaxStatus.error.code, result);
        }
    }


}
