import cn.hutool.core.thread.ThreadUtil; import cn.hutool.poi.excel.ExcelUtil; import com.newfiber.common.core.utils.file.FileUtils; import com.newfiber.termite.NewfiberTermiteApplication; import com.newfiber.termite.domain.DeviceInfo; import com.newfiber.termite.domain.DeviceMonitoringData; import com.newfiber.termite.domain.ProjectInfo; import com.newfiber.termite.domain.dto.PhotoIdentifyDto; import com.newfiber.termite.domain.dto.TermiteDataUpRequest; import com.newfiber.termite.domain.jingchu.JingchuProjectConfig; import com.newfiber.termite.domain.request.jingchuProjectConfig.JingchuProjectConfigQueryRequest; import com.newfiber.termite.domain.request.project.ProjectInfoQueryRequest; import com.newfiber.termite.enums.EExistsAnt; import com.newfiber.termite.mapper.TermiteMapper; import com.newfiber.termite.service.IDeviceMonitoringDataService; import com.newfiber.termite.service.IProjectInfoService; import com.newfiber.termite.service.ISmsRecordService; import com.newfiber.termite.service.impl.DataPublishService; import com.newfiber.termite.service.impl.DeviceInfoServiceImpl; import com.newfiber.termite.service.impl.TermiteServiceImpl; import com.newfiber.termite.service.jingchu.IJingchuProjectConfigService; import com.newfiber.termite.service.jingchu.IJingchuUploadRecordService; import com.newfiber.termite.util.CosUtil; import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import javax.annotation.Resource; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.multipart.MultipartFile; @SpringBootTest(classes = NewfiberTermiteApplication.class) @RunWith(SpringRunner.class) public class ServiceTest { @Resource private TermiteMapper termiteMapper; @Resource private TermiteServiceImpl termiteService; @Resource private ISmsRecordService smsRecordService; @Resource private DataPublishService dataPublishService; @Resource private IJingchuUploadRecordService jingchuUploadRecordService; @Resource private IDeviceMonitoringDataService deviceMonitoringDataService; @Resource private DeviceInfoServiceImpl deviceInfoService; @Resource private IProjectInfoService projectInfoService; @Resource private IJingchuProjectConfigService jingchuProjectConfigService; @Test public void termiteDataupTest() throws Exception{ TermiteDataUpRequest termiteDataUpRequest = new TermiteDataUpRequest(); termiteDataUpRequest.setSn("ANT231031003"); MultipartFile multipartFile = FileUtils.getMultipartFile(new File("C:\\Users\\Administrator\\Downloads\\复位.png")); // DataUpResponse dataUpResponse = termiteService.termiteDataup(termiteDataUpRequest, multipartFile); // System.out.println(dataUpResponse.toString()); } @Test public void photoIdentifyTest() throws Exception{ PhotoIdentifyDto photoIdentifyDto = new PhotoIdentifyDto(); photoIdentifyDto.setId("1795644012890468354"); photoIdentifyDto.setYesnoant(EExistsAnt.True.getCode()); MultipartFile multipartFile = FileUtils.getMultipartFile(new File("C:\\Users\\Administrator\\Downloads\\复位.png")); String url = termiteService.photoIdentify(photoIdentifyDto, multipartFile); System.out.println(url); } @Test public void smsTest(){ smsRecordService.send("wulinshuiku", "10-1"); } @Test public void dataPublishServiceTest(){ DeviceMonitoringData deviceMonitoringData = new DeviceMonitoringData(); deviceMonitoringData.setSn("12345"); deviceMonitoringData.setDate("2024-11-01 10:00:01"); deviceMonitoringData.setYesnoant("1"); // dataPublishService.publish("241028", "123", deviceMonitoringData); // dataPublishService.publish("24102801", "123", deviceMonitoringData); // dataPublishService.publish("20241029", "123", deviceMonitoringData); // dataPublishService.publish("abc", "123", deviceMonitoringData); ThreadUtil.sleep(10, TimeUnit.SECONDS); } @Test public void jingchuTest(){ // jingchuUploadRecordService.insert("wulinshuiku", "ANT-T2403280013", // "280013", "", ""); DeviceMonitoringData deviceMonitoringData = deviceMonitoringDataService.selectDetail(524594L); termiteService.jingChuUpload(deviceMonitoringData, "1"); } @Test public void geometryTest2(){ List<String> projectCodeList = new ArrayList<>(); projectCodeList.add("20241115"); for(String projectCode : projectCodeList){ // List<DeviceMonitoringData> deviceMonitoringDataList = deviceMonitoringDataService.selectList(projectCode); // List<SiteTotalWarnCount> siteTotalWarnCountList = new ArrayList<>(); // // Map<String, List<DeviceMonitoringData>> siteDeviceMonitoringDataMap = deviceMonitoringDataList.stream().collect(Collectors.groupingBy(DeviceMonitoringData::getSn)); // for(Entry<String, List<DeviceMonitoringData>> entry : siteDeviceMonitoringDataMap.entrySet()){ // List<DeviceMonitoringData> enableDeviceMonitoringDataList = new ArrayList<>(); // Map<String, List<DeviceMonitoringData>> siteDailyDeviceMonitoringDataMap = entry.getValue().stream().collect(Collectors.groupingBy(t -> t.getDate().split(" ")[0])); // // for(Entry<String, List<DeviceMonitoringData>> dailyEntry : siteDailyDeviceMonitoringDataMap.entrySet()){ // if(dailyEntry.getValue().size() > 5){ // enableDeviceMonitoringDataList.addAll(dailyEntry.getValue()); // } // } // // DeviceMonitoringData deviceMonitoringData = entry.getValue().get(0); // siteTotalWarnCountList.add(new SiteTotalWarnCount(entry.getKey(), deviceMonitoringData.getLocation(), // enableDeviceMonitoringDataList.size(), deviceMonitoringData.getLocationType(), deviceMonitoringData.getLonandlat())); // } // // String template = "{%s, %s, %s}"; // List<String> arrayList = new ArrayList<>(); // for(SiteTotalWarnCount siteTotalWarnCount : siteTotalWarnCountList){ // String lon = siteTotalWarnCount.getLonandlat().split(",")[0]; // String lat = siteTotalWarnCount.getLonandlat().split(",")[1]; // arrayList.add(String.format(template, lon, lat, siteTotalWarnCount.getCount())); // } // System.out.println("{" + String.join(",", arrayList) + "}"); List<DeviceInfo> deviceInfoList = deviceInfoService.selectList(projectCode); deviceInfoList = deviceInfoList.stream().filter(t -> t.getGeometryNumber().equals("1")).collect( Collectors.toList()); List<String> arrayList = new ArrayList<>(); String template = "{%s, %s, %s}"; for(DeviceInfo deviceInfo : deviceInfoList){ String lon = deviceInfo.getLonandlat().split(",")[0]; String lat = deviceInfo.getLonandlat().split(",")[1]; arrayList.add(String.format(template, lon, lat, 0)); } System.out.println("{" + String.join(",", arrayList) + "}"); } } @Test public void uploadTest(){ MultipartFile multipartFile = FileUtils.getMultipartFile(new File("C:\\Users\\Administrator\\Downloads\\caixianshuiku-zhuba.jpg")); String url = CosUtil.putFile(multipartFile); System.out.println(url); } @Test public void excelTest(){ List<ProjectInfo> projectInfoList = projectInfoService.selectList(new ProjectInfoQueryRequest()); List<JingchuProjectConfig> jingchuProjectConfigList = jingchuProjectConfigService.selectList(new JingchuProjectConfigQueryRequest()); int sheetCount = ExcelUtil.getReader("C:\\Users\\Administrator\\Downloads\\荆楚平台上线1.2.xlsx").getSheets().size(); String template = "INSERT INTO thi_jingchu_project_config(project_code,mn_no,station_id,station_name,device_id,device_name) VALUES('%s', '%s', '%s', '%s', '%s', '%s');"; List<String> projectCodeList = new ArrayList<>(); for(int i = 0; i < sheetCount; i++){ List<List<Object>> excelData = ExcelUtil.getReader("C:\\Users\\Administrator\\Downloads\\荆楚平台上线1.2.xlsx", i).read(1); for(List<Object> row : excelData){ String stationName = row.get(1).toString(); String projectName = row.get(1).toString().replace("白蚁监测站", "水库"); String stationId = row.get(3).toString(); String mnNo = row.get(2).toString(); String deviceId = row.get(4).toString(); String projectCode = ""; Optional<ProjectInfo> projectInfoOptional = projectInfoList.stream().filter(t -> t.getProjectName().equals(projectName)).findFirst(); if(projectInfoOptional.isPresent()){ Optional<JingchuProjectConfig> jingchuProjectConfigOptional = jingchuProjectConfigList.stream().filter(t -> t.getProjectCode().equals(projectInfoOptional.get().getProjectCode())).findFirst(); if(!jingchuProjectConfigOptional.isPresent()){ projectCode = projectInfoOptional.get().getProjectCode(); projectCodeList.add(projectCode); System.out.printf((template) + "%n", projectCode, mnNo, stationId, stationName, deviceId, stationName); } }else{ System.out.printf("项目名称【%s】不匹配%n", projectName); } } } System.out.println(String.join("','", projectCodeList)); } }