| | |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | |
| | | import com.obs.services.ObsClient; |
| | | import com.obs.services.model.HttpMethodEnum; |
| | | import com.obs.services.model.TemporarySignatureRequest; |
| | | import com.obs.services.model.TemporarySignatureResponse; |
| | | import com.qxueyou.scc.config.HweiOBSConfig; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.ApplicationContext; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | |
| | | import com.qxueyou.scc.teach.subject.service.impl.SubjectLectureService; |
| | | |
| | | /** |
| | | * 资源服务 |
| | | * 资源服务 |
| | | * |
| | | * @author 夏德虎 |
| | | * @author 夏德虎 |
| | | */ |
| | | @Service |
| | | public class ResService extends CommonAppService implements IResService { |
| | |
| | | private ApplicationContext appContext; |
| | | |
| | | @Autowired |
| | | private HweiOBSConfig hweiOBSConfig; |
| | | |
| | | @Autowired |
| | | private IClassLectureService classLectureService; |
| | | |
| | | /** |
| | | * 各类型资源服务实现 |
| | | * 各类型资源服务实现 |
| | | */ |
| | | private Map<String, IResItemService> resItemServiceMap = new HashMap<String, IResItemService>(6); |
| | | |
| | |
| | | |
| | | Res res = read(Res.class, resId); |
| | | |
| | | resItemServiceMap.get(res.getType()).update(res.getItemDestId(), name); |
| | | // resItemServiceMap.get(res.getType()).update(res.getItemDestId(), name); |
| | | |
| | | TraceUtils.setUpdateTrace(res); |
| | | res.setName(name); |
| | |
| | | } |
| | | |
| | | /** |
| | | * @param resId 资源id |
| | | * @param resId 资源id |
| | | * @return |
| | | */ |
| | | private Result delete(String resId) { |
| | |
| | | public Result readAccessPath(String resId, String attribute) { |
| | | |
| | | Res res = read(Res.class, resId); |
| | | |
| | | // Object path = Res.FILE_TYPE_VIDEO.equals(res.getType())? JSONObject.parse(resItemServiceMap.get(res.getType()).readAccessPath(res.getItemDestId(), attribute)):CollectionUtils.newObjectMap("path", resItemServiceMap.get(res.getType()).readAccessPath(res.getItemDestId(), attribute)); |
| | | Object path = Res.FILE_TYPE_VIDEO.equals(res.getType())? resItemServiceMap.get(res.getType()).readAccessPath(res.getItemDestId(), attribute):resItemServiceMap.get(res.getType()).readAccessPath(res.getItemDestId(), attribute); |
| | | if(Res.FILE_TYPE_DOC.equals(res.getType())) { |
| | | // if(Res.FILE_TYPE_DOC.equals(res.getType())) { |
| | | // return new Result(true, "success", |
| | | // CollectionUtils.newObjectMap("path", path, "name", res.getName(), "coverPageUrl", res.getCoverPageUrl(), "size", |
| | | // this.classLectureService.readDocPageCount(res.getItemDestId())));//文件的页数 |
| | | // }else { |
| | | // URL有效期,3600秒 |
| | | long expireSeconds = 3600L; |
| | | TemporarySignatureRequest request = new TemporarySignatureRequest(HttpMethodEnum.GET, expireSeconds); |
| | | //设置桶名,一般都是写在配置里,这里直接赋值即可 |
| | | request.setBucketName(hweiOBSConfig.getBucketName()); |
| | | //这里相当于设置你上传到obs的文件路 |
| | | request.setObjectKey((String) path); |
| | | |
| | | ObsClient obsClient = new ObsClient(hweiOBSConfig.getAccessKey(),hweiOBSConfig.getSecurityKey(),hweiOBSConfig.getEndPoint()); |
| | | TemporarySignatureResponse temporarySignatureResponse=obsClient.createTemporarySignature(request); |
| | | return new Result(true, "success", |
| | | CollectionUtils.newObjectMap("path", path, "name", res.getName(), "coverPageUrl", res.getCoverPageUrl(), "size", |
| | | this.classLectureService.readDocPageCount(res.getItemDestId())));//文件的页数 |
| | | }else { |
| | | return new Result(true, "success", |
| | | CollectionUtils.newObjectMap("path", path, "name", res.getName(), "coverPageUrl", res.getCoverPageUrl(), "size", 0)); |
| | | } |
| | | CollectionUtils.newObjectMap("path", temporarySignatureResponse.getSignedUrl(), "name", res.getName(), "coverPageUrl", res.getCoverPageUrl(), "size", 0)); |
| | | // } |
| | | |
| | | } |
| | | |
| | |
| | | public Result deleteDir(String[] dirIds) { |
| | | |
| | | for (String dirId : dirIds) { |
| | | deleteFile4Dir(dirId);// 删除对应的文件 |
| | | deleteFile4Dir(dirId);// 删除对应的文件 |
| | | deleteDir(dirId); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * 删除资源库文件夹对应删除文件 |
| | | * 删除资源库文件夹对应删除文件 |
| | | * |
| | | * @param dirId 文件夹id |
| | | * @param dirId 文件夹id |
| | | */ |
| | | @Override |
| | | public void deleteFile4Dir(String dirId) { |
| | |
| | | @Override |
| | | public ResDir doGetRootDir(String type, String ownerId) { |
| | | ResLib lib = getResLib(type, ownerId); |
| | | // 无资源库则初始化,并返回根节点 |
| | | // 无资源库则初始化,并返回根节点 |
| | | if (lib == null) { |
| | | Result result = initResLib(type, ownerId); |
| | | return read(ResDir.class, result.getDataT("rootDirId")); |
| | |
| | | |
| | | private List<ResDir> doGetChildDirsInner(String parentDirId, String type) { |
| | | |
| | | // 根节点的处理 |
| | | // 根节点的处理 |
| | | if (StringUtils.isEmpty(parentDirId)) { |
| | | ResLib lib = getResLib(type, ClientUtils.getUserId()); |
| | | |
| | | // 无资源库则初始化,并返回根节点 |
| | | // 无资源库则初始化,并返回根节点 |
| | | if (lib == null) { |
| | | Result result = initUserLib(); |
| | | return CollectionUtils.newList(ResDir.class, read(ResDir.class, result.getDataT("rootDirId"))); |
| | |
| | | |
| | | if (lib == null) { |
| | | |
| | | Result result = addDir(RES_DIR_ROOT, "根目录"); |
| | | Result result = addDir(RES_DIR_ROOT, "根目录"); |
| | | |
| | | lib = new ResLib(); |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * 定时器监控转码完成后设置同步res表的状态 |
| | | * 定时器监控转码完成后设置同步res表的状态 |
| | | */ |
| | | @Scheduled(cron = "0/2 * * * * ?") |
| | | public void doTimer() { |