Newer
Older
PgInterface / src / main / java / com / casic / PgInterface / rs / PgAlarmLinkRs.java
yanxiaowei on 25 Mar 2020 5 KB 添加获取需要关闭的风机
package com.casic.PgInterface.rs;

import com.casic.PgInterface.core.util.StringUtils;
import com.casic.PgInterface.devTable.domain.PgAlarm;
import com.casic.PgInterface.devTable.domain.PgDevice;
import com.casic.PgInterface.devTable.dto.PgDeviceDto;
import com.casic.PgInterface.devTable.manager.PgAlarmManager;
import com.casic.PgInterface.devTable.manager.PgDeviceManager;
import com.casic.PgInterface.reservePlan.dto.PgReservePlanDto;
import com.casic.PgInterface.reservePlan.manager.PgReservePlanManager;
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 2018/3/29.
 */
@Component
@Path("pgAlarmLink")
public class PgAlarmLinkRs {

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

    @Resource
    private PgAlarmManager pgAlarmManager;
    @Resource
    private PgDeviceManager pgDeviceManager;
    @Resource
    private PgReservePlanManager pgReservePlanManager;

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

        List<PgDeviceDto> pgDeviceDtoList = new ArrayList<>();

        try {
            if(StringUtils.isNotBlank(id)) {
                PgAlarm pgAlarm = pgAlarmManager.get(Long.valueOf(id));
                if (pgAlarm == null)
                    msg = "不存在报警信息";
                else {
                    PgDevice pgDevice = pgAlarm.getAlarmDevId();
                    if (pgDevice == null)
                        msg = "不存在报警设备";
                    else {
                        pgDeviceDtoList = pgDeviceManager.getAlarmLinkDeviceDto(pgDevice,pgAlarm);
                        msg = "报警关联设备获取成功";
                        code="200";
                    }
                }
            }
            else
                msg="未接受到报警设备ID信息";
        } catch (Exception e) {
            e.printStackTrace();
            msg = "获取关联设备失败";
        }

        resultMap.put("code",code);
        resultMap.put("msg", msg);
        resultMap.put("result", pgDeviceDtoList);

        return resultMap;
    }

    /*
     * 获取报警设备所在仓位的所有摄像机
     */
    @POST
    @Path("linkPartitionCamera")
    @Produces(MediaType.APPLICATION_JSON)
    public Map<String, Object> linkPartitionCamera(@FormParam("id") String id) throws Exception {
        Map<String, Object> resultMap = new HashMap<>();
        String msg = "";
        String code="0";

        List<PgDeviceDto> pgDeviceDtoList = new ArrayList<>();
        try {
            if(StringUtils.isNotBlank(id)) {
                PgAlarm pgAlarm = pgAlarmManager.get(Long.valueOf(id));
                if(pgAlarm==null)
                    msg="不存在报警信息";
                else {
                    PgDevice pgDevice = pgAlarm.getAlarmDevId();
                    if (pgDevice == null)
                        msg = "不存在报警设备";
                    else {
                        String strPosition=pgDevice.getPosition();
                        String position="";
                        if(!strPosition.equals(""))
                            position=pgDevice.getPosition().substring(0,3);
                        String partition=pgDevice.getPartition();

                        pgDeviceDtoList = pgDeviceManager.getPgCameraListByPosition(partition,position);
                        msg = "关联设备获取成功";
                        code="200";
                    }
                }
            }
            else
                msg="请输入报警设备Id信息";
        } catch (Exception e) {
            e.printStackTrace();
            msg = "分区设备关联失败";
        }
        resultMap.put("code",code);
        resultMap.put("msg", msg);
        resultMap.put("result", pgDeviceDtoList);
        return resultMap;
    }

    /*
     * 根据报警记录获取关联的预案
     */
    @POST
    @Path("linkReservePlan")
    @Produces(MediaType.APPLICATION_JSON)
    public Map<String, Object> linkReservePlan(@FormParam("id") String id) throws Exception {
        Map<String, Object> resultMap = new HashMap<>();
        String msg = "";
        String code="0";

        List<PgReservePlanDto> pgReservePlanDtoList=new ArrayList<>();
        try{
            if(StringUtils.isNotBlank(id)) {
                PgAlarm pgAlarm = pgAlarmManager.get(Long.valueOf(id));
                if (pgAlarm == null)
                    msg = "不存在报警信息";
                else {
                    pgReservePlanDtoList = pgReservePlanManager.getReservePlanDtoByAlarmType(pgAlarm);

                    if (pgReservePlanDtoList == null || pgReservePlanDtoList.size() == 0)
                        msg = "不存在关联的报警预案";
                    else {
                        msg = "关联预案获取成功";
                        code="200";
                    }
                }
            }
            else
                msg="请输入报警信息";
        }
        catch(Exception e)
        {
            e.printStackTrace();
            msg="预案关联失败";
        }
        resultMap.put("code",code);
        resultMap.put("msg",msg);
        resultMap.put("result",pgReservePlanDtoList);

        return resultMap;
    }

}