|
@@ -1,21 +1,24 @@
|
|
package com.huaxu.service.impl;
|
|
package com.huaxu.service.impl;
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
+import com.huaxu.client.OperationManagerClient;
|
|
|
|
+import com.huaxu.client.UserCenterClient;
|
|
import com.huaxu.dao.AlarmDetailMapper;
|
|
import com.huaxu.dao.AlarmDetailMapper;
|
|
-import com.huaxu.dto.AlarmDetailsDto;
|
|
|
|
-import com.huaxu.dto.AlarmDetailsHistoryDto;
|
|
|
|
-import com.huaxu.dto.AlarmDetailsRealTimeDto;
|
|
|
|
-import com.huaxu.dto.DeviceCheckAlarmDto;
|
|
|
|
|
|
+import com.huaxu.dto.*;
|
|
import com.huaxu.entity.AlarmDetailsEntity;
|
|
import com.huaxu.entity.AlarmDetailsEntity;
|
|
|
|
+import com.huaxu.entity.Message;
|
|
import com.huaxu.model.LoginUser;
|
|
import com.huaxu.model.LoginUser;
|
|
import com.huaxu.service.AlarmDetailsService;
|
|
import com.huaxu.service.AlarmDetailsService;
|
|
|
|
+import com.huaxu.util.DatesUtil;
|
|
|
|
+import com.huaxu.util.MessageSendUtil;
|
|
import com.huaxu.util.UserUtil;
|
|
import com.huaxu.util.UserUtil;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
-import java.util.Date;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
+import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -28,6 +31,12 @@ public class AlarmDetailsServiceImpl implements AlarmDetailsService {
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
private AlarmDetailMapper alarmDetailMapper;
|
|
private AlarmDetailMapper alarmDetailMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private OperationManagerClient operationManagerClient;
|
|
|
|
+ @Autowired
|
|
|
|
+ private UserCenterClient userCenterClient;
|
|
|
|
+ @Autowired
|
|
|
|
+ private MessageSendUtil messageSendUtil;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public AlarmDetailsDto selectById(Integer id) {
|
|
public AlarmDetailsDto selectById(Integer id) {
|
|
@@ -179,6 +188,32 @@ public class AlarmDetailsServiceImpl implements AlarmDetailsService {
|
|
alarmDetailsEntity.setDeviceId(d.getDeviceId());
|
|
alarmDetailsEntity.setDeviceId(d.getDeviceId());
|
|
alarmDetailsEntity.setTenantId(d.getTenantId());
|
|
alarmDetailsEntity.setTenantId(d.getTenantId());
|
|
alarmDetailsEntity.setAlarmSettingId(d.getAlarmSettingId());
|
|
alarmDetailsEntity.setAlarmSettingId(d.getAlarmSettingId());
|
|
|
|
+
|
|
|
|
+ Message message=new Message();
|
|
|
|
+ message.setStatus(1);
|
|
|
|
+ message.setCreateBy("system");
|
|
|
|
+ message.setTenantId(d.getTenantId());
|
|
|
|
+ message.setMessageId(UUID.randomUUID().toString());
|
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
|
+ //${场景名称}${设备名称}${状态}${报警规则}【${数值单位}】
|
|
|
|
+ jsonObject.put("场景名称",d.getSceneName());
|
|
|
|
+ jsonObject.put("设备名称",d.getDeviceName());
|
|
|
|
+ jsonObject.put("状态","离线");
|
|
|
|
+ jsonObject.put("报警规则",d.getAlarmCondition() +d.getAlarmValue());
|
|
|
|
+ jsonObject.put("数值单位","分钟");
|
|
|
|
+ message.setMessageContent(jsonObject.toJSONString()); //消息内容,如果需要动态使用,配合模板使用{key:value}
|
|
|
|
+ message.setMessageType(2); //消息类型
|
|
|
|
+ message.setMessageTemplateId(2); //模板id
|
|
|
|
+ message.setChannel(0); //渠道
|
|
|
|
+ Integer companyOrgId = d.getCompanyOrgId();
|
|
|
|
+ Integer departmentOrgId = d.getDeptOrgId();
|
|
|
|
+ List<Integer> taskUsers = userCenterClient.findUserIdsByPermissonOrg(d.getTenantId(),companyOrgId,departmentOrgId);
|
|
|
|
+ if(taskUsers!=null){
|
|
|
|
+ taskUsers.forEach(id->{
|
|
|
|
+ message.setUserId(id);
|
|
|
|
+ messageSendUtil.send(message);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
return alarmDetailsEntity;
|
|
return alarmDetailsEntity;
|
|
})
|
|
})
|
|
.collect(Collectors.toList());
|
|
.collect(Collectors.toList());
|
|
@@ -213,4 +248,71 @@ public class AlarmDetailsServiceImpl implements AlarmDetailsService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public void saveWorkOrderManageInfo(){
|
|
|
|
+ List<DeviceAlarmInfoForOrder> deviceAlarmInfoForOrders = alarmDetailMapper.getAlarmInfoForWorkOrderManage();
|
|
|
|
+ if(deviceAlarmInfoForOrders.size()>0){
|
|
|
|
+ List<WorkOrderManageByAlarmDto> workOrderManageByAlarms = new ArrayList<>();
|
|
|
|
+ List<DeviceAlarmInfoForOrder> errData= new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ //组合工单,并发送消息
|
|
|
|
+ for(DeviceAlarmInfoForOrder deviceAlarmInfoForOrder : deviceAlarmInfoForOrders){
|
|
|
|
+ WorkOrderManageByAlarmDto workOrderManageByAlarm = new WorkOrderManageByAlarmDto();
|
|
|
|
+ workOrderManageByAlarm.setTaskNo(DatesUtil.formatDate(new Date(),"yyyyMMddHHmmssSSS")+((int) (Math.random()*(9999-1000)+1000)));
|
|
|
|
+ workOrderManageByAlarm.setTenantId(deviceAlarmInfoForOrder.getTenantId());
|
|
|
|
+ workOrderManageByAlarm.setCompanyOrgId(deviceAlarmInfoForOrder.getCompanyOrgId());
|
|
|
|
+ workOrderManageByAlarm.setDepartmentOrgId(deviceAlarmInfoForOrder.getDepartmentOrgId());
|
|
|
|
+ workOrderManageByAlarm.setAddress(deviceAlarmInfoForOrder.getAddress());
|
|
|
|
+ workOrderManageByAlarm.setGeo(deviceAlarmInfoForOrder.getGeo());
|
|
|
|
+ workOrderManageByAlarm.setOrderTime(deviceAlarmInfoForOrder.getOrderTime());
|
|
|
|
+ workOrderManageByAlarm.setTaskDesc(deviceAlarmInfoForOrder.getTaskDesc());
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ Message message=new Message();
|
|
|
|
+ message.setStatus(1);
|
|
|
|
+ message.setCreateBy("system");
|
|
|
|
+ message.setTenantId(deviceAlarmInfoForOrder.getTenantId());
|
|
|
|
+ message.setMessageId(UUID.randomUUID().toString());
|
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
|
+ jsonObject.put("工单类型","");
|
|
|
|
+ jsonObject.put("工单编号",workOrderManageByAlarm.getTaskNo());
|
|
|
|
+ message.setMessageContent(jsonObject.toJSONString()); //消息内容,如果需要动态使用,配合模板使用{key:value}
|
|
|
|
+ message.setMessageType(7); //消息类型
|
|
|
|
+ message.setMessageTemplateId(7); //模板id
|
|
|
|
+ message.setChannel(0); //渠道
|
|
|
|
+ Integer companyOrgId = null;
|
|
|
|
+ Integer departmentOrgId = null;
|
|
|
|
+ if(StringUtils.isNotBlank(workOrderManageByAlarm.getCompanyOrgId())){
|
|
|
|
+ companyOrgId=Integer.valueOf(workOrderManageByAlarm.getCompanyOrgId());
|
|
|
|
+ }
|
|
|
|
+ if(StringUtils.isNotBlank(workOrderManageByAlarm.getDepartmentOrgId())){
|
|
|
|
+ departmentOrgId=Integer.valueOf(workOrderManageByAlarm.getDepartmentOrgId());
|
|
|
|
+ }
|
|
|
|
+ try{
|
|
|
|
+ List<Integer> taskUsers = userCenterClient.findUserIdsByPermissonOrg(workOrderManageByAlarm.getTenantId(),companyOrgId,departmentOrgId);
|
|
|
|
+ if(taskUsers!=null){
|
|
|
|
+ taskUsers.forEach(id->{
|
|
|
|
+ message.setUserId(id);
|
|
|
|
+ messageSendUtil.send(message);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ workOrderManageByAlarms.add(workOrderManageByAlarm);
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ errData.add(deviceAlarmInfoForOrder);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //去掉推送失败的数据
|
|
|
|
+ if(errData.size()>0){
|
|
|
|
+ deviceAlarmInfoForOrders.removeAll(errData);
|
|
|
|
+ }
|
|
|
|
+ //保存工单
|
|
|
|
+ Integer resut = operationManagerClient.saveByAlarms(workOrderManageByAlarms);
|
|
|
|
+
|
|
|
|
+ if(resut > 0) {
|
|
|
|
+ alarmDetailMapper.updateAlarmSendMessageState(deviceAlarmInfoForOrders);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|