Commit 4e65cd3e by wubh

包活干V2.0.0-修改:工具类修改

git-svn-id: svn://192.168.3.233/frms/code/car-service/trunk/car-service@28248 aeb6102e-e053-11e5-9fec-f9ebc45caf4b
1 parent ec5d98ce
package com.glsx.common.pojo; package com.glsx.common.pojo;
import java.util.List; import java.util.List;
import com.github.pagehelper.PageInfo;
import com.glsx.common.utils.Page; import com.glsx.common.utils.Page;
/** /**
...@@ -20,6 +21,11 @@ public class PagedResp<E> { ...@@ -20,6 +21,11 @@ public class PagedResp<E> {
this.items = items; this.items = items;
} }
public static <E> PagedResp<E> of(PagedReq pagedReq, List<E> list) {
PageInfo<E> pageInfo = new PageInfo<>(list);
return of(pageInfo.getTotal(), pagedReq, list);
}
public static <E> PagedResp<E> of(long totalCount, PagedReq pagedReq, List<E> list) { public static <E> PagedResp<E> of(long totalCount, PagedReq pagedReq, List<E> list) {
int pageIndex = (pagedReq.getPageIndex() == null) ? 0 : pagedReq.getPageIndex(); int pageIndex = (pagedReq.getPageIndex() == null) ? 0 : pagedReq.getPageIndex();
int pageSize = (pagedReq.getPageSize() == null) ? 0 : pagedReq.getPageSize(); int pageSize = (pagedReq.getPageSize() == null) ? 0 : pagedReq.getPageSize();
......
...@@ -42,17 +42,24 @@ public class UserUtils { ...@@ -42,17 +42,24 @@ public class UserUtils {
return userId; return userId;
} }
/**
* 根据ID获取用户信息
*
* @param id 用户ID
* @return 用户信息
*/
public static JSONObject getUserInfo(Integer id) { public static JSONObject getUserInfo(Integer id) {
JSONObject respObj = userClient.getUserById(id); return parseUserInfo(userClient.getUserById(id));
JSONObject userObj; }
if (respObj != null
&& respObj.getIntValue("code") == ResultCodeEnum.SUCCESS.getCode()) {
userObj = respObj.getJSONObject("data");
} else {
userObj = new JSONObject();
}
return userObj; /**
* 根据ID获取商户信息
*
* @param id 商户ID
* @return 商户信息
*/
public static JSONObject getMerchantInfo(Integer id) {
return parseUserInfo(userClient.getMerchantById(id));
} }
/** /**
...@@ -111,6 +118,18 @@ public class UserUtils { ...@@ -111,6 +118,18 @@ public class UserUtils {
return userTypeMap.get(userType); return userTypeMap.get(userType);
} }
private static JSONObject parseUserInfo(JSONObject respObj) {
JSONObject userObj;
if (respObj != null
&& respObj.getInteger("code") == ResultCodeEnum.SUCCESS.getCode()) {
userObj = respObj.getJSONObject("data");
} else {
userObj = new JSONObject();
}
return userObj;
}
@Autowired @Autowired
public void setUserClient(UserClient userClient) { public void setUserClient(UserClient userClient) {
UserUtils.userClient = userClient; UserUtils.userClient = userClient;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!