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

import com.chinaitop.depot.intelligent.basicdata.model.TJctable;
import com.chinaitop.depot.intelligent.basicdata.service.QuantityService;
import com.chinaitop.depot.intelligent.grainNumberMonitor.model.TNumberWarningHistory;
import com.chinaitop.depot.intelligent.grainNumberMonitor.service.MonitorWarningService;
import com.chinaitop.depot.intelligent.socket.SocketClient;
import com.chinaitop.depot.intelligent.utils.ConstUtils;
import com.chinaitop.depot.intelligent.utils.HexConvertUtils;
import com.chinaitop.depot.intelligent.wsClientJc.jc3.MyWebServiceSoap;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.unissoft.model.ResponseEntity;
import com.unissoft.model.SendEntity;
import com.unissoft.model.TypeEnum;
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.beans.factory.annotation.Autowired;
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.*;

/**
 * @author qingsong.han
 * @description: 数量检测分析预警
 * @create 2019-02-22 15:50
 */
@RestController
@RequestMapping(value = "/intelligents/monitorWarning")
@Api(value = "MonitorWarningController", description = "数量检测分析预警")
@SuppressWarnings("all")
public class MonitorWarningController {

    @Resource
    private MonitorWarningService monitorWarningService;
    @Autowired
    private SocketClient socketClient;
    @Autowired
    private ConstUtils constUtils;

    @RequestMapping(value = "/getList", method = RequestMethod.GET)
    @ApiOperation(value = "数量检测分析预警列表", notes = "数量检测分析预警列表，支持分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", defaultValue = "1", value = "页码", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", defaultValue = "10", value = "每页条数", paramType = "query"),
            @ApiImplicitParam(name = "vcfcode", defaultValue = "001", value = "仓房编码", paramType = "query")
    })
    public ResponseEntity<PageInfo<Map<String, Object>>> getList(Integer pageNum, Integer pageSize, String vcfcode) {
        List<Map<String, Object>> list = null;
        try {
            if (null != pageNum && null != pageSize) {
                PageHelper.startPage(pageNum, pageSize);
            }
            list = monitorWarningService.getList(vcfcode);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseEntity.failed(e.getMessage());
        }
        PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(list);
        return ResponseEntity.ok(pageInfo);
    }

    //获取测量进度
    @RequestMapping(value = "/getScanResult", method = RequestMethod.GET)
    @ApiOperation(value = "获取测量进度", notes = "按仓房编码查看数量监测进度")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "vcfcode", defaultValue = "001", value = "仓房编码", paramType = "query"),
            @ApiImplicitParam(name = "ws", defaultValue = "ws地址", value = "仓房编码", paramType = "query")
    })
    public ResponseEntity getScanResult(String vcfcode, String ws) {
        String scanResult = monitorWarningService.getScanResult(vcfcode, ws);
        return ResponseEntity.ok(scanResult);
    }

    //获取扫描结果
    @RequestMapping(value = "/getmeasureweight", method = RequestMethod.GET)
    @ApiOperation(value = "获取扫描结果", notes = "获取扫描结果")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "vcfcode", defaultValue = "001", value = "仓房编码", paramType = "query"),
            @ApiImplicitParam(name = "devcode", value = "设备编码", paramType = "query"),
            @ApiImplicitParam(name = "operator", value = "操作人", paramType = "query"),
            @ApiImplicitParam(name = "orgId", value = "库房编码", paramType = "query"),
            @ApiImplicitParam(name = "ws", defaultValue = "ws地址", value = "仓房编码", paramType = "query")
    })
    public ResponseEntity getmeasureweight(String vcfcode, String devcode, String operator, String orgId, String ws) {
        String weight = monitorWarningService.getmeasureweight(vcfcode, devcode, operator, orgId, ws);
        return ResponseEntity.ok(weight);
    }


    @RequestMapping(value = "/sendNumberMonitor", method = RequestMethod.GET)
    @ApiOperation(value = "数量监测指令", notes = "按仓房编码执行数量监测")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "vcfcode", defaultValue = "001", value = "仓房编码", paramType = "query"),
            @ApiImplicitParam(name = "ws", defaultValue = "ws地址", value = "仓房编码", paramType = "query")
    })
    public ResponseEntity sendNumberMonitor(String vcfcode, String ws) {
        String s = monitorWarningService.sendNumberMonitor(vcfcode, ws);
        return ResponseEntity.ok(s);
    }

    //TNumberWarningHistory
    @RequestMapping(value = "/getListHistory", method = RequestMethod.GET)
    @ApiOperation(value = "数量监测指令列表", notes = "数量监测指令列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", paramType = "query"),
            @ApiImplicitParam(name = "orgId", value = "库点编码", paramType = "query"),
            @ApiImplicitParam(name = "vcfcode", value = "仓房编码", paramType = "query"),
            @ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query")
    })
    public ResponseEntity getListHistory(Integer pageNum, Integer pageSize,String orgId, String vcfcode, String startTime, String endTime) {
        List<TNumberWarningHistory> list = null;
        try {
            if (null != pageNum && null != pageSize) {
                PageHelper.startPage(pageNum, pageSize);
            }
            list = monitorWarningService.getListHistory(orgId,vcfcode, startTime, endTime);//查询方法添加id查询
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseEntity.failed(e.getMessage());
        }
        PageInfo<TNumberWarningHistory> pageInfo = new PageInfo<TNumberWarningHistory>(list);
        return ResponseEntity.ok(pageInfo);
    }

    //TNumberWarningHistory
    @RequestMapping(value = "/getTWarning", method = RequestMethod.GET)
    @ApiOperation(value = "根据库点id和仓房编码查询检测数量", notes = "根据库点id和仓房编码查询检测数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orgId", value = "库点编码", paramType = "query"),
            @ApiImplicitParam(name = "vcfcode", value = "仓房编码", paramType = "query")
    })
    public ResponseEntity getTWarning(String orgId, String vcfcode) {
        TNumberWarningHistory tWarning = null;
        try {
            tWarning = monitorWarningService.getTWarning(orgId, vcfcode);//查询方法添加id查询
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseEntity.failed(e.getMessage());
        }
        return ResponseEntity.ok(tWarning);
    }
}
