Commit 86f9720e by xmh

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

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