123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- 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.beans.factory.annotation.Value;
- 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;
- @Value("${local.obj_path}")
- private String OBJ_PATH;
- @Value("${local.glb_path}")
- private String GLB_PATH;
- @Value("${upload.query-path}")
- private String queryPath;
- @Override
- public void uploadObj(MultipartFile file, String username) throws Exception {
- 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);
- try {
- String objPath = String.format(OBJ_PATH , "modelId_"+model.getModelId());
- String glbPath = String.format(GLB_PATH , "modelId_"+model.getModelId());
- String glbOssPath = String.format(FilePath.GLB_OSS_PATH, model.getModelId());
- model.setModelObjUrl(objPath);
- model.setModelGlbUrl(queryPath +"/"+glbPath + "/"+modelName +"/mesh.glb");
- 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.objToGlb(objPath+"/"+modelName,glbPath+"/"+modelName +"/mesh.glb");
- uploadToOssUtil.upload(glbPath,glbOssPath);
- model.setCreateStatus(1); //上传成功
- this.updateById(model);
- }catch (Exception e){
- model.setCreateStatus(-1);
- this.updateById(model);
- e.printStackTrace();
- throw e;
- }
- }
- @Override
- public PageInfo pageList(ModelPram param, String token) {
- String username = JwtUtil.getUsername(token);
- LambdaQueryWrapper<Model> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(Model::getUserName,username);
- wrapper.eq(Model::getType,3);
- if(StringUtils.isNotBlank(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());
- if(caseNumEntityList.size() >0 || fusionNumList.size() >0){
- throw new BusinessException(ResultCode.CASE_USE);
- }
- this.removeById(modelId);
- }
- @Override
- public List<Model> getListByModeId(List<String> numList) {
- LambdaQueryWrapper<Model> wrapper = new LambdaQueryWrapper<>();
- wrapper.in(Model::getModelId,numList);
- return this.list(wrapper);
- }
- }
|