1
This commit is contained in:
@@ -2,33 +2,30 @@ package org.springblade.modules.appFormal.controller;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.qiniu.util.Auth;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springblade.core.mp.support.Condition;
|
||||
import org.springblade.core.mp.support.Query;
|
||||
import org.springblade.core.redis.ratelimiter.RateLimiter;
|
||||
import org.springblade.core.secure.utils.AuthUtil;
|
||||
import org.springblade.core.tool.api.R;
|
||||
import org.springblade.modules.appFormal.manager.FormalAppCustomerManager;
|
||||
import org.springblade.modules.appFormal.request.AppUserNoticeRequest;
|
||||
import org.springblade.modules.appFormal.request.CustomerSmsRequest;
|
||||
import org.springblade.modules.appFormal.request.UpdatePasswordRequest;
|
||||
import org.springblade.modules.appFormal.vo.AppUserNoticeVO;
|
||||
import org.springblade.modules.appFormal.vo.MallIntegralLogVO;
|
||||
import org.springblade.modules.appFormal.vo.MallIntegralVO;
|
||||
import org.springblade.modules.appFormal.vo.UserInfoVO;
|
||||
import org.springblade.modules.desk.pojo.vo.NoticeVO;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@RequestMapping("formal-app/customer")
|
||||
@Tag(name = "用户信息", description = "用户信息接口")
|
||||
@Slf4j
|
||||
public class FormalCustomerController {
|
||||
|
||||
|
||||
@@ -97,10 +94,10 @@ public class FormalCustomerController {
|
||||
return R.data(formalAppCustomerManager.findUserNoticePage(Condition.getPage(query), userNotice, AuthUtil.getUserId()));
|
||||
}
|
||||
|
||||
@Operation(summary = "查询用户通知")
|
||||
@Operation(summary = "读取用户通知")
|
||||
@PostMapping("/read-user-notice")
|
||||
public R<Boolean> readUserNotice(AppUserNoticeVO userNotice) {
|
||||
return R.status(formalAppCustomerManager.readUserNotice(userNotice.getId()));
|
||||
public R<Boolean> readUserNotice(@RequestBody AppUserNoticeRequest request) {
|
||||
return R.status(formalAppCustomerManager.readUserNotice(request.getNoticeId()));
|
||||
}
|
||||
|
||||
@Operation(summary = "未读消息总数")
|
||||
|
||||
@@ -2,7 +2,6 @@ package org.springblade.modules.appFormal.controller;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -16,7 +15,6 @@ import org.springblade.modules.appFormal.request.AddressSubmitRequest;
|
||||
import org.springblade.modules.appFormal.request.MallCartRemoveRequest;
|
||||
import org.springblade.modules.appFormal.request.MallCartRequest;
|
||||
import org.springblade.modules.appFormal.vo.*;
|
||||
import org.springblade.modules.mall.pojo.vo.MallSpuVO;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -113,7 +113,6 @@ public class FormalAppCustomerManager {
|
||||
|
||||
public Boolean updatePasswordNonCode(UpdatePasswordRequest request) {
|
||||
Assert.notNull(request.getPhone() , "手机号不能为空");
|
||||
Assert.notNull(request.getCode() , "验证码不能为空");
|
||||
Assert.isTrue(PhoneUtil.isMobile(String.valueOf(request.getPhone())), "手机号格式不正确");
|
||||
Long phone = request.getPhone();
|
||||
User user = userService.getOne(
|
||||
@@ -149,18 +148,31 @@ public class FormalAppCustomerManager {
|
||||
|
||||
public Boolean deleteAccount(Long userId) {
|
||||
BladeUser user = AuthUtil.getUser();
|
||||
|
||||
|
||||
boolean update = userService.update(
|
||||
Wrappers.lambdaUpdate(User.class)
|
||||
.eq(User::getId, userId)
|
||||
.set(User::getIsDeleted, 1)
|
||||
);
|
||||
|
||||
if (!update) {
|
||||
throw new RuntimeException("注销失败");
|
||||
}
|
||||
|
||||
if (user != null && this.jwtProperties.getState()) {
|
||||
OAuth2Request request = OAuth2Request.create().buildHeaderArgs();
|
||||
String token = JwtUtil.getToken(request.getToken());
|
||||
JwtUtil.removeAccessToken(user.getTenantId(), user.getClientId(), String.valueOf(user.getUserId()), token);
|
||||
JwtUtil.removeRefreshToken(user.getTenantId(), user.getClientId(), String.valueOf(user.getUserId()), token);
|
||||
}
|
||||
if(userService.removeUser(String.valueOf(List.of(userId)))){
|
||||
publisher.publishEvent(
|
||||
new AppUserRevokedEvent()
|
||||
|
||||
|
||||
publisher.publishEvent(
|
||||
new AppUserRevokedEvent()
|
||||
.setUserId(userId)
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
@@ -215,9 +227,9 @@ public class FormalAppCustomerManager {
|
||||
return pageResult.convert(AppBaseConvert.INSTANCE::convertUserNoticePageToVO);
|
||||
}
|
||||
|
||||
public boolean readUserNotice(Long id) {
|
||||
public boolean readUserNotice(Long noticeId) {
|
||||
|
||||
UserNoticeEntity userNotice = userNoticeService.getById(id);
|
||||
UserNoticeEntity userNotice = userNoticeService.getById(noticeId);
|
||||
Assert.notNull(userNotice, "通知不存在");
|
||||
userNotice.setHasRead(1);
|
||||
userNotice.setReleaseTime(new Date());
|
||||
@@ -229,7 +241,6 @@ public class FormalAppCustomerManager {
|
||||
Wrappers.lambdaQuery(UserNoticeEntity.class)
|
||||
.eq(UserNoticeEntity::getUserId, userId)
|
||||
.eq(Objects.nonNull(userNotice.getNoticeType()), UserNoticeEntity::getNoticeType, userNotice.getNoticeType())
|
||||
.orderByDesc(UserNoticeEntity::getHasRead, UserNoticeEntity::getId)
|
||||
);
|
||||
return Math.toIntExact(count);
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.modules.appFormal.request;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 用户通知 实体类
|
||||
*
|
||||
* @author lzq
|
||||
* @since 2026-02-03
|
||||
*/
|
||||
@Data
|
||||
public class AppUserNoticeRequest implements Serializable {
|
||||
|
||||
|
||||
/**
|
||||
* 消息id
|
||||
*/
|
||||
private Long noticeId;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -29,6 +29,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
@@ -38,14 +39,13 @@ import java.util.Date;
|
||||
* @since 2026-02-03
|
||||
*/
|
||||
@Data
|
||||
public class AppUserNoticeVO {
|
||||
public class AppUserNoticeVO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
@Schema(description = "用户id")
|
||||
private Long id;
|
||||
|
||||
private Integer noticeType;
|
||||
|
||||
@@ -10,13 +10,11 @@ import org.springblade.core.mp.support.Query;
|
||||
import org.springblade.core.secure.utils.AuthUtil;
|
||||
import org.springblade.core.tool.api.R;
|
||||
import org.springblade.modules.appFormal.manager.FormalAppCustomerManager;
|
||||
import org.springblade.modules.appFormal.request.AppUserNoticeRequest;
|
||||
import org.springblade.modules.appFormal.vo.AppUserNoticeVO;
|
||||
import org.springblade.modules.appOffline.manager.OfflineAppCustomerManager;
|
||||
import org.springblade.modules.appOffline.vo.*;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -50,10 +48,10 @@ public class OfflineCustomerController {
|
||||
return R.data(formalAppCustomerManager.findUserNoticePage(Condition.getPage(query), userNotice, AuthUtil.getUserId()));
|
||||
}
|
||||
|
||||
@Operation(summary = "查询用户通知")
|
||||
@GetMapping("/read-user-notice")
|
||||
public R<Boolean> readUserNotice(AppUserNoticeVO userNotice) {
|
||||
return R.status(formalAppCustomerManager.readUserNotice(userNotice.getId()));
|
||||
@Operation(summary = "读取用户通知")
|
||||
@PostMapping("/read-user-notice")
|
||||
public R<Boolean> readUserNotice(@RequestBody AppUserNoticeRequest request) {
|
||||
return R.status(formalAppCustomerManager.readUserNotice(request.getNoticeId()));
|
||||
}
|
||||
|
||||
@Operation(summary = "未读消息总数")
|
||||
|
||||
@@ -32,6 +32,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springblade.common.cache.ParamCache;
|
||||
import org.springblade.core.launch.constant.TokenConstant;
|
||||
import org.springblade.core.oauth2.exception.ExceptionCode;
|
||||
import org.springblade.core.oauth2.exception.UserInvalidException;
|
||||
import org.springblade.core.oauth2.granter.AbstractTokenGranter;
|
||||
@@ -44,8 +45,6 @@ import org.springblade.core.oauth2.service.OAuth2ClientService;
|
||||
import org.springblade.core.oauth2.service.OAuth2User;
|
||||
import org.springblade.core.oauth2.service.OAuth2UserService;
|
||||
import org.springblade.core.oauth2.service.impl.OAuth2UserDetail;
|
||||
import org.springblade.core.oauth2.utils.OAuth2Util;
|
||||
import org.springblade.core.secure.TokenInfo;
|
||||
import org.springblade.core.social.props.SocialProperties;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
import org.springblade.core.tool.utils.SM2Util;
|
||||
@@ -117,7 +116,7 @@ public class RegisterTokenGranter extends AbstractTokenGranter {
|
||||
String code = request.getCode();
|
||||
String password = "";
|
||||
if (code != null){
|
||||
aliYunSmsService.verifySms(request.getPhone(), code);
|
||||
// aliYunSmsService.verifySms(request.getPhone(), code);
|
||||
// 截取手机号后六位
|
||||
password = createDefaultPassword(request.getPhone());
|
||||
}else {
|
||||
@@ -190,11 +189,14 @@ public class RegisterTokenGranter extends AbstractTokenGranter {
|
||||
|
||||
@Override
|
||||
public OAuth2Token token(OAuth2User user, OAuth2Request request) {
|
||||
TokenInfo accessToken = OAuth2Util.createAccessToken(user);
|
||||
TokenInfo refreshToken = OAuth2Util.createRefreshToken(user);
|
||||
OAuth2Token token = OAuth2Token.create();
|
||||
token.getArgs().set("tenant_id", user.getTenantId()).set("user_id", user.getUserId()).set("dept_id", user.getDeptId()).set("post_id", user.getPostId()).set("role_id", user.getRoleId()).set("oauth_id", user.getOauthId()).set("account", user.getAccount()).set("user_name", user.getAccount()).set("nick_name", user.getName()).set("real_name", user.getRealName()).set("role_name", Func.join(user.getAuthorities())).set("avatar", Func.toStr(user.getAvatar(), "https://bladex.cn/images/logo-small.png")).set("access_token", accessToken.getToken()).set("refresh_token", refreshToken.getToken()).set("token_type", "bearer").set("expires_in", accessToken.getExpire()).set("detail", user.getDetail()).set("license", "powered by bladex");
|
||||
return token.setAccessToken(accessToken.getToken()).setAccessTokenExpire(accessToken.getExpire()).setRefreshToken(refreshToken.getToken()).setRefreshTokenExpire(refreshToken.getExpire());
|
||||
// 移除注册后返回的令牌与刷新令牌,防止外部攻击采用注册接口获取令牌并调用低权接口
|
||||
// 注意:
|
||||
// 1. 框架已默认开启严格模式,blade.secure.strict-token=true,不移除令牌则不受影响,注册令牌会被框架校验并拒绝
|
||||
// 2. 若自行关闭严格模式,blade.secure.strict-token=false,必须将令牌移除,否则注册获取令牌后可调用低权接口
|
||||
OAuth2Token token = super.token(user, request);
|
||||
token.getArgs().remove(TokenConstant.ACCESS_TOKEN);
|
||||
token.getArgs().remove(TokenConstant.REFRESH_TOKEN);
|
||||
return token;
|
||||
}
|
||||
|
||||
private void validateUser(User user) {
|
||||
|
||||
Reference in New Issue
Block a user