增加操作日志功能

This commit is contained in:
liwen
2020-12-04 10:47:50 +08:00
parent 88ae95e1ab
commit c454ce1d27
27 changed files with 1407 additions and 114 deletions

View File

File diff suppressed because one or more lines are too long

View File

@@ -1,5 +1,6 @@
package com.epri.fx.server;
import com.epri.fx.server.util.DBLog;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -12,6 +13,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
public class ServerApplication {
public static void main(String[] args) {
DBLog.getInstance().start();
SpringApplication.run(ServerApplication.class, args);
}

View File

@@ -0,0 +1,42 @@
package com.epri.fx.server.config;
import com.epri.fx.server.filter.ReplaceStreamFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.servlet.Filter;
/**
* @author 01
* @program wrapper-demo
* @description 过滤器配置类
* @create 2018-12-24 21:06
* @since 1.0
**/
@Configuration
public class FilterConfig {
/**
* 注册过滤器
*
* @return FilterRegistrationBean
*/
@Bean
public FilterRegistrationBean someFilterRegistration() {
FilterRegistrationBean registration = new FilterRegistrationBean();
registration.setFilter(replaceStreamFilter());
registration.addUrlPatterns("/*");
registration.setName("streamFilter");
return registration;
}
/**
* 实例化StreamFilter
*
* @return Filter
*/
@Bean(name = "replaceStreamFilter")
public Filter replaceStreamFilter() {
return new ReplaceStreamFilter();
}
}

View File

@@ -2,6 +2,7 @@ package com.epri.fx.server.config;
import com.epri.fx.server.handler.GlobalExceptionHandler;
import com.epri.fx.server.interceptor.LogInterceptor;
import com.epri.fx.server.interceptor.UserAuthRestInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -18,7 +19,7 @@ import java.util.Collections;
*/
@Configuration("admimWebConfig")
@Primary
public class WebConfiguration implements WebMvcConfigurer {
public class WebConfiguration implements WebMvcConfigurer {
@Bean
GlobalExceptionHandler getGlobalExceptionHandler() {
return new GlobalExceptionHandler();
@@ -27,6 +28,7 @@ public class WebConfiguration implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(getUserAuthRestInterceptor()).addPathPatterns(getIncludePathPatterns());
registry.addInterceptor(getLogInterceptor()).addPathPatterns(getIncludePathPatterns());
}
@@ -34,6 +36,10 @@ public class WebConfiguration implements WebMvcConfigurer {
UserAuthRestInterceptor getUserAuthRestInterceptor() {
return new UserAuthRestInterceptor();
}
@Bean
LogInterceptor getLogInterceptor() {
return new LogInterceptor();
}
/**

View File

@@ -0,0 +1,32 @@
package com.epri.fx.server.entity.log;
import java.io.Serializable;
import java.util.Date;
import lombok.Data;
/**
* gate_log
* @author
*/
@Data
public class GateLog implements Serializable {
private Integer id;
private String menu;
private String opt;
private String uri;
private Date crtTime;
private String crtUser;
private String crtName;
private String crtHost;
private String body;
private static final long serialVersionUID = 1L;
}

View File

@@ -0,0 +1,115 @@
package com.epri.fx.server.entity.log;
import java.io.Serializable;
import java.util.Date;
/**
* ${DESCRIPTION}
*
* @author wanghaobin
* @create 2017-07-01 11:18
*/
public class LogInfo implements Serializable{
private String id;
private String menu;
private String opt;
private String uri;
private Long crtTime;
private String crtUser;
private String crtName;
private String crtHost;
private String body;
public LogInfo(String menu, String option, String uri, Date crtTime, String crtUser, String crtName, String crtHost, String body) {
this.menu = menu;
this.opt = option;
this.uri = uri;
this.crtTime = crtTime.getTime();
this.crtUser = crtUser;
this.crtName = crtName;
this.crtHost = crtHost;
this.body = body;
}
public LogInfo() {
}
public String getMenu() {
return menu;
}
public void setMenu(String menu) {
this.menu = menu;
}
public String getOpt() {
return opt;
}
public void setOpt(String option) {
this.opt = option;
}
public String getUri() {
return uri;
}
public void setUri(String uri) {
this.uri = uri;
}
public Long getCrtTime() {
return crtTime;
}
public void setCrtTime(Date crtTime) {
this.crtTime = crtTime.getTime();
}
public String getCrtUser() {
return crtUser;
}
public void setCrtUser(String crtUser) {
this.crtUser = crtUser;
}
public String getCrtName() {
return crtName;
}
public void setCrtName(String crtName) {
this.crtName = crtName;
}
public String getCrtHost() {
return crtHost;
}
public void setCrtHost(String crtHost) {
this.crtHost = crtHost;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}

View File

@@ -0,0 +1,33 @@
package com.epri.fx.server.filter;
import lombok.extern.slf4j.Slf4j;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
/**
* @author 01
* @program wrapper-demo
* @description 替换HttpServletRequest
* @create 2018-12-24 21:04
* @since 1.0
**/
@Slf4j
public class ReplaceStreamFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
log.info("StreamFilter初始化...");
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
ServletRequest requestWrapper = new RequestWrapper((HttpServletRequest) request);
chain.doFilter(requestWrapper, response);
}
@Override
public void destroy() {
log.info("StreamFilter销毁...");
}
}

View File

@@ -0,0 +1,124 @@
package com.epri.fx.server.filter;
import lombok.extern.slf4j.Slf4j;
import javax.servlet.ReadListener;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import java.io.*;
import java.nio.charset.Charset;
/**
* @author 01
* @program wrapper-demo
* @description 包装HttpServletRequest目的是让其输入流可重复读
* @create 2018-12-24 20:48
* @since 1.0
**/
@Slf4j
public class RequestWrapper extends HttpServletRequestWrapper {
/**
* 存储body数据的容器
*/
private final byte[] body;
public RequestWrapper(HttpServletRequest request) throws IOException {
super(request);
// 将body数据存储起来
String bodyStr = getBodyString(request);
body = bodyStr.getBytes(Charset.defaultCharset());
}
/**
* 获取请求Body
*
* @param request request
* @return String
*/
public String getBodyString(final ServletRequest request) {
try {
return inputStream2String(request.getInputStream());
} catch (IOException e) {
log.error("", e);
throw new RuntimeException(e);
}
}
/**
* 获取请求Body
*
* @return String
*/
public String getBodyString() {
final InputStream inputStream = new ByteArrayInputStream(body);
return inputStream2String(inputStream);
}
/**
* 将inputStream里的数据读取出来并转换成字符串
*
* @param inputStream inputStream
* @return String
*/
private String inputStream2String(InputStream inputStream) {
StringBuilder sb = new StringBuilder();
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(inputStream, Charset.defaultCharset()));
String line;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
} catch (IOException e) {
log.error("", e);
throw new RuntimeException(e);
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
log.error("", e);
}
}
}
return sb.toString();
}
@Override
public BufferedReader getReader() throws IOException {
return new BufferedReader(new InputStreamReader(getInputStream()));
}
@Override
public ServletInputStream getInputStream() throws IOException {
final ByteArrayInputStream inputStream = new ByteArrayInputStream(body);
return new ServletInputStream() {
@Override
public int read() throws IOException {
return inputStream.read();
}
@Override
public boolean isFinished() {
return false;
}
@Override
public boolean isReady() {
return false;
}
@Override
public void setReadListener(ReadListener readListener) {
}
};
}
}

View File

@@ -0,0 +1,149 @@
package com.epri.fx.server.interceptor;
import com.epri.fx.server.config.UserConfiguration;
import com.epri.fx.server.context.BaseContextHandler;
import com.epri.fx.server.entity.log.LogInfo;
import com.epri.fx.server.filter.RequestWrapper;
import com.epri.fx.server.jwt.IJWTInfo;
import com.epri.fx.server.service.PermissionService;
import com.epri.fx.server.service.log.GateLogService;
import com.epri.fx.server.util.DBLog;
import com.epri.fx.server.util.user.JwtTokenUtil;
import com.epri.fx.server.vo.PermissionInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* Created by ace on 2017/9/10.
*/
public class LogInterceptor extends HandlerInterceptorAdapter {
private Logger logger = LoggerFactory.getLogger(LogInterceptor.class);
@Autowired
private JwtTokenUtil jwtTokenUtil;
@Autowired
private UserConfiguration userConfiguration;
@Autowired
private GateLogService gateLogService;
@Autowired
private PermissionService permissionService;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
HandlerMethod handlerMethod = (HandlerMethod) handler;
String token = request.getHeader(userConfiguration.getUserTokenHeader());
IJWTInfo infoFromToken = jwtTokenUtil.getInfoFromToken(token);
HttpServletRequest requestWrapper = null;
//遇到post方法才对request进行包装
String methodType = request.getMethod();
List<PermissionInfo> permissionIfs = permissionService.getAllPermission();
// 判断资源是否启用权限约束
Stream<PermissionInfo> stream = getPermissionIfs(request.getRequestURI(), request.getMethod().toString(), permissionIfs);
List<PermissionInfo> result = stream.collect(Collectors.toList());
PermissionInfo[] permissions = result.toArray(new PermissionInfo[]{});
if (permissions.length > 0) {
checkUserPermission(permissions, request, infoFromToken);
}
return super.preHandle(request, response, handler);
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
BaseContextHandler.remove();
super.afterCompletion(request, response, handler, ex);
}
private boolean checkUserPermission(PermissionInfo[] permissions, HttpServletRequest ctx, IJWTInfo user) {
List<PermissionInfo> permissionInfos = permissionService.getPermissionByUsername(user.getUniqueName());
PermissionInfo current = null;
for (PermissionInfo info : permissions) {
boolean anyMatch = permissionInfos.parallelStream().anyMatch(permissionInfo -> permissionInfo.getCode().equals(info.getCode()));
if (anyMatch) {
current = info;
break;
}
}
if (current == null) {
return true;
} else {
if (!RequestMethod.GET.toString().equals(current.getMethod())) {
setCurrentUserInfoAndLog(ctx, user, current);
}
return false;
}
}
private void setCurrentUserInfoAndLog(HttpServletRequest request, IJWTInfo user, PermissionInfo pm) {
String host = request.getRemoteHost();
if (isJson(request)) {
// 获取json字符串
String jsonParam = null;
try {
jsonParam = new RequestWrapper(request).getBodyString();
LogInfo logInfo = new LogInfo(pm.getMenu(), pm.getName(), pm.getUri(), new Date(), user.getId(), user.getName(), host, jsonParam);
DBLog.getInstance().setLogService(gateLogService).offerQueue(logInfo);
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 获取目标权限资源
*
* @param requestUri
* @param method
* @param serviceInfo
* @return
*/
private Stream<PermissionInfo> getPermissionIfs(final String requestUri, final String method, List<PermissionInfo> serviceInfo) {
return serviceInfo.parallelStream().filter(permissionInfo -> {
String uri = permissionInfo.getUri();
if (uri.indexOf("{") > 0) {
uri = uri.replaceAll("\\{\\*\\}", "[a-zA-Z\\\\d]+");
}
String regEx = "^" + uri + "$";
return (Pattern.compile(regEx).matcher(requestUri).find())
&& method.equals(permissionInfo.getMethod());
});
}
/**
* 判断本次请求的数据类型是否为json
*
* @param request request
* @return boolean
*/
private boolean isJson(HttpServletRequest request) {
if (request.getContentType() != null) {
return request.getContentType().equals(MediaType.APPLICATION_JSON_VALUE) ||
request.getContentType().equals(MediaType.APPLICATION_JSON_UTF8_VALUE);
}
return false;
}
}

View File

@@ -4,6 +4,8 @@ package com.epri.fx.server.interceptor;
import com.epri.fx.server.config.UserConfiguration;
import com.epri.fx.server.context.BaseContextHandler;
import com.epri.fx.server.jwt.IJWTInfo;
import com.epri.fx.server.service.PermissionService;
import com.epri.fx.server.service.log.GateLogService;
import com.epri.fx.server.util.user.JwtTokenUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -23,6 +25,10 @@ public class UserAuthRestInterceptor extends HandlerInterceptorAdapter {
private JwtTokenUtil jwtTokenUtil;
@Autowired
private UserConfiguration userConfiguration;
@Autowired
private GateLogService gateLogService;
@Autowired
private PermissionService permissionService;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
@@ -32,6 +38,7 @@ public class UserAuthRestInterceptor extends HandlerInterceptorAdapter {
BaseContextHandler.setUsername(infoFromToken.getUniqueName());
BaseContextHandler.setName(infoFromToken.getName());
BaseContextHandler.setUserID(infoFromToken.getId());
return super.preHandle(request, response, handler);
}
@@ -40,4 +47,5 @@ public class UserAuthRestInterceptor extends HandlerInterceptorAdapter {
BaseContextHandler.remove();
super.afterCompletion(request, response, handler, ex);
}
}

View File

@@ -0,0 +1,23 @@
package com.epri.fx.server.mapper;
import com.epri.fx.server.entity.User;
import com.epri.fx.server.entity.log.GateLog;
import java.util.List;
public interface GateLogMapper {
int deleteByPrimaryKey(Integer id);
int insert(GateLog record);
int insertSelective(GateLog record);
GateLog selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(GateLog record);
int updateByPrimaryKey(GateLog record);
List<GateLog> selectPage(String keyId);
}

View File

@@ -0,0 +1,53 @@
package com.epri.fx.server.rest;
import com.epri.fx.server.entity.User;
import com.epri.fx.server.entity.UserInfo;
import com.epri.fx.server.entity.log.GateLog;
import com.epri.fx.server.entity.log.LogInfo;
import com.epri.fx.server.msg.ObjectRestResponse;
import com.epri.fx.server.msg.TableResultResponse;
import com.epri.fx.server.service.PermissionService;
import com.epri.fx.server.service.UserService;
import com.epri.fx.server.service.log.GateLogService;
import com.epri.fx.server.vo.FrontUser;
import com.epri.fx.server.vo.MenuVO;
import com.epri.fx.server.vo.PermissionInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
/**
* @Description:
* @param:
* @return:
* @auther: liwen
* @date: 2020/9/11 9:28 上午
*/
@RestController
@RequestMapping("log")
public class LogController {
@Autowired
private GateLogService gateLogService;
@GetMapping(value = "/page")
@ResponseBody
public TableResultResponse<GateLog> getPageList(@RequestParam Map<String, Object> params) {
return gateLogService.getPageList(params);
}
@DeleteMapping("/{id}")
@ResponseBody
public ObjectRestResponse<Integer> add(@PathVariable Integer id) {
return gateLogService.remove(id);
}
}

View File

@@ -37,7 +37,7 @@ public class GroupTypeService {
public Integer addGroupType(GroupTypeVO groupTypeVO) {
GroupType groupType = new GroupType();
BeanUtils.copyProperties(groupTypeVO, groupType);
EntityUtils.setCreateInfo(groupType);
EntityUtils.setCreatAndUpdatInfo(groupType);
groupType.setId(null);
return groupTypeMapper.insertSelective(groupType);
}

View File

@@ -0,0 +1,55 @@
package com.epri.fx.server.service.log;
import com.alibaba.druid.util.StringUtils;
import com.epri.fx.server.entity.log.GateLog;
import com.epri.fx.server.entity.log.LogInfo;
import com.epri.fx.server.mapper.GateLogMapper;
import com.epri.fx.server.msg.ObjectRestResponse;
import com.epri.fx.server.msg.TableResultResponse;
import com.epri.fx.server.util.Query;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* @description:
* @className: GateLogService
* @author: liwen
* @date: 2020/12/3 10:33
*/
@Service
public class GateLogService {
@Autowired
private GateLogMapper gateLogMapper;
public void saveLog(LogInfo info){
GateLog log = new GateLog();
BeanUtils.copyProperties(info,log);
log.setCrtTime(new Date(info.getCrtTime()));
gateLogMapper.insertSelective(log);
}
public TableResultResponse<GateLog> getPageList(Map<String, Object> params) {
Query query = new Query(params);
Page<Object> page = PageHelper.startPage(query.getPage(), query.getLimit());
String keyId = (String) params.get("keyId");
List<GateLog> list = gateLogMapper.selectPage(StringUtils.isEmpty(keyId) ? null : keyId);
int total = (int) Math.ceil(page.getTotal() / (float) query.getLimit());
return new TableResultResponse<GateLog>(total == 0 ? 1 : total, list);
}
public ObjectRestResponse<Integer> remove(Integer id) {
gateLogMapper.deleteByPrimaryKey(id);
return new ObjectRestResponse<Integer>().rel(true);
}
}

View File

@@ -0,0 +1,86 @@
package com.epri.fx.server.util;
import com.epri.fx.server.entity.log.LogInfo;
import com.epri.fx.server.service.log.GateLogService;
import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
/**
* ${DESCRIPTION}
*
* @author wanghaobin
* @create 2017-07-01 15:28
*/
@Slf4j
public class DBLog extends Thread {
private static DBLog dblog = null;
private static BlockingQueue<LogInfo> logInfoQueue = new LinkedBlockingQueue<LogInfo>(1024);
public GateLogService get() {
return logService;
}
public DBLog setLogService(GateLogService logService) {
if (this.logService == null) {
this.logService = logService;
}
return this;
}
private GateLogService logService;
public static synchronized DBLog getInstance() {
if (dblog == null) {
dblog = new DBLog();
}
return dblog;
}
private DBLog() {
super("CLogOracleWriterThread");
}
public void offerQueue(LogInfo logInfo) {
try {
logInfoQueue.offer(logInfo);
} catch (Exception e) {
log.error("日志写入失败", e);
}
}
@Override
public void run() {
List<LogInfo> bufferedLogList = new ArrayList<LogInfo>(); // 缓冲队列
while (true) {
try {
bufferedLogList.add(logInfoQueue.take());
logInfoQueue.drainTo(bufferedLogList);
if (bufferedLogList != null && bufferedLogList.size() > 0) {
// 写入日志
for (LogInfo log : bufferedLogList) {
logService.saveLog(log);
}
}
} catch (Exception e) {
e.printStackTrace();
// 防止缓冲队列填充数据出现异常时不断刷屏
try {
Thread.sleep(1000);
} catch (Exception eee) {
}
} finally {
if (bufferedLogList != null && bufferedLogList.size() > 0) {
try {
bufferedLogList.clear();
} catch (Exception e) {
}
}
}
}
}
}

View File

@@ -5,8 +5,6 @@ spring:
# 使用druid数据源
type: com.alibaba.druid.pool.DruidDataSource
druid:
#url: jdbc:dm://10.105.73.121:12345/EMSHIS
# url: jdbc:dm://192.168.1.210:12345/EMSHIS
url: jdbc:mysql://${MYSQL_HOST:10.211.55.3}:${MYSQL_PORT:3306}/ipsm_dba?serverTimezone=Asia/Shanghai
username: root
password: Root@12345
@@ -35,8 +33,8 @@ spring:
connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
mybatis:
basepackage: com.wlkj.ipsm.realtime.mapper
xmlLocation: classpath:mapper/**/*.xml
basepackage: com.epri.fx.server.mapper
xmlLocation: classpath:mapper/*.xml
mapper-locations: "classpath*:mapper/*.xml"
#分页控件配置

View File

@@ -0,0 +1,147 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.epri.fx.server.mapper.GateLogMapper">
<resultMap id="BaseResultMap" type="com.epri.fx.server.entity.log.GateLog">
<id column="id" jdbcType="INTEGER" property="id"/>
<result column="menu" jdbcType="VARCHAR" property="menu"/>
<result column="opt" jdbcType="VARCHAR" property="opt"/>
<result column="uri" jdbcType="VARCHAR" property="uri"/>
<result column="crt_time" jdbcType="TIMESTAMP" property="crtTime"/>
<result column="crt_user" jdbcType="VARCHAR" property="crtUser"/>
<result column="crt_name" jdbcType="VARCHAR" property="crtName"/>
<result column="crt_host" jdbcType="VARCHAR" property="crtHost"/>
<result column="body" jdbcType="VARCHAR" property="body"/>
</resultMap>
<sql id="Base_Column_List">
id, menu, opt, uri, crt_time, crt_user, crt_name, crt_host, body
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from gate_log
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from gate_log
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.epri.fx.server.entity.log.GateLog"
useGeneratedKeys="true">
insert into gate_log (menu, opt, uri,
crt_time, crt_user, crt_name,
crt_host, body)
values (#{menu,jdbcType=VARCHAR}, #{opt,jdbcType=VARCHAR}, #{uri,jdbcType=VARCHAR},
#{crtTime,jdbcType=TIMESTAMP}, #{crtUser,jdbcType=VARCHAR}, #{crtName,jdbcType=VARCHAR},
#{crtHost,jdbcType=VARCHAR}, #{body,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.epri.fx.server.entity.log.GateLog"
useGeneratedKeys="true">
insert into gate_log
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="menu != null">
menu,
</if>
<if test="opt != null">
opt,
</if>
<if test="uri != null">
uri,
</if>
<if test="crtTime != null">
crt_time,
</if>
<if test="crtUser != null">
crt_user,
</if>
<if test="crtName != null">
crt_name,
</if>
<if test="crtHost != null">
crt_host,
</if>
<if test="body != null">
body,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="menu != null">
#{menu,jdbcType=VARCHAR},
</if>
<if test="opt != null">
#{opt,jdbcType=VARCHAR},
</if>
<if test="uri != null">
#{uri,jdbcType=VARCHAR},
</if>
<if test="crtTime != null">
#{crtTime,jdbcType=TIMESTAMP},
</if>
<if test="crtUser != null">
#{crtUser,jdbcType=VARCHAR},
</if>
<if test="crtName != null">
#{crtName,jdbcType=VARCHAR},
</if>
<if test="crtHost != null">
#{crtHost,jdbcType=VARCHAR},
</if>
<if test="body != null">
#{body,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.epri.fx.server.entity.log.GateLog">
update gate_log
<set>
<if test="menu != null">
menu = #{menu,jdbcType=VARCHAR},
</if>
<if test="opt != null">
opt = #{opt,jdbcType=VARCHAR},
</if>
<if test="uri != null">
uri = #{uri,jdbcType=VARCHAR},
</if>
<if test="crtTime != null">
crt_time = #{crtTime,jdbcType=TIMESTAMP},
</if>
<if test="crtUser != null">
crt_user = #{crtUser,jdbcType=VARCHAR},
</if>
<if test="crtName != null">
crt_name = #{crtName,jdbcType=VARCHAR},
</if>
<if test="crtHost != null">
crt_host = #{crtHost,jdbcType=VARCHAR},
</if>
<if test="body != null">
body = #{body,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.epri.fx.server.entity.log.GateLog">
update gate_log
set menu = #{menu,jdbcType=VARCHAR},
opt = #{opt,jdbcType=VARCHAR},
uri = #{uri,jdbcType=VARCHAR},
crt_time = #{crtTime,jdbcType=TIMESTAMP},
crt_user = #{crtUser,jdbcType=VARCHAR},
crt_name = #{crtName,jdbcType=VARCHAR},
crt_host = #{crtHost,jdbcType=VARCHAR},
body = #{body,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectPage" parameterType="java.lang.String" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from gate_log
<where>
<if test="keyId != null">
and crt_name like #{keyId,jdbcType=VARCHAR} or crt_host like #{keyId,jdbcType=VARCHAR}
</if>
</where>
</select>
</mapper>