2024-07-03 16:11:21 +08:00

144 lines
7.4 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.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 {
QueryWrapper<ProjectUfaceConfig> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(ProjectUfaceConfig::getProjectSn, projectSn);
ProjectUfaceConfig tempProjectUfaceConfig = projectUfaceConfigMapper.selectOne(queryWrapper);
if (tempProjectUfaceConfig != null && StringUtils.isNotEmpty(tempProjectUfaceConfig.getHousing()) && !"0".equals(tempProjectUfaceConfig.getHousing())) {
QueryWrapper<Project> queryWrapper1 = new QueryWrapper<>();
queryWrapper1.lambda().eq(Project::getProjectSn, projectSn);
Project project = projectMapper.selectOne(queryWrapper1);
String[] arr = tempProjectUfaceConfig.getHousing().split(",");
Map<String, Object> data = new HashMap<>(16);
Map<String, Object> param = new HashMap<>(16);
param.put("projectSn", projectSn);
EntityMap extendInfo = projectExtendMapper.getProjectExtendInfo(param);
List<EntityMap> enterpriseList = enterpriseInfoMapper.getEnterpriseInfoList(param);
JSONObject projectObj = JSONUtil.parseObj(project);
projectObj.set("supervisorUnit", MapUtils.getString(extendInfo, "supervisorUnit"));
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");
for (String housingId : arr) {
ThirdPartyPlatformService dictionariesRecord = thirdPartyPlatformServiceMapper.selectById(housingId);
if (dictionariesRecord != null && StringUtils.isNotEmpty(dictionariesRecord.getServiceUrl()) && dictionariesRecord.getProjectSystem() == 1) {
log.info("-----下发执行项目基本信息数据下发----" + dictionariesRecord.getServiceName());
String result = HttpUtil.post(dictionariesRecord.getServiceUrl() + "/saveProject", JSONUtil.toJsonStr(data));
log.info("-----下发执行接口地址----" + dictionariesRecord.getServiceUrl() + "/saveProject");
log.info("-----下发执行项目基本信息数据结果----" + result);
}
}
}
} catch (Exception e) {
log.error("error", e);
}
}
/**
* 发视频数据
*/
@Async("sendWorkerExecutor")
public void sendVideoInfo(String projectSn) {
try {
QueryWrapper<ProjectUfaceConfig> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(ProjectUfaceConfig::getProjectSn, projectSn);
ProjectUfaceConfig tempProjectUfaceConfig = projectUfaceConfigMapper.selectOne(queryWrapper);
if (tempProjectUfaceConfig != null && StringUtils.isNotEmpty(tempProjectUfaceConfig.getHousing()) && !"0".equals(tempProjectUfaceConfig.getHousing())) {
QueryWrapper<ProjectVideoConfig> qu = new QueryWrapper<>();
qu.lambda().eq(ProjectVideoConfig::getProjectSn, projectSn)
.eq(ProjectVideoConfig::getIsEnable, 1);
ProjectVideoConfig projectVideoConfig = projectVideoConfigMapper.selectOne(qu);
List<EntityMap> list = null;
if (projectVideoConfig != null) {
HashMap<String, Object> map = new HashMap<>(16);
map.put("videoId", projectVideoConfig.getId());
list = videoItemMapper.selectVideoItemListByVideoId(map);
}
String[] arr = tempProjectUfaceConfig.getHousing().split(",");
Map<String, Object> data = new HashMap<>(16);
data.put("projectSn", projectSn);
data.put("projectVideoConfig", projectVideoConfig);
data.put("videoList", list);
for (String housingId : arr) {
ThirdPartyPlatformService dictionariesRecord = thirdPartyPlatformServiceMapper.selectById(housingId);
if (dictionariesRecord != null && StringUtils.isNotEmpty(dictionariesRecord.getServiceUrl()) && dictionariesRecord.getVideoSystem() == 1) {
log.info("-----下发执行视频数据下发----" + dictionariesRecord.getServiceName());
String urlString = dictionariesRecord.getServiceUrl() + "/saveVideo";
log.info("视频数据下发url:{}", urlString);
String body = JSONUtil.toJsonStr(data);
log.info("视频数据下发body:{}", body);
String result = HttpUtil.post(urlString, body);
log.info("-----下发执行视频数据结果----" + result);
}
}
}
} catch (Exception e) {
log.error("err:", e);
}
}
}