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

import com.chinaitop.depot.intelligent.grainsituation.model.TLqdata;
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.springframework.http.MediaType;
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.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author qingsong.han
 * @description: 粮情检查分析
 * @create 2018-12-16 16:55
 */
@RestController
@RequestMapping(value = "/intelligents/grainCheckAnalyze")
@Api(value = "GrainCheckAnalyzeController", description = "粮情检查分析控制类")
@SuppressWarnings("all")
public class GrainCheckAnalyzeController {

    @Resource
    private GrainCheckAnalyzeService analyzeService;


    /**
     * 检测时间查询列表
     * @param pageNum
     * @param pageSize
     * @param vDataTime
     * @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 = "vDataTime", value = "检测时间", paramType = "query"),
            @ApiImplicitParam(name = "orgId", value = "组织机构编号", paramType = "query")
    })
    public ResponseEntity<PageInfo<TLqdata>> getList(Integer pageNum, Integer pageSize, String vDataTime,Integer orgId) {
        List<TLqdata> list = null;
        try {
            if (null != pageNum && null != pageSize) {
                PageHelper.startPage(pageNum, pageSize);
            }
            list = analyzeService.getList(vDataTime);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseEntity.failed(e.getMessage());
        }
        PageInfo<TLqdata> pageInfo = new PageInfo<>(list);
        return ResponseEntity.ok(pageInfo);
    }

    @RequestMapping(value = "/getByCfCodes", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
    @ApiOperation(value = "根据仓房code查询测温,测虫,测气信息", notes = "根据仓房code查询测温,测虫,测气信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orgId", value = "粮库id", paramType = "query")
    })
    public ResponseEntity getByCfCodes(String orgId) {
        Map<String, Object> map = new HashMap<String, Object>();
        if (orgId != null && !"".equals(orgId)) {
            map.put("orgId", orgId);
        }
        Map<String, Object> allTesting = analyzeService.getAllTesting(map);
        return ResponseEntity.ok(allTesting);
    }

}
