|
@@ -1,18 +1,38 @@
|
|
package cn.com.ctop.common.module.service.impl;
|
|
package cn.com.ctop.common.module.service.impl;
|
|
|
|
|
|
|
|
+import cn.com.ctop.common.module.entity.MaterialAscription;
|
|
import cn.com.ctop.common.module.entity.MaterialInfo;
|
|
import cn.com.ctop.common.module.entity.MaterialInfo;
|
|
|
|
+import cn.com.ctop.common.module.entity.MaterialParameter;
|
|
|
|
+import cn.com.ctop.common.module.entity.MaterialTag;
|
|
|
|
+import cn.com.ctop.common.module.mapper.MaterialAscriptionMapper;
|
|
import cn.com.ctop.common.module.mapper.MaterialInfoMapper;
|
|
import cn.com.ctop.common.module.mapper.MaterialInfoMapper;
|
|
|
|
+import cn.com.ctop.common.module.mapper.MaterialParameterMapper;
|
|
|
|
+import cn.com.ctop.common.module.mapper.MaterialTagMapper;
|
|
import cn.com.ctop.common.module.service.IMaterialInfoService;
|
|
import cn.com.ctop.common.module.service.IMaterialInfoService;
|
|
|
|
+import cn.com.ctop.common.module.utils.Check;
|
|
import cn.com.ctop.common.module.utils.ResultMapUtils;
|
|
import cn.com.ctop.common.module.utils.ResultMapUtils;
|
|
import cn.com.ctop.common.module.utils.StatusCode;
|
|
import cn.com.ctop.common.module.utils.StatusCode;
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import it.sauronsoftware.jave.Encoder;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.jeecg.common.util.LoadFileUtil;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.FileInputStream;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.math.RoundingMode;
|
|
|
|
+import java.nio.channels.FileChannel;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
|
+import java.util.concurrent.Executors;
|
|
import java.util.regex.Pattern;
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -22,8 +42,10 @@ import java.util.regex.Pattern;
|
|
* @version V1.0
|
|
* @version V1.0
|
|
* @date 2019-10-11
|
|
* @date 2019-10-11
|
|
*/
|
|
*/
|
|
|
|
+@Slf4j
|
|
@Service
|
|
@Service
|
|
public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, MaterialInfo> implements IMaterialInfoService {
|
|
public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, MaterialInfo> implements IMaterialInfoService {
|
|
|
|
+ static ExecutorService executorService = Executors.newFixedThreadPool(5);
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public MaterialInfo getMaterialInfoByCode(String code) {
|
|
public MaterialInfo getMaterialInfoByCode(String code) {
|
|
@@ -59,25 +81,148 @@ public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, Mat
|
|
Pattern p = Pattern.compile(reg);
|
|
Pattern p = Pattern.compile(reg);
|
|
System.out.println(p.matcher("https://ctop-media.oss-cn-beijing.aliyuncs.com/video/2019-10-30/ios%E6%8E%A8%E5%B9%BF%E8%A7%86%E9%A2%91-1572437289724.mp4").find());
|
|
System.out.println(p.matcher("https://ctop-media.oss-cn-beijing.aliyuncs.com/video/2019-10-30/ios%E6%8E%A8%E5%B9%BF%E8%A7%86%E9%A2%91-1572437289724.mp4").find());
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private MaterialAscriptionMapper materialAscriptionMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private MaterialTagMapper materialTagMapper;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
- public Map<String, Object> insert(String userId, String code, String url) throws IOException {
|
|
|
|
|
|
+ public Map<String, Object> insert(JSONObject jsonObject) {
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
- Boolean isVideo = imgLocation(url);
|
|
|
|
- MaterialInfo info = new MaterialInfo();
|
|
|
|
- info.setId(code);
|
|
|
|
- info.setCode(code);
|
|
|
|
- info.setUrl("https:" + url);
|
|
|
|
- info.setStatus(1);
|
|
|
|
- info.setUserId(userId);
|
|
|
|
- info.setCreateTime(new Date());
|
|
|
|
- info.setUpdateTime(new Date());
|
|
|
|
- if (isVideo) {
|
|
|
|
- info.setType("VIDEO");
|
|
|
|
- } else {
|
|
|
|
- info.setType("IMAGE");
|
|
|
|
|
|
+ try {
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ Boolean isVideo = imgLocation(jsonObject.getString("url"));
|
|
|
|
+ MaterialInfo info = new MaterialInfo();
|
|
|
|
+ info.setId(jsonObject.getString("code"));
|
|
|
|
+ info.setCode(jsonObject.getString("code"));
|
|
|
|
+ info.setWatermarkUrl("https:" + jsonObject.getString("watermarkUrl"));
|
|
|
|
+ info.setUrl("https:" + jsonObject.getString("url"));
|
|
|
|
+ info.setUserId(jsonObject.getString("userId"));
|
|
|
|
+ info.setProjectId(jsonObject.getLong("projectId"));
|
|
|
|
+ info.setWatermarkCode(jsonObject.getString("watermarkCode"));
|
|
|
|
+ info.setStatus(0);
|
|
|
|
+ info.setMaterialName(jsonObject.getString("materialName"));
|
|
|
|
+ info.setWatermarkMaterialName(jsonObject.getString("watermarkMaterialName"));
|
|
|
|
+ info.setMaterialDescribe(jsonObject.getString("describe"));
|
|
|
|
+ info.setCreateTime(new Date());
|
|
|
|
+ info.setUpdateTime(new Date());
|
|
|
|
+ if (isVideo) {
|
|
|
|
+ info.setType("VIDEO");
|
|
|
|
+ } else {
|
|
|
|
+ info.setType("IMAGE");
|
|
|
|
+ }
|
|
|
|
+ this.save(info);
|
|
|
|
+ Map<String, Object> deleteMap = new HashMap<>();
|
|
|
|
+ deleteMap.put("material_id", info.getId());
|
|
|
|
+
|
|
|
|
+ JSONObject ascription = jsonObject.getJSONObject("ascription");
|
|
|
|
+ if (!Check.isNull(ascription)) {
|
|
|
|
+ MaterialAscription materialAscription = new MaterialAscription();
|
|
|
|
+ materialAscription.setMaterialId(info.getId());
|
|
|
|
+ materialAscription.setClipId(ascription.getString("clipId")); // 剪辑人
|
|
|
|
+ materialAscription.setShotId(ascription.getString("shotId")); // 拍摄人id
|
|
|
|
+ materialAscription.setPlaneId(ascription.getString("planId")); // 策划id
|
|
|
|
+ materialAscription.setPlaneId(ascription.getString("planeId")); //平面id
|
|
|
|
+ materialAscriptionMapper.deleteByMap(deleteMap);
|
|
|
|
+ int i = materialAscriptionMapper.insert(materialAscription);
|
|
|
|
+ if (i > 0) {
|
|
|
|
+ log.info("素材归属信息入库完成,MaterialId:{}", info.getId());
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ JSONArray tag = jsonObject.getJSONArray("tag");
|
|
|
|
+ if (!Check.isNull(tag)) {
|
|
|
|
+ materialTagMapper.deleteByMap(deleteMap);
|
|
|
|
+ for (int i = 0; i < tag.size(); i++) {
|
|
|
|
+ String tagStr = tag.getString(i);
|
|
|
|
+ if (!Check.isNull(tagStr)) {
|
|
|
|
+ MaterialTag materialTag = new MaterialTag();
|
|
|
|
+ materialTag.setMaterialId(info.getId());
|
|
|
|
+ materialTag.setTag(tagStr);
|
|
|
|
+ materialTagMapper.insert(materialTag);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ getFile(info);
|
|
|
|
+ ResultMapUtils.setResultMap(resultMap, StatusCode.COMMON_SUCCESS.getCode());
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ ResultMapUtils.setResultMap(resultMap, StatusCode.MATERIAL_UPLOAD_FAIL.getCode());
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+
|
|
}
|
|
}
|
|
- this.save(info);
|
|
|
|
- ResultMapUtils.setResultMap(resultMap, StatusCode.COMMON_SUCCESS.getCode());
|
|
|
|
|
|
+
|
|
|
|
+
|
|
return resultMap;
|
|
return resultMap;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private MaterialParameterMapper materialParameterMapper;
|
|
|
|
+
|
|
|
|
+ public void getFile(MaterialInfo materialInfo) {
|
|
|
|
+ executorService.submit(new Runnable() {
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ try {
|
|
|
|
+ this.loadFile(materialInfo);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void loadFile(MaterialInfo materialInfo) throws IOException {
|
|
|
|
+ if (!Check.isNull(materialInfo)) {
|
|
|
|
+ String url = materialInfo.getUrl();
|
|
|
|
+ long l = System.currentTimeMillis();
|
|
|
|
+ String localUrl = LoadFileUtil.downLoadFromUrl(url, "D:\\tets1\\video");
|
|
|
|
+ File file = new File(localUrl);
|
|
|
|
+
|
|
|
|
+ it.sauronsoftware.jave.Encoder encoder = new Encoder();
|
|
|
|
+ try {
|
|
|
|
+ it.sauronsoftware.jave.MultimediaInfo m = encoder.getInfo(file);
|
|
|
|
+ long duration = m.getDuration();
|
|
|
|
+ long secondDuration = duration / 1000;
|
|
|
|
+ MaterialParameter materialParameter = new MaterialParameter();
|
|
|
|
+ materialParameter.setMaterialId(materialInfo.getId());
|
|
|
|
+ materialParameter.setSecond(secondDuration); // 视频秒数
|
|
|
|
+ materialParameter.setFormat(m.getFormat()); // 视频格式
|
|
|
|
+ materialParameter.setWidth(String.valueOf(m.getVideo().getSize().getWidth()));// 视频宽
|
|
|
|
+ materialParameter.setHeight(String.valueOf(m.getVideo().getSize().getHeight()));// 视频高
|
|
|
|
+
|
|
|
|
+ FileInputStream fis = new FileInputStream(file);
|
|
|
|
+ FileChannel fc = fis.getChannel();
|
|
|
|
+ BigDecimal fileSize = new BigDecimal(fc.size());
|
|
|
|
+ String size = fileSize.divide(new BigDecimal(1048576), 2, RoundingMode.HALF_UP) + "MB";
|
|
|
|
+ materialParameter.setSize(size);
|
|
|
|
+
|
|
|
|
+ Map<String, Object> deleteMap = new HashMap<>();
|
|
|
|
+ deleteMap.put("material_id", materialInfo.getId());
|
|
|
|
+ materialParameterMapper.deleteByMap(deleteMap);
|
|
|
|
+
|
|
|
|
+ int insert = materialParameterMapper.insert(materialParameter);
|
|
|
|
+ if (insert > 0) {
|
|
|
|
+ log.info("素材基本信息入库完成,用时:{} s", (System.currentTimeMillis() - l) / 1000);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ } finally {
|
|
|
|
+ file.delete();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ executorService.shutdown();
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|