package com.casic.PgInterface.rs;

import com.casic.PgInterface.devTable.dto.PgAlarmTjDto;
import com.casic.PgInterface.devTable.manager.PgAlarmTjManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by yxw on 2017/11/24.
 */
@Component
@Path("pgAlarmTj")
public class PgAlarmTjRs {

    private static Logger logger = LoggerFactory.getLogger(PgAlarmRs.class);

    @Resource
    private PgAlarmTjManager pgAlarmTjManager;

    /**
     * 按类型统计历史报警记录
     */
    @POST
    @Path("getTjResultByAlarmType")
    @Produces(MediaType.APPLICATION_JSON)
    public Map<String,Object> getTjResultByAlarmType(@FormParam("startDate") String startDate,
                                                     @FormParam("endDate") String endDate)throws Exception{
        Map<String, Object> resultMap = new HashMap<>();
        String msg = "";
        List<PgAlarmTjDto> pgAlarmTjDtoList=null;
        try{
            pgAlarmTjDtoList=pgAlarmTjManager.getAlarmTjResultByType(startDate,endDate);
            msg="获取成功";
        }
        catch(Exception ex) {
            msg = "统计失败";
        }
        resultMap.put("result",pgAlarmTjDtoList);
        resultMap.put("msg",msg);
        return resultMap;
    }

    /**
     * 根据时间统计报警次数
     */
    @POST
    @Path("getAlarmByTime")
    @Produces(MediaType.APPLICATION_JSON)
    public Map<String, Object> getAlarmByTime(@FormParam("startTime") String startTime,
                                              @FormParam("endTime") String endTime,
                                              @FormParam("statisticType") String statisticType) throws Exception {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        String msg = "";

        List<PgAlarmTjDto> pgAlarmTjDtoList = new ArrayList<PgAlarmTjDto>();
        try {
            pgAlarmTjDtoList = pgAlarmTjManager.getAlarmByTime(startTime, endTime, statisticType);
            if(pgAlarmTjDtoList==null)
                msg="报警统计信息获取失败";
            else
                msg="报警统计信息获取成功";
        } catch (Exception e) {
            e.printStackTrace();
            msg = "报警统计信息获取失败";
        }
        resultMap.put("msg", msg);
        resultMap.put("result", pgAlarmTjDtoList);
        return resultMap;
    }

}
