| | |
| | | package com.whyc.service; |
| | | |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.google.gson.reflect.TypeToken; |
| | | import com.whyc.dto.InspectionTask; |
| | | 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 |
| | |
| | | return response; |
| | | } |
| | | |
| | | public Response<PageInfo<InspectionTask>> getPageOfInspectionRecord(int pageNum, int pageSize) { |
| | | 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/recordAnalysis"; |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | PageInfo<InspectionTask> pageInfo = new PageInfo<>(); |
| | | //获取当前的总数 |
| | | 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("http://192.168.10.133:8088/br/inspectRecord/video/"+videoName); |
| | | inspectionRecord.setDocUrl("http://192.168.10.133:8088/br/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); |
| | | } |
| | | } |