package com.fastbee.data.controller.aaScreenAgricultural;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fastbee.common.annotation.Log;
import com.fastbee.common.core.controller.BaseController;
import com.fastbee.common.core.domain.AjaxResult;
import com.fastbee.common.enums.BusinessType;
import com.fastbee.breakdown.domain.DeviceBreakdown;
import com.fastbee.breakdown.service.IDeviceBreakdownService;
import com.fastbee.common.utils.poi.ExcelUtil;
import com.fastbee.common.core.page.TableDataInfo;

/**
 * 故障Controller
 *
 * @author kerwincui
 * @date 2024-11-27
 */
@RestController
@RequestMapping("/breakdown")
@Api(tags = "故障")
public class DeviceBreakdownController extends BaseController
{
    @Autowired
    private IDeviceBreakdownService deviceBreakdownService;

/**
 * 查询故障列表
 */
@GetMapping("/list")
@ApiOperation("查询故障列表")
    public TableDataInfo list(DeviceBreakdown deviceBreakdown)
    {
        startPage();
        List<DeviceBreakdown> list = deviceBreakdownService.selectDeviceBreakdownList(deviceBreakdown);
        return getDataTable(list);
    }

    /**
     * 导出故障列表
     */
    @ApiOperation("导出故障列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeviceBreakdown deviceBreakdown)
    {
        List<DeviceBreakdown> list = deviceBreakdownService.selectDeviceBreakdownList(deviceBreakdown);
        ExcelUtil<DeviceBreakdown> util = new ExcelUtil<DeviceBreakdown>(DeviceBreakdown.class);
        util.exportExcel(response, list, "故障数据");
    }

    /**
     * 获取故障详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation("获取故障详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(deviceBreakdownService.selectDeviceBreakdownById(id));
    }

    /**
     * 新增故障
     */
    @PostMapping
    @ApiOperation("新增故障")
    public AjaxResult add(@RequestBody DeviceBreakdown deviceBreakdown)
    {
        return toAjax(deviceBreakdownService.insertDeviceBreakdown(deviceBreakdown));
    }

    /**
     * 修改故障
     */
    @PutMapping
    @ApiOperation("修改故障")
    public AjaxResult edit(@RequestBody DeviceBreakdown deviceBreakdown)
    {
        return toAjax(deviceBreakdownService.updateDeviceBreakdown(deviceBreakdown));
    }

    /**
     * 删除故障
     */
    @DeleteMapping("/{ids}")
    @ApiOperation("删除故障")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(deviceBreakdownService.deleteDeviceBreakdownByIds(ids));
    }
    /*
     *
     */
    @GetMapping("/statistics")
    @ApiOperation("查询故障列表")
    public AjaxResult getFaultStatistics(String TypeValue, String CreateTimeValue,String EndTimeValue)
    {
        return success(deviceBreakdownService.getFaultStatistics(TypeValue, CreateTimeValue,EndTimeValue));
    }
}
