feat: 增加导出照片异常统计汇总

dev
huangfeng 3 months ago
parent 19419e9808
commit 808e516fbe

@ -5,7 +5,9 @@ import com.shxy.xymanager_common.base.BaseController;
import com.shxy.xymanager_common.base.ResponseReult; import com.shxy.xymanager_common.base.ResponseReult;
import com.shxy.xymanager_common.bean.ServiceBody; import com.shxy.xymanager_common.bean.ServiceBody;
import com.shxy.xymanager_common.bean.ServiceStatus; 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.model.*;
import com.shxy.xymanager_common.util.DateUtil;
import com.shxy.xymanager_common.util.EasyExcelUtil; import com.shxy.xymanager_common.util.EasyExcelUtil;
import com.shxy.xymanager_common.util.xinyin.HeaderUtil; import com.shxy.xymanager_common.util.xinyin.HeaderUtil;
import com.shxy.xymanager_common.vo.*; import com.shxy.xymanager_common.vo.*;
@ -24,6 +26,7 @@ import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
@ -154,25 +157,26 @@ public class TerminalPhotoController extends BaseController {
ServiceBody<TerminalPhotoSelectListModel> serviceBody = terminalPhotoService.getPhotoList(requestIp, vo); ServiceBody<TerminalPhotoSelectListModel> serviceBody = terminalPhotoService.getPhotoList(requestIp, vo);
if (serviceBody.getCode() == ServiceStatus.SUCCESS) { if (serviceBody.getCode() == ServiceStatus.SUCCESS) {
TerminalPhotoSelectListModel model = serviceBody.getData(); TerminalPhotoSelectListModel model = serviceBody.getData();
List<StatTerm> result = this.buildPhotoStat(model.getList()); List<String> hourList = DateUtil.getEachHour(vo.getStarttime(), vo.getEndtime());
List<StatTerm> result = this.buildPhotoStat(model.getList(), hourList);
return ResponseReult.success(result); return ResponseReult.success(result);
} else { } else {
return ResponseReult.error(serviceBody.getCode(), serviceBody.getMsg()); return ResponseReult.error(serviceBody.getCode(), serviceBody.getMsg());
} }
} }
private List<StatTerm> buildPhotoStat(List<TerminalPhotoSelectListModel.PhotoBean> list) { private List<StatTerm> buildPhotoStat(List<TerminalPhotoSelectListModel.PhotoBean> list, List<String> hourList) {
List<StatTerm> result = new ArrayList<>(); List<StatTerm> result = new ArrayList<>();
if (list != null) { if (list != null) {
for (TerminalPhotoSelectListModel.PhotoBean photo : list) { for (TerminalPhotoSelectListModel.PhotoBean photo : list) {
StatTerm term = this.findStatTerm(result, photo); StatTerm term = this.findStatTerm(result, photo, hourList);
term.addPhoto(photo); term.addPhoto(photo);
} }
} }
return result; return result;
} }
private StatTerm findStatTerm(List<StatTerm> list, TerminalPhotoSelectListModel.PhotoBean photo) { private StatTerm findStatTerm(List<StatTerm> list, TerminalPhotoSelectListModel.PhotoBean photo, List<String> hourList) {
StatTerm the = null; StatTerm the = null;
for (StatTerm item : list) { for (StatTerm item : list) {
if (item.getTermId() == photo.getTermid()) { if (item.getTermId() == photo.getTermid()) {
@ -182,6 +186,7 @@ public class TerminalPhotoController extends BaseController {
} }
if (the == null) { if (the == null) {
the = new StatTerm(); the = new StatTerm();
the.setHourList(hourList);
the.setTermId(photo.getTermid()); the.setTermId(photo.getTermid());
the.setCmdid(photo.getCmdid()); the.setCmdid(photo.getCmdid());
list.add(the); list.add(the);
@ -201,7 +206,8 @@ public class TerminalPhotoController extends BaseController {
ServiceBody<TerminalPhotoSelectListModel> serviceBody = terminalPhotoService.getPhotoList(requestIp, vo); ServiceBody<TerminalPhotoSelectListModel> serviceBody = terminalPhotoService.getPhotoList(requestIp, vo);
if (serviceBody.getCode() == ServiceStatus.SUCCESS) { if (serviceBody.getCode() == ServiceStatus.SUCCESS) {
TerminalPhotoSelectListModel model = serviceBody.getData(); TerminalPhotoSelectListModel model = serviceBody.getData();
List<StatTerm> result = this.buildPhotoStat(model.getList()); List<String> hourList = DateUtil.getEachHour(vo.getStarttime(), vo.getEndtime());
List<StatTerm> result = this.buildPhotoStat(model.getList(), hourList);
response.setContentType("application/vnd.ms-excel"); response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf-8"); 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<TerminalPhotoSelectListModel> serviceBody = terminalPhotoService.getPhotoList(requestIp, vo);
if (serviceBody.getCode() == ServiceStatus.SUCCESS) {
TerminalPhotoSelectListModel model = serviceBody.getData();
List<String> hourList = DateUtil.getEachHour(vo.getStarttime(), vo.getEndtime());
List<StatTerm> list = this.buildPhotoStat(model.getList(), hourList);
List<PhotoStatExcel> result = this.buildPhotoStatExcel(list);
EasyExcelUtil.createExcel(response, "图片统计合计", result, PhotoStatExcel.class);
}
}
private List<PhotoStatExcel> buildPhotoStatExcel(List<StatTerm> list) {
List<PhotoStatExcel> 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<String> 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") @ApiOperation(value = "图片轮询", notes = "图片轮询接口", httpMethod = "POST")
@ApiResponses({@ApiResponse(code = 200, message = "请求成功"), @ApiResponse(code = 400, message = "请求参数没填好"), @ApiResponse(code = 404, message = "请求路径没有或页面跳转路径不对")}) @ApiResponses({@ApiResponse(code = 200, message = "请求成功"), @ApiResponse(code = 400, message = "请求参数没填好"), @ApiResponse(code = 404, message = "请求路径没有或页面跳转路径不对")})

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

@ -9,6 +9,7 @@ import java.util.List;
public class StatChannel { public class StatChannel {
Integer channelId; Integer channelId;
List<StatPreset> presets = new ArrayList<>(); List<StatPreset> presets = new ArrayList<>();
List<String> hourList;
public void addPhoto(TerminalPhotoSelectListModel.PhotoBean photo) { public void addPhoto(TerminalPhotoSelectListModel.PhotoBean photo) {
StatPreset the = null; StatPreset the = null;
@ -20,6 +21,7 @@ public class StatChannel {
} }
if (the == null) { if (the == null) {
the = new StatPreset(); the = new StatPreset();
the.init(hourList);
the.setPresetId(photo.getPresetId()); the.setPresetId(photo.getPresetId());
presets.add(the); presets.add(the);
} }

@ -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() { public int getTotal() {
return timeList.size(); return timeList.size();
} }

@ -11,6 +11,15 @@ public class StatPreset {
Integer presetId; Integer presetId;
List<StatHour> hours = new ArrayList<>(); List<StatHour> hours = new ArrayList<>();
public void init(List<String> hourList) {
for (String str : hourList) {
StatHour hour = new StatHour();
hour.setHour(str);
hour.setBase(2);
hours.add(hour);
}
}
public void addPhoto(TerminalPhotoSelectListModel.PhotoBean photo) { public void addPhoto(TerminalPhotoSelectListModel.PhotoBean photo) {
String hour = DateUtil.format(photo.getPhotoTime(), "yyyy-MM-dd HH"); String hour = DateUtil.format(photo.getPhotoTime(), "yyyy-MM-dd HH");
StatHour the = null; StatHour the = null;

@ -13,6 +13,7 @@ public class StatTerm {
Object uploads; Object uploads;
String cmdid; String cmdid;
List<StatChannel> channels = new ArrayList<>(); List<StatChannel> channels = new ArrayList<>();
List<String> hourList;
public void addPhoto(TerminalPhotoSelectListModel.PhotoBean photo) { public void addPhoto(TerminalPhotoSelectListModel.PhotoBean photo) {
StatChannel the = null; StatChannel the = null;
@ -24,6 +25,7 @@ public class StatTerm {
} }
if (the == null) { if (the == null) {
the = new StatChannel(); the = new StatChannel();
the.setHourList(hourList);
the.setChannelId(photo.getChannelid()); the.setChannelId(photo.getChannelid());
channels.add(the); channels.add(the);
} }

@ -5,8 +5,10 @@ import java.text.SimpleDateFormat;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.List;
public class DateUtil { public class DateUtil {
public final static String defaultDatePattern = "yyyy-MM-dd HH:mm:ss"; public final static String defaultDatePattern = "yyyy-MM-dd HH:mm:ss";
@ -89,10 +91,27 @@ public class DateUtil {
return cal.getTime(); 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) { public static long getDifferenceInDays(Date startDate, Date endDate) {
LocalDate startLocalDate = startDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); LocalDate startLocalDate = startDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
LocalDate endLocalDate = endDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); LocalDate endLocalDate = endDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
return ChronoUnit.DAYS.between(startLocalDate, endLocalDate); return ChronoUnit.DAYS.between(startLocalDate, endLocalDate);
} }
public static List<String> getEachHour(Date startDate, Date endDate) {
List<String> 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;
}
} }

Loading…
Cancel
Save