DevController.java 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. package com.fdkk.fdkkmeta.ctroller;
  2. /**
  3. * @author Xiewj
  4. * @date 2021/12/29
  5. */
  6. import cn.hutool.core.io.FileUtil;
  7. import com.alibaba.fastjson.JSON;
  8. import com.alibaba.fastjson.JSONArray;
  9. import com.alibaba.fastjson.JSONObject;
  10. import com.fdkk.fdkkmeta.domain.entity.mysql.BreakpointsEntity;
  11. import com.fdkk.fdkkmeta.domain.entity.mysql.MoveFrameEntity;
  12. import com.fdkk.fdkkmeta.domain.entity.mysql.RoomEntity;
  13. import com.fdkk.fdkkmeta.domain.entity.mysql.RotateFrameEntity;
  14. import com.fdkk.fdkkmeta.domain.po.AnglePO;
  15. import com.fdkk.fdkkmeta.domain.po.PointPO;
  16. import com.fdkk.fdkkmeta.grpc.RotateRequest;
  17. import com.fdkk.fdkkmeta.redis.RedisCache;
  18. import com.fdkk.fdkkmeta.redis.RedisPublishService;
  19. import com.fdkk.fdkkmeta.service.BreakpointsService;
  20. import com.fdkk.fdkkmeta.service.MoveFrameService;
  21. import com.fdkk.fdkkmeta.service.RoomService;
  22. import com.fdkk.fdkkmeta.service.RotateFrameService;
  23. import com.fdkk.fdkkmeta.util.ProtoJsonUtils;
  24. import com.google.gson.JsonObject;
  25. import constants.RedisQueueConstant;
  26. import lombok.extern.slf4j.Slf4j;
  27. import org.springframework.beans.factory.annotation.Autowired;
  28. import org.springframework.web.bind.annotation.PostMapping;
  29. import org.springframework.web.bind.annotation.RequestBody;
  30. import org.springframework.web.bind.annotation.RequestMapping;
  31. import org.springframework.web.bind.annotation.RestController;
  32. import java.awt.geom.AffineTransform;
  33. import java.io.File;
  34. import java.io.IOException;
  35. import java.math.BigDecimal;
  36. import java.text.DecimalFormat;
  37. import java.util.*;
  38. @RestController
  39. @RequestMapping("/dev")
  40. @Slf4j
  41. public class DevController {
  42. @Autowired
  43. RoomService roomService;
  44. @Autowired
  45. BreakpointsService breakpointsService;
  46. @Autowired
  47. RotateFrameService rotateFrameService;
  48. @Autowired
  49. MoveFrameService moveFrameService;
  50. @Autowired
  51. RedisCache redisCache;
  52. @Autowired
  53. private RedisPublishService redisPublishService;
  54. /**
  55. * test
  56. *
  57. * @return
  58. */
  59. @PostMapping("/test")
  60. public String test() {
  61. String path="H:\\workfile\\100-150点json数据\\100-150点json数据\\outputjson";
  62. if (FileUtil.exist(path.replaceAll("outputjson",""))){
  63. String s = FileUtil.readString(path.replaceAll("outputjson","") + "points.json", "utf8");
  64. JSONArray points= JSON.parseArray(s);
  65. for (Object point : points) {
  66. JSONObject a = JSON.parseObject(JSONObject.toJSON(point).toString());
  67. BreakpointsEntity breakpointsEntity=new BreakpointsEntity();
  68. breakpointsEntity.setAppId("0000000001");
  69. PointPO po=new PointPO();
  70. po.setX(a.getJSONObject("position").getDoubleValue("x")*100);
  71. po.setY(a.getJSONObject("position").getDoubleValue("y")*100);
  72. po.setZ(a.getJSONObject("position").getDoubleValue("z")*100);
  73. breakpointsEntity.setPosition(po);
  74. breakpointsEntity.setBreakPointId(a.getLong("id"));
  75. JSONArray contact = a.getJSONArray("contact");
  76. List<Integer> collection = JSONObject.parseArray(contact.toJSONString(), Integer.class);//把字符串转换成集合
  77. breakpointsEntity.setContact(collection);
  78. breakpointsService.save(breakpointsEntity);
  79. }
  80. }
  81. // //break*100
  82. // File[] ls = FileUtil.ls(path);
  83. // for (File l : ls) {
  84. // List<File> files = FileUtil.loopFiles(l);
  85. // for (File file : files) {
  86. // if (!file.getName().contains("_")){
  87. // String s = FileUtil.readString(file, "utf8");
  88. // JSONArray rotate= JSON.parseArray(s);
  89. // List<RotateFrameEntity> rotateFrameEntityList = new ArrayList<>();
  90. // for (int i = 0; i < rotate.size(); i++) {
  91. // if (i!=360){
  92. // DecimalFormat decimalFormat = new DecimalFormat("0000");
  93. // String numFormat= decimalFormat .format(i);
  94. // JSONObject a = JSON.parseObject(JSONObject.toJSON(rotate.get(i)).toString());
  95. // RotateFrameEntity rotateFrameEntity=new RotateFrameEntity();
  96. // rotateFrameEntity.setFrameIndex(a.getInteger("frame"));
  97. // rotateFrameEntity.setFileName(l.getName()+"."+numFormat+".h264");
  98. // rotateFrameEntity.setDirectory(l.getName());
  99. // AnglePO anglePO=new AnglePO();
  100. // anglePO.setPitch(a.getJSONObject("angle").getIntValue("pitch"));
  101. // anglePO.setRoll(a.getJSONObject("angle").getIntValue("roll"));
  102. // anglePO.setYaw(a.getJSONObject("angle").getIntValue("yaw"));
  103. // rotateFrameEntity.setCameraAngle(anglePO);
  104. // PointPO po=new PointPO();
  105. // po.setX(a.getJSONObject("position").getDoubleValue("x"));
  106. // po.setY(a.getJSONObject("position").getDoubleValue("y"));
  107. // po.setZ(a.getJSONObject("position").getDoubleValue("z"));
  108. // rotateFrameEntity.setCameraPosition(po);
  109. // rotateFrameEntity.setBreakPointId(Long.parseLong(l.getName()));
  110. // rotateFrameEntity.setAppId("0000000001");
  111. // rotateFrameEntityList.add(rotateFrameEntity);
  112. // }
  113. // }
  114. // boolean b = rotateFrameService.saveBatch(rotateFrameEntityList);
  115. // System.out.println("saverotateFrameEntityList-"+b );
  116. //
  117. // }else {
  118. // String s = FileUtil.readString(file, "utf8");
  119. // JSONArray moveFrame= JSON.parseArray(s);
  120. // List<MoveFrameEntity> moveFrameEntityList=new ArrayList<>();
  121. // for (int i = 0; i < moveFrame.size(); i++) {
  122. // DecimalFormat decimalFormat = new DecimalFormat("0000");
  123. // String numFormat= decimalFormat .format(i);
  124. // JSONObject a = JSON.parseObject(JSONObject.toJSON(moveFrame.get(i)).toString());
  125. // MoveFrameEntity moveFrameEntity=new MoveFrameEntity();
  126. // AnglePO anglePO=new AnglePO();
  127. // anglePO.setPitch(a.getJSONObject("angle").getIntValue("pitch"));
  128. // anglePO.setRoll(a.getJSONObject("angle").getIntValue("roll"));
  129. // anglePO.setYaw(a.getJSONObject("angle").getIntValue("yaw"));
  130. // moveFrameEntity.setCameraAngle(anglePO);
  131. // PointPO po=new PointPO();
  132. // po.setX(a.getJSONObject("position").getDoubleValue("x"));
  133. // po.setY(a.getJSONObject("position").getDoubleValue("y"));
  134. // po.setZ(a.getJSONObject("position").getDoubleValue("z"));
  135. // moveFrameEntity.setCameraPosition(po);
  136. // String name = file.getName().replace(".json", "");
  137. // String[] s1 = name.split("_");
  138. // moveFrameEntity.setStartBreakPointId(Long.parseLong(s1[0]));
  139. // moveFrameEntity.setEndBreakPointId(Long.parseLong(s1[1]));
  140. // moveFrameEntity.setAngle(Integer.parseInt(s1[2]));
  141. // moveFrameEntity.setFrameIndex(a.getInteger("frame"));
  142. // moveFrameEntity.setDirectory(file.getName().replace(".json",""));
  143. // System.out.println(JSON.toJSONString(moveFrameEntity));
  144. // moveFrameEntity.setAppId("0000000001");
  145. // moveFrameEntity.setFileName(file.getName().replace(".json","")+"."+numFormat+".h264");
  146. // moveFrameEntityList.add(moveFrameEntity);
  147. // }
  148. // boolean b = moveFrameService.saveBatch(moveFrameEntityList);
  149. // System.out.println("savemoveFrameEntityList-"+b );
  150. // }
  151. // }
  152. // System.out.println(FileUtil.isFile(l));
  153. // }
  154. return "";
  155. }
  156. // @PostMapping("redis")
  157. // public void testredis(String userId,Object value) throws IOException, InterruptedException {
  158. //
  159. // for (int i = 0; i < 10000; i++) {
  160. // RotateRequest.Builder builder = RotateRequest.newBuilder();
  161. // builder.setUserId("u_"+i);
  162. // redisPublishService.sendProtocolMessage(RedisQueueConstant.JOYSTICK_QUEUE,builder);
  163. //
  164. // }
  165. // }
  166. }