diff --git a/src/main/java/com/nis/domain/Page.java b/src/main/java/com/nis/domain/Page.java index 733c2fb..fa864f4 100644 --- a/src/main/java/com/nis/domain/Page.java +++ b/src/main/java/com/nis/domain/Page.java @@ -518,7 +518,7 @@ public class Page { */ public Page setList(List list) { this.list = list; - initialize(); +// initialize(); return this; } diff --git a/src/main/java/com/nis/domain/restful/NtcCollectVoipLog.java b/src/main/java/com/nis/domain/restful/NtcCollectVoipLog.java new file mode 100644 index 0000000..8479133 --- /dev/null +++ b/src/main/java/com/nis/domain/restful/NtcCollectVoipLog.java @@ -0,0 +1,429 @@ +package com.nis.domain.restful; + +import java.io.Serializable; +import java.util.Date; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.nis.domain.LogEntity; +import com.wordnik.swagger.annotations.ApiModelProperty; + +/** + * + * @ClassName:NtcCollectVoipLog + * @Description:TODO(这里用一句话描述这个类的作用) + * @author zdx + * @date 2018年11月5日 下午5:50:18 + * @version V1.0 + */ +public class NtcCollectVoipLog implements Serializable{ + + private static final long serialVersionUID = -8215121930207772717L; + + @ApiModelProperty(value = "节目ID", required = true) + protected String pid; + + @ApiModelProperty(value = "发现时间", required = true) + protected Date foundTime; + @ApiModelProperty(value = "接收时间", required = true) + protected Date recvTime; + @ApiModelProperty(value = "处理机IP", required = true) + protected String capIp; + @ApiModelProperty(value = "VOIP协议", required = true) + protected String voipProtocol; + @ApiModelProperty(value = "RTP服务端ip地址", required = true) + protected String rtpDIp; + @ApiModelProperty(value = "RTP客户端ip地址", required = true) + protected String rtpSIp; + @ApiModelProperty(value = "RTP服务端端口", required = true) + protected Integer rtpDPort; + @ApiModelProperty(value = "RTP客户端端口", required = true) + protected Integer rtpSPort; + @ApiModelProperty(value = "主叫VOIP语音文件存放服务器IP", required = true) + protected String fromToStoreIp; + @ApiModelProperty(value = "主叫VOIP语音文件存放服务器URL", required = true) + protected String fromToStoreUrl; + @ApiModelProperty(value = "被叫VOIP语音文件存放服务器IP", required = true) + protected String toFromStoreIp; + @ApiModelProperty(value = "被叫VOIP语音文件存放服务器URL", required = true) + protected String toFromStoreUrl; + @ApiModelProperty(value = "VOIP通话时长(秒)", required = true) + protected String duation; + @ApiModelProperty(value = "SIP服务端ip地址", required = true) + protected String sipDIp; + @ApiModelProperty(value = "SIP客户端ip地址", required = true) + protected String sipSIp; + @ApiModelProperty(value = "SIP服务端端口", required = true) + protected Integer sipDPort; + @ApiModelProperty(value = "SIP客户端端口", required = true) + protected Integer sipSPort; + @ApiModelProperty(value = "SIP会话ID", required = true) + protected String callId; + @ApiModelProperty(value = "SIP请求URI", required = true) + protected String requestUri; + @ApiModelProperty(value = "SIP主叫VOIP账号", required = true) + protected String callingAccount; + @ApiModelProperty(value = "SIP被叫VOIP账号", required = true) + protected String calledAccount; + @ApiModelProperty(value = "SIP相应字段", required = true) + protected String contacts; + @ApiModelProperty(value = "SIP相应字段", required = true) + protected String via; + @ApiModelProperty(value = "SIP相应字段", required = true) + protected String route; + @ApiModelProperty(value = "SIP相应字段", required = true) + protected String recordRoute; + @ApiModelProperty(value = "SIP相应字段", required = true) + protected String userAgent; + @ApiModelProperty(value = "SIP相应字段", required = true) + protected String server; + + protected String searchVoipProtocol;//协议类型 + protected String searchRtpDIp;//RTP服务端ip + protected String searchRtpSIp;//RTP客户端ip + protected String searchSipDIp;//SIP服务端ip + protected String searchDipDIp;//SIP客户端ip + protected String searchCapIp;//处理机IP + protected String searchFoundStartTime;//开始发现时间 + protected String searchFoundEndTime;//结束发现时间 + + public NtcCollectVoipLog(String pid, Date foundTime, Date recvTime, + String capIp, String voipProtocol, String rtpDIp, String rtpSIp, + Integer rtpDPort, Integer rtpSPort, String fromToStoreIp, + String fromToStoreUrl, String toFromStoreIp, String toFromStoreUrl, + String duation, String sipDIp, String sipSIp, Integer sipDPort, + Integer sipSPort, String callId, String requestUri, + String callingAccount, String calledAccount, String contacts, + String via, String route, String recordRoute, String userAgent, + String server) { + super(); + this.pid = pid; + this.foundTime = foundTime; + this.recvTime = recvTime; + this.capIp = capIp; + this.voipProtocol = voipProtocol; + this.rtpDIp = rtpDIp; + this.rtpSIp = rtpSIp; + this.rtpDPort = rtpDPort; + this.rtpSPort = rtpSPort; + this.fromToStoreIp = fromToStoreIp; + this.fromToStoreUrl = fromToStoreUrl; + this.toFromStoreIp = toFromStoreIp; + this.toFromStoreUrl = toFromStoreUrl; + this.duation = duation; + this.sipDIp = sipDIp; + this.sipSIp = sipSIp; + this.sipDPort = sipDPort; + this.sipSPort = sipSPort; + this.callId = callId; + this.requestUri = requestUri; + this.callingAccount = callingAccount; + this.calledAccount = calledAccount; + this.contacts = contacts; + this.via = via; + this.route = route; + this.recordRoute = recordRoute; + this.userAgent = userAgent; + this.server = server; + } + + public NtcCollectVoipLog() { + super(); + // TODO Auto-generated constructor stub + } + + /** + * @return the voipProtocol + */ + public String getVoipProtocol() { + return voipProtocol; + } + + /** + * @param voipProtocol + * the voipProtocol to set + */ + public void setVoipProtocol(String voipProtocol) { + this.voipProtocol = voipProtocol; + } + + public String getDuation() { + return duation; + } + + public void setDuation(String duation) { + this.duation = duation; + } + + public String getCallingAccount() { + return callingAccount; + } + + public void setCallingAccount(String callingAccount) { + this.callingAccount = callingAccount; + } + + public String getCalledAccount() { + return calledAccount; + } + + public void setCalledAccount(String calledAccount) { + this.calledAccount = calledAccount; + } + + public String getPid() { + return pid; + } + + public void setPid(String pid) { + this.pid = pid; + } + + public Date getFoundTime() { + return foundTime; + } + + public void setFoundTime(Date foundTime) { + this.foundTime = foundTime; + } + + public Date getRecvTime() { + return recvTime; + } + + public void setRecvTime(Date recvTime) { + this.recvTime = recvTime; + } + + public String getCapIp() { + return capIp; + } + + public void setCapIp(String capIp) { + this.capIp = capIp; + } + + public String getRtpDIp() { + return rtpDIp; + } + + public void setRtpDIp(String rtpDIp) { + this.rtpDIp = rtpDIp; + } + + public String getRtpSIp() { + return rtpSIp; + } + + public void setRtpSIp(String rtpSIp) { + this.rtpSIp = rtpSIp; + } + + public Integer getRtpDPort() { + return rtpDPort; + } + + public void setRtpDPort(Integer rtpDPort) { + this.rtpDPort = rtpDPort; + } + + public Integer getRtpSPort() { + return rtpSPort; + } + + public void setRtpSPort(Integer rtpSPort) { + this.rtpSPort = rtpSPort; + } + + public String getFromToStoreIp() { + return fromToStoreIp; + } + + public void setFromToStoreIp(String fromToStoreIp) { + this.fromToStoreIp = fromToStoreIp; + } + + public String getFromToStoreUrl() { + return fromToStoreUrl; + } + + public void setFromToStoreUrl(String fromToStoreUrl) { + this.fromToStoreUrl = fromToStoreUrl; + } + + public String getToFromStoreIp() { + return toFromStoreIp; + } + + public void setToFromStoreIp(String toFromStoreIp) { + this.toFromStoreIp = toFromStoreIp; + } + + public String getToFromStoreUrl() { + return toFromStoreUrl; + } + + public void setToFromStoreUrl(String toFromStoreUrl) { + this.toFromStoreUrl = toFromStoreUrl; + } + + public String getSipDIp() { + return sipDIp; + } + + public void setSipDIp(String sipDIp) { + this.sipDIp = sipDIp; + } + + public String getSipSIp() { + return sipSIp; + } + + public void setSipSIp(String sipSIp) { + this.sipSIp = sipSIp; + } + + public Integer getSipDPort() { + return sipDPort; + } + + public void setSipDPort(Integer sipDPort) { + this.sipDPort = sipDPort; + } + + public Integer getSipSPort() { + return sipSPort; + } + + public void setSipSPort(Integer sipSPort) { + this.sipSPort = sipSPort; + } + + public String getCallId() { + return callId; + } + + public void setCallId(String callId) { + this.callId = callId; + } + + public String getRequestUri() { + return requestUri; + } + + public void setRequestUri(String requestUri) { + this.requestUri = requestUri; + } + + public String getContacts() { + return contacts; + } + + public void setContacts(String contacts) { + this.contacts = contacts; + } + + public String getVia() { + return via; + } + + public void setVia(String via) { + this.via = via; + } + + public String getRoute() { + return route; + } + + public void setRoute(String route) { + this.route = route; + } + + public String getRecordRoute() { + return recordRoute; + } + + public void setRecordRoute(String recordRoute) { + this.recordRoute = recordRoute; + } + + public String getUserAgent() { + return userAgent; + } + + public void setUserAgent(String userAgent) { + this.userAgent = userAgent; + } + + public String getServer() { + return server; + } + + public void setServer(String server) { + this.server = server; + } + @JsonIgnore + public String getSearchVoipProtocol() { + return searchVoipProtocol; + } + + public void setSearchVoipProtocol(String searchVoipProtocol) { + this.searchVoipProtocol = searchVoipProtocol; + } + @JsonIgnore + public String getSearchRtpDIp() { + return searchRtpDIp; + } + + public void setSearchRtpDIp(String searchRtpDIp) { + this.searchRtpDIp = searchRtpDIp; + } + @JsonIgnore + public String getSearchRtpSIp() { + return searchRtpSIp; + } + + public void setSearchRtpSIp(String searchRtpSIp) { + this.searchRtpSIp = searchRtpSIp; + } + @JsonIgnore + public String getSearchSipDIp() { + return searchSipDIp; + } + + public void setSearchSipDIp(String searchSipDIp) { + this.searchSipDIp = searchSipDIp; + } + @JsonIgnore + public String getSearchDipDIp() { + return searchDipDIp; + } + + public void setSearchDipDIp(String searchDipDIp) { + this.searchDipDIp = searchDipDIp; + } + @JsonIgnore + public String getSearchCapIp() { + return searchCapIp; + } + + public void setSearchCapIp(String searchCapIp) { + this.searchCapIp = searchCapIp; + } + @JsonIgnore + public String getSearchFoundStartTime() { + return searchFoundStartTime; + } + + public void setSearchFoundStartTime(String searchFoundStartTime) { + this.searchFoundStartTime = searchFoundStartTime; + } + + @JsonIgnore + public String getSearchFoundEndTime() { + return searchFoundEndTime; + } + + public void setSearchFoundEndTime(String searchFoundEndTime) { + this.searchFoundEndTime = searchFoundEndTime; + } +} diff --git a/src/main/java/com/nis/util/Constants.java b/src/main/java/com/nis/util/Constants.java index 5d5f45c..74620ed 100644 --- a/src/main/java/com/nis/util/Constants.java +++ b/src/main/java/com/nis/util/Constants.java @@ -196,6 +196,10 @@ public final class Constants { * 日志查询是否使用clickhouse,否则使用hive */ public static final Boolean ISUSECLICKHOUSE = Configurations.getBooleanProperty("isUseClickHouse", true); + /** + * 是否开启日志查询count和last功能 + */ + public static final Boolean ISOPENLOGCOUNTANDLAST = Configurations.getBooleanProperty("isOpenLogCountAndLast", true); public static final String DIGEST_GEN_TOOL_PATH = Configurations.getStringProperty("digest.gen.tool.path", "maat-redis/digest_gen"); diff --git a/src/main/java/com/nis/util/LogJDBCByDruid.java b/src/main/java/com/nis/util/LogJDBCByDruid.java index 164de1b..e45a39d 100644 --- a/src/main/java/com/nis/util/LogJDBCByDruid.java +++ b/src/main/java/com/nis/util/LogJDBCByDruid.java @@ -15,7 +15,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import com.zdjizhi.utils.StringUtil; import org.apache.ibatis.mapping.ResultMap; import org.apache.ibatis.mapping.ResultMapping; import org.apache.ibatis.session.SqlSessionFactory; @@ -23,17 +22,17 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.alibaba.druid.pool.DruidDataSource; -import com.jolbox.bonecp.BoneCPDataSource; import com.nis.domain.Page; import com.nis.web.service.SpringContextHolder; +import com.zdjizhi.utils.StringUtil; /** * *

- * Title: HiveJDBCByDruid + * Title: LogJDBCByDruid *

*

- * Description: 使用druid连接池对hive进行查询并解析结果 + * Description: 使用druid连接池对hive或clickhouse进行查询并解析结果 *

*

* Company: IIE @@ -50,7 +49,7 @@ public class LogJDBCByDruid { ResultSet rs = null; Statement st = null; - public static Connection getConnection() throws SQLException { + private static Connection getConnection() throws SQLException { if (datasource == null) { if (Constants.ISUSECLICKHOUSE) { datasource = (DruidDataSource) SpringContextHolder.getBean("ClickHouseDataSourceByDruid"); @@ -62,25 +61,17 @@ public class LogJDBCByDruid { } /** - * 将结果利用反射映射成对象集合 + * 根据sql从数据中心中获取日志并set到list中 * - * @param rs - * resultSet + * @param page + * @param sql * @param entityClass - * 实体类 - * @param obj - * 那些字段需要转换为date类型(由于数据中心表结构中没有date类型数据,其日期用long型表示,界面中需要显示yyyy-MM-dd - * hh:mm:ss形式,所以需要将long转换为date) - * @return * @throws Exception */ - public Map> tableMapping(Page page, String redisKey, String sql, Class entityClass, - Object... obj) throws Exception { - Map> mapList = new HashMap>(); + public void getTableData(Page page, String sql, Class entityClass) throws Exception { + List listObject = new ArrayList(); try { Map filedAndColumnMap = getColumn2FiledMap(entityClass); - List listString = new ArrayList(); - List listObject = new ArrayList(); // 不从Object... obj中获取需要date类型的字段了,调用的时候容易漏写,改为反射获取date类型的字段 List columnList = getDateColumn(entityClass); conn = getConnection(); @@ -100,8 +91,6 @@ public class LogJDBCByDruid { long time = 0L; time = Long.parseLong(value.toString()); map.put(filedName, time == 0L ? null : new Date(time * 1000)); - // map.put(filedName, new - // Date(Long.parseLong("1476583810000"))); } else { map.put(filedName, value); } @@ -109,51 +98,23 @@ public class LogJDBCByDruid { map.put(filedName, null); } } - listString.add(JsonMapper.toJsonString(map2Obj(map, entityClass))); - listObject.add(map2Obj(map, entityClass)); + listObject.add((T) map2Obj(map, entityClass)); } - if (null == listString || listString.size() == 0 || null == listObject || listObject.size() == 0) { - return null; + if (null == listObject || listObject.size() == 0) { + page.setList(new ArrayList()); } else { - // 暂时没有往缓存写的操作 - // if (Constants.IS_OPEN_REDIS && Constants.DATACENTER_OPEN_REDIS) { - // new SaveRedisListThread(redisKey, listString, Constants.HIVE_EXPIRE).start(); - // } - } - if (Constants.ISUSECLICKHOUSE) {// sql查询时已经分页了 - mapList.put("str", listString); - mapList.put("obj", listObject); - } else { - // sublist包前不包后,0-30实际获取的是0-29的数据 - Integer startNum = (page.getPageNo() - 1) * page.getPageSize(); - Integer endNum = startNum - 1 + page.getPageSize() + 1; - if (listString.size() >= startNum) { - if (listString.size() >= endNum) { - mapList.put("str", listString.subList(startNum, endNum)); - } else { - mapList.put("str", listString.subList(startNum, listString.size())); - } - - } else { - mapList.put("str", new ArrayList()); - } - if (listObject.size() >= startNum) { - if (listObject.size() >= endNum) { - mapList.put("obj", listObject.subList(startNum, endNum)); - } else { - mapList.put("obj", listObject.subList(startNum, listObject.size())); - } - } else { - mapList.put("obj", new ArrayList()); - } + page.setList(listObject); } + logger.info("执行日志查询语句成功,sql={}", sql); } finally { closeConn(); } - return mapList; } - public void closeConn() { + /** + * 关闭数据库连接 + */ + private void closeConn() { try { if (rs != null) { rs.close(); @@ -181,7 +142,7 @@ public class LogJDBCByDruid { * @return * @throws Exception */ - public static List getDateColumn(Class type) throws Exception { + private static List getDateColumn(Class type) throws Exception { List columnList = new ArrayList(); BeanInfo beanInfo = Introspector.getBeanInfo(type); PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); @@ -196,7 +157,15 @@ public class LogJDBCByDruid { return columnList; } - public static Object map2Obj(Map map, Class beanClass) throws Exception { + /** + * 将map中的数据利用反射set到Class中,并返回设置好值的对象 + * + * @param map + * @param beanClass + * @return + * @throws Exception + */ + private static Object map2Obj(Map map, Class beanClass) throws Exception { BeanInfo beanInfo = Introspector.getBeanInfo(beanClass); Object obj = beanClass.newInstance(); PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); @@ -237,7 +206,13 @@ public class LogJDBCByDruid { return obj; } - public static Map getColumn2FiledMap(Class clazz) { + /** + * 根据class从DfLogSearchDao.xml中获取对应的resultMap里column与property的关系,key是column + * + * @param clazz + * @return + */ + private static Map getColumn2FiledMap(Class clazz) { Map map = new HashMap(); SqlSessionFactory sqlSessionFactory = SpringContextHolder.getBean(SqlSessionFactory.class); ResultMap resultMap = sqlSessionFactory.getConfiguration().getResultMap(clazz.getSimpleName() + "Map"); @@ -249,25 +224,19 @@ public class LogJDBCByDruid { } - public ResultSet query(String sql) throws Exception { - conn = getConnection(); - logger.info("连接数据中心日志库成功--------------------------"); - st = conn.createStatement(); - // logger.info("开始选择{}数据库--------------------------", Constants.HIVEDBNAME); - // String hiveAName = "use " + Constants.HIVEDBNAME; - // st.execute(hiveAName); - // logger.info("选择数据库{}成功,开始执行查询", Constants.HIVEDBNAME); - // logger.info("选择数据库{}成功,开始执行查询", Constants.HIVEDBNAME); - rs = st.executeQuery(sql); - logger.info("执行查询语句成功sql={}", sql); - return rs; - - } - - public long getCount(String sql) throws Exception { + /** + * 执行count的sql并将结果和计算的last的值set到page对象中 + * + * @param page + * @param sql + * @throws Exception + */ + public void getCount(Page page, String sql) throws Exception { try { conn = getConnection(); + logger.info("连接数据中心日志库成功--------------------------"); st = conn.createStatement(); + logger.info("开始执行查询日志总条数sql={}", sql); rs = st.executeQuery(sql); String countStr = null; while (rs.next()) { @@ -275,14 +244,26 @@ public class LogJDBCByDruid { break; } if (countStr == null || countStr.trim().equals("")) { - logger.info("获取数据中心日志总条数成功总共===================0条配置"); - return 0l; + logger.info("获取数据中心日志总条数成功,总共0条日志,sql={}", sql); + page.setCount(0l); + page.setLast(1); } else { - return Long.valueOf(countStr); + Long count = Long.valueOf(countStr); + logger.info("获取数据中心日志总条数成功,总共{}条日志,sql={}", count, sql); + page.setCount(count); + page.setLast(getLastPageNum(count.intValue(), page.getPageSize())); } } finally { closeConn(); } } + private int getLastPageNum(int totalCount, int pageSize) { + int pageNum = totalCount / pageSize; + if (totalCount % pageSize > 0) { + pageNum++; + } + return pageNum; + } + } diff --git a/src/main/java/com/nis/web/controller/BaseRestController.java b/src/main/java/com/nis/web/controller/BaseRestController.java index 53a2177..140eb19 100644 --- a/src/main/java/com/nis/web/controller/BaseRestController.java +++ b/src/main/java/com/nis/web/controller/BaseRestController.java @@ -24,16 +24,17 @@ import org.springframework.web.bind.WebDataBinder; import org.springframework.web.bind.annotation.InitBinder; import org.springframework.web.bind.annotation.RequestMethod; +import com.nis.domain.LogEntity; import com.nis.domain.restful.ConfigCommonSource; import com.nis.restful.RestBusinessCode; import com.nis.restful.RestConstants; import com.nis.restful.RestResult; import com.nis.restful.RestServiceException; -import com.nis.util.Configurations; import com.nis.util.Constants; import com.nis.util.DateUtils; import com.nis.web.service.AuditLogThread; import com.nis.web.service.ServicesRequestLogService; +import com.zdjizhi.utils.StringUtil; /** * @ClassName: BaseRestController @@ -402,19 +403,19 @@ public class BaseRestController { return thread; } - - protected String getTableName(String key, String defaultTableName) { - if (Constants.ISUSECLICKHOUSE) { - key = key.replace("HiveTable", "ClickHouseTable"); + /** + * 判断开始和结束时间是否为null,如果为null则初始化时间 + * + * @param entity + * @throws Exception + */ + protected void resetTime(LogEntity entity) throws Exception { + if (StringUtil.isEmpty(entity.getSearchFoundStartTime()) + && StringUtil.isEmpty(entity.getSearchFoundEndTime())) { + Map map = DateUtils.getLocalTime(entity.getSearchFoundStartTime(), + entity.getSearchFoundEndTime(), Constants.LOG_LOCAL_TIME, "minute"); + entity.setSearchFoundStartTime(map.get("startTime")); + entity.setSearchFoundEndTime(map.get("endTime")); } - return Configurations.getStringProperty(key, defaultTableName); - } - - protected int getLastPageNum(int totalCount, int pageSize) { - int pageNum = totalCount / pageSize; - if (totalCount % pageSize > 0) { - pageNum++; - } - return pageNum; } } diff --git a/src/main/java/com/nis/web/controller/restful/LogController.java b/src/main/java/com/nis/web/controller/restful/LogController.java index 4296f42..b1b82de 100644 --- a/src/main/java/com/nis/web/controller/restful/LogController.java +++ b/src/main/java/com/nis/web/controller/restful/LogController.java @@ -1,33 +1,24 @@ package com.nis.web.controller.restful; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import com.zdjizhi.utils.StringUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; -import com.nis.domain.LogEntity; import com.nis.domain.Page; import com.nis.domain.restful.DkBehaviorLog; import com.nis.domain.restful.PxyHttpLog; import com.nis.restful.RestServiceException; -import com.nis.util.Configurations; import com.nis.util.Constants; -import com.nis.util.DateUtils; -import com.nis.util.LogJDBCByDruid; -import com.nis.util.JsonMapper; import com.nis.web.controller.BaseRestController; import com.nis.web.service.AuditLogThread; -import com.nis.web.service.HiveSqlService; +import com.nis.web.service.LogDataService; import com.nis.web.service.ServicesRequestLogService; import com.nis.web.service.restful.NtcLogService; import com.wordnik.swagger.annotations.Api; @@ -35,11 +26,18 @@ import com.wordnik.swagger.annotations.ApiOperation; /** * - *

Title: LogController

- *

Description: 日志查询controller

- *

Company: IIE

+ *

+ * Title: LogController + *

+ *

+ * Description: 日志查询controller + *

+ *

+ * Company: IIE + *

+ * * @author rkg - * @date 2018年7月2日 + * @date 2018年7月2日 * */ @RestController @@ -48,51 +46,23 @@ import com.wordnik.swagger.annotations.ApiOperation; public class LogController extends BaseRestController { @Autowired protected ServicesRequestLogService servicesRequestLogService; - + @Autowired protected NtcLogService ntcLogService; + @Autowired + private LogDataService logDataService; @RequestMapping(value = "/dkBehaviorLogs", method = RequestMethod.GET) @ApiOperation(value = "行为识别日志查询", httpMethod = "GET", notes = "对日志功能“行为识别”提供数据基础查询服务") - public Map dkBehaviorLogs(Page page, DkBehaviorLog dkBehaviorLog, Model model, HttpServletRequest request, - HttpServletResponse response) { + public Map dkBehaviorLogs(Page page, DkBehaviorLog dkBehaviorLog, Model model, + HttpServletRequest request, HttpServletResponse response) { long start = System.currentTimeMillis(); - AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, - request, null); - - Page logPage = null; + AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, + null); try { resetTime(dkBehaviorLog); ntcLogService.queryConditionCheck(auditLogThread, start, dkBehaviorLog, DkBehaviorLog.class, page); - logPage = new Page(); - logPage.setPageNo(page.getPageNo()); - logPage.setPageSize(page.getPageSize()); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = Page.getOrderBySql(DkBehaviorLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - String sql = HiveSqlService.getSql(page, dkBehaviorLog, - getTableName(DkBehaviorLog.class.getSimpleName() + "HiveTable", "DK_BEHAVIOR_LOG"), - getCol2Col(), orderBy, null); - Map> tableMapping = new LogJDBCByDruid().tableMapping(page, null, sql, DkBehaviorLog.class, "foundTime", - "recvTime"); - if (tableMapping == null) { - logPage.setList(new ArrayList()); - } else { - List list = tableMapping.get("obj"); - if (list.size() > 0) { - String jsonString = JsonMapper.toJsonString(list); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - DkBehaviorLog.class); - logPage.setList(List); - logPage.setCount(List.size()); - - } else { - logPage.setList(new ArrayList()); - } - } + logDataService.getData(page, dkBehaviorLog); } catch (Exception e) { e.printStackTrace(); auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause()); @@ -102,50 +72,21 @@ public class LogController extends BaseRestController { } throw ((RestServiceException) e); } - return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "行为识别日志检索成功", - logPage, 0); + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "行为识别日志检索成功", page, 0); } + @RequestMapping(value = "/pxyHttpLogs", method = RequestMethod.GET) @ApiOperation(value = "PXY HTTP日志查询", httpMethod = "GET", notes = "对日志功能“控制策略”-“HTTP日志”提供数据基础查询服务") public Map pxyHttpLogs(Page page, PxyHttpLog pxyHttpLog, Model model, HttpServletRequest request, HttpServletResponse response) { long start = System.currentTimeMillis(); - AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, - request, null); + AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, + null); - Page logPage = null; try { resetTime(pxyHttpLog); ntcLogService.queryConditionCheck(auditLogThread, start, pxyHttpLog, PxyHttpLog.class, page); - logPage = new Page(); - logPage.setPageNo(page.getPageNo()); - logPage.setPageSize(page.getPageSize()); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = Page.getOrderBySql(PxyHttpLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - String sql = HiveSqlService.getSql(page, pxyHttpLog, - getTableName(PxyHttpLog.class.getSimpleName() + "HiveTable", "PXY_HTTP_LOG"), - getCol2Col(), orderBy, null); - Map> tableMapping = new LogJDBCByDruid().tableMapping(page, null, sql, PxyHttpLog.class, "foundTime", - "recvTime"); - if (tableMapping == null) { - logPage.setList(new ArrayList()); - } else { - List list = tableMapping.get("obj"); - if (list.size() > 0) { - String jsonString = JsonMapper.toJsonString(list); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - PxyHttpLog.class); - logPage.setList(List); - logPage.setCount(List.size()); - - } else { - logPage.setList(new ArrayList()); - } - } + logDataService.getData(page, pxyHttpLog); } catch (Exception e) { e.printStackTrace(); auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause()); @@ -155,40 +96,8 @@ public class LogController extends BaseRestController { } throw ((RestServiceException) e); } - return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "PXY HTTP日志检索成功", - logPage, 0); - } - - - - - /** - *判断开始和结束时间是否为null,如果为null则初始化时间 - * @param entity - * @throws Exception - */ - public void resetTime(LogEntity entity) throws Exception { - if (StringUtil.isEmpty(entity.getSearchFoundStartTime())&& StringUtil.isEmpty(entity.getSearchFoundEndTime())) { - Map map = DateUtils.getLocalTime(entity.getSearchFoundStartTime(), - entity.getSearchFoundEndTime(), Constants.LOG_LOCAL_TIME, "minute"); - entity.setSearchFoundStartTime(map.get("startTime")); - entity.setSearchFoundEndTime(map.get("endTime")); - } - } - - /** - * 将searchFoundStartTime,searchFoundEndTime与foundTime进行关联 - * @return - */ - public Map> getCol2Col() { - Map> col2col = new HashMap>(); - Map startMap = new HashMap(); - startMap.put("start", "foundTime"); - col2col.put("searchFoundStartTime", startMap); - Map endMap = new HashMap(); - endMap.put("end", "foundTime"); - col2col.put("searchFoundEndTime", endMap); - return col2col; + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "PXY HTTP日志检索成功", page, + 0); } } diff --git a/src/main/java/com/nis/web/controller/restful/MmLogSearchController.java b/src/main/java/com/nis/web/controller/restful/MmLogSearchController.java index 50d0808..98869ed 100644 --- a/src/main/java/com/nis/web/controller/restful/MmLogSearchController.java +++ b/src/main/java/com/nis/web/controller/restful/MmLogSearchController.java @@ -1,22 +1,16 @@ package com.nis.web.controller.restful; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import com.zdjizhi.utils.StringUtil; -import org.apache.ibatis.annotations.Delete; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; -import com.nis.domain.LogEntity; import com.nis.domain.Page; import com.nis.domain.restful.MmAvIpLog; import com.nis.domain.restful.MmAvUrlLog; @@ -36,12 +30,9 @@ import com.nis.domain.restful.MmVoipAccountLog; import com.nis.domain.restful.MmVoipIpLog; import com.nis.restful.RestServiceException; import com.nis.util.Constants; -import com.nis.util.DateUtils; -import com.nis.util.JsonMapper; -import com.nis.util.LogJDBCByDruid; import com.nis.web.controller.BaseRestController; import com.nis.web.service.AuditLogThread; -import com.nis.web.service.HiveSqlService; +import com.nis.web.service.LogDataService; import com.nis.web.service.ServicesRequestLogService; import com.nis.web.service.restful.NtcLogService; import com.wordnik.swagger.annotations.Api; @@ -61,51 +52,24 @@ import com.wordnik.swagger.annotations.ApiOperation; public class MmLogSearchController extends BaseRestController { @Autowired protected ServicesRequestLogService servicesRequestLogService; - + @Autowired protected NtcLogService ntcLogService; - + @Autowired + private LogDataService logDataService; + @RequestMapping(value = "/mmAvIpLogs", method = RequestMethod.GET) @ApiOperation(value = "音视频IP日志查询", httpMethod = "GET", notes = "对日志功能“音视频IP日志”提供数据基础查询服务") public Map mmAvIpLogs(Page page, MmAvIpLog mmAvIpLog, Model model, HttpServletRequest request, HttpServletResponse response) { long start = System.currentTimeMillis(); - AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, - request, null); + AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, + null); - Page logPage = null; try { resetTime(mmAvIpLog); ntcLogService.queryConditionCheck(auditLogThread, start, mmAvIpLog, MmAvIpLog.class, page); - logPage = new Page(); - logPage.setPageNo(page.getPageNo()); - logPage.setPageSize(page.getPageSize()); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = Page.getOrderBySql(MmAvIpLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - String sql = HiveSqlService.getSql(page, mmAvIpLog, - getTableName(MmAvIpLog.class.getSimpleName() + "HiveTable", "MM_AV_IP_LOG"), - getCol2Col(), orderBy, null); - Map> tableMapping = new LogJDBCByDruid().tableMapping(page, null, sql, MmAvIpLog.class, "foundTime", - "recvTime"); - if (tableMapping == null) { - logPage.setList(new ArrayList()); - } else { - List list = tableMapping.get("obj"); - if (list.size() > 0) { - String jsonString = JsonMapper.toJsonString(list); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - MmAvIpLog.class); - logPage.setList(List); - logPage.setCount(List.size()); - - } else { - logPage.setList(new ArrayList()); - } - } + logDataService.getData(page, mmAvIpLog); } catch (Exception e) { e.printStackTrace(); auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause()); @@ -115,50 +79,21 @@ public class MmLogSearchController extends BaseRestController { } throw ((RestServiceException) e); } - return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "音视频IP日志检索成功", - logPage, 0); + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "音视频IP日志检索成功", page, 0); } + @RequestMapping(value = "/mmAvUrlLogs", method = RequestMethod.GET) @ApiOperation(value = "音视频URL日志查询", httpMethod = "GET", notes = "对日志功能“音视频URL日志”提供数据基础查询服务") public Map mmAvUrlLogs(Page page, MmAvUrlLog mmAvUrlLog, Model model, HttpServletRequest request, HttpServletResponse response) { long start = System.currentTimeMillis(); - AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, - request, null); + AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, + null); - Page logPage = null; try { resetTime(mmAvUrlLog); ntcLogService.queryConditionCheck(auditLogThread, start, mmAvUrlLog, MmAvUrlLog.class, page); - logPage = new Page(); - logPage.setPageNo(page.getPageNo()); - logPage.setPageSize(page.getPageSize()); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = Page.getOrderBySql(MmAvUrlLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - String sql = HiveSqlService.getSql(page, mmAvUrlLog, - getTableName(MmAvUrlLog.class.getSimpleName() + "HiveTable", "MM_AV_URL_LOG"), - getCol2Col(), orderBy, null); - Map> tableMapping = new LogJDBCByDruid().tableMapping(page, null, sql, MmAvUrlLog.class, "foundTime", - "recvTime"); - if (tableMapping == null) { - logPage.setList(new ArrayList()); - } else { - List list = tableMapping.get("obj"); - if (list.size() > 0) { - String jsonString = JsonMapper.toJsonString(list); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - MmAvUrlLog.class); - logPage.setList(List); - logPage.setCount(List.size()); - - } else { - logPage.setList(new ArrayList()); - } - } + logDataService.getData(page, mmAvUrlLog); } catch (Exception e) { e.printStackTrace(); auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause()); @@ -168,50 +103,21 @@ public class MmLogSearchController extends BaseRestController { } throw ((RestServiceException) e); } - return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "音视频URL日志检索成功", - logPage, 0); + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "音视频URL日志检索成功", page, 0); } + @RequestMapping(value = "/mmPicIpLogs", method = RequestMethod.GET) @ApiOperation(value = "图片IP日志查询", httpMethod = "GET", notes = "对日志功能“图片IP日志”提供数据基础查询服务") public Map mmPicIpLogs(Page page, MmPicIpLog mmPicIpLog, Model model, HttpServletRequest request, HttpServletResponse response) { long start = System.currentTimeMillis(); - AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, - request, null); + AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, + null); - Page logPage = null; try { resetTime(mmPicIpLog); ntcLogService.queryConditionCheck(auditLogThread, start, mmPicIpLog, MmPicIpLog.class, page); - logPage = new Page(); - logPage.setPageNo(page.getPageNo()); - logPage.setPageSize(page.getPageSize()); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = Page.getOrderBySql(MmPicIpLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - String sql = HiveSqlService.getSql(page, mmPicIpLog, - getTableName(MmPicIpLog.class.getSimpleName() + "HiveTable", "MM_PIC_IP_LOG"), - getCol2Col(), orderBy, null); - Map> tableMapping = new LogJDBCByDruid().tableMapping(page, null, sql, MmPicIpLog.class, "foundTime", - "recvTime"); - if (tableMapping == null) { - logPage.setList(new ArrayList()); - } else { - List list = tableMapping.get("obj"); - if (list.size() > 0) { - String jsonString = JsonMapper.toJsonString(list); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - MmPicIpLog.class); - logPage.setList(List); - logPage.setCount(List.size()); - - } else { - logPage.setList(new ArrayList()); - } - } + logDataService.getData(page, mmPicIpLog); } catch (Exception e) { e.printStackTrace(); auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause()); @@ -221,50 +127,21 @@ public class MmLogSearchController extends BaseRestController { } throw ((RestServiceException) e); } - return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "图片IP日志检索成功", - logPage, 0); + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "图片IP日志检索成功", page, 0); } + @RequestMapping(value = "/mmPicUrlLogs", method = RequestMethod.GET) @ApiOperation(value = "图片URL日志查询", httpMethod = "GET", notes = "对日志功能“图片URL日志”提供数据基础查询服务") public Map mmPicUrlLogs(Page page, MmPicUrlLog mmPicUrlLog, Model model, HttpServletRequest request, HttpServletResponse response) { long start = System.currentTimeMillis(); - AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, - request, null); + AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, + null); - Page logPage = null; try { resetTime(mmPicUrlLog); ntcLogService.queryConditionCheck(auditLogThread, start, mmPicUrlLog, MmPicUrlLog.class, page); - logPage = new Page(); - logPage.setPageNo(page.getPageNo()); - logPage.setPageSize(page.getPageSize()); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = Page.getOrderBySql(MmPicUrlLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - String sql = HiveSqlService.getSql(page, mmPicUrlLog, - getTableName(MmPicUrlLog.class.getSimpleName() + "HiveTable", "MM_PIC_URL_LOG"), - getCol2Col(), orderBy, null); - Map> tableMapping = new LogJDBCByDruid().tableMapping(page, null, sql, MmPicUrlLog.class, "foundTime", - "recvTime"); - if (tableMapping == null) { - logPage.setList(new ArrayList()); - } else { - List list = tableMapping.get("obj"); - if (list.size() > 0) { - String jsonString = JsonMapper.toJsonString(list); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - MmPicUrlLog.class); - logPage.setList(List); - logPage.setCount(List.size()); - - } else { - logPage.setList(new ArrayList()); - } - } + logDataService.getData(page, mmPicUrlLog); } catch (Exception e) { e.printStackTrace(); auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause()); @@ -274,51 +151,23 @@ public class MmLogSearchController extends BaseRestController { } throw ((RestServiceException) e); } - return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "图片URL日志检索成功", - logPage, 0); + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "图片URL日志检索成功", page, 0); } + @Deprecated @RequestMapping(value = "/mmVoipIpLogs", method = RequestMethod.GET) @ApiOperation(value = "VoIP IP日志查询", httpMethod = "GET", notes = "对日志功能“VoIP IP日志”提供数据基础查询服务") public Map mmVoipIpLogs(Page page, MmVoipIpLog mmVoipIpLog, Model model, HttpServletRequest request, HttpServletResponse response) { long start = System.currentTimeMillis(); - AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, - request, null); + AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, + null); - Page logPage = null; try { resetTime(mmVoipIpLog); ntcLogService.queryConditionCheck(auditLogThread, start, mmVoipIpLog, MmVoipIpLog.class, page); - logPage = new Page(); - logPage.setPageNo(page.getPageNo()); - logPage.setPageSize(page.getPageSize()); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = Page.getOrderBySql(MmVoipIpLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - String sql = HiveSqlService.getSql(page, mmVoipIpLog, - getTableName(MmVoipIpLog.class.getSimpleName() + "HiveTable", "MM_VOIP_IP_LOG"), - getCol2Col(), orderBy, null); - Map> tableMapping = new LogJDBCByDruid().tableMapping(page, null, sql, MmVoipIpLog.class, "foundTime", - "recvTime"); - if (tableMapping == null) { - logPage.setList(new ArrayList()); - } else { - List list = tableMapping.get("obj"); - if (list.size() > 0) { - String jsonString = JsonMapper.toJsonString(list); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - MmVoipIpLog.class); - logPage.setList(List); - logPage.setCount(List.size()); + logDataService.getData(page, mmVoipIpLog); - } else { - logPage.setList(new ArrayList()); - } - } } catch (Exception e) { e.printStackTrace(); auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause()); @@ -328,51 +177,23 @@ public class MmLogSearchController extends BaseRestController { } throw ((RestServiceException) e); } - return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "VoIP IP日志检索成功", - logPage, 0); + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "VoIP IP日志检索成功", page, + 0); } + @Deprecated @RequestMapping(value = "/mmVoipAccountLogs", method = RequestMethod.GET) @ApiOperation(value = "VoIP Account日志查询", httpMethod = "GET", notes = "对日志功能“VoIP Account日志”提供数据基础查询服务") - public Map mmVoipAccountLogs(Page page, MmVoipAccountLog mmVoipLog, Model model, HttpServletRequest request, - HttpServletResponse response) { + public Map mmVoipAccountLogs(Page page, MmVoipAccountLog mmVoipLog, Model model, + HttpServletRequest request, HttpServletResponse response) { long start = System.currentTimeMillis(); - AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, - request, null); + AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, + null); - Page logPage = null; try { resetTime(mmVoipLog); ntcLogService.queryConditionCheck(auditLogThread, start, mmVoipLog, MmVoipAccountLog.class, page); - logPage = new Page(); - logPage.setPageNo(page.getPageNo()); - logPage.setPageSize(page.getPageSize()); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = Page.getOrderBySql(MmVoipAccountLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - String sql = HiveSqlService.getSql(page, mmVoipLog, - getTableName(MmVoipAccountLog.class.getSimpleName() + "HiveTable", "MM_VOIP_ACCOUNT_LOG"), - getCol2Col(), orderBy, null); - Map> tableMapping = new LogJDBCByDruid().tableMapping(page, null, sql, MmVoipAccountLog.class, "foundTime", - "recvTime"); - if (tableMapping == null) { - logPage.setList(new ArrayList()); - } else { - List list = tableMapping.get("obj"); - if (list.size() > 0) { - String jsonString = JsonMapper.toJsonString(list); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - MmVoipAccountLog.class); - logPage.setList(List); - logPage.setCount(List.size()); - - } else { - logPage.setList(new ArrayList()); - } - } + logDataService.getData(page, mmVoipLog); } catch (Exception e) { e.printStackTrace(); auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause()); @@ -383,50 +204,21 @@ public class MmLogSearchController extends BaseRestController { throw ((RestServiceException) e); } return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "VoIP Account日志检索成功", - logPage, 0); + page, 0); } - + @RequestMapping(value = "/mmSampleAudioLogs", method = RequestMethod.GET) @ApiOperation(value = "音频样例日志查询", httpMethod = "GET", notes = "对日志功能“音频样例日志”提供数据基础查询服务") - public Map mmSampleAudioLogs(Page page, MmSampleAudioLog mmSampleAudioLog, Model model, HttpServletRequest request, - HttpServletResponse response) { + public Map mmSampleAudioLogs(Page page, MmSampleAudioLog mmSampleAudioLog, Model model, + HttpServletRequest request, HttpServletResponse response) { long start = System.currentTimeMillis(); - AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, - request, null); + AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, + null); - Page logPage = null; try { resetTime(mmSampleAudioLog); ntcLogService.queryConditionCheck(auditLogThread, start, mmSampleAudioLog, MmSampleAudioLog.class, page); - logPage = new Page(); - logPage.setPageNo(page.getPageNo()); - logPage.setPageSize(page.getPageSize()); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = Page.getOrderBySql(MmSampleAudioLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - String sql = HiveSqlService.getSql(page, mmSampleAudioLog, - getTableName(MmSampleAudioLog.class.getSimpleName() + "HiveTable", "MM_SAMPLE_AUDIO_LOG"), - getCol2Col(), orderBy, null); - Map> tableMapping = new LogJDBCByDruid().tableMapping(page, null, sql, MmSampleAudioLog.class, "foundTime", - "recvTime"); - if (tableMapping == null) { - logPage.setList(new ArrayList()); - } else { - List list = tableMapping.get("obj"); - if (list.size() > 0) { - String jsonString = JsonMapper.toJsonString(list); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - MmSampleAudioLog.class); - logPage.setList(List); - logPage.setCount(List.size()); - - } else { - logPage.setList(new ArrayList()); - } - } + logDataService.getData(page, mmSampleAudioLog); } catch (Exception e) { e.printStackTrace(); auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause()); @@ -436,50 +228,21 @@ public class MmLogSearchController extends BaseRestController { } throw ((RestServiceException) e); } - return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "音频样例日志检索成功", - logPage, 0); + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "音频样例日志检索成功", page, 0); } + @RequestMapping(value = "/mmSampleVideoLogs", method = RequestMethod.GET) @ApiOperation(value = "视频样例日志查询", httpMethod = "GET", notes = "对日志功能“视频样例日志”提供数据基础查询服务") - public Map mmSampleVideoLogs(Page page, MmSampleVideoLog mmSampleVideoLog, Model model, HttpServletRequest request, - HttpServletResponse response) { + public Map mmSampleVideoLogs(Page page, MmSampleVideoLog mmSampleVideoLog, Model model, + HttpServletRequest request, HttpServletResponse response) { long start = System.currentTimeMillis(); - AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, - request, null); + AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, + null); - Page logPage = null; try { resetTime(mmSampleVideoLog); ntcLogService.queryConditionCheck(auditLogThread, start, mmSampleVideoLog, MmSampleVideoLog.class, page); - logPage = new Page(); - logPage.setPageNo(page.getPageNo()); - logPage.setPageSize(page.getPageSize()); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = Page.getOrderBySql(MmSampleVideoLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - String sql = HiveSqlService.getSql(page, mmSampleVideoLog, - getTableName(MmSampleVideoLog.class.getSimpleName() + "HiveTable", "MM_SAMPLE_VIDEO_LOG"), - getCol2Col(), orderBy, null); - Map> tableMapping = new LogJDBCByDruid().tableMapping(page, null, sql, MmSampleVideoLog.class, "foundTime", - "recvTime"); - if (tableMapping == null) { - logPage.setList(new ArrayList()); - } else { - List list = tableMapping.get("obj"); - if (list.size() > 0) { - String jsonString = JsonMapper.toJsonString(list); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - MmSampleVideoLog.class); - logPage.setList(List); - logPage.setCount(List.size()); - - } else { - logPage.setList(new ArrayList()); - } - } + logDataService.getData(page, mmSampleVideoLog); } catch (Exception e) { e.printStackTrace(); auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause()); @@ -489,50 +252,22 @@ public class MmLogSearchController extends BaseRestController { } throw ((RestServiceException) e); } - return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "视频样例日志检索成功", - logPage, 0); + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "视频样例日志检索成功", page, 0); } + @RequestMapping(value = "/mmPornAudioLevelLogs", method = RequestMethod.GET) @ApiOperation(value = "音频色情日志查询", httpMethod = "GET", notes = "对日志功能“音频色情日志”提供数据基础查询服务") - public Map mmPornAudioLevelLogs(Page page, MmPornAudioLevelLog mmPornAudioLevelLog, Model model, HttpServletRequest request, - HttpServletResponse response) { + public Map mmPornAudioLevelLogs(Page page, MmPornAudioLevelLog mmPornAudioLevelLog, Model model, + HttpServletRequest request, HttpServletResponse response) { long start = System.currentTimeMillis(); - AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, - request, null); + AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, + null); - Page logPage = null; try { resetTime(mmPornAudioLevelLog); - ntcLogService.queryConditionCheck(auditLogThread, start, mmPornAudioLevelLog, MmPornAudioLevelLog.class, page); - logPage = new Page(); - logPage.setPageNo(page.getPageNo()); - logPage.setPageSize(page.getPageSize()); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = Page.getOrderBySql(MmPornAudioLevelLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - String sql = HiveSqlService.getSql(page, mmPornAudioLevelLog, - getTableName(MmPornAudioLevelLog.class.getSimpleName() + "HiveTable", "MM_PORN_AUDIO_LEVEL_LOG"), - getCol2Col(), orderBy, null); - Map> tableMapping = new LogJDBCByDruid().tableMapping(page, null, sql, MmPornAudioLevelLog.class, "foundTime", - "recvTime"); - if (tableMapping == null) { - logPage.setList(new ArrayList()); - } else { - List list = tableMapping.get("obj"); - if (list.size() > 0) { - String jsonString = JsonMapper.toJsonString(list); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - MmPornAudioLevelLog.class); - logPage.setList(List); - logPage.setCount(List.size()); - - } else { - logPage.setList(new ArrayList()); - } - } + ntcLogService.queryConditionCheck(auditLogThread, start, mmPornAudioLevelLog, MmPornAudioLevelLog.class, + page); + logDataService.getData(page, mmPornAudioLevelLog); } catch (Exception e) { e.printStackTrace(); auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause()); @@ -542,50 +277,22 @@ public class MmLogSearchController extends BaseRestController { } throw ((RestServiceException) e); } - return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "音频色情日志检索成功", - logPage, 0); + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "音频色情日志检索成功", page, 0); } + @RequestMapping(value = "/mmPornVideoLevelLogs", method = RequestMethod.GET) @ApiOperation(value = "视频色情日志查询", httpMethod = "GET", notes = "对日志功能“视频色情日志”提供数据基础查询服务") - public Map mmPornVideoLevelLogs(Page page, MmPornVideoLevelLog mmPornVideoLevelLog, Model model, HttpServletRequest request, - HttpServletResponse response) { + public Map mmPornVideoLevelLogs(Page page, MmPornVideoLevelLog mmPornVideoLevelLog, Model model, + HttpServletRequest request, HttpServletResponse response) { long start = System.currentTimeMillis(); - AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, - request, null); + AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, + null); - Page logPage = null; try { resetTime(mmPornVideoLevelLog); - ntcLogService.queryConditionCheck(auditLogThread, start, mmPornVideoLevelLog, MmPornVideoLevelLog.class, page); - logPage = new Page(); - logPage.setPageNo(page.getPageNo()); - logPage.setPageSize(page.getPageSize()); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = Page.getOrderBySql(MmPornVideoLevelLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - String sql = HiveSqlService.getSql(page, mmPornVideoLevelLog, - getTableName(MmPornVideoLevelLog.class.getSimpleName() + "HiveTable", "MM_PRON_VIDEO_LOG"), - getCol2Col(), orderBy, null); - Map> tableMapping = new LogJDBCByDruid().tableMapping(page, null, sql, MmPornVideoLevelLog.class, "foundTime", - "recvTime"); - if (tableMapping == null) { - logPage.setList(new ArrayList()); - } else { - List list = tableMapping.get("obj"); - if (list.size() > 0) { - String jsonString = JsonMapper.toJsonString(list); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - MmPornVideoLevelLog.class); - logPage.setList(List); - logPage.setCount(List.size()); - - } else { - logPage.setList(new ArrayList()); - } - } + ntcLogService.queryConditionCheck(auditLogThread, start, mmPornVideoLevelLog, MmPornVideoLevelLog.class, + page); + logDataService.getData(page, mmPornVideoLevelLog); } catch (Exception e) { e.printStackTrace(); auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause()); @@ -595,51 +302,21 @@ public class MmLogSearchController extends BaseRestController { } throw ((RestServiceException) e); } - return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "视频色情日志检索成功", - logPage, 0); + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "视频色情日志检索成功", page, 0); } - + @RequestMapping(value = "/mmSamplePicLogs", method = RequestMethod.GET) @ApiOperation(value = "图片样例日志查询", httpMethod = "GET", notes = "对日志功能“图片样例日志”提供数据基础查询服务") - public Map mmSamplePicLogs(Page page, MmSamplePicLog mmSamplePicLog, Model model, HttpServletRequest request, - HttpServletResponse response) { + public Map mmSamplePicLogs(Page page, MmSamplePicLog mmSamplePicLog, Model model, + HttpServletRequest request, HttpServletResponse response) { long start = System.currentTimeMillis(); - AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, - request, null); + AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, + null); - Page logPage = null; try { resetTime(mmSamplePicLog); ntcLogService.queryConditionCheck(auditLogThread, start, mmSamplePicLog, MmSamplePicLog.class, page); - logPage = new Page(); - logPage.setPageNo(page.getPageNo()); - logPage.setPageSize(page.getPageSize()); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = Page.getOrderBySql(MmSamplePicLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - String sql = HiveSqlService.getSql(page, mmSamplePicLog, - getTableName(MmSamplePicLog.class.getSimpleName() + "HiveTable", "MM_SAMPLE_PIC_LOG"), - getCol2Col(), orderBy, null); - Map> tableMapping = new LogJDBCByDruid().tableMapping(page, null, sql, MmSamplePicLog.class, "foundTime", - "recvTime"); - if (tableMapping == null) { - logPage.setList(new ArrayList()); - } else { - List list = tableMapping.get("obj"); - if (list.size() > 0) { - String jsonString = JsonMapper.toJsonString(list); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - MmSamplePicLog.class); - logPage.setList(List); - logPage.setCount(List.size()); - - } else { - logPage.setList(new ArrayList()); - } - } + logDataService.getData(page, mmSamplePicLog); } catch (Exception e) { e.printStackTrace(); auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause()); @@ -649,50 +326,21 @@ public class MmLogSearchController extends BaseRestController { } throw ((RestServiceException) e); } - return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "图片样例日志检索成功", - logPage, 0); + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "图片样例日志检索成功", page, 0); } + @RequestMapping(value = "/mmSampleVoipLogs", method = RequestMethod.GET) @ApiOperation(value = "VOIP样例日志查询", httpMethod = "GET", notes = "对日志功能“VOIP样例日志”提供数据基础查询服务") - public Map mmSampleVoipLogs(Page page, MmSampleVoipLog mmSampleVoipLog, Model model, HttpServletRequest request, - HttpServletResponse response) { + public Map mmSampleVoipLogs(Page page, MmSampleVoipLog mmSampleVoipLog, Model model, + HttpServletRequest request, HttpServletResponse response) { long start = System.currentTimeMillis(); - AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, - request, null); + AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, + null); - Page logPage = null; try { resetTime(mmSampleVoipLog); ntcLogService.queryConditionCheck(auditLogThread, start, mmSampleVoipLog, MmSampleVoipLog.class, page); - logPage = new Page(); - logPage.setPageNo(page.getPageNo()); - logPage.setPageSize(page.getPageSize()); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = Page.getOrderBySql(MmSampleVoipLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - String sql = HiveSqlService.getSql(page, mmSampleVoipLog, - getTableName(MmSampleVoipLog.class.getSimpleName() + "HiveTable", "MM_SAMPLE_VOIP_LOG"), - getCol2Col(), orderBy, null); - Map> tableMapping = new LogJDBCByDruid().tableMapping(page, null, sql, MmSampleVoipLog.class, "foundTime", - "recvTime"); - if (tableMapping == null) { - logPage.setList(new ArrayList()); - } else { - List list = tableMapping.get("obj"); - if (list.size() > 0) { - String jsonString = JsonMapper.toJsonString(list); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - MmSampleVoipLog.class); - logPage.setList(List); - logPage.setCount(List.size()); - - } else { - logPage.setList(new ArrayList()); - } - } + logDataService.getData(page, mmSampleVoipLog); } catch (Exception e) { e.printStackTrace(); auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause()); @@ -702,51 +350,22 @@ public class MmLogSearchController extends BaseRestController { } throw ((RestServiceException) e); } - return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "VOIP样例日志检索成功", - logPage, 0); + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "VOIP样例日志检索成功", page, 0); } - + @RequestMapping(value = "/mmSpeakerRecognizationLogs", method = RequestMethod.GET) @ApiOperation(value = "说话人识别日志查询", httpMethod = "GET", notes = "对日志功能“说话人识别日志”提供数据基础查询服务") - public Map mmSpeakerRecognizationLogs(Page page, MmSpeakerRecognizationLog mmSpeakerRecognizationLog, Model model, HttpServletRequest request, - HttpServletResponse response) { + public Map mmSpeakerRecognizationLogs(Page page, MmSpeakerRecognizationLog mmSpeakerRecognizationLog, + Model model, HttpServletRequest request, HttpServletResponse response) { long start = System.currentTimeMillis(); - AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, - request, null); + AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, + null); - Page logPage = null; try { resetTime(mmSpeakerRecognizationLog); - ntcLogService.queryConditionCheck(auditLogThread, start, mmSpeakerRecognizationLog, MmSpeakerRecognizationLog.class, page); - logPage = new Page(); - logPage.setPageNo(page.getPageNo()); - logPage.setPageSize(page.getPageSize()); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = Page.getOrderBySql(MmSpeakerRecognizationLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - String sql = HiveSqlService.getSql(page, mmSpeakerRecognizationLog, - getTableName(MmSpeakerRecognizationLog.class.getSimpleName() + "HiveTable", "MM_SPEAKER_RECOGNIZATION_LOG"), - getCol2Col(), orderBy, null); - Map> tableMapping = new LogJDBCByDruid().tableMapping(page, null, sql, MmSpeakerRecognizationLog.class, "foundTime", - "recvTime"); - if (tableMapping == null) { - logPage.setList(new ArrayList()); - } else { - List list = tableMapping.get("obj"); - if (list.size() > 0) { - String jsonString = JsonMapper.toJsonString(list); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - MmSpeakerRecognizationLog.class); - logPage.setList(List); - logPage.setCount(List.size()); - - } else { - logPage.setList(new ArrayList()); - } - } + ntcLogService.queryConditionCheck(auditLogThread, start, mmSpeakerRecognizationLog, + MmSpeakerRecognizationLog.class, page); + logDataService.getData(page, mmSpeakerRecognizationLog); } catch (Exception e) { e.printStackTrace(); auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause()); @@ -756,51 +375,22 @@ public class MmLogSearchController extends BaseRestController { } throw ((RestServiceException) e); } - return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "说话人识别日志检索成功", - logPage, 0); + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "说话人识别日志检索成功", page, 0); } - + @RequestMapping(value = "/mmLogoDetectionLogs", method = RequestMethod.GET) @ApiOperation(value = "台标识别日志查询", httpMethod = "GET", notes = "对日志功能“台标识别IP日志”提供数据基础查询服务") - public Map mmLogoDetectionLogs(Page page, MmLogoDetectionLog mmLogoDetectionLog, Model model, HttpServletRequest request, - HttpServletResponse response) { + public Map mmLogoDetectionLogs(Page page, MmLogoDetectionLog mmLogoDetectionLog, Model model, + HttpServletRequest request, HttpServletResponse response) { long start = System.currentTimeMillis(); - AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, - request, null); + AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, + null); - Page logPage = null; try { resetTime(mmLogoDetectionLog); - ntcLogService.queryConditionCheck(auditLogThread, start, mmLogoDetectionLog, MmLogoDetectionLog.class, page); - logPage = new Page(); - logPage.setPageNo(page.getPageNo()); - logPage.setPageSize(page.getPageSize()); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = Page.getOrderBySql(MmLogoDetectionLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - String sql = HiveSqlService.getSql(page, mmLogoDetectionLog, - getTableName(MmLogoDetectionLog.class.getSimpleName() + "HiveTable", "MM_LOGO_DETECTION_LOG"), - getCol2Col(), orderBy, null); - Map> tableMapping = new LogJDBCByDruid().tableMapping(page, null, sql, MmLogoDetectionLog.class, "foundTime", - "recvTime"); - if (tableMapping == null) { - logPage.setList(new ArrayList()); - } else { - List list = tableMapping.get("obj"); - if (list.size() > 0) { - String jsonString = JsonMapper.toJsonString(list); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - MmLogoDetectionLog.class); - logPage.setList(List); - logPage.setCount(List.size()); - - } else { - logPage.setList(new ArrayList()); - } - } + ntcLogService.queryConditionCheck(auditLogThread, start, mmLogoDetectionLog, MmLogoDetectionLog.class, + page); + logDataService.getData(page, mmLogoDetectionLog); } catch (Exception e) { e.printStackTrace(); auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause()); @@ -810,51 +400,22 @@ public class MmLogSearchController extends BaseRestController { } throw ((RestServiceException) e); } - return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "台标识别日志检索成功", - logPage, 0); + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "台标识别日志检索成功", page, 0); } - + @RequestMapping(value = "/mmFaceRecognizationLogs", method = RequestMethod.GET) @ApiOperation(value = "人脸识别日志查询", httpMethod = "GET", notes = "对日志功能“人脸识别日志”提供数据基础查询服务") - public Map mmFaceRecognizationLogs(Page page, MmFaceRecognizationLog mmFaceRecognizationLog, Model model, HttpServletRequest request, - HttpServletResponse response) { + public Map mmFaceRecognizationLogs(Page page, MmFaceRecognizationLog mmFaceRecognizationLog, Model model, + HttpServletRequest request, HttpServletResponse response) { long start = System.currentTimeMillis(); - AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, - request, null); + AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, + null); - Page logPage = null; try { resetTime(mmFaceRecognizationLog); - ntcLogService.queryConditionCheck(auditLogThread, start, mmFaceRecognizationLog, MmFaceRecognizationLog.class, page); - logPage = new Page(); - logPage.setPageNo(page.getPageNo()); - logPage.setPageSize(page.getPageSize()); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = Page.getOrderBySql(MmFaceRecognizationLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - String sql = HiveSqlService.getSql(page, mmFaceRecognizationLog, - getTableName(MmFaceRecognizationLog.class.getSimpleName() + "HiveTable", "MM_FACE_RECOGNIZATION_LOG"), - getCol2Col(), orderBy, null); - Map> tableMapping = new LogJDBCByDruid().tableMapping(page, null, sql, MmFaceRecognizationLog.class, "foundTime", - "recvTime"); - if (tableMapping == null) { - logPage.setList(new ArrayList()); - } else { - List list = tableMapping.get("obj"); - if (list.size() > 0) { - String jsonString = JsonMapper.toJsonString(list); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - MmFaceRecognizationLog.class); - logPage.setList(List); - logPage.setCount(List.size()); - - } else { - logPage.setList(new ArrayList()); - } - } + ntcLogService.queryConditionCheck(auditLogThread, start, mmFaceRecognizationLog, + MmFaceRecognizationLog.class, page); + logDataService.getData(page, mmFaceRecognizationLog); } catch (Exception e) { e.printStackTrace(); auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause()); @@ -864,51 +425,21 @@ public class MmLogSearchController extends BaseRestController { } throw ((RestServiceException) e); } - return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "人脸识别日志检索成功", - logPage, 0); + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "人脸识别日志检索成功", page, 0); } - + @RequestMapping(value = "/mmFileDigestLogs", method = RequestMethod.GET) @ApiOperation(value = "文件摘要日志查询", httpMethod = "GET", notes = "对日志功能“文件摘要日志”提供数据基础查询服务") - public Map mmFileDigestLogs(Page page, MmFileDigestLog mmFileDigestLog, Model model, HttpServletRequest request, - HttpServletResponse response) { + public Map mmFileDigestLogs(Page page, MmFileDigestLog mmFileDigestLog, Model model, + HttpServletRequest request, HttpServletResponse response) { long start = System.currentTimeMillis(); - AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, - request, null); + AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, + null); - Page logPage = null; try { resetTime(mmFileDigestLog); ntcLogService.queryConditionCheck(auditLogThread, start, mmFileDigestLog, MmFileDigestLog.class, page); - logPage = new Page(); - logPage.setPageNo(page.getPageNo()); - logPage.setPageSize(page.getPageSize()); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = Page.getOrderBySql(MmFileDigestLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - String sql = HiveSqlService.getSql(page, mmFileDigestLog, - getTableName(MmFileDigestLog.class.getSimpleName() + "HiveTable", "MM_FILE_DIGEST_LOG"), - getCol2Col(), orderBy, null); - Map> tableMapping = new LogJDBCByDruid().tableMapping(page, null, sql, MmFileDigestLog.class, "foundTime", - "recvTime"); - if (tableMapping == null) { - logPage.setList(new ArrayList()); - } else { - List list = tableMapping.get("obj"); - if (list.size() > 0) { - String jsonString = JsonMapper.toJsonString(list); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - MmFileDigestLog.class); - logPage.setList(List); - logPage.setCount(List.size()); - - } else { - logPage.setList(new ArrayList()); - } - } + logDataService.getData(page, mmFileDigestLog); } catch (Exception e) { e.printStackTrace(); auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause()); @@ -918,37 +449,9 @@ public class MmLogSearchController extends BaseRestController { } throw ((RestServiceException) e); } - return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "文件摘要日志检索成功", - logPage, 0); - } - - /** - *判断开始和结束时间是否为null,如果为null则初始化时间 - * @param entity - * @throws Exception - */ - public void resetTime(LogEntity entity) throws Exception { - if (StringUtil.isEmpty(entity.getSearchFoundStartTime())&& StringUtil.isEmpty(entity.getSearchFoundEndTime())) { - Map map = DateUtils.getLocalTime(entity.getSearchFoundStartTime(), - entity.getSearchFoundEndTime(), Constants.LOG_LOCAL_TIME, "minute"); - entity.setSearchFoundStartTime(map.get("startTime")); - entity.setSearchFoundEndTime(map.get("endTime")); - } + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "文件摘要日志检索成功", page, 0); } - /** - * 将searchFoundStartTime,searchFoundEndTime与foundTime进行关联 - * @return - */ - public Map> getCol2Col() { - Map> col2col = new HashMap>(); - Map startMap = new HashMap(); - startMap.put("start", "foundTime"); - col2col.put("searchFoundStartTime", startMap); - Map endMap = new HashMap(); - endMap.put("end", "foundTime"); - col2col.put("searchFoundEndTime", endMap); - return col2col; - } + } diff --git a/src/main/java/com/nis/web/controller/restful/NtcLogSearchController.java b/src/main/java/com/nis/web/controller/restful/NtcLogSearchController.java index 650c477..71f36a3 100644 --- a/src/main/java/com/nis/web/controller/restful/NtcLogSearchController.java +++ b/src/main/java/com/nis/web/controller/restful/NtcLogSearchController.java @@ -1,8 +1,5 @@ package com.nis.web.controller.restful; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; @@ -14,10 +11,10 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; -import com.nis.domain.LogEntity; import com.nis.domain.Page; import com.nis.domain.restful.NtcAppLog; import com.nis.domain.restful.NtcBgpLog; +import com.nis.domain.restful.NtcCollectVoipLog; import com.nis.domain.restful.NtcDdosLog; import com.nis.domain.restful.NtcDnsLog; import com.nis.domain.restful.NtcFtpLog; @@ -37,11 +34,9 @@ import com.nis.domain.restful.NtcVoipLog; import com.nis.restful.RestServiceException; import com.nis.util.Constants; import com.nis.util.DateUtils; -import com.nis.util.JsonMapper; -import com.nis.util.LogJDBCByDruid; import com.nis.web.controller.BaseRestController; import com.nis.web.service.AuditLogThread; -import com.nis.web.service.HiveSqlService; +import com.nis.web.service.LogDataService; import com.nis.web.service.ServicesRequestLogService; import com.nis.web.service.restful.NtcLogService; import com.wordnik.swagger.annotations.Api; @@ -64,6 +59,8 @@ public class NtcLogSearchController extends BaseRestController { @Autowired protected NtcLogService ntcLogService; + @Autowired + private LogDataService logDataService; @RequestMapping(value = "/ntcIpLogs", method = RequestMethod.GET) @ApiOperation(value = "IP地址日志查询", httpMethod = "GET", notes = "对应配置为IP地址管理,存储动作为阻断与监测的命中日志。对日志功能IP地址提供数据基础查询服务") @@ -72,57 +69,10 @@ public class NtcLogSearchController extends BaseRestController { long start = System.currentTimeMillis(); AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null); - Page ntcIpLogPage = null; try { resetTime(ntcIpLog); ntcLogService.queryConditionCheck(auditLogThread, start, ntcIpLog, NtcIpLog.class, page); - ntcIpLogPage = new Page(); - ntcIpLogPage.setPageNo(page.getPageNo()); - ntcIpLogPage.setPageSize(page.getPageSize()); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = Page.getOrderBySql(NtcIpLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - // ResultSet rs = HiveSqlService.getResultSet(page, ntcIpLog, - // getTableName(NtcIpLog.class.getSimpleName() + "HiveTable", "ntc_ip_log"), - // getCol2Col(), orderBy, null); - // Map tableMapping = HiveJDBC.tableMapping(page, null, rs, - // NtcIpLog.class, "foundTime", - // "recvTime"); - String sql = HiveSqlService.getSql(page, ntcIpLog, - getTableName(NtcIpLog.class.getSimpleName() + "HiveTable", "ntc_ip_log"), getCol2Col(), orderBy, - null); - Map> tableMapping = new LogJDBCByDruid().tableMapping(page, null, sql, NtcIpLog.class, - "foundTime", "recvTime"); - if (tableMapping == null) { - ntcIpLogPage.setList(new ArrayList()); - } else { - List list = new ArrayList(); - list = tableMapping.get("obj"); - // if (tableMapping.get("obj").size() > page.getPageSize()) { - // list = tableMapping.get("obj").subList(0, page.getPageSize()); - // } else { - // list = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - // } - if (list.size() > 0) { - String jsonString = JsonMapper.toJsonString(list); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - NtcIpLog.class); - ntcIpLogPage.setList(List); - ntcIpLogPage.setCount(List.size()); - // ntcIpLogPage - // .setCount( - // HiveSqlService.getHivePageCount(ntcIpLog, null, - // getTableName( - // NtcIpLog.class.getSimpleName() + "HiveTable", "ntc_ip_log"), - // getCol2Col(), null)); - } else { - ntcIpLogPage.setList(new ArrayList()); - ntcIpLogPage.setCount(0L); - } - } + logDataService.getData(page, ntcIpLog); } catch (Exception e) { e.printStackTrace(); auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause()); @@ -132,8 +82,7 @@ public class NtcLogSearchController extends BaseRestController { } throw ((RestServiceException) e); } - return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "IP地址日志检索成功", - ntcIpLogPage, 0); + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "IP地址日志检索成功", page, 0); } @RequestMapping(value = "/ntcHttpLogs", method = RequestMethod.GET) @@ -144,44 +93,10 @@ public class NtcLogSearchController extends BaseRestController { AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null); - Page ntcHttpLogPage = null; try { resetTime(ntcHttpLog); ntcLogService.queryConditionCheck(auditLogThread, start, ntcHttpLog, NtcHttpLog.class, page); - ntcHttpLogPage = new Page(); - ntcHttpLogPage.setPageNo(page.getPageNo()); - ntcHttpLogPage.setPageSize(page.getPageSize()); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = Page.getOrderBySql(NtcHttpLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - String sql = HiveSqlService.getSql(page, ntcHttpLog, - getTableName(NtcHttpLog.class.getSimpleName() + "HiveTable", "ntc_http_log"), getCol2Col(), orderBy, - null); - Map> tableMapping = new LogJDBCByDruid().tableMapping(page, null, sql, - NtcHttpLog.class, "foundTime", "recvTime"); - if (tableMapping == null) { - ntcHttpLogPage.setList(new ArrayList()); - } else { - List list = tableMapping.get("obj"); - // if (tableMapping.get("obj").size() > page.getPageSize()) { - // list = tableMapping.get("obj").subList(0, page.getPageSize()); - // } else { - // list = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - // } - if (list.size() > 0) { - String jsonString = JsonMapper.toJsonString(list); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - NtcHttpLog.class); - ntcHttpLogPage.setList(List); - ntcHttpLogPage.setCount(List.size()); - - } else { - ntcHttpLogPage.setList(new ArrayList()); - } - } + logDataService.getData(page, ntcHttpLog); } catch (Exception e) { e.printStackTrace(); auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause()); @@ -192,8 +107,7 @@ public class NtcLogSearchController extends BaseRestController { throw ((RestServiceException) e); } - return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "Http日志检索成功", - ntcHttpLogPage, 0); + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "Http日志检索成功", page, 0); } @RequestMapping(value = "/ntcDnsLogs", method = RequestMethod.GET) @@ -204,44 +118,10 @@ public class NtcLogSearchController extends BaseRestController { AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null); - Page ntcDnsLogPage = null; try { resetTime(ntcDnsLog); ntcLogService.queryConditionCheck(auditLogThread, start, ntcDnsLog, NtcDnsLog.class, page); - ntcDnsLogPage = new Page(); - ntcDnsLogPage.setPageNo(page.getPageNo()); - ntcDnsLogPage.setPageSize(page.getPageSize()); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = Page.getOrderBySql(NtcDnsLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - String sql = HiveSqlService.getSql(page, ntcDnsLog, - getTableName(NtcDnsLog.class.getSimpleName() + "HiveTable", "ntc_dns_log"), getCol2Col(), orderBy, - null); - Map> tableMapping = new LogJDBCByDruid().tableMapping(page, null, sql, NtcDnsLog.class, - "foundTime", "recvTime"); - if (tableMapping == null) { - ntcDnsLogPage.setList(new ArrayList()); - } else { - List list = tableMapping.get("obj"); - // if (tableMapping.get("obj").size() > page.getPageSize()) { - // list = tableMapping.get("obj").subList(0, page.getPageSize()); - // } else { - // list = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - // } - if (list.size() > 0) { - String jsonString = JsonMapper.toJsonString(list); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - NtcDnsLog.class); - ntcDnsLogPage.setList(List); - ntcDnsLogPage.setCount(List.size()); - - } else { - ntcDnsLogPage.setList(new ArrayList()); - } - } + logDataService.getData(page, ntcDnsLog); } catch (Exception e) { e.printStackTrace(); auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause()); @@ -252,8 +132,7 @@ public class NtcLogSearchController extends BaseRestController { throw ((RestServiceException) e); } - return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "Dns日志检索成功", - ntcDnsLogPage, 0); + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "Dns日志检索成功", page, 0); } @RequestMapping(value = "/ntcMailLogs", method = RequestMethod.GET) @@ -263,45 +142,10 @@ public class NtcLogSearchController extends BaseRestController { long start = System.currentTimeMillis(); AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null); - - Page ntcMailLogPage = null; try { resetTime(ntcMailLog); ntcLogService.queryConditionCheck(auditLogThread, start, ntcMailLog, NtcMailLog.class, page); - ntcMailLogPage = new Page(); - ntcMailLogPage.setPageNo(page.getPageNo()); - ntcMailLogPage.setPageSize(page.getPageSize()); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = Page.getOrderBySql(NtcMailLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - String sql = HiveSqlService.getSql(page, ntcMailLog, - getTableName(NtcMailLog.class.getSimpleName() + "HiveTable", "ntc_mail_log"), getCol2Col(), orderBy, - null); - Map> tableMapping = new LogJDBCByDruid().tableMapping(page, null, sql, - NtcMailLog.class, "foundTime", "recvTime"); - if (tableMapping == null) { - ntcMailLogPage.setList(new ArrayList()); - } else { - List list = tableMapping.get("obj"); - // if (tableMapping.get("obj").size() > page.getPageSize()) { - // list = tableMapping.get("obj").subList(0, page.getPageSize()); - // } else { - // list = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - // } - if (list.size() > 0) { - String jsonString = JsonMapper.toJsonString(list); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - NtcMailLog.class); - ntcMailLogPage.setList(List); - ntcMailLogPage.setCount(List.size()); - - } else { - ntcMailLogPage.setList(new ArrayList()); - } - } + logDataService.getData(page, ntcMailLog); } catch (Exception e) { e.printStackTrace(); auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause()); @@ -312,8 +156,7 @@ public class NtcLogSearchController extends BaseRestController { throw ((RestServiceException) e); } - return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "Mail日志检索成功", - ntcMailLogPage, 0); + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "Mail日志检索成功", page, 0); } @RequestMapping(value = "/ntcSslLogs", method = RequestMethod.GET) @@ -324,44 +167,10 @@ public class NtcLogSearchController extends BaseRestController { AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null); - Page ntcSslLogPage = null; try { resetTime(ntcSslLog); ntcLogService.queryConditionCheck(auditLogThread, start, ntcSslLog, NtcSslLog.class, page); - ntcSslLogPage = new Page(); - ntcSslLogPage.setPageNo(page.getPageNo()); - ntcSslLogPage.setPageSize(page.getPageSize()); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = Page.getOrderBySql(NtcSslLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - String sql = HiveSqlService.getSql(page, ntcSslLog, - getTableName(NtcSslLog.class.getSimpleName() + "HiveTable", "ntc_ssl_log"), getCol2Col(), orderBy, - null); - Map> tableMapping = new LogJDBCByDruid().tableMapping(page, null, sql, NtcSslLog.class, - "foundTime", "recvTime"); - if (tableMapping == null) { - ntcSslLogPage.setList(new ArrayList()); - } else { - List list = tableMapping.get("obj"); - // if (tableMapping.get("obj").size() > page.getPageSize()) { - // list = tableMapping.get("obj").subList(0, page.getPageSize()); - // } else { - // list = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - // } - if (list.size() > 0) { - String jsonString = JsonMapper.toJsonString(list); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - NtcSslLog.class); - ntcSslLogPage.setList(List); - ntcSslLogPage.setCount(List.size()); - - } else { - ntcSslLogPage.setList(new ArrayList()); - } - } + logDataService.getData(page, ntcSslLog); } catch (Exception e) { e.printStackTrace(); auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause()); @@ -372,8 +181,7 @@ public class NtcLogSearchController extends BaseRestController { throw ((RestServiceException) e); } - return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "SSL日志检索成功", - ntcSslLogPage, 0); + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "SSL日志检索成功", page, 0); } @RequestMapping(value = "/ntcPptpLogs", method = RequestMethod.GET) @@ -384,43 +192,10 @@ public class NtcLogSearchController extends BaseRestController { AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null); - Page ntcPptpLogPage = null; try { resetTime(ntcPptpLog); ntcLogService.queryConditionCheck(auditLogThread, start, ntcPptpLog, NtcPptpLog.class, page); - ntcPptpLogPage = new Page(); - ntcPptpLogPage.setPageNo(page.getPageNo()); - ntcPptpLogPage.setPageSize(page.getPageSize()); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = Page.getOrderBySql(NtcPptpLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - String sql = HiveSqlService.getSql(page, ntcPptpLog, - getTableName(NtcPptpLog.class.getSimpleName() + "HiveTable", "ntc_pptp_log"), getCol2Col(), orderBy, - null); - Map> tableMapping = new LogJDBCByDruid().tableMapping(page, null, sql, - NtcPptpLog.class, "foundTime", "recvTime"); - if (tableMapping == null) { - ntcPptpLogPage.setList(new ArrayList()); - } else { - List list = tableMapping.get("obj"); - // if (tableMapping.get("obj").size() > page.getPageSize()) { - // list = tableMapping.get("obj").subList(0, page.getPageSize()); - // } else { - // list = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - // } - if (list.size() > 0) { - String jsonString = JsonMapper.toJsonString(list); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - NtcPptpLog.class); - ntcPptpLogPage.setList(List); - ntcPptpLogPage.setCount(List.size()); - } else { - ntcPptpLogPage.setList(new ArrayList()); - } - } + logDataService.getData(page, ntcPptpLog); } catch (Exception e) { e.printStackTrace(); auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause()); @@ -431,8 +206,7 @@ public class NtcLogSearchController extends BaseRestController { throw ((RestServiceException) e); } - return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "PPTP日志检索成功", - ntcPptpLogPage, 0); + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "PPTP日志检索成功", page, 0); } @RequestMapping(value = "/ntcL2tpLogs", method = RequestMethod.GET) @@ -443,44 +217,10 @@ public class NtcLogSearchController extends BaseRestController { AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null); - Page ntcL2tpLogPage = null; try { resetTime(ntcL2tpLog); ntcLogService.queryConditionCheck(auditLogThread, start, ntcL2tpLog, NtcL2tpLog.class, page); - ntcL2tpLogPage = new Page(); - ntcL2tpLogPage.setPageNo(page.getPageNo()); - ntcL2tpLogPage.setPageSize(page.getPageSize()); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = Page.getOrderBySql(NtcL2tpLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - String sql = HiveSqlService.getSql(page, ntcL2tpLog, - getTableName(NtcL2tpLog.class.getSimpleName() + "HiveTable", "ntc_l2tp_log"), getCol2Col(), orderBy, - null); - Map> tableMapping = new LogJDBCByDruid().tableMapping(page, null, sql, - NtcL2tpLog.class, "foundTime", "recvTime"); - if (tableMapping == null) { - ntcL2tpLogPage.setList(new ArrayList()); - } else { - List list = tableMapping.get("obj"); - // if (tableMapping.get("obj").size() > page.getPageSize()) { - // list = tableMapping.get("obj").subList(0, page.getPageSize()); - // } else { - // list = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - // } - if (list.size() > 0) { - String jsonString = JsonMapper.toJsonString(list); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - NtcL2tpLog.class); - ntcL2tpLogPage.setList(List); - ntcL2tpLogPage.setCount(List.size()); - - } else { - ntcL2tpLogPage.setList(new ArrayList()); - } - } + logDataService.getData(page, ntcL2tpLog); } catch (Exception e) { e.printStackTrace(); auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause()); @@ -491,8 +231,7 @@ public class NtcLogSearchController extends BaseRestController { throw ((RestServiceException) e); } - return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "L2TP日志检索成功", - ntcL2tpLogPage, 0); + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "L2TP日志检索成功", page, 0); } @RequestMapping(value = "/ntcOpenvpnLogs", method = RequestMethod.GET) @@ -503,44 +242,10 @@ public class NtcLogSearchController extends BaseRestController { AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null); - Page ntcOpenvpnLogPage = null; try { resetTime(ntcOpenvpnLog); ntcLogService.queryConditionCheck(auditLogThread, start, ntcOpenvpnLog, NtcOpenvpnLog.class, page); - ntcOpenvpnLogPage = new Page(); - ntcOpenvpnLogPage.setPageNo(page.getPageNo()); - ntcOpenvpnLogPage.setPageSize(page.getPageSize()); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = Page.getOrderBySql(NtcOpenvpnLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - String sql = HiveSqlService.getSql(page, ntcOpenvpnLog, - getTableName(NtcOpenvpnLog.class.getSimpleName() + "HiveTable", "ntc_openvpn_log"), getCol2Col(), - orderBy, null); - Map> tableMapping = new LogJDBCByDruid().tableMapping(page, null, sql, - NtcOpenvpnLog.class, "foundTime", "recvTime"); - if (tableMapping == null) { - ntcOpenvpnLogPage.setList(new ArrayList()); - } else { - List list = tableMapping.get("obj"); - // if (tableMapping.get("obj").size() > page.getPageSize()) { - // list = tableMapping.get("obj").subList(0, page.getPageSize()); - // } else { - // list = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - // } - if (list.size() > 0) { - String jsonString = JsonMapper.toJsonString(list); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - NtcOpenvpnLog.class); - ntcOpenvpnLogPage.setList(List); - ntcOpenvpnLogPage.setCount(List.size()); - - } else { - ntcOpenvpnLogPage.setList(new ArrayList()); - } - } + logDataService.getData(page, ntcOpenvpnLog); } catch (Exception e) { e.printStackTrace(); auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause()); @@ -551,8 +256,8 @@ public class NtcLogSearchController extends BaseRestController { throw ((RestServiceException) e); } - return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "Openvpn日志检索成功", - ntcOpenvpnLogPage, 0); + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "Openvpn日志检索成功", page, + 0); } @RequestMapping(value = "/ntcIpsecLogs", method = RequestMethod.GET) @@ -563,44 +268,10 @@ public class NtcLogSearchController extends BaseRestController { AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null); - Page ntcIpsecLogPage = null; try { resetTime(ntcIpsecLog); ntcLogService.queryConditionCheck(auditLogThread, start, ntcIpsecLog, NtcIpsecLog.class, page); - ntcIpsecLogPage = new Page(); - ntcIpsecLogPage.setPageNo(page.getPageNo()); - ntcIpsecLogPage.setPageSize(page.getPageSize()); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = Page.getOrderBySql(NtcIpsecLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - String sql = HiveSqlService.getSql(page, ntcIpsecLog, - getTableName(NtcIpsecLog.class.getSimpleName() + "HiveTable", "ntc_ipsec_log"), getCol2Col(), - orderBy, null); - Map> tableMapping = new LogJDBCByDruid().tableMapping(page, null, sql, - NtcIpsecLog.class, "foundTime", "recvTime"); - if (tableMapping == null) { - ntcIpsecLogPage.setList(new ArrayList()); - } else { - List list = tableMapping.get("obj"); - // if (tableMapping.get("obj").size() > page.getPageSize()) { - // list = tableMapping.get("obj").subList(0, page.getPageSize()); - // } else { - // list = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - // } - if (list.size() > 0) { - String jsonString = JsonMapper.toJsonString(list); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - NtcIpsecLog.class); - ntcIpsecLogPage.setList(List); - ntcIpsecLogPage.setCount(List.size()); - - } else { - ntcIpsecLogPage.setList(new ArrayList()); - } - } + logDataService.getData(page, ntcIpsecLog); } catch (Exception e) { e.printStackTrace(); auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause()); @@ -611,8 +282,7 @@ public class NtcLogSearchController extends BaseRestController { throw ((RestServiceException) e); } - return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "IPSEC日志检索成功", - ntcIpsecLogPage, 0); + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "IPSEC日志检索成功", page, 0); } @RequestMapping(value = "/ntcSshLogs", method = RequestMethod.GET) @@ -623,44 +293,10 @@ public class NtcLogSearchController extends BaseRestController { AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null); - Page ntcSshLogPage = null; try { resetTime(ntcSshLog); ntcLogService.queryConditionCheck(auditLogThread, start, ntcSshLog, NtcSshLog.class, page); - ntcSshLogPage = new Page(); - ntcSshLogPage.setPageNo(page.getPageNo()); - ntcSshLogPage.setPageSize(page.getPageSize()); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = Page.getOrderBySql(NtcSshLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - String sql = HiveSqlService.getSql(page, ntcSshLog, - getTableName(NtcSshLog.class.getSimpleName() + "HiveTable", "ntc_ssh_log"), getCol2Col(), orderBy, - null); - Map> tableMapping = new LogJDBCByDruid().tableMapping(page, null, sql, NtcSshLog.class, - "foundTime", "recvTime"); - if (tableMapping == null) { - ntcSshLogPage.setList(new ArrayList()); - } else { - List list = tableMapping.get("obj"); - // if (tableMapping.get("obj").size() > page.getPageSize()) { - // list = tableMapping.get("obj").subList(0, page.getPageSize()); - // } else { - // list = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - // } - if (list.size() > 0) { - String jsonString = JsonMapper.toJsonString(list); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - NtcSshLog.class); - ntcSshLogPage.setList(List); - ntcSshLogPage.setCount(List.size()); - - } else { - ntcSshLogPage.setList(new ArrayList()); - } - } + logDataService.getData(page, ntcSshLog); } catch (Exception e) { e.printStackTrace(); auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause()); @@ -671,8 +307,7 @@ public class NtcLogSearchController extends BaseRestController { throw ((RestServiceException) e); } - return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "SSH日志检索成功", - ntcSshLogPage, 0); + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "SSH日志检索成功", page, 0); } @RequestMapping(value = "/ntcFtpLogs", method = RequestMethod.GET) @@ -683,44 +318,12 @@ public class NtcLogSearchController extends BaseRestController { AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null); - Page ntcFtpLogPage = null; try { resetTime(ntcFtpLog); ntcLogService.queryConditionCheck(auditLogThread, start, ntcFtpLog, NtcFtpLog.class, page); - ntcFtpLogPage = new Page(); - ntcFtpLogPage.setPageNo(page.getPageNo()); - ntcFtpLogPage.setPageSize(page.getPageSize()); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = Page.getOrderBySql(NtcFtpLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - String sql = HiveSqlService.getSql(page, ntcFtpLog, - getTableName(NtcFtpLog.class.getSimpleName() + "HiveTable", "ntc_ftp_log"), getCol2Col(), orderBy, - null); - Map> tableMapping = new LogJDBCByDruid().tableMapping(page, null, sql, NtcFtpLog.class, - "foundTime", "recvTime"); - if (tableMapping == null) { - ntcFtpLogPage.setList(new ArrayList()); - } else { - List list = tableMapping.get("obj"); - // if (tableMapping.get("obj").size() > page.getPageSize()) { - // list = tableMapping.get("obj").subList(0, page.getPageSize()); - // } else { - // list = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - // } - if (list.size() > 0) { - String jsonString = JsonMapper.toJsonString(list); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - NtcFtpLog.class); - ntcFtpLogPage.setList(List); - ntcFtpLogPage.setCount(List.size()); - } else { - ntcFtpLogPage.setList(new ArrayList()); - } - } + logDataService.getData(page, ntcFtpLog); + } catch (Exception e) { e.printStackTrace(); auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause()); @@ -730,8 +333,7 @@ public class NtcLogSearchController extends BaseRestController { } throw ((RestServiceException) e); } - return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "FTP日志检索成功", - ntcFtpLogPage, 0); + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "FTP日志检索成功", page, 0); } @RequestMapping(value = "/ntcAppLogs", method = RequestMethod.GET) @@ -741,45 +343,10 @@ public class NtcLogSearchController extends BaseRestController { long start = System.currentTimeMillis(); AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null); - - Page ntcAppLogPage = null; try { resetTime(ntcAppLog); ntcLogService.queryConditionCheck(auditLogThread, start, ntcAppLog, NtcAppLog.class, page); - ntcAppLogPage = new Page(); - ntcAppLogPage.setPageNo(page.getPageNo()); - ntcAppLogPage.setPageSize(page.getPageSize()); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = Page.getOrderBySql(NtcAppLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - String sql = HiveSqlService.getSql(page, ntcAppLog, - getTableName(NtcAppLog.class.getSimpleName() + "HiveTable", "ntc_app_log"), getCol2Col(), orderBy, - null); - Map> tableMapping = new LogJDBCByDruid().tableMapping(page, null, sql, NtcAppLog.class, - "foundTime", "recvTime"); - if (tableMapping == null) { - ntcAppLogPage.setList(new ArrayList()); - } else { - List list = tableMapping.get("obj"); - // if (tableMapping.get("obj").size() > page.getPageSize()) { - // list = tableMapping.get("obj").subList(0, page.getPageSize()); - // } else { - // list = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - // } - if (list.size() > 0) { - String jsonString = JsonMapper.toJsonString(list); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - NtcAppLog.class); - ntcAppLogPage.setList(List); - ntcAppLogPage.setCount(List.size()); - - } else { - ntcAppLogPage.setList(new ArrayList()); - } - } + logDataService.getData(page, ntcAppLog); } catch (Exception e) { e.printStackTrace(); auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause()); @@ -789,8 +356,7 @@ public class NtcLogSearchController extends BaseRestController { } throw ((RestServiceException) e); } - return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "App日志检索成功", - ntcAppLogPage, 0); + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "App日志检索成功", page, 0); } @RequestMapping(value = "/ntcDdosLogs", method = RequestMethod.GET) @@ -801,44 +367,10 @@ public class NtcLogSearchController extends BaseRestController { AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null); - Page ntcDdosLogPage = null; try { resetTime(ntcDdosLog); ntcLogService.queryConditionCheck(auditLogThread, start, ntcDdosLog, NtcDdosLog.class, page); - ntcDdosLogPage = new Page(); - ntcDdosLogPage.setPageNo(page.getPageNo()); - ntcDdosLogPage.setPageSize(page.getPageSize()); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = Page.getOrderBySql(NtcDdosLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - String sql = HiveSqlService.getSql(page, ntcDdosLog, - getTableName(NtcDdosLog.class.getSimpleName() + "HiveTable", "ntc_ddos_log"), getCol2Col(), orderBy, - null); - Map> tableMapping = new LogJDBCByDruid().tableMapping(page, null, sql, - NtcDdosLog.class, "foundTime", "recvTime"); - if (tableMapping == null) { - ntcDdosLogPage.setList(new ArrayList()); - } else { - List list = tableMapping.get("obj"); - // if (tableMapping.get("obj").size() > page.getPageSize()) { - // list = tableMapping.get("obj").subList(0, page.getPageSize()); - // } else { - // list = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - // } - if (list.size() > 0) { - String jsonString = JsonMapper.toJsonString(list); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - NtcDdosLog.class); - ntcDdosLogPage.setList(List); - ntcDdosLogPage.setCount(List.size()); - - } else { - ntcDdosLogPage.setList(new ArrayList()); - } - } + logDataService.getData(page, ntcDdosLog); } catch (Exception e) { e.printStackTrace(); auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause()); @@ -848,8 +380,7 @@ public class NtcLogSearchController extends BaseRestController { } throw ((RestServiceException) e); } - return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "DDos日志检索成功", - ntcDdosLogPage, 0); + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "DDos日志检索成功", page, 0); } @RequestMapping(value = "/ntcP2pLogs", method = RequestMethod.GET) @@ -860,46 +391,11 @@ public class NtcLogSearchController extends BaseRestController { AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null); - Page ntcP2pLogPage = null; try { resetTime(ntcP2pLog); ntcLogService.queryConditionCheck(auditLogThread, start, ntcP2pLog, NtcP2pLog.class, page); - ntcP2pLogPage = new Page(); - ntcP2pLogPage.setPageNo(page.getPageNo()); - ntcP2pLogPage.setPageSize(page.getPageSize()); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = Page.getOrderBySql(NtcP2pLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - String sql = HiveSqlService.getSql(page, ntcP2pLog, - getTableName(NtcP2pLog.class.getSimpleName() + "HiveTable", "ntc_p2p_log"), getCol2Col(), orderBy, - null); - - Map> tableMapping = new LogJDBCByDruid().tableMapping(page, null, sql, NtcP2pLog.class, - "foundTime", "recvTime"); - if (tableMapping == null) { - ntcP2pLogPage.setList(new ArrayList()); - } else { - List list = tableMapping.get("obj"); - // if (tableMapping.get("obj").size() > page.getPageSize()) { - // list = tableMapping.get("obj").subList(0, page.getPageSize()); - // } else { - // list = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - // } - if (list.size() > 0) { - String jsonString = JsonMapper.toJsonString(list); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - NtcP2pLog.class); - ntcP2pLogPage.setList(List); - ntcP2pLogPage.setCount(List.size()); - - } else { - ntcP2pLogPage.setList(new ArrayList()); - } - } + logDataService.getData(page, ntcP2pLog); } catch (Exception e) { e.printStackTrace(); auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause()); @@ -909,8 +405,7 @@ public class NtcLogSearchController extends BaseRestController { } throw ((RestServiceException) e); } - return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "P2P日志检索成功", - ntcP2pLogPage, 0); + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "P2P日志检索成功", page, 0); } @RequestMapping(value = "/ntcBgpLogs", method = RequestMethod.GET) @@ -921,46 +416,11 @@ public class NtcLogSearchController extends BaseRestController { AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null); - Page ntcBgpLogPage = null; try { resetTime(ntcBgpLog); ntcLogService.queryConditionCheck(auditLogThread, start, ntcBgpLog, NtcBgpLog.class, page); - ntcBgpLogPage = new Page(); - ntcBgpLogPage.setPageNo(page.getPageNo()); - ntcBgpLogPage.setPageSize(page.getPageSize()); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = Page.getOrderBySql(NtcBgpLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - String sql = HiveSqlService.getSql(page, ntcBgpLog, - getTableName(NtcBgpLog.class.getSimpleName() + "HiveTable", "ntc_bgp_log"), getCol2Col(), orderBy, - null); - - Map> tableMapping = new LogJDBCByDruid().tableMapping(page, null, sql, NtcBgpLog.class, - "foundTime", "recvTime"); - if (tableMapping == null) { - ntcBgpLogPage.setList(new ArrayList()); - } else { - List list = tableMapping.get("obj"); - // if (tableMapping.get("obj").size() > page.getPageSize()) { - // list = tableMapping.get("obj").subList(0, page.getPageSize()); - // } else { - // list = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - // } - if (list.size() > 0) { - String jsonString = JsonMapper.toJsonString(list); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - NtcBgpLog.class); - ntcBgpLogPage.setList(List); - ntcBgpLogPage.setCount(List.size()); - - } else { - ntcBgpLogPage.setList(new ArrayList()); - } - } + logDataService.getData(page, ntcBgpLog); } catch (Exception e) { e.printStackTrace(); auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause()); @@ -970,8 +430,7 @@ public class NtcLogSearchController extends BaseRestController { } throw ((RestServiceException) e); } - return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "BGP日志检索成功", - ntcBgpLogPage, 0); + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "BGP日志检索成功", page, 0); } @RequestMapping(value = "/ntcVoipLogs", method = RequestMethod.GET) @@ -982,39 +441,10 @@ public class NtcLogSearchController extends BaseRestController { AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null); - Page logPage = null; try { resetTime(ntcVoipLog); ntcLogService.queryConditionCheck(auditLogThread, start, ntcVoipLog, NtcVoipLog.class, page); - logPage = new Page(); - logPage.setPageNo(page.getPageNo()); - logPage.setPageSize(page.getPageSize()); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = Page.getOrderBySql(NtcVoipLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - String sql = HiveSqlService.getSql(page, ntcVoipLog, - getTableName(NtcVoipLog.class.getSimpleName() + "HiveTable", "NTC_VOIP_LOG"), getCol2Col(), orderBy, - null); - Map> tableMapping = new LogJDBCByDruid().tableMapping(page, null, sql, - NtcVoipLog.class, "foundTime", "recvTime"); - if (tableMapping == null) { - logPage.setList(new ArrayList()); - } else { - List list = tableMapping.get("obj"); - if (list.size() > 0) { - String jsonString = JsonMapper.toJsonString(list); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - NtcVoipLog.class); - logPage.setList(List); - logPage.setCount(List.size()); - - } else { - logPage.setList(new ArrayList()); - } - } + logDataService.getData(page, ntcVoipLog); } catch (Exception e) { e.printStackTrace(); auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause()); @@ -1024,8 +454,8 @@ public class NtcLogSearchController extends BaseRestController { } throw ((RestServiceException) e); } - return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "NTC VoIP日志检索成功", - logPage, 0); + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "NTC VoIP日志检索成功", page, + 0); } @RequestMapping(value = "/ntcStreamMediaLogs", method = RequestMethod.GET) @@ -1036,40 +466,11 @@ public class NtcLogSearchController extends BaseRestController { AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null); - Page logPage = null; try { resetTime(ntcStreamMediaLog); ntcLogService.queryConditionCheck(auditLogThread, start, ntcStreamMediaLog, NtcStreamingMediaLog.class, page); - logPage = new Page(); - logPage.setPageNo(page.getPageNo()); - logPage.setPageSize(page.getPageSize()); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = Page.getOrderBySql(NtcStreamingMediaLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - String sql = HiveSqlService.getSql(page, ntcStreamMediaLog, - getTableName(NtcStreamingMediaLog.class.getSimpleName() + "HiveTable", "NTC_STREAMING_MEDIA_LOG"), - getCol2Col(), orderBy, null); - Map> tableMapping = new LogJDBCByDruid().tableMapping(page, null, sql, - NtcStreamingMediaLog.class, "foundTime", "recvTime"); - if (tableMapping == null) { - logPage.setList(new ArrayList()); - } else { - List list = tableMapping.get("obj"); - if (list.size() > 0) { - String jsonString = JsonMapper.toJsonString(list); - List List = (java.util.List) JsonMapper - .fromJsonList(jsonString, NtcStreamingMediaLog.class); - logPage.setList(List); - logPage.setCount(List.size()); - - } else { - logPage.setList(new ArrayList()); - } - } + logDataService.getData(page, ntcStreamMediaLog); } catch (Exception e) { e.printStackTrace(); auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause()); @@ -1079,8 +480,7 @@ public class NtcLogSearchController extends BaseRestController { } throw ((RestServiceException) e); } - return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "流媒体协议日志检索成功", logPage, - 0); + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "流媒体协议日志检索成功", page, 0); } @RequestMapping(value = "/ntcKeywordsUrlLogs", method = RequestMethod.GET) @@ -1091,43 +491,10 @@ public class NtcLogSearchController extends BaseRestController { AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null); - Page logPage = null; try { resetTime(ntcKeywordsUrlLog); ntcLogService.queryConditionCheck(auditLogThread, start, ntcKeywordsUrlLog, NtcKeywordsUrlLog.class, page); - logPage = new Page(); - logPage.setPageNo(page.getPageNo()); - logPage.setPageSize(page.getPageSize()); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = Page.getOrderBySql(NtcKeywordsUrlLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - String sql = HiveSqlService.getSql(page, ntcKeywordsUrlLog, - getTableName(NtcKeywordsUrlLog.class.getSimpleName() + "HiveTable", "NTC_KEYWORDS_URL_LOG"), - getCol2Col(), orderBy, null); - Map> tableMapping = new LogJDBCByDruid().tableMapping(page, null, sql, - NtcKeywordsUrlLog.class, "foundTime", "recvTime"); - if (tableMapping == null) { - logPage.setList(new ArrayList()); - } else { - List list = tableMapping.get("obj"); - if (list.size() > 0) { - String jsonString = JsonMapper.toJsonString(list); - List List = (java.util.List) JsonMapper - .fromJsonList(jsonString, NtcKeywordsUrlLog.class); - logPage.setList(List); - Long hivePageCount = HiveSqlService.getLogCount(ntcKeywordsUrlLog, - getTableName(NtcKeywordsUrlLog.class.getSimpleName() + "HiveTable", "NTC_KEYWORDS_URL_LOG"), - getCol2Col()); - - logPage.setLast(getLastPageNum(hivePageCount.intValue(), page.getPageSize())); - logPage.setCount(hivePageCount); - } else { - logPage.setList(new ArrayList()); - } - } + logDataService.getData(page, ntcKeywordsUrlLog); } catch (Exception e) { e.printStackTrace(); auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause()); @@ -1137,40 +504,39 @@ public class NtcLogSearchController extends BaseRestController { } throw ((RestServiceException) e); } - return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "NTC关键字转URL日志检索成功", - logPage, 0); + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "NTC关键字转URL日志检索成功", page, + 0); } - /** - * 判断开始和结束时间是否为null,如果为null则初始化时间 - * - * @param entity - * @throws Exception - */ - public void resetTime(LogEntity entity) throws Exception { - if (StringUtil.isEmpty(entity.getSearchFoundStartTime()) - && StringUtil.isEmpty(entity.getSearchFoundEndTime())) { - Map map = DateUtils.getLocalTime(entity.getSearchFoundStartTime(), - entity.getSearchFoundEndTime(), Constants.LOG_LOCAL_TIME, "minute"); - entity.setSearchFoundStartTime(map.get("startTime")); - entity.setSearchFoundEndTime(map.get("endTime")); + @RequestMapping(value = "/ntcCollectVoipLogs", method = RequestMethod.GET) + @ApiOperation(value = "VoIp泛收日志查询", httpMethod = "GET", notes = "对日志功能“VoIp泛收日志查询”提供数据基础查询服务") + public Map ntcCollectVoipLogs(Page page, NtcCollectVoipLog ntcCollectVoipLog, Model model, + HttpServletRequest request, HttpServletResponse response) { + long start = System.currentTimeMillis(); + AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, + null); + + try { + if (StringUtil.isEmpty(ntcCollectVoipLog.getSearchFoundStartTime()) + && StringUtil.isEmpty(ntcCollectVoipLog.getSearchFoundEndTime())) { + Map map = DateUtils.getLocalTime(null, + null, Constants.LOG_LOCAL_TIME, "minute"); + ntcCollectVoipLog.setSearchFoundStartTime(map.get("startTime")); + ntcCollectVoipLog.setSearchFoundEndTime(map.get("endTime")); + } + + ntcLogService.collectConditionCheck(auditLogThread, start,ntcCollectVoipLog, NtcCollectVoipLog.class, page); + logDataService.getData(page, ntcCollectVoipLog); + } catch (Exception e) { + e.printStackTrace(); + auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause()); + logger.error(e); + if (!(e instanceof RestServiceException)) { + e = new RestServiceException(auditLogThread, System.currentTimeMillis() - start, "VoIp泛收日志检索失败"); + } + throw ((RestServiceException) e); } + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "VoIp泛收日志检索成功", page, + 0); } - - /** - * 将searchFoundStartTime,searchFoundEndTime与foundTime进行关联 - * - * @return - */ - public Map> getCol2Col() { - Map> col2col = new HashMap>(); - Map startMap = new HashMap(); - startMap.put("start", "foundTime"); - col2col.put("searchFoundStartTime", startMap); - Map endMap = new HashMap(); - endMap.put("end", "foundTime"); - col2col.put("searchFoundEndTime", endMap); - return col2col; - } - } diff --git a/src/main/java/com/nis/web/dao/DfLogSearchDao.xml b/src/main/java/com/nis/web/dao/DfLogSearchDao.xml index b0fcf26..c673e92 100644 --- a/src/main/java/com/nis/web/dao/DfLogSearchDao.xml +++ b/src/main/java/com/nis/web/dao/DfLogSearchDao.xml @@ -1403,4 +1403,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/com/nis/web/service/BaseLogService.java b/src/main/java/com/nis/web/service/BaseLogService.java index 30f6cea..7998f1d 100644 --- a/src/main/java/com/nis/web/service/BaseLogService.java +++ b/src/main/java/com/nis/web/service/BaseLogService.java @@ -19,7 +19,6 @@ import org.springframework.beans.factory.annotation.Autowired; import com.nis.domain.LogEntity; import com.nis.domain.Page; -import com.nis.domain.restful.NtcRadiusReport; import com.nis.domain.restful.NtcReportEntity; import com.nis.restful.RestBusinessCode; import com.nis.restful.RestServiceException; @@ -240,6 +239,62 @@ public abstract class BaseLogService { } logger.info("请求参数校验结束----" + System.currentTimeMillis()); + } + /** + * 验证日志查询条件格式是否正确 + * @param thread + * @param start + * @param entity + * @param clazz + * @param page + */ + public void collectConditionCheck(AuditLogThread thread, long start, NtcCollectVoipLog entity, Class clazz, + Page page) { + logger.info("请求参数校验开始----" + System.currentTimeMillis()); + try { + if (!StringUtil.isBlank(entity.getSearchFoundEndTime())) { + sdf.setLenient(false); + sdf.parse(entity.getSearchFoundEndTime()); + } + } catch (ParseException e) { + thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); + logger.error(e); + throw new RestServiceException(thread, System.currentTimeMillis() - start, "searchFoundEndTime参数格式错误", + RestBusinessCode.param_formate_error.getValue()); + } catch (Exception e) { + thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); + logger.error(e); + throw new RestServiceException(thread, System.currentTimeMillis() - start, "searchFoundEndTime参数格式格式"); + } + + try { + if (!StringUtil.isBlank(entity.getSearchFoundStartTime())) { + sdf.setLenient(false); + sdf.parse(entity.getSearchFoundStartTime()); + } + } catch (ParseException e) { + thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); + logger.error(e); + throw new RestServiceException(thread, System.currentTimeMillis() - start, "searchFoundStartTime参数格式错误", + RestBusinessCode.param_formate_error.getValue()); + } catch (Exception e) { + thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); + logger.error(e); + throw new RestServiceException(thread, System.currentTimeMillis() - start, "searchFoundStartTime参数错误"); + } + + try { + checkCloumnIsExist(thread, start, clazz, page); + } catch (RestServiceException e) { + logger.error(e); + throw e; + } catch (Exception e) { + thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); + logger.error(e); + throw new RestServiceException(thread, System.currentTimeMillis() - start, "请求参数错误"); + } + logger.info("请求参数校验结束----" + System.currentTimeMillis()); + } /** * @@ -295,6 +350,14 @@ public abstract class BaseLogService { logger.error(e); throw new RestServiceException(thread, System.currentTimeMillis() - start, "searchReportEndTime参数错误"); } + if (!StringUtil.isBlank(entity.getSearchBusinessType())&&!StringUtil.isNumeric(entity.getSearchBusinessType())) { + logger.error(RestBusinessCode.param_formate_error.getErrorReason()+",searchBusinessType参数格式错误"); + thread.setExceptionInfo("searchBusinessType参数格式错误"); + throw new RestServiceException(thread, + System.currentTimeMillis() - start, + "searchBusinessType参数格式错误", + RestBusinessCode.param_formate_error.getValue()); + } logger.info("实时报表统计查询参数校验结束----" + System.currentTimeMillis()); @@ -367,7 +430,7 @@ public abstract class BaseLogService { logger.error(e); throw new RestServiceException(thread, System.currentTimeMillis() - start, "searchReportStartTime参数错误"); } - + try { if (!StringUtil.isBlank(entity.getSearchReportEndTime())) { sdf.parse(entity.getSearchReportEndTime()); @@ -391,8 +454,8 @@ public abstract class BaseLogService { "searchReportStartTime和searchReportEndTime参数必须同时填写", RestBusinessCode.config_integrity_error.getValue()); } - - + + //根据用户查看IP趋势时(searchBusinessType=2),用户名必需填写 if ("2".equals(entity.getSearchBusinessType())&&StringUtil.isEmpty(entity.getSearchAccount())) { logger.error(RestBusinessCode.config_integrity_error.getErrorReason()+",searchBusinessType=2时searchAccount参数必须填写"); @@ -402,7 +465,7 @@ public abstract class BaseLogService { "searchBusinessType=2时searchAccount参数必须填写", RestBusinessCode.config_integrity_error.getValue()); } - + //根据用户查看IP趋势时(searchBusinessType=3),用户名必需填写 if ("3".equals(entity.getSearchBusinessType())&&StringUtil.isEmpty(entity.getSearchNasIp())) { logger.error(RestBusinessCode.config_integrity_error.getErrorReason()+",searchBusinessType=3时searchNasIp参数必须填写"); @@ -412,11 +475,11 @@ public abstract class BaseLogService { "searchBusinessType=3时searchNasIp参数必须填写", RestBusinessCode.config_integrity_error.getValue()); } - + logger.info("用户行为日志统计参数校验结束----" + System.currentTimeMillis()); - } - + } + /** * * @Title: getJedisKey diff --git a/src/main/java/com/nis/web/service/HiveSqlService.java b/src/main/java/com/nis/web/service/HiveSqlService.java deleted file mode 100644 index a4fcac6..0000000 --- a/src/main/java/com/nis/web/service/HiveSqlService.java +++ /dev/null @@ -1,625 +0,0 @@ -package com.nis.web.service; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.Statement; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.ibatis.mapping.ResultMap; -import org.apache.ibatis.mapping.ResultMapping; -import org.apache.ibatis.session.SqlSessionFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.alibaba.druid.pool.DruidDataSource; -import com.nis.domain.Page; -import com.nis.util.Constants; -import com.nis.util.LogJDBCByDruid; -import com.zdjizhi.utils.StringUtil; -import com.nis.util.redis.SaveRedisThread; - -public class HiveSqlService { - private final static Logger logger = LoggerFactory.getLogger(HiveSqlService.class); - static DruidDataSource datasource = null; - Connection conn = null; - ResultSet rs = null; - Statement st = null; - private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - private static SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMdd"); - - private static Map getFiledsType(Object o) { - Field[] fields = o.getClass().getSuperclass().getDeclaredFields(); - Field[] superfields = o.getClass().getDeclaredFields(); - Map infoMap = new HashMap(); - for (int i = 0; i < fields.length; i++) { - infoMap.put(fields[i].getName(), fields[i].getType().toString().replace("class", "")); - } - for (int i = 0; i < superfields.length; i++) { - infoMap.put(superfields[i].getName(), superfields[i].getType().toString().replace("class", "")); - } - return infoMap; - } - - public static String getSql(Page page, Object bean, String tableName, Map> col2col, - String orderBy, String searchActiveSys) throws Exception { - if (Constants.ISUSECLICKHOUSE) { - return getSqlByClickHouse(page, bean, tableName, col2col, orderBy, searchActiveSys); - } else { - return getSqlByHive(page, bean, tableName, col2col, orderBy, searchActiveSys); - } - } - - public static String getSqlByClickHouse(Page page, Object bean, String tableName, - Map> col2col, String orderBy, String searchActiveSys) throws Exception { - tableName = tableName.toLowerCase(); - String showColmun = getFiledsSql(bean.getClass().getSimpleName(), page.getFields()); - StringBuffer sql = new StringBuffer(); - Map filedAndColumnMap = getFiledAndColumnMap(bean.getClass()); - if (null == showColmun || showColmun.equals("")) { - for (String key : filedAndColumnMap.keySet()) { - if (!filedAndColumnMap.get(key).toLowerCase().equals("id")) { - sql.append(filedAndColumnMap.get(key) + ","); - } - } - } else { - sql.append(showColmun); - } - String sqlTrim = sql.toString().trim(); - if (sqlTrim.endsWith(",")) { - sqlTrim = sqlTrim.substring(0, sqlTrim.length() - 1); - } - sql.setLength(0); - sql.append(" select " + sqlTrim.toLowerCase() + " from " + tableName.toLowerCase() + " t "); - StringBuffer whereSB = new StringBuffer(); - if (!StringUtil.isEmpty(bean)) { - Class clazz = bean.getClass(); - Map filedsType = null; - filedsType = getFiledsType(bean); - for (; clazz != Object.class; clazz = clazz.getSuperclass()) { - Field[] fields = clazz.getDeclaredFields(); - for (int i = 0; i < fields.length; i++) { - // 现在gwall日志表结构中只有数值和字符串两种类型,数值都是int类型没有bigint所以不需要加L, - Field f = fields[i]; - String key = f.getName();// 获取字段名 - if (f.getType().getName().equals("java.lang.String") && key.startsWith("search")) { - Object value = getFieldValue(bean, key); - if (!StringUtil.isEmpty(value)) { - setFieldValue(bean, key, value.toString().trim()); - if (key.endsWith("Time")) {// 日期开始或结束的字段 - if (col2col.containsKey(key)) { - Long partition = Long.parseLong(sdf2.format(sdf.parse(value.toString().trim()))); - value = sdf.parse(value.toString().trim()).getTime() / 1000; - if (col2col.get(key).get("start") != null) { - whereSB.append(" and " - + filedAndColumnMap.get(col2col.get(key).get("start")).toLowerCase() - + ">=" + value); - } else { - whereSB.append(" and " - + filedAndColumnMap.get(col2col.get(key).get("end")).toLowerCase() + "<" - + value); - } - } - } else { - if (key.toLowerCase().startsWith("search")) { - key = key.replace("search", ""); - key = key.substring(0, 1).toLowerCase() + key.substring(1); - } - - // clickhouse写法 - String type = filedsType.get(key).trim(); - if (type.equals("java.lang.String")) { - String field = filedAndColumnMap.get(key).toLowerCase(); - if (field.equals("url")) { - whereSB.append(" and " + field + " like '" + value.toString().trim() + "%'"); - } else { - whereSB.append(" and " + field + "='" + value.toString().trim() + "'"); - } - } else if (type.equals("java.lang.Integer") || type.equals("int") - || type.equals("java.lang.Long") || type.equals("long")) { - whereSB.append(" and " + filedAndColumnMap.get(key).toLowerCase() + "=" - + value.toString().trim()); - } - - } - } - - } - } - - } - } - if (whereSB.length() > 0) { - int indexOf = whereSB.indexOf("and") + "and".length(); - sql.append(" where " + whereSB.substring(indexOf)); - } - Integer startNum = (page.getPageNo() - 1) * page.getPageSize(); - if (orderBy.toLowerCase().contains("asc") || orderBy.toLowerCase().contains("desc")) { - sql.append(" order by " + orderBy.toLowerCase()); - } else { - sql.append(" order by " + orderBy.toLowerCase() + " desc"); - } - sql.append(" limit " + startNum + "," + page.getPageSize());// clickhouse的分页与mysql相同 - - return sql.toString(); - } - - public static String getSqlByHive(Page page, Object bean, String tableName, - Map> col2col, String orderBy, String searchActiveSys) throws Exception { - tableName = tableName.toLowerCase(); - String showColmun = getFiledsSql(bean.getClass().getSimpleName(), page.getFields()); - StringBuffer sql = new StringBuffer(); - Map filedAndColumnMap = getFiledAndColumnMap(bean.getClass()); - if (null == showColmun || showColmun.equals("")) { - for (String key : filedAndColumnMap.keySet()) { - if (!filedAndColumnMap.get(key).toLowerCase().equals("id")) { - sql.append(filedAndColumnMap.get(key) + ","); - } - } - } else { - sql.append(showColmun); - } - String sqlTrim = sql.toString().trim(); - if (sqlTrim.endsWith(",")) { - sqlTrim = sqlTrim.substring(0, sqlTrim.length() - 1); - } - if (orderBy.toLowerCase().contains("asc") || orderBy.toLowerCase().contains("desc")) { - orderBy = " order by " + orderBy; - } else { - orderBy = " order by " + orderBy + " desc "; - } - sql.setLength(0); - sql.append(" select " + sqlTrim.toLowerCase() + " from (select " + sqlTrim.toLowerCase() - + ",row_number() over(partition by found_time_partition " + orderBy + ") as row_num from " - + tableName.toLowerCase() + " "); - StringBuffer whereSB = new StringBuffer(); - if (!StringUtil.isEmpty(bean)) { - Class clazz = bean.getClass(); - Map filedsType = null; - for (; clazz != Object.class; clazz = clazz.getSuperclass()) { - // 获取所有的字段包括public,private,protected,private - // Field[] fields = bean.getClass().getDeclaredFields(); - Field[] fields = clazz.getDeclaredFields(); - Long foundTimePartStart = null; - Long foundTimePartEnd = null; - for (int i = 0; i < fields.length; i++) { - // 现在gwall日志表结构中只有数值和字符串两种类型,数值都是int类型没有bigint所以不需要加L, - Field f = fields[i]; - String key = f.getName();// 获取字段名 - String typeName = f.getType().getName(); - if (f.getType().getName().equals("java.lang.String") && key.startsWith("search")) { - Object value = getFieldValue(bean, key); - if (!StringUtil.isEmpty(value)) { - setFieldValue(bean, key, value.toString().trim()); - if (key.endsWith("Time")) {// 日期开始或结束的字段 - if (col2col.containsKey(key)) { - Long partition = Long.parseLong(sdf2.format(sdf.parse(value.toString().trim()))); - value = sdf.parse(value.toString().trim()).getTime() / 1000; - if (key.toLowerCase().equals("searchfoundstarttime")) { - foundTimePartStart = partition; - } - if (key.toLowerCase().equals("searchfoundendtime")) { - foundTimePartEnd = partition; - } - if (col2col.get(key).get("start") != null) { - // sql.append(" and " + - // filedAndColumnMap.get(col2col.get(key).get("start")) - // + ">=to_date('" + - // value.toString().trim() - // + "','yyyy-mm-dd HH24:mi:ss')"); - whereSB.append(" and " - + filedAndColumnMap.get(col2col.get(key).get("start")).toLowerCase() - + ">=" + value); - } else { - // sql.append(" and " + - // filedAndColumnMap.get(col2col.get(key).get("end")) - // + "<=to_date('" + - // value.toString().trim() - // + "','yyyy-mm-dd HH24:mi:ss')"); - whereSB.append(" and " - + filedAndColumnMap.get(col2col.get(key).get("end")).toLowerCase() + "<" - + value); - } - } - } else { - if (key.toLowerCase().startsWith("search")) { - key = key.replace("search", ""); - key = key.substring(0, 1).toLowerCase() + key.substring(1); - } - - if (typeName.equals("java.lang.String")) { - String field = filedAndColumnMap.get(key); - if (field.equals("url")) { - whereSB.append(" and " + field + " like '" + value.toString().trim() + "%'"); - } else { - whereSB.append(" and " + field + "='" + value.toString().trim() + "'"); - } - } else if (typeName.equals("java.lang.Integer") || typeName.equals("int")) { - whereSB.append( - " and " + filedAndColumnMap.get(key) + "=" + value.toString().trim()); - - } else if (typeName.equals("java.lang.Long") || typeName.equals("long")) { - whereSB.append( - " and " + filedAndColumnMap.get(key) + "=" + value.toString().trim() + "L"); - } - - } - } - - } - } - if (null != foundTimePartStart) { - // sql.append(" and found_time_partition>=" + foundTimePartStart + "L"); - whereSB.append(" and found_time_partition>=" + foundTimePartStart); - } - if (null != foundTimePartEnd) { - // sql.append(" and found_time_partition<" + foundTimePartEnd + "L"); - whereSB.append(" and found_time_partition<=" + foundTimePartEnd); - } - - } - } - - if (whereSB.length() > 0) { - int indexOf = whereSB.indexOf("and") + "and".length(); - sql.append(" where " + whereSB.substring(indexOf)); - } - Integer startNum = (page.getPageNo() - 1) * page.getPageSize() + 1; - Integer endNum = startNum - 1 + page.getPageSize(); - sql.append(" ) t where row_Num between " + startNum + " and " + endNum); - logger.info("获取数据中心日志sql==================={}", sql); - return sql.toString(); - } - - public static Long getLogCount(Object bean, String tableName, Map> col2col) throws Exception { - if (Constants.ISUSECLICKHOUSE) { - return getLogCountFromClickHouse(bean, tableName, col2col); - } else { - return getLogCountFromHive(bean, tableName, col2col); - } - } - - public static Long getLogCountFromClickHouse(Object bean, String tableName, - Map> col2col) throws Exception { - tableName = tableName.toLowerCase(); - StringBuffer sql = new StringBuffer(); - Map filedAndColumnMap = getFiledAndColumnMap(bean.getClass()); - sql.append("select count(1) from " + tableName + " "); - StringBuffer whereSB = new StringBuffer(); - if (!StringUtil.isEmpty(bean)) { - Class clazz = bean.getClass(); - Map filedsType = null; - filedsType = getFiledsType(bean); - for (; clazz != Object.class; clazz = clazz.getSuperclass()) { - Field[] fields = clazz.getDeclaredFields(); - for (int i = 0; i < fields.length; i++) { - // 现在gwall日志表结构中只有数值和字符串两种类型,数值都是int类型没有bigint所以不需要加L, - Field f = fields[i]; - String key = f.getName();// 获取字段名 - if (f.getType().getName().equals("java.lang.String") && key.startsWith("search")) { - Object value = getFieldValue(bean, key); - if (!StringUtil.isEmpty(value)) { - setFieldValue(bean, key, value.toString().trim()); - if (key.endsWith("Time")) {// 日期开始或结束的字段 - if (col2col.containsKey(key)) { - Long partition = Long.parseLong(sdf2.format(sdf.parse(value.toString().trim()))); - value = sdf.parse(value.toString().trim()).getTime() / 1000; - if (col2col.get(key).get("start") != null) { - whereSB.append(" and " - + filedAndColumnMap.get(col2col.get(key).get("start")).toLowerCase() - + ">=" + value); - } else { - whereSB.append(" and " - + filedAndColumnMap.get(col2col.get(key).get("end")).toLowerCase() + "<" - + value); - } - } - } else { - if (key.toLowerCase().startsWith("search")) { - key = key.replace("search", ""); - key = key.substring(0, 1).toLowerCase() + key.substring(1); - } - - // clickhouse写法 - String type = filedsType.get(key).trim(); - if (type.equals("java.lang.String")) { - String field = filedAndColumnMap.get(key).toLowerCase(); - if (field.equals("url")) { - whereSB.append(" and " + field + " like '" + value.toString().trim() + "%'"); - } else { - whereSB.append(" and " + field + "='" + value.toString().trim() + "'"); - } - } else if (type.equals("java.lang.Integer") || type.equals("int") - || type.equals("java.lang.Long") || type.equals("long")) { - whereSB.append(" and " + filedAndColumnMap.get(key).toLowerCase() + "=" - + value.toString().trim()); - } - - } - } - - } - } - - } - } - if (whereSB.length() > 0) { - int indexOf = whereSB.indexOf("and") + "and".length(); - sql.append(" where " + whereSB.substring(indexOf)); - } - logger.info("获取数据中心日志总条数sql==================" + sql.toString()); - Long count = new LogJDBCByDruid().getCount(sql.toString()); - return count; - } - - public static Long getLogCountFromHive(Object bean, String tableName, Map> col2col) - throws Exception { - tableName = tableName.toLowerCase(); - StringBuffer sql = new StringBuffer(); - Map filedAndColumnMap = getFiledAndColumnMap(bean.getClass()); - sql.append("select count(1) from " + tableName + " "); - StringBuffer whereSB = new StringBuffer(); - if (bean != null) { - Class clazz = bean.getClass(); - for (; clazz != Object.class; clazz = clazz.getSuperclass()) { - // 获取所有的字段包括public,private,protected,private - // Field[] fields = bean.getClass().getDeclaredFields(); - Field[] fields = clazz.getDeclaredFields(); - Long foundTimePartStart = null; - Long foundTimePartEnd = null; - for (int i = 0; i < fields.length; i++) { - // 现在gwall日志表结构中只有数值和字符串两种类型,数值都是int类型没有bigint所以不需要加L, - Field f = fields[i]; - String key = f.getName();// 获取字段名 - String typeName = f.getType().getName(); - if (f.getType().getName().equals("java.lang.String") && key.startsWith("search")) { - Object value = getFieldValue(bean, key); - if (!StringUtil.isEmpty(value)) { - setFieldValue(bean, key, value.toString().trim()); - if (key.endsWith("Time")) {// 日期开始或结束的字段 - if (col2col.containsKey(key)) { - Long partition = Long.parseLong(sdf2.format(sdf.parse(value.toString().trim()))); - value = sdf.parse(value.toString().trim()).getTime() / 1000; - if (key.toLowerCase().equals("searchfoundstarttime")) { - foundTimePartStart = partition; - } - if (key.toLowerCase().equals("searchfoundendtime")) { - foundTimePartEnd = partition; - } - if (col2col.get(key).get("start") != null) { - // sql.append(" and " + - // filedAndColumnMap.get(col2col.get(key).get("start")) - // + ">=to_date('" + - // value.toString().trim() - // + "','yyyy-mm-dd HH24:mi:ss')"); - whereSB.append(" and " - + filedAndColumnMap.get(col2col.get(key).get("start")).toLowerCase() - + ">=" + value); - } else { - // sql.append(" and " + - // filedAndColumnMap.get(col2col.get(key).get("end")) - // + "<=to_date('" + - // value.toString().trim() - // + "','yyyy-mm-dd HH24:mi:ss')"); - whereSB.append(" and " - + filedAndColumnMap.get(col2col.get(key).get("end")).toLowerCase() + "<" - + value); - } - } - } else { - if (key.toLowerCase().startsWith("search")) { - key = key.replace("search", ""); - key = key.substring(0, 1).toLowerCase() + key.substring(1); - } - - if (typeName.equals("java.lang.String")) { - String field = filedAndColumnMap.get(key); - if (field.equals("url")) { - whereSB.append(" and " + field + " like '" + value.toString().trim() + "%'"); - } else { - whereSB.append(" and " + field + "='" + value.toString().trim() + "'"); - } - } else if (typeName.equals("java.lang.Integer") || typeName.equals("int")) { - whereSB.append( - " and " + filedAndColumnMap.get(key) + "=" + value.toString().trim()); - - } else if (typeName.equals("java.lang.Long") || typeName.equals("long")) { - whereSB.append( - " and " + filedAndColumnMap.get(key) + "=" + value.toString().trim() + "L"); - } - - } - } - - } - } - if (null != foundTimePartStart) { - // sql.append(" and found_time_partition>=" + foundTimePartStart + "L"); - whereSB.append(" and found_time_partition>=" + foundTimePartStart); - } - if (null != foundTimePartEnd) { - // sql.append(" and found_time_partition<" + foundTimePartEnd + "L"); - whereSB.append(" and found_time_partition<=" + foundTimePartEnd); - } - - } - } - if (whereSB.length() > 0) { - int indexOf = whereSB.indexOf("and") + "and".length(); - sql.append(" where " + whereSB.substring(indexOf)); - } - logger.info("获取数据中心日志总条数sql==================" + sql.toString()); - Long count = new LogJDBCByDruid().getCount(sql.toString()); - return count; - } - - public static String getFiledsSql(String mapName, String fileds) throws Exception { - String[] fieldsColoumn = null; - // 所有字段名 - List columnList = new ArrayList(); - // 所有属性名 - List propertyList = new ArrayList(); - // 属性名称为key,字段名称为value - Map columnMap = new HashMap(); - - if (!StringUtil.isBlank(fileds)) { - // 解析Fileds的字段/属性名称 - fieldsColoumn = fileds.split(","); - - // 从resultMap中获取字段名称和属性名称 - if (fieldsColoumn != null) { - SqlSessionFactory sqlSessionFactory = SpringContextHolder.getBean(SqlSessionFactory.class); - ResultMap map = sqlSessionFactory.getConfiguration().getResultMap(mapName + "Map"); - List mapping = map.getResultMappings(); - for (ResultMapping mapp : mapping) { - columnList.add(mapp.getColumn().toLowerCase()); - propertyList.add(mapp.getProperty()); - columnMap.put(mapp.getProperty(), mapp.getColumn()); - } - } - if (fieldsColoumn != null) { - fileds = ""; - for (String column : fieldsColoumn) { - if (!StringUtil.isBlank(column)) { - column = column.trim(); - if (columnList.contains(column)) { - fileds += "," + column; - } else if (propertyList.contains(column)) { - fileds += "," + columnMap.get(column).toString(); - } - } - } - if (!StringUtil.isBlank(fileds)) { - fileds = fileds.substring(1); - } - - } - - } - return fileds; - } - - public static Map getFiledAndColumnMap(Class clazz) { - Map map = new HashMap(); - SqlSessionFactory sqlSessionFactory = SpringContextHolder.getBean(SqlSessionFactory.class); - ResultMap resultMap = sqlSessionFactory.getConfiguration().getResultMap(clazz.getSimpleName() + "Map"); - List mapping = resultMap.getResultMappings(); - for (ResultMapping mapp : mapping) { - map.put(mapp.getProperty(), mapp.getColumn().toLowerCase()); - } - return map; - - } - - /** - * 利用反射通过get方法获取bean中字段fieldName的值 - * - * @param bean - * @param fieldName - * @return - * @throws Exception - */ - private static Object getFieldValue(Object bean, String fieldName) throws Exception { - StringBuffer result = new StringBuffer(); - String methodName = result.append("get").append(fieldName.substring(0, 1).toUpperCase()) - .append(fieldName.substring(1)).toString(); - - Object rObject = null; - Method method = null; - - @SuppressWarnings("rawtypes") - Class[] classArr = new Class[0]; - method = bean.getClass().getMethod(methodName, classArr); - rObject = method.invoke(bean, new Object[0]); - - return rObject; - } - - /** - * 利用发射调用bean.set方法将value设置到字段 - * - * @param bean - * @param fieldName - * @param value - * @throws Exception - */ - private static void setFieldValue(Object bean, String fieldName, Object value) throws Exception { - StringBuffer result = new StringBuffer(); - String methodName = result.append("set").append(fieldName.substring(0, 1).toUpperCase()) - .append(fieldName.substring(1)).toString(); - /** - * 利用发射调用bean.set方法将value设置到字段 - */ - Class[] classArr = new Class[1]; - classArr[0] = "java.lang.String".getClass(); - Method method = bean.getClass().getMethod(methodName, classArr); - method.invoke(bean, value); - } - - /** - * 比较开始时间或者结束时间是否比当前系统时间早48小时 - * - * @param startTime - * 开始时间 - * @param endTime - * 结束时间 - * @return - * @throws ParseException - */ - public static boolean ifTimeGreaterThan48(String startTime, String endTime) throws Exception { - logger.info("ifTimeGreaterThan48方法开始" + System.currentTimeMillis()); - if (null != startTime && !startTime.equals("") && null != endTime && !endTime.equals("")) {// 开始和结束时间都不为空 - Date startDate = sdf.parse(startTime); - Date endDate = sdf.parse(endTime); - if (startDate.getTime() < endDate.getTime()) {// 开始时间比结束时间早 - logger.info("ifTimeGreaterThan48方法结束" + System.currentTimeMillis()); - return gt48(endTime); - } else {// 开始时间比结束时间晚,不符合一般情况 - logger.info("ifTimeGreaterThan48方法结束" + System.currentTimeMillis()); - return false; - } - } else if (null != endTime && !endTime.equals("")) {// 开始时间为空,结束时间不为空 - logger.info("ifTimeGreaterThan48方法结束" + System.currentTimeMillis()); - return gt48(endTime); - } else if (null != startTime && !startTime.equals("")) {// 结束时间为空,开始时间不为空 - logger.info("ifTimeGreaterThan48方法结束" + System.currentTimeMillis()); - return gt48(startTime); - } else {// 开始和结束时间都为空 - logger.info("ifTimeGreaterThan48方法结束" + System.currentTimeMillis()); - return false; - } - - } - - public static boolean gt48(String eqTime) throws ParseException { - logger.info("gt48方法开始" + System.currentTimeMillis()); - Date eqDate = sdf.parse(eqTime); - Long dateNum = eqDate.getTime(); - Long currentDate = new Date().getTime(); - Long time = 0l; - if (dateNum < currentDate) { - time = currentDate - dateNum;// 获取结束时间与当前系统时间的时间差毫秒数 - } else { - logger.info("gt48方法结束" + System.currentTimeMillis()); - return false;// 结束时间比当前系统时间晚,不符合从数据中心查询数据要求(当前日期48小时前数据从数据中心查询) - } - double hours = time.doubleValue() / (1000 * 60 * 60); - Long datacenterTime = Constants.DATACENTER_TIME; - double doubleValue = datacenterTime.doubleValue(); - if (hours > doubleValue) { - logger.info("gt48方法结束" + System.currentTimeMillis()); - return true;// 符合要求 - } else { - logger.info("gt48方法结束" + System.currentTimeMillis()); - return false; - } - - } -} diff --git a/src/main/java/com/nis/web/service/LogDataService.java b/src/main/java/com/nis/web/service/LogDataService.java new file mode 100644 index 0000000..6d5b090 --- /dev/null +++ b/src/main/java/com/nis/web/service/LogDataService.java @@ -0,0 +1,512 @@ +package com.nis.web.service; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.Statement; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.ibatis.mapping.ResultMap; +import org.apache.ibatis.mapping.ResultMapping; +import org.apache.ibatis.session.SqlSessionFactory; +import org.springframework.stereotype.Service; + +import com.alibaba.druid.pool.DruidDataSource; +import com.nis.domain.Page; +import com.nis.util.Configurations; +import com.nis.util.Constants; +import com.nis.util.LogJDBCByDruid; +import com.zdjizhi.utils.StringUtil; + +/** + * 从clickhouse或者hive中查询数据并set到page.list返回给界面 + * + * @author rkg + * + */ +@Service +public class LogDataService { + // private final static Logger logger = + // LoggerFactory.getLogger(LogDataService.class); + static DruidDataSource datasource = null; + Connection conn = null; + ResultSet rs = null; + Statement st = null; + private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + private static SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMdd"); + private static Map> col2col = new HashMap>(); + static { + Map startMap = new HashMap(); + startMap.put("start", "foundTime"); + col2col.put("searchFoundStartTime", startMap); + Map endMap = new HashMap(); + endMap.put("end", "foundTime"); + col2col.put("searchFoundEndTime", endMap); + } + + /** + * 根据类名加对应的标识获取hive或者clickhouse中对应的表名 + * + * @param key + * @param defaultTableName + * @return + */ + private String getTableName(String key, String defaultTableName) { + if (Constants.ISUSECLICKHOUSE) { + key = key.replace("HiveTable", "ClickHouseTable"); + } + return Configurations.getStringProperty(key, defaultTableName); + } + + /** + * 根据page及obj对象中的属性值,利用反射拼接对应的查询sql(支持分页,排序) 和计算总量的sql并去对应的数据库中查询, + * 并将结果set到page对象中,返回给界面展示 + * + * @param page + * @param obj + * @throws Exception + */ + public void getData(Page page, Object obj) throws Exception { + String className = obj.getClass().getSimpleName(); + String tableName = getTableName(className + "HiveTable", ""); + if (tableName == null || tableName.trim().equals("")) { + throw new RuntimeException("日志类" + className + "对应的表名为空,请检查配置文件"); + } + String orderBy = " order by "; + if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { + orderBy = orderBy + Page.getOrderBySql(className, page.getOrderBy()); + } else { + orderBy = orderBy + "found_Time desc "; + } + if (Constants.ISUSECLICKHOUSE) { + getDataFromClickHouse(page, obj, tableName, className, orderBy.toLowerCase()); + } else { + getDataFromHive(page, obj, tableName, className, orderBy.toLowerCase()); + } + + } + + /** + * 从clickhouse中查询数据,注意clickhouse区分大小写,目前和百分点商定都是用小写 + * + * @param page + * 里面含有pagesize和pageno,order by + * @param bean + * 日志类对象(从DfLogSearchDao.xml中获取对应的map,类名+Map),用来获取各个属性对应的数据库字段名 + * @param tableName + * 表名 + * @param className + * 类名 + * @param orderBy + * orderby条件 + * @throws Exception + */ + private void getDataFromClickHouse(Page page, Object bean, String tableName, String className, + String orderBy) throws Exception { + tableName = tableName.toLowerCase(); + String showColmun = getFiledsSql(className, page.getFields()); + StringBuffer sql = new StringBuffer(); + Map filedAndColumnMap = getFiledAndColumnMap(bean.getClass()); + if (null == showColmun || showColmun.equals("")) { + for (String key : filedAndColumnMap.keySet()) { + if (!filedAndColumnMap.get(key).toLowerCase().equals("id")) { + sql.append(filedAndColumnMap.get(key) + ","); + } + } + } else { + sql.append(showColmun); + } + String sqlTrim = sql.toString().trim(); + if (sqlTrim.endsWith(",")) { + sqlTrim = sqlTrim.substring(0, sqlTrim.length() - 1); + } + sql.setLength(0); + sql.append(" select " + sqlTrim.toLowerCase() + " from " + tableName.toLowerCase() + " t where "); + StringBuffer whereFoundTime = new StringBuffer(); + StringBuffer countSql = new StringBuffer(); + countSql.append("select count(1) from " + tableName + " where "); + + StringBuffer whereSB = new StringBuffer(); + if (!StringUtil.isEmpty(bean)) { + Class clazz = bean.getClass(); + Map filedsType = null; + filedsType = getFiledsType(bean); + for (; clazz != Object.class; clazz = clazz.getSuperclass()) { + Field[] fields = clazz.getDeclaredFields(); + for (int i = 0; i < fields.length; i++) { + // 现在gwall日志表结构中只有数值和字符串两种类型,数值都是int类型没有bigint所以不需要加L, + Field f = fields[i]; + String key = f.getName();// 获取字段名 + if (f.getType().getName().equals("java.lang.String") && key.startsWith("search")) { + Object value = getFieldValue(bean, key); + if (!StringUtil.isEmpty(value)) { + setFieldValue(bean, key, value.toString().trim()); + if (key.endsWith("Time")) {// 日期开始或结束的字段 + if (col2col.containsKey(key)) { + value = sdf.parse(value.toString().trim()).getTime() / 1000; + if (col2col.get(key).get("start") != null) { + whereFoundTime.append(" and " + + filedAndColumnMap.get(col2col.get(key).get("start")).toLowerCase() + + ">=" + value); + } else { + whereFoundTime.append(" and " + + filedAndColumnMap.get(col2col.get(key).get("end")).toLowerCase() + "<" + + value); + } + } + } else { + if (key.toLowerCase().startsWith("search")) { + key = key.replace("search", ""); + key = key.substring(0, 1).toLowerCase() + key.substring(1); + } + // clickhouse写法 + String type = filedsType.get(key).trim(); + if (type.equals("java.lang.String")) { + String field = filedAndColumnMap.get(key).toLowerCase(); + if (field.equals("url")) { + whereSB.append(" and " + field + " like '" + value.toString().trim() + "%'"); + } else { + whereSB.append(" and " + field + "='" + value.toString().trim() + "'"); + } + } else if (type.equals("java.lang.Integer") || type.equals("int") + || type.equals("java.lang.Long") || type.equals("long")) { + whereSB.append(" and " + filedAndColumnMap.get(key).toLowerCase() + "=" + + value.toString().trim()); + } + + } + } + + } + } + + } + } + Integer startNum = (page.getPageNo() - 1) * page.getPageSize(); + StringBuffer foundTimeSql = new StringBuffer(); + foundTimeSql.append("select distinct found_time from " + tableName + " where "); + if (whereSB.length() == 0) {// 没有其他查询条件只有默认的found_time条件 + if (whereFoundTime.length() > 0) { + int indexOf = whereFoundTime.indexOf("and") + "and".length(); + countSql.append(whereFoundTime.substring(indexOf)); + + foundTimeSql.append(whereFoundTime.substring(indexOf) + orderBy.toLowerCase() + " limit " + startNum + + "," + page.getPageSize()); + sql.append(" found_time in(" + foundTimeSql + ") "); + } else { + throw new RuntimeException("从clickhouse的" + tableName + "表查询时,必须要有一个where条件"); + } + } else { + int foundIndexOf = whereFoundTime.append(whereSB).indexOf("and") + "and".length(); + countSql.append(whereFoundTime.substring(foundIndexOf)); + + foundTimeSql.append(whereFoundTime.substring(foundIndexOf) + orderBy.toLowerCase() + " limit " + startNum + + "," + page.getPageSize()); + + int indexOf = whereSB.indexOf("and") + "and".length(); + sql.append(whereSB.substring(indexOf) + " and found_time in(" + foundTimeSql + ") "); + } + sql.append(orderBy.toLowerCase() + " limit " + startNum + "," + page.getPageSize());// clickhouse的分页与mysql相同 + searchFromDataCenter(page, bean, sql, countSql); + } + + /** + * 从hive中查询数据 + * + * @param page + * 里面含有pagesize和pageno,order by + * @param bean + * 日志类对象(从DfLogSearchDao.xml中获取对应的map,类名+Map),用来获取各个属性对应的数据库字段名 + * @param tableName + * 表名 + * @param className + * 类名 + * @param orderBy + * orderby条件 + * @throws Exception + */ + private void getDataFromHive(Page page, Object bean, String tableName, String className, String orderBy) + throws Exception { + tableName = tableName.toLowerCase(); + String showColmun = getFiledsSql(className, page.getFields()); + StringBuffer sql = new StringBuffer(); + Map filedAndColumnMap = getFiledAndColumnMap(bean.getClass()); + if (null == showColmun || showColmun.equals("")) { + for (String key : filedAndColumnMap.keySet()) { + if (!filedAndColumnMap.get(key).toLowerCase().equals("id")) { + sql.append(filedAndColumnMap.get(key) + ","); + } + } + } else { + sql.append(showColmun); + } + String sqlTrim= sql.toString().trim(); + if (sqlTrim.endsWith(",")) { + sqlTrim = sqlTrim.substring(0, sqlTrim.length() - 1); + } + sql.setLength(0); + sql.append(" select " + sqlTrim.toLowerCase() + " from (select " + sqlTrim.toLowerCase() + + ",row_number() over(partition by found_time_partition " + orderBy + ") as row_num from " + + tableName.toLowerCase() + " "); + StringBuffer countSql = new StringBuffer(); + countSql.append("select count(1) from " + tableName + " "); + + StringBuffer whereSB = new StringBuffer(); + if (!StringUtil.isEmpty(bean)) { + Class clazz = bean.getClass(); + for (; clazz != Object.class; clazz = clazz.getSuperclass()) { + // 获取所有的字段包括public,private,protected,private + // Field[] fields = bean.getClass().getDeclaredFields(); + Field[] fields = clazz.getDeclaredFields(); + Long foundTimePartStart = null; + Long foundTimePartEnd = null; + for (int i = 0; i < fields.length; i++) { + // 现在gwall日志表结构中只有数值和字符串两种类型,数值都是int类型没有bigint所以不需要加L, + Field f = fields[i]; + String key = f.getName();// 获取字段名 + String typeName = f.getType().getName(); + if (f.getType().getName().equals("java.lang.String") && key.startsWith("search")) { + Object value = getFieldValue(bean, key); + if (!StringUtil.isEmpty(value)) { + setFieldValue(bean, key, value.toString().trim()); + if (key.endsWith("Time")) {// 日期开始或结束的字段 + if (col2col.containsKey(key)) { + Long partition = Long.parseLong(sdf2.format(sdf.parse(value.toString().trim()))); + value = sdf.parse(value.toString().trim()).getTime() / 1000; + if (key.toLowerCase().equals("searchfoundstarttime")) { + foundTimePartStart = partition; + } + if (key.toLowerCase().equals("searchfoundendtime")) { + foundTimePartEnd = partition; + } + if (col2col.get(key).get("start") != null) { + // sql.append(" and " + + // filedAndColumnMap.get(col2col.get(key).get("start")) + // + ">=to_date('" + + // value.toString().trim() + // + "','yyyy-mm-dd HH24:mi:ss')"); + whereSB.append(" and " + + filedAndColumnMap.get(col2col.get(key).get("start")).toLowerCase() + + ">=" + value); + } else { + // sql.append(" and " + + // filedAndColumnMap.get(col2col.get(key).get("end")) + // + "<=to_date('" + + // value.toString().trim() + // + "','yyyy-mm-dd HH24:mi:ss')"); + whereSB.append(" and " + + filedAndColumnMap.get(col2col.get(key).get("end")).toLowerCase() + "<" + + value); + } + } + } else { + if (key.toLowerCase().startsWith("search")) { + key = key.replace("search", ""); + key = key.substring(0, 1).toLowerCase() + key.substring(1); + } + + if (typeName.equals("java.lang.String")) { + String field = filedAndColumnMap.get(key); + if (field.equals("url")) { + whereSB.append(" and " + field + " like '" + value.toString().trim() + "%'"); + } else { + whereSB.append(" and " + field + "='" + value.toString().trim() + "'"); + } + } else if (typeName.equals("java.lang.Integer") || typeName.equals("int")) { + whereSB.append( + " and " + filedAndColumnMap.get(key) + "=" + value.toString().trim()); + + } else if (typeName.equals("java.lang.Long") || typeName.equals("long")) { + whereSB.append( + " and " + filedAndColumnMap.get(key) + "=" + value.toString().trim() + "L"); + } + + } + } + + } + } + if (null != foundTimePartStart) { + // sql.append(" and found_time_partition>=" + foundTimePartStart + "L"); + whereSB.append(" and found_time_partition>=" + foundTimePartStart); + } + if (null != foundTimePartEnd) { + // sql.append(" and found_time_partition<" + foundTimePartEnd + "L"); + whereSB.append(" and found_time_partition<=" + foundTimePartEnd); + } + + } + } + if (whereSB.length() > 0) { + int indexOf = whereSB.indexOf("and") + "and".length(); + sql.append(" where " + whereSB.substring(indexOf)); + countSql.append(" where " + whereSB.substring(indexOf)); + + } + Integer startNum = (page.getPageNo() - 1) * page.getPageSize() + 1; + Integer endNum = startNum - 1 + page.getPageSize(); + sql.append(" ) t where row_Num between " + startNum + " and " + endNum); + searchFromDataCenter(page, bean, sql, countSql); + } + + /** + * 执行sql + * + * @param page + * @param bean + * @param selSql + * @param countSql + * @throws Exception + */ + private void searchFromDataCenter(Page page, Object bean, StringBuffer selSql, StringBuffer countSql) + throws Exception { + new LogJDBCByDruid().getTableData(page, selSql.toString(), bean.getClass()); + if (Constants.ISOPENLOGCOUNTANDLAST) { + if (page.getList() != null && page.getList().size() > 0) { + new LogJDBCByDruid().getCount(page, countSql.toString().toLowerCase()); + } + } + + } + + /** + * 利用反射获取class中各个属性的数据类型,key是属性名称,value是数据类型 + * + * @param obj + * @return + */ + private static Map getFiledsType(Object obj) { + Field[] fields = obj.getClass().getSuperclass().getDeclaredFields(); + Field[] superfields = obj.getClass().getDeclaredFields(); + Map infoMap = new HashMap(); + for (int i = 0; i < fields.length; i++) { + infoMap.put(fields[i].getName(), fields[i].getType().toString().replace("class", "")); + } + for (int i = 0; i < superfields.length; i++) { + infoMap.put(superfields[i].getName(), superfields[i].getType().toString().replace("class", "")); + } + return infoMap; + } + + /** + * 将fileds中的字段根据DfLogSearchDao.xml中对应的resultMap转换为数据库中的字段 + * + * @param mapName + * @param fileds与界面商定好的是传日志类中的对象名(界面没有表结构不知道对象属性对应的数据库字段名称是什么),不是数据库中的字段名 + * @return + * @throws Exception + */ + private static String getFiledsSql(String mapName, String fileds) throws Exception { + if (!StringUtil.isBlank(fileds)) { + String[] fieldsColoumn = null; + // 所有字段名 + List columnList = new ArrayList(); + // 所有属性名 + List propertyList = new ArrayList(); + // 属性名称为key,字段名称为value + Map columnMap = new HashMap(); + // 解析Fileds的字段/属性名称 + fieldsColoumn = fileds.split(","); + + // 从resultMap中获取字段名称和属性名称 + if (fieldsColoumn != null) { + SqlSessionFactory sqlSessionFactory = SpringContextHolder.getBean(SqlSessionFactory.class); + ResultMap map = sqlSessionFactory.getConfiguration().getResultMap(mapName + "Map"); + List mapping = map.getResultMappings(); + for (ResultMapping mapp : mapping) { + columnList.add(mapp.getColumn().toLowerCase()); + propertyList.add(mapp.getProperty()); + columnMap.put(mapp.getProperty(), mapp.getColumn()); + } + } + if (fieldsColoumn != null) { + fileds = ""; + for (String column : fieldsColoumn) { + if (!StringUtil.isBlank(column)) { + column = column.trim(); + if (columnList.contains(column)) { + fileds += "," + column; + } else if (propertyList.contains(column)) { + fileds += "," + columnMap.get(column).toString(); + } + } + } + if (!StringUtil.isBlank(fileds)) { + fileds = fileds.substring(1); + } + + } + + } + return fileds; + } + + /** + * 根据class从DfLogSearchDao.xml中获取对应的resultMap里column与property的关系,key是property + * + * @param clazz + * @return + */ + private static Map getFiledAndColumnMap(Class clazz) { + Map map = new HashMap(); + SqlSessionFactory sqlSessionFactory = SpringContextHolder.getBean(SqlSessionFactory.class); + ResultMap resultMap = sqlSessionFactory.getConfiguration().getResultMap(clazz.getSimpleName() + "Map"); + List mapping = resultMap.getResultMappings(); + for (ResultMapping mapp : mapping) { + map.put(mapp.getProperty(), mapp.getColumn().toLowerCase()); + } + return map; + + } + + /** + * 利用反射通过get方法获取bean中字段fieldName的值 + * + * @param bean + * @param fieldName + * @return + * @throws Exception + */ + private static Object getFieldValue(Object bean, String fieldName) throws Exception { + StringBuffer result = new StringBuffer(); + String methodName = result.append("get").append(fieldName.substring(0, 1).toUpperCase()) + .append(fieldName.substring(1)).toString(); + + Object rObject = null; + Method method = null; + + @SuppressWarnings("rawtypes") + Class[] classArr = new Class[0]; + method = bean.getClass().getMethod(methodName, classArr); + rObject = method.invoke(bean, new Object[0]); + + return rObject; + } + + /** + * 利用反射调用bean.set方法将value设置到字段 + * + * @param bean + * @param fieldName + * @param value + * @throws Exception + */ + private static void setFieldValue(Object bean, String fieldName, Object value) throws Exception { + StringBuffer result = new StringBuffer(); + String methodName = result.append("set").append(fieldName.substring(0, 1).toUpperCase()) + .append(fieldName.substring(1)).toString(); + /** + * 利用发射调用bean.set方法将value设置到字段 + */ + Class[] classArr = new Class[1]; + classArr[0] = "java.lang.String".getClass(); + Method method = bean.getClass().getMethod(methodName, classArr); + method.invoke(bean, value); + } + +} diff --git a/src/main/resources/applicationLog-clickhouse.properties b/src/main/resources/applicationLog-clickhouse.properties index 2f686b9..9797557 100644 --- a/src/main/resources/applicationLog-clickhouse.properties +++ b/src/main/resources/applicationLog-clickhouse.properties @@ -35,7 +35,7 @@ NtcVoipLogClickHouseTable=TBS_ODS_NTC_VOIP_LOG NtcStreamingMediaLogClickHouseTable=TBS_ODS_NTC_STREAMING_MEDIA_LOG MmFileDigestLogClickHouseTable=TBS_ODS_MM_FILE_DIGEST_LOG NtcKeywordsUrlLogClickHouseTable=TBS_ODS_NTC_KEYWORDS_URL_LOG - +NtcCollectVoipLogClickHouseTable=TBS_ODS_NTC_COLLECT_VOIP_LOG diff --git a/src/main/resources/applicationLog-hive.properties b/src/main/resources/applicationLog-hive.properties index 824f387..1668ad4 100644 --- a/src/main/resources/applicationLog-hive.properties +++ b/src/main/resources/applicationLog-hive.properties @@ -22,7 +22,7 @@ MmPicUrlLogHiveTable=MM_PIC_URL_LOG MmVoipIpLogHiveTable=MM_VOIP_IP_LOG MmVoipAccountLogHiveTable=MM_VOIP_ACCOUNT_LOG MmSampleAudioLogHiveTable=MM_SAMPLE_AUDIO_LOG -MmSampleVideoLogLogHiveTable=MM_SAMPLE_VIDEO_LOG +MmSampleVideoLogHiveTable=MM_SAMPLE_VIDEO_LOG MmPornAudioLevelLogHiveTable=MM_PORN_AUDIO_LEVEL_LOG MmPornVideoLevelLogHiveTable=MM_PORN_VIDEO_LEVEL_LOG MmSamplePicLogHiveTable=MM_SAMPLE_PIC_LOG @@ -35,7 +35,7 @@ NtcVoipLogHiveTable=NTC_VOIP_LOG NtcStreamingMediaLogHiveTable=NTC_STREAMING_MEDIA_LOG MmFileDigestLogHiveTable=MM_FILE_DIGEST_LOG NtcKeywordsUrlLogHiveTable=NTC_KEYWORDS_URL_LOG - +NtcCollectVoipLogHiveTable=NTC_COLLECT_VOIP_LOG diff --git a/src/main/resources/nis.properties b/src/main/resources/nis.properties index f24a8ea..bc848d8 100644 --- a/src/main/resources/nis.properties +++ b/src/main/resources/nis.properties @@ -172,7 +172,7 @@ serviceValidate=true maxPageSize=100000 #是否开启Debug模式 -isDebug=true +isDebug=false @@ -209,3 +209,7 @@ isUseMinio=true ##存储到redis中的文件类型(拼接的前缀) fileProtocol=redis:// + +#是否开启日志查询count和last功能 +isOpenLogCountAndLast=true +