2024-10-24 19:17:00 +08:00

115 lines
5.5 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.zhgd.xmgl.async;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhgd.xmgl.constant.Cts;
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;
import org.springframework.context.annotation.Lazy;
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;
@Lazy
@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())) {
String[] arr = tempProjectUfaceConfig.getHousing().split(Cts.COMMA);
Map<String,Object> data=new HashMap<>(16);
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){
log.error("error", e);
}
}
/**
* 转发升级机实时数据
*/
@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())) {
String[] arr = tempProjectUfaceConfig.getHousing().split(Cts.COMMA);
Map<String,Object> data=new HashMap<>(16);
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){
log.error("error", e);
log.error("转发升降机实时数据异常" + e);
}
}
@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);
noticeService.addUserNotice(systemUser.getUserId(), title, msg, "10");
asyncAiAnalyse.sendAppNotice(offlineLifter.getProjectSn(),title,msg,systemUserList,payload);
}
}
}
}