115 lines
5.5 KiB
Java
Raw Normal View History

2023-02-16 15:28:15 +08:00
package com.zhgd.xmgl.async;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
2024-07-09 16:42:03 +08:00
import com.zhgd.xmgl.constant.Cts;
2023-02-16 15:28:15 +08:00
import com.zhgd.xmgl.modules.basicdata.entity.SystemUser;
import com.zhgd.xmgl.modules.basicdata.entity.ThirdPartyPlatformService;
import com.zhgd.xmgl.modules.basicdata.service.INoticeService;
import com.zhgd.xmgl.modules.project.entity.ProjectUfaceConfig;
import com.zhgd.xmgl.modules.project.mapper.ProjectUfaceConfigMapper;
import com.zhgd.xmgl.modules.basicdata.mapper.ThirdPartyPlatformServiceMapper;
import com.zhgd.xmgl.modules.bigdevice.entity.Lifter;
import com.zhgd.xmgl.modules.bigdevice.entity.LifterCurrentData;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
2024-05-22 19:06:24 +08:00
import org.springframework.context.annotation.Lazy;
2023-02-16 15:28:15 +08:00
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @program: wisdomSite
* @description: 异步转发升级机数据
* @author: Mr.Peng
* @create: 2021-07-29 11:34
**/
@Slf4j
@Component
public class AsyncLifter {
@Autowired
private ProjectUfaceConfigMapper projectUfaceConfigMapper;
@Autowired
private ThirdPartyPlatformServiceMapper thirdPartyPlatformServiceMapper;
@Autowired
private INoticeService noticeService;
2024-05-22 19:06:24 +08:00
@Lazy
2023-02-16 15:28:15 +08:00
@Autowired
private AsyncAiAnalyse asyncAiAnalyse;
/**
* 发送升级机设备数据
*/
@Async("lifterExecutor")
public void sendLifterDev(Lifter lifter) {
try {
QueryWrapper<ProjectUfaceConfig> queryWrapper =new QueryWrapper<>();
queryWrapper.lambda().eq(ProjectUfaceConfig::getProjectSn, lifter.getProjectSn());
ProjectUfaceConfig tempProjectUfaceConfig=projectUfaceConfigMapper.selectOne(queryWrapper);
if(tempProjectUfaceConfig!=null&& StringUtils.isNotEmpty(tempProjectUfaceConfig.getHousing())&&!"0".equals(tempProjectUfaceConfig.getHousing())) {
2024-07-09 16:42:03 +08:00
String[] arr = tempProjectUfaceConfig.getHousing().split(Cts.COMMA);
2024-07-03 16:11:21 +08:00
Map<String,Object> data=new HashMap<>(16);
2023-02-16 15:28:15 +08:00
data.put("projectSn",lifter.getProjectSn());
data.put("lifter",lifter);
for (String housingId : arr) {
ThirdPartyPlatformService dictionariesRecord = thirdPartyPlatformServiceMapper.selectById(housingId);
if (dictionariesRecord != null && StringUtils.isNotEmpty(dictionariesRecord.getServiceUrl())&&dictionariesRecord.getLifterSystem()==1) {
log.info("-----开始执行升级机设备数据下发----" + dictionariesRecord.getServiceName());
String result = HttpUtil.post(dictionariesRecord.getServiceUrl() + "/saveLifterDev", JSONUtil.toJsonStr(data));
log.info("-----下发执行升级机设备数据结果----" + result);
}
}
}
}catch (Exception e){
2024-04-14 21:05:01 +08:00
log.error("error", e);
2023-02-16 15:28:15 +08:00
}
}
/**
* 转发升级机实时数据
*/
@Async("lifterExecutor")
public void sendLifterCurrentData(LifterCurrentData lifterCurrentData, Lifter lifter) {
try {
QueryWrapper<ProjectUfaceConfig> queryWrapper =new QueryWrapper<>();
queryWrapper.lambda().eq(ProjectUfaceConfig::getProjectSn, lifter.getProjectSn());
ProjectUfaceConfig tempProjectUfaceConfig=projectUfaceConfigMapper.selectOne(queryWrapper);
if(tempProjectUfaceConfig!=null&& StringUtils.isNotEmpty(tempProjectUfaceConfig.getHousing())&&!"0".equals(tempProjectUfaceConfig.getHousing())) {
2024-07-09 16:42:03 +08:00
String[] arr = tempProjectUfaceConfig.getHousing().split(Cts.COMMA);
2024-07-03 16:11:21 +08:00
Map<String,Object> data=new HashMap<>(16);
2023-02-16 15:28:15 +08:00
data.put("projectSn",lifter.getProjectSn());
data.put("lifterCurrentData",lifterCurrentData);
data.put("lifter",lifter);
for (String housingId : arr) {
ThirdPartyPlatformService dictionariesRecord = thirdPartyPlatformServiceMapper.selectById(housingId);
if (dictionariesRecord != null && StringUtils.isNotEmpty(dictionariesRecord.getServiceUrl())&&dictionariesRecord.getLifterSystem()==1) {
log.info("-----开始执行升级机实时数据下发----" + dictionariesRecord.getServiceName());
String result = HttpUtil.post(dictionariesRecord.getServiceUrl() + "/saveLifterCurrentData", JSONUtil.toJsonStr(data));
log.info("-----下发执行升级机实时数据结果----" + result);
}
}
}
}catch (Exception e){
2024-04-14 21:05:01 +08:00
log.error("error", e);
log.error("转发升降机实时数据异常" + e);
2023-02-16 15:28:15 +08:00
}
}
@Async("lifterExecutor")
public void sendOfflineAlarm(List<SystemUser> systemUserList,Lifter offlineLifter, String msg, String title,String payload) {
if(CollectionUtils.isNotEmpty(systemUserList)){
for (SystemUser systemUser:systemUserList){
log.info(systemUser.getAccount()+"收消息:"+msg);
2024-10-24 19:17:00 +08:00
noticeService.addUserNotice(systemUser.getUserId(), title, msg, "10");
2023-02-16 15:28:15 +08:00
asyncAiAnalyse.sendAppNotice(offlineLifter.getProjectSn(),title,msg,systemUserList,payload);
}
}
}
}