Commit 0c33d873 authored by Quxl's avatar Quxl

集成操作日志功能

parent 1d648b2e
...@@ -34,14 +34,14 @@ public class AdminAuthServiceImpl implements AdminAuthService { ...@@ -34,14 +34,14 @@ public class AdminAuthServiceImpl implements AdminAuthService {
@Override @Override
public List<Map<String, Object>> queryGroupList(String keyword, Page page) { 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()); String sql = "select * from fc_admin_group" + StringUtil.join(" and ", " where ", "", "", argEdit.getStringList());
return jdbcTemplate.limit(sql, page, argEdit.getObjectList()); return jdbcTemplate.limit(sql, page, argEdit.getObjectList());
} }
@Override @Override
public List<Map<String, Object>> queryAdminList(String keyword, Integer group_id, Page page) { 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()); String sql = "select * from fc_admin" + StringUtil.join(" and ", " where ", "", "", argEdit.getStringList());
return jdbcTemplate.limit(sql, page, argEdit.getObjectList()); return jdbcTemplate.limit(sql, page, argEdit.getObjectList());
} }
......
...@@ -20,7 +20,7 @@ public class AdminUserServiceImpl implements AdminUserService { ...@@ -20,7 +20,7 @@ public class AdminUserServiceImpl implements AdminUserService {
@Override @Override
public List<Map<String, Object>> queryGroupList(String keyword, Page page) { 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()); String sql = "select * from fc_user_group" + StringUtil.join(" and ", " where ", "", "", argEdit.getStringList());
return jdbcTemplate.limit(sql, page, argEdit.getObjectList()); return jdbcTemplate.limit(sql, page, argEdit.getObjectList());
} }
......
...@@ -22,7 +22,7 @@ import com.egolm.film.api.common.service.Messages; ...@@ -22,7 +22,7 @@ import com.egolm.film.api.common.service.Messages;
import com.egolm.film.api.member.service.MemberService; import com.egolm.film.api.member.service.MemberService;
import com.egolm.film.bean.Fc_member; import com.egolm.film.bean.Fc_member;
import com.egolm.film.config.XException; 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 com.egolm.film.util.Common;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
...@@ -128,7 +128,7 @@ public class MemberOpenApiController { ...@@ -128,7 +128,7 @@ public class MemberOpenApiController {
@ApiImplicitParam(paramType = "query", dataType = "String", required = true, name = "i18n_language", defaultValue="zh_CN") @ApiImplicitParam(paramType = "query", dataType = "String", required = true, name = "i18n_language", defaultValue="zh_CN")
}) })
public Object setLocale(HttpServletResponse response, String i18n_language) { 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.setMaxAge(3600000);
cookie.setPath("/"); cookie.setPath("/");
response.addCookie(cookie); response.addCookie(cookie);
......
...@@ -497,7 +497,7 @@ public class MemberServiceImpl implements MemberService { ...@@ -497,7 +497,7 @@ public class MemberServiceImpl implements MemberService {
@Override @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) { 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()); 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(); Object[] objs = where.getObjectList();
return jdbcTemplate.limit(sql, page, objs); return jdbcTemplate.limit(sql, page, objs);
......
...@@ -19,7 +19,7 @@ import org.springframework.web.servlet.config.annotation.PathMatchConfigurer; ...@@ -19,7 +19,7 @@ import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import com.egolm.film.config.interceptor.AdminLoginInterceptor; 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.MemberLoginInterceptor;
import com.egolm.film.config.interceptor.UserLoginInterceptor; import com.egolm.film.config.interceptor.UserLoginInterceptor;
...@@ -36,7 +36,7 @@ public class WebMvcConfig extends WebMvcConfigurerAdapter { ...@@ -36,7 +36,7 @@ public class WebMvcConfig extends WebMvcConfigurerAdapter {
private MemberLoginInterceptor memberLoginInterceptor; private MemberLoginInterceptor memberLoginInterceptor;
@Autowired @Autowired
private LocaleCookieInterceptor localeSessionInterceptor; private LocaleInterceptor localeSessionInterceptor;
@Override @Override
public void addInterceptors(InterceptorRegistry registry) { public void addInterceptors(InterceptorRegistry registry) {
......
...@@ -18,9 +18,13 @@ public class AdminLoginInterceptor extends HandlerInterceptorAdapter { ...@@ -18,9 +18,13 @@ public class AdminLoginInterceptor extends HandlerInterceptorAdapter {
@Autowired @Autowired
private AdminTokenService tokenService; private AdminTokenService tokenService;
@Autowired
private LogsUtil logUtil;
@Override @Override
public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object handler) throws Exception { public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object handler) throws Exception {
if(tokenService.isLogin()) { if(tokenService.isLogin()) {
logUtil.log(tokenService, req);
return super.preHandle(req, resp, handler); return super.preHandle(req, resp, handler);
} else { } else {
String sessionid = null; String sessionid = null;
...@@ -31,6 +35,7 @@ public class AdminLoginInterceptor extends HandlerInterceptorAdapter { ...@@ -31,6 +35,7 @@ public class AdminLoginInterceptor extends HandlerInterceptorAdapter {
} }
} }
if(sessionid != null && tokenService.isLoginByToken(sessionid)) { if(sessionid != null && tokenService.isLoginByToken(sessionid)) {
logUtil.log(tokenService, req);
return super.preHandle(req, resp, handler); return super.preHandle(req, resp, handler);
} }
throw new XException("用户未登陆", 300); throw new XException("用户未登陆", 300);
......
...@@ -14,10 +14,10 @@ import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; ...@@ -14,10 +14,10 @@ import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import com.egolm.common.StringUtil; import com.egolm.common.StringUtil;
@Component @Component
public class LocaleCookieInterceptor extends HandlerInterceptorAdapter { public class LocaleInterceptor extends HandlerInterceptorAdapter {
public static final String language = "i18n_language"; 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 @Override
public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object handler) throws Exception { 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 { ...@@ -18,9 +18,13 @@ public class MemberLoginInterceptor extends HandlerInterceptorAdapter {
@Autowired @Autowired
private MemberTokenService tokenService; private MemberTokenService tokenService;
@Autowired
private LogsUtil logUtil;
@Override @Override
public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object handler) throws Exception { public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object handler) throws Exception {
if(tokenService.isLogin()) { if(tokenService.isLogin()) {
logUtil.log(tokenService, req);
return super.preHandle(req, resp, handler); return super.preHandle(req, resp, handler);
} else { } else {
String sessionid = null; String sessionid = null;
...@@ -31,6 +35,7 @@ public class MemberLoginInterceptor extends HandlerInterceptorAdapter { ...@@ -31,6 +35,7 @@ public class MemberLoginInterceptor extends HandlerInterceptorAdapter {
} }
} }
if(sessionid != null && tokenService.isLoginByToken(sessionid)) { if(sessionid != null && tokenService.isLoginByToken(sessionid)) {
logUtil.log(tokenService, req);
return super.preHandle(req, resp, handler); return super.preHandle(req, resp, handler);
} }
throw new XException("用户未登陆", 300); throw new XException("用户未登陆", 300);
......
...@@ -18,9 +18,13 @@ public class UserLoginInterceptor extends HandlerInterceptorAdapter { ...@@ -18,9 +18,13 @@ public class UserLoginInterceptor extends HandlerInterceptorAdapter {
@Autowired @Autowired
private UserTokenService tokenService; private UserTokenService tokenService;
@Autowired
private LogsUtil logUtil;
@Override @Override
public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object handler) throws Exception { public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object handler) throws Exception {
if(tokenService.isLogin()) { if(tokenService.isLogin()) {
logUtil.log(tokenService, req);
return super.preHandle(req, resp, handler); return super.preHandle(req, resp, handler);
} else { } else {
String sessionid = null; String sessionid = null;
...@@ -31,6 +35,7 @@ public class UserLoginInterceptor extends HandlerInterceptorAdapter { ...@@ -31,6 +35,7 @@ public class UserLoginInterceptor extends HandlerInterceptorAdapter {
} }
} }
if(sessionid != null && tokenService.isLoginByToken(sessionid)) { if(sessionid != null && tokenService.isLoginByToken(sessionid)) {
logUtil.log(tokenService, req);
return super.preHandle(req, resp, handler); return super.preHandle(req, resp, handler);
} }
throw new XException("用户未登陆", 300); throw new XException("用户未登陆", 300);
......
...@@ -39,7 +39,7 @@ public class SqlWhere { ...@@ -39,7 +39,7 @@ public class SqlWhere {
return this; return this;
} }
public SqlWhere gte(String name, Object obj) { public SqlWhere ge(String name, Object obj) {
if(StringUtil.isNotBlank(obj)) { if(StringUtil.isNotBlank(obj)) {
this.strList.add(name + " >= ?"); this.strList.add(name + " >= ?");
this.objList.add(obj); this.objList.add(obj);
...@@ -47,7 +47,7 @@ public class SqlWhere { ...@@ -47,7 +47,7 @@ public class SqlWhere {
return this; return this;
} }
public SqlWhere lte(String name, Object obj) { public SqlWhere le(String name, Object obj) {
if(StringUtil.isNotBlank(obj)) { if(StringUtil.isNotBlank(obj)) {
this.strList.add(name + " <= ?"); this.strList.add(name + " <= ?");
this.objList.add(obj); this.objList.add(obj);
...@@ -55,7 +55,7 @@ public class SqlWhere { ...@@ -55,7 +55,7 @@ public class SqlWhere {
return this; return this;
} }
public SqlWhere like(String name, Object obj) { public SqlWhere lk(String name, Object obj) {
if(StringUtil.isNotBlank(obj)) { if(StringUtil.isNotBlank(obj)) {
this.strList.add(name + " like ?"); this.strList.add(name + " like ?");
this.objList.add("%" + obj + "%"); this.objList.add("%" + obj + "%");
...@@ -63,7 +63,7 @@ public class SqlWhere { ...@@ -63,7 +63,7 @@ public class SqlWhere {
return this; 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)) { if(name != null && name.length > 0 && StringUtil.isNotBlank(obj)) {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
sb.append("("); 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