Newer
Older
newfiber-termite / newfiber-termites / newfiber-termites-package / src / test / java / ServiceTest.java
@xiongkai xiongkai 16 days ago 7 KB 代码修改
import cn.hutool.core.thread.ThreadUtil;
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.dto.PhotoIdentifyDto;
import com.newfiber.termite.domain.dto.TermiteDataUpRequest;
import com.newfiber.termite.domain.response.DataUpResponse;
import com.newfiber.termite.enums.EExistsAnt;
import com.newfiber.termite.mapper.TermiteMapper;
import com.newfiber.termite.schedule.HeatMapSchedule;
import com.newfiber.termite.service.IDeviceMonitoringDataService;
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.IJingchuUploadRecordService;
import com.newfiber.termite.util.CosUtil;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
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
    HeatMapSchedule heatMapSchedule;

    @Resource
    private DataPublishService dataPublishService;

    @Resource
    private IJingchuUploadRecordService jingchuUploadRecordService;

    @Resource
    private IDeviceMonitoringDataService deviceMonitoringDataService;

    @Resource
    private DeviceInfoServiceImpl deviceInfoService;

    @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 geometryTest(){
        heatMapSchedule.generator();
    }

    @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);
    }
}