Browse Source

提取token中用户登录信息

master
xyiege 4 years ago
parent
commit
4485dbe16a
  1. 81
      src/main/java/cn/chjyj/szwh/controller/BaseController.java

81
src/main/java/cn/chjyj/szwh/controller/BaseController.java

@ -1,9 +1,15 @@
package cn.chjyj.szwh.controller; package cn.chjyj.szwh.controller;
import cn.chjyj.szwh.bean.Admin;
import cn.chjyj.szwh.service.AdminService;
import cn.chjyj.szwh.service.impl.AdminServiceImpl;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.auth0.jwt.JWT;
import com.auth0.jwt.interfaces.DecodedJWT;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.request.RequestAttributes; import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.context.request.ServletRequestAttributes;
@ -20,6 +26,12 @@ public abstract class BaseController {
public static Log log = LogFactory.getLog(BaseController.class); public static Log log = LogFactory.getLog(BaseController.class);
// jsonobject 全局 // jsonobject 全局
protected JSONObject jsonObject=new JSONObject(); protected JSONObject jsonObject=new JSONObject();
//当前用户信息
protected static Integer userid;
// 用户名
protected static String accountName;
// 用户账号
protected static String accountId;
static { static {
RequestAttributes ra = RequestContextHolder.getRequestAttributes(); RequestAttributes ra = RequestContextHolder.getRequestAttributes();
@ -32,68 +44,15 @@ public abstract class BaseController {
String token=request.getHeader("token"); String token=request.getHeader("token");
// 查询头部中的模块 // 查询头部中的模块
final String url=request.getHeader("url"); final String url=request.getHeader("url");
} // 提取用户信息
} DecodedJWT decode = JWT.decode(token);
accountId = decode.getClaim("accountId").asString();
/** accountName = decode.getClaim("accountName").asString();
* 将所有列表中筛选条件抽取出来
* @param request 为jsonobject对象
* @return
*/
protected Map orderMap(JSONObject request){
Map rqmap = new HashMap();
// 订单编号
String batchcode= request.getString("batchcode");
if(StringUtils.isNotBlank(batchcode)){
rqmap.put("batchcode",batchcode);
}
//
String entrustName=request.getString("entrust_name");
if(StringUtils.isNotBlank(entrustName)){
rqmap.put("entrust_name",entrustName);
}
//
String buyName=request.getString("buy_name");
if(StringUtils.isNotBlank(buyName)){
rqmap.put("buy_name",buyName);
}
//商品名称 //查询系统用户编号
String goodsName=request.getString("goods_name"); AdminService adminService = new AdminServiceImpl();
if(StringUtils.isNotBlank(goodsName)){ Admin admin = adminService.getAdminByAccountId(accountId);
rqmap.put("goods_name",goodsName); userid=Integer.valueOf(admin.getId());
} }
// 订单类型
String orderType= request.getString("order_type");
if(StringUtils.isNotBlank(orderType)){
rqmap.put("order_type",orderType);
} }
// String transactionStatus =request.getString("transaction_status");
// if(StringUtils.isNotBlank(transactionStatus)){
// rqmap.put("transaction_status",transactionStatus);
// }
//创建时间,拆分
// String createtime=request.getString("createtime");
// if(StringUtils.isNotBlank(createtime)){
// rqmap.put("createtime",createtime);
// }
//
// String goodsIsli = request.getString("goods_isli");
// if(StringUtils.isNotBlank(goodsIsli)){
// rqmap.put("goods_isli",goodsIsli);
// }
//充值类型
String chargesType= request.getString("charges_type");
if(StringUtils.isNotBlank(chargesType)){
rqmap.put("charges_type",chargesType);
}
return rqmap;
}
} }

Loading…
Cancel
Save