浏览代码

Merge remote-tracking branch 'origin/master'

jiakai 4 月之前
父节点
当前提交
72200f9e4d

+ 34 - 25
authentication/src/main/java/com/jzg/config/JzgAuthenticationProvider.java

@@ -1,5 +1,6 @@
 package com.jzg.config;
 
+import cn.hutool.json.JSONUtil;
 import com.alipay.api.AlipayApiException;
 import com.alipay.api.AlipayClient;
 import com.alipay.api.AlipayConfig;
@@ -17,10 +18,7 @@ import com.jzg.entity.SysRolePerms;
 import com.jzg.entity.SysUser;
 import com.jzg.entity.vo.SysUserJzgVo;
 import com.jzg.commons.exception.SystemException;
-import com.jzg.mapper.SysAreaMapper;
-import com.jzg.mapper.SysRoleDataScopeLinkMapper;
-import com.jzg.mapper.SysRoleDataScopeMapper;
-import com.jzg.mapper.SysUserJzgAppMapper;
+import com.jzg.mapper.*;
 import com.jzg.service.SysSystemService;
 import com.jzg.service.SysUserRoleService;
 import com.jzg.service.SysUserService;
@@ -66,6 +64,8 @@ public class JzgAuthenticationProvider implements AuthenticationProvider {
 
     private SysUserJzgAppMapper sysUserJzgAppMapper;
 
+    private SysUserJzgInfoMapper sysUserJzgInfoMapper;
+
     private Map<String, WxMpService> wxMpService;
 
     @Autowired
@@ -73,7 +73,7 @@ public class JzgAuthenticationProvider implements AuthenticationProvider {
 
     public JzgAuthenticationProvider(UserDetailsService userDetailsService, SysUserService sysUserService, SysUserRoleService sysUserRoleService,
                                      RedissonClient redissonClient, SysRoleDataScopeMapper sysRoleDataScopeMapper, SysRoleDataScopeLinkMapper sysRoleDataScopeLinkMapper,
-                                     SysSystemService sysSystemService, SysUserJzgAppMapper sysUserJzgAppMapper,Map<String, WxMpService> wxMpService) {
+                                     SysSystemService sysSystemService, SysUserJzgAppMapper sysUserJzgAppMapper,Map<String, WxMpService> wxMpService, SysUserJzgInfoMapper sysUserJzgInfoMapper) {
         this.userDetailsService = userDetailsService;
         this.sysUserService = sysUserService;
         this.sysUserRoleService = sysUserRoleService;
@@ -83,6 +83,7 @@ public class JzgAuthenticationProvider implements AuthenticationProvider {
         this.sysSystemService = sysSystemService;
         this.sysUserJzgAppMapper = sysUserJzgAppMapper;
         this.wxMpService = wxMpService;
+        this.sysUserJzgInfoMapper = sysUserJzgInfoMapper;
     }
 
 
@@ -113,17 +114,25 @@ public class JzgAuthenticationProvider implements AuthenticationProvider {
                 throw new SystemException("验证码错误,请重新输入");
             }
         }
-        SysUser byId = new SysUser();
+        SysUser weblogUser = new SysUser();
         String salt = null;
         if(StringUtils.isNotBlank(username)){
-            byId = sysUserService.getByUserName(username);
-            if(Objects.isNull(byId)){
+            weblogUser = sysUserService.getByUserName(username);
+            if(Objects.isNull(weblogUser)){
                 throw new SystemException("用户名不存在");
             }
-            salt = byId.getSalt();
+            SysUserJzgInfo sysUserJzgInfo = sysUserJzgInfoMapper.queryJzgInfoByUserId(weblogUser.getId());
+            if(sysUserJzgInfo == null){
+                log.info("登录异常:用户不存在。 userId=[{}]",weblogUser.getId());
+                throw new SystemException("业务员不存在");
+            }
+            if (!sysUserJzgInfo.canLogin()) {
+                log.info("用户被禁用,不能登录。sysUserJzgInfo=[{}]", JSONUtil.toJsonStr(sysUserJzgInfo));
+                throw new SystemException("用户已被禁用,无法登录");
+            }
+            salt = weblogUser.getSalt();
         }
 
-
         //检验短信验证码
         if(Objects.nonNull(code)){
             String systemSmsCode = redissonClient.getBucket(RedisKeyConstants.SMS_CODE + username).get().toString();
@@ -138,7 +147,7 @@ public class JzgAuthenticationProvider implements AuthenticationProvider {
             //调试时候用 万能密码
             if(!rawPassword.equals("Aa159357")) {
                 // 对比密码
-                if (!encryptedPassword.equals(byId.getPassword())) {
+                if (!encryptedPassword.equals(weblogUser.getPassword())) {
                     throw new SystemException("用户名或密码错误");
                 }
             }
@@ -176,12 +185,12 @@ public class JzgAuthenticationProvider implements AuthenticationProvider {
             }
             if(StringUtils.isNotBlank(username)){  // 未绑定手机登录
                 SysUserJzgApp jzgUserApp = sysUserJzgAppMapper.selectOne(new LambdaQueryWrapper<SysUserJzgApp>()
-                        .eq(SysUserJzgApp::getUserId, byId.getId())
+                        .eq(SysUserJzgApp::getUserId, weblogUser.getId())
                         .eq(SysUserJzgApp::getIsDelete,0));
                 // 如果用户存在,app信息为空,则创建app信息
                 if(Objects.isNull(jzgUserApp)){
                     jzgUserApp = new SysUserJzgApp();
-                    jzgUserApp.setUserId(byId.getId());
+                    jzgUserApp.setUserId(weblogUser.getId());
                     jzgUserApp.setSystemCode("APP");
                     if(type.equals(0)){
                         jzgUserApp.setOpenId(openId);
@@ -211,8 +220,8 @@ public class JzgAuthenticationProvider implements AuthenticationProvider {
                 if(StringUtils.isNull(sysSystem)){
                     throw new SystemException("该租户已经禁用或者删除,请联系运营平台!");
                 }
-                byId = sysUserService.getById(userJzgApp.getUserId());
-                if(Objects.isNull(byId)){
+                weblogUser = sysUserService.getById(userJzgApp.getUserId());
+                if(Objects.isNull(weblogUser)){
                     throw new SystemException("用户名不存在");
                 }
             }
@@ -225,12 +234,12 @@ public class JzgAuthenticationProvider implements AuthenticationProvider {
 
             if(system.equals(SystemConstants.SYSTEM_JZG_APP.getCode())){
                 SysUserJzgApp jzgUserApp = sysUserJzgAppMapper.selectOne(new LambdaQueryWrapper<SysUserJzgApp>()
-                        .eq(SysUserJzgApp::getUserId, byId.getId())
+                        .eq(SysUserJzgApp::getUserId, weblogUser.getId())
                         .eq(SysUserJzgApp::getIsDelete,0));
                 // 如果用户存在,app信息为空,则创建app信息
                 if(Objects.isNull(jzgUserApp)){
                     jzgUserApp = new SysUserJzgApp();
-                    jzgUserApp.setUserId(byId.getId());
+                    jzgUserApp.setUserId(weblogUser.getId());
                     jzgUserApp.setSystemCode("APP");
                     sysUserJzgAppMapper.insert(jzgUserApp);
                 }
@@ -241,17 +250,17 @@ public class JzgAuthenticationProvider implements AuthenticationProvider {
                 jzgUserApp.setLastLoginTime(LocalDateTime.now());
                 sysUserJzgAppMapper.updateById(jzgUserApp);
             }else if(!system.equals(SystemConstants.SYSTEM_PLATFORM.getCode())){
-                SysUserJzgVo jzgUserInfo = sysUserService.getJzgUserInfo(byId.getId(),system);
+                SysUserJzgVo jzgUserInfo = sysUserService.getJzgUserInfo(weblogUser.getId(),system);
                 name = jzgUserInfo.getName();
                 workNumber = jzgUserInfo.getWorkNumber();
                 province = jzgUserInfo.getProvince();
             }else{
-                name = byId.getUsername();
+                name = weblogUser.getUsername();
             }
         }
 
         //获取用户角色权限标识
-        List<SysRolePerms> userPerms = sysUserRoleService.getUserPerms(byId.getId(), system);
+        List<SysRolePerms> userPerms = sysUserRoleService.getUserPerms(weblogUser.getId(), system);
 
         List<JzgGrantedAuthority> authorities = userPerms.stream()
                 .map(perms -> new JzgGrantedAuthority(perms.getSysCode(),perms.getPermsId(),perms.getPerms()))
@@ -264,17 +273,17 @@ public class JzgAuthenticationProvider implements AuthenticationProvider {
         SysUserJzgVo jzgUserInfo = new SysUserJzgVo();
         //获取用户头像
         if(SystemConstants.SYSTEM_JZG_APP.getCode().equals(system)){
-            SysUser user = sysUserService.getById(byId.getId());
+            SysUser user = sysUserService.getById(weblogUser.getId());
             if(!Objects.isNull(user.getHeadSculpture()) && !user.getHeadSculpture().isEmpty()) {
                 jzgUserInfo.setHeadSculpture(MinioUtils.getPresignedObjectUrl("jzg", user.getHeadSculpture()));
             }
         }else if(SystemConstants.SYSTEM_PLATFORM.getCode().equals(system)){
-            SysUser user = sysUserService.getById(byId.getId());
+            SysUser user = sysUserService.getById(weblogUser.getId());
             if(!Objects.isNull(user.getHeadSculpture()) && !user.getHeadSculpture().isEmpty()) {
                 jzgUserInfo.setHeadSculpture(MinioUtils.getPresignedObjectUrl("jzg", user.getHeadSculpture()));
             }
         }else{
-            jzgUserInfo = sysUserService.getJzgUserInfo(byId.getId(),system);
+            jzgUserInfo = sysUserService.getJzgUserInfo(weblogUser.getId(),system);
             if(!Objects.isNull(jzgUserInfo.getHeadSculpture()) && !jzgUserInfo.getHeadSculpture().isEmpty()) {
                 jzgUserInfo.setHeadSculpture(MinioUtils.getPresignedObjectUrl("jzg", jzgUserInfo.getHeadSculpture()));
             }
@@ -321,8 +330,8 @@ public class JzgAuthenticationProvider implements AuthenticationProvider {
         detailMap.put("dataScope",sysRoleDataScopeVo);
         detailMap.put("name",name);
         detailMap.put("workNumber",workNumber);
-        detailMap.put("id",byId.getId());
-        detailMap.put("username",byId.getUsername());
+        detailMap.put("id",weblogUser.getId());
+        detailMap.put("username",weblogUser.getUsername());
         detailMap.put("headSculpture",jzgUserInfo.getHeadSculpture());
         detailMap.put("isFirst",isFirst);
         if (Objects.nonNull(province) && !province.equals("")) {

+ 5 - 1
authentication/src/main/java/com/jzg/config/SecurityConfig.java

@@ -5,6 +5,7 @@ import com.jzg.handler.JzgAuthenticationSuccessHandler;
 import com.jzg.mapper.SysRoleDataScopeLinkMapper;
 import com.jzg.mapper.SysRoleDataScopeMapper;
 import com.jzg.mapper.SysUserJzgAppMapper;
+import com.jzg.mapper.SysUserJzgInfoMapper;
 import com.jzg.service.SysSystemService;
 import com.jzg.service.SysUserRoleService;
 import com.jzg.service.SysUserService;
@@ -59,6 +60,9 @@ public class SecurityConfig {
     @Autowired
     Map<String, WxMpService> wxMpService;
 
+    @Autowired
+    private SysUserJzgInfoMapper sysUserJzgInfoMapper;
+
     @Bean
     public AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationConfiguration) throws Exception {
         return authenticationConfiguration.getAuthenticationManager();
@@ -67,7 +71,7 @@ public class SecurityConfig {
     @Bean
     public AuthenticationProvider authenticationProvider(UserDetailsService userDetailsService) {
         return new JzgAuthenticationProvider(userDetailsService,sysUserService,sysRoleService,redissonClient,sysRoleDataScopeMapper,
-                sysRoleDataScopeLinkMapper,sysSystemService,sysUserJzgAppMapper,wxMpService);
+                sysRoleDataScopeLinkMapper,sysSystemService,sysUserJzgAppMapper,wxMpService,sysUserJzgInfoMapper);
     }
 
     @Bean

+ 9 - 0
authentication/src/main/java/com/jzg/mapper/SysUserJzgInfoMapper.java

@@ -10,4 +10,13 @@ public interface SysUserJzgInfoMapper extends BaseMapper<SysUserJzgInfo> {
 
     @Select("SELECT IF(partner_status = 3, true, false) AS is_partner_status FROM sys_user_jzg_info_salesman WHERE sys_user_jzg_info_id = #{id} AND type_attr = 3")
     boolean selectTypeAttr(String id);
+
+    /**
+     * 根据用户序号查询租户下的用户信息
+     *
+     * @author lipf
+     * @date 2026/4/22 11:13
+     */
+    @Select("select * from sys_user_jzg_info a where a.user_id  = #{userId,jdbcType=DECIMAL}")
+    SysUserJzgInfo queryJzgInfoByUserId(String userId);
 }

+ 10 - 0
commons/src/main/java/com/jzg/commons/entity/po/SysUserJzgInfo.java

@@ -338,6 +338,16 @@ public class SysUserJzgInfo extends BaseModel implements Serializable {
     @Schema(description = "合伙人类型")
     private String partnerTypeAttr;
 
+    /**
+     * 判断用户是否能登录
+     *      启用状态才能登录
+     * @author lipf
+     * @date 2026/4/22 11:16
+     */
+    public boolean canLogin(){
+        return this.isEnable != null && this.isEnable == 0;
+    }
+
     public SysUserJzgInfo(String userName, SysUser user, String systemCode, String deptId){
         this.userId = user.getId();
         //默认添加管理员账户

+ 1 - 0
gateway/src/main/java/com/jzg/filter/AuthFilter.java

@@ -50,6 +50,7 @@ public class AuthFilter implements GlobalFilter {
                     Long beginTimeObj = exchange.getAttribute(BEGIN_VISIT_TIME);
                     long beginTime = beginTimeObj != null ? beginTimeObj : System.currentTimeMillis();
                     long cost = System.currentTimeMillis() - beginTime;
+                    log.info("e.msg=[{}]", e.getMessage());
                     log.error("【Gateway请求异常】 请求地址:{} , 耗时: {}ms, 异常信息",path,cost, e);
                 });
     }

+ 7 - 1
tenant/organization/src/main/java/com/jzg/organization/controller/SysDistributionSettingController.java

@@ -30,8 +30,14 @@ public class SysDistributionSettingController {
         return sysDistributionSettingService.saveSetting(sysDistributionSettingVo);
     }
 
+    /**
+     * 修改分销设置
+     *
+     * @author lipf
+     * @date 2026/4/22 14:17
+     */
     @PostMapping("/updateSetting")
-    public HttpResult updateSetting(@RequestBody SysDistributionSettingVo sysDistributionSettingVo){
+    public HttpResult<String> updateSetting(@RequestBody SysDistributionSettingVo sysDistributionSettingVo){
         return sysDistributionSettingService.updateSetting(sysDistributionSettingVo);
     }
 

+ 8 - 1
tenant/organization/src/main/java/com/jzg/organization/service/SysDistributionSettingService.java

@@ -9,11 +9,18 @@ import com.jzg.commons.entity.vo.*;
 import java.util.List;
 
 public interface SysDistributionSettingService extends IService<SysDistributionSetting> {
+
     HttpResult getSettingBySystemCode();
 
     HttpResult saveSetting(SysDistributionSettingVo sysDistributionSettingVo);
 
-    HttpResult updateSetting(SysDistributionSettingVo sysDistributionSettingVo);
+    /**
+     * 修改分销设置
+     *
+     * @author lipf
+     * @date 2026/4/22 14:16
+     */
+    HttpResult<String> updateSetting(SysDistributionSettingVo sysDistributionSettingVo);
 
     Page<SysDistributionListVo> distributorList(Page page,SysDistributionListVo sysDistributionListVo);
 

+ 15 - 1
tenant/organization/src/main/java/com/jzg/organization/service/impl/SysDistributionSettingServiceImpl.java

@@ -1,5 +1,6 @@
 package com.jzg.organization.service.impl;
 
+import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -17,6 +18,8 @@ import com.jzg.organization.mapper.SysDistributionSettingMapper;
 import com.jzg.organization.mapper.SysUserJzgInfoMapper;
 import com.jzg.organization.service.*;
 import jakarta.annotation.Resource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 
@@ -34,6 +37,8 @@ import java.util.Set;
 
 @Service
 public class SysDistributionSettingServiceImpl extends ServiceImpl<SysDistributionSettingMapper, SysDistributionSetting> implements SysDistributionSettingService {
+
+    private static final Logger log = LoggerFactory.getLogger(SysDistributionSettingServiceImpl.class);
     @Resource
     private SysDistributionSettingMapper sysDistributionSettingMapper;
 
@@ -60,10 +65,12 @@ public class SysDistributionSettingServiceImpl extends ServiceImpl<SysDistributi
 
     @Resource
     private QuoteClient quoteClient;
+
     public HttpResult getSettingBySystemCode() {
         SysDistributionSetting sysDistributionSetting = sysDistributionSettingMapper
                 .selectOne(new LambdaQueryWrapper<SysDistributionSetting>().eq(SysDistributionSetting::getSystemCode, baseController.getUserSystemCode()));
         if (sysDistributionSetting == null) {
+            log.info("租户[{}]未开启分销权限, 请在[分销管理]-[分销设置]页面进行配置", baseController.getUserSystemCode());
             return HttpResult.error("该租户未开启分销权限");
         }
         List<SysDept> sysDeptList = sysDeptService.list(new LambdaQueryWrapper<SysDept>().eq(SysDept::getIsDistribution, "0").eq(SysDept::getSystemCode, baseController.getUserSystemCode()));
@@ -94,8 +101,15 @@ public class SysDistributionSettingServiceImpl extends ServiceImpl<SysDistributi
         return HttpResult.ok("保存成功");
     }
 
+    /**
+     * 修改分销设置
+     *
+     * @author lipf
+     * @date 2026/4/22 14:15
+     */
     @Override
-    public HttpResult updateSetting(SysDistributionSettingVo sysDistributionSettingVo) {
+    public HttpResult<String> updateSetting(SysDistributionSettingVo sysDistributionSettingVo) {
+        log.info("修改分销设置:sysDistributionSettingVo=[{}]", JSONUtil.toJsonStr(sysDistributionSettingVo));
         SysDistributionSetting sysDistributionSetting = sysDistributionSettingMapper.selectById(sysDistributionSettingVo.getId());
         if (sysDistributionSetting == null) {
             return HttpResult.error("该分销设置不存在");