SceneServiceImpl.java 9.9 KB

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