package com.unis.base.server.controller;

import com.github.pagehelper.PageInfo;
import com.unis.base.common.vo.*;
import com.unis.base.server.service.FacilityService;
import com.unis.common.utils.ResponseWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.Value;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

/**
 * @Author ChenKai
 * @Date 2019/9/19 18:37
 * @Version 1.0
 */

@RestController
@Api(value = "消防器材配置台账", tags = "消防器材配置台账")
@Slf4j
public class FacilityController {

    @Autowired
    private FacilityService facilityService;

    //设备报废记录
    @ApiOperation(value = "设备报废记录(分页)", notes = "参数：")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "起始页", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页展示行数", required = true),
            @ApiImplicitParam(name = "lx", value = "1：设备，2：设施，3：仪器", required = true)})

    @PostMapping(value = "/findFacility")
    public ResponseWrapper findFacility(@RequestBody DSbxxsjyQueryVO vo,
                                        @RequestParam(value = "pageNum") Integer pageNum,
                                        @RequestParam(value = "pageSize") Integer pageSize,
                                        @RequestParam(value = "lx") Integer lx){
        try {
            PageInfo<DsbbfxxVO> pageInfos = new PageInfo<DsbbfxxVO>(facilityService.findFacility(vo,pageNum,pageSize,lx));

            return ResponseWrapper.success(HttpStatus.OK.value(),HttpStatus.OK.getReasonPhrase(),pageInfos);
        }catch (Exception e){
            e.printStackTrace();
            log.error(e.getMessage());
        }
        return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(),HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(),"服务错误，请联系管理员");
    }

    //设备报废记录详情
    @ApiOperation(value = "设备报废记录详情", notes = "参数：")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "起始页", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页展示行数", required = true)})
    @PostMapping(value = "/findFacilityById")
    public ResponseWrapper findFacilityById(@RequestBody DSbxxsjyQueryVO vo,
                                            @RequestParam(value = "pageNum") Integer pageNum,
                                            @RequestParam(value = "pageSize") Integer pageSize){
        try {
            MachineVO machineVO = facilityService.findFacilityById(vo,pageNum,pageSize);
            return ResponseWrapper.success(HttpStatus.OK.value(),HttpStatus.OK.getReasonPhrase(),machineVO);
        }catch (Exception e){
            e.printStackTrace();
            log.error(e.getMessage());
        }
        return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(),HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(),"服务错误，请联系管理员");
    }

    //设备维护分页
    @ApiOperation(value = "设备维护分页", notes = "参数：")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "起始页", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页展示行数", required = true),
            @ApiImplicitParam(name = "lx", value = "1：设备，2：设施，3：仪器", required = true)})
    @PostMapping(value = "/findVindicate")
    public ResponseWrapper findVindicate(@RequestBody DSbxxsjyQueryVO vo,
                                         @RequestParam(value = "pageNum") Integer pageNum,
                                         @RequestParam(value = "pageSize") Integer pageSize,
                                         @RequestParam(value = "lx") Integer lx){
        try {
            PageInfo<DsbwhxxVO> pageInfos = new PageInfo<DsbwhxxVO>(facilityService.findVindicate(vo,pageNum,pageSize,lx));
            return ResponseWrapper.success(HttpStatus.OK.value(),HttpStatus.OK.getReasonPhrase(),pageInfos);
        }catch (Exception e){
            e.printStackTrace();
            log.error(e.getMessage());
        }
        return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(),HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(),"服务错误，请联系管理员");
    }

    //设备维护详情
    @ApiOperation(value = "设备维护详情", notes = "参数：")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "起始页", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页展示行数", required = true)})
    @PostMapping(value = "/findVindicateById")
    public ResponseWrapper findVindicateById(@RequestBody DSbxxsjyQueryVO vo,
                                             @RequestParam(value = "pageNum") Integer pageNum,
                                             @RequestParam(value = "pageSize") Integer pageSize){
        try {
            MachineVO machineVO = facilityService.findVindicateById(vo,pageNum,pageSize);
            return ResponseWrapper.success(HttpStatus.OK.value(),HttpStatus.OK.getReasonPhrase(),machineVO);
        }catch (Exception e){
            e.printStackTrace();
            log.error(e.getMessage());
        }
        return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(),HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(),"服务错误，请联系管理员");
    }

    //设备维修分页
    @ApiOperation(value = "设备维修分页", notes = "参数：")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "起始页", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页展示行数", required = true),
            @ApiImplicitParam(name = "lx", value = "1：设备，2：设施，3：仪器", required = true)})
    @PostMapping(value = "/findMaintain")
    public ResponseWrapper findMaintain(@RequestBody DSbxxsjyQueryVO vo,
                                        @RequestParam(value = "pageNum") Integer pageNum,
                                        @RequestParam(value = "pageSize") Integer pageSize,
                                        @RequestParam(value = "lx") Integer lx){
        try {
            PageInfo<DSbwxxxVO> pageInfos = new PageInfo<DSbwxxxVO>(facilityService.findMaintain(vo,pageNum,pageSize,lx));
            return ResponseWrapper.success(HttpStatus.OK.value(),HttpStatus.OK.getReasonPhrase(),pageInfos);
        }catch (Exception e){
            e.printStackTrace();
            log.error(e.getMessage());
        }
        return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(),HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(),"服务错误，请联系管理员");
    }

    //设备维修详情
    @ApiOperation(value = "设备维修详情", notes = "参数：")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "起始页", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页展示行数", required = true)})
    @PostMapping(value = "/findMaintainById")
    public ResponseWrapper findMaintainById(@RequestBody DSbxxsjyQueryVO vo,
                                            @RequestParam(value = "pageNum") Integer pageNum,
                                            @RequestParam(value = "pageSize") Integer pageSize){
        try {
            MachineVO machineVO = facilityService.findMaintainById(vo,pageNum,pageSize);
            return ResponseWrapper.success(HttpStatus.OK.value(),HttpStatus.OK.getReasonPhrase(),machineVO);
        }catch (Exception e){
            e.printStackTrace();
            log.error(e.getMessage());
        }
        return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(),HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(),"服务错误，请联系管理员");
    }

    //设备领用分页
    @ApiOperation(value = "设备领用分页", notes = "参数：")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "起始页", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页展示行数", required = true)})
    @PostMapping(value = "/findReceive")
    public ResponseWrapper findReceive(@RequestBody DSbxxsjyQueryVO vo,
                                       @RequestParam(value = "pageNum") Integer pageNum,
                                       @RequestParam(value = "pageSize") Integer pageSize,
                                       @RequestParam(value = "lx") Integer lx){
        try {
            PageInfo<DsblyxxVO> pageInfos = new PageInfo<DsblyxxVO>(facilityService.findReceive(vo,pageNum,pageSize,lx));
            return ResponseWrapper.success(HttpStatus.OK.value(),HttpStatus.OK.getReasonPhrase(),pageInfos);
        }catch (Exception e){
            e.printStackTrace();
            log.error(e.getMessage());
        }
        return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(),HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(),"服务错误，请联系管理员");
    }

    //设备领用详情
    @ApiOperation(value = "设备领用详情", notes = "参数：设备编号(sbbh)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "起始页", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页展示行数", required = true)})
    @PostMapping(value = "/findReceiveById")
    public ResponseWrapper findReceiveById(@RequestBody DSbxxsjyQueryVO vo,
                                           @RequestParam(value = "pageNum") Integer pageNum,
                                           @RequestParam(value = "pageSize") Integer pageSize){
        try {
            MachineVO machineVO = facilityService.findReceiveById(vo,pageNum,pageSize);
            return ResponseWrapper.success(HttpStatus.OK.value(),HttpStatus.OK.getReasonPhrase(),machineVO);
        }catch (Exception e){
            e.printStackTrace();
            log.error(e.getMessage());
        }
        return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(),HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(),"服务错误，请联系管理员");
    }

    //设备入库分页
    @ApiOperation(value = "设备入库分页", notes = "参数：")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "起始页", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页展示行数", required = true),
            @ApiImplicitParam(name = "lx", value = "1：设备，2：设施，3：仪器", required = true)})
    @PostMapping(value = "/findStorage")
    public ResponseWrapper findStorage(@RequestBody DSbxxsjyQueryVO vo,
                                       @RequestParam(value = "pageNum") Integer pageNum,
                                       @RequestParam(value = "pageSize") Integer pageSize,
                                       @RequestParam(value = "lx") Integer lx){
        try {
            PageInfo<DSbxxsjyVO> pageInfos = new PageInfo<DSbxxsjyVO>(facilityService.findStorage(vo,pageNum,pageSize,lx));
            return ResponseWrapper.success(HttpStatus.OK.value(),HttpStatus.OK.getReasonPhrase(),pageInfos);
        }catch (Exception e){
            e.printStackTrace();
            log.error(e.getMessage());
        }
        return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(),HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(),"服务错误，请联系管理员");
    }

    //设备入库详情
    @ApiOperation(value = "设备入库详情", notes = "参数：")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "起始页", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页展示行数", required = true)})
    @PostMapping(value = "/findStorageById")
    public ResponseWrapper findStorageById(@RequestBody DSbxxsjyQueryVO vo,
                                           @RequestParam(value = "pageNum") Integer pageNum,
                                           @RequestParam(value = "pageSize") Integer pageSize){
        try {
            MachineVO machineVO = facilityService.findStorageById(vo,pageNum,pageSize);
            return ResponseWrapper.success(HttpStatus.OK.value(),HttpStatus.OK.getReasonPhrase(),machineVO);
        }catch (Exception e){
            e.printStackTrace();
            log.error(e.getMessage());
        }
        return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(),HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(),"服务错误，请联系管理员");
    }

    //设备申购分页
    @ApiOperation(value = "设备申购分页", notes = "参数：")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "起始页", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页展示行数", required = true)})
    @PostMapping(value = "/findPurchase")
    public ResponseWrapper findPurchase(@RequestBody DSbxxsjyQueryVO vo,
                                        @RequestParam(value = "pageNum") Integer pageNum,
                                        @RequestParam(value = "pageSize") Integer pageSize,
                                        @RequestParam(value = "lx") Integer lx){
        try {
            PageInfo<DSbsgxxVO> pageInfos = new PageInfo<DSbsgxxVO>(facilityService.findPurchase(vo,pageNum,pageSize,lx));
            return ResponseWrapper.success(HttpStatus.OK.value(),HttpStatus.OK.getReasonPhrase(),pageInfos);
        }catch (Exception e){
            e.printStackTrace();
            log.error(e.getMessage());
        }
        return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(),HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(),"服务错误，请联系管理员");
    }

    //设备申购详情
    @ApiOperation(value = "设备申购详情", notes = "参数：")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "起始页", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页展示行数", required = true)})
    @PostMapping(value = "/findPurchaseById")
    public ResponseWrapper findPurchaseById(@RequestBody DSbxxsjyQueryVO vo,
                                            @RequestParam(value = "pageNum") Integer pageNum,
                                            @RequestParam(value = "pageSize") Integer pageSize){
        try {
            MachineVO machineVO = facilityService.findPurchaseById(vo,pageNum,pageSize);
            return ResponseWrapper.success(HttpStatus.OK.value(),HttpStatus.OK.getReasonPhrase(),machineVO);
        }catch (Exception e){
            e.printStackTrace();
            log.error(e.getMessage());
        }
        return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(),HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(),"服务错误，请联系管理员");
    }




    //机械设备统计
    @ApiOperation(value = "机械设备统计", notes = "参数：")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "起始页", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页展示行数", required = true)})
    @PostMapping(value = "/findSbtjfx")
    public ResponseWrapper findSbtjfx(@RequestBody DSbtjfxVO vo,
                                      @RequestParam(value = "pageNum") Integer pageNum,
                                      @RequestParam(value = "pageSize") Integer pageSize,
                                      @RequestParam(value = "lx") Integer lx){
        try {
            PageInfo<DSbtjfxVO> pageInfos = new PageInfo<DSbtjfxVO>(facilityService.findSbtjfx(vo,pageNum,pageSize,lx));
            return ResponseWrapper.success(HttpStatus.OK.value(),HttpStatus.OK.getReasonPhrase(),pageInfos);
        }catch (Exception e){
            e.printStackTrace();
            log.error(e.getMessage());
        }
        return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(),HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(),"服务错误，请联系管理员");
    }








}
