Prechádzať zdrojové kódy

上传文件从百度BOS调整到阿里OSS相关代码

user5 5 rokov pred
rodič
commit
8314f809f8

+ 7 - 0
pom.xml

@@ -969,6 +969,13 @@
             <artifactId>bce-java-sdk</artifactId>
             <version>0.10.87</version>
         </dependency>
+
+        <dependency>
+            <groupId>com.aliyun.oss</groupId>
+            <artifactId>aliyun-sdk-oss</artifactId>
+            <version>3.8.1</version>
+        </dependency>
+
     </dependencies>
 
 </project>

+ 135 - 0
src/main/java/com/jeeplus/common/alioss/AliyunOSSUtil.java

@@ -0,0 +1,135 @@
+package com.jeeplus.common.alioss;
+
+import com.aliyun.oss.ClientException;
+import com.aliyun.oss.OSSClient;
+import com.aliyun.oss.OSSException;
+import com.aliyun.oss.model.*;
+import com.jeeplus.common.config.Global;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author 徐滕
+ * @version 2020-04-14
+ */
+@SuppressWarnings("unused")
+public class AliyunOSSUtil {
+ 
+    private static final org.slf4j.Logger logger = LoggerFactory.getLogger(AliyunOSSUtil.class);
+
+    private final static String endpoint= Global.getConfig("media.endpoint");
+    private final static String accessKeyId= Global.getConfig("media.keyid");
+    private final static String accessKeySecret= Global.getConfig("media.keysecret");
+    private final static String bucketName= Global.getConfig("media.bucketname");
+    private final static String fileHost= Global.getConfig("media.filehost");
+
+	public static Map upload(File file){
+        Map map = new HashMap();
+        logger.info("=========>OSS文件上传开始:"+file.getName());
+        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
+        String dateStr = format.format(new Date());
+        if(null == file){
+            return null;
+        }
+        OSSClient ossClient = new OSSClient(endpoint,accessKeyId,accessKeySecret);
+        try {
+            //容器不存在,就创建
+            if(!ossClient.doesBucketExist(bucketName)){
+                ossClient.createBucket(bucketName);
+                CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
+                createBucketRequest.setCannedACL(CannedAccessControlList.PublicRead);
+                ossClient.createBucket(createBucketRequest);
+            }
+            //创建文件路径
+            String fileUrl = fileHost+"/"+(dateStr + "/" +file.getName());
+            //上传文件
+            PutObjectResult result = ossClient.putObject(new PutObjectRequest(bucketName, fileUrl, file));
+            //设置权限 这里是公开的
+            ossClient.setBucketAcl(bucketName,CannedAccessControlList.PublicRead);
+            if(null != result){
+                //生成下载路径
+                URL url = ossClient.generatePresignedUrl(bucketName, fileUrl, new Date(new Date().getTime() + 3600 * 10000));
+                logger.info("==========>OSS文件上传成功,OSS地址:"+fileUrl);
+                System.err.println(fileUrl);
+                map.put("msg","上传成功");
+                map.put("code","1");
+                map.put("url",url);
+                return map;
+            }
+        }catch (OSSException oe){
+            logger.error(oe.getMessage());
+        }catch (ClientException ce){
+            logger.error(ce.getMessage());
+        }finally {
+            //关闭
+            ossClient.shutdown();
+        }
+        map.put("msg","上传失败");
+        map.put("code","0");
+        return map;
+    }
+
+    /**
+     * 文件下载
+     * @param fileUrl
+     * @return
+     */
+    public static void downloadFile(String fileUrl,String fileName, HttpServletResponse response){
+        OSSClient ossClient = new OSSClient(endpoint,accessKeyId,accessKeySecret);
+        OSSObject object = ossClient.getObject(bucketName, fileUrl);
+        // 获取Object的输入流
+        InputStream inputStream = object.getObjectContent();
+        int buffer = 1024 * 10;
+        byte data[] = new byte[buffer];
+        try {
+            response.setContentType("application/octet-stream");
+            // 文件名可以任意指定
+            response.setHeader("Content-disposition", "attachment; filename=" + fileName);
+            response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName,"UTF-8"));//将文件名转为ASCLL编码
+            int read;
+            while ((read = inputStream.read(data)) != -1) {
+                response.getOutputStream().write(data, 0, read);
+            }
+            response.getOutputStream().flush();
+            response.getOutputStream().close();
+            object.close();
+        } catch (UnsupportedEncodingException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }  catch (IOException e) {
+            e.printStackTrace();
+        }finally {
+            // 关闭OSSClient。
+            ossClient.shutdown();
+        }
+    }
+
+    /**
+     * 删除文件
+     * @param OSSKeyUrl
+     * @return
+     */
+    public static String delFile(String OSSKeyUrl){
+        OSSClient ossClient = new OSSClient(endpoint,accessKeyId,accessKeySecret);
+        //key键为:保存文件时,OSS服务器返回给我们的url
+        try {
+            ossClient.deleteObject(bucketName, OSSKeyUrl);
+        }catch (Exception e){
+            e.getMessage();
+        }finally {
+            ossClient.shutdown();
+        }
+        return null;
+    }
+}

+ 45 - 0
src/main/java/com/jeeplus/common/alioss/ConstantProperties.java

@@ -0,0 +1,45 @@
+package com.jeeplus.common.alioss;
+ 
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author 徐滕
+ * @version 2020-04-14
+ * 配置文件配置项
+ */
+@Component
+public class ConstantProperties implements InitializingBean{
+ 
+    @Value("${media.endpoint}")
+    private String media_endpoint;
+ 
+    @Value("${media.keyid}")
+    private String media_keyid;
+ 
+    @Value("${media.keysecret}")
+    private String media_keysecret;
+ 
+    @Value("${media.filehost}")
+    private String media_filehost;
+ 
+    @Value("${media.bucketname}")
+    private String media_bucketname;
+ 
+ 
+    public static String POINT;
+    public static String KEY_ID;
+    public static String KEY_SECRET;
+    public static String BUCKET_NAME;
+    public static String HOST;
+ 
+    @Override
+    public void afterPropertiesSet() throws Exception {
+        POINT = media_endpoint;
+        KEY_ID = media_keyid;
+        KEY_SECRET = media_keysecret;
+        HOST = media_filehost;
+        BUCKET_NAME = media_bucketname;
+    }
+}

+ 27 - 1
src/main/java/com/jeeplus/common/bos/BosController.java

@@ -1,12 +1,14 @@
 package com.jeeplus.common.bos;
 
-import com.jeeplus.modules.iim.entity.MailPage;
+import com.jeeplus.common.alioss.AliyunOSSUtil;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletRequest;
+import java.io.File;
+import java.io.FileOutputStream;
 import java.io.InputStream;
 import java.util.HashMap;
 import java.util.Map;
@@ -34,6 +36,30 @@ public class BosController {
         return map;
     }
 
+    /**
+     * 通过阿里云OSS上传文件
+     * @param file
+     * @return
+     */
+    @RequestMapping("uploadOSS")
+    @ResponseBody
+    public Map uploadOSS(HttpServletRequest request,MultipartFile file){
+        String fileName = file.getOriginalFilename();
+        File newFile = new File(fileName);
+        FileOutputStream os;
+        try {
+            os = new FileOutputStream(newFile);
+            os.write(file.getBytes());
+            os.close();
+            file.transferTo(newFile);
+        } catch (Exception e1) {
+            e1.printStackTrace();
+        }
+        //上传到OSS
+        Map map = AliyunOSSUtil.upload(newFile);
+        return map;
+    }
+
     @RequestMapping("uploadPic")
     @ResponseBody
     public Map uploadPic(MultipartFile uploadFile){

+ 340 - 0
src/main/java/com/jeeplus/common/config/FileGlobal.java

@@ -0,0 +1,340 @@
+package com.jeeplus.common.config;
+
+import com.google.common.collect.Maps;
+import com.jeeplus.common.utils.FileUtils;
+import com.jeeplus.common.utils.PropertiesLoader;
+import com.jeeplus.common.utils.StringUtils;
+import com.jeeplus.common.web.Servlets;
+import com.jeeplus.modules.sys.security.SystemAuthorizingRealm;
+import com.jeeplus.modules.sys.utils.UserUtils;
+import org.apache.ibatis.io.Resources;
+import org.springframework.core.io.DefaultResourceLoader;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.Reader;
+import java.util.Map;
+import java.util.Properties;
+
+public class FileGlobal {
+
+    /**
+     * 当前对象实例
+     */
+    private static FileGlobal global = new FileGlobal();
+
+    /**
+     * 保存全局属性值
+     */
+    private static Map<String, String> map = Maps.newHashMap();
+
+    /**
+     * 属性文件加载对象
+     */
+    private static PropertiesLoader loader = new PropertiesLoader("/properties/jeeplus.properties");
+
+    /**
+     * 显示/隐藏
+     */
+    public static final String SHOW = "1";
+    public static final String HIDE = "0";
+
+    /**
+     * 是/否
+     */
+    public static final String YES = "1";
+    public static final String NO = "0";
+
+    /**
+     * 对/错
+     */
+    public static final String TRUE = "true";
+    public static final String FALSE = "false";
+
+    /**
+     * 上传文件基础虚拟路径
+     */
+    public static final String USERFILES_BASE_URL = "/freemarker/";
+
+    public static final String FILES_FILESERVER = "/fileServer/";
+
+
+    /**
+     * 判断服务器系统类型,1是windows系统,2是linux系统
+     */
+    public static final String SYS_TYPE = System.getProperty("os.name").toLowerCase().startsWith("win") ? "1" : "2";
+
+
+
+    /**
+     * 共享文档物理存储地址
+     *
+     * @return
+     */
+    public static String getShareBaseDir() {
+        String dir = Global.getUserfilesBaseDir() + Global.USERFILES_BASE_URL + "共享文档/";
+        FileUtils.createDirectory(dir);
+        return dir;
+    }
+
+    /**
+     * 共享文档网络访问地址
+     *
+     * @return
+     */
+    public static String getShareBaseUrl() {
+        SystemAuthorizingRealm.Principal principal = (SystemAuthorizingRealm.Principal) UserUtils.getPrincipal();
+        return Servlets.getRequest().getContextPath() + Global.USERFILES_BASE_URL + "/共享文档/";
+    }
+
+    /**
+     * 我的文档物理存储地址
+     *
+     * @return
+     */
+    public static String getMyDocDir() {
+        SystemAuthorizingRealm.Principal principal = (SystemAuthorizingRealm.Principal) UserUtils.getPrincipal();
+        String dir = Global.getUserfilesBaseDir() + Global.USERFILES_BASE_URL + principal + "/我的文档/";
+        FileUtils.createDirectory(dir);
+        return dir;
+    }
+
+    /**
+     * 我的文档网络访问地址
+     *
+     * @return
+     */
+    public static String getMyDocUrl() {
+        SystemAuthorizingRealm.Principal principal = (SystemAuthorizingRealm.Principal) UserUtils.getPrincipal();
+        return Servlets.getRequest().getContextPath() + Global.USERFILES_BASE_URL + principal + "/我的文档/";
+    }
+
+    /**
+     * 程序附件物理存储地址
+     *
+     * @return
+     */
+    public static String getAttachmentDir() {
+        SystemAuthorizingRealm.Principal principal = (SystemAuthorizingRealm.Principal) UserUtils.getPrincipal();
+        String dir = Global.getUserfilesBaseDir() + Global.USERFILES_BASE_URL;
+        FileUtils.createDirectory(dir);
+        return dir;
+    }
+
+    /**
+     * 程序附件物理存储地址
+     *
+     * @return
+     */
+    public static String getAttachmentDir2() {
+        SystemAuthorizingRealm.Principal principal = (SystemAuthorizingRealm.Principal) UserUtils.getPrincipal();
+        String dir = "";
+        String FILE_PREFIX = loader.getProperty("linux.file.store.prefix");
+        if (SYS_TYPE.equals("1")) {
+            dir = FileGlobal.getUserfilesBaseDir() + FileGlobal.FILES_FILESERVER;
+        } else {
+            //liunx file store prefix
+            dir =  FILE_PREFIX + Servlets.getRequest().getContextPath() + FileGlobal.FILES_FILESERVER;
+        }
+
+        FileUtils.createDirectory(dir);
+        return dir;
+    }
+
+    /**
+     * 程序附件网络访问地址
+     *
+     * @return
+     */
+    public static String getAttachmentUrl() {
+
+        SystemAuthorizingRealm.Principal principal = (SystemAuthorizingRealm.Principal) UserUtils.getPrincipal();
+        return Servlets.getRequest().getContextPath() + Global.USERFILES_BASE_URL;
+    }
+
+
+    /**
+     * 程序附件网络访问地址
+     *
+     * @return
+     */
+    public static String getAttachmentUrl2() {
+
+        SystemAuthorizingRealm.Principal principal = (SystemAuthorizingRealm.Principal) UserUtils.getPrincipal();
+        return Servlets.getRequest().getContextPath() + FileGlobal.FILES_FILESERVER;
+    }
+
+    /**
+     * 绝对地址转换为网络地址
+     *
+     * @return
+     */
+    public static String transDirToUrl(String dir) {
+        return Servlets.getRequest().getContextPath() + "/" + dir.substring(Global.getUserfilesBaseDir().length());
+    }
+
+    /**
+     * 获取当前对象实例
+     */
+    public static FileGlobal getInstance() {
+        return global;
+    }
+
+    /**
+     * 获取配置
+     */
+    public static String getConfig(String key) {
+        String value = map.get(key);
+        if (value == null) {
+            value = loader.getProperty(key);
+            map.put(key, value != null ? value : StringUtils.EMPTY);
+        }
+        return value;
+    }
+
+    /**
+     * 获取管理端根路径
+     */
+    public static String getAdminPath() {
+        return getConfig("adminPath");
+    }
+
+
+    /**
+     * 获取管理端根路径
+     */
+    public static String getDefaultTheme() {
+        return getConfig("defaultTheme");
+    }
+
+    /**
+     * 获取前端根路径
+     */
+    public static String getFrontPath() {
+        return getConfig("frontPath");
+    }
+
+    /**
+     * 获取URL后缀
+     */
+    public static String getUrlSuffix() {
+        return getConfig("urlSuffix");
+    }
+
+    /**
+     * 是否是演示模式,演示模式下不能修改用户、角色、密码、菜单、授权
+     */
+    public static Boolean isDemoMode() {
+        String dm = getConfig("demoMode");
+        return "true".equals(dm) || "1".equals(dm);
+    }
+
+    /**
+     * 在修改系统用户和角色时是否同步到Activiti
+     */
+    public static Boolean isSynActivitiIndetity() {
+        String dm = getConfig("activiti.isSynActivitiIndetity");
+        return "true".equals(dm) || "1".equals(dm);
+    }
+
+    /**
+     * 页面获取常量
+     */
+    public static Object getConst(String field) {
+        try {
+            return Global.class.getField(field).get(null);
+        } catch (Exception e) {
+            // 异常代表无配置,这里什么也不做
+        }
+        return null;
+    }
+
+    /**
+     * 获取上传文件的根目录
+     *
+     * @return
+     */
+    public static String getUserfilesBaseDir() {
+        String dir = getConfig("userfiles.basedir");
+        if (StringUtils.isBlank(dir)) {
+            return "";
+        }
+        if (!dir.endsWith("/")) {
+            dir += "/";
+        }
+//		System.out.println("userfiles.basedir: " + dir);
+        return dir;
+    }
+
+    /**
+     * 获取工程路径
+     *
+     * @return
+     */
+    public static String getProjectPath() {
+        // 如果配置了工程路径,则直接返回,否则自动获取。
+        String projectPath = Global.getConfig("projectPath");
+        if (StringUtils.isNotBlank(projectPath)) {
+            return projectPath;
+        }
+        try {
+            File file = new DefaultResourceLoader().getResource("").getFile();
+            if (file != null) {
+                while (true) {
+                    File f = new File(file.getPath() + File.separator + "src" + File.separator + "main");
+                    if (f == null || f.exists()) {
+                        break;
+                    }
+                    if (file.getParentFile() != null) {
+                        file = file.getParentFile();
+                    } else {
+                        break;
+                    }
+                }
+                projectPath = file.toString();
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return projectPath;
+    }
+
+    /**
+     * 写入properties信息
+     *
+     * @param key   名称
+     * @param value 值
+     */
+    public static void modifyConfig(String key, String value) {
+        try {
+            // 从输入流中读取属性列表(键和元素对)
+            Properties prop = getProperties();
+            prop.setProperty(key, value);
+            String path = Global.class.getResource("/properties/jeeplus.properties").getPath();
+            FileOutputStream outputFile = new FileOutputStream(path);
+            prop.store(outputFile, "modify");
+            outputFile.close();
+            outputFile.flush();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 返回 Properties
+     *
+     * @param
+     * @return
+     */
+    public static Properties getProperties() {
+        Properties prop = new Properties();
+        try {
+            Reader reader = Resources.getResourceAsReader("/properties/jeeplus.properties");
+            prop.load(reader);
+        } catch (Exception e) {
+            return null;
+        }
+        return prop;
+    }
+}

+ 1 - 3
src/main/java/com/jeeplus/modules/filePreview/OSSRequestSigner.java

@@ -5,8 +5,6 @@ import com.aliyun.oss.common.auth.Credentials;
 import com.aliyun.oss.common.auth.RequestSigner;
 import com.aliyun.oss.common.auth.ServiceSignature;
 import com.aliyun.oss.common.comm.RequestMessage;
-import com.aliyun.oss.internal.OSSHeaders;
-import com.aliyun.oss.internal.OSSUtils;
 import com.aliyun.oss.internal.SignUtils;
 
 public class OSSRequestSigner  implements RequestSigner{
@@ -30,7 +28,7 @@ public class OSSRequestSigner  implements RequestSigner{
         if (accessKeyId.length() > 0 && secretAccessKey.length() > 0) {
             String canonicalString = SignUtils.buildCanonicalString(httpMethod, resourcePath, request, null);
             String signature = ServiceSignature.create().computeSignature(secretAccessKey, canonicalString);
-            request.addHeader(OSSHeaders.AUTHORIZATION, OSSUtils.composeRequestAuthorization(accessKeyId, signature));
+            //request.addHeader(OSSHeaders.AUTHORIZATION, OSSUtils.composeRequestAuthorization(accessKeyId, signature));
         }
     }
 }

+ 7 - 8
src/main/java/com/jeeplus/modules/sys/service/WorkattachmentService.java

@@ -3,24 +3,19 @@
  */
 package com.jeeplus.modules.sys.service;
 
-import com.jeeplus.common.bos.BOSClientUtil;
-import com.jeeplus.common.config.Global;
+import com.jeeplus.common.alioss.AliyunOSSUtil;
 import com.jeeplus.common.oss.OSSClientUtil;
 import com.jeeplus.common.persistence.Page;
 import com.jeeplus.common.service.CrudService;
 import com.jeeplus.common.utils.StringUtils;
-import com.jeeplus.modules.isignature.service.ISignatureDocumentService;
 import com.jeeplus.modules.sys.dao.WorkattachmentDao;
 import com.jeeplus.modules.sys.entity.Workattachment;
 import com.jeeplus.modules.sys.utils.UserUtils;
-import org.apache.commons.io.FilenameUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.multipart.MultipartHttpServletRequest;
-import sun.awt.AWTCharset;
-import sun.nio.cs.SingleByte;
 
 import java.net.URLDecoder;
 import java.util.*;
@@ -177,10 +172,14 @@ public class WorkattachmentService extends CrudService<WorkattachmentDao, Workat
 //			workattachment1.setUrl(url);
 //			deleteByUrl(workattachment1);
 			try {
-				int index = url.indexOf(".com");
+				String newUrl = URLDecoder.decode(url.substring(0, url.lastIndexOf("?")), "UTF-8");
+				int index = newUrl.indexOf(".com");
+				String 	path = URLDecoder.decode(newUrl.substring(index + 4, newUrl.length()), "UTF-8");
+				AliyunOSSUtil.delFile(path);
+				/*int index = url.indexOf(".com");
 				String 	path = URLDecoder.decode(url.substring(index + 4, url.length()), "UTF-8");
 				BOSClientUtil bosClientUtil = new BOSClientUtil();
-				bosClientUtil.deleteObject(path);
+				bosClientUtil.deleteObject(path);*/
 			}catch (Exception e){
 
 			}

+ 24 - 32
src/main/java/com/jeeplus/modules/workcontractinfo/web/WorkContractInfoController.java

@@ -6,33 +6,25 @@ package com.jeeplus.modules.workcontractinfo.web;
 import com.google.common.base.Strings;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
-import com.google.zxing.aztec.decoder.Decoder;
+import com.jeeplus.common.alioss.AliyunOSSUtil;
 import com.jeeplus.common.beanvalidator.BeanValidators;
-import com.jeeplus.common.bos.BOSClientUtil;
 import com.jeeplus.common.config.Global;
-import com.jeeplus.common.json.AjaxJson;
 import com.jeeplus.common.oss.OSSClientUtil;
 import com.jeeplus.common.persistence.Page;
 import com.jeeplus.common.utils.DateUtils;
-import com.jeeplus.common.utils.IdGen;
 import com.jeeplus.common.utils.MyBeanUtils;
 import com.jeeplus.common.utils.StringUtils;
 import com.jeeplus.common.utils.excel.ExportExcel;
 import com.jeeplus.common.utils.excel.ImportExcel;
 import com.jeeplus.common.web.BaseController;
-import com.jeeplus.common.websocket.onchat.ChatServerPool;
 import com.jeeplus.modules.act.entity.Act;
 import com.jeeplus.modules.act.service.ActTaskService;
 import com.jeeplus.modules.act.utils.ActUtils;
 import com.jeeplus.modules.alterinfo.entity.AlterInfo;
 import com.jeeplus.modules.alterinfo.service.AlterInfoService;
-import com.jeeplus.modules.contractclient.entity.WorkContractClient;
-import com.jeeplus.modules.contractclient.service.WorkContractClientService;
 import com.jeeplus.modules.sys.entity.Office;
 import com.jeeplus.modules.sys.entity.Role;
 import com.jeeplus.modules.sys.entity.User;
-import com.jeeplus.modules.sys.service.OfficeService;
-import com.jeeplus.modules.sys.utils.RoleActivityEnname;
 import com.jeeplus.modules.sys.utils.UserUtils;
 import com.jeeplus.modules.sysimportinfo.entity.SysImportInfo;
 import com.jeeplus.modules.sysimportinfo.service.SysImportInfoService;
@@ -44,9 +36,7 @@ import com.jeeplus.modules.workclientinfo.dao.WorkClientAttachmentDao;
 import com.jeeplus.modules.workclientinfo.entity.WorkClientAttachment;
 import com.jeeplus.modules.workclientinfo.entity.WorkClientInfo;
 import com.jeeplus.modules.workclientinfo.service.WorkClientInfoService;
-import com.jeeplus.modules.workcontractinfo.dao.WorkContractInfoCopyDao;
 import com.jeeplus.modules.workcontractinfo.entity.WorkContractInfo;
-import com.jeeplus.modules.workcontractinfo.entity.WorkContractInfoCopy;
 import com.jeeplus.modules.workcontractinfo.entity.WorkContractListInfo;
 import com.jeeplus.modules.workcontractinfo.entity.WorkContractReview;
 import com.jeeplus.modules.workcontractinfo.service.WorkContractInfoService;
@@ -69,8 +59,6 @@ import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.multipart.commons.CommonsMultipartFile;
 import org.springframework.web.servlet.mvc.support.RedirectAttributes;
-import sun.nio.cs.SingleByte;
-import sun.nio.cs.ext.HKSCS;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -1460,30 +1448,34 @@ public class WorkContractInfoController extends BaseController {
      */
     @RequestMapping("/downLoadAttach")
     public void downLoadAttach(@RequestParam("file") String file, HttpServletResponse response) throws IOException {
-//        file = file.replace("amp;","");
-//        String fileName = file.substring(file.lastIndexOf("/") + 1, file.length());
-//        String aliyunUrl = Global.getAliyunUrl();
-//        String aliDownloadUrl = Global.getAliDownloadUrl();
-//        String cons = "";
-//        if (file.contains(aliyunUrl)){
-//            cons = aliyunUrl;
-//        }else if (file.contains("http://gangwan-app.oss-cn-hangzhou.aliyuncs.com")){
-//            cons = "http://gangwan-app.oss-cn-hangzhou.aliyuncs.com";
-//        }else {
-//            cons = aliDownloadUrl;
-//        }
-//        final String[] arr = file.split(cons + "/");
-//        String key = arr[1];
-//        new OSSClientUtil().downByStream(key, fileName, response,request.getHeader("USER-AGENT"));
+/*        file = file.replace("amp;","");
+        String fileName = file.substring(file.lastIndexOf("/") + 1, file.length());
+        String aliyunUrl = Global.getAliyunUrl();
+        String aliDownloadUrl = Global.getAliDownloadUrl();
+        String cons = "";
+        if (file.contains(aliyunUrl)){
+            cons = aliyunUrl;
+        }else if (file.contains("http://gangwan-app.oss-cn-hangzhou.aliyuncs.com")){
+            cons = "http://gangwan-app.oss-cn-hangzhou.aliyuncs.com";
+        }else {
+            cons = aliDownloadUrl;
+        }
+        final String[] arr = file.split(cons + "/");
+        String key = arr[1];
+        new OSSClientUtil().downByStream(key, fileName, response,request.getHeader("USER-AGENT"));*/
         OutputStream out = null;
         InputStream in = null;
         try {
-            file = URLDecoder.decode(file,"UTF-8");
+            /*file = URLDecoder.decode(file,"UTF-8");
             String path = file.substring(file.indexOf(".com") + 4, file.length());
             String fileName = URLEncoder.encode(file.substring(file.lastIndexOf("/") + 1, file.length()),"UTF-8");
             BOSClientUtil bosClientUtil = new BOSClientUtil();
-            in = bosClientUtil.getObject(path);
-            response.reset();//重置 响应头
+            in = bosClientUtil.getObject(path);*/
+            file = URLDecoder.decode(file,"UTF-8");
+            String path = file.substring(file.indexOf(".com") + 5, file.indexOf("?"));
+            String fileName = path.substring(path.lastIndexOf("/") + 1, path.length());
+            AliyunOSSUtil.downloadFile(path,fileName,response);
+            /*response.reset();//重置 响应头
             response.setContentType("application/x-download");
             response.setHeader("Content-disposition", "attachment; filename=" + fileName);
             out = response.getOutputStream();
@@ -1493,7 +1485,7 @@ public class WorkContractInfoController extends BaseController {
                 response.getOutputStream().write(b, 0, len);
             }
             in.close();
-            out.close();
+            out.close();*/
         }catch (IOException e){
             e.printStackTrace();
         }finally {

+ 13 - 0
src/main/resources/jeeplus.properties

@@ -247,5 +247,18 @@ bos_buck_name=newxgccpm
 #bos_buck_name=xgccpm
 
 
+#\u963F\u91CC\u4E91OSS
+# oss-cn-hangzhou.aliyuncs.com  \u676D\u5DDE
+media.endpoint=oss-cn-hangzhou.aliyuncs.com
+#AccessKey ID
+media.keyid=LTAI4FxP5oK8d1HbyCb3TDu5
+#Access Key Secret
+media.keysecret=w8krvH1fBaacQd9lC6h88ewba98aIL
+#oss \u5B58\u50A8\u7684\u57DF\u540D \u5373\u4E3A Bucket\u7684\u540D\u5B57
+media.bucketname=xgxm-test
+# Bucket\u4E0B\u521B\u5EFA\u7684\u6587\u4EF6\u8DEF\u5F84
+media.filehost=xg
+
+
 serverDomain=http://192.168.2.4:18080/total_process
 

+ 6 - 3
src/main/webapp/static/bos/bosupload.js

@@ -31,7 +31,8 @@ function multitest (storeAs, file,attachmentId,attachmentFlag,uploadPath,divId,
     var name = names[names.length-1];
     $.ajax({
         type:'post',
-        url:realPath+"/a/bos/upload",
+        //url:realPath+"/a/bos/upload",
+        url:realPath+"/bos/uploadOSS",
         data:formdata,
         contentType: false,
         processData: false,
@@ -46,7 +47,8 @@ function multitest (storeAs, file,attachmentId,attachmentFlag,uploadPath,divId,
         // }
         success:function (data1) {
             if(data1.code==='1'){
-                returnUrl = realPath+"/a/sys/workattachment/saveAttachment";
+                //returnUrl = realPath+"/a/sys/workattachment/saveAttachment";
+                returnUrl = realPath+"/sys/workattachment/saveAttachment";
                 var p = Math.floor(1*100);
                 $("#jindutiao"+divId).attr("style","width: "+p+"%");
                 $("#jindutiao"+divId).attr("aria-valuenow",p+"%");
@@ -95,7 +97,8 @@ function multitest (storeAs, file,attachmentId,attachmentFlag,uploadPath,divId,
                                 '<div class="op-btn-box">' +
                                 // '<a href="javascript:location.href=\''+realPath+'/a/workfullmanage/workFullManage/downLoadAttach?file=\'+encodeURIComponent(\''+data.url+'\');" class="op-btn op-btn-download"><i class="fa fa-download"></i>&nbsp;下载</a>'+
                                 '<a href="'+data1.url+'" class="op-btn op-btn-download"><i class="fa fa-download"></i>&nbsp;下载</a>'+
-                                '<a href="javascript:void(0)" onclick="deleteFileFromAliyun(this,\''+realPath+'/a/sys/workattachment/deleteFileFromAliyun?url='+data.url+'&id='+data.id+'&type=2\',\''+addFile+'\',\''+divId+'\')" class="op-btn op-btn-delete" ><i class="fa fa-trash"></i>&nbsp;删除</a>'+
+                                //'<a href="javascript:void(0)" onclick="deleteFileFromAliyun(this,\''+realPath+'/a/sys/workattachment/deleteFileFromAliyun?url='+data.url+'&id='+data.id+'&type=2\',\''+addFile+'\',\''+divId+'\')" class="op-btn op-btn-delete" ><i class="fa fa-trash"></i>&nbsp;删除</a>'+
+                                '<a href="javascript:void(0)" onclick="deleteFileFromAliyun(this,\''+realPath+'/sys/workattachment/deleteFileFromAliyun?url='+data.url+'&id='+data.id+'&type=2\',\''+addFile+'\',\''+divId+'\')" class="op-btn op-btn-delete" ><i class="fa fa-trash"></i>&nbsp;删除</a>'+
                                 '</div>' +
                                 '</td>'+
                                 '</tr>';