package com.shining.cloud.controller.AdminStatistic;

import com.njcn.enums.app.ReturnCode;
import com.njcn.pojo.commons.DataIntegrMsgData;
import com.njcn.pojo.commons.ResponseMsgData;
import com.njcn.pojo.commons.StaticMsgData;
import com.njcn.utils.PubUtils;
import com.njcn.utils.UserUtil;
import com.shining.cloud.enums.AdminStatistic.DataIntegrityEnums;
import com.shining.cloud.enums.AdminStatistic.StaticaEnums;
import com.shining.cloud.pojo.AdminStatistic.DataIntegrity;
import com.shining.cloud.pojo.AdminStatistic.DevStatic;
import com.shining.cloud.pojo.AdminStatistic.Integrity;
import com.shining.cloud.pojo.AdminStatistic.StaticInfo;
import com.shining.cloud.service.AdminStatistic.DataIntegrityService;
import com.shining.cloud.service.AdminStatistic.StaticService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
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.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @description: 监测点统计
 * @author: denghuajun
 * @time: 2020-01-02 09:56:25
 **/
@RestController
@RequestMapping("/dataIntegrity")
@Api(tags = "统计装置在线率接口")
public class StaticController {
    @Autowired
    private StaticService staticService;
    @Autowired
    UserUtil userUtil;

    /**
     * 统计数据完整性率
     */
    @PostMapping("getDevStatus")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户ID", required = true, paramType = "query"),
    })
    @ApiOperation(value = "统计装置在线率入口", notes = "统计装置在线率列表", response = ResponseMsgData.class)
    public StaticMsgData getDevStatus(String userId, HttpServletRequest request) {
        StaticMsgData responseData = null;
        if (PubUtils.isBlank(userId)) {
            responseData = PubUtils.assignmentAppStaticResponse(ReturnCode.RETURN_FAIL, StaticaEnums.USERID_WRONG.getCode(), StaticaEnums.USERID_WRONG.getMsg(), null,null,null,0,null);
            return responseData;
        }

        try {
            //获取相应的值
            StaticInfo integrity = new StaticInfo();
            integrity=staticService.getStatic(userUtil.ApplistDev(userId));
            List<DevStatic> dataIntegrities = staticService.getDevStatic(userUtil.ApplistDev(userId));
            responseData = PubUtils.assignmentAppStaticResponse(ReturnCode.RETURN_SUCCESS,StaticaEnums.GETDEVSTATUS_SUCCESS.getCode(), StaticaEnums.GETDEVSTATUS_SUCCESS.getMsg(), integrity.getTimeStart(), integrity.getTimeEnd(),integrity.getOnlineRatez(),integrity.getComError(),dataIntegrities);
        } catch (Exception e) {
            responseData = PubUtils.assignmentAppStaticResponse(ReturnCode.RETURN_FAIL,StaticaEnums.GETDEVSTATUS_FALL.getCode(), StaticaEnums.GETDEVSTATUS_FALL.getMsg(), null, null, null,0,null);
        }
        return responseData;
    }
}