@@ -6,6 +6,7 @@ import com.tuoheng.admin.entity.request.*; | |||
import com.tuoheng.admin.entity.vo.QuestionCountVO; | |||
import com.tuoheng.admin.entity.vo.QuestionTypeCountVO; | |||
import com.tuoheng.common.common.IBaseService; | |||
import com.tuoheng.common.exception.ServiceException; | |||
import com.tuoheng.common.utils.JsonResult; | |||
import java.util.List; | |||
@@ -37,6 +38,6 @@ public interface IQuestionService extends IBaseService<Question> { | |||
JsonResult<List<QuestionTypeCountVO>> analyzeType(Integer missionId); | |||
JsonResult process(String requestId, CallbackRequest callbackRequest); | |||
JsonResult process(String requestId, CallbackRequest callbackRequest) throws ServiceException; | |||
} |
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject; | |||
import com.tuoheng.admin.service.IDspService; | |||
import com.tuoheng.common.utils.HttpUtils; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Value; | |||
import org.springframework.stereotype.Service; | |||
import java.io.BufferedOutputStream; | |||
@@ -18,18 +19,20 @@ import java.util.Map; | |||
@Slf4j | |||
@Service | |||
public class DspServiceImpl implements IDspService { | |||
@Value("${tuoheng.dsp-domain-url:}") | |||
private String dspDomainUrl; | |||
@Override | |||
public JSONObject serviceInstApplication(JSONObject jsonObject) { | |||
//TODO 替换成配置文件地址 | |||
String url = "http://192.168.11.241:1011/api/web/serviceInst/92cee2e917366746e5d2b0ac28799d02/application"; | |||
String url = dspDomainUrl + "api/web/serviceInst/92cee2e917366746e5d2b0ac28799d02/application"; | |||
String result = doSend(url, jsonObject, null,"POST"); | |||
return JSONObject.parseObject(result); | |||
} | |||
@Override | |||
public JSONObject serviceStopApplication(JSONObject jsonObject) { | |||
//TODO 替换成配置文件地址 | |||
String url = "http://192.168.11.241:1011/api/web/serviceInst/92cee2e917366746e5d2b0ac28799d02/stop"; | |||
String url = dspDomainUrl + "api/web/serviceInst/92cee2e917366746e5d2b0ac28799d02/stop"; | |||
String result = doSend(url, jsonObject, null,"PUT"); | |||
return JSONObject.parseObject(result); | |||
} |
@@ -29,6 +29,7 @@ import com.tuoheng.system.utils.ShiroUtils; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.BeanUtils; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.beans.factory.annotation.Value; | |||
import org.springframework.http.HttpStatus; | |||
import org.springframework.stereotype.Service; | |||
import org.springframework.transaction.annotation.Transactional; | |||
@@ -57,6 +58,10 @@ public class MissionServiceImpl extends BaseServiceImpl<ThMissionMapper, ThMissi | |||
private IDspService dspService; | |||
@Value("${tuoheng.dsp-callback-url:}") | |||
private String dspCallbackUrl; | |||
@Override | |||
public Integer addMission(MissionRequest addThMissionRequest) throws ServiceException { | |||
@@ -121,7 +126,7 @@ public class MissionServiceImpl extends BaseServiceImpl<ThMissionMapper, ThMissi | |||
configList.add(instConfigMode); | |||
JSONObject instConfigUrl = new JSONObject(); | |||
instConfigUrl.put("ename","callback_url"); | |||
instConfigUrl.put("evalue","URL");//todo 替换成URL | |||
instConfigUrl.put("evalue",dspCallbackUrl); | |||
configList.add(instConfigUrl); | |||
request.put("serviceInstConfigList",configList); | |||
@@ -21,6 +21,7 @@ import com.tuoheng.common.utils.JsonResult; | |||
import com.tuoheng.system.utils.ShiroUtils; | |||
import org.springframework.beans.BeanUtils; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.http.HttpStatus; | |||
import org.springframework.stereotype.Service; | |||
import java.util.*; | |||
@@ -148,32 +149,54 @@ public class QuestionServiceImpl extends BaseServiceImpl<QuestionMapper, Questio | |||
} | |||
@Override | |||
public JsonResult process(String requestId, CallbackRequest callbackRequest) { | |||
//todo 获取正在直播的任务,这个任务肯定是当前正在运行的任务,可以根据通道来确定 | |||
public JsonResult process(String requestId, CallbackRequest callbackRequest) throws ServiceException { | |||
ThMission mission = getThMission(requestId); | |||
Boolean aBoolean = saveQuestion(callbackRequest, mission); | |||
//如果任务已经完成就修改任务状态 | |||
ThMission thMissionUpdate=new ThMission(UpdateOrCreateEnum.UPDATE.getCode()); | |||
if(aBoolean){ | |||
setComplate(callbackRequest, mission, thMissionUpdate); | |||
}else{ | |||
setTaskStatusEnum(thMissionUpdate, TaskStatusEnum.FAIL, mission); | |||
} | |||
return JsonResult.success(); | |||
} | |||
private void setTaskStatusEnum(ThMission thMissionUpdate, TaskStatusEnum statusEnum, ThMission mission) { | |||
thMissionUpdate.setStatus(statusEnum.getCode()); | |||
thMissionUpdate.setId(mission.getId()); | |||
missionMapper.updateById(thMissionUpdate); | |||
} | |||
private void setComplate(CallbackRequest callbackRequest, ThMission mission, ThMission thMissionUpdate) { | |||
if(callbackRequest.getAnalyseStatus()== AiAnalyseStatusEnum.SUCCESS.getCode()){ | |||
setTaskStatusEnum(thMissionUpdate, TaskStatusEnum.COMPLETE, mission); | |||
} | |||
} | |||
private Boolean saveQuestion(CallbackRequest callbackRequest, ThMission mission) { | |||
List<CallbackRequest.QuestionFilesDTO> questionFiles = callbackRequest.getQuestionFiles(); | |||
List<Question> questionList=new ArrayList<>(); | |||
for (CallbackRequest.QuestionFilesDTO questionFile : questionFiles) { | |||
Question question=new Question(UpdateOrCreateEnum.CREATE.getCode()); | |||
question.setMissionId(mission.getId()); | |||
question.setMissionName(mission.getName()); | |||
BeanUtils.copyProperties(questionFile,question); | |||
questionList.add(question); | |||
} | |||
boolean batch=saveBatch(questionList); | |||
return saveBatch(questionList); | |||
} | |||
ThMission thMissionUpdate=new ThMission(UpdateOrCreateEnum.UPDATE.getCode()); | |||
if(callbackRequest.getAnalyseStatus()== AiAnalyseStatusEnum.SUCCESS.getCode()){ | |||
thMissionUpdate.setStatus(TaskStatusEnum.COMPLETE.getCode()); | |||
//missionMapper.up | |||
private ThMission getThMission(String requestId) { | |||
LambdaQueryWrapper<ThMission> lambdaQueryWrapper=new LambdaQueryWrapper<>(); | |||
lambdaQueryWrapper.eq(ThMission::getMark,MarkTypeEnum.VALID.getCode()) | |||
.eq(ThMission::getRequestId, requestId) | |||
.eq(ThMission::getStatus,TaskStatusEnum.FLIGHT.getCode()).orderByDesc(ThMission::getCreateTime); | |||
List<ThMission> thMissions = missionMapper.selectList(lambdaQueryWrapper); | |||
if(ObjectUtil.isNotEmpty(thMissions) || thMissions.size()==0){ | |||
throw new ServiceException(HttpStatus.BAD_REQUEST.value(),"正在执行的任务不存在!"); | |||
} | |||
return null; | |||
return thMissions.get(0); | |||
} | |||
} |
@@ -8,18 +8,10 @@ server: | |||
basedir: /data/java/tuoheng_lc/uploads/temp | |||
# 自定义配置 | |||
tuoheng: | |||
# 图片域名 | |||
image-url: https://image.t-aaron.com/ | |||
# OSS域名 | |||
oss-url: https://ta-tech-image.oss-cn-shanghai.aliyuncs.com | |||
# 机场域名 | |||
airport-url: http://124.223.218.130:9060/ | |||
# 视频域名 | |||
video-url: https://vod.play.t-aaron.com/ | |||
# 高德Key | |||
gaodeKey: 8eb26a06684d34501e5a56dcc2f5af15 | |||
# 通道地址 | |||
live-channel-domain-url: https://streaming.t-aaron.com/ | |||
# DSP服务域名 | |||
dsp-domain-url: http://192.168.11.241:1011/ | |||
# DSP回调地址 | |||
dsp-callback-url: http://192.168.11.11:9099/api/question/{requestId}/callback | |||
#阿里云 | |||
aliyuncsVod: | |||
accessKeyId: LTAI5tE7KWN9fsuGU7DyfYF4 |