package com.chinaitop.depot.intelligent.grainsituation.controller;

import com.chinaitop.depot.intelligent.grainsituation.model.TWarningThresholdHistory;
import com.chinaitop.depot.intelligent.grainsituation.service.InsectPestDetectionService;
import com.chinaitop.depot.intelligent.grainsituation.service.TWarningThresholdHistoryService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.unissoft.model.ResponseEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "/intelligents/warning")
@Api(value = "TWarningThresholdHistoryController", description = "故障报警记录控制类")
@SuppressWarnings("all")
public class TWarningThresholdHistoryController {

    @Resource
    private TWarningThresholdHistoryService tWarningThresholdHistoryService;

    /**
     * 虫害信息列表
     *
     * @param pageNum
     * @param pageSize
     * @param iBeginTdh
     * @param iEndTdh
     * @return
     */
    @RequestMapping(value = "/getList", method = RequestMethod.GET)
    @ApiOperation(value = "查询故障报警记录控制列表", notes = "故障报警记录列表，支持分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", paramType = "query"),
            @ApiImplicitParam(name = "vCfCode", value = "仓房code", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "报警处理状态", paramType = "query"),
            @ApiImplicitParam(name = "searchStartDate", value = "开始时间", paramType = "query"),
            @ApiImplicitParam(name = "searchEndDate", value = "结束时间", paramType = "query"),
            @ApiImplicitParam(name = "showType", value = "模块名称", paramType = "query")
    })
    public ResponseEntity<PageInfo<TWarningThresholdHistory>> getList(Integer pageNum, Integer pageSize, String vCfCode, Integer state, String searchStartDate, String searchEndDate, String showType, String wName) {
        List<TWarningThresholdHistory> list = null;
        try {
            if (null != pageNum && null != pageSize) {
                PageHelper.startPage(pageNum, pageSize);
            }
            list = tWarningThresholdHistoryService.getList(vCfCode, state, searchStartDate, searchEndDate, showType, wName);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseEntity.failed("查询失败");
        }
        PageInfo<TWarningThresholdHistory> pageInfo = new PageInfo<TWarningThresholdHistory>(list);
        return ResponseEntity.ok(pageInfo);
    }

    /**
     * 测温记录检测概览查询
     * @param vCfCode
     * @param wTime
     * @param wMode
     * @return
     */
    @RequestMapping(value = "/getWarningInfo", method = RequestMethod.GET)
    @ApiOperation(value = "检测概览查询", notes = "检测概览")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "vCfCode", value = "仓房code", paramType = "query"),
            @ApiImplicitParam(name = "wTime", value = "检测时间", paramType = "query"),
            @ApiImplicitParam(name = "wMode", value = "0测温,1测虫,2测气", paramType = "query")
    })
    public ResponseEntity<List<TWarningThresholdHistory>> getWarningInfoList(String vCfCode, String wTime, String wMode) {
        List<TWarningThresholdHistory> list = null;
        try {
            if (StringUtils.isBlank(vCfCode))
                return ResponseEntity.failed("仓房编码为空!");
            else if (StringUtils.isBlank(wTime))
                return ResponseEntity.failed("检测时间为空!");
            else if (StringUtils.isBlank(wMode))
                return ResponseEntity.failed("检测类别为空!");
            list = tWarningThresholdHistoryService.getWarningInfoList(vCfCode, wTime, wMode);
        } catch (Exception e) {
            return ResponseEntity.failed("查询失败!");
        }
        return ResponseEntity.ok(list);
    }

}
