浏览代码

后台代码的腾讯云文档上传

wutt 5 年之前
父节点
当前提交
caaaf8ff2c

+ 26 - 0
cloud-model/pom.xml

@@ -132,8 +132,34 @@
             <scope>system</scope>
             <systemPath>${basedir}/src/main/resources/lib/jodconverter-core-3.0.jar</systemPath>
         </dependency>
+        <!--腾讯云上传文件SDK-->
+        <dependency>
+            <groupId>com.qcloud</groupId>
+            <artifactId>cos_api</artifactId>
+            <version>5.6.8</version>
+        </dependency>
+        <dependency>
+            <groupId>com.tencent.cloud</groupId>
+            <artifactId>cos-sts-java</artifactId>
+            <version>3.0.5</version>
+        </dependency>
     </dependencies>
 
+    <repositories>
+        <repository>
+            <id>bintray-qcloud-maven-repo</id>
+            <name>qcloud-maven-repo</name>
+            <url>https://dl.bintray.com/qcloud/maven-repo/</url>
+            <layout>default</layout>
+            <releases>
+                <enabled>true</enabled>
+            </releases>
+            <snapshots>
+                <enabled>false</enabled>
+            </snapshots>
+        </repository>
+    </repositories>
+
     <build>
         <plugins>
             <plugin>

+ 12 - 0
cloud-model/src/main/java/com/hssx/cloudmodel/controller/MouldController.java

@@ -222,5 +222,17 @@ public class MouldController {
         msg = projectService.getModelListMapByUser(userVO);
         return msg;
     }
+
+//    /**
+//     * 本地E盘文件上传到腾讯云
+//     * @return
+//     */
+//    @ApiOperation("本地E盘文件上传到腾讯云")
+//    @RequestMapping("/listMap")
+//    @ResponseBody
+//    public HttpRespMsg uploadQcloud(UserVO userVO, String token) {
+//        HttpRespMsg msg = new HttpRespMsg();
+//    }
+
 }
 

+ 39 - 12
cloud-model/src/main/java/com/hssx/cloudmodel/service/impl/MouldFileServiceImpl.java

@@ -27,6 +27,8 @@ import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 import java.util.stream.Collectors;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipOutputStream;
@@ -75,6 +77,7 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
         Mould mould = mouldMapper.selectById(userVO.getMouldId());
         if (user != null) {
             if (file != null && !file.isEmpty()) {
+                ExecutorService fixedThreadPool = Executors.newFixedThreadPool(3);
                 MouldFile projectFile = new MouldFile();
                 projectFile.setUplodtorId(user.getId());
                 projectFile.setUploadtor(user.getUsername());
@@ -103,6 +106,14 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
                     try {
                         saveFile.createNewFile();
                         file.transferTo(saveFile);
+                        final String qFileName = fileName;
+                        fixedThreadPool.execute(new Runnable() {
+                            @Override
+                            public void run() {
+                                QcloudUntil.upload(path + qFileName, qFileName);
+                                QcloudUntil.close();
+                            }
+                        });
                     } catch (IOException e) {
                         e.printStackTrace();
                         projectFile = null;
@@ -129,6 +140,14 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
                         try {
                             saveFile2.createNewFile();
                             file2.transferTo(saveFile2);
+                            final String qFileName = fileName2;
+                            fixedThreadPool.execute(new Runnable() {
+                                @Override
+                                public void run() {
+                                    QcloudUntil.upload(path + qFileName, qFileName);
+                                    QcloudUntil.close();
+                                }
+                            });
                         } catch (IOException e) {
                             e.printStackTrace();
                             projectFile = null;
@@ -146,7 +165,7 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
                         projectFile.setDwgType(userVO.getDwgType());
                     }
                     mouldFileMapper.insert(projectFile);
-                    if(".pdf".equals(sufix1)){
+                    if (".pdf".equals(sufix1)) {
                         PdfFile pdfFile = new PdfFile();
                         pdfFile.setPdfUrl(projectFile.getFileUrl());
                         pdfFile.setFileId(projectFile.getId());
@@ -154,7 +173,7 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
                         pdfFile.setRafId(projectFile.getModelId());
                         pdfFile.setSourceFileUrl(projectFile.getFileUrl());
                         pdfFileMapper.insert(pdfFile);
-                    }else{
+                    } else {
                         //上传完,需要生成pdf
                         String dFile1 = path + UUID.randomUUID().toString().replaceAll("-", "") + ".pdf";
                         openOfficeService.start();
@@ -170,9 +189,9 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
                         pdfFile.setSourceFileUrl(projectFile.getFileUrl());
                         pdfFileMapper.insert(pdfFile);
                     }
-                   if (blongType == 5 && file2 != null && !file2.isEmpty()) {
+                    if (blongType == 5 && file2 != null && !file2.isEmpty()) {
                         //上传的是pdf文件则直接保存
-                        if(".pdf".equals(sufix2)){
+                        if (".pdf".equals(sufix2)) {
                             PdfFile pdfFile = new PdfFile();
                             pdfFile.setPdfUrl(projectFile.getFileUrl2());
                             pdfFile.setFileId(projectFile.getId());
@@ -180,7 +199,7 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
                             pdfFile.setRafId(projectFile.getModelId());
                             pdfFile.setSourceFileUrl(projectFile.getFileUrl2());
                             pdfFileMapper.insert(pdfFile);
-                        }else{
+                        } else {
                             dFile2 = path + UUID.randomUUID().toString().replaceAll("-", "") + ".pdf";
                             File testFile = new File(dFile2);
                             if (!testFile.exists()) {
@@ -485,7 +504,7 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
             dynamics.setFileId(file.getId());
             dynamics.setBelongType(file.getBlongType());
             mouldOperationDynamicsMapper.insert(dynamics);
-            if(null != file.getFileName2()){
+            if (null != file.getFileName2()) {
                 dynamics.setContent(Constant.DOWNLOAD);
                 dynamics.setApplicantId(file.getUplodtorId());
                 dynamics.setApplicantName(file.getUploadtor());
@@ -497,8 +516,8 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
                 dynamics.setBelongType(file.getBlongType());
                 mouldOperationDynamicsMapper.insert(dynamics);
             }
-        }else{
-            if(null != projectFile.getPartId()){
+        } else {
+            if (null != projectFile.getPartId()) {
                 //零件文档
                 List<MouldFile> mouldFiles = mouldFileMapper.selectList(new QueryWrapper<>(projectFile));
                 for (MouldFile file : mouldFiles) {
@@ -566,9 +585,9 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
             if (Constant.SYS_ID.equals(currentUser.getParentId())) {
                 //判断是不是资产方管理员
                 msg.data = mouldFileMapper.deleteById(mouldFile.getId());
-            } else if(file.getUplodtorId().equals(currentUser.getId())){
+            } else if (file.getUplodtorId().equals(currentUser.getId())) {
                 msg.data = mouldFileMapper.deleteById(mouldFile.getId());
-            }else{
+            } else {
                 msg.setError("您没有该权限!");
             }
         }
@@ -685,7 +704,6 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
                     newFolders.add(folder);
                 }
             }
-
             try {
                 // 生成的压缩文件
                 if (newFolders.size() > 0) {
@@ -735,6 +753,7 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
             OpenOfficeService openOfficeService = new OpenOfficeService();
             List<Part> partLists = partMapper.selectList(new QueryWrapper<Part>().eq("mould_id", userVO.getMouldId()));
             openOfficeService.start();
+            ExecutorService fixedThreadPool = Executors.newFixedThreadPool(3);
             for (MultipartFile file : files) {
                 MouldFile partFile = new MouldFile();
                 partFile.setModelId(userVO.getMouldId());
@@ -787,9 +806,17 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
                 try {
                     saveFile.createNewFile();
                     file.transferTo(saveFile);
+                    //将文件传到腾讯云,用线程池里的线程来异步执行,防止把程序中断
+                    final String qFileName = fileName;
+                    fixedThreadPool.execute(new Runnable() {
+                        @Override
+                        public void run() {
+                            QcloudUntil.upload(path + qFileName, qFileName);
+                            QcloudUntil.close();
+                        }
+                    });
                     //上传完,需要生成pdf
                     String dFile1 = path + UUID.randomUUID().toString().replaceAll("-", "") + ".pdf";
-
                     File newFile = new File(dFile1);
                     if (!newFile.exists()) {
                         openOfficeService.office2PDF(path + fileName, dFile1);

+ 10 - 0
cloud-model/src/main/java/com/hssx/cloudmodel/service/impl/ProjectFileServiceImpl.java

@@ -1,4 +1,5 @@
 package com.hssx.cloudmodel.service.impl;
+import	java.io.RandomAccessFile;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.hssx.cloudmodel.constant.Constant;
@@ -11,6 +12,7 @@ import com.hssx.cloudmodel.service.ProjectOperationDynamicsService;
 import com.hssx.cloudmodel.util.FileUtil;
 import com.hssx.cloudmodel.util.HttpRespMsg;
 import com.hssx.cloudmodel.util.OpenOfficeService;
+import com.hssx.cloudmodel.util.QcloudUntil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.Base64Utils;
@@ -78,6 +80,14 @@ public class ProjectFileServiceImpl extends ServiceImpl<ProjectFileMapper, Proje
                     try {
                         saveFile.createNewFile();
                         file.transferTo(saveFile);
+                        //将文件传到腾讯云
+                        final String qFileName = fileName;
+                        new Thread(){
+                            public void run() {
+                                QcloudUntil.upload(path + qFileName,qFileName);
+                                QcloudUntil.close();
+                            }
+                        }.start();
                         //上传完,需要生成pdf
                         OpenOfficeService openOfficeService = new OpenOfficeService();
                         String dFile1 = path+UUID.randomUUID().toString().replaceAll("-", "")+".pdf";

+ 10 - 2
cloud-model/src/main/java/com/hssx/cloudmodel/util/CRC16Util.java

@@ -1,4 +1,8 @@
 package com.hssx.cloudmodel.util;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
 public class CRC16Util {
     /**
      * 计算CRC16校验码
@@ -67,7 +71,11 @@ public class CRC16Util {
 //        System.out.println(getCRC("01 03 20 7F FF 7F FF 7F FF 7F FF 7F FF 7F FF 7F FF 7F FF 7F FF 7F FF 7F FF 7F FF 7F FF 7F FF 7F FF 7F FF"));
 //        System.out.println(getCRC("01 03 00 00 00 08"));
 //        System.out.println(getCRC("01 03 10 00 8F 02 4E 00 91 02 44 00 92 02 5A 00 8B 02 47"));
-    	String crc = getCRC("FA AF 00 07 01 1e 78 1e 50 00 3C");
-        System.out.println(crc);
+//    	String crc = getCRC("FA AF 00 07 01 1e 78 1e 50 00 3C");
+//        System.out.println(crc);
+        Date date=new Date();
+        SimpleDateFormat dateFm = new SimpleDateFormat("EEEE");
+        String format = dateFm.format(date);
+        System.out.println(format+date.getDay());
     }
 }

+ 42 - 23
cloud-model/src/main/java/com/hssx/cloudmodel/util/FileCopyToFolderUtil.java

@@ -13,25 +13,27 @@ import java.util.List;
  */
 public class FileCopyToFolderUtil {
     public static void main(String[] args) throws IOException {
-        Date date = new Date();
-        long time1 = date.getTime();
-        List<String>  sourceFileUrls = new ArrayList<>();
-        sourceFileUrls.add("D:\\软件\\ideaIU-2018.1.5.exe");
-        copy(sourceFileUrls, "D:\\775");
-        date = new Date();
-        long time2 = date.getTime();
-        System.out.println("耗时===》"+(time2-time1)/1000);
-        File file = new File("D:\\776");
-        if (file.exists()) {
-            file.delete();
-            //创建文件夹
-            file.mkdirs();
-        } else {
-            file.mkdirs();
-        }
-        System.out.println(file.getPath());
+//        Date date = new Date();
+//        long time1 = date.getTime();
+//        List<String> sourceFileUrls = new ArrayList<>();
+//        sourceFileUrls.add("D:\\软件\\ideaIU-2018.1.5.exe");
+//        copy(sourceFileUrls, "D:\\775");
+//        date = new Date();
+//        long time2 = date.getTime();
+//        System.out.println("耗时===》" + (time2 - time1) / 1000);
+//        File file = new File("D:\\776");
+//        if (file.exists()) {
+//            file.delete();
+//            //创建文件夹
+//            file.mkdirs();
+//        } else {
+//            file.mkdirs();
+//        }
+//        System.out.println(file.getPath());
+        getSourceUrlFiles();
     }
-    public static String copy(List<String>  sourceFileUrls, String destinationFolder) throws IOException {
+
+    public static String copy(List<String> sourceFileUrls, String destinationFolder) throws IOException {
         //新文件夾
         File file = new File(destinationFolder);
         if (file.exists()) {
@@ -50,16 +52,16 @@ public class FileCopyToFolderUtil {
                 File newFile = new File(file + File.separator + source.getName());
                 if (source.isFile()) {
                     FileInputStream in = new FileInputStream(source);
-                    BufferedInputStream bis= new BufferedInputStream(in);
+                    BufferedInputStream bis = new BufferedInputStream(in);
                     FileOutputStream out = new FileOutputStream(newFile);
-                    BufferedOutputStream bos= new BufferedOutputStream(out);
-                    byte[] bs = new byte[4096*10];
+                    BufferedOutputStream bos = new BufferedOutputStream(out);
+                    byte[] bs = new byte[4096 * 10];
                     int count = 0;
-//循环把源文件的内容写入新文件
+                    //循环把源文件的内容写入新文件
                     while ((count = bis.read(bs, 0, bs.length)) != -1) {
                         bos.write(bs, 0, count);
                     }
-//关闭流
+                    //关闭流
                     out.flush();
                     out.close();
                     in.close();
@@ -69,4 +71,21 @@ public class FileCopyToFolderUtil {
         return file.getPath();
     }
 
+    public static void getSourceUrlFiles(){
+            /*new filenameFilter接口,重写接口内部的一个方法*/
+            /*在E盘的根目录下创建一个Test文件夹,然后在里面创建一些文件*/
+            String[] names = new File("D:\\files\\upload").list(new FilenameFilter() {
+                @Override
+                public boolean accept(File dir, String name) {
+                    // TODO Auto-generated method stub
+                    System.out.println("dir:"+dir);//输出盘符路径
+                    System.out.println("name:"+name); //输出文件名称
+                    return name.endsWith("txt");//输出一个以当前后缀结尾的文件
+                }
+            });
+            /*循环遍历里面放在names字符串数组当中的内容*/
+            for (String temp : names) {
+                System.out.println(temp);
+            }
+        }
 }

+ 249 - 0
cloud-model/src/main/java/com/hssx/cloudmodel/util/QcloudUntil.java

@@ -0,0 +1,249 @@
+package com.hssx.cloudmodel.util;
+import	java.util.HashMap;
+
+import com.qcloud.cos.COSClient;
+import com.qcloud.cos.ClientConfig;
+import com.qcloud.cos.auth.BasicCOSCredentials;
+import com.qcloud.cos.auth.BasicSessionCredentials;
+import com.qcloud.cos.auth.COSCredentials;
+import com.qcloud.cos.exception.CosClientException;
+import com.qcloud.cos.exception.CosServiceException;
+import com.qcloud.cos.model.*;
+import com.qcloud.cos.region.Region;
+import com.tencent.cloud.CosStsClient;
+import org.json.JSONObject;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Map;
+import java.util.TreeMap;
+
+/**
+ * Author: 吴涛涛
+ * Date : 2019 - 12 - 20 14:31
+ * Description:<腾讯云文件上传的工具类>
+ * Version: 1.0
+ */
+public class QcloudUntil {
+
+    private static String secretId = "AKIDkfMmvJUndLwXruCUJq7EINmzvHOFqNZU";
+    private static String secretKey = "qPkqeCI9l6CrHTO31jBPNCk2nJabAO2R";
+    private static String tmpSecretId = "";
+    private static String tmpSecretKey = "";
+    private static String sessionToken = "";
+    private static COSClient cosClient;
+    private static String bucket = "yunsu-1300270157";
+    //静态块,用于初始化用到的配置
+    static {
+        try {
+            //获取临时密钥
+            getTemporaryKey();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
+        // 1 初始化用户身份信息(secretId, secretKey)。
+        COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);
+        // 1 传入获取到的临时密钥 (tmpSecretId, tmpSecretKey, sessionToken)
+        BasicSessionCredentials created = new BasicSessionCredentials(tmpSecretId, tmpSecretKey, sessionToken);
+        // 2 设置 bucket 的区域, COS 地域的简称请参照 https://cloud.tencent.com/document/product/436/6224
+        // clientConfig 中包含了设置 region, https(默认 http), 超时, 代理等 set 方法, 使用可参见源码或者常见问题 Java SDK 部分。
+        Region region = new Region("ap-shanghai");
+        ClientConfig clientConfig = new ClientConfig(region);
+        // 3 生成 cos 客户端。
+        cosClient = new COSClient(cred, clientConfig);
+    }
+
+    public static PutObjectResult upload(String pathName,String onlyFileName) {
+        //存储桶名称,格式:BucketName-APPID
+        CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucket);
+// 设置 bucket 的权限为 PublicRead(公有读私有写), 其他可选有私有读写, 公有读写
+        createBucketRequest.setCannedAcl(CannedAccessControlList.PublicRead);
+        try {
+            //创建存储桶
+            Bucket bucketResult = cosClient.createBucket(createBucketRequest);
+        } catch (CosServiceException serverException) {
+            serverException.printStackTrace();
+        } catch (CosClientException clientException) {
+            clientException.printStackTrace();
+        }
+
+        try {
+            // 指定要上传的文件
+            File localFile = new File(pathName);
+            // 指定要上传到的存储桶
+            String bucketName = bucket;
+            // 指定要上传到 COS 上对象键
+            String key = "/upload_files/"+onlyFileName;
+            PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, localFile);
+            PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest);
+            return putObjectResult;
+        } catch (CosServiceException serverException) {
+            serverException.printStackTrace();
+        } catch (CosClientException clientException) {
+            clientException.printStackTrace();
+        }
+        return null;
+
+    }
+
+    /**
+     * 获取临时密钥
+     * @return
+     * @throws IOException
+     */
+    public static Map getTemporaryKey() throws IOException {
+        Map<String,String> map = new HashMap<String, String> ();
+        TreeMap<String, Object> config = new TreeMap<String, Object>();
+//        try {
+        // 替换为您的 SecretId
+        config.put("SecretId", secretId);
+        System.out.println(secretId);
+        // 替换为您的 SecretKey
+        config.put("SecretKey", secretKey);
+        System.out.println(secretKey);
+        // 临时密钥有效时长,单位是秒,默认1800秒,最长可设定有效期为7200秒
+        config.put("durationSeconds", 1800);
+
+        // 换成您的 bucket
+        config.put("bucket", "yunsu-1300270157");
+        // 换成 bucket 所在地区
+        config.put("region", "ap-shanghai");
+
+//            config.put("expiredtime", 1800);
+
+        // 这里改成允许的路径前缀,可以根据自己网站的用户登录态判断允许上传的具体路径,例子:a.jpg 或者 a/* 或者 * 。
+        // 如果填写了“*”,将允许用户访问所有资源;除非业务需要,否则请按照最小权限原则授予用户相应的访问权限范围。
+        config.put("allowPrefix", "a.jpg");
+
+        // 密钥的权限列表。简单上传、表单上传和分片上传需要以下的权限,其他权限列表请看 https://cloud.tencent.com/document/product/436/31923
+        String[] allowActions = new String[]{
+                // 简单上传
+                "name/cos:PutObject",
+                // 表单上传、小程序上传
+                "name/cos:PostObject",
+                // 分片上传
+                "name/cos:InitiateMultipartUpload",
+                "name/cos:ListMultipartUploads",
+                "name/cos:ListParts",
+                "name/cos:UploadPart",
+                "name/cos:CompleteMultipartUpload"
+        };
+        config.put("allowActions", allowActions);
+
+        JSONObject credential = CosStsClient.getCredential(config);
+        //成功返回临时密钥信息,如下打印密钥信息
+        System.out.println(credential);
+        if (credential.toString().indexOf("credentials") != -1) {
+            tmpSecretId = credential.getJSONObject("credentials").getString("tmpSecretId");
+            System.out.println("tmpSecretId"+tmpSecretId);
+            map.put("tmpSecretId",tmpSecretId);
+            tmpSecretKey = credential.getJSONObject("credentials").getString("tmpSecretKey");
+            System.out.println("tmpSecretKey"+tmpSecretKey);
+            map.put("tmpSecretKey",tmpSecretKey);
+            sessionToken = credential.getJSONObject("credentials").getString("sessionToken");
+            System.out.println("sessionToken"+sessionToken);
+            map.put("sessionToken",sessionToken);
+        }
+//        } catch (Exception e) {
+//            //失败抛出异常
+//            throw new IllegalArgumentException("no valid secret !");
+//        }
+        return map;
+    }
+
+    //获取存储桶中的文件列表
+    /**
+     *
+     * @param prifix 文件的开始前缀(一般指文件夹名字)
+     * @return
+     */
+    public static String getBucketList(String prifix) {
+        try {
+            String bucket = "yunsu-1300270157";
+            ListObjectsRequest listObjectsRequest = new ListObjectsRequest();
+            // 设置 bucket 名称
+            listObjectsRequest.setBucketName(bucket);
+            // prefix 表示列出的 object 的 key 以 prefix 开始
+            listObjectsRequest.setPrefix(prifix);
+            // 设置最大遍历出多少个对象, 一次 listobject 最大支持1000
+            listObjectsRequest.setMaxKeys(1000);
+            listObjectsRequest.setDelimiter("/");
+            ObjectListing objectListing = cosClient.listObjects(listObjectsRequest);
+            for (COSObjectSummary cosObjectSummary : objectListing.getObjectSummaries()) {
+                // 对象的路径 key
+                String key = cosObjectSummary.getKey();
+                // 对象的 etag
+                String etag = cosObjectSummary.getETag();
+                // 对象的长度
+                long fileSize = cosObjectSummary.getSize();
+                // 对象的存储类型
+                String storageClass = cosObjectSummary.getStorageClass();
+                System.out.println("key:" + key + "; etag:" + etag + "; fileSize:" + fileSize + "; storageClass:" + storageClass);
+//                return storageClass;
+            }
+            return null;
+        } catch (CosServiceException serverException) {
+            serverException.printStackTrace();
+        } catch (CosClientException clientException) {
+            clientException.printStackTrace();
+        }
+        return null;
+    }
+
+    /**
+     * 删除存储桶里的文件
+     * @param fileKey 指定对象在存储桶上的对象键(注:文件夹+文件名 具体参考腾讯云的对象键说明)
+     */
+    public static void delete(String fileKey){
+        try {
+            // 指定对象所在的存储桶
+            String bucketName = bucket;
+            // 指定对象在 COS 上的对象键
+            String key = fileKey;
+            cosClient.deleteObject(bucketName, key);
+        } catch (CosServiceException serverException) {
+            serverException.printStackTrace();
+        } catch (CosClientException clientException) {
+            clientException.printStackTrace();
+        }
+
+    }
+    /**
+     * 下载存储桶里的文件
+     * @param fileKey 指定对象在存储桶上的对象键(注:文件夹+文件名 具体参考腾讯云的对象键说明)
+     * @param downloadPath 要下载到的路径和文件名(如:D:\34.txt 注:一定要是全路径和文件名一起,否则会导致文件无法识别)
+     */
+    public static void downLoadFile(String fileKey,String downloadPath){
+        try{
+            // 指定对象所在的存储桶
+            String bucketName = bucket;
+            // 指定对象在 COS 上的对象键
+            String key = fileKey;
+            // 指定要下载到的本地路径
+            File downFile = new File(downloadPath);
+            GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, key);
+            ObjectMetadata downObjectMeta = cosClient.getObject(getObjectRequest, downFile);
+        } catch (CosServiceException serverException) {
+            serverException.printStackTrace();
+        } catch (CosClientException clientException) {
+            clientException.printStackTrace();
+        }
+    }
+
+    // 关闭客户端(关闭后台线程)
+    public static void close(){
+        cosClient.shutdown();
+    }
+
+    public static void main(String[] args) throws IOException {
+//        JSONObject tem = tem();
+//        String a = tem.getJSONObject("credentials").getString("tmpSecretId");
+//        System.out.println(a);
+
+//        PutObjectResult upload = upload("D:\\1\\爱你.txt","ai.txt");
+//        System.out.println(upload.ge);
+        downLoadFile("upload_files/ai.txt","D:\\34.txt");
+//        System.out.println("存储桶列表" + getBucketList("/upload_files/"));
+    }
+}

+ 1 - 1
cloud-model/src/main/resources/application-prod.properties

@@ -16,7 +16,7 @@ spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
 # 云模服务器对应的数据库
 #spring.datasource.url=jdbc:mysql://118.190.47.230:3306/cloud_model?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
 # 我们测试的自己服务器数据库
-#spring.datasource.url=jdbc:mysql://118.190.47.230:3306/cloud_model_test?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
+#spring.datasource.url=jdbc:mysql://118.190.47.230:3306/cloud_mould?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
 #spring.datasource.username=root
 #spring.datasource.password=p011430seya1026
 spring.datasource.url=jdbc:mysql://127.0.0.1:3306/cloud_mould?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8

+ 1 - 1
cloud-model/src/main/resources/application.properties

@@ -14,7 +14,7 @@ spring.thymeleaf.jackson.date-format=yyyy-MM-dd HH:mm:ss
 # Êý¾ÝÔ´ÅäÖÃ
 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
 #spring.datasource.url=jdbc:mysql://118.190.47.230:3306/cloud_model?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
-spring.datasource.url=jdbc:mysql://118.190.47.230:3306/cloud_model_test?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
+spring.datasource.url=jdbc:mysql://118.190.47.230:3306/cloud_mould?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
 spring.datasource.username=root
 spring.datasource.password=p011430seya1026
 #spring.datasource.druid.test-on-borrow=true

+ 4 - 0
official_backend/pom.xml

@@ -77,6 +77,10 @@
             <artifactId>commons-fileupload</artifactId>
             <version>1.4</version>
         </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-autoconfigure</artifactId>
+        </dependency>
     </dependencies>
 
     <build>

+ 6 - 4
website/src/main/resources/application-prod.properties

@@ -19,11 +19,13 @@ spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/reso
 # 数据源配置
 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
 # 云模服务器对应的数据库
-#spring.datasource.url=jdbc:mysql://118.190.47.230:3306/cloud_model?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
-# 我们测试的自己服务器数据库
-spring.datasource.url=jdbc:mysql://127.0.0.1:3306/cloud_model_website?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
+spring.datasource.url=jdbc:mysql://118.190.47.230:3306/cloud_mould?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
 spring.datasource.username=root
-spring.datasource.password=Hssx2019.!
+spring.datasource.password=p011430seya1026
+# 我们测试的自己服务器数据库
+#spring.datasource.url=jdbc:mysql://127.0.0.1:3306/cloud_model_website?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
+#spring.datasource.username=root
+#spring.datasource.password=Hssx2019.!
 #spring.datasource.druid.test-on-borrow=true
 #spring.datasource.druid.test-while-idle=true
 # ####################################################################################################

+ 1 - 1
website/src/main/resources/application.properties

@@ -22,7 +22,7 @@ spring.thymeleaf.jackson.date-format=yyyy-MM-dd HH:mm:ss
 # ####################################################################################################
 # Êý¾ÝÔ´ÅäÖÃ
 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
-spring.datasource.url=jdbc:mysql://118.190.47.230:3306/cloud_model_website?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
+spring.datasource.url=jdbc:mysql://118.190.47.230:3306/cloud_mould?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
 spring.datasource.username=root
 spring.datasource.password=p011430seya1026
 #spring.datasource.druid.test-on-borrow=true