提交代码

master
胡锐 6 months ago committed by yuanye
parent 5921fd55d8
commit c94ad1df82
  1. 114
      bweb/src/main/java/com/bweb/controller/BsUserController.java
  2. 9
      order/src/main/java/com/order/controller/OrderController.java
  3. 11
      service/src/main/java/com/hfkj/common/security/UserCenter.java
  4. 15
      service/src/main/java/com/hfkj/service/user/BsUserService.java
  5. 35
      service/src/main/java/com/hfkj/service/user/impl/BsUserServiceImpl.java
  6. 4
      service/src/main/java/com/hfkj/sysenum/UserStatusEnum.java
  7. 2
      user/src/main/java/com/user/controller/BsUserController.java

@ -0,0 +1,114 @@
package com.bweb.controller;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.common.utils.ResponseMsgUtil;
import com.hfkj.entity.BsUser;
import com.hfkj.model.ResponseData;
import com.hfkj.service.user.BsUserService;
import com.hfkj.service.user.impl.BsUserServiceImpl;
import com.hfkj.sysenum.SecUserStatusEnum;
import com.hfkj.sysenum.UserStatusEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
/**
* @className: BsUserController
* @author: HuRui
* @date: 2024/5/6
**/
@Controller
@RequestMapping(value="/user")
@Api(value="系统菜单管理")
public class BsUserController {
private static Logger log = LoggerFactory.getLogger(BsUserController.class);
@Resource
private BsUserService userService;
@RequestMapping(value="/restore",method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "恢复")
public ResponseData restore(@RequestBody JSONObject body) {
try {
if (body == null || body.getLong("userId") == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
// 查询用户详情
BsUser user = userService.getUser(body.getLong("userId"));
if (user == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
user.setStatus(UserStatusEnum.status1.getCode());
userService.editData(user);
return ResponseMsgUtil.success("操作成功");
} catch (Exception e) {
log.error("error!",e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/disable",method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "禁用")
public ResponseData disable(@RequestBody JSONObject body) {
try {
if (body == null || body.getLong("userId") == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
// 查询用户详情
BsUser user = userService.getUser(body.getLong("userId"));
if (user == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
user.setStatus(SecUserStatusEnum.status2.getCode());
userService.editData(user);
// 退出当前登录信息
userService.loginOut(new BsUserServiceImpl().token(user));
return ResponseMsgUtil.success("操作成功");
} catch (Exception e) {
log.error("error!",e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/queryUserList",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "查询用户列表")
public ResponseData queryUserList(@RequestParam(value = "name" , required = false) String name,
@RequestParam(value = "phone" , required = false) String phone,
@RequestParam(value = "status" , required = false) Integer status,
@RequestParam(value = "pageNum" , required = true) Integer pageNum,
@RequestParam(value = "pageSize" , required = true) Integer pageSize) {
try {
Map<String,Object> param = new HashMap<>();
param.put("name", name);
param.put("phone", phone);
param.put("status", status);
PageHelper.startPage(pageNum, pageSize);
return ResponseMsgUtil.success(new PageInfo<>(userService.getList(param)));
} catch (Exception e) {
log.error("error!",e);
return ResponseMsgUtil.exception(e);
}
}
}

@ -6,6 +6,7 @@ import com.hfkj.common.exception.SysCode;
import com.hfkj.common.security.UserCenter; import com.hfkj.common.security.UserCenter;
import com.hfkj.common.utils.ResponseMsgUtil; import com.hfkj.common.utils.ResponseMsgUtil;
import com.hfkj.model.ResponseData; import com.hfkj.model.ResponseData;
import com.hfkj.model.UserSessionObject;
import com.hfkj.model.order.OrderChildModel; import com.hfkj.model.order.OrderChildModel;
import com.hfkj.model.order.OrderModel; import com.hfkj.model.order.OrderModel;
import com.hfkj.service.order.BsOrderService; import com.hfkj.service.order.BsOrderService;
@ -39,12 +40,14 @@ public class OrderController {
@ApiOperation(value = "创建订单") @ApiOperation(value = "创建订单")
public ResponseData create(@RequestBody OrderModel body) { public ResponseData create(@RequestBody OrderModel body) {
try { try {
// TODO 获取用户信息 // 用户session
UserSessionObject userSession = userCenter.getSessionModel(UserSessionObject.class);
if (userSession == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_LOGIN_NOT, "");
}
if (body == null || body.getOrderChildList().isEmpty()) { if (body == null || body.getOrderChildList().isEmpty()) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
} }
// 子订单必填项校验 // 子订单必填项校验
for (OrderChildModel orderChild : body.getOrderChildList()) { for (OrderChildModel orderChild : body.getOrderChildList()) {
if (orderChild.getProductType() == null if (orderChild.getProductType() == null

@ -71,6 +71,17 @@ public class UserCenter {
} }
} }
/**
* 退出登录
* @param token
*/
public void remove(String token) {
if (StringUtils.isNotBlank(token)) {
//通过token方式登录
redisUtil.del(token);
}
}
/** /**
* 获取session信息 * 获取session信息
* @param clazz * @param clazz

@ -5,6 +5,7 @@ import com.hfkj.entity.BsUser;
import com.hfkj.sysenum.UserLoginPlatform; import com.hfkj.sysenum.UserLoginPlatform;
import com.hfkj.sysenum.UserLoginType; import com.hfkj.sysenum.UserLoginType;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
@ -34,6 +35,14 @@ public interface BsUserService {
*/ */
BsUser getUser(String phone); BsUser getUser(String phone);
/**
* 获取用户列表
* @param param
* @return
*/
List<BsUser> getList(Map<String,Object> param);
/** /**
* 用户注册 * 用户注册
* @param phone 手机号 * @param phone 手机号
@ -56,6 +65,12 @@ public interface BsUserService {
*/ */
SessionObject login(UserLoginPlatform platform, UserLoginType loginType, String phone, String password, Map<String, Object> other) throws Exception; SessionObject login(UserLoginPlatform platform, UserLoginType loginType, String phone, String password, Map<String, Object> other) throws Exception;
/**
* 退出登录
* @param token
*/
void loginOut(String token);
/** /**
* 更新登录Session * 更新登录Session
* @param token * @param token

@ -73,15 +73,34 @@ public class BsUserServiceImpl implements BsUserService {
return null; return null;
} }
@Override
public List<BsUser> getList(Map<String, Object> param) {
BsUserExample example = new BsUserExample();
BsUserExample.Criteria criteria = example.createCriteria()
.andStatusNotEqualTo(UserStatusEnum.status0.getCode());
if (StringUtils.isNotBlank(MapUtils.getString(param, "name"))) {
criteria.andNameLike("%"+MapUtils.getString(param, "name")+"%");
}
if (StringUtils.isNotBlank(MapUtils.getString(param, "phone"))) {
criteria.andPhoneLike("%"+MapUtils.getString(param, "phone")+"%");
}
if (MapUtils.getInteger(param, "status") != null) {
criteria.andStatusEqualTo(MapUtils.getInteger(param, "status"));
}
example.setOrderByClause("update_time desc");
return userMapper.selectByExample(example);
}
/** /**
* 生成token * 生成token
* @param user 用户 * @param user 用户
* @return * @return
* @throws Exception * @throws Exception
*/ */
private String token(BsUser user) throws Exception { public String token(BsUser user) throws Exception {
// token 生成格式:账户id + 时间戳 // token 生成格式:账户id + 时间戳
return AESEncodeUtil.aesEncrypt(user.getId()+"_"+System.currentTimeMillis(), "ydQcF894xdcKQKfc8SEZdZrnSxzMckjZ"); return AESEncodeUtil.aesEncrypt(user.getId().toString(), "ydQcF894xdcKQKfc8SEZdZrnSxzMckjZ");
} }
@Override @Override
@ -120,12 +139,20 @@ public class BsUserServiceImpl implements BsUserService {
return sessionObject; return sessionObject;
} }
@Override
public void loginOut(String token) {
userCenter.remove(token);
}
@Override @Override
public SessionObject updateSession(String token) { public SessionObject updateSession(String token) {
SessionObject sessionObject = userCenter.getSessionObject(token); SessionObject sessionObject = userCenter.getSessionObject(token);
UserSessionObject user = (UserSessionObject) sessionObject.getObject(); UserSessionObject user = (UserSessionObject) sessionObject.getObject();
userCenter.save(new SessionObject(token, new UserSessionObject(getUser(user.getUser().getId()))));
return null; // 重新缓存
SessionObject newSession = new SessionObject(token, new UserSessionObject(getUser(user.getUser().getId())));
userCenter.save(newSession);
return newSession;
} }
} }

@ -17,9 +17,9 @@ public enum UserStatusEnum {
status1(1, "正常"), status1(1, "正常"),
/** /**
* 冻结 * 禁用
*/ */
status2(2, "冻结"), status2(2, "禁用"),
; ;
private int code; private int code;

@ -203,7 +203,7 @@ public class BsUserController {
if (session != null) { if (session != null) {
userCenter.remove(request); userCenter.remove(request);
} else { } else {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "账户已退出登录"); throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_LOGIN_NOT, "");
} }
return ResponseMsgUtil.success("退出成功"); return ResponseMsgUtil.success("退出成功");

Loading…
Cancel
Save