Commit 4338339a by zhanghj

V1.0.0--增加获取用户id的方法

git-svn-id: svn://192.168.3.233/frms/code/car-service/trunk/car-service@17302 aeb6102e-e053-11e5-9fec-f9ebc45caf4b
1 parent 09e6ff35
...@@ -14,7 +14,14 @@ public interface Constants { ...@@ -14,7 +14,14 @@ public interface Constants {
final static int OPERATION_INSERT = 1; final static int OPERATION_INSERT = 1;
final static int OPERATION_delete = 0; final static int OPERATION_delete = 0;
public static final String SESSION_USERNAME_KEY = "username"; /*
*session中的用户名
*/
public static final String SESSION_USERNAME_KEY = "carService_username";
/*
* session中的用户id
*/
public static final String SESSION_USERID_KEY = "carService_userId";
/* /*
*字典: 操作日志-操作类型-新增 *字典: 操作日志-操作类型-新增
......
...@@ -81,7 +81,9 @@ public class AuthInterceptor implements HandlerInterceptor { ...@@ -81,7 +81,9 @@ public class AuthInterceptor implements HandlerInterceptor {
JSONObject data = result.getJSONObject("data"); JSONObject data = result.getJSONObject("data");
isLogin = data.getBooleanValue("isLogin"); isLogin = data.getBooleanValue("isLogin");
String username = data.getString(Constants.SESSION_USERNAME_KEY); String username = data.getString(Constants.SESSION_USERNAME_KEY);
Integer userId = data.getInteger(Constants.SESSION_USERID_KEY);
session.setAttribute(Constants.SESSION_USERNAME_KEY, username); session.setAttribute(Constants.SESSION_USERNAME_KEY, username);
session.setAttribute(Constants.SESSION_USERID_KEY, userId);
} }
if (isLogin) { if (isLogin) {
return true; return true;
......
...@@ -12,11 +12,11 @@ import com.glsx.common.constants.Constants; ...@@ -12,11 +12,11 @@ import com.glsx.common.constants.Constants;
/** /**
* *
* @Title UserUtils.java * @Title UserUtils.java
* @Package com.qurong.credit.sp.utils * @Package com.glsx.common.utils
* @Description TODO 获取当前用户工具类 * @Description TODO 获取当前用户工具类
* @author zhanghj * @author zhanghj
* @date 2018年7月16日 下午4:35:03 * @date 2019年2月12日 上午11:35:30
* @version * @version 1.0.0
*/ */
public class UserUtils { public class UserUtils {
...@@ -28,4 +28,10 @@ public class UserUtils { ...@@ -28,4 +28,10 @@ public class UserUtils {
String username = (String) session.getAttribute(Constants.SESSION_USERNAME_KEY); String username = (String) session.getAttribute(Constants.SESSION_USERNAME_KEY);
return username; return username;
} }
public static Integer getUserId(HttpServletRequest request) {
HttpSession session = request.getSession();
Integer userId = (Integer)session.getAttribute(Constants.SESSION_USERID_KEY);
return userId;
}
} }
...@@ -6,6 +6,7 @@ import java.util.HashMap; ...@@ -6,6 +6,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.validation.groups.Default; import javax.validation.groups.Default;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -22,6 +23,7 @@ import com.glsx.common.annotation.Log; ...@@ -22,6 +23,7 @@ import com.glsx.common.annotation.Log;
import com.glsx.common.constants.Constants; import com.glsx.common.constants.Constants;
import com.glsx.common.constants.ResultObject; import com.glsx.common.constants.ResultObject;
import com.glsx.common.utils.Page; import com.glsx.common.utils.Page;
import com.glsx.common.utils.UserUtils;
import com.glsx.manager.constants.ResultCodeEnum; import com.glsx.manager.constants.ResultCodeEnum;
import com.glsx.manager.pojo.GroupA; import com.glsx.manager.pojo.GroupA;
import com.glsx.manager.pojo.dictionary.DictionaryType; import com.glsx.manager.pojo.dictionary.DictionaryType;
...@@ -56,12 +58,12 @@ public class DictionaryTypeController extends BaseController{ ...@@ -56,12 +58,12 @@ public class DictionaryTypeController extends BaseController{
*/ */
@Log(menuName="系统管理-字典管理", operateType = Constants.SYS_LOG_OPERATE_TYPE_SAVE) @Log(menuName="系统管理-字典管理", operateType = Constants.SYS_LOG_OPERATE_TYPE_SAVE)
@RequestMapping(value="/save", method=RequestMethod.POST) @RequestMapping(value="/save", method=RequestMethod.POST)
public ResultObject save(@Validated(value={Default.class}) DictionaryType dictionaryType, BindingResult bindingResult){ public ResultObject save(HttpServletRequest request, @Validated(value={Default.class}) DictionaryType dictionaryType, BindingResult bindingResult){
if (bindingResult.hasErrors()) { if (bindingResult.hasErrors()) {
Map<String, String> errorMap = getErrors(bindingResult); Map<String, String> errorMap = getErrors(bindingResult);
return new ResultObject(ResultCodeEnum.PARAM_ERROR.getCode(), ResultCodeEnum.PARAM_ERROR.getMsg(), errorMap); return new ResultObject(ResultCodeEnum.PARAM_ERROR.getCode(), ResultCodeEnum.PARAM_ERROR.getMsg(), errorMap);
} }
//dictionaryType.setCreateBy(); dictionaryType.setCreateBy(UserUtils.getUserName(request));
dictionaryType.setCreateTime(new Date()); dictionaryType.setCreateTime(new Date());
int num = dictionaryTypeService.save(dictionaryType); int num = dictionaryTypeService.save(dictionaryType);
if (num > 0) { if (num > 0) {
......
...@@ -48,7 +48,8 @@ public class TestController extends BaseController{ ...@@ -48,7 +48,8 @@ public class TestController extends BaseController{
public ResultObject list(@RequestParam(defaultValue = "1") int pageIndex, @RequestParam(defaultValue = "10") int pageSize, public ResultObject list(@RequestParam(defaultValue = "1") int pageIndex, @RequestParam(defaultValue = "10") int pageSize,
HttpServletRequest request, HttpSession session){ HttpServletRequest request, HttpSession session){
String username = UserUtils.getUserName(request); String username = UserUtils.getUserName(request);
logger.info("当前用户的用户名" + username); Integer userId = UserUtils.getUserId(request);
logger.info("当前用户的用户名=" + username + "当前用户id=" + userId);
Map<String, Object> result = new HashMap<String, Object>(); Map<String, Object> result = new HashMap<String, Object>();
Page page = new Page(pageIndex, pageSize); Page page = new Page(pageIndex, pageSize);
List<Test> list = testService.list(page); List<Test> list = testService.list(page);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!