diff --git a/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/TerminalPhotoController.java b/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/TerminalPhotoController.java index 2eef4a9..70fd284 100644 --- a/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/TerminalPhotoController.java +++ b/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/TerminalPhotoController.java @@ -5,7 +5,9 @@ import com.shxy.xymanager_common.base.BaseController; import com.shxy.xymanager_common.base.ResponseReult; import com.shxy.xymanager_common.bean.ServiceBody; import com.shxy.xymanager_common.bean.ServiceStatus; +import com.shxy.xymanager_common.excel.PhotoStatExcel; import com.shxy.xymanager_common.model.*; +import com.shxy.xymanager_common.util.DateUtil; import com.shxy.xymanager_common.util.EasyExcelUtil; import com.shxy.xymanager_common.util.xinyin.HeaderUtil; import com.shxy.xymanager_common.vo.*; @@ -24,6 +26,7 @@ import javax.servlet.http.HttpServletResponse; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.ArrayList; +import java.util.Date; import java.util.List; @@ -154,25 +157,26 @@ public class TerminalPhotoController extends BaseController { ServiceBody serviceBody = terminalPhotoService.getPhotoList(requestIp, vo); if (serviceBody.getCode() == ServiceStatus.SUCCESS) { TerminalPhotoSelectListModel model = serviceBody.getData(); - List result = this.buildPhotoStat(model.getList()); + List hourList = DateUtil.getEachHour(vo.getStarttime(), vo.getEndtime()); + List result = this.buildPhotoStat(model.getList(), hourList); return ResponseReult.success(result); } else { return ResponseReult.error(serviceBody.getCode(), serviceBody.getMsg()); } } - private List buildPhotoStat(List list) { + private List buildPhotoStat(List list, List hourList) { List result = new ArrayList<>(); if (list != null) { for (TerminalPhotoSelectListModel.PhotoBean photo : list) { - StatTerm term = this.findStatTerm(result, photo); + StatTerm term = this.findStatTerm(result, photo, hourList); term.addPhoto(photo); } } return result; } - private StatTerm findStatTerm(List list, TerminalPhotoSelectListModel.PhotoBean photo) { + private StatTerm findStatTerm(List list, TerminalPhotoSelectListModel.PhotoBean photo, List hourList) { StatTerm the = null; for (StatTerm item : list) { if (item.getTermId() == photo.getTermid()) { @@ -182,6 +186,7 @@ public class TerminalPhotoController extends BaseController { } if (the == null) { the = new StatTerm(); + the.setHourList(hourList); the.setTermId(photo.getTermid()); the.setCmdid(photo.getCmdid()); list.add(the); @@ -201,7 +206,8 @@ public class TerminalPhotoController extends BaseController { ServiceBody serviceBody = terminalPhotoService.getPhotoList(requestIp, vo); if (serviceBody.getCode() == ServiceStatus.SUCCESS) { TerminalPhotoSelectListModel model = serviceBody.getData(); - List result = this.buildPhotoStat(model.getList()); + List hourList = DateUtil.getEachHour(vo.getStarttime(), vo.getEndtime()); + List result = this.buildPhotoStat(model.getList(), hourList); response.setContentType("application/vnd.ms-excel"); response.setCharacterEncoding("utf-8"); @@ -211,6 +217,81 @@ public class TerminalPhotoController extends BaseController { } } + @ApiOperation(value = "图片统计导出合计", notes = "图片统计导出合计接口", httpMethod = "POST") + @RequestMapping("/exportPhotoStatSum") + @Log(title = "图片统计导出合计", type = "导出") + public void exportPhotoStatSum(@RequestHeader HttpHeaders headers, + @RequestBody @Validated TerminalPhotoSelectVo vo, + HttpServletResponse response) throws Exception { + String requestIp = HeaderUtil.getRequestIp(headers); + vo.setPageindex(1); + vo.setPagesize(100000); + ServiceBody serviceBody = terminalPhotoService.getPhotoList(requestIp, vo); + if (serviceBody.getCode() == ServiceStatus.SUCCESS) { + TerminalPhotoSelectListModel model = serviceBody.getData(); + List hourList = DateUtil.getEachHour(vo.getStarttime(), vo.getEndtime()); + List list = this.buildPhotoStat(model.getList(), hourList); + List result = this.buildPhotoStatExcel(list); + + EasyExcelUtil.createExcel(response, "图片统计合计", result, PhotoStatExcel.class); + } + } + + private List buildPhotoStatExcel(List list) { + List result = new ArrayList<>(); + for (StatTerm term : list) { + PhotoStatExcel item = new PhotoStatExcel(); + item.setCmdid(term.getCmdid()); + item.setTotal(term.getTotal()); + result.add(item); + if (term.getWrongCount() > 0) { + item.setStatus("有异常"); + } else { + item.setStatus("正常"); + } + for (StatChannel channel : term.getChannels()) { + PhotoStatExcel item2 = new PhotoStatExcel(); + item2.setChannelId(channel.getChannelId()); + item2.setTotal(channel.getTotal()); + result.add(item2); + if (channel.getWrongCount() > 0) { + item2.setStatus("有异常"); + } else { + item2.setStatus("正常"); + } + for (StatPreset preset : channel.getPresets()) { + PhotoStatExcel item3 = new PhotoStatExcel(); + item3.setChannelId(channel.getChannelId()); + item3.setPresetId(preset.getPresetId()); + item3.setTotal(preset.getTotal()); + result.add(item3); + if (preset.getWrongCount() > 0) { + item3.setStatus("有异常"); + } else { + item3.setStatus("正常"); + } + for (StatHour hour : preset.getHours()) { + if (hour.isWrong()) { + PhotoStatExcel err = new PhotoStatExcel(); + err.setChannelId(channel.getChannelId()); + err.setPresetId(preset.getPresetId()); + err.setHour(hour.getHour()); + List dateList = new ArrayList<>(); + for (Date date : hour.getTimeList()) { + dateList.add(DateUtil.format(date)); + } + err.setTotal(dateList.size()); + err.setStatus(hour.getWrongDetail()); + err.setDetail(String.join(System.lineSeparator(), dateList)); + result.add(err); + } + } + } + } + } + return result; + } + @ApiOperation(value = "图片轮询", notes = "图片轮询接口", httpMethod = "POST") @ApiResponses({@ApiResponse(code = 200, message = "请求成功"), @ApiResponse(code = 400, message = "请求参数没填好"), @ApiResponse(code = 404, message = "请求路径没有或页面跳转路径不对")}) diff --git a/xymanager_common/src/main/java/com/shxy/xymanager_common/excel/PhotoStatExcel.java b/xymanager_common/src/main/java/com/shxy/xymanager_common/excel/PhotoStatExcel.java new file mode 100644 index 0000000..52b3fe0 --- /dev/null +++ b/xymanager_common/src/main/java/com/shxy/xymanager_common/excel/PhotoStatExcel.java @@ -0,0 +1,37 @@ +package com.shxy.xymanager_common.excel; + +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.annotation.write.style.ColumnWidth; +import lombok.Data; + +@Data +public class PhotoStatExcel { + + @ColumnWidth(20) + @ExcelProperty(value = "cmdid") + String cmdid; + + @ColumnWidth(15) + @ExcelProperty(value = "通道号") + Integer channelId; + + @ColumnWidth(15) + @ExcelProperty(value = "预置位") + Integer presetId; + + @ColumnWidth(15) + @ExcelProperty(value = "总图片数") + Integer total; + + @ColumnWidth(15) + @ExcelProperty(value = "状态") + String status; + + @ColumnWidth(20) + @ExcelProperty(value = "时间") + String hour; + + @ColumnWidth(30) + @ExcelProperty(value = "明细") + String detail; +} diff --git a/xymanager_common/src/main/java/com/shxy/xymanager_common/model/StatChannel.java b/xymanager_common/src/main/java/com/shxy/xymanager_common/model/StatChannel.java index d08e33f..39dad21 100644 --- a/xymanager_common/src/main/java/com/shxy/xymanager_common/model/StatChannel.java +++ b/xymanager_common/src/main/java/com/shxy/xymanager_common/model/StatChannel.java @@ -9,6 +9,7 @@ import java.util.List; public class StatChannel { Integer channelId; List presets = new ArrayList<>(); + List hourList; public void addPhoto(TerminalPhotoSelectListModel.PhotoBean photo) { StatPreset the = null; @@ -20,6 +21,7 @@ public class StatChannel { } if (the == null) { the = new StatPreset(); + the.init(hourList); the.setPresetId(photo.getPresetId()); presets.add(the); } diff --git a/xymanager_common/src/main/java/com/shxy/xymanager_common/model/StatHour.java b/xymanager_common/src/main/java/com/shxy/xymanager_common/model/StatHour.java index 003fea5..b8dd1f2 100644 --- a/xymanager_common/src/main/java/com/shxy/xymanager_common/model/StatHour.java +++ b/xymanager_common/src/main/java/com/shxy/xymanager_common/model/StatHour.java @@ -34,6 +34,14 @@ public class StatHour { } } + public String getWrongDetail() { + if (timeList.size() > base) { + return "多" + (timeList.size() - base); + } else { + return "少" + (base - timeList.size()); + } + } + public int getTotal() { return timeList.size(); } diff --git a/xymanager_common/src/main/java/com/shxy/xymanager_common/model/StatPreset.java b/xymanager_common/src/main/java/com/shxy/xymanager_common/model/StatPreset.java index 5c855ca..8c68741 100644 --- a/xymanager_common/src/main/java/com/shxy/xymanager_common/model/StatPreset.java +++ b/xymanager_common/src/main/java/com/shxy/xymanager_common/model/StatPreset.java @@ -11,6 +11,15 @@ public class StatPreset { Integer presetId; List hours = new ArrayList<>(); + public void init(List hourList) { + for (String str : hourList) { + StatHour hour = new StatHour(); + hour.setHour(str); + hour.setBase(2); + hours.add(hour); + } + } + public void addPhoto(TerminalPhotoSelectListModel.PhotoBean photo) { String hour = DateUtil.format(photo.getPhotoTime(), "yyyy-MM-dd HH"); StatHour the = null; diff --git a/xymanager_common/src/main/java/com/shxy/xymanager_common/model/StatTerm.java b/xymanager_common/src/main/java/com/shxy/xymanager_common/model/StatTerm.java index 317962d..5ab752a 100644 --- a/xymanager_common/src/main/java/com/shxy/xymanager_common/model/StatTerm.java +++ b/xymanager_common/src/main/java/com/shxy/xymanager_common/model/StatTerm.java @@ -13,6 +13,7 @@ public class StatTerm { Object uploads; String cmdid; List channels = new ArrayList<>(); + List hourList; public void addPhoto(TerminalPhotoSelectListModel.PhotoBean photo) { StatChannel the = null; @@ -24,6 +25,7 @@ public class StatTerm { } if (the == null) { the = new StatChannel(); + the.setHourList(hourList); the.setChannelId(photo.getChannelid()); channels.add(the); } diff --git a/xymanager_common/src/main/java/com/shxy/xymanager_common/util/DateUtil.java b/xymanager_common/src/main/java/com/shxy/xymanager_common/util/DateUtil.java index 2ef37b4..5170aa3 100644 --- a/xymanager_common/src/main/java/com/shxy/xymanager_common/util/DateUtil.java +++ b/xymanager_common/src/main/java/com/shxy/xymanager_common/util/DateUtil.java @@ -5,8 +5,10 @@ import java.text.SimpleDateFormat; import java.time.LocalDate; import java.time.ZoneId; import java.time.temporal.ChronoUnit; +import java.util.ArrayList; import java.util.Calendar; import java.util.Date; +import java.util.List; public class DateUtil { public final static String defaultDatePattern = "yyyy-MM-dd HH:mm:ss"; @@ -89,10 +91,27 @@ public class DateUtil { return cal.getTime(); } + public static Date addHour(Date date, int n) { + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + cal.add(Calendar.HOUR_OF_DAY, n); + return cal.getTime(); + } + public static long getDifferenceInDays(Date startDate, Date endDate) { LocalDate startLocalDate = startDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); LocalDate endLocalDate = endDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); return ChronoUnit.DAYS.between(startLocalDate, endLocalDate); } + public static List getEachHour(Date startDate, Date endDate) { + List result = new ArrayList<>(); + while (startDate.before(endDate)) { + String hour = DateUtil.format(startDate, "yyyy-MM-dd HH"); + result.add(hour); + startDate = addHour(startDate, 1); + } + return result; + } + }