|
@@ -1,12 +1,22 @@
|
|
|
package com.szwl.service.impl;
|
|
|
|
|
|
-import com.szwl.model.entity.TAlarmRecord;
|
|
|
-import com.szwl.mapper.TAlarmRecordMapper;
|
|
|
-import com.szwl.service.TAlarmRecordService;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.szwl.constant.ConfigConsts;
|
|
|
+import com.szwl.mapper.TAlarmRecordMapper;
|
|
|
+import com.szwl.model.dto.AlarmRecordVo;
|
|
|
+import com.szwl.model.entity.*;
|
|
|
+import com.szwl.model.utils.YunPianSms;
|
|
|
+import com.szwl.service.*;
|
|
|
+import com.szwl.util.TimezoneFmtUtil;
|
|
|
+import com.szwl.util.WechatSendUtil;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
@@ -19,9 +29,22 @@ import java.util.List;
|
|
|
*/
|
|
|
@Service
|
|
|
public class TAlarmRecordServiceImpl extends ServiceImpl<TAlarmRecordMapper, TAlarmRecord> implements TAlarmRecordService {
|
|
|
+
|
|
|
@Autowired
|
|
|
private TAlarmRecordMapper tAlarmRecordMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private TEquipmentService equipmentService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TAdminService adminService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TWechatService wechatService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TAdminEquipmentService adminEquipmentService;
|
|
|
+
|
|
|
@Override
|
|
|
public List<TAlarmRecord> getAlarmList(Long adminId) {
|
|
|
return tAlarmRecordMapper.getAlarmList(adminId);
|
|
@@ -31,4 +54,136 @@ public class TAlarmRecordServiceImpl extends ServiceImpl<TAlarmRecordMapper, TAl
|
|
|
public List<TAlarmRecord> getLastAlarmRecord(Long id) {
|
|
|
return tAlarmRecordMapper.getLastAlarmRecord(id);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void addAlarmRecord(AlarmRecordVo alarmRecordVo) {
|
|
|
+ TAlarmRecord alarmRecord = new TAlarmRecord();
|
|
|
+
|
|
|
+ String clientId = alarmRecordVo.getClientId();
|
|
|
+ LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
|
|
|
+ query.eq(TEquipment::getClientId, clientId);
|
|
|
+ TEquipment equipment = equipmentService.getOne(query);
|
|
|
+ if (equipment != null) {
|
|
|
+ Integer type = equipment.getType();
|
|
|
+ Long adminId = equipment.getAdminId();
|
|
|
+ Long equipmentId = equipment.getId();
|
|
|
+ String name = equipment.getName();
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(name)) {
|
|
|
+ name = clientId.substring(clientId.length() - 6);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新设备状态为报警
|
|
|
+ equipment.setIsAlarm(true);
|
|
|
+ equipmentService.updateById(equipment);
|
|
|
+ String adminUserName = equipment.getAdminUserName();
|
|
|
+ alarmRecord.setEquipmentId(equipmentId);
|
|
|
+ alarmRecord.setName(name);
|
|
|
+ alarmRecord.setAdminLevel(equipment.getAdminLevel());
|
|
|
+ alarmRecord.setClientId(clientId);
|
|
|
+ alarmRecord.setType(type);
|
|
|
+ alarmRecord.setAdminId(adminId);
|
|
|
+ alarmRecord.setCreateDate(new Date());
|
|
|
+ alarmRecord.setModifyDate(new Date());
|
|
|
+ alarmRecord.setAdminUserName(adminUserName);
|
|
|
+ String alarmContent = alarmRecordVo.getAlarmContent();
|
|
|
+ alarmRecord.setAlarmContent(alarmContent);
|
|
|
+ alarmRecord.setRemark(alarmRecordVo.getRemark());
|
|
|
+ alarmRecord.setOccurrenceTime(alarmRecordVo.getOccurrenceTime());
|
|
|
+ alarmRecord.setIsEliminate(0);
|
|
|
+ if (alarmRecordVo.getLevel() != null) {
|
|
|
+ alarmRecord.setLevel(alarmRecordVo.getLevel());
|
|
|
+ }
|
|
|
+ this.save(alarmRecord);
|
|
|
+ TAdmin admin = adminService.getById(adminId);
|
|
|
+ String email = admin.getEmail();
|
|
|
+ String ifForeign = admin.getIfForeign();
|
|
|
+ String companyType = admin.getCompanyType();
|
|
|
+ String messageReceiver = equipment.getMessageReceiver();
|
|
|
+ String timeZone = admin.getTimeZone();
|
|
|
+ timeZone = StringUtils.isEmpty(timeZone) ? "Asia/Shanghai" : timeZone;
|
|
|
+ // 根据时区获取时间
|
|
|
+ String localTime = TimezoneFmtUtil.getTimeByZoneID(timeZone);
|
|
|
+ // 查询是否绑定微信
|
|
|
+ LambdaQueryWrapper<TWechat> wechatQuery = Wrappers.lambdaQuery();
|
|
|
+ wechatQuery.eq(TWechat::getAdminId, admin.getId());
|
|
|
+ TWechat wechat = wechatService.getOne(wechatQuery);
|
|
|
+ ArrayList<String> openIds = new ArrayList<>();
|
|
|
+ if (wechat != null) {
|
|
|
+ openIds.add(wechat.getOpenId());
|
|
|
+ }
|
|
|
+ // 查询子账号
|
|
|
+ LambdaQueryWrapper<TAdmin> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.eq(TAdmin::getParentId, admin.getId());
|
|
|
+ List<TAdmin> adminList = adminService.list(queryWrapper);
|
|
|
+ if (!adminList.isEmpty()) {
|
|
|
+ for (TAdmin adminChild : adminList) {
|
|
|
+ // 查找子账号是否管理该机器
|
|
|
+ TAdminEquipment adminEquipment = adminEquipmentService.getById(adminChild.getId());
|
|
|
+ if (adminEquipment != null) {
|
|
|
+ String equipmentIds = adminEquipment.getEquipmentIds();
|
|
|
+ if (equipmentIds.contains(equipmentId.toString()) || "0".equals(adminEquipment.getType())) {
|
|
|
+ // 查询子账号是否绑定微信
|
|
|
+ LambdaQueryWrapper<TWechat> wechatLambdaQueryWrapper = Wrappers.lambdaQuery();
|
|
|
+ wechatLambdaQueryWrapper.eq(TWechat::getAdminId, adminChild.getId());
|
|
|
+ TWechat childWechat = wechatService.getOne(wechatLambdaQueryWrapper);
|
|
|
+ if (childWechat != null) {
|
|
|
+ openIds.add(childWechat.getOpenId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 微信公众号推送
|
|
|
+ if(!openIds.isEmpty()) {
|
|
|
+ String sendContent = alarmContent;
|
|
|
+ if (sendContent.length() > 20) {
|
|
|
+ // 如果超过20个字符
|
|
|
+ sendContent = sendContent.substring(0, 16) + "...";
|
|
|
+ }
|
|
|
+ for (String openId : openIds) {
|
|
|
+ wechatService.sendAlarmMessage(openId, clientId, name, companyType, sendContent, alarmRecordVo.getOccurrenceTime());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (ifForeign.equals("1")) {
|
|
|
+ String machineType = equipment.getMachineType();
|
|
|
+ if (StringUtils.isEmpty(machineType)) {
|
|
|
+ machineType = "0";
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(messageReceiver)) {
|
|
|
+ String[] split = messageReceiver.split(",");
|
|
|
+ for (String s : split) {
|
|
|
+ WechatSendUtil.sentEmail(s, name, timeZone, machineType, alarmContent);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (email != null) {
|
|
|
+ WechatSendUtil.sentEmail(admin.getEmail(), name, timeZone, machineType, alarmContent);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 发送短信
|
|
|
+ try {
|
|
|
+ if (!"二次曲棍".equals(alarmContent)) {
|
|
|
+ if (StringUtils.isNotEmpty(messageReceiver)) {
|
|
|
+ String[] split = messageReceiver.split(",");
|
|
|
+ for (int i = 0; i < split.length; i++) {
|
|
|
+ if (StringUtils.isNotEmpty(split[i])) {
|
|
|
+ if (StringUtils.isNotEmpty(companyType) && companyType.equals("1")) {
|
|
|
+ // 如果是七云科技的用户
|
|
|
+ YunPianSms.sendSms(ConfigConsts.QINIU_APP_ID, YunPianSms.getSCMessage(alarmContent, name, clientId.substring(clientId.length() - 6)), split[i]);
|
|
|
+ } else {
|
|
|
+ // 如果是申泽智能的用户
|
|
|
+ YunPianSms.sendSms(ConfigConsts.QINIU_APP_ID, YunPianSms.getMessage(alarmContent, name, clientId.substring(clientId.length() - 6)), split[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|