whycxzp
2025-04-02 fbc4439f1ee5ab4590ff5c2d54b6818f23c3d969
src/main/java/com/whyc/service/FireRobotService.java
@@ -1,12 +1,16 @@
package com.whyc.service;
import com.google.gson.reflect.TypeToken;
import com.github.pagehelper.PageInfo;
import com.whyc.dto.EnvironmentThreshold;
import com.whyc.dto.InspectionRecord;
import com.whyc.dto.Response;
import com.whyc.dto.WmsMaterialDto;
import com.whyc.util.HttpUtil;
import com.whyc.util.JsonUtil;
import com.whyc.util.ThreadLocalUtil;
import org.springframework.stereotype.Service;
import java.io.File;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
@Service
@@ -36,6 +40,8 @@
            }else{
                response.set(1,false,dataStr);
            }
        }else{
            response.set(1,false);
        }
        return response;
    }
@@ -52,4 +58,119 @@
        }
        return response;
    }
    public Response setInspectionInterval(float hour) {
        String httpUrl = "http://192.168.10.45:8085"+"/InspectionIntervals?hour="+2;
        Response response = HttpUtil.doPost(httpUrl, (String) null);
        //对结果进行处理
        if(response.getCode() == 1){ //请求成功,data有正常数据
            String dataStr = (String) response.getData();
            //巡检间隔已设置: 2.0 h/次
            response.setMsg(dataStr);
            response.setData(null);
        }
        return response;
    }
    public Response setEnvironmentThreshold(EnvironmentThreshold threshold) {
        String httpUrl = "http://192.168.10.45:8085"+"/EnvironmentThrSet?tempThold="+threshold.getTempThold()+"&humidityThold="+threshold.getHumidityThold()+"&COTthold="+threshold.getCOTthold()+"&CO2Thold="+threshold.getCO2Thold()+"&CH4Thold="+threshold.getCH4Thold()+"&H2Thold="+threshold.getH2Thold()+"&SmokeThold="+threshold.getSmokeThold();
        Response response = HttpUtil.doPost(httpUrl, (String) null);
        //对结果进行处理
        if(response.getCode() == 1){ //请求成功,data有正常数据
            String dataStr = (String) response.getData();
            //环境阈值修改成功,温度阈值:60.0、湿度阈值:60.0、CO:100.0、CO2:1500、CH4:100.0、H2:100.0、烟感:100.0
            response.setMsg(dataStr);
            response.setData(null);
        }
        return response;
    }
    public Response getEnvironmentThreshold() {
        //TODO 环境读取接口
        return null;
    }
    public Response<PageInfo<InspectionRecord>> getPageOfInspectionRecord(int pageNum, int pageSize, String startDateStr, String endDateStr) {
        List<InspectionRecord> recordList = new LinkedList<>();
        //查询固定位置的文件数
        //再通过传入的pageNum和pageSize来获取 文件顺序的起止具体index值
        //生产环境为 /mnt/disk2/YunNan3/video 和 /mnt/disk2/YunNan3/recordAnalysis
        //String videoDirPath = "C:\\Users\\29550\\Desktop\\当前项目\\2023\\0智能机器人运维系统\\巡检记录\\video";
        //String docDirPath = "C:\\Users\\29550\\Desktop\\当前项目\\2023\\0智能机器人运维系统\\巡检记录\\recordAnalysis";
        String videoDirPath = "/mnt/disk2/YunNan3/video";
        String docDirPath = "/mnt/disk2/YunNan3/reportAnalysis";
        File file = new File(docDirPath);
        String[] filenameListOrigin = file.list();
        List<String> filenameList = new LinkedList<>();
        //倒序遍历
        //filenameList内的元素的格式为 2025-03-25-01.doc,对filenameList进行遍历,
        //保留日期在startDate(例如2025-03-25)和endDate(例如2025-07-05)之间(包含起止时间)的文件并存到行的列表
        //按文件名按时间倒序排列
        for(int i = filenameListOrigin.length-1; i >=0 ; i--){
            String filename = filenameListOrigin[i];
            String dateStr = filename.substring(0, 10);
            Date date = ThreadLocalUtil.parse(dateStr, 3);
            //判断是否存在 起止日期 过滤
            if(startDateStr!=null && endDateStr!=null) {
                Date startDate = ThreadLocalUtil.parse(startDateStr, 3);
                Date endDate = ThreadLocalUtil.parse(endDateStr, 3);
                if (date.compareTo(endDate) <= 0) { //进入满足条件区域上限
                    if (date.compareTo(startDate) >= 0) { //满足条件下限
                        filenameList.add(filename);
                    } else { //超过下限,退出遍历.
                        break;
                    }
                }
            }else if (startDateStr!=null){ //只存在 起始时间筛选
                Date startDate = ThreadLocalUtil.parse(startDateStr, 3);
                if (date.compareTo(startDate) >= 0) { //满足条件下限
                    filenameList.add(filename);
                } else { //超过下限,退出遍历.
                    break;
                }
            }else if (endDateStr!=null){ //只存在 终止时间筛选
                Date endDate = ThreadLocalUtil.parse(endDateStr, 3);
                if (date.compareTo(endDate) <= 0) { //进入满足条件区域上限
                    filenameList.add(filename);
                }
            }else{ //不存在筛选
                filenameList.add(filename);
            }
        }
        //获取当前的总数
        int total = filenameList.size();
        //获取起始和结束index
        int pageStartIndex = (pageNum-1)*pageSize;
        int pageEndIndex = Math.min(total - 1, pageStartIndex + pageSize - 1);
        //实际总数跟分页终点做校验 例如: 一共有4条,size=5
        for (int i = pageStartIndex; i <= pageEndIndex; i++) {
            InspectionRecord inspectionRecord = new InspectionRecord();
            //字符串格式为 2025-03-25-01.doc,取年月日2025-03-25,取序号01
            String recordName = filenameList.get(i);
            String[] split = recordName.split("\\.");
            String date = recordName.substring(0, 10);
            String num = split[0].substring(11);
            //视频的名称为 2025-03-25-01-kjg.mp4
            String videoName = date+"-"+num+"-kjg.mp4";
            inspectionRecord.setDate(ThreadLocalUtil.parse(date,3));
            inspectionRecord.setNum(num);
            inspectionRecord.setVideoUrl("/inspectRecord/video/"+videoName);
            inspectionRecord.setDocUrl("/inspectRecord/recordAnalysis/"+recordName);
            recordList.add(inspectionRecord);
        }
        PageInfo<InspectionRecord> pageInfo = new PageInfo<>();
        pageInfo.setPageNum(pageNum);
        pageInfo.setPageSize(pageSize);
        //pageInfo设置setPages,总页数为总数/size并向上取整
        pageInfo.setPages((int) Math.ceil((double) total /pageSize));
        pageInfo.setTotal(total);
        pageInfo.setList(recordList);
        return new Response().set(1,pageInfo);
    }
}