package cn.superdesk.uniorder.controller.unified;

import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.controller.base.BaseController;
import cn.superdesk.uniorder.dto.vo.unified.UnifiedWarningVo;
import cn.superdesk.uniorder.dubbo.consumer.unified.UnifiedWarningDubboConsumerService;
import cn.superdesk.uniorder.common.exception.utils.ExceptionUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/uwarning")
public class UnifiedWarningController extends BaseController {

	@Autowired
	private UnifiedWarningDubboConsumerService unifiedWarningDubboConsumerService;

	/***
	 * 信控预警列表分页
	 * @return
	 */
	@PostMapping("/getdata")
	@ResponseBody
	public R<List<UnifiedWarningVo>> getData() {

		R<List<UnifiedWarningVo>> result = new R<>();

		try {
			Map<String, Object> params = new HashMap<>();

			params.put("project", getString("project"));
			params.put("cususername", getString("cususername"));
			params.put("state", getString("state"));

			params.put("startTime", getString("startTime"));//预警时间
			params.put("endTime", getString("endTime"));

			// 处理时间
			params.put("overstarTime", getString("overstarTime"));
			params.put("overendTime", getString("overendTime"));

			result = unifiedWarningDubboConsumerService.getDataByPage(getToken(), params, getPageNum(), getPageSize());

		} catch (Exception e) {

			result.setCode(String.valueOf(e.hashCode()));
			result.setSuccess(false);
			result.setMessage(e.getMessage());

			log.error(ExceptionUtils.getMessage(e));
			e.printStackTrace();
		}

		return result;
	}
}
