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

import com.chinaitop.depot.intelligent.grainsituation.model.TTestdata;
import com.chinaitop.depot.intelligent.grainsituation.service.GrainCheckAnalyzeService;
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.lang.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;

/**
 * @author qingsong.han
 * @description: 粮情检测-时实数据查询
 * @create 2019-01-10 16:31
 */
@RestController
@RequestMapping(value = "/intelligents/realTimeData")
@Api(value = "RealTimeDataController", description = "粮情检查分析控制类")
@SuppressWarnings("all")
public class RealTimeDataController {

    @Resource
    private GrainCheckAnalyzeService grainCheckAnalyzeService;

    /**
     * 时实数据查询列表,查询最新数据
     *
     * @param pageNum
     * @param pageSize
     * @param storehouse
     * @return
     */
    @RequestMapping(value = "/getList", method = RequestMethod.GET)
    @ApiOperation(value = "查询粮情检查信息列表", notes = "粮情检查列表，支持分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", paramType = "query", defaultValue = "1"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", paramType = "query", defaultValue = "10"),
            @ApiImplicitParam(name = "storehouse", value = "仓房编码", paramType = "query")
    })
    public ResponseEntity<PageInfo<TTestdata>> getByCfCodes(Integer pageNum, Integer pageSize, String storehouse) {
        List<TTestdata> list = null;
        if (StringUtils.isNotBlank(storehouse)) {
            PageHelper.startPage(1, 1);
            list = grainCheckAnalyzeService.getByCfCode(storehouse);
        } else {
            if (null != pageNum && null != pageSize) {
                PageHelper.startPage(pageNum, (pageSize == 1 ? 10 : pageSize));
            }
            list = grainCheckAnalyzeService.getNewest(storehouse);
        }
        PageInfo<TTestdata> pageInfo = new PageInfo<>(list);
        return ResponseEntity.ok(pageInfo);
    }

}
