账号鉴权 bug fix
This commit is contained in:
parent
894739bb1d
commit
5469e9d708
@ -209,6 +209,7 @@ public interface AccountUserBaseService extends IBaseService<AccountUserBase> {
|
||||
|
||||
/**
|
||||
* 根据 userAccount 也就是手机号判断是否存在会员
|
||||
*
|
||||
* @param userAccount
|
||||
* @param storeId
|
||||
* @return
|
||||
@ -240,20 +241,23 @@ public interface AccountUserBaseService extends IBaseService<AccountUserBase> {
|
||||
|
||||
/**
|
||||
* 根据手机号和商户查询map,用于批量匹配
|
||||
*
|
||||
* @param moblies 就是账号集合
|
||||
* @return
|
||||
*/
|
||||
Map<String,Integer> getAccountBaseMapByMobile(List<String> moblies);
|
||||
Map<String, Integer> getAccountBaseMapByMobile(List<String> moblies);
|
||||
|
||||
/**
|
||||
* 找出accountbase的最大id
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Integer getAccountMaxId();
|
||||
Integer getAccountMaxId();
|
||||
|
||||
|
||||
/**
|
||||
* 批量保存accountBase
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
ThirdApiRes saveBatchAccountBase(List<AccountUserBase> accountUserBaseList);
|
||||
@ -261,6 +265,7 @@ public interface AccountUserBaseService extends IBaseService<AccountUserBase> {
|
||||
|
||||
/**
|
||||
* 批量保存accountInfo
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
ThirdApiRes saveBatchAccountInfo(List<AccountUserInfo> accountUserInfoList);
|
||||
|
||||
@ -62,6 +62,7 @@ import com.suisung.mall.core.web.service.RedisService;
|
||||
import com.suisung.mall.core.web.service.impl.BaseServiceImpl;
|
||||
import io.seata.common.util.StringUtils;
|
||||
import io.seata.spring.annotation.GlobalTransactional;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -91,6 +92,7 @@ import static com.suisung.mall.common.utils.I18nUtil._;
|
||||
* @author Xinze
|
||||
* @since 2021-03-30
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class AccountUserBaseServiceImpl extends BaseServiceImpl<AccountUserBaseMapper, AccountUserBase> implements AccountUserBaseService {
|
||||
|
||||
@ -324,7 +326,17 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl<AccountUserBaseM
|
||||
userDTO.setUser_state(accountUserBase.getUser_state());
|
||||
userDTO.setUser_salt(accountUserBase.getUser_salt());
|
||||
|
||||
// //角色编号: 0-用户;2-商家;3-门店;9-平台;
|
||||
// if (user_is_admin.contains(CommonConstant.USER_TYPE_MCH)) {
|
||||
// userDTO.setRole_id(RoleIdEnum.STORE.getState());
|
||||
// } else if (user_is_admin.contains(CommonConstant.USER_TYPE_ADMIN)) {
|
||||
// userDTO.setRole_id(RoleIdEnum.PLATFORM.getState());
|
||||
// }
|
||||
|
||||
|
||||
// 设置用户角色
|
||||
setIdentityByUser(userDTO, accountUserBase);
|
||||
|
||||
userDTO.setUser_nickname(accountUserBase.getUser_nickname());
|
||||
List<AdminRightsGroup> roles = null;
|
||||
List<String> roleNames = new ArrayList<>();
|
||||
@ -368,8 +380,9 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl<AccountUserBaseM
|
||||
setIdentity(RoleIdEnum.PLATFORM.getState(), null, null, userDTO);
|
||||
return;
|
||||
}
|
||||
|
||||
String store_ids = user.getStore_ids();
|
||||
if (StrUtil.isNotBlank(store_ids)) {
|
||||
if (StrUtil.isNotBlank(store_ids) || ObjectUtil.equal(user_is_admin, CommonConstant.USER_TYPE_MCH)) {
|
||||
setIdentity(RoleIdEnum.STORE.getState(), user.getStore_ids(), null, userDTO);
|
||||
return;
|
||||
}
|
||||
@ -397,7 +410,7 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl<AccountUserBaseM
|
||||
return;
|
||||
}
|
||||
String store_ids = user.getStore_ids();
|
||||
if (StrUtil.isNotBlank(store_ids)) {
|
||||
if (StrUtil.isNotBlank(store_ids) || ObjectUtil.equal(user_is_admin, CommonConstant.USER_TYPE_MCH)) {
|
||||
user.setRid(RoleIdEnum.STORE.getState());
|
||||
}
|
||||
}
|
||||
@ -411,6 +424,9 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl<AccountUserBaseM
|
||||
* @param userDTO
|
||||
*/
|
||||
private void setIdentity(Integer role_id, String store_id, String chain_id, UserDto userDTO) {
|
||||
if (userDTO == null) {
|
||||
return;
|
||||
}
|
||||
userDTO.setRole_id(role_id);
|
||||
userDTO.setStore_id(store_id);
|
||||
userDTO.setChain_id(chain_id);
|
||||
@ -1635,7 +1651,7 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl<AccountUserBaseM
|
||||
*
|
||||
* @return array 用户登录数据
|
||||
*/
|
||||
// @GlobalTransactional
|
||||
// @GlobalTransactional
|
||||
@Override
|
||||
public AccountUserBase register(Map userInfo) {
|
||||
|
||||
@ -3415,6 +3431,7 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl<AccountUserBaseM
|
||||
|
||||
/**
|
||||
* 判断店铺某个手机是否存在
|
||||
*
|
||||
* @param storeId
|
||||
* @return
|
||||
*/
|
||||
@ -3566,54 +3583,55 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl<AccountUserBaseM
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String,Integer> getAccountBaseMapByMobile(List<String> moblies) {
|
||||
QueryWrapper<AccountUserBase> queryWrapper=new QueryWrapper<>();
|
||||
public Map<String, Integer> getAccountBaseMapByMobile(List<String> moblies) {
|
||||
QueryWrapper<AccountUserBase> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.select("user_id", "user_account");
|
||||
moblies.forEach(moblie -> {
|
||||
queryWrapper.or(q -> q.eq("user_account", moblie));
|
||||
});
|
||||
List<AccountUserBase> userBaseList= this.list(queryWrapper);
|
||||
List<AccountUserBase> userBaseList = this.list(queryWrapper);
|
||||
return userBaseList.stream().collect(Collectors.toMap(AccountUserBase::getUser_account, AccountUserBase::getUser_id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getAccountMaxId() {
|
||||
QueryWrapper<AccountUserBase> queryWrapper=new QueryWrapper<>();
|
||||
QueryWrapper<AccountUserBase> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.select("max(user_id) as user_id");
|
||||
AccountUserBase accountUserBase=this.getOne(queryWrapper);
|
||||
AccountUserBase accountUserBase = this.getOne(queryWrapper);
|
||||
return accountUserBase.getUser_id();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ThirdApiRes saveBatchAccountBase(List<AccountUserBase> accountUserBaseList) {
|
||||
boolean result=false;
|
||||
if(!accountUserBaseList.isEmpty()){
|
||||
boolean result = false;
|
||||
if (!accountUserBaseList.isEmpty()) {
|
||||
try {
|
||||
result= saveBatch(accountUserBaseList,accountUserBaseList.size());
|
||||
}catch (RuntimeException e){
|
||||
throw new ApiException("保存saveBatchAccountBase报错:"+e.getMessage());
|
||||
result = saveBatch(accountUserBaseList, accountUserBaseList.size());
|
||||
} catch (RuntimeException e) {
|
||||
throw new ApiException("保存saveBatchAccountBase报错:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
if(result){
|
||||
if (result) {
|
||||
return new ThirdApiRes().success("成功");
|
||||
}
|
||||
return new ThirdApiRes().fail(250,"保存异常");
|
||||
return new ThirdApiRes().fail(250, "保存异常");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ThirdApiRes saveBatchAccountInfo(List<AccountUserInfo> accountUserInfoList){
|
||||
boolean result=false;
|
||||
if(!accountUserInfoList.isEmpty()){
|
||||
public ThirdApiRes saveBatchAccountInfo(List<AccountUserInfo> accountUserInfoList) {
|
||||
boolean result = false;
|
||||
if (!accountUserInfoList.isEmpty()) {
|
||||
try {
|
||||
result= accountUserInfoService.saveBatch(accountUserInfoList,accountUserInfoList.size());
|
||||
}catch (Exception e){
|
||||
throw new RuntimeException("保存AccountUserInfo报错:"+e.getMessage());
|
||||
result = accountUserInfoService.saveBatch(accountUserInfoList, accountUserInfoList.size());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("保存AccountUserInfo报错:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
if(result){
|
||||
if (result) {
|
||||
return new ThirdApiRes().success("成功");
|
||||
}
|
||||
return new ThirdApiRes().fail(250,"保存异常");
|
||||
return new ThirdApiRes().fail(250, "保存异常");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -105,8 +105,7 @@ public class AdminBaseProtocolServiceImpl extends BaseServiceImpl<AdminBaseProto
|
||||
redisService.del(AuthConstant.RESOURCE_ROLES_MAP_KEY);
|
||||
redisService.hSetAll(AuthConstant.RESOURCE_ROLES_MAP_KEY, resourceRoleMap);
|
||||
return resourceRoleMap;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -8,6 +8,7 @@ import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -16,7 +17,7 @@ import java.util.List;
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@NoArgsConstructor
|
||||
public class UserDto {
|
||||
public class UserDto implements Serializable {
|
||||
private Integer id;
|
||||
private String user_account;
|
||||
private String user_password;
|
||||
@ -50,7 +51,7 @@ public class UserDto {
|
||||
* @return
|
||||
*/
|
||||
public boolean isStore() {
|
||||
return StrUtil.isNotBlank(this.store_id)&&!"0".equals(this.store_id);
|
||||
return StrUtil.isNotBlank(this.store_id) && !"0".equals(this.store_id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -40,13 +40,8 @@ public class ContextUtil {
|
||||
public static UserDto getCurrentUser() {
|
||||
try {
|
||||
UserDto loginUser = staticUserInfoService.getUser();
|
||||
// log.info("##### 当前登录用户:{}###", JsonUtil.object2json(loginUser));
|
||||
return loginUser;//todo 测试去除
|
||||
// UserDto user= new UserDto();
|
||||
//user.setStore_id("1");
|
||||
//user.setRole_id(9);
|
||||
//user.setUser_account("18260885688");
|
||||
//return user;
|
||||
log.info("##### 当前登录用户:{}###", JsonUtil.object2json(loginUser));
|
||||
return loginUser;
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
|
||||
@ -110,7 +110,7 @@ public class ProductTitleUtil {
|
||||
int score = calculateWeightedScore(fields1, fields2);
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("相似度计算耗时:{}ns", System.nanoTime() - startTime);
|
||||
log.debug("相似度计算耗时:{}ms", (System.nanoTime() - startTime) / 1000);
|
||||
}
|
||||
return score;
|
||||
} catch (Exception e) {
|
||||
@ -273,11 +273,11 @@ public class ProductTitleUtil {
|
||||
String title7 = "iPhone 苹果13 128G 智能手机 白色 新品";
|
||||
String title8 = "苹果13 128G 手机 黑色 特惠";
|
||||
|
||||
System.out.println("标题1与标题2相似度:" + calculateSimilarity(title1, title2)); // 约100.0
|
||||
System.out.println("标题1与标题3相似度:" + calculateSimilarity(title1, title3)); // 约30.0
|
||||
System.out.println("标题1与标题4相似度:" + calculateSimilarity(title1, title4)); // 约100.0
|
||||
System.out.println("标题5与标题6相似度:" + calculateSimilarity(title5, title6)); // 输出约90
|
||||
System.out.println("标题7与标题8相似度:" + calculateSimilarity(title7, title8)); // 输出约45
|
||||
System.out.println("标题1与标题2相似度:" + calculateSimilarity(title1, title2) + "%"); // 约100.0
|
||||
System.out.println("标题1与标题3相似度:" + calculateSimilarity(title1, title3) + "%"); // 约30.0
|
||||
System.out.println("标题1与标题4相似度:" + calculateSimilarity(title1, title4) + "%"); // 约100.0
|
||||
System.out.println("标题5与标题6相似度:" + calculateSimilarity(title5, title6) + "%"); // 输出约90
|
||||
System.out.println("标题7与标题8相似度:" + calculateSimilarity(title7, title8) + "%"); // 输出约45
|
||||
|
||||
|
||||
String[] testTitles = {
|
||||
|
||||
@ -6,13 +6,12 @@ import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.nimbusds.jose.JWSObject;
|
||||
import com.suisung.mall.common.constant.AuthConstant;
|
||||
import com.suisung.mall.common.constant.ConfigConstant;
|
||||
import com.suisung.mall.common.domain.RoleIdEnum;
|
||||
import com.suisung.mall.common.domain.TokenDto;
|
||||
import com.suisung.mall.common.domain.UserDto;
|
||||
import com.suisung.mall.common.exception.ApiException;
|
||||
import com.suisung.mall.core.web.service.RedisService;
|
||||
import com.suisung.mall.config.IgnoreUrlsConfig;
|
||||
import com.suisung.mall.config.UniversalUrlsConfig;
|
||||
import com.suisung.mall.core.web.service.RedisService;
|
||||
import lombok.SneakyThrows;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -38,13 +37,12 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.suisung.mall.common.utils.I18nUtil._;
|
||||
|
||||
/**
|
||||
* 鉴权管理器,用于判断是否有资源的访问权限
|
||||
*/
|
||||
@Component
|
||||
public class AuthorizationManager implements ReactiveAuthorizationManager<AuthorizationContext> {
|
||||
private final Logger logger = LoggerFactory.getLogger(AuthorizationManager.class);
|
||||
@Autowired
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
@Autowired
|
||||
@ -54,8 +52,6 @@ public class AuthorizationManager implements ReactiveAuthorizationManager<Author
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(AuthorizationManager.class);
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public Mono<AuthorizationDecision> check(Mono<Authentication> mono, AuthorizationContext authorizationContext) {
|
||||
@ -131,7 +127,9 @@ public class AuthorizationManager implements ReactiveAuthorizationManager<Author
|
||||
JWSObject jwsObject = JWSObject.parse(realToken);
|
||||
String userStr = jwsObject.getPayload().toString();
|
||||
UserDto userDto = JSONUtil.toBean(userStr, UserDto.class);
|
||||
if (userDto.getRole_id() != null && (userDto.getRole_id() == 3 || userDto.getRole_id() == 2)) {
|
||||
|
||||
// logger.info("路由器认证用户数据:{}", userDto);
|
||||
if (userDto.getRole_id() != null && (userDto.getRole_id() == RoleIdEnum.STORE.getState() || userDto.getRole_id() == RoleIdEnum.CHAIN.getState())) {
|
||||
return Mono.just(new AuthorizationDecision(true));
|
||||
}
|
||||
|
||||
@ -163,6 +161,8 @@ public class AuthorizationManager implements ReactiveAuthorizationManager<Author
|
||||
}
|
||||
}
|
||||
authorities = authorities.stream().map(i -> i = AuthConstant.AUTHORITY_PREFIX + i).collect(Collectors.toList());
|
||||
|
||||
// logger.info("路由器认证用户权限:{}", authorities);
|
||||
//认证通过且角色匹配的用户可访问当前路径
|
||||
return mono
|
||||
.filter(Authentication::isAuthenticated)
|
||||
|
||||
@ -201,6 +201,16 @@ public class ShopOrderReturnController extends BaseControllerImpl {
|
||||
|
||||
// 商家App 相关接口
|
||||
|
||||
/**
|
||||
* 商家处理退货退款,支持全单或部分商品退货
|
||||
*
|
||||
* @param params JSON格式请求参数,包含:
|
||||
* - order_id: 订单ID (必填)
|
||||
* - order_return_vo: 退货商品信息 (可选,用于部分商品退货)
|
||||
* - reason: 退货理由说明 (可选)
|
||||
* {"order_id":"DD-20250701-1","reason":"商家协商退款","order_return_vo":{"order_id":"DD-20250701-1","return_items":[{"order_item_id":1,"return_item_num":1,"return_refund_amount":"0.01"}]}}
|
||||
* @return CommonResult 处理结果
|
||||
*/
|
||||
@ApiOperation(value = "商家退货退款", notes = "商家退货退款,支持整单或个别商品退货")
|
||||
@RequestMapping(value = "/mch/order/doRefund", method = RequestMethod.POST)
|
||||
public CommonResult doRefundForMch(@RequestBody JSONObject params) {
|
||||
|
||||
@ -200,4 +200,15 @@ public interface ShopStoreBaseService extends IBaseService<ShopStoreBase> {
|
||||
*/
|
||||
Boolean updateStoreBizState(Integer storeId, Integer bizState);
|
||||
|
||||
|
||||
/**
|
||||
* 追加店铺Id到商户 store_ids 字段,不保存
|
||||
*
|
||||
* @param userId
|
||||
* @param storeId
|
||||
* @return
|
||||
*/
|
||||
String appendStoreIdToAccount(Integer userId, Integer storeId);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -67,6 +67,7 @@ import com.suisung.mall.shop.store.service.*;
|
||||
import com.suisung.mall.shop.user.service.ShopUserFavoritesStoreService;
|
||||
import com.suisung.mall.shop.wechat.service.WxQrCodeService;
|
||||
import io.seata.spring.annotation.GlobalTransactional;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -100,6 +101,7 @@ import static com.suisung.mall.common.utils.ContextUtil.getCurrentUser;
|
||||
* @author Xinze
|
||||
* @since 2021-04-23
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class ShopStoreBaseServiceImpl extends BaseServiceImpl<ShopStoreBaseMapper, ShopStoreBase> implements ShopStoreBaseService {
|
||||
|
||||
@ -3407,7 +3409,9 @@ public class ShopStoreBaseServiceImpl extends BaseServiceImpl<ShopStoreBaseMappe
|
||||
// 添加店铺到用户
|
||||
AccountUserBase accountUserBase = new AccountUserBase();
|
||||
accountUserBase.setUser_id(userId);
|
||||
accountUserBase.setStore_ids(String.valueOf(storeId));
|
||||
String storeIds = appendStoreIdToAccount(userId, storeId);
|
||||
accountUserBase.setStore_ids(storeIds);
|
||||
|
||||
|
||||
// todo 初始化商家角色(默认 店铺管理员角色)
|
||||
String user_rights_group_id = Convert.toStr(rights_group_id.get(0));
|
||||
@ -3801,4 +3805,45 @@ public class ShopStoreBaseServiceImpl extends BaseServiceImpl<ShopStoreBaseMappe
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 追加店铺ID到用户的店铺ID列表(仅返回处理后的字符串,不保存)
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param storeId 要追加的店铺ID
|
||||
* @return 追加后的店铺ID字符串(格式:id1,id2,)或空字符串(参数无效/用户不存在)
|
||||
* @throws IllegalArgumentException 当参数无效时抛出
|
||||
*/
|
||||
@Override
|
||||
public String appendStoreIdToAccount(Integer userId, Integer storeId) {
|
||||
// 参数校验
|
||||
if (ObjectUtil.isNull(userId) || ObjectUtil.isNull(storeId)) {
|
||||
log.error("用户ID和店铺ID不能为空,userId: {}, storeId: {}", userId, storeId);
|
||||
return "";
|
||||
}
|
||||
|
||||
try {
|
||||
// 查询用户现有的店铺ID列表
|
||||
AccountUserBase accountUserBase = accountService.getUserBase(userId);
|
||||
|
||||
// 用户不存在或没有店铺时返回空
|
||||
if (accountUserBase == null || StrUtil.isBlank(accountUserBase.getStore_ids())) {
|
||||
return "";
|
||||
}
|
||||
|
||||
// 标准化格式:确保末尾有逗号
|
||||
String storeIds = accountUserBase.getStore_ids();
|
||||
if (!storeIds.endsWith(",")) {
|
||||
storeIds += ",";
|
||||
}
|
||||
|
||||
// 追加新店铺ID
|
||||
return storeIds + storeId;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("追加店铺ID到用户失败,userId: {}, storeId: {}", userId, storeId, e);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user