|
@@ -10,28 +10,30 @@ import com.sckw.core.model.enums.DictItemEnum;
|
|
|
import com.sckw.core.model.enums.MessageLogEnum;
|
|
import com.sckw.core.model.enums.MessageLogEnum;
|
|
|
import com.sckw.core.model.page.PageRes;
|
|
import com.sckw.core.model.page.PageRes;
|
|
|
import com.sckw.core.utils.IdWorker;
|
|
import com.sckw.core.utils.IdWorker;
|
|
|
-import com.sckw.core.web.response.HttpResult;
|
|
|
|
|
|
|
+import com.sckw.core.utils.UUIDUtils;
|
|
|
import com.sckw.core.web.response.PhpResult;
|
|
import com.sckw.core.web.response.PhpResult;
|
|
|
-
|
|
|
|
|
|
|
+import com.sckw.slope.detection.common.config.SmsTemplateConfig;
|
|
|
import com.sckw.slope.detection.dao.mysql.KwsDeviceReferenceMapper;
|
|
import com.sckw.slope.detection.dao.mysql.KwsDeviceReferenceMapper;
|
|
|
import com.sckw.slope.detection.dao.mysql.KwsDictMapper;
|
|
import com.sckw.slope.detection.dao.mysql.KwsDictMapper;
|
|
|
import com.sckw.slope.detection.dao.mysql.KwsLogMapper;
|
|
import com.sckw.slope.detection.dao.mysql.KwsLogMapper;
|
|
|
-import com.sckw.slope.detection.model.dos.mysql.KwsDeviceReference;
|
|
|
|
|
-import com.sckw.slope.detection.model.dos.mysql.KwsLog;
|
|
|
|
|
|
|
+import com.sckw.slope.detection.dao.mysql.KwsProjectDeviceMapper;
|
|
|
|
|
+import com.sckw.slope.detection.dao.tdengine.SlopeDataMapper;
|
|
|
|
|
+import com.sckw.slope.detection.model.dos.mysql.*;
|
|
|
import com.sckw.slope.detection.model.dos.tdengine.SlopeData;
|
|
import com.sckw.slope.detection.model.dos.tdengine.SlopeData;
|
|
|
import com.sckw.slope.detection.model.dto.HeaderData;
|
|
import com.sckw.slope.detection.model.dto.HeaderData;
|
|
|
import com.sckw.slope.detection.model.dto.SystemDict;
|
|
import com.sckw.slope.detection.model.dto.SystemDict;
|
|
|
|
|
+import com.sckw.slope.detection.model.param.SmsMessageParam;
|
|
|
import com.sckw.slope.detection.model.vo.DeviceIntegrationVo;
|
|
import com.sckw.slope.detection.model.vo.DeviceIntegrationVo;
|
|
|
import com.sckw.slope.detection.model.vo.QueryDictTypePageReqVo;
|
|
import com.sckw.slope.detection.model.vo.QueryDictTypePageReqVo;
|
|
|
import com.sckw.slope.detection.service.api.DetectionApiService;
|
|
import com.sckw.slope.detection.service.api.DetectionApiService;
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.apache.dubbo.common.utils.MD5Utils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
|
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
-import com.sckw.slope.detection.dao.tdengine.SlopeDataMapper;
|
|
|
|
|
-import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.text.ParseException;
|
|
import java.text.ParseException;
|
|
@@ -48,6 +50,14 @@ import java.util.*;
|
|
|
@Service
|
|
@Service
|
|
|
@RefreshScope
|
|
@RefreshScope
|
|
|
public class CommonService {
|
|
public class CommonService {
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 设备告警短信模板
|
|
|
|
|
+ */
|
|
|
|
|
+ private static final String DEVICE_ALARM_SMS_TEMPLATE_CODE = "SMS_464035567";
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 数据告警短信模板
|
|
|
|
|
+ */
|
|
|
|
|
+ private static final String DATA_ALARM_SMS_TEMPLATE_CODE = "SMS_464050617";
|
|
|
|
|
|
|
|
@Value("${spring.profiles.active}")
|
|
@Value("${spring.profiles.active}")
|
|
|
private String isDev;
|
|
private String isDev;
|
|
@@ -67,6 +77,9 @@ public class CommonService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
SlopeDataMapper slopeDataMapper;
|
|
SlopeDataMapper slopeDataMapper;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ KwsProjectDeviceMapper projectDeviceMapper;
|
|
|
|
|
+
|
|
|
public HeaderData getHeaderData(HttpServletRequest request) {
|
|
public HeaderData getHeaderData(HttpServletRequest request) {
|
|
|
/**
|
|
/**
|
|
|
* {"companyId":"198","companyName":"四川金顶集团","createBy":"2","createName":"600678","updateBy":"2","updateName":"600678","mountainId":"198"}
|
|
* {"companyId":"198","companyName":"四川金顶集团","createBy":"2","createName":"600678","updateBy":"2","updateName":"600678","mountainId":"198"}
|
|
@@ -76,7 +89,7 @@ public class CommonService {
|
|
|
// if (StringUtils.isBlank(uInfo)) {
|
|
// if (StringUtils.isBlank(uInfo)) {
|
|
|
// throw new BusinessException("数据请求异常!");
|
|
// throw new BusinessException("数据请求异常!");
|
|
|
// }
|
|
// }
|
|
|
- if ("lfdc".equals(isDev) || "dev".equals(isDev)) {
|
|
|
|
|
|
|
+ if ("lfdc".equals(isDev)/* || "dev".equals(isDev)*/) {
|
|
|
uInfo = "eyJjb21wYW55SWQiOiIxOTgiLCJjb21wYW55TmFtZSI6IuWbm+W3nemHkemhtumbhuWboiIsImNyZWF0ZUJ5IjoiMiIsImNyZWF0ZU5hbWUiOiI2MDA2NzgiLCJ1cGRhdGVCeSI6IjIiLCJ1cGRhdGVOYW1lIjoiNjAwNjc4IiwibW91bnRhaW5JZCI6IjE5OCJ9";
|
|
uInfo = "eyJjb21wYW55SWQiOiIxOTgiLCJjb21wYW55TmFtZSI6IuWbm+W3nemHkemhtumbhuWboiIsImNyZWF0ZUJ5IjoiMiIsImNyZWF0ZU5hbWUiOiI2MDA2NzgiLCJ1cGRhdGVCeSI6IjIiLCJ1cGRhdGVOYW1lIjoiNjAwNjc4IiwibW91bnRhaW5JZCI6IjE5OCJ9";
|
|
|
}
|
|
}
|
|
|
String message = new String(Base64.getDecoder().decode(uInfo));
|
|
String message = new String(Base64.getDecoder().decode(uInfo));
|
|
@@ -258,15 +271,15 @@ public class CommonService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//集成要数判断
|
|
//集成要数判断
|
|
|
- public double returnIntegrationData(String snCode, List<SlopeData> data, DeviceIntegrationVo inter){
|
|
|
|
|
|
|
+ public double returnIntegrationData(String snCode, List<SlopeData> data, DeviceIntegrationVo inter) {
|
|
|
|
|
|
|
|
BigDecimal offsetValue = new BigDecimal("0.00");
|
|
BigDecimal offsetValue = new BigDecimal("0.00");
|
|
|
BigDecimal subtract = new BigDecimal(data.get(0).getVal()).subtract(new BigDecimal(data.get(1).getVal()));
|
|
BigDecimal subtract = new BigDecimal(data.get(0).getVal()).subtract(new BigDecimal(data.get(1).getVal()));
|
|
|
Date newD = data.get(0).getTs();
|
|
Date newD = data.get(0).getTs();
|
|
|
Date oldD = data.get(1).getTs();
|
|
Date oldD = data.get(1).getTs();
|
|
|
- double diff = (newD.getTime()-oldD.getTime())/(1000*60*60.0);
|
|
|
|
|
|
|
+ double diff = (newD.getTime() - oldD.getTime()) / (1000 * 60 * 60.0);
|
|
|
//判断集成要素
|
|
//判断集成要素
|
|
|
- if(DictItemEnum.LONGITUDE_X.getValue().equals(inter.getPartNames())){
|
|
|
|
|
|
|
+ if (DictItemEnum.LONGITUDE_X.getValue().equals(inter.getPartNames())) {
|
|
|
List<SlopeData> y = slopeDataMapper.selectListByTwoLine(snCode, DictItemEnum.LATITUDE_Y.getValue());
|
|
List<SlopeData> y = slopeDataMapper.selectListByTwoLine(snCode, DictItemEnum.LATITUDE_Y.getValue());
|
|
|
double angleInRadians = Double.parseDouble(y.get(1).getVal());
|
|
double angleInRadians = Double.parseDouble(y.get(1).getVal());
|
|
|
double cosValue = Math.cos(angleInRadians);
|
|
double cosValue = Math.cos(angleInRadians);
|
|
@@ -280,48 +293,48 @@ public class CommonService {
|
|
|
if (DictItemEnum.ALTITUDE_Z.getValue().equals(inter.getPartNames())) {
|
|
if (DictItemEnum.ALTITUDE_Z.getValue().equals(inter.getPartNames())) {
|
|
|
offsetValue = subtract.divide(new BigDecimal(1000), 9, BigDecimal.ROUND_HALF_UP);
|
|
offsetValue = subtract.divide(new BigDecimal(1000), 9, BigDecimal.ROUND_HALF_UP);
|
|
|
}
|
|
}
|
|
|
- if(inter.getFormula().equals(String.valueOf(NumberConstant.ONE))){//加速度(a-a’)/t² formula=1
|
|
|
|
|
|
|
+ if (inter.getFormula().equals(String.valueOf(NumberConstant.ONE))) {//加速度(a-a’)/t² formula=1
|
|
|
BigDecimal t = new BigDecimal(diff).multiply(new BigDecimal(diff));
|
|
BigDecimal t = new BigDecimal(diff).multiply(new BigDecimal(diff));
|
|
|
- return offsetValue.divide(t,9, BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
|
|
|
|
|
+ return offsetValue.divide(t, 9, BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
|
|
|
|
|
|
- }else if(inter.getFormula().equals(String.valueOf(NumberConstant.TWO))){//速度(a-a’)/t formula=2
|
|
|
|
|
- return offsetValue.divide(new BigDecimal(diff),9, BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
|
|
|
|
|
+ } else if (inter.getFormula().equals(String.valueOf(NumberConstant.TWO))) {//速度(a-a’)/t formula=2
|
|
|
|
|
+ return offsetValue.divide(new BigDecimal(diff), 9, BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
|
}
|
|
}
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public Map<String,List<Object>> getDateByNull(String dateStart,String dateEnd,String[] arr) throws ParseException {
|
|
|
|
|
- Map<String,List<Object>> map = new HashMap<>();
|
|
|
|
|
|
|
+ public Map<String, List<Object>> getDateByNull(String dateStart, String dateEnd, String[] arr) throws ParseException {
|
|
|
|
|
+ Map<String, List<Object>> map = new HashMap<>();
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH");
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH");
|
|
|
Date start = sdf.parse(dateStart);
|
|
Date start = sdf.parse(dateStart);
|
|
|
Date end = sdf.parse(dateEnd);
|
|
Date end = sdf.parse(dateEnd);
|
|
|
|
|
|
|
|
- for(String ar: arr){
|
|
|
|
|
|
|
+ for (String ar : arr) {
|
|
|
Date temp = start;
|
|
Date temp = start;
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
calendar.setTime(start);
|
|
calendar.setTime(start);
|
|
|
List<Object> list = new ArrayList<>();
|
|
List<Object> list = new ArrayList<>();
|
|
|
|
|
|
|
|
- while(temp.getTime() < end.getTime()){
|
|
|
|
|
- Map<Object,Object> map1 = new HashMap<>();
|
|
|
|
|
|
|
+ while (temp.getTime() < end.getTime()) {
|
|
|
|
|
+ Map<Object, Object> map1 = new HashMap<>();
|
|
|
temp = calendar.getTime();
|
|
temp = calendar.getTime();
|
|
|
map1.put("ts", sdf.format(temp.getTime()));
|
|
map1.put("ts", sdf.format(temp.getTime()));
|
|
|
list.add(map1);
|
|
list.add(map1);
|
|
|
- calendar.add(Calendar.HOUR_OF_DAY,1);
|
|
|
|
|
|
|
+ calendar.add(Calendar.HOUR_OF_DAY, 1);
|
|
|
}
|
|
}
|
|
|
- map.put(ar,list);
|
|
|
|
|
|
|
+ map.put(ar, list);
|
|
|
}
|
|
}
|
|
|
return map;
|
|
return map;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public List<Object> returnIntegrationDataArray(String snCode, String dateStart, String dateEnd,DeviceIntegrationVo listvo,String key1,String key2){
|
|
|
|
|
|
|
+ public List<Object> returnIntegrationDataArray(String snCode, String dateStart, String dateEnd, DeviceIntegrationVo listvo, String key1, String key2) {
|
|
|
//首先获取全部数据
|
|
//首先获取全部数据
|
|
|
- String[] partName = {listvo.getPartNames()};
|
|
|
|
|
|
|
+ String[] partName = {listvo.getPartNames()};
|
|
|
List<SlopeData> selectedData = slopeDataMapper.selectLineListByArray(snCode, partName, dateStart, dateEnd);
|
|
List<SlopeData> selectedData = slopeDataMapper.selectLineListByArray(snCode, partName, dateStart, dateEnd);
|
|
|
Map<String, List<Object>> mapList = new HashMap<>();
|
|
Map<String, List<Object>> mapList = new HashMap<>();
|
|
|
List<Object> listTmp = new ArrayList<>();
|
|
List<Object> listTmp = new ArrayList<>();
|
|
|
- for(int i=0;i<selectedData.size();i++) {
|
|
|
|
|
- if(i+1>=selectedData.size()){
|
|
|
|
|
|
|
+ for (int i = 0; i < selectedData.size(); i++) {
|
|
|
|
|
+ if (i + 1 >= selectedData.size()) {
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
BigDecimal offsetValue = new BigDecimal("0.00");
|
|
BigDecimal offsetValue = new BigDecimal("0.00");
|
|
@@ -333,8 +346,8 @@ public class CommonService {
|
|
|
//判断集成要素
|
|
//判断集成要素
|
|
|
if (DictItemEnum.LONGITUDE_X.getValue().equals(listvo.getPartNames())) {
|
|
if (DictItemEnum.LONGITUDE_X.getValue().equals(listvo.getPartNames())) {
|
|
|
//依次获取当前推送的Y轴数据
|
|
//依次获取当前推送的Y轴数据
|
|
|
- List<SlopeData> y = slopeDataMapper.selectListLineByMsgId(snCode, DictItemEnum.LATITUDE_Y.getValue(),selectedData.get(i).getMsgId());
|
|
|
|
|
- if(y.size()>0){
|
|
|
|
|
|
|
+ List<SlopeData> y = slopeDataMapper.selectListLineByMsgId(snCode, DictItemEnum.LATITUDE_Y.getValue(), selectedData.get(i).getMsgId());
|
|
|
|
|
+ if (y.size() > 0) {
|
|
|
double angleInRadians = Double.parseDouble(y.get(0).getVal());
|
|
double angleInRadians = Double.parseDouble(y.get(0).getVal());
|
|
|
double cosValue = Math.cos(angleInRadians);
|
|
double cosValue = Math.cos(angleInRadians);
|
|
|
double doubleValue = subtract.divide(new BigDecimal("360"), 9, BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
double doubleValue = subtract.divide(new BigDecimal("360"), 9, BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
@@ -354,14 +367,89 @@ public class CommonService {
|
|
|
} else if (listvo.getFormula().equals(String.valueOf(NumberConstant.TWO))) {//速度(a-a’)/t formula=2
|
|
} else if (listvo.getFormula().equals(String.valueOf(NumberConstant.TWO))) {//速度(a-a’)/t formula=2
|
|
|
offsetRetrun = offsetValue.divide(new BigDecimal(diff), 9, BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
offsetRetrun = offsetValue.divide(new BigDecimal(diff), 9, BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
|
}
|
|
}
|
|
|
- Map<String ,Object> map = new HashMap();
|
|
|
|
|
|
|
+ Map<String, Object> map = new HashMap();
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
String time = sdf.format(selectedData.get(i + 1).getRawId());
|
|
String time = sdf.format(selectedData.get(i + 1).getRawId());
|
|
|
- map.put(key1,time);
|
|
|
|
|
- map.put(key2,offsetRetrun);
|
|
|
|
|
|
|
+ map.put(key1, time);
|
|
|
|
|
+ map.put(key2, offsetRetrun);
|
|
|
listTmp.add(map);
|
|
listTmp.add(map);
|
|
|
}
|
|
}
|
|
|
//mapList.put(listvo.getIntegrationName(),listTmp);
|
|
//mapList.put(listvo.getIntegrationName(),listTmp);
|
|
|
return listTmp;
|
|
return listTmp;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 发送短信
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param messageUrl 消息地址
|
|
|
|
|
+ * @param device 设备
|
|
|
|
|
+ * @param level 等级
|
|
|
|
|
+ * @param thresholdId 阈值id
|
|
|
|
|
+ * @param messageMap 消息内容
|
|
|
|
|
+ */
|
|
|
|
|
+ @Async
|
|
|
|
|
+ public void pushDataAlarmSmsMessage(String messageUrl, KwsDevice device, Long level, Long thresholdId, Map<String, Object> messageMap) {
|
|
|
|
|
+ Long deviceId = device.getId();
|
|
|
|
|
+ KwsProjectDevice projectDevice = projectDeviceMapper.selectOne(new LambdaQueryWrapper<KwsProjectDevice>()
|
|
|
|
|
+ .eq(KwsProjectDevice::getDeviceId, deviceId)
|
|
|
|
|
+ .eq(KwsProjectDevice::getDelFlag, 0)
|
|
|
|
|
+ .eq(KwsProjectDevice::getStatus, 0)
|
|
|
|
|
+ .orderByDesc(KwsProjectDevice::getCreateTime)
|
|
|
|
|
+ .last(" limit 1")
|
|
|
|
|
+ );
|
|
|
|
|
+ LambdaQueryWrapper<KwsAlarm> wrapper = new LambdaQueryWrapper<KwsAlarm>()
|
|
|
|
|
+ .eq(KwsAlarm::getLevel, level.intValue())
|
|
|
|
|
+ .eq(KwsAlarm::getDeviceId, deviceId)
|
|
|
|
|
+ .eq(KwsAlarm::getType, NumberConstant.ONE)
|
|
|
|
|
+ .orderByDesc(KwsAlarm::getCreateTime);
|
|
|
|
|
+ if (projectDevice != null) {
|
|
|
|
|
+ wrapper.eq(KwsAlarm::getProjectId, projectDevice.getProjectId())
|
|
|
|
|
+ .eq(KwsAlarm::getMountainId, projectDevice.getMountainId());
|
|
|
|
|
+ if (projectDevice.getProjectId() != null) {
|
|
|
|
|
+ wrapper.eq(KwsAlarm::getCompanyId, projectDevice.getCompanyId());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ SmsMessageParam param = new SmsMessageParam();
|
|
|
|
|
+ param.setCode(DEVICE_ALARM_SMS_TEMPLATE_CODE);
|
|
|
|
|
+ param.setType(2);
|
|
|
|
|
+ List<String> stringList = new ArrayList<>();
|
|
|
|
|
+ stringList.add("18215677925");
|
|
|
|
|
+ param.setPushTo(stringList);
|
|
|
|
|
+ SmsMessageParam.Content content = new SmsMessageParam.Content();
|
|
|
|
|
+ content.setTemplateCode("SMS_262585113");
|
|
|
|
|
+ content.setSignName("矿拉拉");
|
|
|
|
|
+// SmsMessageParam.TemplateParam templateParam = new SmsMessageParam.TemplateParam();
|
|
|
|
|
+// templateParam.setName("123");
|
|
|
|
|
+// templateParam.setStart("123");
|
|
|
|
|
+// content.setTemplateParam(templateParam);
|
|
|
|
|
+ param.setContent(content);
|
|
|
|
|
+ detectionApiService.pushSmsMessage(messageUrl, JSONObject.toJSONString(param));
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ SmsTemplateConfig smsTemplateConfig;
|
|
|
|
|
+
|
|
|
|
|
+ @Value("${sms.url}")
|
|
|
|
|
+ private String smsUrl;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+// @Async
|
|
|
|
|
+ public void pushSmsMessage(List<String> pushToPhone, String templateCode, String signName, Map<String, String> templateParam) {
|
|
|
|
|
+ SmsMessageParam param = new SmsMessageParam();
|
|
|
|
|
+ param.setCode("");
|
|
|
|
|
+ param.setType(2);
|
|
|
|
|
+ param.setPushTo(pushToPhone);
|
|
|
|
|
+ SmsMessageParam.Content content = new SmsMessageParam.Content();
|
|
|
|
|
+ content.setTemplateCode(templateCode);
|
|
|
|
|
+ content.setSignName(signName);
|
|
|
|
|
+ content.setTemplateParam(templateParam);
|
|
|
|
|
+ param.setContent(content);
|
|
|
|
|
+ Map<String, String> headerMap = new HashMap<>();
|
|
|
|
|
+ headerMap.put("sign", new MD5Utils().getMd5("sign"));
|
|
|
|
|
+ headerMap.put("account", "zhangsan");
|
|
|
|
|
+ headerMap.put("msgId", UUIDUtils.get32UUID());
|
|
|
|
|
+ detectionApiService.pushSmsMessage(smsUrl, JSONObject.toJSONString(param));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|