Commit f52970d0 authored by zhengjiangtao's avatar zhengjiangtao

Merge branch 'develop_20200601' of http://172.16.10.76/bank/AmosBankRoot into develop_20200601

parents 6f3dd1bd a70d412b
......@@ -13,6 +13,7 @@ import com.yeejoin.amos.bank.dao.mapper.AlarmMapper;
import com.yeejoin.amos.bank.dao.mapper.BankInfoMapper;
import com.yeejoin.amos.bank.dao.repository.IAlarmRepository;
import com.yeejoin.amos.bank.entity.EquipmentQualityVo;
import com.yeejoin.amos.bank.remote.AmosWsService;
import com.yeejoin.amos.bank.remote.client.RiskModelRemoteClient;
import com.yeejoin.amos.bank.service.IAlarmPointService;
import com.yeejoin.amos.bank.service.IAlarmService;
......@@ -54,7 +55,7 @@ public class EquipmentListener extends EmqxListener implements InitializingBean
private BankInfoMapper bankInfoMapper;
@Autowired
private AmosWsClient client;
private AmosWsService amosWsService;
@Autowired
EquipmentMapper equipmentMapper;
......@@ -124,7 +125,7 @@ public class EquipmentListener extends EmqxListener implements InitializingBean
Map<String, Object> resultMap = bankInfoMapper.selectBankInfoBySourceId(eqpId);
resultMap.put("eqpId", eqpId);
pushAisleAlarm(resultMap);
amosWsService.pushAlarmPoint("aisleAlarm", resultMap);
logger.info("=======aisle状态有变化=====");
}
});
......@@ -139,14 +140,6 @@ public class EquipmentListener extends EmqxListener implements InitializingBean
}
}
/**
* 发送通道刷新标识
*/
public void pushAisleAlarm(Map<String, Object> result) {
WebsocketParam param = new WebsocketParam("aisleAlarm", JSON.toJSONString(result));
client.sendMessage(param);
}
public void handleAlarmData(String jsonStr) {
try {
logger.info("start handle ip equipment alarm..");
......@@ -204,7 +197,7 @@ public class EquipmentListener extends EmqxListener implements InitializingBean
}
String authOrgTemp = JsonUtil.arraysToString(JsonUtil.toStringArray(authOrg));
if (!ObjectUtils.isEmpty(authOrgTemp)){
if (!ObjectUtils.isEmpty(authOrgTemp)) {
orgCode = authOrgTemp;
}
......@@ -304,34 +297,32 @@ public class EquipmentListener extends EmqxListener implements InitializingBean
public void addAlarmRecord(Long eqpId, String metricKey, Integer statusByName, String orgCode, String ipAddress, String eqpName) {
List<Alarm> curAlarmList = alarmService.findByQueryColumn(eqpId + metricKey);
if (curAlarmList != null && curAlarmList.size() > 0) {
// if("异常".equals(curAlarmList.get(0).getCurrentState())){
Alarm alarm = curAlarmList.get(0);
alarm.setUpdateDate(DateTimeKit.now());
alarm.setOrgCode(orgCode);
alarm.setClearPerson(CLEAR_PERSON);
if (!ObjectUtils.isEmpty(alarm.getHappenDate())){
if (!ObjectUtils.isEmpty(alarm.getHappenDate())) {
String subtract = DateTimeKit.getSubtract(alarm.getHappenDate());
alarm.setContinueDate(subtract);
}
if (ALARM_ABNORMAL_STATUS.equals(alarm.getCurrentState()) && statusByName != 0) {
alarm.setCurrentState(ALARM_ABNORMAL_STATUS);
} else {
alarm.setClearDate(DateTimeKit.now());
alarm.setClearPerson(CLEAR_PERSON);
alarm.setCurrentState(ALARM_NORMAL_STATUS);
}
alarmMapper.updateAlarm(alarm);
// }
} else {
Alarm alarm = new Alarm();
alarm.setSourceId(eqpId + "");
alarm.setAlarmLevel(ALARM_LEVEL);
alarm.setAlarmReason("");
alarm.setAlarmReason(ALARM_CAUSE);
alarm.setAlarmSourceIp(ipAddress + "");
alarm.setAlarmSourceName(eqpName);
alarm.setAlarmSourceType(metricKey);
alarm.setAlarmSourceType(ALARM_TYPE);
alarm.setClearDate("");
alarm.setContinueDate("");
alarm.setEnsureDate("");
alarm.setHappenDate("");
alarm.setEnsurePerson("");
alarm.setOrgCode(orgCode);
alarm.setHappenDate(DateTimeKit.now());
......@@ -353,7 +344,7 @@ public class EquipmentListener extends EmqxListener implements InitializingBean
if (statusByName == 0) {
// 删除告警
alarmPointService.delete(alarmPoint.get(0));
pushAlarmPoint("alarmPoint", alarmPointService.findAll());
amosWsService.pushAlarmPoint("alarmPoint", alarmPointService.findAll());
}
return;
} else {
......@@ -377,16 +368,8 @@ public class EquipmentListener extends EmqxListener implements InitializingBean
alarmPoint1.setPointAttrs(JSON.toJSONString(map));
alarmPointService.save(alarmPoint1);
// 推送告警
pushAlarmPoint("alarmPoint", alarmPointService.findAll());
}
amosWsService.pushAlarmPoint("alarmPoint", alarmPointService.findAll());
}
}
/**
* 发送跑马灯告警
*/
public void pushAlarmPoint(String WS, Object object) {
WebsocketParam param = new WebsocketParam(WS, JSON.toJSONString(object));
client.sendMessage(param);
}
}
......@@ -7,6 +7,9 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import com.yeejoin.amos.bank.dao.mapper.AlarmMapper;
import com.yeejoin.amos.bank.remote.AmosWsService;
import com.yeejoin.amos.bank.utils.DateTimeKit;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.eclipse.paho.client.mqttv3.MqttMessage;
......@@ -46,6 +49,8 @@ import com.yeejoin.amos.spc.core.util.StringUtil;
import liquibase.integration.commandline.Main;
import static com.yeejoin.amos.bank.constants.AlarmConstant.*;
@Component
public class SelfSupportListener extends EmqxListener implements InitializingBean {
......@@ -79,6 +84,13 @@ public class SelfSupportListener extends EmqxListener implements InitializingBea
private IAlarmService alarmService;
@Autowired
private IAlarmRepository iAlarmDao;
@Autowired
private AmosWsService amosWsService;
@Autowired
private AlarmMapper alarmMapper;
/**
* 监听主题
*/
......@@ -111,16 +123,16 @@ public class SelfSupportListener extends EmqxListener implements InitializingBea
// logger.error("----supprtmqtt received--jsonStr",jsonStr);
JSONObject parseObject = JSON.parseObject(jsonStr);
//logger.info("----supprtmqtt received sucess",parseObject);
System.out.println("----supprtmqtt received sucess :"+ parseObject);
System.out.println("----supprtmqtt received sucess :" + parseObject);
Long eqpId = parseObject.getLong("eqpId");
JSONArray jsonArray = parseObject.getJSONArray("metricDatas");
JSONArray eqpConfigMap = parseObject.getJSONArray("eqpConfigMap");
//获取ip
String ipAddress = getIpAddress(eqpConfigMap);
//楼层
String lou =getIpAddress1(eqpConfigMap,"所属楼层");
String lou = getIpAddress1(eqpConfigMap, "所属楼层");
//3为坐标
String sanwei =getIpAddress1(eqpConfigMap,"三维位置");
String sanwei = getIpAddress1(eqpConfigMap, "三维位置");
String eqpName = parseObject.getString("eqpName");
//orgcode
......@@ -130,25 +142,25 @@ public class SelfSupportListener extends EmqxListener implements InitializingBea
return;
}
//告警信息
String metricKey="";
String metricKey = "";
//默认状态为正常
int statusByName=0 ;
int statusByName = 0;
// jsonArray.forEach(e -> {
for (Object e : jsonArray){
for (Object e : jsonArray) {
JSONObject object = (JSONObject) e;
String string = object.getString("metricJson");
metricKey = object.getString("metricKey");
if (!StringUtil.isNotEmpty(string)) {
return;
}
logger.error("---------shudu--string",string);
System.out.println("----supprtmqtt chuli recording : "+ string);
logger.error("---------shudu--string", string);
System.out.println("----supprtmqtt chuli recording : " + string);
//{\"maxTime\":\"1\",\"packetLossRate\":\"0\",\"avgTime\":\"0\",\"minTime\":\"0\",\"发包数\":\"\",\"icmpPackSize\":\"32\",\"status\":\"通\"}
JSONObject metricJson = JSONObject.parseObject(string);
for (Map.Entry entry : metricJson.entrySet()) {
// 指标名
System.out.println("----start chuli device state : "+ entry);
System.out.println("----start chuli device state : " + entry);
String remark = entry.getKey().toString();
String statusName = entry.getValue().toString();
......@@ -183,11 +195,11 @@ public class SelfSupportListener extends EmqxListener implements InitializingBea
}
}
if(null!=node) {
if (null != node) {
node.setNumber(statusByName);
node.setState(statusByName);
equipmentMapper.updateNodeState(node);
String nodeDetail = (statusByName== 0 ? "[{\"name\":\"通信状态\",\"value\":\"正常\"}]":"[{\"name\":\"通信状态\",\"value\":\"异常\"}]");
String nodeDetail = (statusByName == 0 ? "[{\"name\":\"通信状态\",\"value\":\"正常\"}]" : "[{\"name\":\"通信状态\",\"value\":\"异常\"}]");
equipmentMapper.updateNodeDetail(node.getId(), nodeDetail);
try {
webSocketServer.sendMessage("refresh", "self");
......@@ -197,87 +209,83 @@ public class SelfSupportListener extends EmqxListener implements InitializingBea
}
}
}
};
}
;
// });
//增加报警
List<AlarmPoint> alarmPoint= alarmPointService.selectPointTypeAndPointId(AlarmPointTypeEnum.设备.getCode(), eqpId);
if(alarmPoint!=null&&alarmPoint.size()>0){
List<AlarmPoint> alarmPoint = alarmPointService.selectPointTypeAndPointId(AlarmPointTypeEnum.设备.getCode(), eqpId);
if (alarmPoint != null && alarmPoint.size() > 0) {
//存在报警,判断当前状态是不是合格,合格则删除上次的报警
if(statusByName==0){
if (statusByName == 0) {
//删除告警
alarmPointService.delete(alarmPoint.get(0));
amosWsService.pushAlarmPoint("alarmPoint", alarmPointService.findAll());
}
}else{
} else {
//不存在,判断当前状态是不是合格,不合格新增,合格不做任何操作
if(statusByName!=0){
if (statusByName != 0) {
//增加告警
AlarmPoint alarmPoint1=new AlarmPoint();
AlarmPoint alarmPoint1 = new AlarmPoint();
alarmPoint1.setPointId(eqpId);
alarmPoint1.setPointType(AlarmPointTypeEnum.设备.getCode());
alarmPoint1.setUpdateDate(new Date());
alarmPoint1.setIsAlarm(1);//不合格
alarmPoint1.setContent(eqpName+"-"+ipAddress+"-"+metricKey);
alarmPoint1.setContent(eqpName + "-" + ipAddress + "-" + metricKey);
alarmPoint1.setCode(orgCode1);
alarmPoint1.setPointName(eqpName);
Map<String, Object> map = new HashMap<>();
map.put("position",sanwei);
map.put("position", sanwei);
map.put("storey", lou);
map.put("levelStr", "impEqu_04");
alarmPoint1.setPointAttrs(JSON.toJSONString(map));
alarmPointService.save(alarmPoint1);
//推送告警
List<AlarmPoint> list= alarmPointService.findAll();
WebsocketParam param=new WebsocketParam("alarmPoint", JSON.toJSONString(list));
Properties props = PropertiesLoaderUtils.loadAllProperties("application.properties");
String url = (String) props.get("params.remoteWebsocketUrl") + "/generic/sendMessage";
HttpUtil.PostJson(url, JSON.toJSONString(param));
amosWsService.pushAlarmPoint("alarmPoint", alarmPointService.findAll());
}
}
//增建告警记录表
//告警记录
List<Alarm> curAlarmList = alarmService.findByQueryColumn(eqpId+metricKey);
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
List<Alarm> curAlarmList = alarmService.findByQueryColumn(eqpId + metricKey);
if (curAlarmList != null && curAlarmList.size() > 0) {
// if("异常".equals(curAlarmList.get(0).getCurrentState())){
Alarm alarm = curAlarmList.get(0);
alarm.setUpdateDate(df.format(new Date()));
if(statusByName!=0){
alarm.setCurrentState("异常");
}else{
alarm.setCurrentState("正常");
alarm.setUpdateDate(DateTimeKit.now());
if (!ObjectUtils.isEmpty(alarm.getHappenDate())) {
String subtract = DateTimeKit.getSubtract(alarm.getHappenDate());
alarm.setContinueDate(subtract);
}
alarm.setQueryColumn(eqpId+metricKey);
alarm.setAlarmSourceType(metricKey);
alarm.setClearPerson(metricKey);
iAlarmDao.save(alarm);
// }
if (ALARM_ABNORMAL_STATUS.equals(alarm.getCurrentState()) && statusByName != 0) {
alarm.setCurrentState(ALARM_ABNORMAL_STATUS);
} else {
alarm.setClearDate(DateTimeKit.now());
alarm.setClearPerson(CLEAR_PERSON);
alarm.setCurrentState(ALARM_NORMAL_STATUS);
}
alarmMapper.updateAlarm(alarm);
} else {
Alarm alarm = new Alarm();
alarm.setSourceId(eqpId+"");
alarm.setAlarmLevel("紧急告警");
alarm.setAlarmReason("");
alarm.setAlarmSourceIp(ipAddress+"");
alarm.setSourceId(eqpId + "");
alarm.setAlarmLevel(ALARM_LEVEL);
alarm.setAlarmReason(ALARM_CAUSE);
alarm.setAlarmSourceIp(ipAddress + "");
alarm.setAlarmSourceName(eqpName);
alarm.setAlarmSourceType(metricKey);
alarm.setAlarmSourceType(ALARM_TYPE);
alarm.setClearDate("");
alarm.setClearPerson(metricKey);
alarm.setContinueDate("");
if(statusByName!=0){
alarm.setCurrentState("异常");
}else{
alarm.setCurrentState("正常");
}
alarm.setEnsureDate("");
alarm.setHappenDate("");
alarm.setEnsurePerson("");
alarm.setOrgCode(orgCode1);
alarm.setUpdateDate(df.format(new Date()));
alarm.setQueryColumn(eqpId+metricKey);
alarm.setQueryColumn(eqpId + metricKey);
alarm.setHappenDate(DateTimeKit.now());
if (statusByName != 0) {
alarm.setCurrentState(ALARM_ABNORMAL_STATUS);
iAlarmDao.save(alarm);
} else {
alarm.setCurrentState(ALARM_NORMAL_STATUS);
}
}
} catch (Exception e) {
logger.error("消息流转报错.");
......@@ -287,14 +295,13 @@ public class SelfSupportListener extends EmqxListener implements InitializingBea
}
public String getIpAddress1(JSONArray eqpConfigMap,String name) {
public String getIpAddress1(JSONArray eqpConfigMap, String name) {
//配置信息
if(null != eqpConfigMap && eqpConfigMap.size() > 0) {
if (null != eqpConfigMap && eqpConfigMap.size() > 0) {
for (Object object : eqpConfigMap) {
JSONObject obj = (JSONObject) object;
String str = obj.getString("displayName");
if(str.contains(name)) {
if (str.contains(name)) {
String ip = obj.getString("valueStr");
return ip;
}
......@@ -304,16 +311,13 @@ public class SelfSupportListener extends EmqxListener implements InitializingBea
}
public String getIpAddress(JSONArray eqpConfigMap) {
//配置信息
if(null != eqpConfigMap && eqpConfigMap.size() > 0) {
if (null != eqpConfigMap && eqpConfigMap.size() > 0) {
for (Object object : eqpConfigMap) {
JSONObject obj = (JSONObject) object;
String str = obj.getString("displayName");
if(str.contains("IP")) {
if (str.contains("IP")) {
String ip = obj.getString("valueStr");
return ip;
}
......
......@@ -10,6 +10,7 @@ public class AlarmConstant {
public static String ALARM_CAUSE = "设备Ping不通";
public static String CLEAR_PERSON = "自动清除";
public static String ALARM_LEVEL = "紧急告警";
public static String ALARM_TYPE = "IP设备告警";
public static String ALARM_NORMAL_STATUS = "清除";
public static String ALARM_ABNORMAL_STATUS = "告警";
}
......@@ -18,7 +18,7 @@ public interface IAlarmRepository extends IBaseRepository<Alarm, String> {
@Query(value="select * from spc_alarm where query_column =?1 AND current_state in ('未确认未清除','已确认未清除','异常','告警')",nativeQuery=true )
public List<Alarm> selectByQueryColumn(String type);
@Query(value="select COUNT(*) value,spc_alarm.alarm_level name from spc_alarm where spc_alarm.org_code like CONCAT(?1,'%' ) and spc_alarm.current_state in ('未确认未清除','已确认未清除','异常') GROUP BY spc_alarm.alarm_level ",nativeQuery=true )
@Query(value="select COUNT(*) value,spc_alarm.alarm_level name from spc_alarm where spc_alarm.org_code like CONCAT('%', ?1, '%' ) and spc_alarm.current_state in ('未确认未清除','已确认未清除','异常','告警') GROUP BY spc_alarm.alarm_level ",nativeQuery=true )
public List<Object[]> countnum(String code);
}
......
package com.yeejoin.amos.bank.remote;
import com.alibaba.fastjson.JSON;
import com.yeejoin.amos.bank.webSocket.AmosWsClient;
import com.yeejoin.amos.bank.webSocket.WebsocketParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @Author: xinglei
* @Description:
* @Date: 2020/6/11 8:56
*/
@Service
public class AmosWsService {
@Autowired
private AmosWsClient client;
/**
* 发送Websocket
*/
public void pushAlarmPoint(String WS, Object object) {
WebsocketParam param = new WebsocketParam(WS, JSON.toJSONString(object));
client.sendMessage(param);
}
}
......@@ -44,16 +44,11 @@ public class DateTimeKit {
sb.append(day).append("天");
}
if (hour != 0) {
sb.append(hour%24).append("小时");
sb.append(hour % 24).append("小时");
}
if (minute != 0) {
sb.append(minute%60).append("分");
sb.append(minute % 60).append("分");
}
return sb.toString();
}
public static void main(String[] args) {
String subtract = getSubtract("2020-06-09 17:38:59");
System.out.println(subtract);
}
}
......@@ -14,5 +14,4 @@ public interface AmosWsClient {
@PostMapping("/generic/sendDataList")
CommonResponse sendDataList(@RequestBody WebsocketListParam param);
}
......@@ -47,7 +47,7 @@ public class AlarmController extends BaseController {
//获取当前登录人的公司code
ReginParams reginParams = getSelectedOrgInfo();
DaoCriteria criteria = new DaoCriteria();
criteria.setValue(reginParams.getCompany().getOrgCode() + "%");
criteria.setValue("%" + reginParams.getCompany().getOrgCode() + "%");
criteria.setOperator(QueryOperatorEnum.LIKE.getName());
criteria.setPropertyName("orgCode");
......
......@@ -15,6 +15,9 @@
<if test="updateDate != null">
update_date = #{updateDate},
</if>
<if test="clearDate != null">
clear_date = #{clearDate},
</if>
<if test="clearPerson != null">
clear_person = #{clearPerson},
</if>
......@@ -22,6 +25,6 @@
continue_date = #{continueDate},
</if>
</set>
where query_column = #{queryColumn}
where id = #{id}
</update>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment