Commit 0c33d873 authored by Quxl's avatar Quxl

集成操作日志功能

parent 1d648b2e
......@@ -34,14 +34,14 @@ public class AdminAuthServiceImpl implements AdminAuthService {
@Override
public List<Map<String, Object>> queryGroupList(String keyword, Page page) {
SqlWhere argEdit = new SqlWhere().like("group_name", keyword);
SqlWhere argEdit = new SqlWhere().lk("group_name", keyword);
String sql = "select * from fc_admin_group" + StringUtil.join(" and ", " where ", "", "", argEdit.getStringList());
return jdbcTemplate.limit(sql, page, argEdit.getObjectList());
}
@Override
public List<Map<String, Object>> queryAdminList(String keyword, Integer group_id, Page page) {
SqlWhere argEdit = new SqlWhere().olike(new String[]{"realname", "username"}, keyword).eq("group_id", group_id);
SqlWhere argEdit = new SqlWhere().lk(new String[]{"realname", "username"}, keyword).eq("group_id", group_id);
String sql = "select * from fc_admin" + StringUtil.join(" and ", " where ", "", "", argEdit.getStringList());
return jdbcTemplate.limit(sql, page, argEdit.getObjectList());
}
......
......@@ -20,7 +20,7 @@ public class AdminUserServiceImpl implements AdminUserService {
@Override
public List<Map<String, Object>> queryGroupList(String keyword, Page page) {
SqlWhere argEdit = new SqlWhere().like("group_name", keyword);
SqlWhere argEdit = new SqlWhere().lk("group_name", keyword);
String sql = "select * from fc_user_group" + StringUtil.join(" and ", " where ", "", "", argEdit.getStringList());
return jdbcTemplate.limit(sql, page, argEdit.getObjectList());
}
......
......@@ -22,7 +22,7 @@ import com.egolm.film.api.common.service.Messages;
import com.egolm.film.api.member.service.MemberService;
import com.egolm.film.bean.Fc_member;
import com.egolm.film.config.XException;
import com.egolm.film.config.interceptor.LocaleCookieInterceptor;
import com.egolm.film.config.interceptor.LocaleInterceptor;
import com.egolm.film.util.Common;
import io.swagger.annotations.Api;
......@@ -128,7 +128,7 @@ public class MemberOpenApiController {
@ApiImplicitParam(paramType = "query", dataType = "String", required = true, name = "i18n_language", defaultValue="zh_CN")
})
public Object setLocale(HttpServletResponse response, String i18n_language) {
Cookie cookie = new Cookie(LocaleCookieInterceptor.language, i18n_language);
Cookie cookie = new Cookie(LocaleInterceptor.language, i18n_language);
cookie.setMaxAge(3600000);
cookie.setPath("/");
response.addCookie(cookie);
......
......@@ -497,7 +497,7 @@ public class MemberServiceImpl implements MemberService {
@Override
public List<Map<String, Object>> queryChuShenList(String keyword, Integer state, Integer apply_state, String film_type, String enroll_type, String film_country, Page page) {
SqlWhere where = new SqlWhere().olike(new String[]{"mf.en_name", "mf.cn_name"}, keyword).eq("mf.state", state).eq("mf.apply_state", apply_state).eq("mf.film_type_name", film_type).eq("mf.enroll_type_name", enroll_type).eq("mf.film_country", film_country);
SqlWhere where = new SqlWhere().lk(new String[]{"mf.en_name", "mf.cn_name"}, keyword).eq("mf.state", state).eq("mf.apply_state", apply_state).eq("mf.film_type_name", film_type).eq("mf.enroll_type_name", enroll_type).eq("mf.film_country", film_country);
String sql = "select mf.*, (select GROUP_CONCAT(mfd.director_name) from fc_member_film_director mfd where mfd.film_id = mf.id) director_name from fc_member_film mf" + StringUtil.join(" and ", " where ", "", "", where.getStringList());
Object[] objs = where.getObjectList();
return jdbcTemplate.limit(sql, page, objs);
......
......@@ -19,7 +19,7 @@ import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import com.egolm.film.config.interceptor.AdminLoginInterceptor;
import com.egolm.film.config.interceptor.LocaleCookieInterceptor;
import com.egolm.film.config.interceptor.LocaleInterceptor;
import com.egolm.film.config.interceptor.MemberLoginInterceptor;
import com.egolm.film.config.interceptor.UserLoginInterceptor;
......@@ -36,7 +36,7 @@ public class WebMvcConfig extends WebMvcConfigurerAdapter {
private MemberLoginInterceptor memberLoginInterceptor;
@Autowired
private LocaleCookieInterceptor localeSessionInterceptor;
private LocaleInterceptor localeSessionInterceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
......
......@@ -18,9 +18,13 @@ public class AdminLoginInterceptor extends HandlerInterceptorAdapter {
@Autowired
private AdminTokenService tokenService;
@Autowired
private LogsUtil logUtil;
@Override
public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object handler) throws Exception {
if(tokenService.isLogin()) {
logUtil.log(tokenService, req);
return super.preHandle(req, resp, handler);
} else {
String sessionid = null;
......@@ -31,6 +35,7 @@ public class AdminLoginInterceptor extends HandlerInterceptorAdapter {
}
}
if(sessionid != null && tokenService.isLoginByToken(sessionid)) {
logUtil.log(tokenService, req);
return super.preHandle(req, resp, handler);
}
throw new XException("用户未登陆", 300);
......
......@@ -14,10 +14,10 @@ import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import com.egolm.common.StringUtil;
@Component
public class LocaleCookieInterceptor extends HandlerInterceptorAdapter {
public class LocaleInterceptor extends HandlerInterceptorAdapter {
public static final String language = "i18n_language";
private static final Logger logger = Logger.getLogger(LocaleCookieInterceptor.class);
private static final Logger logger = Logger.getLogger(LocaleInterceptor.class);
@Override
public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object handler) throws Exception {
......
package com.egolm.film.config.interceptor;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.alibaba.fastjson.JSON;
import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.common.web.ServletUtil;
import com.egolm.film.api.TokenService;
import com.egolm.film.api.admin.service.AdminTokenService;
import com.egolm.film.api.member.service.MemberTokenService;
import com.egolm.film.api.user.service.UserTokenService;
import com.egolm.film.model.LoginToken;
@Component
public class LogsUtil {
@Autowired
private JdbcTemplate jdbcTemplate;
public void log(TokenService tokenService, HttpServletRequest request) {
LoginToken token = tokenService.getToken();
String type = null;
if(tokenService instanceof AdminTokenService) {
type = "admin";
} else if(tokenService instanceof MemberTokenService) {
type = "member";
} else if(tokenService instanceof UserTokenService) {
type = "user";
}
String loginid = String.valueOf(token.getId());
Date now = new Date();
String path = request.getRequestURI().replace(request.getContextPath(), "");
String prefix = path.split("/")[1];
String content = JSON.toJSONString(request.getParameterMap());
String ip = ServletUtil.readReqJson(request);
String sql = "insert into fc_logs (type, loginid, prefix, path, ip, content, create_time) values (?, ?, ?, ?, ?, ?, ?)";
Object[] objs = new Object[]{type, loginid, prefix, path, ip, content, now};
jdbcTemplate.executeUpdate(sql, objs);
}
}
......@@ -18,9 +18,13 @@ public class MemberLoginInterceptor extends HandlerInterceptorAdapter {
@Autowired
private MemberTokenService tokenService;
@Autowired
private LogsUtil logUtil;
@Override
public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object handler) throws Exception {
if(tokenService.isLogin()) {
logUtil.log(tokenService, req);
return super.preHandle(req, resp, handler);
} else {
String sessionid = null;
......@@ -31,6 +35,7 @@ public class MemberLoginInterceptor extends HandlerInterceptorAdapter {
}
}
if(sessionid != null && tokenService.isLoginByToken(sessionid)) {
logUtil.log(tokenService, req);
return super.preHandle(req, resp, handler);
}
throw new XException("用户未登陆", 300);
......
......@@ -18,9 +18,13 @@ public class UserLoginInterceptor extends HandlerInterceptorAdapter {
@Autowired
private UserTokenService tokenService;
@Autowired
private LogsUtil logUtil;
@Override
public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object handler) throws Exception {
if(tokenService.isLogin()) {
logUtil.log(tokenService, req);
return super.preHandle(req, resp, handler);
} else {
String sessionid = null;
......@@ -31,6 +35,7 @@ public class UserLoginInterceptor extends HandlerInterceptorAdapter {
}
}
if(sessionid != null && tokenService.isLoginByToken(sessionid)) {
logUtil.log(tokenService, req);
return super.preHandle(req, resp, handler);
}
throw new XException("用户未登陆", 300);
......
......@@ -39,7 +39,7 @@ public class SqlWhere {
return this;
}
public SqlWhere gte(String name, Object obj) {
public SqlWhere ge(String name, Object obj) {
if(StringUtil.isNotBlank(obj)) {
this.strList.add(name + " >= ?");
this.objList.add(obj);
......@@ -47,7 +47,7 @@ public class SqlWhere {
return this;
}
public SqlWhere lte(String name, Object obj) {
public SqlWhere le(String name, Object obj) {
if(StringUtil.isNotBlank(obj)) {
this.strList.add(name + " <= ?");
this.objList.add(obj);
......@@ -55,7 +55,7 @@ public class SqlWhere {
return this;
}
public SqlWhere like(String name, Object obj) {
public SqlWhere lk(String name, Object obj) {
if(StringUtil.isNotBlank(obj)) {
this.strList.add(name + " like ?");
this.objList.add("%" + obj + "%");
......@@ -63,7 +63,7 @@ public class SqlWhere {
return this;
}
public SqlWhere olike(String[] name, Object obj) {
public SqlWhere lk(String[] name, Object obj) {
if(name != null && name.length > 0 && StringUtil.isNotBlank(obj)) {
StringBuffer sb = new StringBuffer();
sb.append("(");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment