CaseNumServiceImpl.java 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. package com.fdkankan.fusion.service.impl;
  2. import cn.hutool.core.io.FileUtil;
  3. import com.alibaba.fastjson.JSONArray;
  4. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  5. import com.fdkankan.fusion.common.FilePath;
  6. import com.fdkankan.fusion.common.ResultCode;
  7. import com.fdkankan.fusion.common.util.*;
  8. import com.fdkankan.fusion.entity.CaseNumEntity;
  9. import com.fdkankan.fusion.entity.Model;
  10. import com.fdkankan.fusion.exception.BusinessException;
  11. import com.fdkankan.fusion.httpClient.client.FdKKClient;
  12. import com.fdkankan.fusion.mapper.ICaseNumMapper;
  13. import com.fdkankan.fusion.request.SceneNumParam;
  14. import com.fdkankan.fusion.service.*;
  15. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  16. import org.apache.commons.lang3.StringUtils;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.beans.factory.annotation.Value;
  19. import org.springframework.stereotype.Service;
  20. import javax.annotation.Resource;
  21. import java.io.File;
  22. import java.sql.BatchUpdateException;
  23. import java.util.*;
  24. import java.util.stream.Collectors;
  25. /**
  26. * <p>
  27. * 服务实现类
  28. * </p>
  29. *
  30. * @author
  31. * @since 2022-07-27
  32. */
  33. @Service
  34. public class CaseNumServiceImpl extends ServiceImpl<ICaseNumMapper, CaseNumEntity> implements ICaseNumService {
  35. @Autowired
  36. UploadToOssUtil uploadToOssUtil;
  37. @Value("${upload.query-path}")
  38. private String queryPath;
  39. @Value("${spring.profiles.active}")
  40. private String environment;
  41. @Autowired
  42. IModelService modelService;
  43. @Autowired
  44. IFusionNumService fusionNumService;
  45. @Autowired
  46. ICaseViewService caseViewService;
  47. @Autowired
  48. IFusionMeterService fusionMeterService;
  49. @Autowired
  50. IFusionGuidePathService fusionGuidePathService;
  51. @Autowired
  52. ICaseTagService caseTagService;
  53. @Autowired
  54. ICaseTagPointService caseTagPointService;
  55. @Override
  56. public List<CaseNumEntity> getByCaseId(Integer caseId) {
  57. LambdaQueryWrapper<CaseNumEntity> wrapper = new LambdaQueryWrapper<>();
  58. wrapper.eq(CaseNumEntity::getCaseId,caseId);
  59. return this.list(wrapper);
  60. }
  61. @Override
  62. public void addBatch(Integer caseId, List<SceneNumParam> sceneNumParam) {
  63. List<String> addNumList = this.updateByNumList(caseId, sceneNumParam);
  64. if(addNumList == null || addNumList.size()<=0){
  65. return;
  66. }
  67. List<CaseNumEntity> newCaseNums = new ArrayList<>();
  68. List<Model> modelList = new ArrayList<>();
  69. for (SceneNumParam param : sceneNumParam) {
  70. List<String> numList = param.getNumList();
  71. HashSet<String> setNum = new HashSet<>(numList);
  72. for (String num : setNum) {
  73. if(!addNumList.contains(num)){
  74. continue;
  75. }
  76. CaseNumEntity caseNumEntity = new CaseNumEntity();
  77. caseNumEntity.setCaseId(caseId);
  78. caseNumEntity.setNumType(param.getType());
  79. caseNumEntity.setNum(num);
  80. newCaseNums.add(caseNumEntity);
  81. if(param.getType() == 3){ //用户上传三维模型跳过
  82. continue;
  83. }
  84. Model model = modelService.getIsNullNewByNum(num,param.getType());
  85. model.setModelDateType("obj");
  86. model.setType(param.getType());
  87. model.setModelType("pointcloud"); //深时点云类型
  88. if(param.getType() == 0 || param.getType() == 1 || param.getType() == 4 || param.getType() == 6){ //看看,看见
  89. model.setModelObjUrl(String.format(FilePath.OBJ_LOCAL_PATH,environment ,num) +"/mesh.obj");
  90. model.setModelGlbUrl(getGlbUrl(param.getType(),num,model));
  91. model.setModelType("glb");
  92. }
  93. model.setNum(num);
  94. model.setCreateStatus(1);
  95. modelList.add(model);
  96. }
  97. }
  98. if(newCaseNums.size() >0){
  99. this.saveBatch(newCaseNums);
  100. }
  101. if(modelList.size() >0){
  102. modelService.saveOrUpdateBatch(modelList);
  103. }
  104. }
  105. private String getGlbUrl(Integer type, String num,Model model) {
  106. if(type == 0 || type == 1 || type == 4 || type == 6){ //看看,看见
  107. String objPath = String.format(FilePath.OBJ_LOCAL_PATH ,environment,num);
  108. // if(uploadToOssUtil.existKey(glbOssPath)){
  109. // return queryPath + "/"+glbOssPath;
  110. // }
  111. ShellUtil.yunDownload(String.format(FilePath.OBJ_OSS_PATH, num) ,objPath);
  112. List<String> localGlbPaths = new ArrayList<>();
  113. List<String> ossGlbPaths = new ArrayList<>();
  114. File localFile = new File(objPath);
  115. this.toGlB(localFile,localGlbPaths);
  116. if(localGlbPaths.size() >0){
  117. for (String localGlbPath : localGlbPaths) {
  118. String ossGlbPath = localGlbPath.replace(FilePath.LOCAL_BASE_PATH,"fusion/");
  119. uploadToOssUtil.uploadOss(localGlbPath,ossGlbPath);
  120. if(ossGlbPath.contains("lod_")){
  121. if(ossGlbPath.contains("lod_0")){
  122. ossGlbPaths.add(queryPath +ossGlbPath);
  123. }
  124. File file = new File(localGlbPath);
  125. if(file!=null){
  126. model.setModelSize(FileWriterUtil.setFileSize(file.length()));
  127. }
  128. continue;
  129. }
  130. File file = new File(localGlbPath);
  131. if(file!=null){
  132. model.setModelSize(FileWriterUtil.setFileSize(file.length()));
  133. }
  134. ossGlbPaths.add(queryPath +ossGlbPath);
  135. }
  136. return JSONArray.toJSONString(ossGlbPaths);
  137. }
  138. FileUtil.del(objPath);
  139. }
  140. return null;
  141. }
  142. private void toGlB(File localFile, List<String> localGlbPath) {
  143. File[] files = localFile.listFiles();
  144. for (File file : files) {
  145. if(file.isDirectory()){
  146. toGlB(file,localGlbPath);
  147. }
  148. if(file.getName().contains(".obj")){
  149. String glbPath = OBJToGLBUtil.objToGlb(file.getPath(),file.getPath().replace(".obj",".glb") );
  150. localGlbPath.add(glbPath);
  151. }
  152. }
  153. }
  154. private List<String> updateByNumList(Integer caseId, List<SceneNumParam> sceneNumParam) {
  155. List<String> addList = new ArrayList<>();
  156. for (SceneNumParam param : sceneNumParam) {
  157. Integer type = param.getType();
  158. List<String> numList = param.getNumList();
  159. LambdaQueryWrapper<CaseNumEntity> wrapper = new LambdaQueryWrapper<>();
  160. wrapper.eq(CaseNumEntity::getCaseId,caseId);
  161. wrapper.eq(CaseNumEntity::getNumType,type);
  162. List<CaseNumEntity> list = this.list(wrapper);
  163. List<String> hanNumList = list.parallelStream().map(CaseNumEntity::getNum).collect(Collectors.toList());
  164. List<String> delList = new ArrayList<>();
  165. for (String num : hanNumList) {
  166. if(!numList.contains(num)){
  167. delList.add(num);
  168. }
  169. }
  170. for (String num : numList) {
  171. if(!hanNumList.contains(num)){
  172. addList.add(num);
  173. }
  174. }
  175. this.deleteByNum(caseId,delList,param.getType());
  176. }
  177. return addList;
  178. }
  179. @Override
  180. public void deleteByNum(Integer caseId, List<String> delList,Integer type) {
  181. if(delList.size() >0){
  182. LambdaQueryWrapper<CaseNumEntity> wrapper = new LambdaQueryWrapper<>();
  183. wrapper.eq(CaseNumEntity::getCaseId,caseId);
  184. wrapper.eq(CaseNumEntity::getNumType,type);
  185. wrapper.in(CaseNumEntity::getNum,delList);
  186. this.remove(wrapper);
  187. fusionNumService.deleteByNumList(caseId,delList,true,type);
  188. }
  189. }
  190. @Override
  191. public void deleteByCaseId(Integer caseId) {
  192. LambdaQueryWrapper<CaseNumEntity> wrapper = new LambdaQueryWrapper<>();
  193. wrapper.eq(CaseNumEntity::getCaseId,caseId);
  194. this.remove(wrapper);
  195. fusionNumService.deleteByCaseId(caseId);
  196. caseViewService.deleteByCaseId(caseId);
  197. fusionGuidePathService.deleteByCaseId(caseId);
  198. fusionMeterService.deleteByCaseId(caseId);
  199. caseTagService.deletePointByCaseId(caseId);
  200. }
  201. @Override
  202. public HashMap<Integer, List<String>> getTypeMap(Integer caseId) {
  203. List<CaseNumEntity> caseNumList = this.getByCaseId(caseId);
  204. HashMap<Integer,List<String>> typeMap = new HashMap<>();
  205. for (CaseNumEntity caseNumEntity : caseNumList) {
  206. List<String> numList ;
  207. if(typeMap.get(caseNumEntity.getNumType()) == null){
  208. numList = new ArrayList<>();
  209. }else {
  210. numList = typeMap.get(caseNumEntity.getNumType());
  211. }
  212. numList.add(caseNumEntity.getNum());
  213. typeMap.put(caseNumEntity.getNumType(),numList);
  214. }
  215. return typeMap;
  216. }
  217. @Override
  218. public List<CaseNumEntity> getByNum(String num) {
  219. LambdaQueryWrapper<CaseNumEntity> wrapper = new LambdaQueryWrapper<>();
  220. wrapper.eq(CaseNumEntity::getNum,num);
  221. return this.list(wrapper);
  222. }
  223. }