|
@@ -0,0 +1,128 @@
|
|
|
+package com.fdkankan.fusion.service.impl;
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.fdkankan.common.response.PageInfo;
|
|
|
+import com.fdkankan.common.util.CreateObjUtil;
|
|
|
+import com.fdkankan.common.util.JwtUtil;
|
|
|
+import com.fdkankan.fusion.common.FilePath;
|
|
|
+import com.fdkankan.fusion.common.ResultCode;
|
|
|
+import com.fdkankan.fusion.common.util.OBJToGLBUtil;
|
|
|
+import com.fdkankan.fusion.entity.CaseNumEntity;
|
|
|
+import com.fdkankan.fusion.entity.FusionNum;
|
|
|
+import com.fdkankan.fusion.entity.Model;
|
|
|
+import com.fdkankan.fusion.exception.BusinessException;
|
|
|
+import com.fdkankan.fusion.mapper.IModelMapper;
|
|
|
+import com.fdkankan.fusion.request.ModelPram;
|
|
|
+import com.fdkankan.fusion.request.ScenePram;
|
|
|
+import com.fdkankan.fusion.service.ICaseNumService;
|
|
|
+import com.fdkankan.fusion.service.IFusionNumService;
|
|
|
+import com.fdkankan.fusion.service.IModelService;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fdkankan.fyun.oss.UploadToOssUtil;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.tools.zip.ZipFile;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author
|
|
|
+ * @since 2022-08-03
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class ModelServiceImpl extends ServiceImpl<IModelMapper, Model> implements IModelService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ UploadToOssUtil uploadToOssUtil;
|
|
|
+ @Autowired
|
|
|
+ ICaseNumService caseNumService;
|
|
|
+ @Autowired
|
|
|
+ IFusionNumService fusionNumService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void uploadObj(MultipartFile file, String username) {
|
|
|
+ if(file.isEmpty()){
|
|
|
+ throw new BusinessException(ResultCode.UPLOAD_FILE_NO_EXIST);
|
|
|
+ }
|
|
|
+ if(file.getSize()>10 * 1024 * 1024 * 100){
|
|
|
+ System.out.println(file.getSize());
|
|
|
+ throw new BusinessException(ResultCode.UPLOAD_FILE_TO_LONG);
|
|
|
+ }
|
|
|
+ //获取文件名
|
|
|
+ String fileName = file.getOriginalFilename();
|
|
|
+ if(StringUtils.isEmpty(fileName)){
|
|
|
+ throw new BusinessException(ResultCode.UPLOAD_FILE_NO_EXIST);
|
|
|
+ }
|
|
|
+ if(fileName.toLowerCase().contains("zip") || fileName.toLowerCase().contains("rar")){
|
|
|
+ throw new BusinessException(ResultCode.UPLOAD_FILE_TYPE_ERROR);
|
|
|
+ }
|
|
|
+ //获取文件后缀名
|
|
|
+ String modelName = fileName.substring(0,fileName.lastIndexOf("."));
|
|
|
+
|
|
|
+ Model model = new Model();
|
|
|
+ model.setModelTitle(modelName);
|
|
|
+ model.setModelDateType("obj");
|
|
|
+ model.setModelSize(file.getSize());
|
|
|
+ model.setUserName(username);
|
|
|
+ this.save(model);
|
|
|
+ Integer createStatus = -1;
|
|
|
+ try {
|
|
|
+ String objPath = FilePath.OBJ_PATH +"/" + model.getModelId();
|
|
|
+ String glbPath = FilePath.GLB_PATH +"/" + model.getModelId();
|
|
|
+ String glbOssPath = FilePath.GLB_OSS_PATH +"/" + model.getModelId();
|
|
|
+ model.setModelObjUrl(objPath);
|
|
|
+ model.setModelGlbUrl(glbPath);
|
|
|
+
|
|
|
+ File newObjFile = new File(objPath +"/" + fileName);
|
|
|
+ if(!newObjFile.getParentFile().exists()){
|
|
|
+ newObjFile.mkdirs();
|
|
|
+ }
|
|
|
+ file.transferTo(newObjFile);
|
|
|
+ if(fileName.toLowerCase().contains("zip")){
|
|
|
+ CreateObjUtil.unZip(newObjFile.getPath(),objPath);
|
|
|
+ }
|
|
|
+ if(fileName.toLowerCase().contains("rar")){
|
|
|
+ CreateObjUtil.unRar(newObjFile.getPath(),objPath);
|
|
|
+ }
|
|
|
+ OBJToGLBUtil.checkObj(objPath);
|
|
|
+
|
|
|
+ OBJToGLBUtil.objToGlb(objPath,glbPath);
|
|
|
+ uploadToOssUtil.upload(glbPath,glbOssPath);
|
|
|
+ createStatus = 1; //上传成功
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }finally {
|
|
|
+ model.setCreateStatus(createStatus);
|
|
|
+ this.updateById(model);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageInfo pageList(ModelPram param, String token) {
|
|
|
+ String username = JwtUtil.getUsername(token);
|
|
|
+ LambdaQueryWrapper<Model> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(Model::getUserName,username);
|
|
|
+ if(StringUtils.isEmpty(param.getModelTitle())){
|
|
|
+ wrapper.like(Model::getModelTitle,param.getModelTitle());
|
|
|
+ }
|
|
|
+ wrapper.orderByDesc(Model::getCreateTime);
|
|
|
+ Page<Model> page = this.page(new Page<>(param.getPageNum(),param.getPageSize()),wrapper);
|
|
|
+ return PageInfo.PageInfo(page);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void delete(Integer modelId) {
|
|
|
+ List<CaseNumEntity> caseNumEntityList = caseNumService.getByNum(modelId.toString());
|
|
|
+ List<FusionNum> fusionNumList = fusionNumService.getByNum(modelId.toString());
|
|
|
+ }
|
|
|
+}
|