Commit a8fc8049 by xmh

<feat> 移植流量检索功能

<feat> 检索时加日志
1 parent 005d6629
package com.viontech.fanxing.query.controller.web; package com.viontech.fanxing.query.controller.web;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SerializeFilter;
import com.alibaba.fastjson.serializer.SimplePropertyPreFilter;
import com.viontech.fanxing.commons.base.BaseExample; import com.viontech.fanxing.commons.base.BaseExample;
import com.viontech.fanxing.commons.base.BaseMapper; import com.viontech.fanxing.commons.model.BehaviorExample;
import com.viontech.fanxing.commons.vo.BehaviorVo; import com.viontech.fanxing.commons.vo.BehaviorVo;
import com.viontech.fanxing.query.controller.base.BehaviorBaseController; import com.viontech.fanxing.query.controller.base.BehaviorBaseController;
import com.viontech.fanxing.commons.model.Behavior; import com.viontech.fanxing.query.service.main.OpsClientService;
import com.viontech.fanxing.commons.model.BehaviorExample;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import javax.annotation.Resource;
@Controller @Controller
@RequestMapping("/behaviors") @RequestMapping("/behaviors")
public class BehaviorController extends BehaviorBaseController { public class BehaviorController extends BehaviorBaseController {
@Resource
private OpsClientService opsClientService;
@Override @Override
protected BaseExample getExample(BehaviorVo behaviorVo, int type) { protected BaseExample getExample(BehaviorVo behaviorVo, int type) {
BehaviorExample behaviorExample = (BehaviorExample)super.getExample(behaviorVo,type); BehaviorExample behaviorExample = (BehaviorExample) super.getExample(behaviorVo, type);
return behaviorExample; return behaviorExample;
} }
@Override
public Object page(BehaviorVo behaviorVo, int page, int pageSize, String sortName, String sortOrder) {
Assert.notNull(behaviorVo.getEventTime_gte(), "起始时间不能为空");
Assert.notNull(behaviorVo.getEventTime_lte(), "结束时间不能为空");
SimplePropertyPreFilter simplePropertyPreFilter = new SimplePropertyPreFilter();
simplePropertyPreFilter.getExcludes().add("model");
opsClientService.addLog("检索分析结果,条件:" + JSON.toJSONString(behaviorVo, SerializeConfig.globalInstance, new SerializeFilter[]{simplePropertyPreFilter}, "yyyy-MM-dd HH:mm:ss", JSON.DEFAULT_GENERATE_FEATURE));
return super.page(behaviorVo, page, pageSize, sortName, sortOrder);
}
} }
\ No newline at end of file \ No newline at end of file
package com.viontech.fanxing.query.controller.web; package com.viontech.fanxing.query.controller.web;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SerializeFilter;
import com.alibaba.fastjson.serializer.SimplePropertyPreFilter;
import com.viontech.fanxing.commons.base.BaseExample; import com.viontech.fanxing.commons.base.BaseExample;
import com.viontech.fanxing.commons.base.BaseMapper; import com.viontech.fanxing.commons.model.FlowEventExample;
import com.viontech.fanxing.commons.vo.FlowEventVo; import com.viontech.fanxing.commons.vo.FlowEventVo;
import com.viontech.fanxing.query.controller.base.FlowEventBaseController; import com.viontech.fanxing.query.controller.base.FlowEventBaseController;
import com.viontech.fanxing.commons.model.FlowEvent; import com.viontech.fanxing.query.mapper.FlowMapper;
import com.viontech.fanxing.commons.model.FlowEventExample; import com.viontech.fanxing.query.model.TrafficFlowDataModel;
import com.viontech.fanxing.query.model.TrafficFlowEventModel;
import com.viontech.fanxing.query.model.TrafficFlowRequestVo;
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.stereotype.Controller;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
@Controller @Controller
@RequestMapping("/flowEvents") @RequestMapping("/flowEvents")
public class FlowEventController extends FlowEventBaseController { public class FlowEventController extends FlowEventBaseController {
@Resource
private FlowMapper flowMapper;
@Resource
private OpsClientService opsClientService;
@Override @Override
protected BaseExample getExample(FlowEventVo flowEventVo, int type) { protected BaseExample getExample(FlowEventVo flowEventVo, int type) {
FlowEventExample flowEventExample = (FlowEventExample)super.getExample(flowEventVo,type); FlowEventExample flowEventExample = (FlowEventExample) super.getExample(flowEventVo, type);
return flowEventExample; return flowEventExample;
} }
@GetMapping("/statistics")
@ResponseBody
public JsonMessageUtil.JsonMessage statistics(TrafficFlowRequestVo trafficFlowRequestVo) {
Assert.hasLength(trafficFlowRequestVo.getEvent_dt__gte(), "起始时间不能为空");
Assert.hasLength(trafficFlowRequestVo.getEvent_dt__lt(), "结束时间不能为空");
Assert.hasLength(trafficFlowRequestVo.getStatistic_type(), "统计方式不能为空");
SimplePropertyPreFilter simplePropertyPreFilter = new SimplePropertyPreFilter();
simplePropertyPreFilter.getExcludes().add("model");
opsClientService.addLog("检索分析结果,条件:" + JSON.toJSONString(trafficFlowRequestVo, SerializeConfig.globalInstance, new SerializeFilter[]{simplePropertyPreFilter}, "yyyy-MM-dd HH:mm:ss", JSON.DEFAULT_GENERATE_FEATURE));
try {
Map<String, Object> result = new HashMap<String, Object>(4);
String detection_type = trafficFlowRequestVo.getDetection_type() != null && !trafficFlowRequestVo.getDetection_type().isEmpty() ? trafficFlowRequestVo.getDetection_type().get(0) : null;
if (trafficFlowRequestVo.getOffset() == null) {
trafficFlowRequestVo.setOffset(0);
}
if (trafficFlowRequestVo.getLimit() == null) {
trafficFlowRequestVo.setLimit(100);
}
trafficFlowRequestVo.setVdev_unid("tflow_statics");
List<TrafficFlowEventModel> trafficFlowEventModels = flowMapper.selectEvents(trafficFlowRequestVo);
int counts = flowMapper.counts(trafficFlowRequestVo);
result.put("offset", trafficFlowRequestVo.getOffset());
result.put("total_num", counts);
if (trafficFlowEventModels != null && trafficFlowEventModels.size() > 0) {
// StringBuffer eventdts = new StringBuffer("('_1')");
// StringBuffer idList = new StringBuffer("(-1)");
// trafficFlowEventModels.forEach(trafficFlowEventModel -> {
// eventdts.append(",('").append(trafficFlowEventModel.getEvent_dt()).append("')");
// idList.append(",(").append(trafficFlowEventModel.getId()).append(")");
// });
Set<Long> collect = trafficFlowEventModels.stream().map(TrafficFlowEventModel::getId).collect(Collectors.toSet());
trafficFlowRequestVo.setIdSet(collect);
// trafficFlowRequestVo.setEventdts(eventdts.toString());
}
if (CollectionUtils.isEmpty(trafficFlowRequestVo.getIdSet())) {
result.put("offset", trafficFlowRequestVo.getOffset());
result.put("total_num", 0);
result.put("regionids", null);
result.put("list_data", new ArrayList<>(1));
result.put("event_type", trafficFlowRequestVo.getEvent_type());
result.put("maxRoadNum", 0);
return JsonMessageUtil.getSuccessJsonMsg(result);
}
if (StringUtils.isBlank(trafficFlowRequestVo.getStatistic_type())) {
trafficFlowRequestVo.setStatistic_type("road");
}
switch (trafficFlowRequestVo.getStatistic_type()) {
case "road":
trafficFlowRequestVo.setColumn_List(" flow_event_id,td.event_time,\n" +
"\t\tcase when te.device_name is null OR te.device_name='' then '-' else te.device_name end as device_name,\n" +
"\t\tcase when te.location_name is null OR te.location_name='' then '-' else te.location_name end as location_name,\n" +
" road_code as road,\n" +
"\t\tSUM(td.velocity*td.sample_num)/(CASE WHen sum(td.sample_num)=0 then 1 ELSE sum(td.sample_num) end) as velocity,AVG(td.occupy) as occupy,AVG(td.distance) as distance ,AVG(td.queue_length) as queue_length,AVG(td.sample_dura) as sample_dura ,\n" +
" sum(td.sample_num) as sample_num,\n" +
"\t\tAVG ( td.time_occupy ) AS time_occupy,\n" +
"\t\tAVG ( td.dist_time ) AS dist_time");
trafficFlowRequestVo.setGroupByClause(" flow_event_id,td.event_time,te.device_name,te.location_name,td.road_code ");
trafficFlowRequestVo.setOrderByClause(" td.event_time,flow_event_id,te.device_name,te.location_name,cast(road as signed INTEGER) ASC ");
List<TrafficFlowDataModel> l = flowMapper.flowstatistics(trafficFlowRequestVo);
result.put("list_data", report(trafficFlowEventModels, l, detection_type, trafficFlowRequestVo.getDevice_name()));
return JsonMessageUtil.getSuccessJsonMsg(result);
case "device":
trafficFlowRequestVo.setColumn_List(" td.event_time,flow_event_id,\n" +
"\t\tcase when te.device_name is null OR te.device_name='' then '-' else te.device_name end as device_name,\n" +
"\t\tcase when te.location_name is null OR te.location_name='' then '-' else te.location_name end as location_name,\n" +
" case when td.direction_code is null OR td.direction_code='' then '-' else td.direction_code end as direction,\n" +
"\t\tSUM(td.velocity*td.sample_num)/(CASE WHen sum(td.sample_num)=0 then 1 ELSE sum(td.sample_num) end) as velocity,AVG(td.occupy) as occupy,AVG(td.distance) as distance ,AVG(td.queue_length) as queue_length,AVG(td.sample_dura) as sample_dura ,\n" +
" sum(td.sample_num) as sample_num,\n" +
"\t\tAVG ( td.time_occupy ) AS time_occupy,\n" +
"\t\tAVG ( td.dist_time ) AS dist_time");
trafficFlowRequestVo.setGroupByClause(" td.event_time,flow_event_id,te.device_name,te.location_name,td.direction_code");
trafficFlowRequestVo.setOrderByClause(" td.event_time,flow_event_id,te.device_name,te.location_name,td.direction_code ASC ");
result.put("list_data", report(trafficFlowEventModels, flowMapper.flowstatistics(trafficFlowRequestVo), detection_type, trafficFlowRequestVo.getDevice_name()));
return JsonMessageUtil.getSuccessJsonMsg(result);
default:
return JsonMessageUtil.getSuccessJsonMsg();
}
} catch (Exception e) {
e.printStackTrace();
return JsonMessageUtil.getErrorJsonMsg("失败");
}
}
private List report(List<TrafficFlowEventModel> trafficFlowEventModels, List<TrafficFlowDataModel> trafficFlowDataModels, String detection_type, String device_name) {
List result = Optional.ofNullable(trafficFlowEventModels).map(tfem -> {
List trees = new ArrayList<>();
try {
tfem.forEach(trafficFlowEventModel -> {
Map data;
Iterator<TrafficFlowDataModel> it = trafficFlowDataModels == null ? null : trafficFlowDataModels.iterator();
while (it != null && it.hasNext()) {
data = new TreeMap();
TrafficFlowDataModel tra = it.next();
if (trafficFlowEventModel.getId().equals(tra.getEventId())) {
if (StringUtils.isNotBlank(device_name) && !device_name.equals(tra.getDeviceName())) {
continue;
}
data.put("road", tra.getRoad());
data.put("direction", tra.getDirection());
data.put("sample_dura", tra.getSampleDura());
data.put("sample_num", tra.getSampleNum());
data.put("velocity", tra.getVelocity());
data.put("velocity_unit", tra.getVelocityUnit());
data.put("occupy", tra.getOccupy());
data.put("distance", tra.getDistance());
data.put("queue_length", tra.getQueueLength());
data.put("detection_type", detection_type);
data.put("device_name", tra.getDeviceName());
data.put("location_name", tra.getLocationName());
data.put("event_dt", tra.getEventTime());
data.put("time_occupy", tra.getTimeOccupy());
data.put("dist_time", tra.getDistTime());
trees.add(data);
it.remove();
}
}
});
} catch (Exception e) {
e.printStackTrace();
}
return trees;
}).orElse(new ArrayList<Map>());
return result;
}
} }
\ No newline at end of file \ No newline at end of file
package com.viontech.fanxing.query.controller.web; package com.viontech.fanxing.query.controller.web;
import com.alibaba.fastjson.JSON;
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.base.BaseExample;
import com.viontech.fanxing.commons.base.BaseMapper; import com.viontech.fanxing.commons.model.TrafficExample;
import com.viontech.fanxing.commons.vo.TrafficVo; import com.viontech.fanxing.commons.vo.TrafficVo;
import com.viontech.fanxing.query.controller.base.TrafficBaseController; import com.viontech.fanxing.query.controller.base.TrafficBaseController;
import com.viontech.fanxing.commons.model.Traffic; import com.viontech.fanxing.query.service.main.OpsClientService;
import com.viontech.fanxing.commons.model.TrafficExample;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestMapping; 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 javax.annotation.Resource;
import java.util.List;
import static com.viontech.keliu.util.JsonMessageUtil.getSuccessJsonMsg;
@Controller @Controller
@RequestMapping("/traffics") @RequestMapping("/traffics")
public class TrafficController extends TrafficBaseController { public class TrafficController extends TrafficBaseController {
@Resource
private OpsClientService opsClientService;
@Override @Override
protected BaseExample getExample(TrafficVo trafficVo, int type) { protected BaseExample getExample(TrafficVo trafficVo, int type) {
TrafficExample trafficExample = (TrafficExample)super.getExample(trafficVo,type); TrafficExample trafficExample = (TrafficExample) super.getExample(trafficVo, type);
trafficExample.createColumns().hasIdColumn().hasEventTimeColumn();
return trafficExample; return trafficExample;
} }
@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) {
Assert.hasLength(trafficVo.getEventType(), "数据类型不能为空");
Assert.notNull(trafficVo.getEventTime_gte(), "起始时间不能为空");
Assert.notNull(trafficVo.getEventTime_lte(), "结束时间不能为空");
SimplePropertyPreFilter simplePropertyPreFilter = new SimplePropertyPreFilter();
simplePropertyPreFilter.getExcludes().add("model");
opsClientService.addLog("检索分析结果,条件:" + JSON.toJSONString(trafficVo, SerializeConfig.globalInstance, new SerializeFilter[]{simplePropertyPreFilter}, "yyyy-MM-dd HH:mm:ss", JSON.DEFAULT_GENERATE_FEATURE));
BaseExample baseExample = getExample(trafficVo, EXAMPLE_TYPE_PAGE);
if (isNotNull(sortOrder) && isNotNull(sortName)) {
baseExample.setOrderByClause(baseExample.getTableAlias() + "." + sortName + " " + sortOrder);
} else if (isNotNull(sortName) && !isNotNull(sortOrder)) {
baseExample.setOrderByClause(sortName);
}
if (page <= 0) {
List result = getService().selectByExample(baseExample);
return getSuccessJsonMsg(MESSAGE_SELECT_SUCCESS, result);
} else {
PageInfo pageInfo = getService().pagedQuery(baseExample, page, pageSize);
return getSuccessJsonMsg(MESSAGE_PAGE_SUCCESS, pageInfo);
}
}
} }
\ No newline at end of file \ No newline at end of file
package com.viontech.fanxing.query.feign;
import com.viontech.fanxing.commons.model.*;
import com.viontech.fanxing.commons.vo.LogVo;
import com.viontech.keliu.util.JsonMessageUtil;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* .
*
* @author 谢明辉
* @date 2021/7/20
*/
@Component
@FeignClient(value = "fanxing-ops")
public interface OpsClient {
@GetMapping("/storeConfigs/{id}")
JsonMessageUtil.JsonMessage<StoreConfig> getStoreConfigById(@PathVariable("id") Long storeConfigId);
@GetMapping("/contents")
JsonMessageUtil.JsonMessage<List<Content>> getContentByName(@RequestParam("name") String name);
@GetMapping("/channels")
JsonMessageUtil.JsonMessage<List<Channel>> getChannelByChannelUnid(@RequestParam("channelUnid") String channelUnid);
@GetMapping("/dictCodes")
JsonMessageUtil.JsonMessage<List<DictCode>> getDictCodeByUnid(@RequestParam("unid") String unid);
@PostMapping("/logs")
JsonMessageUtil.JsonMessage<Log> addLog(@RequestBody LogVo logVo);
}
package com.viontech.fanxing.query.mapper;
import com.viontech.fanxing.query.model.TrafficFlowDataModel;
import com.viontech.fanxing.query.model.TrafficFlowEventModel;
import com.viontech.fanxing.query.model.TrafficFlowRequestVo;
import java.util.List;
/**
* .
*
* @author 谢明辉
* @date 2021/11/16
*/
public interface FlowMapper {
List<TrafficFlowEventModel> selectEvents(TrafficFlowRequestVo trafficFlowRequestVo);
int counts(TrafficFlowRequestVo trafficFlowRequestVo);
List<TrafficFlowDataModel> flowstatistics(TrafficFlowRequestVo trafficFlowRequestVo);
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.viontech.fanxing.query.mapper.FlowMapper">
<resultMap id="baseMap" type="com.viontech.fanxing.query.model.TrafficFlowEventModel">
<result column="id" property="id"/>
<result column="event_dt" property="event_dt"/>
</resultMap>
<resultMap id="dataMap" type="com.viontech.fanxing.query.model.TrafficFlowDataModel">
<result column="flow_event_id" property="eventId"/>
<result column="event_time" property="eventTime"/>
<result column="road" property="road"/>
<result column="device_name" property="deviceName"/>
<result column="location_name" property="locationName"/>
<result column="velocity" property="velocity"/>
<result column="occupy" property="occupy"/>
<result column="distance" property="distance"/>
<result column="sample_dura" property="sampleDura"/>
<result column="queue_length" property="queueLength"/>
<result column="sample_num" property="sampleNum"/>
<result column="direction" property="direction"/>
<result column="time_occupy" property="timeOccupy"/>
<result column="dist_time" property="distTime"/>
</resultMap>
<select id="selectEvents" parameterType="com.viontech.fanxing.query.model.TrafficFlowRequestVo" resultMap="baseMap">
select date_format(te.event_time, '%Y-%m-%d %H:%i:%s') as event_dt,
date_format(te.event_time, '%Y-%m-%d %H:%i:%s') as gevent_dt,
te.id
from d_flow_event te
, d_flow_data
<where>
and d_flow_data.flow_event_id = te.id
AND d_flow_data.road_code != '0'
<if test="task_id != null and task_id != ''">
and te.task_id = #{task_id}
</if>
<if test="event_dt__gte != null and event_dt__lt != null">
and te.event_time <![CDATA[>=]]> #{event_dt__gte}
and te.event_time <![CDATA[<=]]> #{event_dt__lt}
</if>
</where>
GROUP BY gevent_dt, te.id
<if test="statistic_type == 'road'">
, d_flow_data.road_code
</if>
order by event_dt desc
<if test="offset != null and limit != null">
LIMIT #{limit} offset #{offset}
</if>
</select>
<select id="counts" parameterType="com.viontech.fanxing.query.model.TrafficFlowRequestVo" resultType="int">
select count(1) as count from (
select date_format(te.event_time, '%Y-%m-%d %H:%i:%s') as gevent_dt
from d_flow_event te
, d_flow_data
<where>
and d_flow_data.flow_event_id = te.id
AND d_flow_data.road_code != '0'
<if test="task_id != null and task_id != ''">
and te.task_id = #{task_id}
</if>
<if test="event_dt__gte != null and event_dt__lt != null">
and te.event_time <![CDATA[>=]]> #{event_dt__gte}
and te.event_time <![CDATA[<=]]> #{event_dt__lt}
</if>
</where>
GROUP BY gevent_dt, te.id
) as con
</select>
<select id="flowstatistics" parameterType="com.viontech.fanxing.query.model.TrafficFlowRequestVo"
resultMap="dataMap">
select ${column_List}
from d_flow_event te,
d_flow_data td
<where>
<if test="idSet != null">
and td.flow_event_id in
<foreach collection="idSet" item="id" index="index" open="(" close=")" separator=",">
#{id}
</foreach>
</if>
and te.id = td.flow_event_id
<if test="task_id != null">
and td.task_id = #{task_id}
</if>
<if test="detection_type != null and detection_type.size > 0">
and detection_type in
<foreach item="item" index="index" collection="detection_type" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="vehicle_type != null and vehicle_type.length != 0">
and td.detection_type in
<foreach item="item" index="index" collection="vehicle_type"
open="(" separator="," close=")">
#{item}
</foreach>
</if>
and road_code != '0'
</where>
GROUP BY ${groupByClause}
ORDER BY ${orderByClause}
<if test="limit != null">
LIMIT #{limit}
</if>
</select>
</mapper>
\ No newline at end of file \ No newline at end of file
package com.viontech.fanxing.query.model;
/**
* Created by Administrator on 2018/8/9.
*/
public class TrafficBaseModel {
private String event_cate;
private String task_id;
private String task_type;
private String subtask_id;
private String source_type;
private String event_type;
private String dev_unid;
private String vchan_refid;
private String vdev_unid;
private String vchan_duid;
private String event_dt;
private String event_data;
private String device_name;
private String location_name;
private String device_code;
private String location_code;
public String getEvent_cate() {
return event_cate;
}
public void setEvent_cate(String event_cate) {
this.event_cate = event_cate;
}
public String getTask_id() {
return task_id;
}
public void setTask_id(String task_id) {
this.task_id = task_id;
}
public String getTask_type() {
return task_type;
}
public void setTask_type(String task_type) {
this.task_type = task_type;
}
public String getSubtask_id() {
return subtask_id;
}
public void setSubtask_id(String subtask_id) {
this.subtask_id = subtask_id;
}
public String getSource_type() {
return source_type;
}
public void setSource_type(String source_type) {
this.source_type = source_type;
}
public String getEvent_type() {
return event_type;
}
public void setEvent_type(String event_type) {
this.event_type = event_type;
}
public String getDev_unid() {
return dev_unid;
}
public void setDev_unid(String dev_unid) {
this.dev_unid = dev_unid;
}
public String getVchan_refid() {
return vchan_refid;
}
public void setVchan_refid(String vchan_refid) {
this.vchan_refid = vchan_refid;
}
public String getVdev_unid() {
return vdev_unid;
}
public void setVdev_unid(String vdev_unid) {
this.vdev_unid = vdev_unid;
}
public String getVchan_duid() {
return vchan_duid;
}
public void setVchan_duid(String vchan_duid) {
this.vchan_duid = vchan_duid;
}
public String getEvent_dt() {
return event_dt;
}
public void setEvent_dt(String event_dt) {
this.event_dt = event_dt;
}
public String getEvent_data() {
return event_data;
}
public void setEvent_data(String event_data) {
this.event_data = event_data;
}
public String getDevice_name() {
return device_name;
}
public void setDevice_name(String device_name) {
this.device_name = device_name;
}
public String getLocation_name() {
return location_name;
}
public void setLocation_name(String location_name) {
this.location_name = location_name;
}
public String getDevice_code() {
return device_code;
}
public void setDevice_code(String device_code) {
this.device_code = device_code;
}
public String getLocation_code() {
return location_code;
}
public void setLocation_code(String location_code) {
this.location_code = location_code;
}
}
package com.viontech.fanxing.query.model;
public class TrafficFlowBaseRequestVo {
private String[] location_codes;
private String[] vehicle_type;
private String[] device_codes;
private String event_date;
private String start_time;
private String end_time;
private String exportType;
private String start_event_date;
public String[] getLocation_codes() {
return location_codes;
}
public void setLocation_codes(String[] location_codes) {
this.location_codes = location_codes;
}
public String[] getVehicle_type() {
return vehicle_type;
}
public void setVehicle_type(String[] vehicle_type) {
this.vehicle_type = vehicle_type;
}
public String[] getDevice_codes() {
return device_codes;
}
public void setDevice_codes(String[] device_codes) {
this.device_codes = device_codes;
}
public String getEvent_date() {
return event_date;
}
public void setEvent_date(String event_date) {
this.event_date = event_date;
}
public String getStart_time() {
return start_time;
}
public void setStart_time(String start_time) {
this.start_time = start_time;
}
public String getEnd_time() {
return end_time;
}
public void setEnd_time(String end_time) {
this.end_time = end_time;
}
public String getExportType() {
return exportType;
}
public void setExportType(String exportType) {
this.exportType = exportType;
}
public String getStart_event_date() {
return start_event_date;
}
public void setStart_event_date(String start_event_date) {
this.start_event_date = start_event_date;
}
}
package com.viontech.fanxing.query.model;
import lombok.Getter;
import lombok.Setter;
import java.util.Date;
@Getter
@Setter
public class TrafficFlowDataModel {
private Long eventId;
private Date eventTime;
/** 车道标志符编码 */
private String road;
/** 行驶方向编码 */
private String direction;
/** 采样周期(秒) */
private Integer sampleDura;
/** 车流量,辆/采样周期 */
private Integer sampleNum;
/** 流速 */
private Double velocity;
/** km/h", 流速单位 */
private String velocityUnit;
/** 车道占有率 */
private Double occupy;
/** 车头间距 */
private Double distance;
private String deviceName;
private String locationName;
private String queueLength;
private String detectionType;
private Double timeOccupy;
private Double distTime;
}
package com.viontech.fanxing.query.model;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.util.List;
/**
* Created by Administrator on 2018/8/9.
*/
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public class TrafficFlowEventModel extends TrafficBaseModel {
private String unid;
private String event_id;
private Long Id;
//大车
private List<TrafficFlowDataModel> big_vehicle;
//小车
private List<TrafficFlowDataModel> small_vehicle;
//非机动车
private List<TrafficFlowDataModel> xcycle;
//行人
private List<TrafficFlowDataModel> pedestrian;
private Object json_data;
private String pic_name;
private String video_name;
private String event_dtime;
public String getPic_name() {
return pic_name;
}
public void setPic_name(String pic_name) {
this.pic_name = pic_name;
}
public String getVideo_name() {
return video_name;
}
public void setVideo_name(String video_name) {
this.video_name = video_name;
}
public String getUnid() {
return unid;
}
public void setUnid(String unid) {
this.unid = unid;
}
public String getEvent_id() {
return event_id;
}
public void setEvent_id(String event_id) {
this.event_id = event_id;
}
public List<TrafficFlowDataModel> getBig_vehicle() {
return big_vehicle;
}
public void setBig_vehicle(List<TrafficFlowDataModel> big_vehicle) {
this.big_vehicle = big_vehicle;
}
public List<TrafficFlowDataModel> getSmall_vehicle() {
return small_vehicle;
}
public void setSmall_vehicle(List<TrafficFlowDataModel> small_vehicle) {
this.small_vehicle = small_vehicle;
}
public List<TrafficFlowDataModel> getXcycle() {
return xcycle;
}
public void setXcycle(List<TrafficFlowDataModel> xcycle) {
this.xcycle = xcycle;
}
public List<TrafficFlowDataModel> getPedestrian() {
return pedestrian;
}
public void setPedestrian(List<TrafficFlowDataModel> pedestrian) {
this.pedestrian = pedestrian;
}
public Object getJson_data() {
return json_data;
}
public void setJson_data(Object json_data) {
this.json_data = json_data;
}
public String getEvent_dtime() {
return event_dtime;
}
public void setEvent_dtime(String event_dtime) {
this.event_dtime = event_dtime;
}
public Long getId() {
return Id;
}
public TrafficFlowEventModel setId(Long id) {
Id = id;
return this;
}
}
package com.viontech.fanxing.query.model;
import lombok.Getter;
import lombok.Setter;
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 String dev_unid;// 可选,精确匹配,产生数据的设备的unid
private String vchan_refid;//可选,精确匹配,视频通道的参考id
private String vdev_unid;// 可选,精确匹配,视频通道所在设备的unid
private String vchan_duid;//可选,精确匹配,视频通道的duid
private String road;//车道编号
private String direction;//行驶方向编码,参见统一编码服务。
private String task_name__like;//任务名称
private String device_name;// 相机名称
private String source_type;//任务输入源的类型,目前有三种push_pic_files,pull_video_stream,pull_pic_files(
private String statistic_type;// 必填,统计类型(road 表示车道、detection表示检测类型)
private String param_type;// 必填,参数类型(1为流量统计、2为平均车速、3为车头间距、4为时间占有率、5为排队长度)
private List<String> detection_type;//["big_vehicle","small_vehicle",...] #检测类型(big_vehicle大车、small_vehicle小车、xcycle非机动车、pedestrian行人
private Integer statistic_time;
private String statistic_time_unit;
private Long task_id;
private String subtask_id;
private String unids;
private String eventdts;
private String event_type;
private Integer offset = 0;
private Integer limit = 500;
private List task_ids;
private String[] location_codes;
private String[] device_codes;
private String location_name;
private String column_List;
private String orderByClause;
private String groupByClause;
private Set<Long> idSet;
}
package com.viontech.fanxing.query.service.impl; package com.viontech.fanxing.query.service.impl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.viontech.fanxing.commons.base.BaseExample;
import com.viontech.fanxing.commons.base.BaseMapper; import com.viontech.fanxing.commons.base.BaseMapper;
import com.viontech.fanxing.commons.base.BaseServiceImpl; import com.viontech.fanxing.commons.base.BaseServiceImpl;
import com.viontech.fanxing.query.mapper.TrafficMapper;
import com.viontech.fanxing.commons.model.Traffic; import com.viontech.fanxing.commons.model.Traffic;
import com.viontech.fanxing.commons.model.TrafficExample;
import com.viontech.fanxing.query.mapper.TrafficMapper;
import com.viontech.fanxing.query.service.adapter.TrafficService; import com.viontech.fanxing.query.service.adapter.TrafficService;
import javax.annotation.Resource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service @Service
public class TrafficServiceImpl extends BaseServiceImpl<Traffic> implements TrafficService { public class TrafficServiceImpl extends BaseServiceImpl<Traffic> implements TrafficService {
@Resource @Resource
...@@ -17,4 +24,24 @@ public class TrafficServiceImpl extends BaseServiceImpl<Traffic> implements Traf ...@@ -17,4 +24,24 @@ public class TrafficServiceImpl extends BaseServiceImpl<Traffic> implements Traf
public BaseMapper<Traffic> getMapper() { public BaseMapper<Traffic> getMapper() {
return trafficMapper; return trafficMapper;
} }
@Override
public List<Traffic> selectByExample(BaseExample example) {
return trafficMapper.selectByExampleWithBLOBs((TrafficExample) example);
}
@Override
public PageInfo<Traffic> pagedQuery(BaseExample example, int pageNum, int pageSize) {
if (pageSize > 0) {
PageHelper.startPage(pageNum, pageSize);
Page<Traffic> result = (Page<Traffic>) trafficMapper.selectByExampleWithBLOBs((TrafficExample) example);
return new PageInfo<>(result);
} else {
List<Traffic> result = trafficMapper.selectByExampleWithBLOBs((TrafficExample) example);
Page<Traffic> p = new Page<>();
p.addAll(result);
return new PageInfo<>(p);
}
}
} }
\ No newline at end of file \ No newline at end of file
package com.viontech.fanxing.query.service.main;
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.vo.LogVo;
import com.viontech.fanxing.query.feign.OpsClient;
import com.viontech.keliu.util.JsonMessageUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
/**
* .
*
* @author 谢明辉
* @date 2021/9/28
*/
@Service
@Slf4j
public class OpsClientService {
@Resource
private OpsClient opsClient;
public StoreConfig getStoreConfigById(Long id) {
JsonMessageUtil.JsonMessage<StoreConfig> res = opsClient.getStoreConfigById(id);
if (res.getCode() != 200) {
throw new FanXingException(res.getMsg());
} else {
return res.getData();
}
}
public String getContentByName(String name) {
JsonMessageUtil.JsonMessage<List<Content>> res = opsClient.getContentByName(name);
if (res.getCode() != 200) {
throw new FanXingException(res.getMsg());
} else {
List<Content> data = res.getData();
return (data == null || data.size() == 0) ? null : data.get(0).getContent();
}
}
public Channel getChannelByChannelUnid(String channelUnid) {
JsonMessageUtil.JsonMessage<List<Channel>> res = opsClient.getChannelByChannelUnid(channelUnid);
if (res.getCode() != 200) {
throw new FanXingException(res.getMsg());
} else {
List<Channel> data = res.getData();
return (data == null || data.size() == 0) ? null : data.get(0);
}
}
public DictCode getDictCodeByUnid(String unid) {
JsonMessageUtil.JsonMessage<List<DictCode>> res = opsClient.getDictCodeByUnid(unid);
if (res.getCode() != 200) {
throw new FanXingException(res.getMsg());
} else {
List<DictCode> data = res.getData();
return (data == null || data.size() == 0) ? null : data.get(0);
}
}
public void addLog(String content) {
try {
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
String username = null;
if (requestAttributes != null) {
HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
username = request.getHeader("username");
}
LogVo logVo = new LogVo();
logVo.setUsername(username);
logVo.setLogType(LogType.QUERY.value);
logVo.setContent(content);
opsClient.addLog(logVo);
} catch (Exception e) {
log.error("添加日志失败:", e);
}
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!