Commit 86f9720e by xmh

<feat> 存储方案配置的读写

<feat> 数据检索,数据导出优化
1 parent 7e0e11d8
package com.viontech.fanxing.commons.base; package com.viontech.fanxing.commons.base;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.viontech.keliu.util.FileUtil; import com.viontech.keliu.util.JsonMessageUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List; import java.util.List;
import static com.viontech.keliu.util.JsonMessageUtil.getErrorJsonMsg; import static com.viontech.keliu.util.JsonMessageUtil.getErrorJsonMsg;
...@@ -76,6 +72,14 @@ public abstract class BaseController<O extends BaseModel, T extends VoInterface< ...@@ -76,6 +72,14 @@ public abstract class BaseController<O extends BaseModel, T extends VoInterface<
return true; return true;
} }
public static JsonMessageUtil.JsonMessage<Object> success() {
return JsonMessageUtil.getSuccessJsonMsg(MESSAGE_SELECT_SUCCESS, null);
}
public static <T> JsonMessageUtil.JsonMessage<T> success(T t) {
return JsonMessageUtil.getSuccessJsonMsg(MESSAGE_SELECT_SUCCESS, t);
}
/** /**
* 通用添加方法 * 通用添加方法
* *
...@@ -179,7 +183,6 @@ public abstract class BaseController<O extends BaseModel, T extends VoInterface< ...@@ -179,7 +183,6 @@ public abstract class BaseController<O extends BaseModel, T extends VoInterface<
} }
} }
/** /**
* 获取到执行各项操作需要的service * 获取到执行各项操作需要的service
* *
...@@ -195,6 +198,4 @@ public abstract class BaseController<O extends BaseModel, T extends VoInterface< ...@@ -195,6 +198,4 @@ public abstract class BaseController<O extends BaseModel, T extends VoInterface<
* @return 查询条件对象 * @return 查询条件对象
*/ */
protected abstract BaseExample getExample(T t, int type); protected abstract BaseExample getExample(T t, int type);
} }
...@@ -47,20 +47,27 @@ public class ContentController extends ContentBaseController { ...@@ -47,20 +47,27 @@ public class ContentController extends ContentBaseController {
@GetMapping("/imageKeepConfig") @GetMapping("/imageKeepConfig")
@ResponseBody @ResponseBody
public JsonMessageUtil.JsonMessage<ImageKeepConfig> selectImageKeepConfig() { public JsonMessageUtil.JsonMessage<ImageKeepConfig> selectImageKeepConfig() {
return JsonMessageUtil.getSuccessJsonMsg(contentService.selectImageKeepConfig()); return success(contentService.selectImageKeepConfig());
}
@PostMapping("/imageKeepConfig")
@ResponseBody
public JsonMessageUtil.JsonMessage<Object> addOrUpdateImageKeepConfig(@RequestBody ImageKeepConfig imageKeepConfig) {
contentService.addOrUpdateImageKeepConfig(imageKeepConfig);
return success();
} }
@PostMapping("/timing") @PostMapping("/timing")
@ResponseBody @ResponseBody
public JsonMessageUtil.JsonMessage<Object> timing(@RequestBody JSONObject jsonObject) { public JsonMessageUtil.JsonMessage<Object> timing(@RequestBody JSONObject jsonObject) {
contentService.addOrUpdateTimingConfig(jsonObject); contentService.addOrUpdateTimingConfig(jsonObject);
return JsonMessageUtil.getSuccessJsonMsg(MESSAGE_SELECT_SUCCESS, null); return success();
} }
@GetMapping("/timing") @GetMapping("/timing")
@ResponseBody @ResponseBody
public JsonMessageUtil.JsonMessage<JSONObject> getTiming() { public JsonMessageUtil.JsonMessage<JSONObject> getTiming() {
JSONObject timingConfig = contentService.getTimingConfig(); JSONObject timingConfig = contentService.getTimingConfig();
return JsonMessageUtil.getSuccessJsonMsg(MESSAGE_SELECT_SUCCESS, timingConfig); return success(timingConfig);
} }
} }
\ No newline at end of file \ No newline at end of file
...@@ -14,6 +14,8 @@ public interface ContentService extends BaseService<Content> { ...@@ -14,6 +14,8 @@ public interface ContentService extends BaseService<Content> {
ImageKeepConfig selectImageKeepConfig(); ImageKeepConfig selectImageKeepConfig();
void addOrUpdateImageKeepConfig(ImageKeepConfig imageKeepConfig);
void addOrUpdateTimingConfig(JSONObject jsonObject); void addOrUpdateTimingConfig(JSONObject jsonObject);
JSONObject getTimingConfig(); JSONObject getTimingConfig();
......
...@@ -16,17 +16,18 @@ import java.util.List; ...@@ -16,17 +16,18 @@ import java.util.List;
@Service @Service
public class ContentServiceImpl extends BaseServiceImpl<Content> implements ContentService { public class ContentServiceImpl extends BaseServiceImpl<Content> implements ContentService {
private static final String PLATFORM_CONFIG = "platformConfig"; private static final String TYPE_PLATFORM_CONFIG = "platformConfig";
private static final String TIMING_CONFIG = "timingConfig"; private static final String NAME_TIMING_CONFIG = "timingConfig";
private static final String NAME_IMAGE_KEEP_CONFIG = "imageKeepConfig";
@Resource @Resource
private ContentMapper contentMapper; private ContentMapper contentMapper;
@Override @Override
public BaseMapper<Content> getMapper() { public BaseMapper<Content> getMapper() {
return contentMapper; return contentMapper;
} }
@Override @Override
public List<Content> selectByExampleWithBlob(ContentExample contentExample) { public List<Content> selectByExampleWithBlob(ContentExample contentExample) {
return contentMapper.selectByExampleWithBLOBs(contentExample); return contentMapper.selectByExampleWithBLOBs(contentExample);
...@@ -35,7 +36,7 @@ public class ContentServiceImpl extends BaseServiceImpl<Content> implements Cont ...@@ -35,7 +36,7 @@ public class ContentServiceImpl extends BaseServiceImpl<Content> implements Cont
@Override @Override
public ImageKeepConfig selectImageKeepConfig() { public ImageKeepConfig selectImageKeepConfig() {
ContentExample contentExample = new ContentExample(); ContentExample contentExample = new ContentExample();
contentExample.createCriteria().andTypeEqualTo(PLATFORM_CONFIG).andNameEqualTo("imageKeepConfig"); contentExample.createCriteria().andTypeEqualTo(TYPE_PLATFORM_CONFIG).andNameEqualTo(NAME_IMAGE_KEEP_CONFIG);
List<Content> contents = contentMapper.selectByExampleWithBLOBs(contentExample); List<Content> contents = contentMapper.selectByExampleWithBLOBs(contentExample);
if (contents.size() > 0) { if (contents.size() > 0) {
String content = contents.get(0).getContent(); String content = contents.get(0).getContent();
...@@ -46,30 +47,24 @@ public class ContentServiceImpl extends BaseServiceImpl<Content> implements Cont ...@@ -46,30 +47,24 @@ public class ContentServiceImpl extends BaseServiceImpl<Content> implements Cont
} }
@Override @Override
public void addOrUpdateImageKeepConfig(ImageKeepConfig imageKeepConfig) {
addOrUpdate(TYPE_PLATFORM_CONFIG, NAME_IMAGE_KEEP_CONFIG, JSON.toJSONString(imageKeepConfig));
}
@Override
public void addOrUpdateTimingConfig(JSONObject jsonObject) { public void addOrUpdateTimingConfig(JSONObject jsonObject) {
ContentExample contentExample = new ContentExample(); ContentExample contentExample = new ContentExample();
contentExample.createCriteria().andTypeEqualTo(PLATFORM_CONFIG).andNameEqualTo(TIMING_CONFIG); contentExample.createCriteria().andTypeEqualTo(TYPE_PLATFORM_CONFIG).andNameEqualTo(NAME_TIMING_CONFIG);
List<Content> contents = contentMapper.selectByExampleWithBLOBs(contentExample); addOrUpdate(TYPE_PLATFORM_CONFIG, NAME_TIMING_CONFIG, jsonObject.toJSONString());
if (contents.size() > 0) {
Content content = contents.get(0);
content.setContent(jsonObject.toJSONString());
contentMapper.updateByPrimaryKeySelective(content);
} else {
Content content = new Content();
content.setName(TIMING_CONFIG);
content.setType(PLATFORM_CONFIG);
content.setContent(jsonObject.toJSONString());
contentMapper.insertSelective(content);
}
// todo 发给运维服务 // todo 发给运维服务
} }
@Override @Override
public JSONObject getTimingConfig() { public JSONObject getTimingConfig() {
ContentExample contentExample = new ContentExample(); ContentExample contentExample = new ContentExample();
contentExample.createCriteria().andTypeEqualTo(PLATFORM_CONFIG).andNameEqualTo(TIMING_CONFIG); contentExample.createCriteria().andTypeEqualTo(TYPE_PLATFORM_CONFIG).andNameEqualTo(NAME_TIMING_CONFIG);
List<Content> contents = contentMapper.selectByExampleWithBLOBs(contentExample); List<Content> contents = contentMapper.selectByExampleWithBLOBs(contentExample);
if (contents.size() > 0) { if (contents.size() > 0) {
return JSONObject.parseObject(contents.get(0).getContent()); return JSONObject.parseObject(contents.get(0).getContent());
...@@ -77,4 +72,22 @@ public class ContentServiceImpl extends BaseServiceImpl<Content> implements Cont ...@@ -77,4 +72,22 @@ public class ContentServiceImpl extends BaseServiceImpl<Content> implements Cont
return null; return null;
} }
} }
private void addOrUpdate(String type, String name, String s) {
ContentExample contentExample = new ContentExample();
contentExample.createCriteria().andTypeEqualTo(type).andNameEqualTo(name);
List<Content> contents = contentMapper.selectByExampleWithBLOBs(contentExample);
Content content;
if (contents.size() > 0) {
content = contents.get(0);
content.setContent(s);
contentMapper.updateByPrimaryKeySelective(content);
} else {
content = new Content();
content.setName(name);
content.setType(type);
content.setContent(s);
contentMapper.insertSelective(content);
}
}
} }
\ No newline at end of file \ No newline at end of file
...@@ -6,6 +6,7 @@ import com.alibaba.fastjson.serializer.SerializeFilter; ...@@ -6,6 +6,7 @@ import com.alibaba.fastjson.serializer.SerializeFilter;
import com.alibaba.fastjson.serializer.SimplePropertyPreFilter; import com.alibaba.fastjson.serializer.SimplePropertyPreFilter;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.viontech.fanxing.commons.base.BaseExample; import com.viontech.fanxing.commons.base.BaseExample;
import com.viontech.fanxing.commons.exception.FanXingException;
import com.viontech.fanxing.commons.model.BehaviorExample; import com.viontech.fanxing.commons.model.BehaviorExample;
import com.viontech.fanxing.commons.model.ExportData; import com.viontech.fanxing.commons.model.ExportData;
import com.viontech.fanxing.commons.vo.BehaviorVo; import com.viontech.fanxing.commons.vo.BehaviorVo;
...@@ -69,6 +70,12 @@ public class BehaviorController extends BehaviorBaseController { ...@@ -69,6 +70,12 @@ public class BehaviorController extends BehaviorBaseController {
SimplePropertyPreFilter simplePropertyPreFilter = new SimplePropertyPreFilter(); SimplePropertyPreFilter simplePropertyPreFilter = new SimplePropertyPreFilter();
simplePropertyPreFilter.getExcludes().add("model"); simplePropertyPreFilter.getExcludes().add("model");
String param = JSON.toJSONString(behaviorVo, SerializeConfig.globalInstance, new SerializeFilter[]{simplePropertyPreFilter}, "yyyy-MM-dd HH:mm:ss", JSON.DEFAULT_GENERATE_FEATURE); String param = JSON.toJSONString(behaviorVo, SerializeConfig.globalInstance, new SerializeFilter[]{simplePropertyPreFilter}, "yyyy-MM-dd HH:mm:ss", JSON.DEFAULT_GENERATE_FEATURE);
int i = behaviorService.countByExample(getExample(behaviorVo));
if (i == 0) {
throw new FanXingException("数据为空");
}
ExportData exportData = new ExportData(); ExportData exportData = new ExportData();
exportData.setName(name); exportData.setName(name);
exportData.setParam(param); exportData.setParam(param);
......
...@@ -51,6 +51,13 @@ public class FlowEventController extends FlowEventBaseController { ...@@ -51,6 +51,13 @@ public class FlowEventController extends FlowEventBaseController {
SimplePropertyPreFilter simplePropertyPreFilter = new SimplePropertyPreFilter(); SimplePropertyPreFilter simplePropertyPreFilter = new SimplePropertyPreFilter();
simplePropertyPreFilter.getExcludes().add("model"); simplePropertyPreFilter.getExcludes().add("model");
String param = JSON.toJSONString(trafficFlowRequestVo, SerializeConfig.globalInstance, new SerializeFilter[]{simplePropertyPreFilter}, "yyyy-MM-dd HH:mm:ss", JSON.DEFAULT_GENERATE_FEATURE); String param = JSON.toJSONString(trafficFlowRequestVo, SerializeConfig.globalInstance, new SerializeFilter[]{simplePropertyPreFilter}, "yyyy-MM-dd HH:mm:ss", JSON.DEFAULT_GENERATE_FEATURE);
Map<String, Object> result = statisticsResult(trafficFlowRequestVo);
int totalNum = (int) result.get("total_num");
if (totalNum == 0) {
throw new RuntimeException("数据为空");
}
ExportData exportData = new ExportData(); ExportData exportData = new ExportData();
exportData.setName(name); exportData.setName(name);
exportData.setParam(param); exportData.setParam(param);
......
...@@ -2,6 +2,7 @@ package com.viontech.fanxing.query.controller.web; ...@@ -2,6 +2,7 @@ package com.viontech.fanxing.query.controller.web;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializeConfig; import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SerializeFilter; import com.alibaba.fastjson.serializer.SerializeFilter;
import com.alibaba.fastjson.serializer.SimplePropertyPreFilter; import com.alibaba.fastjson.serializer.SimplePropertyPreFilter;
...@@ -46,6 +47,9 @@ public class TrafficController extends TrafficBaseController { ...@@ -46,6 +47,9 @@ public class TrafficController extends TrafficBaseController {
@RequestMapping(value = "", method = RequestMethod.GET) @RequestMapping(value = "", method = RequestMethod.GET)
public Object page(TrafficVo trafficVo, @RequestParam(value = "page", defaultValue = "1") int page, @RequestParam(value = "pageSize", defaultValue = "30") int pageSize, public Object page(TrafficVo trafficVo, @RequestParam(value = "page", defaultValue = "1") int page, @RequestParam(value = "pageSize", defaultValue = "30") int pageSize,
@RequestParam(defaultValue = "event_time") String sortName, @RequestParam(defaultValue = "desc") String sortOrder) { @RequestParam(defaultValue = "event_time") String sortName, @RequestParam(defaultValue = "desc") String sortOrder) {
if (trafficVo.getIllegalState() == null) {
trafficVo.setIllegalState(0);
}
Assert.notNull(trafficVo.getEventTime_gte(), "起始时间不能为空"); Assert.notNull(trafficVo.getEventTime_gte(), "起始时间不能为空");
Assert.notNull(trafficVo.getEventTime_lte(), "结束时间不能为空"); Assert.notNull(trafficVo.getEventTime_lte(), "结束时间不能为空");
Assert.isTrue(pageSize > 0, "页面大小不正确"); Assert.isTrue(pageSize > 0, "页面大小不正确");
...@@ -57,7 +61,7 @@ public class TrafficController extends TrafficBaseController { ...@@ -57,7 +61,7 @@ public class TrafficController extends TrafficBaseController {
dataType = "非机动车"; dataType = "非机动车";
} else if ("pedestrian".equals(eventType)) { } else if ("pedestrian".equals(eventType)) {
dataType = "行人"; dataType = "行人";
} else if (trafficVo.getIllegalState() != null && trafficVo.getIllegalState() == 1) { } else if (trafficVo.getIllegalState() == 1) {
dataType = "违法"; dataType = "违法";
} else if ("vehicle".equals(eventType)) { } else if ("vehicle".equals(eventType)) {
dataType = "过车"; dataType = "过车";
...@@ -91,21 +95,24 @@ public class TrafficController extends TrafficBaseController { ...@@ -91,21 +95,24 @@ public class TrafficController extends TrafficBaseController {
@GetMapping("/export") @GetMapping("/export")
public Object export(TrafficVo trafficVo, @RequestParam String name, @RequestParam Integer withPic, @RequestParam Integer withVideo) { public Object export(TrafficVo trafficVo, @RequestParam String name, @RequestParam Integer withPic, @RequestParam Integer withVideo) {
if (trafficVo.getIllegalState() == null) {
trafficVo.setIllegalState(0);
}
SimplePropertyPreFilter simplePropertyPreFilter = new SimplePropertyPreFilter(); SimplePropertyPreFilter simplePropertyPreFilter = new SimplePropertyPreFilter();
simplePropertyPreFilter.getExcludes().add("model"); simplePropertyPreFilter.getExcludes().add("model");
String param = JSON.toJSONString(trafficVo, SerializeConfig.globalInstance, new SerializeFilter[]{simplePropertyPreFilter}, "yyyy-MM-dd HH:mm:ss", JSON.DEFAULT_GENERATE_FEATURE); String param = JSON.toJSONString(trafficVo, SerializeConfig.globalInstance, new SerializeFilter[]{simplePropertyPreFilter}, "yyyy-MM-dd HH:mm:ss", JSON.DEFAULT_GENERATE_FEATURE);
String eventType = trafficVo.getEventType(); String eventType = trafficVo.getEventType();
if (trafficVo.getIllegalState() == null) { // 违法以外的数据需要带 eventType
if (trafficVo.getIllegalState() == 0) {
Assert.hasLength(eventType, "eventType不能为空"); Assert.hasLength(eventType, "eventType不能为空");
} }
int type; int type;
if ("xcycle".equals(eventType)) { if ("xcycle".equals(eventType)) {
type = ExportDataTypeEnum.XCYCLE.type; type = ExportDataTypeEnum.XCYCLE.type;
} else if ("pedestrian".equals(eventType)) { } else if ("pedestrian".equals(eventType)) {
type = ExportDataTypeEnum.PEDESTRIAN.type; type = ExportDataTypeEnum.PEDESTRIAN.type;
} else if (trafficVo.getIllegalState() != null && trafficVo.getIllegalState() == 1) { } else if (trafficVo.getIllegalState() == 1) {
type = ExportDataTypeEnum.ILLEGAL.type; type = ExportDataTypeEnum.ILLEGAL.type;
} else if ("vehicle".equals(eventType)) { } else if ("vehicle".equals(eventType)) {
type = ExportDataTypeEnum.TRAFFIC.type; type = ExportDataTypeEnum.TRAFFIC.type;
...@@ -113,6 +120,11 @@ public class TrafficController extends TrafficBaseController { ...@@ -113,6 +120,11 @@ public class TrafficController extends TrafficBaseController {
throw new FanXingException("参数有误"); throw new FanXingException("参数有误");
} }
int i = trafficService.countByExample(getExample(trafficVo));
if (i == 0) {
throw new FanXingException("数据为空");
}
ExportData exportData = new ExportData(); ExportData exportData = new ExportData();
exportData.setName(name); exportData.setName(name);
exportData.setParam(param); exportData.setParam(param);
...@@ -129,13 +141,13 @@ public class TrafficController extends TrafficBaseController { ...@@ -129,13 +141,13 @@ public class TrafficController extends TrafficBaseController {
*/ */
@GetMapping("overview") @GetMapping("overview")
@ResponseBody @ResponseBody
public JsonMessageUtil.JsonMessage<Collection<DataOverViewModel>> overview(@RequestParam(required = false) Date date public JsonMessageUtil.JsonMessage<JSONObject> overview(@RequestParam(required = false) Date date
, @RequestParam(required = false) Long taskId) { , @RequestParam(required = false) Long taskId, @RequestParam(required = false, defaultValue = "1") Integer page, @RequestParam(required = false, defaultValue = "30") Integer pageSize) {
if (date == null) { if (date == null) {
date = new Date(); date = new Date();
} }
Collection<DataOverViewModel> dataOverViewModels = trafficService.dataOverview(date, taskId); JSONObject result = trafficService.dataOverview(date, taskId, page, pageSize);
return JsonMessageUtil.getSuccessJsonMsg(dataOverViewModels); return JsonMessageUtil.getSuccessJsonMsg(result);
} }
@GetMapping("overview/detail") @GetMapping("overview/detail")
......
...@@ -28,7 +28,7 @@ public class TrafficFlowDataModel { ...@@ -28,7 +28,7 @@ public class TrafficFlowDataModel {
private Double distance; private Double distance;
private String deviceName; private String deviceName;
private String locationName; private String locationName;
private String queueLength; private Double queueLength;
private String detectionType; private String detectionType;
private Double timeOccupy; private Double timeOccupy;
private Double distTime; private Double distTime;
......
...@@ -2,6 +2,7 @@ package com.viontech.fanxing.query.runner; ...@@ -2,6 +2,7 @@ package com.viontech.fanxing.query.runner;
import cn.hutool.poi.excel.ExcelUtil; import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter; import cn.hutool.poi.excel.ExcelWriter;
import cn.hutool.poi.excel.StyleSet;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
...@@ -25,6 +26,7 @@ import com.viontech.keliu.util.DateUtil; ...@@ -25,6 +26,7 @@ import com.viontech.keliu.util.DateUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.CellStyle;
import org.redisson.api.RLock; import org.redisson.api.RLock;
import org.springframework.context.annotation.Profile; import org.springframework.context.annotation.Profile;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
...@@ -137,13 +139,13 @@ public class ExportDataJob { ...@@ -137,13 +139,13 @@ public class ExportDataJob {
log.info("数据总量:{}", totalNum); log.info("数据总量:{}", totalNum);
item.setCount(((long) totalNum)); item.setCount(((long) totalNum));
String path = vionConfig.getImage().getPath() + "/export/" + item.getId() + "/" + nextPage + ".xlsx"; String path = vionConfig.getImage().getPath() + "/export/" + item.getId() + "/" + item.getName() + "_" + nextPage + ".xlsx";
pathList.add(path); pathList.add(path);
File excel = new File(path); File excel = new File(path);
excel.getParentFile().mkdirs(); excel.getParentFile().mkdirs();
try { try {
// 写入 excel // 写入 excel
ExcelWriter writer = ExcelUtil.getWriter(true); ExcelWriter writer = getWriter();
writer.addHeaderAlias("event_dt", "时间"); writer.addHeaderAlias("event_dt", "时间");
writer.addHeaderAlias("device_name", "相机名称"); writer.addHeaderAlias("device_name", "相机名称");
if ("road".equals(statisticType)) { if ("road".equals(statisticType)) {
...@@ -152,10 +154,10 @@ public class ExportDataJob { ...@@ -152,10 +154,10 @@ public class ExportDataJob {
writer.addHeaderAlias("direction", "方向"); writer.addHeaderAlias("direction", "方向");
} }
writer.addHeaderAlias("velocity", "平均速度(KM/H)"); writer.addHeaderAlias("velocity", "平均速度(KM/H)");
writer.addHeaderAlias("occupy", "占有率"); writer.addHeaderAlias("occupy", "占有率%");
writer.addHeaderAlias("distance", "车头间距"); writer.addHeaderAlias("distance", "车头间距(m)");
writer.addHeaderAlias("queue_length", "排队长度"); writer.addHeaderAlias("queue_length", "排队长度(m)");
writer.addHeaderAlias("sample_num", "车流量"); writer.addHeaderAlias("sample_num", "车流量(辆)");
writer.setOnlyAlias(true); writer.setOnlyAlias(true);
writer.write(result, true); writer.write(result, true);
...@@ -172,6 +174,15 @@ public class ExportDataJob { ...@@ -172,6 +174,15 @@ public class ExportDataJob {
exportDataService.updateByPrimaryKeySelective(item); exportDataService.updateByPrimaryKeySelective(item);
} }
private ExcelWriter getWriter() {
ExcelWriter writer = ExcelUtil.getWriter(true);
StyleSet styleSet = writer.getStyleSet();
CellStyle cellStyleForNumber = styleSet.getCellStyleForNumber();
cellStyleForNumber.setDataFormat((short) 2);
return writer;
}
private void exportTraffic(ExportData item, int type) { private void exportTraffic(ExportData item, int type) {
item.setStatus(1); item.setStatus(1);
boolean withVideo = item.getWithVideo() == 1; boolean withVideo = item.getWithVideo() == 1;
...@@ -190,7 +201,7 @@ public class ExportDataJob { ...@@ -190,7 +201,7 @@ public class ExportDataJob {
if (list.size() == 0) { if (list.size() == 0) {
break; break;
} }
String path = vionConfig.getImage().getPath() + "/export/" + item.getId() + "/" + nextPage + ".zip"; String path = vionConfig.getImage().getPath() + "/export/" + item.getId() + "/" + item.getName() + "_" + nextPage + ".zip";
pathList.add(path); pathList.add(path);
File zipFile = new File(path); File zipFile = new File(path);
zipFile.getParentFile().mkdirs(); zipFile.getParentFile().mkdirs();
...@@ -227,7 +238,7 @@ public class ExportDataJob { ...@@ -227,7 +238,7 @@ public class ExportDataJob {
// 写入视频文件 // 写入视频文件
if (withVideo && StringUtils.isNotEmpty(vo.getVideoName())) { if (withVideo && StringUtils.isNotEmpty(vo.getVideoName())) {
File file = new File(vo.getVideoName()); File file = new File(vo.getVideoName());
o.setPicName(file.getName()); o.setVideoName(file.getName());
if (file.exists()) { if (file.exists()) {
try { try {
byte[] bytes = FileUtils.readFileToByteArray(file); byte[] bytes = FileUtils.readFileToByteArray(file);
...@@ -275,7 +286,7 @@ public class ExportDataJob { ...@@ -275,7 +286,7 @@ public class ExportDataJob {
if (list.size() == 0) { if (list.size() == 0) {
break; break;
} }
String path = vionConfig.getImage().getPath() + "/export/" + item.getId() + "/" + nextPage + ".zip"; String path = vionConfig.getImage().getPath() + "/export/" + item.getId() + "/" + item.getName() + "_" + nextPage + ".zip";
pathList.add(path); pathList.add(path);
File zipFile = new File(path); File zipFile = new File(path);
zipFile.getParentFile().mkdirs(); zipFile.getParentFile().mkdirs();
...@@ -308,7 +319,7 @@ public class ExportDataJob { ...@@ -308,7 +319,7 @@ public class ExportDataJob {
byte[] bytes = FileUtils.readFileToByteArray(file); byte[] bytes = FileUtils.readFileToByteArray(file);
zipO.putNextEntry(new ZipEntry(file.getName())); zipO.putNextEntry(new ZipEntry(file.getName()));
zipO.write(bytes); zipO.write(bytes);
o.setPicName(file.getName()); o.setVideoName(file.getName());
} catch (Exception e) { } catch (Exception e) {
log.error("", e); log.error("", e);
} }
...@@ -439,7 +450,7 @@ public class ExportDataJob { ...@@ -439,7 +450,7 @@ public class ExportDataJob {
} }
private ExcelWriter getExcelWriter() { private ExcelWriter getExcelWriter() {
ExcelWriter writer = ExcelUtil.getWriter(true); ExcelWriter writer = getWriter();
writer.addHeaderAlias("upColor", "上身颜色"); writer.addHeaderAlias("upColor", "上身颜色");
writer.addHeaderAlias("lowColor", "下身颜色"); writer.addHeaderAlias("lowColor", "下身颜色");
writer.addHeaderAlias("gender", "性别"); writer.addHeaderAlias("gender", "性别");
...@@ -449,7 +460,7 @@ public class ExportDataJob { ...@@ -449,7 +460,7 @@ public class ExportDataJob {
writer.addHeaderAlias("taskName", "任务名称"); writer.addHeaderAlias("taskName", "任务名称");
writer.addHeaderAlias("xcycleType", "非机动车类型"); writer.addHeaderAlias("xcycleType", "非机动车类型");
writer.addHeaderAlias("company", "运营公司"); writer.addHeaderAlias("company", "运营公司");
writer.addHeaderAlias("velocity", "速率"); writer.addHeaderAlias("velocity", "速率(KM/H)");
writer.addHeaderAlias("plateNumber", "车牌号码"); writer.addHeaderAlias("plateNumber", "车牌号码");
writer.addHeaderAlias("plateColor", "车牌颜色"); writer.addHeaderAlias("plateColor", "车牌颜色");
writer.addHeaderAlias("vehicleType", "车辆类型"); writer.addHeaderAlias("vehicleType", "车辆类型");
......
package com.viontech.fanxing.query.service.adapter; package com.viontech.fanxing.query.service.adapter;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.viontech.fanxing.commons.base.BaseExample; import com.viontech.fanxing.commons.base.BaseExample;
import com.viontech.fanxing.commons.base.BaseService; import com.viontech.fanxing.commons.base.BaseService;
...@@ -13,7 +14,7 @@ import java.util.Date; ...@@ -13,7 +14,7 @@ import java.util.Date;
public interface TrafficService extends BaseService<Traffic> { public interface TrafficService extends BaseService<Traffic> {
PageInfo<TrafficVo> getJsonData(BaseExample example, int pageNum, int pageSize); PageInfo<TrafficVo> getJsonData(BaseExample example, int pageNum, int pageSize);
Collection<DataOverViewModel> dataOverview(Date date,Long taskId); JSONObject dataOverview(Date date, Long taskId, Integer page, Integer pageSize);
Collection<DataOverViewModel> overviewDetail(Date date, Long taskId); Collection<DataOverViewModel> overviewDetail(Date date, Long taskId);
} }
\ No newline at end of file \ No newline at end of file
package com.viontech.fanxing.query.service.impl; package com.viontech.fanxing.query.service.impl;
import cn.hutool.core.collection.ListUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page; import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
...@@ -59,7 +61,7 @@ public class TrafficServiceImpl extends BaseServiceImpl<Traffic> implements Traf ...@@ -59,7 +61,7 @@ public class TrafficServiceImpl extends BaseServiceImpl<Traffic> implements Traf
} }
@Override @Override
public Collection<DataOverViewModel> dataOverview(Date date, Long taskId) { public JSONObject dataOverview(Date date, Long taskId, Integer page, Integer pageSize) {
Date min = DateUtil.setDayMinTime(date); Date min = DateUtil.setDayMinTime(date);
Date max = DateUtil.setDayMaxTime(date); Date max = DateUtil.setDayMaxTime(date);
HashMap<Long, DataOverViewModel> resultMap = new HashMap<>(); HashMap<Long, DataOverViewModel> resultMap = new HashMap<>();
...@@ -117,7 +119,16 @@ public class TrafficServiceImpl extends BaseServiceImpl<Traffic> implements Traf ...@@ -117,7 +119,16 @@ public class TrafficServiceImpl extends BaseServiceImpl<Traffic> implements Traf
}); });
dov.setBehavior(b.getCount()); dov.setBehavior(b.getCount());
} }
return resultMap.values(); Collection<DataOverViewModel> values = resultMap.values();
List<DataOverViewModel> collect = values.stream().filter(x -> x.getTaskId() != null).sorted(Comparator.comparingLong(DataOverViewModel::getTaskId)).collect(Collectors.toList());
List<List<DataOverViewModel>> partition = ListUtil.partition(collect, pageSize);
JSONObject jsonObject = new JSONObject();
jsonObject.put("total", collect.size());
jsonObject.put("page", page);
jsonObject.put("pageSize", pageSize);
jsonObject.put("data", partition.get(page - 1));
return jsonObject;
} }
@Override @Override
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!