144 lines
7.4 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.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhgd.jeecg.common.mybatis.EntityMap;
import com.zhgd.xmgl.modules.basicdata.entity.ThirdPartyPlatformService;
import com.zhgd.xmgl.modules.basicdata.mapper.ThirdPartyPlatformServiceMapper;
import com.zhgd.xmgl.modules.project.entity.Project;
import com.zhgd.xmgl.modules.project.entity.ProjectUfaceConfig;
import com.zhgd.xmgl.modules.project.entity.ProjectVideoConfig;
import com.zhgd.xmgl.modules.project.mapper.ProjectExtendMapper;
import com.zhgd.xmgl.modules.project.mapper.ProjectMapper;
import com.zhgd.xmgl.modules.project.mapper.ProjectUfaceConfigMapper;
import com.zhgd.xmgl.modules.project.mapper.ProjectVideoConfigMapper;
import com.zhgd.xmgl.modules.video.mapper.VideoItemMapper;
import com.zhgd.xmgl.modules.worker.mapper.EnterpriseInfoMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
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-09-16 17:22
**/
@Slf4j
@Component
public class AsyncProject {
@Autowired
private ProjectMapper projectMapper;
@Autowired
private ProjectUfaceConfigMapper projectUfaceConfigMapper;
@Autowired
private ThirdPartyPlatformServiceMapper thirdPartyPlatformServiceMapper;
@Autowired
private VideoItemMapper videoItemMapper;
@Autowired
private ProjectVideoConfigMapper projectVideoConfigMapper;
@Autowired
private ProjectExtendMapper projectExtendMapper;
@Autowired
private EnterpriseInfoMapper enterpriseInfoMapper;
@Value("${serverUrl}")
private String serverUrl;
/**
* 发送项目基本信息数据
*/
@Async("sendWorkerExecutor")
public void sendProjectInfo(String projectSn) {
try {
2023-07-19 15:14:12 +08:00
QueryWrapper<ProjectUfaceConfig> queryWrapper = new QueryWrapper<>();
2023-02-16 15:28:15 +08:00
queryWrapper.lambda().eq(ProjectUfaceConfig::getProjectSn, projectSn);
2023-07-19 15:14:12 +08:00
ProjectUfaceConfig tempProjectUfaceConfig = projectUfaceConfigMapper.selectOne(queryWrapper);
if (tempProjectUfaceConfig != null && StringUtils.isNotEmpty(tempProjectUfaceConfig.getHousing()) && !"0".equals(tempProjectUfaceConfig.getHousing())) {
QueryWrapper<Project> queryWrapper1 = new QueryWrapper<>();
2023-02-16 15:28:15 +08:00
queryWrapper1.lambda().eq(Project::getProjectSn, projectSn);
2023-07-19 15:14:12 +08:00
Project project = projectMapper.selectOne(queryWrapper1);
2023-02-16 15:28:15 +08:00
String[] arr = tempProjectUfaceConfig.getHousing().split(",");
2023-07-19 15:14:12 +08:00
Map<String, Object> data = new HashMap<>();
Map<String, Object> param = new HashMap<>();
param.put("projectSn", projectSn);
EntityMap extendInfo = projectExtendMapper.getProjectExtendInfo(param);
List<EntityMap> enterpriseList = enterpriseInfoMapper.getEnterpriseInfoList(param);
JSONObject projectObj = JSONUtil.parseObj(project);
2023-02-16 15:28:15 +08:00
projectObj.set("supervisorUnit", MapUtils.getString(extendInfo, "supervisorUnit"));
2023-07-19 15:14:12 +08:00
projectObj.set("designUnit", MapUtils.getString(extendInfo, "designUnit"));
projectObj.set("bidWinner", MapUtils.getString(extendInfo, "bidWinner"));
projectObj.set("constructionUnit", MapUtils.getString(extendInfo, "constructionUnit"));
data.put("projectSn", project.getProjectSn());
data.put("project", projectObj);
data.put("enterpriseList", enterpriseList);
data.put("projectAuditUrl", serverUrl + "/projectApi/updateProjectAuditStatus");
2023-02-16 15:28:15 +08:00
for (String housingId : arr) {
ThirdPartyPlatformService dictionariesRecord = thirdPartyPlatformServiceMapper.selectById(housingId);
2023-07-19 15:14:12 +08:00
if (dictionariesRecord != null && StringUtils.isNotEmpty(dictionariesRecord.getServiceUrl()) && dictionariesRecord.getProjectSystem() == 1) {
2023-02-16 15:28:15 +08:00
log.info("-----下发执行项目基本信息数据下发----" + dictionariesRecord.getServiceName());
String result = HttpUtil.post(dictionariesRecord.getServiceUrl() + "/saveProject", JSONUtil.toJsonStr(data));
log.info("-----下发执行接口地址----" + dictionariesRecord.getServiceUrl() + "/saveProject");
log.info("-----下发执行项目基本信息数据结果----" + result);
}
}
}
2023-07-19 15:14:12 +08:00
} catch (Exception e) {
2023-02-16 15:28:15 +08:00
e.printStackTrace();
}
}
/**
* 发视频数据
*/
@Async("sendWorkerExecutor")
public void sendVideoInfo(String projectSn) {
try {
2023-07-19 15:14:12 +08:00
QueryWrapper<ProjectUfaceConfig> queryWrapper = new QueryWrapper<>();
2023-02-16 15:28:15 +08:00
queryWrapper.lambda().eq(ProjectUfaceConfig::getProjectSn, projectSn);
2023-07-19 15:14:12 +08:00
ProjectUfaceConfig tempProjectUfaceConfig = projectUfaceConfigMapper.selectOne(queryWrapper);
if (tempProjectUfaceConfig != null && StringUtils.isNotEmpty(tempProjectUfaceConfig.getHousing()) && !"0".equals(tempProjectUfaceConfig.getHousing())) {
QueryWrapper<ProjectVideoConfig> qu = new QueryWrapper<>();
2023-02-16 15:28:15 +08:00
qu.lambda().eq(ProjectVideoConfig::getProjectSn, projectSn)
2023-07-19 15:14:12 +08:00
.eq(ProjectVideoConfig::getIsEnable, 1);
ProjectVideoConfig projectVideoConfig = projectVideoConfigMapper.selectOne(qu);
List<EntityMap> list = null;
if (projectVideoConfig != null) {
HashMap<String, Object> map = new HashMap<>();
map.put("videoId", projectVideoConfig.getId());
list = videoItemMapper.selectVideoItemListByVideoId(map);
2023-02-16 15:28:15 +08:00
}
String[] arr = tempProjectUfaceConfig.getHousing().split(",");
2023-07-19 15:14:12 +08:00
Map<String, Object> data = new HashMap<>();
data.put("projectSn", projectSn);
data.put("projectVideoConfig", projectVideoConfig);
data.put("videoList", list);
2023-02-16 15:28:15 +08:00
for (String housingId : arr) {
ThirdPartyPlatformService dictionariesRecord = thirdPartyPlatformServiceMapper.selectById(housingId);
2023-07-19 15:14:12 +08:00
if (dictionariesRecord != null && StringUtils.isNotEmpty(dictionariesRecord.getServiceUrl()) && dictionariesRecord.getVideoSystem() == 1) {
2023-02-16 15:28:15 +08:00
log.info("-----下发执行视频数据下发----" + dictionariesRecord.getServiceName());
2023-07-19 15:14:12 +08:00
String urlString = dictionariesRecord.getServiceUrl() + "/saveVideo";
log.info("视频数据下发url:{}", urlString);
String body = JSONUtil.toJsonStr(data);
log.info("视频数据下发body:{}", body);
String result = HttpUtil.post(urlString, body);
2023-02-16 15:28:15 +08:00
log.info("-----下发执行视频数据结果----" + result);
}
}
}
2023-07-19 15:14:12 +08:00
} catch (Exception e) {
log.error("err:", e);
2023-02-16 15:28:15 +08:00
}
}
}