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.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!