perf: 去掉原先一套计算到小时的逻辑,直接返回预置位的拍照时间表和实际照片数据

dev
huangfeng 2 months ago
parent c9cf6dcb7b
commit 57363177b5

@ -164,28 +164,27 @@ public class TerminalPhotoController extends BaseController {
ServiceBody<TerminalPhotoSelectListModel> serviceBody = terminalPhotoService.getPhotoList(requestIp, vo, termList); ServiceBody<TerminalPhotoSelectListModel> serviceBody = terminalPhotoService.getPhotoList(requestIp, vo, termList);
if (serviceBody.getCode() == ServiceStatus.SUCCESS) { if (serviceBody.getCode() == ServiceStatus.SUCCESS) {
TerminalPhotoSelectListModel model = serviceBody.getData(); TerminalPhotoSelectListModel model = serviceBody.getData();
List<String> hourList = DateUtil.getEachHour(vo.getStarttime(), vo.getEndtime()); this.buildPhotoStat(termList, model.getList());
this.buildPhotoStat(termList, model.getList(), hourList);
return ResponseReult.success(termList); return ResponseReult.success(termList);
} else { } else {
return ResponseReult.error(serviceBody.getCode(), serviceBody.getMsg()); return ResponseReult.error(serviceBody.getCode(), serviceBody.getMsg());
} }
} }
private void buildPhotoStat(List<StatTerm> termList, List<TerminalPhotoSelectListModel.PhotoBean> list, List<String> hourList) throws Exception { private void buildPhotoStat(List<StatTerm> termList, List<TerminalPhotoSelectListModel.PhotoBean> list) throws Exception {
for (StatTerm statTerm : termList) { for (StatTerm statTerm : termList) {
List<CameraSchedule> scheduleList = cameraScheduleService.list(statTerm.getTermId()); List<CameraSchedule> scheduleList = cameraScheduleService.list(statTerm.getTermId());
statTerm.initScheduleList(scheduleList); statTerm.initScheduleList(scheduleList);
} }
if (list != null) { if (list != null) {
for (TerminalPhotoSelectListModel.PhotoBean photo : list) { for (TerminalPhotoSelectListModel.PhotoBean photo : list) {
StatTerm term = this.findStatTerm(termList, photo, hourList); StatTerm term = this.findStatTerm(termList, photo);
term.addPhoto(photo); term.addPhoto(photo);
} }
} }
} }
private StatTerm findStatTerm(List<StatTerm> list, TerminalPhotoSelectListModel.PhotoBean photo, List<String> hourList) { private StatTerm findStatTerm(List<StatTerm> list, TerminalPhotoSelectListModel.PhotoBean photo) {
StatTerm the = null; StatTerm the = null;
for (StatTerm item : list) { for (StatTerm item : list) {
if (item.getTermId() == photo.getTermid()) { if (item.getTermId() == photo.getTermid()) {
@ -199,109 +198,106 @@ public class TerminalPhotoController extends BaseController {
the.setCmdid(photo.getCmdid()); the.setCmdid(photo.getCmdid());
list.add(the); list.add(the);
} }
the.setHourList(hourList);
return the; return the;
} }
@ApiOperation(value = "图片统计导出", notes = "图片统计导出接口", httpMethod = "POST") // @ApiOperation(value = "图片统计导出", notes = "图片统计导出接口", httpMethod = "POST")
@RequestMapping("/exportPhotoStat") // @RequestMapping("/exportPhotoStat")
@Log(title = "图片统计导出", type = "导出") // @Log(title = "图片统计导出", type = "导出")
public void exportPhotoStat(@RequestHeader HttpHeaders headers, // public void exportPhotoStat(@RequestHeader HttpHeaders headers,
@RequestBody @Validated TerminalPhotoSelectVo vo, // @RequestBody @Validated TerminalPhotoSelectVo vo,
HttpServletResponse response) throws Exception { // HttpServletResponse response) throws Exception {
String requestIp = HeaderUtil.getRequestIp(headers); // String requestIp = HeaderUtil.getRequestIp(headers);
vo.setPageindex(1); // vo.setPageindex(1);
vo.setPagesize(100000); // vo.setPagesize(100000);
List<StatTerm> termList = new ArrayList<>(); // List<StatTerm> termList = new ArrayList<>();
ServiceBody<TerminalPhotoSelectListModel> serviceBody = terminalPhotoService.getPhotoList(requestIp, vo, termList); // ServiceBody<TerminalPhotoSelectListModel> serviceBody = terminalPhotoService.getPhotoList(requestIp, vo, termList);
if (serviceBody.getCode() == ServiceStatus.SUCCESS) { // if (serviceBody.getCode() == ServiceStatus.SUCCESS) {
TerminalPhotoSelectListModel model = serviceBody.getData(); // TerminalPhotoSelectListModel model = serviceBody.getData();
List<String> hourList = DateUtil.getEachHour(vo.getStarttime(), vo.getEndtime()); // this.buildPhotoStat(termList, model.getList());
this.buildPhotoStat(termList, model.getList(), hourList); //
// response.setContentType("application/vnd.ms-excel");
response.setContentType("application/vnd.ms-excel"); // response.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8"); // response.setHeader("Content-Disposition", "attachment; filename="
response.setHeader("Content-Disposition", "attachment; filename=" // + URLEncoder.encode("照片统计.xlsx", "UTF-8"));
+ URLEncoder.encode("照片统计.xlsx", "UTF-8")); // EasyExcelUtil.exportPhotoStat(termList, response.getOutputStream());
EasyExcelUtil.exportPhotoStat(termList, response.getOutputStream()); // }
} // }
}
@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);
List<StatTerm> termList = new ArrayList<>();
ServiceBody<TerminalPhotoSelectListModel> serviceBody = terminalPhotoService.getPhotoList(requestIp, vo, termList);
if (serviceBody.getCode() == ServiceStatus.SUCCESS) {
TerminalPhotoSelectListModel model = serviceBody.getData();
List<String> hourList = DateUtil.getEachHour(vo.getStarttime(), vo.getEndtime());
this.buildPhotoStat(termList, model.getList(), hourList);
List<PhotoStatExcel> result = this.buildPhotoStatExcel(termList);
EasyExcelUtil.createExcel(response, "图片统计合计", result, PhotoStatExcel.class); // @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);
// List<StatTerm> termList = new ArrayList<>();
// ServiceBody<TerminalPhotoSelectListModel> serviceBody = terminalPhotoService.getPhotoList(requestIp, vo, termList);
// if (serviceBody.getCode() == ServiceStatus.SUCCESS) {
// TerminalPhotoSelectListModel model = serviceBody.getData();
// this.buildPhotoStat(termList, model.getList());
// List<PhotoStatExcel> result = this.buildPhotoStatExcel(termList);
//
// EasyExcelUtil.createExcel(response, "图片统计合计", result, PhotoStatExcel.class);
// }
// }
private List<PhotoStatExcel> buildPhotoStatExcel(List<StatTerm> list) { // private List<PhotoStatExcel> buildPhotoStatExcel(List<StatTerm> list) {
List<PhotoStatExcel> result = new ArrayList<>(); // List<PhotoStatExcel> result = new ArrayList<>();
for (StatTerm term : list) { // for (StatTerm term : list) {
PhotoStatExcel item = new PhotoStatExcel(); // PhotoStatExcel item = new PhotoStatExcel();
item.setCmdid(term.getCmdid()); // item.setCmdid(term.getCmdid());
item.setTotal(term.getTotal()); // item.setTotal(term.getTotal());
result.add(item); // result.add(item);
if (term.getWrongCount() > 0) { // if (term.getWrongCount() > 0) {
item.setStatus("有异常"); // item.setStatus("有异常");
} else { // } else {
item.setStatus("正常"); // item.setStatus("正常");
} // }
for (StatChannel channel : term.getChannels()) { // for (StatChannel channel : term.getChannels()) {
PhotoStatExcel item2 = new PhotoStatExcel(); // PhotoStatExcel item2 = new PhotoStatExcel();
item2.setChannelId(channel.getChannelId()); // item2.setChannelId(channel.getChannelId());
item2.setTotal(channel.getTotal()); // item2.setTotal(channel.getTotal());
result.add(item2); // result.add(item2);
if (channel.getWrongCount() > 0) { // if (channel.getWrongCount() > 0) {
item2.setStatus("有异常"); // item2.setStatus("有异常");
} else { // } else {
item2.setStatus("正常"); // item2.setStatus("正常");
} // }
for (StatPreset preset : channel.getPresets()) { // for (StatPreset preset : channel.getPresets()) {
PhotoStatExcel item3 = new PhotoStatExcel(); // PhotoStatExcel item3 = new PhotoStatExcel();
item3.setChannelId(channel.getChannelId()); // item3.setChannelId(channel.getChannelId());
item3.setPresetId(preset.getPresetId()); // item3.setPresetId(preset.getPresetId());
item3.setTotal(preset.getTotal()); // item3.setTotal(preset.getTotal());
result.add(item3); // result.add(item3);
if (preset.getWrongCount() > 0) { // if (preset.getWrongCount() > 0) {
item3.setStatus("有异常"); // item3.setStatus("有异常");
} else { // } else {
item3.setStatus("正常"); // item3.setStatus("正常");
} // }
for (StatHour hour : preset.getHours()) { // for (StatHour hour : preset.getHours()) {
if (hour.isWrong()) { // if (hour.isWrong()) {
PhotoStatExcel err = new PhotoStatExcel(); // PhotoStatExcel err = new PhotoStatExcel();
err.setChannelId(channel.getChannelId()); // err.setChannelId(channel.getChannelId());
err.setPresetId(preset.getPresetId()); // err.setPresetId(preset.getPresetId());
err.setHour(hour.getHour()); // err.setHour(hour.getHour());
List<String> dateList = new ArrayList<>(); // List<String> dateList = new ArrayList<>();
for (Date date : hour.getTimeList()) { // for (Date date : hour.getTimeList()) {
dateList.add(DateUtil.format(date)); // dateList.add(DateUtil.format(date));
} // }
err.setTotal(dateList.size()); // err.setTotal(dateList.size());
err.setStatus(hour.getWrongDetail()); // err.setStatus(hour.getWrongDetail());
err.setDetail(String.join(System.lineSeparator(), dateList)); // err.setDetail(String.join(System.lineSeparator(), dateList));
result.add(err); // result.add(err);
} // }
} // }
} // }
} // }
} // }
return result; // return result;
} // }
@PostMapping("uploadPhoto") @PostMapping("uploadPhoto")
@ApiOperation("上传图片") @ApiOperation("上传图片")

@ -11,7 +11,6 @@ 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;
@ -26,7 +25,6 @@ public class StatChannel {
the.setPresetId(photo.getPresetId()); the.setPresetId(photo.getPresetId());
presets.add(the); presets.add(the);
} }
the.init(hourList);
the.addPhoto(photo); the.addPhoto(photo);
} }

@ -5,58 +5,25 @@ import com.shxy.xymanager_common.util.DateUtil;
import lombok.Data; import lombok.Data;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
@Data @Data
public class StatPreset { public class StatPreset {
Integer presetId; Integer presetId;
List<StatHour> hours = new ArrayList<>();
List<ScheduleDetailsDto> scheduleList = new ArrayList<>(); List<ScheduleDetailsDto> scheduleList = new ArrayList<>();
List<Date> timeList = new ArrayList<>();
public void init(List<String> hourList) {
if (hours.size() == 0) {
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"); timeList.add(photo.getPhotoTime());
StatHour the = null;
for (StatHour item : hours) {
if (item.getHour().equals(hour)) {
the = item;
break;
}
}
if (the == null) {
the = new StatHour();
the.setHour(hour);
the.setBase(2);
hours.add(the);
}
the.addPhoto(photo);
} }
public int getTotal() { public int getTotal() {
int total = 0; return timeList.size();
for (StatHour item : hours) {
total = total + item.getTotal();
}
return total;
} }
public int getWrongCount() { public int getWrongCount() {
int count = 0; int count = 0;
for (StatHour item : hours) {
if (item.isWrong()) {
count++;
}
}
return count; return count;
} }

@ -16,7 +16,6 @@ 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;
@ -31,7 +30,6 @@ public class StatTerm {
the.setChannelId(photo.getChannelid()); the.setChannelId(photo.getChannelid());
channels.add(the); channels.add(the);
} }
the.setHourList(hourList);
the.addPhoto(photo); the.addPhoto(photo);
} }

@ -225,58 +225,58 @@ public class EasyExcelUtil implements RowWriteHandler {
return cellMerge; return cellMerge;
} }
public static void exportPhotoStat(List<StatTerm> dataList, OutputStream output) { // public static void exportPhotoStat(List<StatTerm> dataList, OutputStream output) {
// 导出Excel // // 导出Excel
ExcelWriter excelWriter = EasyExcel.write(output).inMemory(true) // ExcelWriter excelWriter = EasyExcel.write(output).inMemory(true)
.registerWriteHandler(new SimpleColumnWidthStyleStrategy(24)).build(); // .registerWriteHandler(new SimpleColumnWidthStyleStrategy(24)).build();
//
writerSheet(excelWriter, 0, dataList); // writerSheet(excelWriter, 0, dataList);
//
excelWriter.finish(); // excelWriter.finish();
} // }
private static void writerSheet(ExcelWriter excelWriter, int idx, List<StatTerm> dataList) { // private static void writerSheet(ExcelWriter excelWriter, int idx, List<StatTerm> dataList) {
// 表头 // // 表头
List<List<String>> heads = new ArrayList<>(); // List<List<String>> heads = new ArrayList<>();
List<String> head = new ArrayList<>(); // List<String> head = new ArrayList<>();
head.add("时间(小时)"); // head.add("时间(小时)");
heads.add(head); // heads.add(head);
//
LinkedHashMap<String, List<String>> lineMap = new LinkedHashMap<>(); // LinkedHashMap<String, List<String>> lineMap = new LinkedHashMap<>();
// 内容 // // 内容
List<List<String>> list = new ArrayList<>(); // List<List<String>> list = new ArrayList<>();
for (StatTerm term : dataList) { // for (StatTerm term : dataList) {
for (StatChannel channel : term.getChannels()) { // for (StatChannel channel : term.getChannels()) {
for (StatPreset preset : channel.getPresets()) { // for (StatPreset preset : channel.getPresets()) {
head = new ArrayList<>(); // head = new ArrayList<>();
String name = term.getCmdid() + "-" + channel.getChannelId() + "-" + preset.getPresetId(); // String name = term.getCmdid() + "-" + channel.getChannelId() + "-" + preset.getPresetId();
head.add(name); // head.add(name);
heads.add(head); // heads.add(head);
for (StatHour hour : preset.getHours()) { // for (StatHour hour : preset.getHours()) {
List<String> line = lineMap.get(hour.getHour()); // List<String> line = lineMap.get(hour.getHour());
if (line == null) { // if (line == null) {
line = new ArrayList<>(); // line = new ArrayList<>();
lineMap.put(hour.getHour(), line); // lineMap.put(hour.getHour(), line);
line.add(String.valueOf(hour.getHour())); // line.add(String.valueOf(hour.getHour()));
} // }
if (hour.isWrong()) { // if (hour.isWrong()) {
List<String> dateList = new ArrayList<>(); // List<String> dateList = new ArrayList<>();
for (Date date : hour.getTimeList()) { // for (Date date : hour.getTimeList()) {
dateList.add(DateUtil.format(date)); // dateList.add(DateUtil.format(date));
} // }
line.add(String.join(System.lineSeparator(), dateList)); // line.add(String.join(System.lineSeparator(), dateList));
} else { // } else {
line.add(hour.getTotal() + "张"); // line.add(hour.getTotal() + "张");
} // }
} // }
} // }
} // }
} // }
list.addAll(lineMap.values()); // list.addAll(lineMap.values());
//
WriteSheet writeSheet = EasyExcel.writerSheet(idx, "照片统计") // WriteSheet writeSheet = EasyExcel.writerSheet(idx, "照片统计")
.head(heads) // .head(heads)
.build(); // .build();
excelWriter.write(list, writeSheet); // excelWriter.write(list, writeSheet);
} // }
} }

@ -614,7 +614,7 @@ public class TerminalPhotoServiceImpl implements TerminalPhotoService {
// } // }
PageInfo<View_Dy_Line_Tower_Terminals> result = terminalExtService.getTerminalPage(dyid, lineid, towerid, termid, PageInfo<View_Dy_Line_Tower_Terminals> result = terminalExtService.getTerminalPage(dyid, lineid, towerid, termid,
search, null, null, search,
null, null, null, vo.getActivityId(), null, null, null, vo.getActivityId(),
1, 100000); 1, 100000);
if (!CollectionUtils.isEmpty(result.getList())) { if (!CollectionUtils.isEmpty(result.getList())) {
@ -625,6 +625,8 @@ public class TerminalPhotoServiceImpl implements TerminalPhotoService {
statTerm.setCmdid(terminal.getCmdid()); statTerm.setCmdid(terminal.getCmdid());
termList.add(statTerm); termList.add(statTerm);
} }
} else {
termidlist.add(-1);
} }
if (channelid == null || channelid.intValue() == -1) { if (channelid == null || channelid.intValue() == -1) {

Loading…
Cancel
Save