| | |
| | | package com.iailab.module.ansteel.job.task; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.iailab.module.ansteel.common.constant.CommonConstant; |
| | | import com.iailab.module.model.api.mcs.McsApi; |
| | | import com.iailab.module.model.api.mcs.dto.AlarmMessageRespDTO; |
| | | import com.iailab.module.model.api.mdk.MdkApi; |
| | | import com.iailab.module.model.api.mdk.dto.MdkScheduleReqDTO; |
| | | import com.iailab.module.model.api.mdk.dto.MdkScheduleRespDTO; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Calendar; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | |
| | | @Autowired |
| | | private McsApi mcsApi; |
| | | |
| | | @Autowired |
| | | private MdkApi mdkApi; |
| | | @Override |
| | | public void run(String params) { |
| | | // {'status_code': 100, 'result': { |
| | | // 'code220': '100', 'code66': '100', |
| | | // '220kVPointReactivePowerInjectionIntoGrid': {'title': '220KV望铁关口无功上网', 'reason': '["大型发电机无功增加", "热轧甲线: 无功减少可能由工序检修引起"]'}, |
| | | // '66kVPointReactivePowerInjectionIntoGrid': {'title': '66KV范家变无功上网', 'reason': '["范铁乙线无功上网:可能因工序突降导致无功减少", "范钢甲线无功上网:炼钢总降#2电容器投运, 炼钢总降#4电容器投运, 炼钢总降#6电容器投运, 炼钢总降#8电容器投运", "范氧甲线无功上网"]'}}} |
| | | logger.info("RunPowerNetAlarmTask定时任务正在执行,参数为:{}", params); |
| | | try { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.set(Calendar.SECOND, 0); |
| | | calendar.set(Calendar.MILLISECOND, 0); |
| | | |
| | | AlarmMessageRespDTO alarmMessageRespDTO = new AlarmMessageRespDTO(); |
| | | alarmMessageRespDTO.setContent("焦化甲线: 无功减少可能由该工序下电容器投运引起;原料甲线: 可能由工序检修引起; 1#炼铁线: 无功减少可能由1#TRT发电机无功增加引起; 2#氧气线: 可能由工序检修引起"); |
| | | alarmMessageRespDTO.setTitle("大型发电机无功增加"); |
| | | alarmMessageRespDTO.setAlarmObj(ALARM_OBJ); |
| | | alarmMessageRespDTO.setAlarmTime(calendar.getTime()); |
| | | alarmMessageRespDTO.setCreateTime(calendar.getTime()); |
| | | |
| | | mcsApi.createAlarmMessage(alarmMessageRespDTO); |
| | | MdkScheduleReqDTO dto = new MdkScheduleReqDTO(); |
| | | dto.setScheduleTime(calendar.getTime()); |
| | | dto.setScheduleCode(ALARM_OBJ); |
| | | MdkScheduleRespDTO mdkScheduleRespDTO = mdkApi.doSchedule(dto); |
| | | logger.info(params + "调度方案执行完成," + mdkScheduleRespDTO); |
| | | if(!CommonConstant.MDK_STATUS_100.equals(mdkScheduleRespDTO.getStatusCode())){ |
| | | logger.info(params + "运行异常"); |
| | | return; |
| | | } |
| | | JSONObject obj = new JSONObject(mdkScheduleRespDTO.getResult()); |
| | | Map<String,Object> result = BeanUtil.beanToMap(obj); |
| | | if(CommonConstant.MDK_STATUS_100.equals(result.get("code220"))){ |
| | | createAlarmMessage(result,"220kVPointReactivePowerInjectionIntoGrid",calendar); |
| | | } |
| | | if(CommonConstant.MDK_STATUS_100.equals(result.get("code66"))){ |
| | | createAlarmMessage(result,"66kVPointReactivePowerInjectionIntoGrid",calendar); |
| | | } |
| | | } catch (Exception ex) { |
| | | logger.error("RunPowerNetAlarmTask运行异常"); |
| | | ex.printStackTrace(); |
| | | } |
| | | logger.info("RunPowerNetAlarmTask运行完成"); |
| | | } |
| | | private void createAlarmMessage( Map<String,Object> result , String type,Calendar calendar){ |
| | | Map<String,Object> map = BeanUtil.beanToMap(result.get(type)); |
| | | if (CollectionUtils.isEmpty(map) || map.get("reason") == null) { |
| | | return; |
| | | } |
| | | try { |
| | | StringBuilder contentBuilder = new StringBuilder(); |
| | | JSONArray jsonArr = JSON.parseArray(map.get("reason").toString()); |
| | | for(int i = 0; i < jsonArr.size(); i++) { |
| | | Object element = jsonArr.get(i); |
| | | if (element != null) { |
| | | contentBuilder.append(JSON.toJSONString(element)).append(";"); |
| | | } |
| | | } |
| | | |
| | | AlarmMessageRespDTO alarmMessageRespDTO = new AlarmMessageRespDTO(); |
| | | alarmMessageRespDTO.setContent(contentBuilder.toString()); |
| | | alarmMessageRespDTO.setTitle(map.get("title").toString()); |
| | | alarmMessageRespDTO.setAlarmObj(ALARM_OBJ); |
| | | alarmMessageRespDTO.setAlarmTime(calendar.getTime()); |
| | | alarmMessageRespDTO.setCreateTime(calendar.getTime()); |
| | | mcsApi.createAlarmMessage(alarmMessageRespDTO); |
| | | } catch (Exception e) { |
| | | logger.error("创建报警消息失败", e); |
| | | } |
| | | } |
| | | } |