package com.casic.PgInterface.rs;

import com.casic.PgInterface.patroler.domain.PgAlarmRule;
import com.casic.PgInterface.patroler.dto.PgAlarmRuleDto;
import com.casic.PgInterface.patroler.manager.PgAlarmRuleManager;
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/12/14.
 */
@Component
@Path("pgAlarmRule")
public class PgAlarmRuleRs {

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

    @Resource
    private PgAlarmRuleManager pgAlarmRuleManager;

    /**
     * 获取报警阈值信息
     */
    @POST
    @Path("getAlarmRule")
    @Produces(MediaType.APPLICATION_JSON)
    public Map<String, Object> getAlarmRule(@FormParam("devType") String devType) throws Exception {
        Map<String, Object> resultMap = new HashMap<>();
        String msg = "";
        String code="0";

        List<PgAlarmRuleDto> pgAlarmRuleDtoList = new ArrayList<>();
        try {
            pgAlarmRuleDtoList = pgAlarmRuleManager.getAlarmRuleDto(devType);
            if (pgAlarmRuleDtoList == null||pgAlarmRuleDtoList.size()==0)
                msg = "不存在报警阈值信息";
            else
                msg = "报警阈值获取成功";
        } catch (Exception e) {
            e.printStackTrace();
            msg = "报警阈值信息获取失败";
        }
        resultMap.put("code",code);
        resultMap.put("msg", msg);
        resultMap.put("result", pgAlarmRuleDtoList);
        return resultMap;
    }

}