|
@@ -25,6 +25,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.io.IOException;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Optional;
|
|
@@ -32,7 +33,7 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
|
- * 服务实现类
|
|
|
+ * 服务实现类
|
|
|
* </p>
|
|
|
*
|
|
|
* @author wuhs
|
|
@@ -62,7 +63,7 @@ public class TEquipmentServiceImpl extends ServiceImpl<TEquipmentMapper, TEquipm
|
|
|
@Resource
|
|
|
TWechatService wechatService;
|
|
|
|
|
|
-// @Resource
|
|
|
+ // @Resource
|
|
|
// private MqttService mqttService;
|
|
|
private final MqttService mqttService;
|
|
|
|
|
@@ -79,9 +80,9 @@ public class TEquipmentServiceImpl extends ServiceImpl<TEquipmentMapper, TEquipm
|
|
|
@Override
|
|
|
public String sentMessage(String clientId, String json) {
|
|
|
LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
|
|
|
- query.eq(TEquipment::getClientId,clientId);
|
|
|
+ query.eq(TEquipment::getClientId, clientId);
|
|
|
List<TEquipment> equipmentList = tEquipmentMapper.selectList(query);
|
|
|
- if(equipmentList.size()==0){
|
|
|
+ if (equipmentList.size() == 0) {
|
|
|
return "该设备不存在";
|
|
|
}
|
|
|
TEquipment equipment = equipmentList.get(0);
|
|
@@ -90,16 +91,21 @@ public class TEquipmentServiceImpl extends ServiceImpl<TEquipmentMapper, TEquipm
|
|
|
}
|
|
|
String channel = equipment.getChannel();
|
|
|
String equimentType = equipment.getEquimentType();
|
|
|
- if(StringUtils.isEmpty(channel)||channel.equals("1")||StringUtils.isEmpty(equimentType)){
|
|
|
+ if (StringUtils.isEmpty(channel) || channel.equals("1") || StringUtils.isEmpty(equimentType)) {
|
|
|
//用个推
|
|
|
PushUtils.push(equipment.getGtClientId(), "", "", json);
|
|
|
}
|
|
|
- if(StringUtils.isNotEmpty(channel)&&channel.equals("2")&&StringUtils.isNotEmpty(equimentType)){
|
|
|
+ if (StringUtils.isNotEmpty(channel) && channel.equals("2") && StringUtils.isNotEmpty(equimentType)) {
|
|
|
//用Mq
|
|
|
//1 创建消息
|
|
|
MessageProperties messageProperties = new MessageProperties();
|
|
|
- messageProperties.setContentType("text/plain");
|
|
|
- org.springframework.amqp.core.Message message = new org.springframework.amqp.core.Message(json.getBytes(), messageProperties);
|
|
|
+// messageProperties.setContentType("text/plain");
|
|
|
+ messageProperties.setContentType("application/json"); // 更改为JSON类型
|
|
|
+ messageProperties.setContentEncoding("UTF-8"); // 明确指定编码
|
|
|
+
|
|
|
+ // 将JSON字符串转为UTF-8字节数组
|
|
|
+ byte[] jsonBytes = json.getBytes(StandardCharsets.UTF_8);
|
|
|
+ org.springframework.amqp.core.Message message = new org.springframework.amqp.core.Message(jsonBytes, messageProperties);
|
|
|
amqpTemplate.send(equimentType, clientId, message);
|
|
|
}
|
|
|
return "success";
|
|
@@ -363,27 +369,27 @@ public class TEquipmentServiceImpl extends ServiceImpl<TEquipmentMapper, TEquipm
|
|
|
// 设备名称
|
|
|
String name = equipment.getName();
|
|
|
// 如果为空就拿设备编号后六位
|
|
|
- if(StringUtils.isEmpty(name)) {
|
|
|
+ if (StringUtils.isEmpty(name)) {
|
|
|
name = equipment.getClientId().substring(equipment.getClientId().length() - 6);
|
|
|
}
|
|
|
String machineType = equipment.getMachineType();
|
|
|
if (StringUtils.isNotEmpty(machineType)) {
|
|
|
machineType = "0";
|
|
|
}
|
|
|
- if(wechat != null) {
|
|
|
+ if (wechat != null) {
|
|
|
// 有绑定微信的话发公众号
|
|
|
String openId = wechat.getOpenId();
|
|
|
- wechatService.sendNetworkMessage(openId,equipment.getClientId(),name, ifForeign, companyType);
|
|
|
+ wechatService.sendNetworkMessage(openId, equipment.getClientId(), name, ifForeign, companyType);
|
|
|
if ("1".equals(ifForeign)) {
|
|
|
// 国外再发邮件
|
|
|
String messageReceiver = equipment.getMessageReceiver();
|
|
|
- if(StringUtils.isNotEmpty(messageReceiver)) {
|
|
|
+ if (StringUtils.isNotEmpty(messageReceiver)) {
|
|
|
String[] split = messageReceiver.split(",");
|
|
|
for (String s : split) {
|
|
|
WechatSendUtil.sentEmail(s, name, timeZone, machineType);
|
|
|
}
|
|
|
} else {
|
|
|
- if(StringUtils.isNotEmpty(admin.getEmail())){
|
|
|
+ if (StringUtils.isNotEmpty(admin.getEmail())) {
|
|
|
WechatSendUtil.sentEmail(admin.getEmail(), name, timeZone, machineType);
|
|
|
}
|
|
|
}
|
|
@@ -395,13 +401,13 @@ public class TEquipmentServiceImpl extends ServiceImpl<TEquipmentMapper, TEquipm
|
|
|
} else {
|
|
|
// 国外发送邮件
|
|
|
String messageReceiver = equipment.getMessageReceiver();
|
|
|
- if(StringUtils.isNotEmpty(messageReceiver)) {
|
|
|
+ if (StringUtils.isNotEmpty(messageReceiver)) {
|
|
|
String[] split = messageReceiver.split(",");
|
|
|
for (String s : split) {
|
|
|
WechatSendUtil.sentEmail(s, name, timeZone, machineType);
|
|
|
}
|
|
|
} else {
|
|
|
- if(StringUtils.isNotEmpty(admin.getEmail())){
|
|
|
+ if (StringUtils.isNotEmpty(admin.getEmail())) {
|
|
|
WechatSendUtil.sentEmail(admin.getEmail(), name, timeZone, machineType);
|
|
|
}
|
|
|
}
|
|
@@ -466,7 +472,7 @@ public class TEquipmentServiceImpl extends ServiceImpl<TEquipmentMapper, TEquipm
|
|
|
|
|
|
private String getInformText(String deviceId) {
|
|
|
String sms = "";
|
|
|
- if(StringUtils.isNotEmpty(deviceId)){
|
|
|
+ if (StringUtils.isNotEmpty(deviceId)) {
|
|
|
sms = "【申泽智能】您好,您名下设备编号为" + deviceId + "的机器,花型数量已推送,请重新设置价格!";
|
|
|
}
|
|
|
return sms;
|
|
@@ -474,17 +480,18 @@ public class TEquipmentServiceImpl extends ServiceImpl<TEquipmentMapper, TEquipm
|
|
|
|
|
|
/**
|
|
|
* 根据经度获取时区
|
|
|
+ *
|
|
|
* @param currentLon 当前经度
|
|
|
* @return
|
|
|
*/
|
|
|
public static int lateTimeZone(double currentLon) {
|
|
|
- int timeZone ;
|
|
|
- int shangValue = (int)(currentLon / 15);
|
|
|
- double yushuValue = Math.abs(currentLon % 15);
|
|
|
+ int timeZone;
|
|
|
+ int shangValue = (int) (currentLon / 15);
|
|
|
+ double yushuValue = Math.abs(currentLon % 15);
|
|
|
if (yushuValue <= 7.5) {
|
|
|
timeZone = shangValue;
|
|
|
} else {
|
|
|
- timeZone = shangValue +(currentLon > 0 ? 1 :-1);
|
|
|
+ timeZone = shangValue + (currentLon > 0 ? 1 : -1);
|
|
|
}
|
|
|
return timeZone;
|
|
|
}
|