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.P3DeviceFault;
import com.gyee.frame.model.custom.Tablepar;
import com.gyee.frame.service.health.FaultKnowledgeService;
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("/faultknowledge")
@Api(value = "故障知识" ,tags =  "故障知识")
public class FaultKnowledgeController {

    @Resource
    private FaultKnowledgeService faultKnowledgeService;



    @PostMapping("/faultknowledgeList")
    @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 = "halttype", value = "停机类型", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "faultlevel", value = "故障级别", required = true, dataType = "string", paramType = "query")})
    public AjaxResult faultknowledgeList(Tablepar tablepar, String name, String halttype, String faultlevel) {


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


        pageInfo = faultKnowledgeService.findP3DeviceFaultList(tablepar, name, halttype, faultlevel);

        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) {


        P3DeviceFault  po = new P3DeviceFault();

        po = faultKnowledgeService.findP3DeviceFaultById(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(P3DeviceFault po) {

        int result =-1;
        if(StringUtils.notEmp(po) && StringUtils.notEmp(po.getId()))
        {
            result =faultKnowledgeService.updateP3DeviceFault(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(P3DeviceFault po) {

        int result =-1;
        if(StringUtils.notEmp(po) )
        {
            result = faultKnowledgeService.insertP3DeviceFault(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 =faultKnowledgeService.deleteP3DeviceFault(id);
        }
        if (result!=-1) {
            return AjaxResult.successData(AjaxStatus.success.code, result);
        } else {
            return AjaxResult.successData(AjaxStatus.error.code, result);
        }
    }


}
