|
@@ -5,7 +5,6 @@ import cn.rankin.common.utils.api.model.APIResult;
|
|
import cn.rankin.common.utils.api.page.Page;
|
|
import cn.rankin.common.utils.api.page.Page;
|
|
import cn.rankin.common.utils.constant.ResourceType;
|
|
import cn.rankin.common.utils.constant.ResourceType;
|
|
import cn.rankin.common.utils.dto.resource.ResourceSearchDTO;
|
|
import cn.rankin.common.utils.dto.resource.ResourceSearchDTO;
|
|
-import cn.rankin.common.utils.enums.BaseStatusEnum;
|
|
|
|
import cn.rankin.common.utils.util.DateUtil;
|
|
import cn.rankin.common.utils.util.DateUtil;
|
|
import cn.rankin.data.api.resource.dto.AudioImgDTO;
|
|
import cn.rankin.data.api.resource.dto.AudioImgDTO;
|
|
import cn.rankin.data.api.resource.entity.AudioImg;
|
|
import cn.rankin.data.api.resource.entity.AudioImg;
|
|
@@ -151,19 +150,40 @@ public class ResourceController {
|
|
return APIResult.ok();
|
|
return APIResult.ok();
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/* ------------ 有声读物 audioImg ---------------------start---------------------------------*/
|
|
/* ------------ 有声读物 audioImg ---------------------start---------------------------------*/
|
|
|
|
+ @RequestMapping(value = "/audioImg/batch", method = RequestMethod.GET)
|
|
|
|
+ public Map<String, Resource> getAudioImgBatch(@RequestParam("ids") List<String> ids) {
|
|
|
|
+ Map<String, Resource> audioImgMap= new HashMap<>();
|
|
|
|
+ List<AudioImg> audioImgs = audioImgService.findMixByIds(ids);
|
|
|
|
+ if(CollectionUtils.isEmpty(audioImgs)){
|
|
|
|
+ return audioImgMap;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ audioImgs.forEach(ai -> {
|
|
|
|
+ Resource resource = resourceService.audioImgToResource(ai);
|
|
|
|
+ audioImgMap.put(ai.getId(),resource);
|
|
|
|
+
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ return audioImgMap;
|
|
|
|
+ }
|
|
|
|
+
|
|
@RequestMapping(value="/audioImg",method = RequestMethod.POST)
|
|
@RequestMapping(value="/audioImg",method = RequestMethod.POST)
|
|
public AudioImg createAudioImg(@RequestBody AudioImgDTO dto) {
|
|
public AudioImg createAudioImg(@RequestBody AudioImgDTO dto) {
|
|
if (audioImgService.exists(dto.getCode())) {
|
|
if (audioImgService.exists(dto.getCode())) {
|
|
|
|
+ log.error("audioImg code Is exist");
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
- Resource audio = toAudioResource(dto);
|
|
|
|
- Resource img = toImgResource(dto);
|
|
|
|
|
|
+ Resource a = dto.getAudio();
|
|
|
|
+ Resource i = dto.getImg();
|
|
|
|
+
|
|
|
|
+ //设置code name
|
|
|
|
+ setCodeName(a, dto);
|
|
|
|
+ setCodeName(i, dto);
|
|
|
|
|
|
- img = saveResource(img);
|
|
|
|
- audio = saveResource(audio);
|
|
|
|
|
|
+ Resource img = saveOrUpdateResource(i);
|
|
|
|
+ Resource audio = saveOrUpdateResource(a);
|
|
|
|
|
|
if(null != audio && null != img){
|
|
if(null != audio && null != img){
|
|
AudioImg ai = new AudioImg();
|
|
AudioImg ai = new AudioImg();
|
|
@@ -182,22 +202,26 @@ public class ResourceController {
|
|
|
|
|
|
return audioImg;
|
|
return audioImg;
|
|
}else{
|
|
}else{
|
|
|
|
+ log.error("create AudioImg is error,audio={},img={}",audio, img);
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@RequestMapping(value="/audioImg",method = RequestMethod.PUT)
|
|
@RequestMapping(value="/audioImg",method = RequestMethod.PUT)
|
|
public AudioImg updateAudioImg(@RequestBody AudioImgDTO dto) {
|
|
public AudioImg updateAudioImg(@RequestBody AudioImgDTO dto) {
|
|
|
|
+ if(StringUtils.isBlank(dto.getCode())){
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ Resource a = dto.getAudio();
|
|
|
|
+ Resource i = dto.getImg();
|
|
|
|
+ setCodeName(a, dto);
|
|
|
|
+ setCodeName(i, dto);
|
|
|
|
|
|
- Resource audio = toAudioResource(dto);
|
|
|
|
- Resource img = toImgResource(dto);
|
|
|
|
-
|
|
|
|
- img = saveResource(img);
|
|
|
|
- audio = saveResource(audio);
|
|
|
|
|
|
+ Resource img = saveOrUpdateResource(i);
|
|
|
|
+ Resource audio = saveOrUpdateResource(a);
|
|
|
|
|
|
if(null != audio && null != img){
|
|
if(null != audio && null != img){
|
|
AudioImg ai = audioImgService.get(dto.getId());
|
|
AudioImg ai = audioImgService.get(dto.getId());
|
|
-
|
|
|
|
ai.setStatus(dto.getStatus());
|
|
ai.setStatus(dto.getStatus());
|
|
ai.setName(dto.getName());
|
|
ai.setName(dto.getName());
|
|
ai.setCode(dto.getCode());
|
|
ai.setCode(dto.getCode());
|
|
@@ -215,96 +239,36 @@ public class ResourceController {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- @RequestMapping(value = "/audioImg/batch", method = RequestMethod.GET)
|
|
|
|
- public Map<String, Resource> getAudioImgBatch(@RequestParam("ids") List<String> ids) {
|
|
|
|
- Map<String, Resource> audioImgMap= new HashMap<>();
|
|
|
|
- List<AudioImg> audioImgs = audioImgService.findMixByIds(ids);
|
|
|
|
- if(CollectionUtils.isEmpty(audioImgs)){
|
|
|
|
- return audioImgMap;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- audioImgs.forEach(ai -> {
|
|
|
|
- Resource resource = resourceService.audioImgToResource(ai);
|
|
|
|
- audioImgMap.put(ai.getId(),resource);
|
|
|
|
-
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- return audioImgMap;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 有声读物 转 资源
|
|
|
|
- * @param ai
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- /*private Resource audioImgToResource(AudioImg ai) {
|
|
|
|
- String audioId = ai.getAudioId();
|
|
|
|
- Resource audio = resourceService.get(audioId);
|
|
|
|
- resourceService.initResourceUrl(audio);
|
|
|
|
- String imgId = ai.getImgId();
|
|
|
|
- Resource img = resourceService.get(imgId);
|
|
|
|
- resourceService.initResourceUrl(img);
|
|
|
|
-
|
|
|
|
- Resource resource = new Resource();
|
|
|
|
- //有声读物info
|
|
|
|
- resource.setType(ai.getType());
|
|
|
|
- resource.setId(ai.getId());
|
|
|
|
- resource.setCode(ai.getCode());
|
|
|
|
- resource.setName(ai.getName());
|
|
|
|
- resource.setStatus(ai.getStatus());
|
|
|
|
- resource.setGmtCreated(ai.getGmtCreated());
|
|
|
|
- resource.setGmtModified(ai.getGmtModified());
|
|
|
|
-
|
|
|
|
- //图片info
|
|
|
|
- resource.setImg(img);
|
|
|
|
- //音频info
|
|
|
|
- resource.setAudio(audio);
|
|
|
|
- return resource;
|
|
|
|
- }*/
|
|
|
|
-
|
|
|
|
- private Resource toAudioResource(AudioImgDTO dto) {
|
|
|
|
- Resource audio = new Resource();
|
|
|
|
- audio.setCode(dto.getCode()+"_"+ResourceType.AUDIO+DateUtil.getTimeStamp());
|
|
|
|
- audio.setName(dto.getName()+"_"+ResourceType.AUDIO+DateUtil.getTimeStamp());
|
|
|
|
- audio.setFormat(dto.getAudioFormat());
|
|
|
|
- audio.setPath(dto.getAudioPath());
|
|
|
|
- audio.setSize(dto.getAudioSize());
|
|
|
|
- audio.setStatus(BaseStatusEnum.NORMAL);
|
|
|
|
- audio.setType(ResourceType.AUDIO);
|
|
|
|
- audio.setQuality(dto.getAudioQuality());
|
|
|
|
- return audio;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private Resource toImgResource(AudioImgDTO dto) {
|
|
|
|
- Resource img = new Resource();
|
|
|
|
- img.setCode(dto.getCode()+"_"+ResourceType.IMG+DateUtil.getTimeStamp());
|
|
|
|
- img.setName(dto.getName()+"_"+ResourceType.IMG+DateUtil.getTimeStamp());
|
|
|
|
- img.setFormat(dto.getImgFormat());
|
|
|
|
- img.setPath(dto.getImgPath());
|
|
|
|
- img.setSize(dto.getImgSize());
|
|
|
|
- img.setQuality(dto.getImgQuality());
|
|
|
|
- img.setStatus(BaseStatusEnum.NORMAL);
|
|
|
|
- img.setType(ResourceType.IMG);
|
|
|
|
- return img;
|
|
|
|
|
|
+ private void setCodeName(Resource resource, AudioImgDTO dto) {
|
|
|
|
+ resource.setCode(dto.getCode()+"_"+ resource.getType() + DateUtil.getTimeStamp());
|
|
|
|
+ resource.setName(dto.getName()+"_"+ resource.getType() + DateUtil.getTimeStamp());
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 存储资源
|
|
|
|
|
|
+ * 更新/存储资源
|
|
* @param resource
|
|
* @param resource
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- private Resource saveResource(Resource resource) {
|
|
|
|
|
|
+ private Resource saveOrUpdateResource(Resource resource) {
|
|
|
|
|
|
if (StringUtils.isEmpty(resource.getCode()) || StringUtils.isEmpty(resource.getPath())) {
|
|
if (StringUtils.isEmpty(resource.getCode()) || StringUtils.isEmpty(resource.getPath())) {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
- if (resourceService.exists(resource.getCode())) {
|
|
|
|
- return null;
|
|
|
|
|
|
+ Resource result = null;
|
|
|
|
+ if(StringUtils.isBlank(resource.getId())){
|
|
|
|
+ if (resourceService.exists(resource.getCode())) {
|
|
|
|
+ log.error("resource code Is exist");
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ resource.setId(null);
|
|
|
|
+ //图片,音频类型 存本地
|
|
|
|
+ result = resourceService.save(resource);
|
|
|
|
+ }else{
|
|
|
|
+ //图片,音频类型 存本地
|
|
|
|
+ result = resourceService.updateResource(resource);
|
|
}
|
|
}
|
|
|
|
|
|
- //图片,音频类型 存本地
|
|
|
|
- Resource result = resourceService.save(resource);
|
|
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|