package com.fdkk.fdkkmeta.ctroller; /** * @author Xiewj * @date 2021/12/29 */ import cn.hutool.core.io.FileUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.fdkk.fdkkmeta.domain.entity.mysql.BreakpointsEntity; import com.fdkk.fdkkmeta.domain.entity.mysql.MoveFrameEntity; import com.fdkk.fdkkmeta.domain.entity.mysql.RoomEntity; import com.fdkk.fdkkmeta.domain.entity.mysql.RotateFrameEntity; import com.fdkk.fdkkmeta.domain.po.AnglePO; import com.fdkk.fdkkmeta.domain.po.PointPO; import com.fdkk.fdkkmeta.redis.RedisCache; import com.fdkk.fdkkmeta.service.BreakpointsService; import com.fdkk.fdkkmeta.service.MoveFrameService; import com.fdkk.fdkkmeta.service.RoomService; import com.fdkk.fdkkmeta.service.RotateFrameService; import com.google.gson.JsonObject; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.awt.geom.AffineTransform; import java.io.File; import java.math.BigDecimal; import java.text.DecimalFormat; import java.util.*; @RestController @RequestMapping("/dev") @Slf4j public class DevController { @Autowired RoomService roomService; @Autowired BreakpointsService breakpointsService; @Autowired RotateFrameService rotateFrameService; @Autowired MoveFrameService moveFrameService; @Autowired RedisCache redisCache; /** * test * * @return */ @PostMapping("/test") public String test() { String path="H:\\workfile\\100-150点json数据\\100-150点json数据\\outputjson"; if (FileUtil.exist(path.replaceAll("outputjson",""))){ String s = FileUtil.readString(path.replaceAll("outputjson","") + "points.json", "utf8"); JSONArray points= JSON.parseArray(s); for (Object point : points) { JSONObject a = JSON.parseObject(JSONObject.toJSON(point).toString()); BreakpointsEntity breakpointsEntity=new BreakpointsEntity(); breakpointsEntity.setAppId("0000000001"); PointPO po=new PointPO(); po.setX(a.getJSONObject("position").getDoubleValue("x")*100); po.setY(a.getJSONObject("position").getDoubleValue("y")*100); po.setZ(a.getJSONObject("position").getDoubleValue("z")*100); breakpointsEntity.setPosition(po); breakpointsEntity.setBreakPointId(a.getLong("id")); JSONArray contact = a.getJSONArray("contact"); List collection = JSONObject.parseArray(contact.toJSONString(), Integer.class);//把字符串转换成集合 breakpointsEntity.setContact(collection); breakpointsService.save(breakpointsEntity); } } // //break*100 // File[] ls = FileUtil.ls(path); // for (File l : ls) { // List files = FileUtil.loopFiles(l); // for (File file : files) { // if (!file.getName().contains("_")){ // String s = FileUtil.readString(file, "utf8"); // JSONArray rotate= JSON.parseArray(s); // List rotateFrameEntityList = new ArrayList<>(); // for (int i = 0; i < rotate.size(); i++) { // if (i!=360){ // DecimalFormat decimalFormat = new DecimalFormat("0000"); // String numFormat= decimalFormat .format(i); // JSONObject a = JSON.parseObject(JSONObject.toJSON(rotate.get(i)).toString()); // RotateFrameEntity rotateFrameEntity=new RotateFrameEntity(); // rotateFrameEntity.setFrameIndex(a.getInteger("frame")); // rotateFrameEntity.setFileName(l.getName()+"."+numFormat+".h264"); // rotateFrameEntity.setDirectory(l.getName()); // AnglePO anglePO=new AnglePO(); // anglePO.setPitch(a.getJSONObject("angle").getIntValue("pitch")); // anglePO.setRoll(a.getJSONObject("angle").getIntValue("roll")); // anglePO.setYaw(a.getJSONObject("angle").getIntValue("yaw")); // rotateFrameEntity.setCameraAngle(anglePO); // PointPO po=new PointPO(); // po.setX(a.getJSONObject("position").getDoubleValue("x")); // po.setY(a.getJSONObject("position").getDoubleValue("y")); // po.setZ(a.getJSONObject("position").getDoubleValue("z")); // rotateFrameEntity.setCameraPosition(po); // rotateFrameEntity.setBreakPointId(Long.parseLong(l.getName())); // rotateFrameEntity.setAppId("0000000001"); // rotateFrameEntityList.add(rotateFrameEntity); // } // } // boolean b = rotateFrameService.saveBatch(rotateFrameEntityList); // System.out.println("saverotateFrameEntityList-"+b ); // // }else { // String s = FileUtil.readString(file, "utf8"); // JSONArray moveFrame= JSON.parseArray(s); // List moveFrameEntityList=new ArrayList<>(); // for (int i = 0; i < moveFrame.size(); i++) { // DecimalFormat decimalFormat = new DecimalFormat("0000"); // String numFormat= decimalFormat .format(i); // JSONObject a = JSON.parseObject(JSONObject.toJSON(moveFrame.get(i)).toString()); // MoveFrameEntity moveFrameEntity=new MoveFrameEntity(); // AnglePO anglePO=new AnglePO(); // anglePO.setPitch(a.getJSONObject("angle").getIntValue("pitch")); // anglePO.setRoll(a.getJSONObject("angle").getIntValue("roll")); // anglePO.setYaw(a.getJSONObject("angle").getIntValue("yaw")); // moveFrameEntity.setCameraAngle(anglePO); // PointPO po=new PointPO(); // po.setX(a.getJSONObject("position").getDoubleValue("x")); // po.setY(a.getJSONObject("position").getDoubleValue("y")); // po.setZ(a.getJSONObject("position").getDoubleValue("z")); // moveFrameEntity.setCameraPosition(po); // String name = file.getName().replace(".json", ""); // String[] s1 = name.split("_"); // moveFrameEntity.setStartBreakPointId(Long.parseLong(s1[0])); // moveFrameEntity.setEndBreakPointId(Long.parseLong(s1[1])); // moveFrameEntity.setAngle(Integer.parseInt(s1[2])); // moveFrameEntity.setFrameIndex(a.getInteger("frame")); // moveFrameEntity.setDirectory(file.getName().replace(".json","")); // System.out.println(JSON.toJSONString(moveFrameEntity)); // moveFrameEntity.setAppId("0000000001"); // moveFrameEntity.setFileName(file.getName().replace(".json","")+"."+numFormat+".h264"); // moveFrameEntityList.add(moveFrameEntity); // } // boolean b = moveFrameService.saveBatch(moveFrameEntityList); // System.out.println("savemoveFrameEntityList-"+b ); // } // } // System.out.println(FileUtil.isFile(l)); // } return ""; } @PostMapping("redis") public void testredis(){ redisCache.pfremove("setCacheRequest:rotate:"+1); redisCache.setCacheList("setCacheRequest:rotate:"+1, Arrays.asList(1)); redisCache.setCacheList("setCacheRequest:rotate:"+1, Arrays.asList(2)); redisCache.setCacheList("setCacheRequest:rotate:"+1, Arrays.asList(3)); List cacheList = redisCache.getCacheList("setCacheRequest:rotate:" + 1); redisCache.lRemove("setCacheRequest:rotate:"+1,0,2); List cacheList1 = redisCache.getCacheList("setCacheRequest:rotate:" + 1); System.out.println(cacheList); } }