package com.keystar.plane.inspection; import com.baomidou.mybatisplus.annotation.TableField; import com.drew.imaging.jpeg.JpegProcessingException; import com.fasterxml.jackson.core.JsonProcessingException; import com.jcraft.jsch.JSchException; import com.jcraft.jsch.SftpException; import com.keystar.plane.inspection.bo.*; //import com.keystar.plane.inspection.config.MinIoConfig; import com.keystar.plane.inspection.constant.LocationConstant; import com.keystar.plane.inspection.constant.MissionConstant; import com.keystar.plane.inspection.dao.DegreesVo; import com.keystar.plane.inspection.dao.PhotoMessageVo; import com.keystar.plane.inspection.dao.PhotoResultVo; import com.keystar.plane.inspection.dao.PlanePhotoVo; import com.keystar.plane.inspection.entity.PhotoResultEntity; import com.keystar.plane.inspection.entity.PlanePhotoEntity; import com.keystar.plane.inspection.mapper.PhotoResultMapper; import com.keystar.plane.inspection.mapper.PlanePhotoMapper; import com.keystar.plane.inspection.mqtt.PlaneMqttHandler; import com.keystar.plane.inspection.service.*; import com.keystar.plane.inspection.service.impl.MinioService; import com.keystar.plane.inspection.service.impl.ReportServiceImpl; import com.keystar.plane.inspection.utils.*; import io.minio.messages.Item; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.util.ResourceUtils; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.math.BigDecimal; import java.nio.charset.Charset; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; @SpringBootTest class PlaneInspectionApplicationTests { @Autowired PhotoService photoService; @Autowired MqttService mqttService; @Autowired MinioService minioService; @Autowired PlanePhotoMapper planePhotoMapper; @Autowired PhotoResultMapper photoResultMapper; @Autowired TangyangDataService tangyangDataService; @Autowired PhotoResultService photoResultService; @Autowired private IReportService reportService; // @Autowired // MinIoConfig minIoConfig; @Autowired NestService nestService; @Autowired PlanePhotoService planePhotoService; // // @Test // void contextLoads() { // } // @Test // public void test() throws IOException, JpegProcessingException { // PhotoMessageVo photoMessage = PhotoUtils.getPhotoMessage(); // System.out.println(photoMessage.toString()); // } // // @Test // public void test1() throws IOException, JpegProcessingException { // PhotoUtils.getPhotoGps(); // } // // @Test // public void test3() throws Exception { // // String encrypt = Utils.encrypt("Keystar@2022", "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCDrKWklonbo4ZFgwLgE63wt+sHiB4Uq0Tl6V6g2Aoj5IPRd4TL8mJlMkaJu/c3G212jhjbUjYkWn5HOnrUwrVN1q+mJGGUCED6ruTNMiAc1Oe5gbLwGIeyk4IMuZFUVwq7XdTgVfFo9cVRAM8jIWftJrCm63ZrqqU/AdBoU4FSTQIDAQAB"); // System.out.println(encrypt); // } // @Test public void testLogin() throws Exception { String s = PlaneMqttHandler.planeLogin(); System.out.println(s); } // // @Test // public void testGetPhoto() throws Exception { // PlanePhotoVo planePhoto = PlaneMqttHandler.getPlanePhoto(); // System.out.println(planePhoto); // } // // @Test // public void test4(){ // String test = "640 pixels"; // String[] s = test.split(" "); // System.out.println(s[0]); // } // // @Test // public void test5() throws IOException, JpegProcessingException { // // 获取图片的信息 // PhotoMessageVo photoMessage = PhotoUtils.getPhotoMessage(); // List locations = PhotoUtils.getDegrees(photoMessage); // System.out.println(locations.toString()); // } // // @Test // public void test6() throws IOException { // String pvJson = FileUtils.getPVJson(); // System.out.println(pvJson); // } // // @Test // public void test7() throws IOException { // String pvJson = FileUtils.getPVJson(); // // Map stringListMap = FileUtils.jsonTransData(pvJson); // System.out.println(stringListMap.toString()); // } // // @Test // public void test8(){ // FileUtil.ReadFileByIO("F:\\tangyangWrj\\plane-inspection\\target\\classes\\pv.json"); // // } // // @Test // public void test9(){ // String nestStatus = nestService.getNestStatus(); // System.out.println(nestStatus); // } @Test public void test10() throws FileNotFoundException { File file = ResourceUtils.getFile("classpath:border.json"); FileUtil.readFZLatLng(file.getPath()); System.out.println(""); } @Test public void test11(){ List locations = LocationConstant.PZLocation.get("01"); Location location = locations.get(1); System.out.println(location.toString()); } // @Test // public void test12() throws IOException, JpegProcessingException { // photoService.queryPhoto(); // } // // @Test // public void testMqtt() throws JsonProcessingException { // mqttService.sendMqtt(); // } @Test public void getNewFile(){ List nest = minioService.listObject("nest"); System.out.println(nest.toString()); } // @Test // public void getNewFile2(){ // List infraredPhoto = minioService.getInfraredPhoto(); // // System.out.println(infraredPhoto.toString()); // } @Test public void getFtpFile(){ FtpUtils.getFtpFile(); } @Test public void ssh() throws JSchException, SftpException { SSHUtils.connect("root", "keystar", "10.138.6.221", 22); SSHUtils.execCmd("cd /data/minio/data/nest/autoUpload/photo/"); SSHUtils.execCmd("ls -ltr"); String lsDirectory = "/data/minio/data/nest/autoUpload/photo/"; SSHUtils.listFiles(lsDirectory); SSHUtils.close(); } @Test public void testSSH(){ // 连接到指定的服务器 try { // 1、首先远程连接ssh SSHRemoteCall.getInstance().sshRemoteCallLogin("10.138.6.221", "root", "keystar"); String command = "ls -lt /data/minio/data/nest/autoUpload/photo/"; SSHRemoteCall.getInstance().execCommand(command); // 7、关闭连接 SSHRemoteCall.getInstance().closeSession(); } catch (Exception e) { // 打印错误信息 System.err.println("远程连接失败......"); e.printStackTrace(); } } // @Test // public void getNew(){ // List newPhoto = FileUtil.getNewPhoto(); // System.out.println(newPhoto.toString()); // // } @Test public void sendMqtt() throws JsonProcessingException { mqttService.sendPhotoFile("/nest/autoUpload/photo/2422/1111/", "0"); } @Test public void insert(){ PlanePhotoEntity planePhotoEntity = new PlanePhotoEntity(); planePhotoEntity.setId(1L); planePhotoEntity.setMissionId(1); planePhotoEntity.setRecordId(1); planePhotoEntity.setInfraredImagePath("123/123"); planePhotoEntity.setPvName("pvName"); planePhotoEntity.setPzName("pzName"); planePhotoEntity.setTime(new Date()); boolean save = planePhotoService.save(planePhotoEntity); System.out.println(save); } @Test public void test() throws IOException, JpegProcessingException { photoService.queryPhoto("F:\\1871\\1871\\方阵13-16巡检任务0224-2023-02-26-15-18-25-DJI_20230226144258_0005_THRM.jpg"); } /** * 测试重合面积 **/ @Test public void CongHe() throws IOException, JpegProcessingException { List location1 = LocationConstant.PZLocation.get("FZ01"); // 获取图片中的信息 PhotoMessageVo photoMessage = PhotoUtils.getPhotoMessage("F:\\1871\\1871\\方阵13-16巡检任务0224-2023-02-26-15-18-25-DJI_20230226144258_0005_THRM.jpg"); // 根据图片信息,获取图片四个角的经纬度,判断图片在哪个光伏区 List degrees = PhotoUtils.getDegrees(photoMessage); List locations = LocationConstant.PVLocation.get("01").get("01HL09-3 01HL09-4"); double v = GisCheckUtils.CoincidentArea(location1, degrees); double v1 = GisCheckUtils.CoincidentArea(locations, degrees); System.out.println(v); System.out.println(v1); } /** * 测试计算多边形面积 **/ @Test public void MianJi(){ // 球面积计算公式 // List pointList = LocationConstant.PZLocation.get("FZ01"); // double v = GisCheckUtils.calculatePolygonArea(pointList); // // 970.2378908613696 // // 722337.9547839954 // System.out.println(v); } @Test public void MJ2(){ List locations = LocationConstant.PVLocation.get("01").get("01HL09-3 01HL09-4"); List sortLocation = GisCheckUtils.sortLocation(locations); System.out.println(sortLocation); // h double lat0 = sortLocation.get(0).getLat(); double lat1 = sortLocation.get(1).getLat(); double latH = lat0-lat1; BigDecimal meterH = new BigDecimal(latH).divide(new BigDecimal(0.00000899), 10, BigDecimal.ROUND_HALF_UP); // 4.6251901441m // w double lon1 = sortLocation.get(1).getLon(); double lon2 = sortLocation.get(2).getLon(); double lonW = lon1-lon2; BigDecimal meterW = new BigDecimal(lonW).divide(new BigDecimal(0.00001141), 10, BigDecimal.ROUND_HALF_UP); // 29.3227901828 //s BigDecimal multiply = meterH.multiply(meterW); System.out.println(multiply); // 135.62348015099879734148 } /** * 地球半径(米) * 6371000.0 ~ 6371009.0 */ private static double earthRadiusMeters = 6371006.0; /** * 米每度 */ private static double metersPerDegree = 2.0 * Math.PI * earthRadiusMeters / 360.0; /** * 弧度每度 */ private static double radiansPerDegree = Math.PI / 180.0; @Test public void MJ3() throws IOException, JpegProcessingException { // List pointList = LocationConstant.PVLocation.get("01").get("01HL09-3 01HL09-4"); File file = ResourceUtils.getFile("classpath:1114_THRM.JPG"); // 获取图片中的信息 PhotoMessageVo photoMessage = PhotoUtils.getPhotoMessage(file.getPath()); // 根据图片信息,获取图片四个角的经纬度,判断图片在哪个光伏区 // List pointLs = PhotoUtils.getDegrees(photoMessage); List pointLs = LocationConstant.PZLocation.get("FZ01"); List pointList = GisCheckUtils.sortLocation(pointLs); // 145.57421875 // 34100.140625 // 1295.87890625 double v = GisCheckUtils.planarPolygonAreaMeters(pointList); System.out.println(v); } @Test public void MJ4(){ System.out.println(System.getProperty("file.encoding")); System.out.println(Charset.defaultCharset()); } /** * 根据图片中的某个坐标求解出对应的经纬度坐标 **/ @Test public void testPhoto() throws IOException, JpegProcessingException { // 获取图片中的信息 PhotoMessageVo photoMessage = PhotoUtils.getPhotoMessage("F:\\1871\\1871\\方阵13-16巡检任务0224-2023-02-26-15-21-02-DJI_20230226144408_0040_THRM.jpg"); Location pointLocation = PhotoUtils.getPointLocation(569.0,409.0 , photoMessage); System.out.println(""+ pointLocation.toString()); } @Test public void testMapper(){ PvNameBo pvNameBo = new PvNameBo(); pvNameBo.setPvName("04HL15-07"); // pvNameBo.setStartIndex(2); // pvNameBo.setPageSize(15); List photoBo = planePhotoMapper.getPhotoBo(pvNameBo); System.out.println(photoBo.toString()); } @Test public void testService(){ PvNameBo pvNameBo = new PvNameBo(); pvNameBo.setPvName("04HL15-07 "); pvNameBo.setStartIndex(1); pvNameBo.setPageSize(15); PhotoResultVo photoMsg = photoService.getPhotoMsg(pvNameBo); System.out.println(photoMsg.toString()); } @Test public void testResultMapper(){ List photoResultEntities = photoResultMapper.queryResultByPhotoId(1630493587477725184L); System.out.println(photoResultEntities); } @Test public void testBo(){ Map> fz01 = LocationConstant.PVLocation.get("FZ01"); System.out.println(fz01.toString()); } @Test public void testMonth(){ DateBo dateBo = new DateBo(); try { dateBo = Utils.getMonthDay(); } catch (ParseException e) { e.printStackTrace(); } System.out.println(dateBo.toString()); } @Test public void testRecordIdNum() throws ParseException { Integer recordIdNum = planePhotoService.getTotalSortie(); System.out.println(recordIdNum); } @Test public void testEff() throws ParseException { Integer effectiveSortie = planePhotoService.getEffectiveSortie(); System.out.println(effectiveSortie); } @Test public void testDate() throws ParseException { Integer effectiveInspectionDate = planePhotoService.getEffectiveInspectionDate(); System.out.println(effectiveInspectionDate); } @Test public void testMapper2(){ List photoResultEntities = photoResultMapper.queryFltPVString(1889, "covered"); int size = photoResultEntities.size(); System.out.println(size); } @Test public void testMapper3(){ List photoEntityList = planePhotoMapper.queryNewRecordByMission(2420); System.out.println(photoEntityList); // 499 } @Test public void testgetHour(){ List planeInspectionResultBos = photoResultService.listInspectionResult(); System.out.println(planeInspectionResultBos); } /*@Test public void testFile(){ String url = "F:/photo" + "/nest/photo/2420/1887/方阵13-16巡检任务0224-2023-03-04-11-04-02-DJI_20230304103720_0025_Z.JPG"; String s = reportService.pic2Base64FromPath(url); System.out.println(s); }*/ }