From 42eadaaeecbb3c400e00a32862d6ea6fac828535 Mon Sep 17 00:00:00 2001 From: hu177768073 <177768073@qq.com> Date: Thu, 17 Oct 2024 17:43:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/hfkj/controller/BsUserController.java | 159 ++++++++++++++++++ .../com/hfkj/controller/CmsController.java | 1 + .../hfkj/service/user/BsUserGradeService.java | 9 + .../com/hfkj/service/user/BsUserService.java | 12 ++ .../user/impl/BsUserGradeServiceImpl.java | 16 ++ .../service/user/impl/BsUserServiceImpl.java | 53 +++++- 6 files changed, 249 insertions(+), 1 deletion(-) create mode 100644 bweb/src/main/java/com/hfkj/controller/BsUserController.java diff --git a/bweb/src/main/java/com/hfkj/controller/BsUserController.java b/bweb/src/main/java/com/hfkj/controller/BsUserController.java new file mode 100644 index 0000000..af20546 --- /dev/null +++ b/bweb/src/main/java/com/hfkj/controller/BsUserController.java @@ -0,0 +1,159 @@ +package com.hfkj.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.entity.BsUserParentRel; +import com.hfkj.model.ResponseData; +import com.hfkj.service.user.BsUserGradeService; +import com.hfkj.service.user.BsUserParentRelService; +import com.hfkj.service.user.BsUserService; +import com.hfkj.sysenum.user.UserGradeEnum; +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.ArrayList; +import java.util.HashMap; +import java.util.Map; + +/** + * @className: CmsController + * @author: HuRui + * @date: 2024/9/24 + **/ +@Controller +@RequestMapping(value = "/bsUser") +@Api(value = "用户管理") +public class BsUserController { + private static Logger log = LoggerFactory.getLogger(BsUserController.class); + @Resource + private BsUserService userService; + @Resource + private BsUserGradeService userGradeService; + @Resource + private BsUserParentRelService userParentRelService; + + @RequestMapping(value="/gradeAdjust",method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "等级调整") + public ResponseData gradeAdjust(@RequestBody JSONObject body) { + try { + if (body == null || body.getLong("userId") == null || body.getInteger("grade") == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + + userGradeService.gradeAdjust(body.getLong("userId"), UserGradeEnum.getDataByType(body.getInteger("grade"))); + + return ResponseMsgUtil.success("操作成功"); + + } catch (Exception e) { + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value="/ban",method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "封禁") + public ResponseData ban(@RequestBody JSONObject body) { + try { + if (body == null || body.getLong("userId") == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + + userService.ban(body.getLong("userId")); + + return ResponseMsgUtil.success("操作成功"); + + } catch (Exception e) { + return ResponseMsgUtil.exception(e); + } + } + + @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, ""); + } + + userService.restore(body.getLong("userId")); + + return ResponseMsgUtil.success("操作成功"); + + } catch (Exception e) { + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value="/getDetail",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "查询详情") + public ResponseData getDetail(@RequestParam(name = "userId", required = true) Long userId) { + try { + // 查询用户 + BsUser user = userService.getUser(userId); + if (user == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的用户"); + } + Map param = new HashMap<>(); + param.put("user", user); + // 授权 + param.put("platform_authorize", new ArrayList<>()); + // 邀请人 + param.put("inviteUser", user.getInviteUserId()!=null?userService.getUser(user.getInviteUserId()):null); + // 贡献关系 + Map contribute = new HashMap<>(); + param.put("contribute", contribute); + if (user.getInviteUserId() != null) { + // 查询用户上级 + BsUserParentRel parent = userParentRelService.getDetailByUserId(userId); + + } + + + return ResponseMsgUtil.success(param); + + } catch (Exception e) { + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value="/queryList",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "查询列表") + public ResponseData queryList(@RequestParam(name = "userId", required = false) Long userId, + @RequestParam(name = "name", required = false) String name, + @RequestParam(name = "phone", required = false) Integer phone, + @RequestParam(name = "grade", required = false) Integer grade, + @RequestParam(name = "status", required = false) Integer status, + @RequestParam(name = "pageNum", required = true) Integer pageNum, + @RequestParam(name = "pageSize", required = true) Integer pageSize) { + try { + Map param = new HashMap<>(); + param.put("id", userId); + param.put("name", name); + param.put("phone", phone); + param.put("grade", grade); + param.put("status", status); + + PageHelper.startPage(pageNum, pageSize); + return ResponseMsgUtil.success(new PageInfo<>(userService.getList(param))); + + } catch (Exception e) { + return ResponseMsgUtil.exception(e); + } + } + +} diff --git a/bweb/src/main/java/com/hfkj/controller/CmsController.java b/bweb/src/main/java/com/hfkj/controller/CmsController.java index 62fbb29..588f847 100644 --- a/bweb/src/main/java/com/hfkj/controller/CmsController.java +++ b/bweb/src/main/java/com/hfkj/controller/CmsController.java @@ -64,6 +64,7 @@ public class CmsController { cmsContent = new CmsContent(); cmsContent.setStatus(CmsStatusEnum.status1.getStatus()); } + cmsContent.setName(body.getName()); cmsContent.setType(body.getType()); cmsContent.setImgUrl(body.getImgUrl()); cmsContent.setJumpType(body.getJumpType()); diff --git a/service/src/main/java/com/hfkj/service/user/BsUserGradeService.java b/service/src/main/java/com/hfkj/service/user/BsUserGradeService.java index 18296fe..04aa6d1 100644 --- a/service/src/main/java/com/hfkj/service/user/BsUserGradeService.java +++ b/service/src/main/java/com/hfkj/service/user/BsUserGradeService.java @@ -1,5 +1,7 @@ package com.hfkj.service.user; +import com.hfkj.sysenum.user.UserGradeEnum; + import java.util.Map; /** @@ -9,6 +11,13 @@ import java.util.Map; **/ public interface BsUserGradeService { + /** + * 等级调整 + * @param userId + * @param userGrade + */ + void gradeAdjust(Long userId, UserGradeEnum userGrade); + /** * 等级晋升 * @param userId diff --git a/service/src/main/java/com/hfkj/service/user/BsUserService.java b/service/src/main/java/com/hfkj/service/user/BsUserService.java index 66385fd..9e4881d 100644 --- a/service/src/main/java/com/hfkj/service/user/BsUserService.java +++ b/service/src/main/java/com/hfkj/service/user/BsUserService.java @@ -46,6 +46,18 @@ public interface BsUserService { */ void bindInviteUser(Long userId, Long inviteUseId) throws Exception; + /** + * 封号 + */ + void ban(Long userId) throws Exception; + + /** + * 恢复 + * @param userId + * @throws Exception + */ + void restore(Long userId) throws Exception; + /** * 注销账户 * @param userId diff --git a/service/src/main/java/com/hfkj/service/user/impl/BsUserGradeServiceImpl.java b/service/src/main/java/com/hfkj/service/user/impl/BsUserGradeServiceImpl.java index 8df4b3d..787a941 100644 --- a/service/src/main/java/com/hfkj/service/user/impl/BsUserGradeServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/user/impl/BsUserGradeServiceImpl.java @@ -34,6 +34,22 @@ public class BsUserGradeServiceImpl implements BsUserGradeService { private BsUserAccountRecordService userAccountRecordService; @Resource private BsUserParentRelService userParentRelService; + + @Override + @Transactional(propagation= Propagation.REQUIRED,rollbackFor= {RuntimeException.class}) + public void gradeAdjust(Long userId, UserGradeEnum userGrade) { + // 查询详情 + BsUser user = userService.getUser(userId); + if (user == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, ""); + } + user.setGrade(userGrade.getCode()); + userService.editData(user); + + // 修改上下级关系等级 + userParentRelService.updateParentGrade(user.getId(), userGrade); + } + @Override @Transactional(propagation= Propagation.REQUIRED,rollbackFor= {RuntimeException.class}) public void promote(Long userId) { diff --git a/service/src/main/java/com/hfkj/service/user/impl/BsUserServiceImpl.java b/service/src/main/java/com/hfkj/service/user/impl/BsUserServiceImpl.java index 7470fa4..0a708f5 100644 --- a/service/src/main/java/com/hfkj/service/user/impl/BsUserServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/user/impl/BsUserServiceImpl.java @@ -15,6 +15,7 @@ import com.hfkj.sysenum.user.UserAccountStatusEnum; import com.hfkj.sysenum.user.UserGradeEnum; import com.hfkj.sysenum.user.UserLoginType; import com.hfkj.sysenum.user.UserStatusEnum; +import org.apache.catalina.User; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -161,6 +162,37 @@ public class BsUserServiceImpl implements BsUserService { userCenter.save(sessionObject); } + @Override + public void ban(Long userId) throws Exception { + // 查询用户 + BsUser user = getUser(userId); + if (user == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到用户"); + } + if (!user.getStatus().equals(UserStatusEnum.status1.getCode())) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "状态不正确,无法封禁"); + } + user.setStatus(UserStatusEnum.status2.getCode()); + updateInfo(user); + + // 退出登录 + userCenter.remove(userToken(user.getId())); + } + + @Override + public void restore(Long userId) throws Exception { + // 查询用户 + BsUser user = getUser(userId); + if (user == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到用户"); + } + if (!user.getStatus().equals(UserStatusEnum.status1.getCode())) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "状态不正确,无法封禁"); + } + user.setStatus(UserStatusEnum.status1.getCode()); + updateInfo(user); + } + @Override @Transactional(propagation= Propagation.REQUIRES_NEW,rollbackFor= {RuntimeException.class}) public void delete(Long userId) throws Exception { @@ -221,8 +253,27 @@ public class BsUserServiceImpl implements BsUserService { @Override public List getList(Map param) { BsUserExample example = new BsUserExample(); - example.createCriteria().andStatusNotEqualTo(0); + BsUserExample.Criteria criteria = example.createCriteria().andStatusNotEqualTo(0); + + if (MapUtils.getLong(param, "id") != null) { + criteria.andIdEqualTo(MapUtils.getLong(param, "id")); + } + 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, "grade") != null) { + criteria.andGradeEqualTo(MapUtils.getInteger(param, "grade")); + } + + if (MapUtils.getInteger(param, "status") != null) { + criteria.andStatusEqualTo(MapUtils.getInteger(param, "status")); + } example.setOrderByClause("create_time desc"); return userMapper.selectByExample(example);