123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- package com.fdkankan.scene.service.impl;
- import cn.hutool.core.collection.CollUtil;
- import cn.hutool.core.date.DatePattern;
- import cn.hutool.core.date.DateUtil;
- import cn.hutool.core.io.FileUtil;
- import cn.hutool.core.util.StrUtil;
- import cn.hutool.crypto.digest.MD5;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.dynamic.datasource.annotation.DS;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.fdkankan.common.constant.ErrorCode;
- import com.fdkankan.common.util.ThreeDESUtil;
- import com.fdkankan.redis.constant.RedisKey;
- import com.fdkankan.redis.util.RedisClient;
- import com.fdkankan.scene.bean.ResultData;
- import com.fdkankan.scene.entity.Scene;
- import com.fdkankan.scene.entity.SceneFileMapping;
- import com.fdkankan.scene.httpclient.CustomHttpClient;
- import com.fdkankan.scene.mapper.SceneMapper;
- import com.fdkankan.scene.service.SceneFileMappingService;
- import com.fdkankan.scene.service.SceneService;
- import com.fdkankan.scene.vo.SceneEditControlsVO;
- import com.fdkankan.scene.vo.SceneInfoParamVO;
- import com.fdkankan.scene.vo.SceneInfoVO;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.core.io.UrlResource;
- import org.springframework.http.MediaType;
- import org.springframework.http.ResponseEntity;
- import org.springframework.stereotype.Service;
- import javax.annotation.Resource;
- import javax.servlet.ServletOutputStream;
- import javax.servlet.http.HttpServletResponse;
- import java.io.File;
- import java.io.IOException;
- import java.io.InputStream;
- import java.net.URL;
- import java.net.URLConnection;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- * <p>
- * 服务实现类
- * </p>
- *
- * @author dsx
- * @since 2024-06-26
- */
- @DS("vr")
- @Slf4j
- @Service
- public class SceneServiceImpl extends ServiceImpl<SceneMapper, Scene> implements SceneService {
- @Autowired
- private SceneFileMappingService sceneFileMappingService;
- @Autowired
- private RedisClient redisClient;
- @Resource
- private CustomHttpClient customHttpClient;
- @Override
- public ResultData getSceneInfo(SceneInfoParamVO param) throws Exception {
- String num = param.getNum();
- SceneInfoVO sceneInfoVO = null;
- List<Scene> list = this.list(new LambdaQueryWrapper<Scene>().eq(Scene::getNum, num).orderByDesc(Scene::getId));
- if(CollUtil.isEmpty(list)){
- return ResultData.error(ErrorCode.FAILURE_CODE_5005.code(), ErrorCode.FAILURE_CODE_5005.message());
- }
- Scene scene = list.get(0);
- sceneInfoVO = new SceneInfoVO();
- sceneInfoVO.setTitle(scene.getTitle());
- sceneInfoVO.setNum(scene.getNum());
- sceneInfoVO.setFloorLogoSize(Integer.valueOf(scene.getFloorlogosize()));
- sceneInfoVO.setSceneKind(scene.getScenekind());
- sceneInfoVO.setSceneResolution(scene.getSceneresolution());
- sceneInfoVO.setSceneFrom(scene.getScenefrom());
- sceneInfoVO.setModelKind(scene.getModelkind());
- sceneInfoVO.setFloorPlanAngle(Float.valueOf(scene.getFloorplanangle()));
- sceneInfoVO.setFloorLogo("2");
- SceneEditControlsVO sceneEditControlsBean = SceneEditControlsVO.builder().showRule(1).showFloorplan(0).showDollhouse(0).showMap(1).showPanorama(1).showVR(1).showTitle(1).build();
- sceneInfoVO.setControls(sceneEditControlsBean);
- List<SceneFileMapping> mappingList = sceneFileMappingService.list(new LambdaQueryWrapper<SceneFileMapping>().eq(SceneFileMapping::getNum, num).orderByAsc(SceneFileMapping::getId));
- Map<String, String> keyMap = new HashMap<>();
- for (SceneFileMapping sceneFileMapping : mappingList) {
- keyMap.put(sceneFileMapping.getKey(), "service/scene/file?key=" + sceneFileMapping.getKey());
- }
- // sceneInfoVO.setMapping(keyMap);
- return ResultData.ok(sceneInfoVO);
- }
- @Override
- public ResponseEntity<org.springframework.core.io.Resource> outFileByKey(String key, HttpServletResponse response) throws IOException {
- SceneFileMapping one = sceneFileMappingService.getOne(new LambdaQueryWrapper<SceneFileMapping>().eq(SceneFileMapping::getKey, key));
- // InputStream inputStream = customHttpClient.downloadFileToInputStream(one.getUrl());
- org.springframework.core.io.Resource resource = null;
- URL url = new URL(one.getUrl());
- URLConnection connection = url.openConnection();
- connection.setConnectTimeout(600000);
- connection.setReadTimeout(600000);
- resource = new UrlResource(url);
- return ResponseEntity.ok().contentType(MediaType.APPLICATION_OCTET_STREAM).body(resource);
- }
- @Override
- public void outFileByKey2(String key, Integer subgroup, String upTime, HttpServletResponse response) throws IOException {
- SceneFileMapping one = sceneFileMappingService.getOne(new LambdaQueryWrapper<SceneFileMapping>().eq(SceneFileMapping::getKey, key).eq(SceneFileMapping::getSubgroup, subgroup).eq(SceneFileMapping::getUpTime, upTime));
- if(Objects.isNull(one)){
- response.setStatus(HttpServletResponse.SC_NOT_FOUND);
- }else{
- response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
- response.setHeader("Content-Disposition", "attachment; filename=\"" + FileUtil.getName(key) + "\"");
- try(
- InputStream inputStream = customHttpClient.downloadFileToInputStream(one.getUrl());
- ServletOutputStream outputStream = response.getOutputStream())
- {
- byte[] buffer = new byte[1024];
- int len;
- while ((len = inputStream.read(buffer)) != -1) {
- outputStream.write(buffer, 0, len);
- }
- outputStream.flush();
- }catch (Exception e){
- log.info("读取文件失败:key:{},url:{}", one.getKey(), one.getUrl());
- throw new RuntimeException(e);
- }
- }
- }
- public static void main(String[] args) {
- // JSONObject params = new JSONObject();
- // params.put("SYSCODE", "CHNTZCGL_ZCSZHGL");
- // params.put("ACCTID", "101269561");
- // params.put("TOKEN", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJSRVMiLCJpc3MiOiJXUzRBIiwiZXhwIjoxNzI3MjQxMTQwLCJOQU5PU0VDT05EIjozNTk0NjI1NTg5ODQ3MDU0Nn0.MIlnrl5X00_0QgaT1N9wYRwi4WQ86dGtQlD3EsA01I0");
- // String encode = ThreeDESUtil.encode(params.toString(), "6#dPz>3F");
- // System.out.println(encode);
- //
- // JSONObject params2 = new JSONObject();
- // params2.put("SERVICEID", "CHNTZCGL_ZCSZHGL");
- // params2.put("LOGINACCOUNT", "yangqc");
- // params2.put("TOKEN", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJSRVMiLCJpc3MiOiJXUzRBIiwiZXhwIjoxNzI3NTc3Mzc2LCJOQU5PU0VDT05EIjozNjI4MjQ5MTc2NjM4MDAzMX0.fbTCdbjMTOD6NywkuKGtsOnQdmFI7PiU4g8mEiLQ5wQ");
- // encode = ThreeDESUtil.encode(params2.toString(), "6#dPz>3F");
- // System.out.println(encode);
- //
- //
- // JSONObject params3 = new JSONObject();
- // params3.put("SERVICEID", "CHNTZCGL_ZCSZHGL");
- // params3.put("QUERYMODE", "3");
- // params3.put("TOKEN", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJSRVMiLCJpc3MiOiJXUzRBIiwiZXhwIjoxNzI3MjQxMTQwLCJOQU5PU0VDT05EIjozNTk0NjI1NTg5ODQ3MDU0Nn0.MIlnrl5X00_0QgaT1N9wYRwi4WQ86dGtQlD3EsA01I0");
- // params3.put("ORGCODE", "100035");
- // encode = ThreeDESUtil.encode(params3.toString(), "6#dPz>3F");
- // System.out.println(encode);
- // String s1 = MD5.create().digestHex16("D:\\四维时代\\江门公安\\场景迁移\\sncode.txt");
- // String s2 = MD5.create().digestHex16("D:\\四维时代\\江门公安\\场景迁移\\KJ-3wS2R5E57eY\\sncode.txt");
- // System.out.println(s1);
- // System.out.println(FileUtil.size(new File("D:\\四维时代\\江门公安\\场景迁移\\sncode.txt")));
- // System.out.println(s2);
- // System.out.println(FileUtil.size(new File("D:\\四维时代\\江门公安\\场景迁移\\KJ-3wS2R5E57eY\\sncode.txt")));
- String s1 = MD5.create().digestHex16("D:\\四维时代\\江门公安\\场景迁移\\123.txt");
- System.out.println(s1);
- FileUtil.writeUtf8String("123123", "D:\\四维时代\\江门公安\\场景迁移\\123.txt");
- String s2 = MD5.create().digestHex16("D:\\四维时代\\江门公安\\场景迁移\\123.txt");
- System.out.println(s2);
- }
- @Override
- public Scene getByNum(String num, Integer subgroup, String upTime) {
- if(StrUtil.isNotEmpty(upTime)){
- return this.getOne(new LambdaQueryWrapper<Scene>().eq(Scene::getNum, num).eq(Scene::getSubgroup, subgroup).eq(Scene::getUpTimeKey, upTime));
- }
- List<Scene> list = this.list(new LambdaQueryWrapper<Scene>().eq(Scene::getNum, num).eq(Scene::getSubgroup, subgroup).orderByDesc(Scene::getUpTimeKey));
- if(CollUtil.isEmpty(list)){
- return null;
- }
- return list.get(0);
- }
- @Override
- public List<Scene> listByNum(String num, Integer subgroup) {
- return this.list(new LambdaQueryWrapper<Scene>().eq(Scene::getNum, num).eq(Scene::getSubgroup, subgroup));
- }
- @Override
- public List<Scene> listByStationcode(String stationCode) {
- return this.list(new LambdaQueryWrapper<Scene>().eq(Scene::getStationcode, stationCode).eq(Scene::getSubgroup, 0));
- }
- @Override
- public Map<String, String> listByNumLast3(String num) {
- List<Scene> list = this.list(new LambdaQueryWrapper<Scene>().eq(Scene::getNum, num).eq(Scene::getSubgroup, 0).orderByDesc(Scene::getUpTime).last("limit 3"));
- if(CollUtil.isEmpty(list)){
- return null;
- }
- Map<String, String> map = new LinkedHashMap<>();
- for (Scene scene : list) {
- map.put(scene.getUpTimeKey(), DateUtil.formatDateTime(DateUtil.parse(scene.getUpTimeKey(), DatePattern.PURE_DATETIME_PATTERN)));
- }
- return map;
- }
- }
|