Sfoglia il codice sorgente

登录用户LoginUser 添加渠道、经销商属性

guanglong 3 anni fa
parent
commit
9761258ab2

+ 22 - 0
mp-common/src/main/java/com/qs/mp/common/enums/UserIdentityEnum.java

@@ -0,0 +1,22 @@
+package com.qs.mp.common.enums;
+
+/**
+ * 用户身份
+ *
+ * @author liugl
+ * @Date 2022/03/01
+ */
+public enum UserIdentityEnum {
+
+	CHANNEL, // 代理渠道
+	SALESITE // 经销商
+	;
+
+	public static UserIdentityEnum valueOf(int ordinal) {
+		if (ordinal < 0 || ordinal >= values().length) {
+			throw new IndexOutOfBoundsException("Invalid ordinal");
+		}
+		return values()[ordinal];
+	}
+
+}

+ 34 - 0
mp-framework/src/main/java/com/qs/mp/framework/web/service/SysLoginService.java

@@ -1,7 +1,10 @@
 package com.qs.mp.framework.web.service;
 
+import com.qs.mp.channel.domain.Channel;
+import com.qs.mp.channel.service.IChannelService;
 import com.qs.mp.common.constant.Constants;
 import com.qs.mp.common.core.redis.RedisCache;
+import com.qs.mp.common.enums.UserIdentityEnum;
 import com.qs.mp.common.exception.ServiceException;
 import com.qs.mp.common.exception.user.CaptchaException;
 import com.qs.mp.common.exception.user.CaptchaExpireException;
@@ -18,6 +21,7 @@ import com.qs.mp.sms.domain.SmsCode;
 import com.qs.mp.system.domain.SysUser;
 import com.qs.mp.system.service.ISysConfigService;
 import com.qs.mp.system.service.ISysUserService;
+
 import javax.annotation.Resource;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -53,6 +57,9 @@ public class SysLoginService
 
     @Autowired
     private ISysConfigService configService;
+    
+    @Autowired
+    private IChannelService channelService;
 
     /**
      * 登录验证
@@ -91,6 +98,9 @@ public class SysLoginService
         AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
         LoginUser loginUser = (LoginUser) authentication.getPrincipal();
         recordLoginInfo(loginUser.getUser());
+        
+        // loginUser.setIdentity(UserIdentityEnum.valueOf(identity));
+        fillChannelInfo(loginUser);
 /*
         // 根据用户身份,设置对应的属性
         loginUser.setIdentity(UserIdentityEnum.valueOf(identity));
@@ -143,6 +153,9 @@ public class SysLoginService
         AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
         LoginUser loginUser = (LoginUser) authentication.getPrincipal();
         recordLoginInfo(loginUser.getUser());
+        
+        // loginUser.setIdentity(UserIdentityEnum.valueOf(identity));
+        fillChannelInfo(loginUser);
 /*
         // 根据用户身份,设置对应的属性
         loginUser.setIdentity(UserIdentityEnum.valueOf(identity));
@@ -185,6 +198,8 @@ public class SysLoginService
         AsyncManager.me().execute(AsyncFactory.recordLogininfor(smsCode.getMobile(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
         LoginUser loginUser = (LoginUser) authentication.getPrincipal();
         recordLoginInfo(loginUser.getUser());
+        
+        fillChannelInfo(loginUser);
 /*
         // 根据用户身份,设置对应的属性
         loginUser.setIdentity(UserIdentityEnum.valueOf(smsCode.getIdentity()));
@@ -263,5 +278,24 @@ public class SysLoginService
         user.setLoginDate(DateUtils.getNowDate());
         userService.updateUserProfile(user);
     }
+    
+    /**
+     * 填充注入Channel 渠道/经销商  信息
+     * @param loginUser
+     */
+    public void fillChannelInfo(LoginUser loginUser){
+    	Channel channel = channelService.getChannelByUserId(loginUser.getUserId());
+        if (null != channel && null != channel.getId()){
+        	loginUser.setChannelId(channel.getId());
+        	loginUser.setChannelNo(channel.getChannelNo());
+        	if(null != channel.getLevel()) {
+        		loginUser.setIdentity(channel.getLevel().intValue() == 0?UserIdentityEnum.SALESITE:UserIdentityEnum.CHANNEL);
+        	}
+        } else if (loginUser.getUserId() != 1L){
+            throw new ServiceException("登录账号不存在");
+        }
+
+    }
+
 
 }

+ 9 - 0
mp-service/src/main/java/com/qs/mp/channel/service/IChannelService.java

@@ -12,5 +12,14 @@ import com.baomidou.mybatisplus.extension.service.IService;
  * @since 2022-02-28
  */
 public interface IChannelService extends IService<Channel> {
+	
+	
+
+    /**
+     * 登录的时候根据userid查询Channel信息
+     * @param userId
+     * @return
+     */
+    public Channel getChannelByUserId(long userId);
 
 }

+ 6 - 0
mp-service/src/main/java/com/qs/mp/channel/service/impl/ChannelServiceImpl.java

@@ -3,6 +3,7 @@ package com.qs.mp.channel.service.impl;
 import com.qs.mp.channel.domain.Channel;
 import com.qs.mp.channel.mapper.ChannelMapper;
 import com.qs.mp.channel.service.IChannelService;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.stereotype.Service;
 
@@ -17,4 +18,9 @@ import org.springframework.stereotype.Service;
 @Service
 public class ChannelServiceImpl extends ServiceImpl<ChannelMapper, Channel> implements IChannelService {
 
+	
+	@Override
+	public Channel getChannelByUserId(long userId) {
+		return getOne(new QueryWrapper<Channel>().lambda().eq(Channel::getUserId, userId));
+	}
 }

+ 41 - 0
mp-service/src/main/java/com/qs/mp/core/domain/LoginUser.java

@@ -1,7 +1,9 @@
 package com.qs.mp.core.domain;
 
 import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.qs.mp.common.enums.UserIdentityEnum;
 import com.qs.mp.system.domain.SysUser;
+
 import java.util.Collection;
 import java.util.Set;
 import org.springframework.security.core.GrantedAuthority;
@@ -70,6 +72,21 @@ public class LoginUser implements UserDetails
      * 用户信息
      */
     private SysUser user;
+    
+    /**
+     * 用户身份,CHANNEL(代理渠道),SALESITE(经销商)
+     */
+    private UserIdentityEnum identity;
+    
+    /**
+     * 渠道ID
+     */
+    private Long channelId;
+    
+    /**
+     * 渠道编码
+     */
+    private String channelNo;
 
     public Long getUserId()
     {
@@ -263,4 +280,28 @@ public class LoginUser implements UserDetails
     {
         return null;
     }
+
+	public UserIdentityEnum getIdentity() {
+		return identity;
+	}
+
+	public void setIdentity(UserIdentityEnum identity) {
+		this.identity = identity;
+	}
+
+	public Long getChannelId() {
+		return channelId;
+	}
+
+	public void setChannelId(Long channelId) {
+		this.channelId = channelId;
+	}
+
+	public String getChannelNo() {
+		return channelNo;
+	}
+
+	public void setChannelNo(String channelNo) {
+		this.channelNo = channelNo;
+	}
 }