|
@@ -13,6 +13,7 @@ import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.mybatisflex.core.paginate.Page;
|
|
|
import com.mybatisflex.core.query.QueryWrapper;
|
|
|
import com.taais.biz.constant.BizConstant;
|
|
|
+import com.taais.biz.domain.HttpResponseEntity;
|
|
|
import com.taais.biz.domain.bo.VideoStableStartResultBo;
|
|
|
import com.taais.biz.utils.ZipUtils;
|
|
|
import com.taais.common.core.config.TaaisConfig;
|
|
@@ -37,6 +38,7 @@ import org.apache.http.impl.client.HttpClients;
|
|
|
import org.apache.http.util.EntityUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.boot.actuate.autoconfigure.observation.ObservationProperties;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import com.taais.biz.mapper.VideoStableMapper;
|
|
@@ -56,8 +58,11 @@ import static com.taais.biz.domain.table.VideoStableTableDef.VIDEO_STABLE;
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
public class VideoStableServiceImpl extends BaseServiceImpl<VideoStableMapper, VideoStable> implements IVideoStableService {
|
|
|
- @Value("${server.video_stable_url}")
|
|
|
- private String video_stable_url;
|
|
|
+ @Value("${server.video_stable_start_url}")
|
|
|
+ private String video_stable_start_url;
|
|
|
+
|
|
|
+ @Value("${server.video_stable_stop_url}")
|
|
|
+ private String video_stable_stop_url;
|
|
|
|
|
|
@Autowired
|
|
|
private ISysOssService ossService;
|
|
@@ -232,8 +237,8 @@ public class VideoStableServiceImpl extends BaseServiceImpl<VideoStableMapper, V
|
|
|
videoStable.setStatus(BizConstant.VideoStatus.RUNNING);
|
|
|
updateById(videoStable);
|
|
|
|
|
|
- boolean flag = sendMsg(videoStable);
|
|
|
- if (!flag) {
|
|
|
+ HttpResponseEntity responseEntity = sendPostMsg(video_stable_start_url, videoStable);
|
|
|
+ if (responseEntity.getStatus() == 200) {
|
|
|
videoStable.setStatus(BizConstant.VideoStatus.FAILED);
|
|
|
updateById(videoStable);
|
|
|
return CommonResult.fail("start video_stable failed");
|
|
@@ -242,25 +247,29 @@ public class VideoStableServiceImpl extends BaseServiceImpl<VideoStableMapper, V
|
|
|
return CommonResult.success("start video_stable success");
|
|
|
}
|
|
|
|
|
|
- public boolean sendMsg(VideoStable videoStable) {
|
|
|
- log.info("start video_stable_url: {}", video_stable_url);
|
|
|
+ public HttpResponseEntity sendPostMsg(String url, Object obj) {
|
|
|
+ log.info("sendMsg: {} - {}", url, JsonUtils.toJsonString(obj));
|
|
|
|
|
|
CloseableHttpClient httpClient = HttpClients.createDefault();
|
|
|
- HttpPost request = new HttpPost(video_stable_url);
|
|
|
+ HttpPost request = new HttpPost(url);
|
|
|
// 设置请求体
|
|
|
- System.out.println(JsonUtils.toJsonString(videoStable));
|
|
|
- StringEntity entity = new StringEntity(JsonUtils.toJsonString(videoStable), "UTF-8");
|
|
|
+ StringEntity entity = new StringEntity(JsonUtils.toJsonString(obj), "UTF-8");
|
|
|
entity.setContentType("application/json");
|
|
|
request.setEntity(entity);
|
|
|
|
|
|
try {
|
|
|
CloseableHttpResponse response = httpClient.execute(request);
|
|
|
+ if (response.getStatusLine().getStatusCode() != 200) {
|
|
|
+ log.error("sendMsg failed, status code -> " + response.getStatusLine().getStatusCode());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
String responseBody = EntityUtils.toString(response.getEntity());
|
|
|
log.info("responseBody -> " + responseBody);
|
|
|
- return true;
|
|
|
+ // 使用 JsonUtils 将响应体转换为指定的实体类
|
|
|
+ return JsonUtils.parseObject(responseBody, HttpResponseEntity.class);
|
|
|
} catch (Exception e) {
|
|
|
log.error("sendMsg error", e);
|
|
|
- return false;
|
|
|
+ return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -275,7 +284,7 @@ public class VideoStableServiceImpl extends BaseServiceImpl<VideoStableMapper, V
|
|
|
videoStable.setEndTime(new Date());
|
|
|
try {
|
|
|
videoStable.setCostSecond((videoStable.getEndTime().getTime() - videoStable.getStartTime().getTime()) / 1000);
|
|
|
- }catch(Exception e) {
|
|
|
+ } catch (Exception e) {
|
|
|
videoStable.setCostSecond(null);
|
|
|
}
|
|
|
updateById(videoStable);
|
|
@@ -316,6 +325,20 @@ public class VideoStableServiceImpl extends BaseServiceImpl<VideoStableMapper, V
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public CommonResult stop(Long id) {
|
|
|
+ VideoStable videoStable = getById(id);
|
|
|
+
|
|
|
+ HttpResponseEntity responseEntity = sendPostMsg(video_stable_stop_url, videoStable);
|
|
|
+ if (ObjectUtil.isNotNull(responseEntity) && responseEntity.getStatus() == 200) {
|
|
|
+ videoStable.setStatus(BizConstant.VideoStatus.INTERRUPTED);
|
|
|
+ updateById(videoStable);
|
|
|
+ return CommonResult.fail("终止任务成功");
|
|
|
+ } else {
|
|
|
+ return CommonResult.fail("终止任务失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 递归统计文件夹中的文件数量
|
|
|
*
|