Browse Source

四川日报项目需求

dengsixing 10 tháng trước cách đây
mục cha
commit
f9e3c0ee1b

+ 5 - 5
src/main/java/com/fdkankan/scene/service/impl/SceneServiceImpl.java

@@ -18,7 +18,7 @@ import com.fdkankan.redis.constant.RedisKey;
 import com.fdkankan.redis.util.RedisUtil;
 import com.fdkankan.scene.bean.BodySegmentStatusBean;
 import com.fdkankan.scene.service.ISceneService;
-import com.fdkankan.scene.util.OssBodySegmentUtil;
+//import com.fdkankan.scene.util.OssBodySegmentUtil;
 import com.fdkankan.web.response.ResultData;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -49,8 +49,8 @@ public class SceneServiceImpl implements ISceneService {
     @Value("${oss.bodySegment.point:oss-cn-shanghai.aliyuncs.com}")
     private String bodySegmentHost;
 
-    @Autowired
-    private OssBodySegmentUtil ossBodySegmentUtil;
+//    @Autowired
+//    private OssBodySegmentUtil ossBodySegmentUtil;
     @Autowired
     private RedisUtil redisUtil;
     @Autowired
@@ -99,7 +99,7 @@ public class SceneServiceImpl implements ISceneService {
         ImgUtil.scale(new File(tempFile.getPath()), new File(tempFile.getPath()), scale);
 
         String orgImgOssPath = "body_segment/original/" + tempFile.getName();
-        ossBodySegmentUtil.uploadOss(tempFile.getPath(), orgImgOssPath);
+//        ossBodySegmentUtil.uploadOss(tempFile.getPath(), orgImgOssPath);
 //        fYunFileService.uploadFile(bodySegmentBucket, tempFile.getPath(), orgImgOssPath);
 
         BodySegmentStatusBean bodySegmentStatusBean = BodySegmentStatusBean.builder().uuid(uuid).status(CommonOperStatus.WAITING.code()).build();
@@ -134,7 +134,7 @@ public class SceneServiceImpl implements ISceneService {
                     DateExtUtil.format(Calendar.getInstance().getTime(), DateExtUtil.dateStyle6);
             String fileName = uuid + ".png";
             String imgPath = dir + "/" + fileName;
-            ossBodySegmentUtil.extracted(imgUrl, dir, fileName);
+//            ossBodySegmentUtil.extracted(imgUrl, dir, fileName);
             if(!FileUtil.exist(imgPath)){
                 throw new Exception("提取图片失败");
             }

+ 98 - 98
src/main/java/com/fdkankan/scene/util/OssBodySegmentUtil.java

@@ -1,98 +1,98 @@
-package com.fdkankan.scene.util;
-
-import cn.hutool.core.io.FileUtil;
-import cn.hutool.http.HttpUtil;
-import com.aliyun.imageseg20191230.models.SegmentBodyResponse;
-import com.aliyun.oss.OSS;
-import com.aliyun.oss.OSSClientBuilder;
-import com.aliyun.tea.TeaException;
-import com.fdkankan.common.util.FileUtils;
-import com.fdkankan.scene.httpclient.MyClient;
-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.Component;
-
-import javax.annotation.Resource;
-import java.io.File;
-
-@Slf4j
-@Component
-@RefreshScope
-public class OssBodySegmentUtil {
-
-    @Value("${oss.bodySegment.point:oss-cn-shanghai.aliyuncs.com}")
-    private String endPoint;
-
-    @Value("${oss.bodySegment.imagesegPoint:imageseg.cn-shanghai.aliyuncs.com}")
-    private String imagesegEndPoint;
-
-    @Value("${fyun.key}")
-    private String accessKeyId;
-
-    @Value("${fyun.secret}")
-    private String accessKeySecret;
-
-    @Value("${oss.bodySegment.bucket:4dkankan-huadong}")
-    private String bucket;
-
-    @Resource
-    private MyClient myClient;
-
-    public void uploadOss(String filePath, String key){
-        OSS ossClient = new OSSClientBuilder().build(endPoint, accessKeyId, accessKeySecret);
-        try {
-            File file = new File(filePath);
-            if (!file.exists()) {
-                log.error("要上传的文件不存在:" + filePath);
-                return;
-            }
-            ossClient.putObject(bucket, key, new File(filePath));
-        } catch (Exception e) {
-            log.error(e.toString() + filePath);
-        } finally {
-            ossClient.shutdown();
-        }
-    }
-
-    public void extracted(String imageUrl, String dir, String fileName) throws Exception {
-        try {
-            com.aliyun.imageseg20191230.Client client = this.createClient();
-            com.aliyun.imageseg20191230.models.SegmentBodyRequest segmentBodyRequest =
-                    new com.aliyun.imageseg20191230.models.SegmentBodyRequest().setImageURL(imageUrl);
-            com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
-            // 复制代码运行请自行打印 API 的返回值
-            SegmentBodyResponse segmentBodyResponse = client.segmentBodyWithOptions(segmentBodyRequest, runtime);
-            String imageURL = segmentBodyResponse.getBody().getData().getImageURL();
-            log.info("人体抠图imageURL:{}", imageURL);
-            myClient.downloadFile(imageURL, dir, fileName);
-        }catch (Exception e){
-            log.error("人体抠图失败,imageUrl:" + imageUrl, e);
-            myClient.downloadFile(imageUrl, dir, fileName);
-        }
-
-    }
-
-    public static void main(String[] args) {
-        FileUtils.downLoadFromUrl("http://vibktprfx-prod-prod-damo-eas-cn-shanghai.oss-cn-shanghai.aliyuncs.com/segment-body/2023-02-24/5d44fe44-308c-44c3-8e1d-2d4cbe601f86/image.png?Expires=1677208715&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRpDvh1&Signature=4ZyzaOz6W1nBD9s3KQuFN10c%2BPw%3D",
-                "1.png","D:\\test");
-    }
-
-    /**
-     * 使用AK&SK初始化账号Client
-     * @return Client
-     * @throws Exception
-     */
-    public com.aliyun.imageseg20191230.Client createClient() throws Exception {
-        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
-                // 必填,您的 AccessKey ID
-                .setAccessKeyId(accessKeyId)
-                // 必填,您的 AccessKey Secret
-                .setAccessKeySecret(accessKeySecret);
-        // 访问的域名
-        config.endpoint = this.imagesegEndPoint;
-        return new com.aliyun.imageseg20191230.Client(config);
-    }
-
-}
+//package com.fdkankan.scene.util;
+//
+//import cn.hutool.core.io.FileUtil;
+//import cn.hutool.http.HttpUtil;
+//import com.aliyun.imageseg20191230.models.SegmentBodyResponse;
+//import com.aliyun.oss.OSS;
+//import com.aliyun.oss.OSSClientBuilder;
+//import com.aliyun.tea.TeaException;
+//import com.fdkankan.common.util.FileUtils;
+//import com.fdkankan.scene.httpclient.MyClient;
+//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.Component;
+//
+//import javax.annotation.Resource;
+//import java.io.File;
+//
+//@Slf4j
+//@Component
+//@RefreshScope
+//public class OssBodySegmentUtil {
+//
+//    @Value("${oss.bodySegment.point:oss-cn-shanghai.aliyuncs.com}")
+//    private String endPoint;
+//
+//    @Value("${oss.bodySegment.imagesegPoint:imageseg.cn-shanghai.aliyuncs.com}")
+//    private String imagesegEndPoint;
+//
+//    @Value("${fyun.key}")
+//    private String accessKeyId;
+//
+//    @Value("${fyun.secret}")
+//    private String accessKeySecret;
+//
+//    @Value("${oss.bodySegment.bucket:4dkankan-huadong}")
+//    private String bucket;
+//
+//    @Resource
+//    private MyClient myClient;
+//
+//    public void uploadOss(String filePath, String key){
+//        OSS ossClient = new OSSClientBuilder().build(endPoint, accessKeyId, accessKeySecret);
+//        try {
+//            File file = new File(filePath);
+//            if (!file.exists()) {
+//                log.error("要上传的文件不存在:" + filePath);
+//                return;
+//            }
+//            ossClient.putObject(bucket, key, new File(filePath));
+//        } catch (Exception e) {
+//            log.error(e.toString() + filePath);
+//        } finally {
+//            ossClient.shutdown();
+//        }
+//    }
+//
+//    public void extracted(String imageUrl, String dir, String fileName) throws Exception {
+//        try {
+//            com.aliyun.imageseg20191230.Client client = this.createClient();
+//            com.aliyun.imageseg20191230.models.SegmentBodyRequest segmentBodyRequest =
+//                    new com.aliyun.imageseg20191230.models.SegmentBodyRequest().setImageURL(imageUrl);
+//            com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
+//            // 复制代码运行请自行打印 API 的返回值
+//            SegmentBodyResponse segmentBodyResponse = client.segmentBodyWithOptions(segmentBodyRequest, runtime);
+//            String imageURL = segmentBodyResponse.getBody().getData().getImageURL();
+//            log.info("人体抠图imageURL:{}", imageURL);
+//            myClient.downloadFile(imageURL, dir, fileName);
+//        }catch (Exception e){
+//            log.error("人体抠图失败,imageUrl:" + imageUrl, e);
+//            myClient.downloadFile(imageUrl, dir, fileName);
+//        }
+//
+//    }
+//
+//    public static void main(String[] args) {
+//        FileUtils.downLoadFromUrl("http://vibktprfx-prod-prod-damo-eas-cn-shanghai.oss-cn-shanghai.aliyuncs.com/segment-body/2023-02-24/5d44fe44-308c-44c3-8e1d-2d4cbe601f86/image.png?Expires=1677208715&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRpDvh1&Signature=4ZyzaOz6W1nBD9s3KQuFN10c%2BPw%3D",
+//                "1.png","D:\\test");
+//    }
+//
+//    /**
+//     * 使用AK&SK初始化账号Client
+//     * @return Client
+//     * @throws Exception
+//     */
+//    public com.aliyun.imageseg20191230.Client createClient() throws Exception {
+//        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
+//                // 必填,您的 AccessKey ID
+//                .setAccessKeyId(accessKeyId)
+//                // 必填,您的 AccessKey Secret
+//                .setAccessKeySecret(accessKeySecret);
+//        // 访问的域名
+//        config.endpoint = this.imagesegEndPoint;
+//        return new com.aliyun.imageseg20191230.Client(config);
+//    }
+//
+//}