Browse Source

获取当前登录人信息失败,从TrainingUTils 中重新获取当前的登录人信息

huangpeng 9 months ago
parent
commit
b6362136eb

+ 1 - 2
js-training/training-common/src/main/java/com/rongwei/trainingcommon/sys/service/impl/SubjectServiceImpl.java

@@ -113,7 +113,6 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectDao, SubjectDo> imple
             SubjectOptionsDo subjectOptionsDo;
             Date date = new Date();
             SysUserVo currentUser = TrainingUtils.getCurrentUser();
-            log.info("currentUser : {}",currentUser.toString());
             Sheet sheet = new XSSFWorkbook(multipartFile.getInputStream()).getSheetAt(0);
             Row row ;
             int lastRowNum = sheet.getLastRowNum();
@@ -128,7 +127,7 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectDao, SubjectDo> imple
                 subjectDo.setSubjectname( row.getCell(1).getStringCellValue());  //考题名称
 
                 if (currentUser!=null){
-                    subjectDo.setTenantid(JSCommonUtils.getCurrentUserFactoryId(currentUser));
+                    subjectDo.setTenantid(TrainingUtils.getCurrentUserFactoryId(currentUser));
                     subjectDo.setCreateusername(currentUser.getName());
                     subjectDo.setCreateuserid(currentUser.getId());
                     subjectDo.setModifyusername(currentUser.getName());

+ 24 - 0
js-training/training-common/src/main/java/com/rongwei/trainingcommon/sys/utils/TrainingUtils.java

@@ -2,7 +2,10 @@ package com.rongwei.trainingcommon.sys.utils;
 
 import com.rongwei.commonservice.serial.service.SysSerialNumberService;
 import com.rongwei.commonservice.service.RedisService;
+import com.rongwei.rwadmincommon.system.domain.SysOrganizationDo;
+import com.rongwei.rwadmincommon.system.vo.SysOrganizationVo;
 import com.rongwei.rwadmincommon.system.vo.SysUserVo;
+import com.rongwei.rwcommon.utils.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -13,6 +16,10 @@ import org.springframework.web.context.request.ServletRequestAttributes;
 import javax.annotation.PostConstruct;
 import javax.servlet.http.HttpServletRequest;
 import java.util.Date;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import static com.rongwei.safecommon.utils.SaveConstans.MINUS_ONE;
 
 /**
  * TrainingUtils class
@@ -47,6 +54,23 @@ public class TrainingUtils {
         return currUser;
     }
 
+    public static String getCurrentUserFactoryId(SysUserVo currentUser) {
+        if (currentUser == null) {
+            currentUser = getCurrentUser();
+        }
+        List<SysOrganizationVo> organizationDoList = currentUser.getOrganizationDoList();
+        String factoryId = organizationDoList.stream()
+                .filter(org -> MINUS_ONE.equals(org.getPid()))
+                .map(SysOrganizationDo::getId)
+                .distinct()
+                .collect(Collectors.joining(","));
+        if (StringUtils.isBlank(factoryId)) {
+            factoryId = organizationDoList.stream().map(info -> info.getFullpid().split(",")[1]).distinct().collect(Collectors.joining(","));
+        }
+        return factoryId;
+    }
+
+
     @PostConstruct
     public void init() {
         redisService = autoRedisService;