Commit f71e95e8 by YG8999

添加保洁短信提醒控制开关,添加网关离线短信提醒,去掉设备操作服务中的开门和取电延时操作

parent f4c56ee8
......@@ -15,6 +15,7 @@ public enum SmsTypeEnum {
SMS_ORDER_END_TEMP(5,"sms.order.end.template","订单即将结束提示短信"),
SMS_CLEAN_RECORDS_STOP_TEMP(6,"sms.clean.records.stop.template","保洁任务中断短信提醒"),
SMS_DEVICE_ABNORMAL_TEMP(7,"sms.device.abnormal.template","设备状态异常变更短信提醒"),
SMS_DEVICE_GATEWAY_TEMP(8,"sms.device.gateway.template","网关设备离线提醒短信"),
;
private Integer code;
......
......@@ -8,8 +8,8 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
public enum YesNoEnum {
yes(1, true, "是", "激活", "正常", "", "", "", "", "", ""),
no(0, false, "否", "冻结", "异常", "", "", "", "", "", "");
yes(1, true, "是", "激活", "正常", "Y", "", "", "", "", ""),
no(0, false, "否", "冻结", "异常", "N", "", "", "", "", "");
private Integer index;
......
......@@ -2,9 +2,12 @@ package share.quartz.task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import share.system.domain.DeviceGateway;
import share.system.service.DeviceGatewayService;
import share.system.service.DeviceStatusLogService;
import java.util.List;
/**
* @className: share.quartz.task.DeviceTask
* @description: 设备定时任务
......@@ -32,9 +35,12 @@ public class DeviceTask {
*/
public void deviceGatewayStatusMonitor() {
// 更新网关状态
boolean b = deviceGatewayService.deviceGatewayStatusMonitor();
if (b) {
List<DeviceGateway> list = deviceGatewayService.deviceGatewayStatusMonitor();
if (list.size() > 0) {
// 离线网关,发送短信提醒
list.forEach(deviceGateway -> {
deviceGatewayService.sendSmsByStatusOff(deviceGateway);
});
}
}
......
......@@ -64,9 +64,16 @@ public interface DeviceGatewayService extends IService<DeviceGateway>
/**
* 网关状态监控
* @return
* @return 离线发送短信提醒的网关对象
*/
boolean deviceGatewayStatusMonitor();
List<DeviceGateway> deviceGatewayStatusMonitor();
TableDataInfo deviceGatewayPage(DeviceGatewayDto deviceGatewayDto);
/**
* 网关离线发送短信提醒
* @param deviceGateway
* @return
*/
boolean sendSmsByStatusOff(DeviceGateway deviceGateway);
}
......@@ -2,6 +2,7 @@ package share.system.service;
import cn.hutool.json.JSONArray;
import share.system.domain.DeviceGateway;
import share.system.domain.DeviceStatusLog;
import share.system.domain.SRoom;
import share.system.domain.SStore;
......@@ -60,5 +61,11 @@ public interface SmsService {
*/
boolean sendSmsDeviceAbnormal(String phone, DeviceStatusLog deviceStatusLog, SStore store, SRoom room);
/**
* 网关离线,发送短信通知
* @return
*/
boolean sendSmsByGatewayOff(String phone, DeviceGateway deviceGateway, SStore store);
}
......@@ -17,18 +17,18 @@ import share.common.core.page.PageDomain;
import share.common.core.page.TableDataInfo;
import share.common.core.page.TableSupport;
import share.common.enums.DeviceStatusEnum;
import share.common.enums.YesNoEnum;
import share.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import share.system.domain.Device;
import share.system.domain.DeviceGatewayDto;
import share.system.domain.SStore;
import share.system.domain.*;
import share.system.domain.vo.DeviceGatewayVo;
import share.system.domain.vo.DeviceVo;
import share.system.mapper.DeviceGatewayMapper;
import share.system.domain.DeviceGateway;
import share.system.mapper.SStoreMapper;
import share.system.service.DeviceGatewayService;
import share.system.service.ISysConfigService;
import share.system.service.SmsService;
/**
* 设备网关信息Service业务层处理
......@@ -46,6 +46,11 @@ public class DeviceGatewayServiceImpl extends ServiceImpl<DeviceGatewayMapper, D
private Integer deviceGatewayLastReportTime;
@Autowired
private SStoreMapper storeMapper;
@Autowired
private ISysConfigService sysConfigService;
@Autowired
private SmsService smsService;
/**
* 查询设备网关信息
......@@ -126,19 +131,29 @@ public class DeviceGatewayServiceImpl extends ServiceImpl<DeviceGatewayMapper, D
* @return
*/
@Override
public boolean deviceGatewayStatusMonitor() {
public List<DeviceGateway> deviceGatewayStatusMonitor() {
List<DeviceGateway> list = deviceGatewayMapper.selectDeviceGatewayList(new DeviceGatewayDto());
List<DeviceGateway> sendList = new ArrayList<>();
if (list.size() > 0) {
list.stream().forEach(gateway -> {
Date lastReportDate = gateway.getLastReportDate();
// 网关上报(最近10分钟内没有上报数据,网关设备离线)
Date startDate = DateUtil.offsetMinute(DateUtil.date(), deviceGatewayLastReportTime);
String status = gateway.getStatus();
if (lastReportDate != null && lastReportDate.compareTo(startDate) > 0) {
gateway.setStatus(DeviceStatusEnum.DEVICE_ONLINE.getCode());
} else {
if (DeviceStatusEnum.DEVICE_ONLINE.getCode().equals(status)) {
// 如果网关之前在线,变更离线需要发送短信提醒
sendList.add(gateway);
}
gateway.setStatus(DeviceStatusEnum.DEVICE_OFFLINE.getCode());
}
});
return this.updateBatchById(list);
// 更新数据
this.updateBatchById(list);
}
return sendList;
}
@Override
......@@ -169,6 +184,24 @@ public class DeviceGatewayServiceImpl extends ServiceImpl<DeviceGatewayMapper, D
return tableDataInfo;
}
/**
* 网关离线发送短信提醒
* @param deviceGateway 网关对象
* @return
*/
@Override
public boolean sendSmsByStatusOff(DeviceGateway deviceGateway) {
LambdaQueryWrapper<SStore> queryWrapper = new LambdaQueryWrapper();
queryWrapper.eq(SStore::getDeviceGroup, deviceGateway.getGroup());
SStore store = storeMapper.selectOne(queryWrapper);
if (store != null) {
String phone = sysConfigService.selectConfigByKey("system.device.phone");
// 发送短信提醒
return smsService.sendSmsByGatewayOff(phone, deviceGateway, store);
}
return Boolean.FALSE;
}
private List<DeviceGatewayVo> convertDosToVos(List<DeviceGateway> deviceGateways) {
List<DeviceGatewayVo> voList = new ArrayList<>();
if (CollectionUtils.isNotEmpty(deviceGateways)) {
......
......@@ -131,11 +131,11 @@ public class DeviceOpServiceImpl implements DeviceOpService {
if (device != null) {
if (DeviceType.DEVICE_CCEE.getCode().equals(device.getDevType())) {
// 门锁
this.deviceOpInit(device.getDevId(), deviceParam.getPhone(), deviceParam.getOpType(), true, 2L);
this.deviceOpInit(device.getDevId(), deviceParam.getPhone(), deviceParam.getOpType(), false, 0);
}
if (DeviceType.DEVICE_0001.getCode().equals(device.getDevType())) {
// 取电开关
this.deviceOpInit(device.getDevId(), deviceParam.getPhone(), deviceParam.getOpType(), true, 2L);
this.deviceOpInit(device.getDevId(), deviceParam.getPhone(), deviceParam.getOpType(), false, 0);
}
}
}
......@@ -153,11 +153,11 @@ public class DeviceOpServiceImpl implements DeviceOpService {
for (Device device : list) {
if (DeviceType.DEVICE_CCEE.getCode().equals(device.getDevType())) {
// 门锁
this.deviceOpInit(device.getDevId(), deviceParam.getPhone(), OpTypeEnum.OPEN_DOOR.getCode(), false, 0L);
this.deviceOpInit(device.getDevId(), deviceParam.getPhone(), OpTypeEnum.OPEN_DOOR.getCode(), false, 0);
}
if (DeviceType.DEVICE_0001.getCode().equals(device.getDevType())) {
// 取电开关
this.deviceOpInit(device.getDevId(), deviceParam.getPhone(), OpTypeEnum.GET_ELECTRIC.getCode(), true, 4L);
this.deviceOpInit(device.getDevId(), deviceParam.getPhone(), OpTypeEnum.GET_ELECTRIC.getCode(), false, 0);
}
}
......@@ -182,7 +182,7 @@ public class DeviceOpServiceImpl implements DeviceOpService {
}
if (DeviceType.DEVICE_0001.getCode().equals(device.getDevType())) {
// 取电开关
this.deviceOpInit(device.getDevId(), phone, OpTypeEnum.GET_ELECTRIC.getCode(), true, 4L);
this.deviceOpInit(device.getDevId(), phone, OpTypeEnum.GET_ELECTRIC.getCode(), false, 0);
}
}
......
......@@ -16,11 +16,13 @@ import share.common.core.redis.RedisUtil;
import share.common.enums.DeviceStatusEnum;
import share.common.enums.SmsStatusEnum;
import share.common.enums.SmsTypeEnum;
import share.common.enums.YesNoEnum;
import share.common.exception.base.BaseException;
import share.common.utils.BaseUtil;
import share.common.utils.SmsUtil;
import share.system.domain.*;
import share.system.mapper.SysConfigMapper;
import share.system.service.ISysConfigService;
import share.system.service.SConsumerService;
import share.system.service.SmsLogService;
import share.system.service.SmsService;
......@@ -64,7 +66,7 @@ public class SmsServiceImpl implements SmsService {
@Autowired
private RedisUtil redisUtil;
@Autowired
private SysConfigMapper sysConfigMapper;
private ISysConfigService sysConfigService;
@Autowired
private SmsLogService smsLogService;
......@@ -103,34 +105,46 @@ public class SmsServiceImpl implements SmsService {
@Override
public boolean sendSmsCleanRecords(String phone, SStore store, SRoom room) {
// 是否发送保洁短信
String isSendSms = sysConfigService.selectConfigByKey("system.isclean.send.sms");
if (YesNoEnum.yes.getDisplay_4().equals(isSendSms)) {
// 通过配置获取短信模版
SysConfig config = sysConfigMapper.checkConfigKeyUnique(SmsTypeEnum.SMS_CLEAN_RECORDS_TEMP.getValue());
if (config != null) {
String content = MessageFormat.format(config.getConfigValue(), store.getName(), room.getName(), store.getAddress());
String configValue = sysConfigService.selectConfigByKey(SmsTypeEnum.SMS_CLEAN_RECORDS_TEMP.getValue());
if (StrUtil.isNotEmpty(configValue)) {
String content = MessageFormat.format(configValue, store.getName(), room.getName(), store.getAddress());
return sendSms(phone, SmsTypeEnum.SMS_CLEAN_RECORDS_TEMP.getCode(), content, store.getId(), room.getId());
} else {
return Boolean.FALSE;
}
} else {
return Boolean.TRUE;
}
}
@Override
public boolean sendSmsCleanRecordsRemind15(String phone, SStore store, SRoom room) {
// 是否发送保洁短信
String isSendSms = sysConfigService.selectConfigByKey("system.isclean.send.sms");
if (YesNoEnum.yes.getDisplay_4().equals(isSendSms)) {
// 通过配置获取短信模版
SysConfig config = sysConfigMapper.checkConfigKeyUnique(SmsTypeEnum.SMS_CLEAN_RECORDS_TEMP_15.getValue());
if (config != null) {
String content = MessageFormat.format(config.getConfigValue(), store.getName(), room.getName(), store.getAddress());
String configValue = sysConfigService.selectConfigByKey(SmsTypeEnum.SMS_CLEAN_RECORDS_TEMP_15.getValue());
if (StrUtil.isNotEmpty(configValue)) {
String content = MessageFormat.format(configValue, store.getName(), room.getName(), store.getAddress());
return sendSms(phone, SmsTypeEnum.SMS_CLEAN_RECORDS_TEMP_15.getCode(), content, store.getId(), room.getId());
} else {
return Boolean.FALSE;
}
} else {
return Boolean.TRUE;
}
}
@Override
public boolean sendSmsOrderStartRemind(String phone, SStore store, SRoom room) {
// 通过配置获取短信模版
SysConfig config = sysConfigMapper.checkConfigKeyUnique(SmsTypeEnum.SMS_ORDER_START_TEMP.getValue());
if (config != null) {
String content = MessageFormat.format(config.getConfigValue(), room.getName(), store.getAddress());
String configValue = sysConfigService.selectConfigByKey(SmsTypeEnum.SMS_ORDER_START_TEMP.getValue());
if (StrUtil.isNotEmpty(configValue)) {
String content = MessageFormat.format(configValue, room.getName(), store.getAddress());
return sendSms(phone, SmsTypeEnum.SMS_ORDER_START_TEMP.getCode(), content, store.getId(), room.getId());
} else {
return Boolean.FALSE;
......@@ -140,9 +154,9 @@ public class SmsServiceImpl implements SmsService {
@Override
public boolean sendSmsOrderEndRemind(String phone, SStore store, SRoom room) {
// 通过配置获取短信模版
SysConfig config = sysConfigMapper.checkConfigKeyUnique(SmsTypeEnum.SMS_ORDER_END_TEMP.getValue());
if (config != null) {
String content = MessageFormat.format(config.getConfigValue(), room.getName());
String configValue = sysConfigService.selectConfigByKey(SmsTypeEnum.SMS_ORDER_END_TEMP.getValue());
if (StrUtil.isNotEmpty(configValue)) {
String content = MessageFormat.format(configValue, room.getName());
return sendSms(phone, SmsTypeEnum.SMS_ORDER_END_TEMP.getCode(), content, store.getId(), room.getId());
} else {
return Boolean.FALSE;
......@@ -151,22 +165,28 @@ public class SmsServiceImpl implements SmsService {
@Override
public boolean sendSmsCleanRecordsStopRemind(String phone, SStore store, SRoom room) {
// 是否发送保洁短信
String isSendSms = sysConfigService.selectConfigByKey("system.isclean.send.sms");
if (YesNoEnum.yes.getDisplay_4().equals(isSendSms)) {
// 通过配置获取短信模版
SysConfig config = sysConfigMapper.checkConfigKeyUnique(SmsTypeEnum.SMS_CLEAN_RECORDS_STOP_TEMP.getValue());
if (config != null) {
String content = MessageFormat.format(config.getConfigValue(), store.getName(), room.getName(), store.getAddress());
String configValue = sysConfigService.selectConfigByKey(SmsTypeEnum.SMS_CLEAN_RECORDS_STOP_TEMP.getValue());
if (StrUtil.isNotEmpty(configValue)) {
String content = MessageFormat.format(configValue, store.getName(), room.getName(), store.getAddress());
return sendSms(phone, SmsTypeEnum.SMS_CLEAN_RECORDS_STOP_TEMP.getCode(), content, store.getId(), room.getId());
} else {
return Boolean.FALSE;
}
} else {
return Boolean.TRUE;
}
}
@Override
public boolean sendSmsDeviceAbnormal(String phone, DeviceStatusLog deviceStatusLog, SStore store, SRoom room) {
// 通过配置获取短信模版
SysConfig config = sysConfigMapper.checkConfigKeyUnique(SmsTypeEnum.SMS_DEVICE_ABNORMAL_TEMP.getValue());
if (config != null) {
String content = MessageFormat.format(config.getConfigValue(), store.getName(), room.getName(),
String configValue = sysConfigService.selectConfigByKey(SmsTypeEnum.SMS_DEVICE_ABNORMAL_TEMP.getValue());
if (StrUtil.isNotEmpty(configValue)) {
String content = MessageFormat.format(configValue, store.getName(), room.getName(),
DeviceStatusEnum.getNameStr(deviceStatusLog.getStatus()));
return sendSms(phone, SmsTypeEnum.SMS_DEVICE_ABNORMAL_TEMP.getCode(), content, store.getId(), room.getId());
} else {
......@@ -174,12 +194,30 @@ public class SmsServiceImpl implements SmsService {
}
}
@Override
public boolean sendSmsByGatewayOff(String phone, DeviceGateway deviceGateway, SStore store) {
// 是否发送网关离线提醒短信
String isSendSms = sysConfigService.selectConfigByKey("system.gateway.issend.sms");
if (YesNoEnum.yes.getDisplay_4().equals(isSendSms)) {
// 通过配置获取短信模版
String configValue = sysConfigService.selectConfigByKey(SmsTypeEnum.SMS_DEVICE_GATEWAY_TEMP.getValue());
if (StrUtil.isNotEmpty(configValue)) {
String content = MessageFormat.format(configValue, store.getName(), deviceGateway.getDevId());
return sendSms(phone, SmsTypeEnum.SMS_DEVICE_GATEWAY_TEMP.getCode(), content, store.getId(), null);
} else {
return Boolean.FALSE;
}
} else {
return Boolean.TRUE;
}
}
private String getSmsContent(String phone, Integer tag) {
// 验证码 特殊处理 code
if (tag.equals(SmsTypeEnum.SMS_CODE_TEMP.getCode())) {
// 通过配置获取短信模版
SysConfig config = sysConfigMapper.checkConfigKeyUnique(SmsTypeEnum.SMS_CODE_TEMP.getValue());
if (config != null) {
String configValue = sysConfigService.selectConfigByKey(SmsTypeEnum.SMS_CODE_TEMP.getValue());
if (StrUtil.isNotEmpty(configValue)) {
// 获取短信验证码过期时间
String codeExpireStr = Constants.CONFIG_KEY_SMS_CODE_EXPIRE;
if (StrUtil.isBlank(codeExpireStr) || Integer.parseInt(codeExpireStr) == 0) {
......@@ -189,7 +227,7 @@ public class SmsServiceImpl implements SmsService {
Integer code = BaseUtil.randomCount(111111, 999999);
// 将验证码存入redis
redisUtil.set(sConsumerService.getValidateCodeRedisKey(phone), code, Long.valueOf(codeExpireStr), TimeUnit.MINUTES);
return MessageFormat.format(config.getConfigValue(), code.toString(), codeExpireStr);
return MessageFormat.format(configValue, code.toString(), codeExpireStr);
}
} // 其他短信内容处理
......
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