package com.njcn.cloud.controller.information;

import cn.hutool.core.util.StrUtil;
import com.njcn.cloud.enums.app.EventMsgCodeEnum;
import com.njcn.cloud.pojo.dto.AppSteadyUrl;
import com.njcn.cloud.pojo.vo.AppSteadyMsgVO;
import com.njcn.cloud.pojo.vo.SteadyMsgDetailVO;
import com.njcn.cloud.pojo.vo.SteadyTargetVO;
import com.njcn.cloud.service.IAppSteadyMsgService;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.web.controller.BaseController;
import com.njcn.web.pojo.param.BaseParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * @description: 稳态消息详情业务层
 * @author: gbl
 * @time: 2019-11-27 
 **/
@RestController
@RequestMapping("/steadymsg")
@Api(tags = "稳态消息接口")
@RequiredArgsConstructor
public class SteadyMsgController extends BaseController {

	private final IAppSteadyMsgService steadyAssService;

	/**
	 * @Description: 稳态越限列表
	 * @param param
	 * @return: com.njcn.common.pojo.response.HttpResult<com.njcn.cloud.pojo.vo.AppSteadyMsgVO>
	 * @Author: wr
	 * @Date: 2023/11/3 15:02
	 */
	@PostMapping("steadyState")
    @ApiOperation(value = "稳态越限列表", notes = "稳态越限列表")
    public HttpResult<AppSteadyMsgVO> steadyState(@RequestBody BaseParam param) {
		String methodDescribe = getMethodDescribe("steadyState");
		if (StrUtil.isBlank(param.getSearchValue())) {
			throw new BusinessException(EventMsgCodeEnum.USERID_WRONG.getMsg());
		}
		AppSteadyMsgVO steadyState = steadyAssService.getSteadyState(param);
		return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, steadyState, methodDescribe);

	}
	
	/**
	 * @Description: 稳态越限列表详细信息
	 * @param steadyIndex 稳态越限列表ID
	 * @return:
	 * @Author: wr
	 * @Date: 2023/11/3 15:02
	 */
	@PostMapping("steadyStateInfo")
	@ApiImplicitParams({
        @ApiImplicitParam(name = "steadyIndex", value = "稳态越限列表ID", required = true, paramType = "query")
	})
    @ApiOperation(value = "稳态越限列表详细信息", notes = "稳态越限详细信息")
    public HttpResult<List<SteadyMsgDetailVO>> steadyStateInfo(String steadyIndex) {
		String methodDescribe = getMethodDescribe("steadyStateInfo");
		List<SteadyMsgDetailVO> steadyDetail = steadyAssService.getSteadyDetail(steadyIndex);
		return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, steadyDetail, methodDescribe);
	}

	/**
	 * @Description: 稳态越限涉及指标
	 * @param lineIndex
	 * @param timeID
	 * @return: ResponseData
	 * @Author: wr
	 * @Date: 2023/11/3 16:23
	 */
	@PostMapping("/steadyTarget")
	@ApiImplicitParams({
        @ApiImplicitParam(name = "lineIndex", value = "监测点ID", required = true, paramType = "query"),
        @ApiImplicitParam(name = "timeID", value = "统计时间", required = true, paramType = "query")
	})
    @ApiOperation(value = "稳态越限涉及指标", notes = "稳态越限指标")
    public HttpResult<List<SteadyTargetVO>> steadyTarget(String lineIndex,String timeID) {
		String methodDescribe = getMethodDescribe("steadyTarget");
		List<SteadyTargetVO> steadyTarget = steadyAssService.getSteadyTarget(lineIndex, timeID);
		return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, steadyTarget, methodDescribe);


	}

	/**
	 * @Description: 稳态越限指标图形
	 * @param lineIndex
	 * @param timeID
	 * @param typeCode
	 * @return: com.njcn.common.pojo.response.HttpResult<java.util.List<com.njcn.cloud.pojo.vo.SteadyTargetVO>>
	 * @Author: wr
	 * @Date: 2023/11/3 16:25
	 */
	@PostMapping("/steadyTargetUrl")
	@ApiImplicitParams({
        @ApiImplicitParam(name = "lineIndex", value = "监测点ID", required = true, paramType = "query"),
        @ApiImplicitParam(name = "timeID", value = "统计时间", required = true, paramType = "query"),
        @ApiImplicitParam(name = "typeCode", value = "指标编码", required = true, paramType = "query")
	})
    @ApiOperation(value = "稳态越限指标图形", notes = "稳态越限图形")
    public HttpResult<AppSteadyUrl> steadyTargetUrl(String lineIndex,String timeID,Integer typeCode) {
		String methodDescribe = getMethodDescribe("steadyTargetUrl");
		AppSteadyUrl steadyTargetUrl = steadyAssService.getSteadyTargetUrl(lineIndex, timeID, typeCode);
		if(StrUtil.isBlank(steadyTargetUrl.getSteadyPath())){
			steadyTargetUrl = steadyAssService.getUrl(lineIndex, timeID, typeCode);
		}
		return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, steadyTargetUrl, methodDescribe);

	}

	/**
	 * @description: 生成稳态越限指标图形
	 * @author wr
	 * @param lineIndex 监测点ID
	 * @param timeID 统计时间
	 * @param typeCode
	 */
	@PostMapping("/steadyImage")
	@ApiImplicitParams({
        @ApiImplicitParam(name = "lineIndex", value = "监测点ID", required = true, paramType = "query"),
        @ApiImplicitParam(name = "timeID", value = "统计时间", required = true, paramType = "query"),
        @ApiImplicitParam(name = "typeCode", value = "指标编码", required = true, paramType = "query")
	})
    @ApiOperation(value = "生成稳态越限指标图形", notes = "稳态越限图形")
    public HttpResult<AppSteadyUrl> steadyImage(String lineIndex,String timeID,Integer typeCode) {
		String methodDescribe = getMethodDescribe("steadyImage");
		AppSteadyUrl steadyTargetUrl = steadyAssService.getUrl(lineIndex, timeID, typeCode);
		return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, steadyTargetUrl, methodDescribe);
	}
}