SceneServiceImpl.java 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. package com.fdkankan.scene.service.impl;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.io.FileUtil;
  4. import cn.hutool.core.util.StrUtil;
  5. import com.alibaba.fastjson.JSON;
  6. import com.alibaba.fastjson.JSONObject;
  7. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  8. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  9. import com.fdkankan.common.constant.ErrorCode;
  10. import com.fdkankan.common.util.ThreeDESUtil;
  11. import com.fdkankan.redis.constant.RedisKey;
  12. import com.fdkankan.redis.util.RedisClient;
  13. import com.fdkankan.scene.bean.ResultData;
  14. import com.fdkankan.scene.entity.Scene;
  15. import com.fdkankan.scene.entity.SceneFileMapping;
  16. import com.fdkankan.scene.httpclient.CustomHttpClient;
  17. import com.fdkankan.scene.mapper.SceneMapper;
  18. import com.fdkankan.scene.service.SceneFileMappingService;
  19. import com.fdkankan.scene.service.SceneService;
  20. import com.fdkankan.scene.vo.SceneEditControlsVO;
  21. import com.fdkankan.scene.vo.SceneInfoParamVO;
  22. import com.fdkankan.scene.vo.SceneInfoVO;
  23. import lombok.extern.slf4j.Slf4j;
  24. import org.springframework.beans.factory.annotation.Autowired;
  25. import org.springframework.core.io.UrlResource;
  26. import org.springframework.http.MediaType;
  27. import org.springframework.http.ResponseEntity;
  28. import org.springframework.stereotype.Service;
  29. import javax.annotation.Resource;
  30. import javax.servlet.ServletOutputStream;
  31. import javax.servlet.http.HttpServletResponse;
  32. import java.io.IOException;
  33. import java.io.InputStream;
  34. import java.net.URL;
  35. import java.net.URLConnection;
  36. import java.util.HashMap;
  37. import java.util.List;
  38. import java.util.Map;
  39. import java.util.Objects;
  40. /**
  41. * <p>
  42. * 服务实现类
  43. * </p>
  44. *
  45. * @author dsx
  46. * @since 2024-06-26
  47. */
  48. @Slf4j
  49. @Service
  50. public class SceneServiceImpl extends ServiceImpl<SceneMapper, Scene> implements SceneService {
  51. @Autowired
  52. private SceneFileMappingService sceneFileMappingService;
  53. @Autowired
  54. private RedisClient redisClient;
  55. @Resource
  56. private CustomHttpClient customHttpClient;
  57. @Override
  58. public ResultData getSceneInfo(SceneInfoParamVO param) throws Exception {
  59. String num = param.getNum();
  60. SceneInfoVO sceneInfoVO = null;
  61. List<Scene> list = this.list(new LambdaQueryWrapper<Scene>().eq(Scene::getNum, num).orderByDesc(Scene::getId));
  62. if(CollUtil.isEmpty(list)){
  63. return ResultData.error(ErrorCode.FAILURE_CODE_5005.code(), ErrorCode.FAILURE_CODE_5005.message());
  64. }
  65. Scene scene = list.get(0);
  66. sceneInfoVO = new SceneInfoVO();
  67. sceneInfoVO.setTitle(scene.getTitle());
  68. sceneInfoVO.setNum(scene.getNum());
  69. sceneInfoVO.setFloorLogoSize(Integer.valueOf(scene.getFloorlogosize()));
  70. sceneInfoVO.setSceneKind(scene.getScenekind());
  71. sceneInfoVO.setSceneResolution(scene.getSceneresolution());
  72. sceneInfoVO.setSceneFrom(scene.getScenefrom());
  73. sceneInfoVO.setModelKind(scene.getModelkind());
  74. sceneInfoVO.setFloorPlanAngle(Float.valueOf(scene.getFloorplanangle()));
  75. sceneInfoVO.setFloorLogo("2");
  76. SceneEditControlsVO sceneEditControlsBean = SceneEditControlsVO.builder().showRule(1).showFloorplan(0).showDollhouse(0).showMap(1).showPanorama(1).showVR(1).showTitle(1).build();
  77. sceneInfoVO.setControls(sceneEditControlsBean);
  78. List<SceneFileMapping> mappingList = sceneFileMappingService.list(new LambdaQueryWrapper<SceneFileMapping>().eq(SceneFileMapping::getNum, num).orderByAsc(SceneFileMapping::getId));
  79. Map<String, String> keyMap = new HashMap<>();
  80. for (SceneFileMapping sceneFileMapping : mappingList) {
  81. keyMap.put(sceneFileMapping.getKey(), "service/scene/file?key=" + sceneFileMapping.getKey());
  82. }
  83. // sceneInfoVO.setMapping(keyMap);
  84. return ResultData.ok(sceneInfoVO);
  85. }
  86. @Override
  87. public ResponseEntity<org.springframework.core.io.Resource> outFileByKey(String key, HttpServletResponse response) throws IOException {
  88. SceneFileMapping one = sceneFileMappingService.getOne(new LambdaQueryWrapper<SceneFileMapping>().eq(SceneFileMapping::getKey, key));
  89. // InputStream inputStream = customHttpClient.downloadFileToInputStream(one.getUrl());
  90. org.springframework.core.io.Resource resource = null;
  91. URL url = new URL(one.getUrl());
  92. URLConnection connection = url.openConnection();
  93. connection.setConnectTimeout(600000);
  94. connection.setReadTimeout(600000);
  95. resource = new UrlResource(url);
  96. return ResponseEntity.ok().contentType(MediaType.APPLICATION_OCTET_STREAM).body(resource);
  97. }
  98. @Override
  99. public void outFileByKey2(String key, Integer subgroup, HttpServletResponse response) throws IOException {
  100. SceneFileMapping one = sceneFileMappingService.getOne(new LambdaQueryWrapper<SceneFileMapping>().eq(SceneFileMapping::getKey, key).eq(SceneFileMapping::getSubgroup, subgroup));
  101. if(Objects.isNull(one)){
  102. response.setStatus(HttpServletResponse.SC_NOT_FOUND);
  103. }else{
  104. response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
  105. response.setHeader("Content-Disposition", "attachment; filename=\"" + FileUtil.getName(key) + "\"");
  106. try(
  107. InputStream inputStream = customHttpClient.downloadFileToInputStream(one.getUrl());
  108. ServletOutputStream outputStream = response.getOutputStream())
  109. {
  110. byte[] buffer = new byte[1024];
  111. int len;
  112. while ((len = inputStream.read(buffer)) != -1) {
  113. outputStream.write(buffer, 0, len);
  114. }
  115. outputStream.flush();
  116. }catch (Exception e){
  117. log.info("读取文件失败:key:{},url:{}", one.getKey(), one.getUrl());
  118. throw new RuntimeException(e);
  119. }
  120. }
  121. }
  122. public static void main(String[] args) {
  123. JSONObject params = new JSONObject();
  124. params.put("SYSCODE", "CHNTZCGL_ZCSZHGL");
  125. params.put("ACCTID", "101269561");
  126. params.put("TOKEN", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJSRVMiLCJpc3MiOiJXUzRBIiwiZXhwIjoxNzI3MjQxMTQwLCJOQU5PU0VDT05EIjozNTk0NjI1NTg5ODQ3MDU0Nn0.MIlnrl5X00_0QgaT1N9wYRwi4WQ86dGtQlD3EsA01I0");
  127. String encode = ThreeDESUtil.encode(params.toString(), "6#dPz>3F");
  128. System.out.println(encode);
  129. JSONObject params2 = new JSONObject();
  130. params2.put("SERVICEID", "CHNTZCGL_ZCSZHGL");
  131. params2.put("LOGINACCOUNT", "yangqc");
  132. params2.put("TOKEN", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJSRVMiLCJpc3MiOiJXUzRBIiwiZXhwIjoxNzI3NTc3Mzc2LCJOQU5PU0VDT05EIjozNjI4MjQ5MTc2NjM4MDAzMX0.fbTCdbjMTOD6NywkuKGtsOnQdmFI7PiU4g8mEiLQ5wQ");
  133. encode = ThreeDESUtil.encode(params2.toString(), "6#dPz>3F");
  134. System.out.println(encode);
  135. JSONObject params3 = new JSONObject();
  136. params3.put("SERVICEID", "CHNTZCGL_ZCSZHGL");
  137. params3.put("QUERYMODE", "3");
  138. params3.put("TOKEN", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJSRVMiLCJpc3MiOiJXUzRBIiwiZXhwIjoxNzI3MjQxMTQwLCJOQU5PU0VDT05EIjozNTk0NjI1NTg5ODQ3MDU0Nn0.MIlnrl5X00_0QgaT1N9wYRwi4WQ86dGtQlD3EsA01I0");
  139. params3.put("ORGCODE", "100035");
  140. encode = ThreeDESUtil.encode(params3.toString(), "6#dPz>3F");
  141. System.out.println(encode);
  142. }
  143. @Override
  144. public Scene getByNum(String num, Integer subgroup) {
  145. return this.getOne(new LambdaQueryWrapper<Scene>().eq(Scene::getNum, num).eq(Scene::getSubgroup, subgroup));
  146. }
  147. @Override
  148. public List<Scene> listByNum(String num, Integer subgroup) {
  149. return this.list(new LambdaQueryWrapper<Scene>().eq(Scene::getNum, num).eq(Scene::getSubgroup, subgroup));
  150. }
  151. }