|
|
@ -5,6 +5,7 @@ import cn.hutool.core.map.MapUtil; |
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import cn.hutool.json.JSONObject; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|
|
@ -14,6 +15,12 @@ import io.minio.StatObjectArgs; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.dubbo.config.annotation.DubboReference; |
|
|
|
import org.apache.http.client.methods.CloseableHttpResponse; |
|
|
|
import org.apache.http.client.methods.HttpPost; |
|
|
|
import org.apache.http.entity.StringEntity; |
|
|
|
import org.apache.http.impl.client.CloseableHttpClient; |
|
|
|
import org.apache.http.impl.client.HttpClients; |
|
|
|
import org.apache.http.util.EntityUtils; |
|
|
|
import org.dromara.business.api.RemoteBusinessAlertService; |
|
|
|
import org.dromara.business.api.domain.bo.RemoteBusinessAlertBo; |
|
|
|
import org.dromara.business.api.domain.vo.RemoteBusinessAlertConstructInfo; |
|
|
@ -28,6 +35,8 @@ import org.dromara.common.satoken.utils.LoginHelper; |
|
|
|
import org.dromara.common.sdk.mqtt.CommonTopicRequest; |
|
|
|
import org.dromara.common.sdk.mqtt.MqttGatewayPublish; |
|
|
|
import org.dromara.common.sdk.mqtt.TopicConst; |
|
|
|
import org.dromara.sample.feign.RemoteConfigFeign; |
|
|
|
import org.dromara.sample.feign.RemoteSystemFeign; |
|
|
|
import org.dromara.sample.media.constant.MinIOConstants; |
|
|
|
import org.dromara.sample.media.service.IFileService; |
|
|
|
import org.dromara.sample.wayline.mapper.IAiCompareMapper; |
|
|
@ -43,10 +52,13 @@ import org.dromara.sample.wayline.service.IAiCompareService; |
|
|
|
import org.dromara.system.api.model.LoginUser; |
|
|
|
import org.dromara.workflow.api.RemoteWorkflowService; |
|
|
|
import org.dromara.workflow.api.domain.RemoteStartProcess; |
|
|
|
import org.jetbrains.annotations.Nullable; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.net.URI; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
@ -68,8 +80,9 @@ public class AiCompareServiceImpl implements IAiCompareService { |
|
|
|
@DubboReference |
|
|
|
private final RemoteBusinessAlertService businessAlertService; |
|
|
|
|
|
|
|
private final RemoteSystemFeign remoteSystemFeign; |
|
|
|
@DubboReference(timeout = 30000) |
|
|
|
private RemoteWorkflowService remoteWorkflowService; |
|
|
|
private final RemoteWorkflowService remoteWorkflowService; |
|
|
|
|
|
|
|
@Override |
|
|
|
public TableDataInfo<AiCompareEntity> queryPageList(AiCompareDTO bo, PageQuery pageQuery) { |
|
|
@ -88,7 +101,6 @@ public class AiCompareServiceImpl implements IAiCompareService { |
|
|
|
return wrapper; |
|
|
|
} |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Boolean insertByBo(List<Map<String,Object>> compareDTOList) { |
|
|
|
if(compareDTOList.isEmpty()){ |
|
|
|
throw new RuntimeException("未选择比对数据"); |
|
|
@ -131,19 +143,53 @@ public class AiCompareServiceImpl implements IAiCompareService { |
|
|
|
if(jobEntityList.isEmpty()){ |
|
|
|
throw new RuntimeException("("+serviceInfo.getWaylineName()+")未找到对应的模板"); |
|
|
|
}else { |
|
|
|
aiCompareEntity.setTemplateId(jobEntityList.get(0).getJobId()); |
|
|
|
templateId=jobEntityList.get(0).getJobId(); |
|
|
|
aiCompareEntity.setTemplateId(templateId); |
|
|
|
} |
|
|
|
} |
|
|
|
aiCompareMapper.insert(aiCompareEntity); |
|
|
|
String topic = TopicConst.IMAGE +TopicConst.COMPARE; |
|
|
|
List<AiCompareMediaFileDTO> mediaFileDTOS = listMediaFile(aiCompareEntity.getJobId(),aiCompareEntity.getId(),43200,false); |
|
|
|
|
|
|
|
String compareUrl = remoteSystemFeign.getConfigKeyFeign("ai_algorithm_compare"); |
|
|
|
if(StrUtil.isNotEmpty(compareUrl)){ |
|
|
|
//添加到算法平台
|
|
|
|
Map<String,Object>compareMap = new HashMap<>(); |
|
|
|
compareMap.put("id",aiCompareEntity.getId()); |
|
|
|
compareMap.put("totalNum",aiCompareEntity.getTotalNum()); |
|
|
|
compareMap.put("compareType",AiCompareStatusConstants.COMPARETYPE); |
|
|
|
compareMap.put("compareName",aiCompareEntity.getWaylineName()); |
|
|
|
compareMap.put("parm",mediaFileDTOS); |
|
|
|
compareMap.put("mateTask",templateId); |
|
|
|
try(CloseableHttpClient httpClient = HttpClients.createDefault()) { |
|
|
|
HttpPost httpPost =new HttpPost(); |
|
|
|
httpPost.setHeader("Content-Type","application/json"); |
|
|
|
httpPost.setURI(URI.create(compareUrl)); |
|
|
|
httpPost.setEntity(new StringEntity(JSON.toJSONString(compareMap), "UTF-8")); |
|
|
|
CloseableHttpResponse response = httpClient.execute(httpPost); |
|
|
|
String resp = EntityUtils.toString(response.getEntity(), "utf-8"); |
|
|
|
}catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
} |
|
|
|
}else { |
|
|
|
String topic = TopicConst.IMAGE +TopicConst.COMPARE; |
|
|
|
mqttGatewayPublish.publish(topic, new CommonTopicRequest().setData(mediaFileDTOS),1); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// insertList.add(aiCompareEntity);
|
|
|
|
} |
|
|
|
// List<BatchResult> resultList = aiCompareMapper.insertOrUpdate(insertList, 10);
|
|
|
|
List<Long> list =compareDTOList.stream().map(e->Convert.toLong(e.get("queueId"))).collect(Collectors.toList()); |
|
|
|
return aiCompareQueueService.updateStatus(list,AiCompareStatusConstants.QUEUW_TYPE_1); |
|
|
|
} |
|
|
|
|
|
|
|
@Nullable |
|
|
|
private static Object getId(Map<String, Object> compareMap, AiCompareEntity aiCompareEntity) { |
|
|
|
return compareMap.put("id", aiCompareEntity.getId()); |
|
|
|
} |
|
|
|
|
|
|
|
public List<AiCompareMediaFileDTO> listMediaFile(String jobId,Long compareId,Integer seconds ,boolean isIllegal){ |
|
|
|
List<AiCompareMediaFileDTO> mediaFileDTOList = aiCompareMapper.listMediaFile(jobId,compareId); |
|
|
|
if(!mediaFileDTOList.isEmpty()){ |
|
|
@ -166,8 +212,8 @@ public class AiCompareServiceImpl implements IAiCompareService { |
|
|
|
|
|
|
|
@Override |
|
|
|
public Boolean update(Map<String,Object> compareDTO) { |
|
|
|
AiCompareEntity aiCompareEntity =new AiCompareEntity(); |
|
|
|
Long id = compareDTO.containsKey("id") ? Convert.toLong(compareDTO.get("id")) : null; |
|
|
|
AiCompareEntity aiCompareEntity = aiCompareMapper.selectById(id); |
|
|
|
String templateId = compareDTO.containsKey("templateId") ? Convert.toStr(compareDTO.get("templateId")) : null; |
|
|
|
aiCompareEntity.setId(id); |
|
|
|
if(StrUtil.isNotEmpty(templateId)){ |
|
|
@ -176,9 +222,36 @@ public class AiCompareServiceImpl implements IAiCompareService { |
|
|
|
aiCompareEntity.setStatus(AiCompareStatusConstants.COMPARE_STATUS_1); |
|
|
|
int i = aiCompareMapper.updateById(aiCompareEntity); |
|
|
|
AiCompareEntity compareEntity = aiCompareMapper.selectById(id); |
|
|
|
String topic = TopicConst.IMAGE +TopicConst.COMPARE; |
|
|
|
|
|
|
|
List<AiCompareMediaFileDTO> mediaFileDTOS = listMediaFile(compareEntity.getJobId(),compareEntity.getId(),43200,false); |
|
|
|
|
|
|
|
//平台url
|
|
|
|
String compareUrl = remoteSystemFeign.getConfigKeyFeign("ai_algorithm_compare"); |
|
|
|
if(StrUtil.isNotEmpty(compareUrl)){ |
|
|
|
//添加到算法平台
|
|
|
|
Map<String,Object>compareMap = new HashMap<>(); |
|
|
|
compareMap.put("id",aiCompareEntity.getId()); |
|
|
|
compareMap.put("totalNum",aiCompareEntity.getTotalNum()); |
|
|
|
compareMap.put("compareType",AiCompareStatusConstants.COMPARETYPE); |
|
|
|
compareMap.put("compareName",aiCompareEntity.getWaylineName()); |
|
|
|
compareMap.put("parm",mediaFileDTOS); |
|
|
|
compareMap.put("mateTask",templateId); |
|
|
|
try(CloseableHttpClient httpClient = HttpClients.createDefault()) { |
|
|
|
HttpPost httpPost =new HttpPost(); |
|
|
|
httpPost.setHeader("Content-Type","application/json"); |
|
|
|
httpPost.setURI(URI.create(compareUrl)); |
|
|
|
httpPost.setEntity(new StringEntity(JSON.toJSONString(compareMap), "UTF-8")); |
|
|
|
CloseableHttpResponse response = httpClient.execute(httpPost); |
|
|
|
String resp = EntityUtils.toString(response.getEntity(), "utf-8"); |
|
|
|
}catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
} |
|
|
|
}else { |
|
|
|
System.out.println("mqtt推送"); |
|
|
|
String topic = TopicConst.IMAGE +TopicConst.COMPARE; |
|
|
|
mqttGatewayPublish.publish(topic, new CommonTopicRequest().setData(mediaFileDTOS),1); |
|
|
|
} |
|
|
|
return i>0; |
|
|
|
} |
|
|
|
|
|
|
@ -220,15 +293,35 @@ public class AiCompareServiceImpl implements IAiCompareService { |
|
|
|
String originMateFileUrl = frameDTO.getMateFileUrl(); |
|
|
|
String mateFileUrl = fileService.getObjectUrlOne(MinIOConstants.BUCKET_MEDIAFILE, originMateFileUrl, 3600).toString(); |
|
|
|
frameDTO.setMateFileUrl(mateFileUrl); |
|
|
|
String topic = TopicConst.IMAGE +TopicConst.FRAME; |
|
|
|
|
|
|
|
|
|
|
|
// if(StrUtil.equals(activeProfile,"w_fengxianranqi"))
|
|
|
|
// activeProfile="w_fengxianranqi"
|
|
|
|
String activeProfile = MapUtil.getStr(objectMap, "activeProfile", "default"); |
|
|
|
if (StrUtil.equals("default", activeProfile)) { |
|
|
|
/* String topic = TopicConst.IMAGE +TopicConst.FRAME; |
|
|
|
//发送mqtt给算法,处理完
|
|
|
|
mqttGatewayPublish.publish(topic, new CommonTopicRequest().setData(frameDTO), 1);*/ |
|
|
|
|
|
|
|
//添加到算法平台
|
|
|
|
String compareUrl = remoteSystemFeign.getConfigKeyFeign("ai_algorithm_frame"); |
|
|
|
if(StrUtil.isNotEmpty(compareUrl)){ |
|
|
|
frameDTO.setCompareType(AiCompareStatusConstants.COMPARETYPE); |
|
|
|
try(CloseableHttpClient httpClient = HttpClients.createDefault()) { |
|
|
|
HttpPost httpPost =new HttpPost(); |
|
|
|
httpPost.setHeader("Content-Type","application/json"); |
|
|
|
httpPost.setURI(URI.create(compareUrl)); |
|
|
|
httpPost.setEntity(new StringEntity(JSON.toJSONString(frameDTO), "UTF-8")); |
|
|
|
CloseableHttpResponse response = httpClient.execute(httpPost); |
|
|
|
String resp = EntityUtils.toString(response.getEntity(), "utf-8"); |
|
|
|
}catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
} |
|
|
|
}else { |
|
|
|
String topic = TopicConst.IMAGE +TopicConst.FRAME; |
|
|
|
//发送mqtt给算法,处理完
|
|
|
|
mqttGatewayPublish.publish(topic, new CommonTopicRequest().setData(frameDTO), 1); |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
//图片处理
|
|
|
|