Commit f3a5e598 by xmh

<feat> 添加 d_export_data 表,添加相关类文件

<feat> 实现数据异步导出
<feat> 实现数据存储方案页面配置化(配置存储在数据库中)
<feat> 添加获取数据存储方案接口
<feat> 添加 AbnormalQueueRollbackRunner 类,启动服务处理异常队列
1 parent a42e6bb4
Showing 48 changed files with 1064 additions and 69 deletions
......@@ -36,16 +36,14 @@ public class VionConfig {
private List<String> skipAuth;
/** 平台srs的配置 */
private Srs srs;
/** sip28181 对接的配置 */
private Sip sip;
/** 视频云平台对接的配置 */
private VideoCloud videoCloud;
public @Getter
@Setter
static class Image {
/** images 本地存储路径 */
private String path;
/** 图片保存天数 */
private Integer keep;
/** 访问 images 前缀,images 包含录像文件和分析图片 */
private String urlPrefix;
}
......@@ -65,7 +63,7 @@ public class VionConfig {
public @Getter
@Setter
static class Sip {
static class VideoCloud {
private String id;
private String url;
}
......
package com.viontech.fanxing.commons.model;
import com.viontech.fanxing.commons.base.BaseModel;
import java.util.Date;
public class ExportData extends BaseModel {
private Long id;
private Date createTime;
private String name;
private Integer type;
private Long count;
private Integer withPic;
private Integer withVideo;
private String param;
private String path;
private Integer status;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name == null ? null : name.trim();
}
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
public Long getCount() {
return count;
}
public void setCount(Long count) {
this.count = count;
}
public Integer getWithPic() {
return withPic;
}
public void setWithPic(Integer withPic) {
this.withPic = withPic;
}
public Integer getWithVideo() {
return withVideo;
}
public void setWithVideo(Integer withVideo) {
this.withVideo = withVideo;
}
public String getParam() {
return param;
}
public void setParam(String param) {
this.param = param == null ? null : param.trim();
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path == null ? null : path.trim();
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
}
\ No newline at end of file
package com.viontech.fanxing.commons.model.main;
import lombok.Getter;
import lombok.Setter;
/**
* .
*
* @author 谢明辉
* @date 2021/11/29
*/
@Getter
@Setter
public class ImageKeepConfig {
/** 存储类型,1按天存储,2按磁盘空间存储 */
private Integer type = 1;
/** 保留多少天 */
private Integer keep = 7;
/** 磁盘空间比率 */
private Integer rate = 75;
}
......@@ -50,6 +50,19 @@ public class RedisService {
return lock;
}
public RLock getLockMust(String lockName, Integer waitTime, Integer leaseTime, TimeUnit timeUnit) {
RLock lock = redissonClient.getLock(lockName);
boolean isLock = false;
while (!isLock) {
try {
isLock = lock.tryLock(waitTime, leaseTime, timeUnit);
Thread.sleep(50L);
} catch (Exception ignore) {
}
}
return lock;
}
public RedissonClient getClient() {
return redissonClient;
}
......
package com.viontech.fanxing.commons.vo;
import com.viontech.fanxing.commons.model.ExportData;
import com.viontech.fanxing.commons.vobase.ExportDataVoBase;
public class ExportDataVo extends ExportDataVoBase {
public ExportDataVo() {
super();
}
public ExportDataVo(ExportData exportData) {
super(exportData);
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ package com.viontech.fanxing.forward.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
/**
......@@ -14,6 +15,7 @@ import org.springframework.web.socket.server.standard.ServerEndpointExporter;
public class ForwardWebConfig {
@Bean
@Profile("!test")
public ServerEndpointExporter serverEndpointExporter() {
return new ServerEndpointExporter();
}
......
package com.viontech.fanxing.forward.feign;
import com.viontech.fanxing.commons.model.Forward;
import com.viontech.fanxing.commons.model.main.ImageKeepConfig;
import com.viontech.keliu.util.JsonMessageUtil;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Service;
......@@ -28,4 +29,7 @@ public interface OpsFeignClient {
@PostMapping("/forwards/{id}")
JsonMessageUtil.JsonMessage<Forward> updateById(@PathVariable("id") Long id, @RequestBody Forward forward);
@GetMapping("/contents/imageKeepConfig")
JsonMessageUtil.JsonMessage<ImageKeepConfig> getImageKeepConfig();
}
package com.viontech.fanxing.forward.runner;
import com.viontech.fanxing.commons.constant.RedisKeys;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RKeys;
import org.redisson.api.RQueue;
import org.redisson.api.RedissonClient;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Profile;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/**
* .
*
* @author 谢明辉
* @date 2021/11/29
*/
@Component
@Order(1)
@Profile("!test")
@Slf4j
public class AbnormalQueueRollbackRunner implements CommandLineRunner {
@Resource
private RedissonClient redissonClient;
@Override
public void run(String... args) throws Exception {
rollback(RedisKeys.FORWARD_TRAFFIC_QUEUE);
rollback(RedisKeys.FORWARD_FLOW_QUEUE);
rollback(RedisKeys.FORWARD_BEHAVIOR_QUEUE);
}
private void rollback(String queueName) {
log.info("队列处理开始:[{}]", queueName);
RKeys keys = redissonClient.getKeys();
Iterable<String> queueNames = keys.getKeysByPattern(queueName + ":workQueue:*");
for (String name : queueNames) {
RQueue<Object> queue = redissonClient.getQueue(name);
int size = queue.size();
log.info("处理队列[{}],数据量:[{}]", name, size);
for (int i = 0; i < size; i++) {
queue.pollLastAndOfferFirstTo(queueName);
}
}
log.info("队列处理完成:[{}]", queueName);
}
}
package com.viontech.fanxing.forward.runner;
import com.viontech.fanxing.commons.config.VionConfig;
import com.viontech.fanxing.commons.model.main.ImageKeepConfig;
import com.viontech.fanxing.forward.feign.OpsFeignClient;
import com.viontech.keliu.util.DateUtil;
import com.viontech.keliu.util.JsonMessageUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.springframework.context.annotation.Profile;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.io.File;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
/**
* .
......@@ -24,33 +31,72 @@ import java.time.format.DateTimeFormatter;
public class PicKeepRunner {
@Resource
private OpsFeignClient opsFeignClient;
@Resource
private JdbcTemplate jdbcTemplate;
@Resource
private VionConfig vionConfig;
@Scheduled(cron = "0 0 08 * * ?")
@Scheduled(cron = "0 1 8 * * ?")
public void run() {
if (vionConfig.getImage().getKeep() == -1) {
return;
JsonMessageUtil.JsonMessage<ImageKeepConfig> imageKeepConfigData = opsFeignClient.getImageKeepConfig();
ImageKeepConfig config = imageKeepConfigData.getData();
// type 为 1, 按天数保留
if (config.getType() == 1) {
keep1(config.getKeep());
}
// type 为 2, 按磁盘空间比例保留
else if (config.getType() == 2) {
}
}
private void keep1(int day) {
Date date = DateUtil.addDays(new Date(), -day);
String yyyyMMdd = DateUtil.format("yyyyMMdd", date);
String sql = "select partition_name,CAST(FROM_UNIXTIME(partition_description) as date) as date from information_schema.partitions where table_name = ? and partition_name< ?";
Set<String> yyyyMMddSet = new HashSet<>();
// 五张表都要处理
for (String tableName : new String[]{"d_traffic", "d_flow_event", "d_behavior", "d_flow_data", "d_traffic_face"}) {
ArrayList<String> partitions = new ArrayList<>();
String minPartitionName = tableName + yyyyMMdd;
// 查找要删除的数据日期和分区名称
jdbcTemplate.query(sql, rs -> {
String name = rs.getString("partition_name");
partitions.add(name);
java.sql.Date date1 = rs.getDate("date");
yyyyMMddSet.add(DateUtil.format("yyyyMMdd", date1));
}, tableName, minPartitionName);
// 删除分区
for (String partitionNeedDel : partitions) {
jdbcTemplate.update("ALTER TABLE " + tableName + " drop partition " + partitionNeedDel);
log.info("删除数据分区:[{}]", partitionNeedDel);
}
}
// 删除文件
for (String dirName : yyyyMMddSet) {
dropDir(dirName);
}
}
private void dropDir(String dirName) {
try {
long nowDay = LocalDate.now().toEpochDay();
DateTimeFormatter yyyyMMdd = DateTimeFormatter.ofPattern("yyyyMMdd");
File baseDir = new File(vionConfig.getImage().getPath());
File[] files = baseDir.listFiles((dir, name) -> name.matches("[1-9]\\d{7}"));
for (File file : files) {
String name = file.getName();
LocalDate day = LocalDate.parse(name, yyyyMMdd);
long l = day.toEpochDay();
if (nowDay - l > vionConfig.getImage().getKeep()) {
log.info("删除文件夹:{}", name);
FileUtils.deleteDirectory(file);
if (files != null) {
for (File file : files) {
String name = file.getName();
if (dirName.equals(name)) {
FileUtils.deleteDirectory(file);
log.info("删除文件夹:{}", name);
}
}
}
} catch (Exception e) {
log.error("", e);
log.error("目录删除失败", e);
}
}
}
......
......@@ -8,6 +8,7 @@ import org.redisson.api.RTopic;
import org.redisson.api.RedissonClient;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Profile;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
......@@ -21,6 +22,7 @@ import javax.annotation.Resource;
@Component
@Slf4j
@Profile("!test")
@Order(10)
public class PicRealTimeRunner implements CommandLineRunner {
@Resource
......
......@@ -57,7 +57,6 @@ pagehelper:
vion:
image:
path: G:\data
keep: 1
enable-forward: true
redisson:
path: F:\myIDEAworkspace\jt\fanxing3\fanxing-commons\src\main\resources\redisson.yml
......
......@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
import com.viontech.fanxing.commons.constant.RedisKeys;
import com.viontech.fanxing.commons.model.Task;
import com.viontech.fanxing.forward.feign.TaskFeignClient;
import com.viontech.fanxing.forward.runner.PicKeepRunner;
import com.viontech.keliu.util.JsonMessageUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -33,6 +34,8 @@ public class Test0 {
private RedissonClient redissonClient;
@Resource
private TaskFeignClient taskFeignClient;
@Resource
private PicKeepRunner picKeepRunner;
@Test
public void test() {
......@@ -47,4 +50,9 @@ public class Test0 {
System.out.println(JSON.toJSONString(allTask));
}
@Test
public void picKeepRunner() {
picKeepRunner.run();
}
}
......@@ -3,13 +3,12 @@ package com.viontech.fanxing.ops.controller.web;
import com.github.pagehelper.PageInfo;
import com.viontech.fanxing.commons.base.BaseExample;
import com.viontech.fanxing.commons.model.ContentExample;
import com.viontech.fanxing.commons.model.main.ImageKeepConfig;
import com.viontech.fanxing.commons.vo.ContentVo;
import com.viontech.fanxing.ops.controller.base.ContentBaseController;
import com.viontech.keliu.util.JsonMessageUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.*;
import java.util.List;
......@@ -43,4 +42,10 @@ public class ContentController extends ContentBaseController {
return getSuccessJsonMsg(MESSAGE_PAGE_SUCCESS, pageInfo);
}
}
@GetMapping("/imageKeepConfig")
@ResponseBody
public JsonMessageUtil.JsonMessage<ImageKeepConfig> selectImageKeepConfig() {
return JsonMessageUtil.getSuccessJsonMsg(contentService.selectImageKeepConfig());
}
}
\ No newline at end of file
......@@ -6,6 +6,7 @@ import com.viontech.fanxing.commons.vo.LogVo;
import com.viontech.fanxing.ops.controller.base.LogBaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
@RequestMapping("/logs")
......@@ -16,4 +17,11 @@ public class LogController extends LogBaseController {
LogExample logExample = (LogExample) super.getExample(logVo, type);
return logExample;
}
@Override
public Object page(LogVo logVo, @RequestParam(value = "page", defaultValue = "-1") int page, @RequestParam(value = "pageSize", defaultValue = "100") int pageSize
, String sortName, String sortOrder) {
return super.page(logVo, page, pageSize, "date_time", "desc");
}
}
\ No newline at end of file
......@@ -3,10 +3,13 @@ package com.viontech.fanxing.ops.service.adapter;
import com.viontech.fanxing.commons.base.BaseService;
import com.viontech.fanxing.commons.model.Content;
import com.viontech.fanxing.commons.model.ContentExample;
import com.viontech.fanxing.commons.model.main.ImageKeepConfig;
import java.util.List;
public interface ContentService extends BaseService<Content> {
List<Content> selectByExampleWithBlob(ContentExample contentExample);
ImageKeepConfig selectImageKeepConfig();
}
\ No newline at end of file
......@@ -282,22 +282,22 @@ public class ChannelServiceImpl extends BaseServiceImpl<Channel> implements Chan
@Override
public Object pullFromVideoCloud() {
Assert.notNull(vionConfig.getSip(), "视频云配置为空");
Assert.hasText(vionConfig.getSip().getId(), "视频云对接id为空");
Assert.hasText(vionConfig.getSip().getUrl(), "视频云对接地址为空");
Assert.notNull(vionConfig.getVideoCloud(), "视频云配置为空");
Assert.hasText(vionConfig.getVideoCloud().getId(), "视频云对接id为空");
Assert.hasText(vionConfig.getVideoCloud().getUrl(), "视频云对接地址为空");
JSONObject response = WebClient.create(vionConfig.getSip().getUrl())
JSONObject response = WebClient.create(vionConfig.getVideoCloud().getUrl())
.get()
.uri(uriBuilder -> uriBuilder.path("/api/device/getAllDeviceList").queryParam("userid", vionConfig.getSip().getId()).build())
.uri(uriBuilder -> uriBuilder.path("/api/device/getAllDeviceList").queryParam("userid", vionConfig.getVideoCloud().getId()).build())
.retrieve()
.bodyToMono(JSONObject.class)
.block(Duration.ofSeconds(10));
DictCode sip28181 = dictcodeService.getOrCreateOrgCode("video_cloud", "视频云");
DictCode videoCloud = dictcodeService.getOrCreateOrgCode("video_cloud", "视频云");
if (response != null && response.containsKey("data")) {
JSONArray data = response.getJSONArray("data");
if (data.size() > 0) {
analyseVideoCloud(data, sip28181, sip28181.getCateId());
analyseVideoCloud(data, videoCloud, videoCloud.getCateId());
}
}
return null;
......
package com.viontech.fanxing.ops.service.impl;
import com.viontech.fanxing.commons.base.BaseExample;
import com.alibaba.fastjson.JSON;
import com.viontech.fanxing.commons.base.BaseMapper;
import com.viontech.fanxing.commons.base.BaseServiceImpl;
import com.viontech.fanxing.commons.model.Content;
import com.viontech.fanxing.commons.model.ContentExample;
import com.viontech.fanxing.commons.model.main.ImageKeepConfig;
import com.viontech.fanxing.ops.mapper.ContentMapper;
import com.viontech.fanxing.ops.service.adapter.ContentService;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
......@@ -27,4 +28,17 @@ public class ContentServiceImpl extends BaseServiceImpl<Content> implements Cont
public List<Content> selectByExampleWithBlob(ContentExample contentExample) {
return contentMapper.selectByExampleWithBLOBs(contentExample);
}
@Override
public ImageKeepConfig selectImageKeepConfig() {
ContentExample contentExample = new ContentExample();
contentExample.createCriteria().andTypeEqualTo("platformConfig").andNameEqualTo("imageKeepConfig");
List<Content> contents = contentMapper.selectByExampleWithBLOBs(contentExample);
if (contents.size() > 0) {
String content = contents.get(0).getContent();
return JSON.parseObject(content, ImageKeepConfig.class);
} else {
return new ImageKeepConfig();
}
}
}
\ No newline at end of file
......@@ -57,10 +57,10 @@ vion:
url-prefix: http://192.168.9.233:30007/images
redisson:
path: F:\myIDEAworkspace\jt\fanxing3\fanxing-commons\src\main\resources\redisson.yml
sip:
id: 800d8652-d1f5-442e-9f34-4d70a6d000a8
url: http://192.168.9.233:8888
supported-video-formats:
- mp4
- avi
- h264
\ No newline at end of file
- h264
video-cloud:
id: 800d8652-d1f5-442e-9f34-4d70a6d000a8
url: http://192.168.9.233:8888
\ No newline at end of file
......@@ -29,6 +29,16 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-config</artifactId>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-poi</artifactId>
<version>5.7.16</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.1.0</version>
</dependency>
</dependencies>
<build>
......
package com.viontech.fanxing.query.controller.base;
import com.viontech.fanxing.commons.base.BaseController;
import com.viontech.fanxing.commons.base.BaseExample;
import com.viontech.fanxing.commons.base.BaseMapper;
import com.viontech.fanxing.commons.base.BaseService;
import com.viontech.fanxing.commons.model.ExportData;
import com.viontech.fanxing.commons.model.ExportDataExample;
import com.viontech.fanxing.commons.vo.ExportDataVo;
import com.viontech.fanxing.query.mapper.ExportDataMapper;
import com.viontech.fanxing.query.service.adapter.ExportDataService;
import javax.annotation.Resource;
public abstract class ExportDataBaseController extends BaseController<ExportData, ExportDataVo> {
@Resource
protected ExportDataService exportDataService;
@Override
protected BaseExample getExample(ExportDataVo exportDataVo, int type) {
ExportDataExample exportDataExample = new ExportDataExample();
ExportDataExample.Criteria criteria = exportDataExample.createCriteria();
if(exportDataVo.getId() != null) {
criteria.andIdEqualTo(exportDataVo.getId());
}
if(exportDataVo.getId_arr() != null) {
criteria.andIdIn(exportDataVo.getId_arr());
}
if(exportDataVo.getId_gt() != null) {
criteria.andIdGreaterThan(exportDataVo.getId_gt());
}
if(exportDataVo.getId_lt() != null) {
criteria.andIdLessThan(exportDataVo.getId_lt());
}
if(exportDataVo.getId_gte() != null) {
criteria.andIdGreaterThanOrEqualTo(exportDataVo.getId_gte());
}
if(exportDataVo.getId_lte() != null) {
criteria.andIdLessThanOrEqualTo(exportDataVo.getId_lte());
}
if(exportDataVo.getCreateTime() != null) {
criteria.andCreateTimeEqualTo(exportDataVo.getCreateTime());
}
if(exportDataVo.getCreateTime_arr() != null) {
criteria.andCreateTimeIn(exportDataVo.getCreateTime_arr());
}
if(exportDataVo.getCreateTime_gt() != null) {
criteria.andCreateTimeGreaterThan(exportDataVo.getCreateTime_gt());
}
if(exportDataVo.getCreateTime_lt() != null) {
criteria.andCreateTimeLessThan(exportDataVo.getCreateTime_lt());
}
if(exportDataVo.getCreateTime_gte() != null) {
criteria.andCreateTimeGreaterThanOrEqualTo(exportDataVo.getCreateTime_gte());
}
if(exportDataVo.getCreateTime_lte() != null) {
criteria.andCreateTimeLessThanOrEqualTo(exportDataVo.getCreateTime_lte());
}
if(exportDataVo.getName() != null) {
criteria.andNameEqualTo(exportDataVo.getName());
}
if(exportDataVo.getName_null() != null) {
if(exportDataVo.getName_null().booleanValue()) {
criteria.andNameIsNull();
} else {
criteria.andNameIsNotNull();
}
}
if(exportDataVo.getName_arr() != null) {
criteria.andNameIn(exportDataVo.getName_arr());
}
if(exportDataVo.getName_like() != null) {
criteria.andNameLike(exportDataVo.getName_like());
}
if(exportDataVo.getType() != null) {
criteria.andTypeEqualTo(exportDataVo.getType());
}
if(exportDataVo.getType_arr() != null) {
criteria.andTypeIn(exportDataVo.getType_arr());
}
if(exportDataVo.getType_gt() != null) {
criteria.andTypeGreaterThan(exportDataVo.getType_gt());
}
if(exportDataVo.getType_lt() != null) {
criteria.andTypeLessThan(exportDataVo.getType_lt());
}
if(exportDataVo.getType_gte() != null) {
criteria.andTypeGreaterThanOrEqualTo(exportDataVo.getType_gte());
}
if(exportDataVo.getType_lte() != null) {
criteria.andTypeLessThanOrEqualTo(exportDataVo.getType_lte());
}
if(exportDataVo.getCount() != null) {
criteria.andCountEqualTo(exportDataVo.getCount());
}
if(exportDataVo.getCount_arr() != null) {
criteria.andCountIn(exportDataVo.getCount_arr());
}
if(exportDataVo.getCount_gt() != null) {
criteria.andCountGreaterThan(exportDataVo.getCount_gt());
}
if(exportDataVo.getCount_lt() != null) {
criteria.andCountLessThan(exportDataVo.getCount_lt());
}
if(exportDataVo.getCount_gte() != null) {
criteria.andCountGreaterThanOrEqualTo(exportDataVo.getCount_gte());
}
if(exportDataVo.getCount_lte() != null) {
criteria.andCountLessThanOrEqualTo(exportDataVo.getCount_lte());
}
if(exportDataVo.getWithPic() != null) {
criteria.andWithPicEqualTo(exportDataVo.getWithPic());
}
if(exportDataVo.getWithPic_arr() != null) {
criteria.andWithPicIn(exportDataVo.getWithPic_arr());
}
if(exportDataVo.getWithPic_gt() != null) {
criteria.andWithPicGreaterThan(exportDataVo.getWithPic_gt());
}
if(exportDataVo.getWithPic_lt() != null) {
criteria.andWithPicLessThan(exportDataVo.getWithPic_lt());
}
if(exportDataVo.getWithPic_gte() != null) {
criteria.andWithPicGreaterThanOrEqualTo(exportDataVo.getWithPic_gte());
}
if(exportDataVo.getWithPic_lte() != null) {
criteria.andWithPicLessThanOrEqualTo(exportDataVo.getWithPic_lte());
}
if(exportDataVo.getWithVideo() != null) {
criteria.andWithVideoEqualTo(exportDataVo.getWithVideo());
}
if(exportDataVo.getWithVideo_arr() != null) {
criteria.andWithVideoIn(exportDataVo.getWithVideo_arr());
}
if(exportDataVo.getWithVideo_gt() != null) {
criteria.andWithVideoGreaterThan(exportDataVo.getWithVideo_gt());
}
if(exportDataVo.getWithVideo_lt() != null) {
criteria.andWithVideoLessThan(exportDataVo.getWithVideo_lt());
}
if(exportDataVo.getWithVideo_gte() != null) {
criteria.andWithVideoGreaterThanOrEqualTo(exportDataVo.getWithVideo_gte());
}
if(exportDataVo.getWithVideo_lte() != null) {
criteria.andWithVideoLessThanOrEqualTo(exportDataVo.getWithVideo_lte());
}
if(exportDataVo.getParam() != null) {
criteria.andParamEqualTo(exportDataVo.getParam());
}
if(exportDataVo.getParam_arr() != null) {
criteria.andParamIn(exportDataVo.getParam_arr());
}
if(exportDataVo.getParam_like() != null) {
criteria.andParamLike(exportDataVo.getParam_like());
}
if(exportDataVo.getPath() != null) {
criteria.andPathEqualTo(exportDataVo.getPath());
}
if(exportDataVo.getPath_arr() != null) {
criteria.andPathIn(exportDataVo.getPath_arr());
}
if(exportDataVo.getPath_like() != null) {
criteria.andPathLike(exportDataVo.getPath_like());
}
if(exportDataVo.getStatus() != null) {
criteria.andStatusEqualTo(exportDataVo.getStatus());
}
if(exportDataVo.getStatus_arr() != null) {
criteria.andStatusIn(exportDataVo.getStatus_arr());
}
if(exportDataVo.getStatus_gt() != null) {
criteria.andStatusGreaterThan(exportDataVo.getStatus_gt());
}
if(exportDataVo.getStatus_lt() != null) {
criteria.andStatusLessThan(exportDataVo.getStatus_lt());
}
if(exportDataVo.getStatus_gte() != null) {
criteria.andStatusGreaterThanOrEqualTo(exportDataVo.getStatus_gte());
}
if(exportDataVo.getStatus_lte() != null) {
criteria.andStatusLessThanOrEqualTo(exportDataVo.getStatus_lte());
}
return exportDataExample;
}
@Override
protected BaseService<ExportData> getService() {
return exportDataService;
}
}
\ No newline at end of file
......@@ -7,13 +7,19 @@ import com.alibaba.fastjson.serializer.SimplePropertyPreFilter;
import com.github.pagehelper.PageInfo;
import com.viontech.fanxing.commons.base.BaseExample;
import com.viontech.fanxing.commons.model.BehaviorExample;
import com.viontech.fanxing.commons.model.ExportData;
import com.viontech.fanxing.commons.vo.BehaviorVo;
import com.viontech.fanxing.query.controller.base.BehaviorBaseController;
import com.viontech.fanxing.query.model.export.ExportDataTypeEnum;
import com.viontech.fanxing.query.service.adapter.ExportDataService;
import com.viontech.fanxing.query.service.main.OpsClientService;
import com.viontech.keliu.util.JsonMessageUtil;
import org.springframework.stereotype.Controller;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
......@@ -25,6 +31,8 @@ public class BehaviorController extends BehaviorBaseController {
@Resource
private OpsClientService opsClientService;
@Resource
private ExportDataService exportDataService;
@Override
protected BaseExample getExample(BehaviorVo behaviorVo, int type) {
......@@ -33,8 +41,14 @@ public class BehaviorController extends BehaviorBaseController {
return behaviorExample;
}
public BehaviorExample getExample(BehaviorVo behaviorVo) {
return (BehaviorExample) super.getExample(behaviorVo, 4);
}
@Override
public Object page(BehaviorVo behaviorVo, @RequestParam(value = "page", defaultValue = "-1") int page, @RequestParam(value = "pageSize", defaultValue = "100") int pageSize, String sortName, String sortOrder) {
@ResponseBody
public Object page(BehaviorVo behaviorVo, @RequestParam(value = "page", defaultValue = "-1") int page, @RequestParam(value = "pageSize", defaultValue = "100") int pageSize,
@RequestParam(defaultValue = "event_time") String sortName, @RequestParam(defaultValue = "desc") String sortOrder) {
Assert.notNull(behaviorVo.getEventTime_gte(), "起始时间不能为空");
Assert.notNull(behaviorVo.getEventTime_lte(), "结束时间不能为空");
SimplePropertyPreFilter simplePropertyPreFilter = new SimplePropertyPreFilter();
......@@ -50,4 +64,22 @@ public class BehaviorController extends BehaviorBaseController {
PageInfo<BehaviorVo> pageInfo = behaviorService.getJsonData(baseExample, page, pageSize);
return getSuccessJsonMsg(MESSAGE_PAGE_SUCCESS, pageInfo);
}
@GetMapping("/export")
@ResponseBody
public Object export(BehaviorVo behaviorVo, @RequestParam String name
, @RequestParam(required = false, defaultValue = "0") Integer withPic, @RequestParam(required = false, defaultValue = "0") Integer withVideo) {
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);
ExportData exportData = new ExportData();
exportData.setName(name);
exportData.setParam(param);
exportData.setType(ExportDataTypeEnum.BEHAVIOR.type);
exportData.setWithPic(withPic);
exportData.setWithVideo(withVideo);
exportDataService.insertSelective(exportData);
return JsonMessageUtil.getSuccessJsonMsg();
}
}
\ No newline at end of file
package com.viontech.fanxing.query.controller.web;
import com.viontech.fanxing.commons.base.BaseExample;
import com.viontech.fanxing.commons.model.ExportDataExample;
import com.viontech.fanxing.commons.vo.ExportDataVo;
import com.viontech.fanxing.query.controller.base.ExportDataBaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/exportDatas")
public class ExportDataController extends ExportDataBaseController {
@Override
protected BaseExample getExample(ExportDataVo exportDataVo, int type) {
ExportDataExample exportDataExample = (ExportDataExample) super.getExample(exportDataVo, type);
return exportDataExample;
}
}
\ No newline at end of file
package com.viontech.fanxing.query.controller.web;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.serializer.SerializeConfig;
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.ExportData;
import com.viontech.fanxing.commons.model.TrafficExample;
import com.viontech.fanxing.commons.vo.TrafficVo;
import com.viontech.fanxing.query.controller.base.TrafficBaseController;
import com.viontech.fanxing.query.model.export.ExportDataTypeEnum;
import com.viontech.fanxing.query.service.adapter.ExportDataService;
import com.viontech.fanxing.query.service.main.OpsClientService;
import com.viontech.keliu.util.JsonMessageUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import static com.viontech.keliu.util.JsonMessageUtil.getSuccessJsonMsg;
@Controller
@RestController
@RequestMapping("/traffics")
public class TrafficController extends TrafficBaseController {
@Resource
private OpsClientService opsClientService;
@Resource
private ExportDataService exportDataService;
@Override
protected BaseExample getExample(TrafficVo trafficVo, int type) {
TrafficExample trafficExample = (TrafficExample) super.getExample(trafficVo, type);
trafficExample.createColumns().hasIdColumn().hasEventTimeColumn().hasVideoNameColumn().hasPicsColumn();
return trafficExample;
return super.getExample(trafficVo, type);
}
@Override
@RequestMapping(value = "", method = RequestMethod.GET)
@ResponseBody
public Object page(TrafficVo trafficVo, @RequestParam(value = "page", defaultValue = "1") int page, @RequestParam(value = "pageSize", defaultValue = "30") int pageSize, String sortName, String sortOrder) {
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) {
Assert.notNull(trafficVo.getEventTime_gte(), "起始时间不能为空");
Assert.notNull(trafficVo.getEventTime_lte(), "结束时间不能为空");
Assert.isTrue(pageSize > 0, "页面大小不正确");
......@@ -62,4 +65,53 @@ public class TrafficController extends TrafficBaseController {
PageInfo<TrafficVo> pageInfo = trafficService.getJsonData(baseExample, page, pageSize);
return getSuccessJsonMsg(MESSAGE_PAGE_SUCCESS, pageInfo);
}
@PostMapping("/batchRemove")
public Object batchRemove(@RequestBody JSONArray ids) {
List<Long> longs = ids.toJavaList(Long.class);
TrafficExample trafficExample = new TrafficExample();
trafficExample.createCriteria().andIdIn(longs);
trafficService.deleteByExample(trafficExample);
return JsonMessageUtil.getSuccessJsonMsg();
}
@GetMapping("/export")
public Object export(TrafficVo trafficVo, @RequestParam String name, @RequestParam Integer withPic, @RequestParam Integer withVideo) {
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) {
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) {
type = ExportDataTypeEnum.ILLEGAL.type;
} else if ("vehicle".equals(eventType)) {
type = ExportDataTypeEnum.TRAFFIC.type;
} else {
throw new FanXingException("参数有误");
}
ExportData exportData = new ExportData();
exportData.setName(name);
exportData.setParam(param);
exportData.setType(type);
exportData.setWithPic(withPic);
exportData.setWithVideo(withVideo);
exportDataService.insertSelective(exportData);
return JsonMessageUtil.getSuccessJsonMsg();
}
public TrafficExample getExample(TrafficVo trafficVo) {
return (TrafficExample) super.getExample(trafficVo, EXAMPLE_TYPE_PAGE);
}
}
\ No newline at end of file
......@@ -32,6 +32,12 @@ public interface OpsClient {
@GetMapping("/dictCodes")
JsonMessageUtil.JsonMessage<List<DictCode>> getDictCodeByUnid(@RequestParam("unid") String unid);
@GetMapping("/dictCodes")
JsonMessageUtil.JsonMessage<List<DictCode>> getDictCodes();
@GetMapping("/dictCates")
JsonMessageUtil.JsonMessage<List<DictCate>> getDictCates();
@PostMapping("/logs")
JsonMessageUtil.JsonMessage<Log> addLog(@RequestBody LogVo logVo);
......
package com.viontech.fanxing.query.mapper;
import com.viontech.fanxing.commons.base.BaseMapper;
import com.viontech.fanxing.commons.model.ExportData;
import com.viontech.fanxing.commons.model.ExportDataExample;
import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface ExportDataMapper extends BaseMapper {
int countByExample(ExportDataExample example);
int deleteByExample(ExportDataExample example);
int deleteByPrimaryKey(Long id);
int insert(ExportData record);
int insertSelective(ExportData record);
List<ExportData> selectByExample(ExportDataExample example);
ExportData selectByPrimaryKey(Long id);
int updateByExampleSelective(@Param("record") ExportData record, @Param("example") ExportDataExample example);
int updateByExample(@Param("record") ExportData record, @Param("example") ExportDataExample example);
int updateByPrimaryKeySelective(ExportData record);
int updateByPrimaryKey(ExportData record);
}
\ No newline at end of file
......@@ -142,19 +142,17 @@
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" resultMap="ResultMapWithBLOBs" parameterType="map" >
<select id="selectByPrimaryKey" resultMap="ResultMapWithBLOBs" parameterType="java.lang.Long" >
select
<include refid="Base_Column_List" />
,
<include refid="Blob_Column_List" />
from `d_behavior` `behavior`
where `behavior`.id = #{id,jdbcType=BIGINT}
and `behavior`.event_time = #{eventTime,jdbcType=TIMESTAMP}
</select>
<delete id="deleteByPrimaryKey" parameterType="map" >
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
delete from `d_behavior` `behavior`
where id = #{id,jdbcType=BIGINT}
and event_time = #{eventTime,jdbcType=TIMESTAMP}
</delete>
<delete id="deleteByExample" parameterType="com.viontech.fanxing.commons.model.BehaviorExample" >
delete from `d_behavior` `behavior`
......
......@@ -144,19 +144,17 @@
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" resultMap="ResultMapWithBLOBs" parameterType="map" >
<select id="selectByPrimaryKey" resultMap="ResultMapWithBLOBs" parameterType="java.lang.Long">
select
<include refid="Base_Column_List" />
,
<include refid="Blob_Column_List" />
from `d_flow_event` `flowEvent`
where `flowEvent`.id = #{id,jdbcType=BIGINT}
and `flowEvent`.event_time = #{eventTime,jdbcType=TIMESTAMP}
</select>
<delete id="deleteByPrimaryKey" parameterType="map" >
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
delete from `d_flow_event` `flowEvent`
where id = #{id,jdbcType=BIGINT}
and event_time = #{eventTime,jdbcType=TIMESTAMP}
</delete>
<delete id="deleteByExample" parameterType="com.viontech.fanxing.commons.model.FlowEventExample" >
delete from `d_flow_event` `flowEvent`
......
......@@ -169,16 +169,15 @@
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" resultMap="ResultMapWithBLOBs" parameterType="map" >
<select id="selectByPrimaryKey" resultMap="ResultMapWithBLOBs" parameterType="java.lang.Long" >
select
<include refid="Base_Column_List" />
,
<include refid="Blob_Column_List" />
from `d_traffic` `traffic`
where `traffic`.id = #{id,jdbcType=BIGINT}
and `traffic`.event_time = #{eventTime,jdbcType=TIMESTAMP}
</select>
<delete id="deleteByPrimaryKey" parameterType="map" >
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
delete from `d_traffic` `traffic`
where id = #{id,jdbcType=BIGINT}
and event_time = #{eventTime,jdbcType=TIMESTAMP}
......
......@@ -3,14 +3,15 @@ package com.viontech.fanxing.query.model;
import lombok.Getter;
import lombok.Setter;
import java.util.Date;
import java.util.List;
import java.util.Set;
@Getter
@Setter
public class TrafficFlowRequestVo extends TrafficFlowBaseRequestVo {
private String event_dt__gte;// 可选,查询时间范围的起始时刻(包含),默认为event_dt_lt前7天。
private String event_dt__lt;//可选,查询时间范围的结束时刻(不含),默认为当前时间后10分钟。
private Date event_dt__gte;// 可选,查询时间范围的起始时刻(包含),默认为event_dt_lt前7天。
private Date event_dt__lt;//可选,查询时间范围的结束时刻(不含),默认为当前时间后10分钟。
private String dev_unid;// 可选,精确匹配,产生数据的设备的unid
private String vchan_refid;//可选,精确匹配,视频通道的参考id
private String vdev_unid;// 可选,精确匹配,视频通道所在设备的unid
......
package com.viontech.fanxing.query.model.export;
import lombok.Getter;
import lombok.Setter;
/**
* .
*
* @author 谢明辉
* @date 2021/11/26
*/
@Getter
@Setter
public class EIllegalModel extends ExportBaseModel {
private String plateNumber;
private String plateColor;
private String vehicleType;
private String vehicleBrand;
private String vehicleColor;
private String illegalType;
// private String withSeatBelt;
// private String phone;
}
package com.viontech.fanxing.query.model.export;
import lombok.Getter;
import lombok.Setter;
/**
* .
*
* @author 谢明辉
* @date 2021/11/26
*/
@Getter
@Setter
public class EPedestrianModel extends ExportBaseModel {
private String upColor;
private String lowColor;
private String gender;
private String height;
private String withHat;
private String location;
}
package com.viontech.fanxing.query.model.export;
import lombok.Getter;
import lombok.Setter;
/**
* .
*
* @author 谢明辉
* @date 2021/11/26
*/
@Getter
@Setter
public class ETrafficModel extends ExportBaseModel {
private String plateNumber;
private String plateColor;
private String vehicleType;
private String vehicleBrand;
private String vehicleColor;
// private String seatBelt = "未知";
// private String phone = "未知";
// private String hugChild = "未知";
private String location = "未知";
}
package com.viontech.fanxing.query.model.export;
import lombok.Getter;
import lombok.Setter;
/**
* .
*
* @author 谢明辉
* @date 2021/11/26
*/
@Getter
@Setter
public class EXcycleModel extends ExportBaseModel{
private String xcycleType;
private String company;
private String velocity;
private String location;
}
package com.viontech.fanxing.query.model.export;
import lombok.Getter;
import lombok.Setter;
/**
* .
*
* @author 谢明辉
* @date 2021/11/26
*/
@Getter
@Setter
public class EbehaviorModel extends ExportBaseModel {
private String eventType;
private String taskName;
}
package com.viontech.fanxing.query.model.export;
import lombok.Getter;
import lombok.Setter;
/**
* .
*
* @author 谢明辉
* @date 2021/11/26
*/
@Getter
@Setter
public class ExportBaseModel {
private String picName;
private String videoName;
private String eventTime;
}
package com.viontech.fanxing.query.model.export;
/**
* .
*
* @author 谢明辉
* @date 2021/11/25
*/
public enum ExportDataTypeEnum {
/** 过车数据 */
TRAFFIC(1),
/** 非机动车 */
XCYCLE(2),
/** 行人 */
PEDESTRIAN(3),
/** 违法数据 */
ILLEGAL(4),
/** 流量数据 */
FLOW(5),
/** 事件数据 */
BEHAVIOR(6);
public int type;
ExportDataTypeEnum(int type) {
this.type = type;
}
}
package com.viontech.fanxing.query.service.adapter;
import com.viontech.fanxing.commons.base.BaseService;
import com.viontech.fanxing.commons.model.ExportData;
public interface ExportDataService extends BaseService<ExportData> {
}
\ No newline at end of file
package com.viontech.fanxing.query.service.impl;
import com.viontech.fanxing.commons.base.BaseMapper;
import com.viontech.fanxing.commons.base.BaseServiceImpl;
import com.viontech.fanxing.commons.config.VionConfig;
import com.viontech.fanxing.commons.exception.FanXingException;
import com.viontech.fanxing.commons.model.ExportData;
import com.viontech.fanxing.query.mapper.ExportDataMapper;
import com.viontech.fanxing.query.service.adapter.ExportDataService;
import org.apache.commons.io.FileUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.io.File;
@Service
public class ExportDataServiceImpl extends BaseServiceImpl<ExportData> implements ExportDataService {
@Resource
private ExportDataMapper exportDataMapper;
@Resource
private VionConfig vionConfig;
@Override
public BaseMapper<ExportData> getMapper() {
return exportDataMapper;
}
@Override
@Transactional(rollbackFor = Exception.class)
public int deleteByPrimaryKey(Object b) {
int i = super.deleteByPrimaryKey(b);
File file = new File(vionConfig.getImage().getPath() + "/export/" + b.toString());
try {
FileUtils.deleteDirectory(file);
} catch (Exception e) {
throw new FanXingException("无法删除目录:{[]}", file.getPath());
}
return i;
}
}
\ No newline at end of file
package com.viontech.fanxing.query.service.main;
import com.viontech.fanxing.commons.base.LocalCache;
import com.viontech.fanxing.commons.constant.LogType;
import com.viontech.fanxing.commons.exception.FanXingException;
import com.viontech.fanxing.commons.model.Channel;
import com.viontech.fanxing.commons.model.Content;
import com.viontech.fanxing.commons.model.DictCode;
import com.viontech.fanxing.commons.model.StoreConfig;
import com.viontech.fanxing.commons.model.*;
import com.viontech.fanxing.commons.vo.LogVo;
import com.viontech.fanxing.query.feign.OpsClient;
import com.viontech.keliu.util.JsonMessageUtil;
......@@ -18,6 +16,9 @@ import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
* .
......@@ -92,4 +93,80 @@ public class OpsClientService {
}
}
@LocalCache(value = "dictCates12312", timeunit = TimeUnit.DAYS, duration = 1)
public Map<String, DictCate> dictCates() {
JsonMessageUtil.JsonMessage<List<DictCate>> response = opsClient.getDictCates();
if (response.isSuccess()) {
List<DictCate> data = response.getData();
Map<String, DictCate> collect = data.stream().collect(Collectors.toMap(DictCate::getCode, x -> x, (a, b) -> a));
return collect;
} else {
throw new FanXingException(response.getMsg());
}
}
@LocalCache(value = "dictCodes123456789")
public Map<Long, Map<String, DictCode>> dictCodes() {
JsonMessageUtil.JsonMessage<List<DictCode>> response = opsClient.getDictCodes();
if (response.isSuccess()) {
List<DictCode> data = response.getData();
Map<Long, Map<String, DictCode>> collect = data.stream().collect(Collectors.groupingBy(DictCode::getCateId, Collectors.toMap(DictCode::getCode, x -> x, (a, b) -> a)));
return collect;
} else {
throw new FanXingException(response.getMsg());
}
}
@LocalCache(value = "plateColorDict", timeunit = TimeUnit.HOURS, duration = 1)
public Map<String, DictCode> plateColorDict() {
return getDictByCate("plate_color");
}
@LocalCache(value = "vehicleColorDict", timeunit = TimeUnit.HOURS, duration = 1)
public Map<String, DictCode> vehicleColorDict() {
return getDictByCate("vehicle_color");
}
@LocalCache(value = "illegalTypeDict", timeunit = TimeUnit.HOURS, duration = 1)
public Map<String, DictCode> illegalTypeDict() {
return getDictByCate("illegal_type");
}
@LocalCache(value = "vehicleTypeDict", timeunit = TimeUnit.HOURS, duration = 1)
public Map<String, DictCode> vehicleTypeDict() {
return getDictByCate("vehicle_type");
}
@LocalCache(value = "vehicleBrandDict", timeunit = TimeUnit.HOURS, duration = 1)
public Map<String, DictCode> vehicleBrandDict() {
return getDictByCate("vehicle_brand");
}
@LocalCache(value = "illegalTypedDict", timeunit = TimeUnit.HOURS, duration = 1)
public Map<String, DictCode> illegalTypedDict() {
return getDictByCate("illegal_type");
}
@LocalCache(value = "behaviorDict", timeunit = TimeUnit.HOURS, duration = 1)
public Map<String, DictCode> behaviorDict() {
return getDictByCate("behavior");
}
@LocalCache(value = "companyDict", timeunit = TimeUnit.HOURS, duration = 1)
public Map<String, DictCode> companyDict() {
return getDictByCate("company");
}
private Map<String, DictCode> getDictByCate(String cateCode) {
Map<String, DictCate> cateMap = dictCates();
DictCate cate = cateMap.get(cateCode);
if (cate == null) {
return null;
}
Long id = cate.getId();
Map<Long, Map<String, DictCode>> dictCodes = dictCodes();
return dictCodes.get(id);
}
}
......@@ -53,4 +53,6 @@ pagehelper:
params: count=countByExample
vion:
redisson:
path: F:\myIDEAworkspace\jt\fanxing3\fanxing-commons\src\main\resources\redisson.yml
\ No newline at end of file
path: F:\myIDEAworkspace\jt\fanxing3\fanxing-commons\src\main\resources\redisson.yml
image:
path: G:\data
\ No newline at end of file
package com.viontech.fanxing.query;
import com.viontech.fanxing.commons.model.DictCode;
import com.viontech.fanxing.commons.model.Traffic;
import com.viontech.fanxing.commons.vo.TrafficVo;
import com.viontech.fanxing.query.model.export.ETrafficModel;
import com.viontech.fanxing.query.runner.ExportDataJob;
import com.viontech.fanxing.query.service.adapter.TrafficService;
import com.viontech.fanxing.query.service.main.OpsClientService;
import com.viontech.keliu.util.DateUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Profile;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import java.util.Date;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
/**
* .
*
* @author 谢明辉
* @date 2021/11/26
*/
@RunWith(SpringRunner.class)
@SpringBootTest
@ActiveProfiles("test")
public class MainTest {
@Resource
private OpsClientService opsClientService;
@Resource
private TrafficService trafficService;
@Test
public void test() {
Traffic traffic = trafficService.selectByPrimaryKey(5808875);
TrafficVo trafficVo = new TrafficVo(traffic);
ETrafficModel e = new ETrafficModel();
Date eventTime = trafficVo.getEventTime();
e.setEventTime(DateUtil.format(DateUtil.FORMAT_FULL, eventTime));
e.setPicName(UUID.randomUUID() + ".pic");
e.setLocation(trafficVo.getLocationName());
e.setPlateNumber(trafficVo.getPlateNumber());
Map<String, DictCode> vehicleTypeDict = opsClientService.vehicleTypeDict();
Map<String, DictCode> vehicleColorDict = opsClientService.vehicleColorDict();
Map<String, DictCode> plateColorDict = opsClientService.plateColorDict();
Map<String, DictCode> vehicleBrandDict = opsClientService.vehicleBrandDict();
String plateColor = Optional.ofNullable(plateColorDict.get(trafficVo.getPlateColor())).map(DictCode::getName).orElse("未识别");
String vehicleType = Optional.ofNullable(vehicleTypeDict.get(trafficVo.getVehicleType())).map(DictCode::getName).orElse("未识别");
String vehicleBrand = Optional.ofNullable(vehicleBrandDict.get(trafficVo.getVehicleLogo())).map(DictCode::getName).orElse("未识别");
String vehicleColor = Optional.ofNullable(vehicleColorDict.get(trafficVo.getVehicleColor())).map(DictCode::getName).orElse("未识别");
e.setPlateColor(plateColor);
e.setVehicleType(vehicleType);
e.setVehicleBrand(vehicleBrand);
e.setVehicleColor(vehicleColor);
}
}
......@@ -56,5 +56,8 @@
<table delimitIdentifiers="true" tableName="d_traffic_face" alias="trafficFace" domainObjectName="TrafficFace">
<generatedKey column="id" sqlStatement="JDBC"/>
</table>
<table delimitIdentifiers="true" tableName="d_export_data" alias="exportData" domainObjectName="ExportData">
<generatedKey column="id" sqlStatement="JDBC"/>
</table>
</context>
</generatorConfiguration>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!