|
@@ -0,0 +1,129 @@
|
|
|
+package com.fdkankan.scene.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.exceptions.ExceptionUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.fdkankan.common.constant.CommonStatus;
|
|
|
+import com.fdkankan.common.constant.CommonSuccessStatus;
|
|
|
+import com.fdkankan.common.constant.OperationType;
|
|
|
+import com.fdkankan.fyun.face.FYunFileServiceInterface;
|
|
|
+import com.fdkankan.model.constants.ConstantFilePath;
|
|
|
+import com.fdkankan.scene.bean.SceneBean;
|
|
|
+import com.fdkankan.scene.entity.SceneCleanOrig;
|
|
|
+import com.fdkankan.scene.mapper.ISceneCleanOrigMapper;
|
|
|
+import com.fdkankan.scene.mapper.IScenePlusExtMapper;
|
|
|
+import com.fdkankan.scene.service.ISceneCleanOrigService;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fdkankan.scene.service.IScenePlusExtService;
|
|
|
+import com.fdkankan.scene.service.IScenePlusService;
|
|
|
+import com.fdkankan.scene.service.ISceneProService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.cloud.context.config.annotation.RefreshScope;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import sun.font.TextRecord;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 删除oss原始资源记录 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author
|
|
|
+ * @since 2023-03-29
|
|
|
+ */
|
|
|
+@RefreshScope
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class SceneCleanOrigServiceImpl extends ServiceImpl<ISceneCleanOrigMapper, SceneCleanOrig> implements ISceneCleanOrigService {
|
|
|
+
|
|
|
+ @Value("${scene.cleanOrig.month}")
|
|
|
+ private Integer cleanOrigMonth;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISceneProService sceneProService;
|
|
|
+ @Autowired
|
|
|
+ private IScenePlusService scenePlusService;
|
|
|
+ @Autowired
|
|
|
+ private IScenePlusExtService scenePlusExtService;
|
|
|
+ @Autowired
|
|
|
+ private FYunFileServiceInterface fYunFileService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void cleanOrigV4() {
|
|
|
+ //查询所有计算时间超过限定时间的场景,计算成功、未被删除、最后一次计算后未被删除过的
|
|
|
+ List<SceneBean> sceneBeans = scenePlusService.listCleanOrigScene(cleanOrigMonth);
|
|
|
+ if(CollUtil.isEmpty(sceneBeans)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ sceneBeans.parallelStream().forEach(scene->{
|
|
|
+ this.cleanOrigHandler(scene);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void cleanOrigV3() {
|
|
|
+ //查询所有计算时间超过限定时间的场景,计算成功、未被删除
|
|
|
+ List<SceneBean> sceneBeans = sceneProService.listCleanOrigScene(cleanOrigMonth);
|
|
|
+ if(CollUtil.isEmpty(sceneBeans)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ sceneBeans.parallelStream().forEach(scene->{
|
|
|
+ this.cleanOrigHandler(scene);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void cleanOrigHandler(SceneBean scene){
|
|
|
+ try {
|
|
|
+ int successStatus = CommonSuccessStatus.SUCCESS.code();
|
|
|
+ String reason = null;
|
|
|
+ String dataSource = scene.getDataSource();
|
|
|
+ if(StrUtil.isNotEmpty(dataSource)){
|
|
|
+ String homePath = dataSource.replace(ConstantFilePath.BUILD_MODEL_PATH, ConstantFilePath.OSS_PREFIX);
|
|
|
+ //由于国内测试和生产用的bucket是同一个,这里需要做一个安全校验,保证不会删错
|
|
|
+ String fileContent = fYunFileService.getFileContent(homePath.concat("/").concat("data.fdage"));
|
|
|
+ if(StrUtil.isNotBlank(fileContent)){
|
|
|
+ JSONObject jsonObject = JSON.parseObject(fileContent);
|
|
|
+ String snCode = jsonObject.getJSONObject("cam").getString("uuid");
|
|
|
+ String uuidTime = jsonObject.getString("uuidtime");
|
|
|
+ if(StrUtil.isEmpty(snCode)
|
|
|
+ || StrUtil.isEmpty(uuidTime)
|
|
|
+ || !homePath.contains(snCode)
|
|
|
+ || !homePath.contains(uuidTime)){
|
|
|
+ successStatus = CommonSuccessStatus.FAIL.code();
|
|
|
+ reason = "dataSource与data.fdage文件不匹配";
|
|
|
+ }else{
|
|
|
+ fYunFileService.deleteFolder(homePath);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.saveLog(scene.getNum(), successStatus, reason);
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("删除原始资源失败,num : " + scene.getNum(), e);
|
|
|
+ this.saveLog(scene.getNum(), CommonSuccessStatus.FAIL.code(), ExceptionUtil.stacktraceToString(e, 3000));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private void saveLog(String num, int status, String reason){
|
|
|
+ //清除旧的日志
|
|
|
+ this.remove(new LambdaQueryWrapper<SceneCleanOrig>().eq(SceneCleanOrig::getNum, num));
|
|
|
+ SceneCleanOrig sceneCleanOrig = new SceneCleanOrig();
|
|
|
+ sceneCleanOrig.setNum(num);
|
|
|
+ sceneCleanOrig.setState(status);
|
|
|
+ sceneCleanOrig.setReason(reason);
|
|
|
+ this.saveOrUpdate(sceneCleanOrig);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|