Bladeren bron

资源管理保存协议路径

xiatian 5 jaren geleden
bovenliggende
commit
771b66a6b9

+ 1 - 1
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/ResourceController.java

@@ -100,7 +100,7 @@ public class ResourceController extends ControllerSupport {
 			BeanUtils.copyProperties(next, bean);
 //			bean.setFileUrl(upyunFileUrl + bean.getFilePath());
 			//通用存储
-			bean.setFileUrl(FileStorageUtil.realPath(bean.getFilePath()));
+			bean.setFileUrl(FileStorageUtil.realPath(bean.getFileTreatyPath()));
 			resourceDomainList.add(bean);
 		}
 		PageInfo<ResourceDomain> ret = new PageInfo<ResourceDomain>();

+ 12 - 0
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/bean/ResourceDomain.java

@@ -25,6 +25,8 @@ public class ResourceDomain implements JsonSerializable {
 	private Long parentId;
 
 	private Date creationTime;
+	
+	private String fileTreatyPath;
 
 	public Long getId() {
 		return id;
@@ -98,4 +100,14 @@ public class ResourceDomain implements JsonSerializable {
 		this.creationTime = creationTime;
 	}
 
+    
+    public String getFileTreatyPath() {
+        return fileTreatyPath;
+    }
+
+    
+    public void setFileTreatyPath(String fileTreatyPath) {
+        this.fileTreatyPath = fileTreatyPath;
+    }
+
 }

+ 72 - 60
examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/entity/ResourceEntity.java

@@ -12,87 +12,99 @@ import cn.com.qmth.examcloud.web.jpa.JpaEntity;
 
 @Entity
 @Table(name = "EC_B_RESOURCE", indexes = {
-		@Index(name = "IDX_B_RESOURCE_000001", columnList = "rootOrgId,parentId", unique = false),
-		@Index(name = "IDX_B_RESOURCE_000002", columnList = "rootOrgId,filePath", unique = true)})
+        @Index(name = "IDX_B_RESOURCE_000001", columnList = "rootOrgId,parentId", unique = false),
+        @Index(name = "IDX_B_RESOURCE_000002", columnList = "rootOrgId,filePath", unique = true) })
 public class ResourceEntity extends JpaEntity {
-	private static final long serialVersionUID = 4326176782077577894L;
 
-	@Id
-	@GeneratedValue(strategy = GenerationType.IDENTITY)
-	private Long id;
+    private static final long serialVersionUID = 4326176782077577894L;
 
-	@Column(nullable = false)
-	private Long rootOrgId;
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    private Long id;
 
-	@Column(nullable = false)
-	private String name;
+    @Column(nullable = false)
+    private Long rootOrgId;
 
-	@Column(nullable = false)
-	private Boolean isFile;
+    @Column(nullable = false)
+    private String name;
 
-	@Column(nullable = true)
-	private String suffix;
+    @Column(nullable = false)
+    private Boolean isFile;
 
-	@Column(nullable = false)
-	private String filePath;
+    @Column(nullable = true)
+    private String suffix;
 
-	@Column(nullable = true)
-	private Long parentId;
+    @Column(nullable = false)
+    private String filePath;
 
-	public Long getId() {
-		return id;
-	}
+    @Column(nullable = true)
+    private Long parentId;
 
-	public void setId(Long id) {
-		this.id = id;
-	}
+    @Column(nullable = true)
+    private String fileTreatyPath;
 
-	public Long getRootOrgId() {
-		return rootOrgId;
-	}
+    public Long getId() {
+        return id;
+    }
 
-	public void setRootOrgId(Long rootOrgId) {
-		this.rootOrgId = rootOrgId;
-	}
+    public void setId(Long id) {
+        this.id = id;
+    }
 
-	public String getName() {
-		return name;
-	}
+    public Long getRootOrgId() {
+        return rootOrgId;
+    }
 
-	public void setName(String name) {
-		this.name = name;
-	}
+    public void setRootOrgId(Long rootOrgId) {
+        this.rootOrgId = rootOrgId;
+    }
 
-	public Boolean getIsFile() {
-		return isFile;
-	}
+    public String getName() {
+        return name;
+    }
 
-	public void setIsFile(Boolean isFile) {
-		this.isFile = isFile;
-	}
+    public void setName(String name) {
+        this.name = name;
+    }
 
-	public String getSuffix() {
-		return suffix;
-	}
+    public Boolean getIsFile() {
+        return isFile;
+    }
 
-	public void setSuffix(String suffix) {
-		this.suffix = suffix;
-	}
+    public void setIsFile(Boolean isFile) {
+        this.isFile = isFile;
+    }
 
-	public String getFilePath() {
-		return filePath;
-	}
+    public String getSuffix() {
+        return suffix;
+    }
 
-	public void setFilePath(String filePath) {
-		this.filePath = filePath;
-	}
+    public void setSuffix(String suffix) {
+        this.suffix = suffix;
+    }
 
-	public Long getParentId() {
-		return parentId;
-	}
+    public String getFilePath() {
+        return filePath;
+    }
 
-	public void setParentId(Long parentId) {
-		this.parentId = parentId;
-	}
+    public void setFilePath(String filePath) {
+        this.filePath = filePath;
+    }
+
+    public Long getParentId() {
+        return parentId;
+    }
+
+    public void setParentId(Long parentId) {
+        this.parentId = parentId;
+    }
+    
+    public String getFileTreatyPath() {
+        return fileTreatyPath;
+    }
+    
+    public void setFileTreatyPath(String fileTreatyPath) {
+        this.fileTreatyPath = fileTreatyPath;
+    }
 
 }

+ 81 - 92
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/ResourceServiceImpl.java

@@ -17,100 +17,89 @@ import cn.com.qmth.examcloud.core.basic.service.ResourceService;
 import cn.com.qmth.examcloud.core.basic.service.bean.ResourceInfo;
 import cn.com.qmth.examcloud.support.filestorage.FileStorageUtil;
 import cn.com.qmth.examcloud.web.filestorage.FileStoragePathEnvInfo;
+import cn.com.qmth.examcloud.web.filestorage.YunPathInfo;
 
 @Service
 public class ResourceServiceImpl implements ResourceService {
 
-	private static final String FILE_ROOT_PATH = "/resource";
-
-	private static final String FILE_PATH_SEPARATE = "/";
-
-	@Autowired
-	ResourceRepo resourceRepo;
-
-//	@Autowired
-//	UpyunCloudService upyunCloudService;
-
-	@Override
-	public void addDir(ResourceInfo info) {
-
-		ResourceEntity e = new ResourceEntity();
-		e.setName(info.getName());
-		e.setRootOrgId(info.getRootOrgId());
-		e.setIsFile(false);
-		if (info.getParentId() == null) {
-			e.setParentId(null);
-			e.setFilePath(FILE_ROOT_PATH + FILE_PATH_SEPARATE + info.getRootOrgId()
-					+ FILE_PATH_SEPARATE + info.getName());
-		} else {
-			e.setParentId(info.getParentId());
-			Optional<ResourceEntity> op = resourceRepo.findById(info.getParentId());
-			if (op.isPresent()) {
-				ResourceEntity pe = op.get();
-				e.setFilePath(pe.getFilePath() + FILE_PATH_SEPARATE + info.getName());
-			} else {
-				throw new StatusException("100000", "上级目录不存在");
-			}
-		}
-		resourceRepo.saveAndFlush(e);
-	}
-
-	@Override
-	public void addFile(Long rootOrgId, Long parentId, MultipartFile dataFile) {
-
-		ResourceEntity e = new ResourceEntity();
-		String fileName = dataFile.getOriginalFilename();
-		e.setName(fileName);
-		e.setRootOrgId(rootOrgId);
-		e.setIsFile(true);
-		String suffix = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length());
-		e.setSuffix(suffix);
-		if (parentId == null) {
-			e.setParentId(null);
-			e.setFilePath(FILE_ROOT_PATH + FILE_PATH_SEPARATE + rootOrgId + FILE_PATH_SEPARATE
-					+ fileName);
-		} else {
-			e.setParentId(parentId);
-			Optional<ResourceEntity> op = resourceRepo.findById(parentId);
-			if (op.isPresent()) {
-				ResourceEntity pe = op.get();
-				e.setFilePath(pe.getFilePath() + FILE_PATH_SEPARATE + fileName);
-			} else {
-				throw new StatusException("100020", "上级目录不存在");
-			}
-		}
-		ResourceEntity olde = resourceRepo.findByRootOrgIdAndFilePath(rootOrgId, e.getFilePath());
-		if (olde != null) {
-			olde.setUpdateTime(new Date());
-			resourceRepo.save(olde);
-		} else {
-			resourceRepo.save(e);
-		}
-		CommonsMultipartFile cf = (CommonsMultipartFile) dataFile;
-		DiskFileItem fi = (DiskFileItem) cf.getFileItem();
-
-		File f = fi.getStoreLocation();
-//		PutFileReq req = new PutFileReq();
-//		List<FormFilePart> formFilePartList = new ArrayList<FormFilePart>();
-
-//		FormFilePart part = new FormFilePart("file", fileName, f);
-//		formFilePartList.add(part);
-//
-//		req.setFormFilePartList(formFilePartList);
-//		req.setSiteId("resource");
-//		req.setRootOrgId(rootOrgId);
-//		String relativePath = e.getFilePath().replaceFirst(FILE_ROOT_PATH, "")
-//				.replaceFirst(FILE_PATH_SEPARATE, "");
-//		req.setRelativePath(relativePath);
-//		upyunCloudService.putFile(req);
-		
-		//通用存储
-		FileStoragePathEnvInfo env=new FileStoragePathEnvInfo();
-		env.setRootOrgId(rootOrgId.toString());
-		String relativePath = e.getFilePath().replaceFirst(FILE_ROOT_PATH, "")
-				.replaceFirst(FILE_PATH_SEPARATE, "");
-		env.setRelativePath(relativePath);
-		FileStorageUtil.saveFile("resource", env, f,null);
-		
-	}
+    private static final String FILE_ROOT_PATH = "/resource";
+
+    private static final String FILE_PATH_SEPARATE = "/";
+
+    @Autowired
+    ResourceRepo resourceRepo;
+
+    // @Autowired
+    // UpyunCloudService upyunCloudService;
+
+    @Override
+    public void addDir(ResourceInfo info) {
+
+        ResourceEntity e = new ResourceEntity();
+        e.setName(info.getName());
+        e.setRootOrgId(info.getRootOrgId());
+        e.setIsFile(false);
+        if (info.getParentId() == null) {
+            e.setParentId(null);
+            e.setFilePath(
+                    FILE_ROOT_PATH + FILE_PATH_SEPARATE + info.getRootOrgId() + FILE_PATH_SEPARATE + info.getName());
+        } else {
+            e.setParentId(info.getParentId());
+            Optional<ResourceEntity> op = resourceRepo.findById(info.getParentId());
+            if (op.isPresent()) {
+                ResourceEntity pe = op.get();
+                e.setFilePath(pe.getFilePath() + FILE_PATH_SEPARATE + info.getName());
+            } else {
+                throw new StatusException("100000", "上级目录不存在");
+            }
+        }
+        resourceRepo.saveAndFlush(e);
+    }
+
+    @Override
+    public void addFile(Long rootOrgId, Long parentId, MultipartFile dataFile) {
+
+        ResourceEntity e = new ResourceEntity();
+        String fileName = dataFile.getOriginalFilename();
+        e.setName(fileName);
+        e.setRootOrgId(rootOrgId);
+        e.setIsFile(true);
+        String suffix = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length());
+        e.setSuffix(suffix);
+
+
+        if (parentId == null) {
+            e.setParentId(null);
+            e.setFilePath(FILE_ROOT_PATH + FILE_PATH_SEPARATE + rootOrgId + FILE_PATH_SEPARATE + fileName);
+        } else {
+            e.setParentId(parentId);
+            Optional<ResourceEntity> op = resourceRepo.findById(parentId);
+            if (op.isPresent()) {
+                ResourceEntity pe = op.get();
+                e.setFilePath(pe.getFilePath() + FILE_PATH_SEPARATE + fileName);
+            } else {
+                throw new StatusException("100020", "上级目录不存在");
+            }
+        }
+        
+        CommonsMultipartFile cf = (CommonsMultipartFile) dataFile;
+        DiskFileItem fi = (DiskFileItem) cf.getFileItem();
+
+        File f = fi.getStoreLocation();
+        // 通用存储
+        FileStoragePathEnvInfo env = new FileStoragePathEnvInfo();
+        env.setRootOrgId(rootOrgId.toString());
+        env.setRelativePath(e.getFilePath());
+        YunPathInfo pi=FileStorageUtil.saveFile("resource", env, f, null);
+        e.setFileTreatyPath(pi.getRelativePath());
+        
+        ResourceEntity olde = resourceRepo.findByRootOrgIdAndFilePath(rootOrgId, e.getFilePath());
+        if (olde != null) {
+            olde.setUpdateTime(new Date());
+            resourceRepo.save(olde);
+        } else {
+            resourceRepo.save(e);
+        }
+
+    }
 }

+ 1 - 1
examcloud-core-basic-starter/src/main/resources/aliyun.xml

@@ -6,7 +6,7 @@
 		<name>资源</name>
 		<aliyunId>1</aliyunId>
 		<maxSize>50M</maxSize>
-		<path>/resource/${relativePath}</path>
+		<path>/${relativePath}</path>
 	</site>
 	<site>
 		<id>orgLogo</id>

+ 1 - 1
examcloud-core-basic-starter/src/main/resources/upyun.xml

@@ -6,7 +6,7 @@
 		<name>资源</name>
 		<upyunId>1</upyunId>
 		<maxSize>50M</maxSize>
-		<path>/resource/${relativePath}</path>
+		<path>/${relativePath}</path>
 	</site>
 	<site>
 		<id>orgLogo</id>