Selaa lähdekoodia

fix 导入知识点

he2802 3 vuotta sitten
vanhempi
commit
02867eca3a

+ 20 - 4
zhongzheng-framework/src/main/java/com/zhongzheng/framework/aspectj/LogAspect.java

@@ -19,7 +19,9 @@ import com.zhongzheng.framework.manager.AsyncManager;
 import com.zhongzheng.framework.manager.factory.AsyncFactory;
 import com.zhongzheng.framework.web.service.TokenService;
 import com.zhongzheng.framework.web.service.TopTokenService;
+import com.zhongzheng.framework.web.service.WxTokenService;
 import com.zhongzheng.modules.system.domain.SysOperLog;
+import com.zhongzheng.modules.user.entity.ClientLoginUser;
 import org.aspectj.lang.JoinPoint;
 import org.aspectj.lang.Signature;
 import org.aspectj.lang.annotation.AfterReturning;
@@ -56,6 +58,9 @@ public class LogAspect
     @Value("${mybatis-plus.tenant.enabled-tenant:true}")
     private boolean enabledTenant;
 
+    @Value("${zhongzheng.name}")
+    private String applicationName;
+
     // 配置织入点
     @Pointcut("@annotation(com.zhongzheng.common.annotation.Log)")
     public void logPointCut()
@@ -98,10 +103,21 @@ public class LogAspect
             String username = null;
             if(enabledTenant){
                 // 获取当前的用户
-                LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
-                if (loginUser != null)
-                {
-                    username = loginUser.getUsername();
+                //后台
+                if(applicationName.equals("zhongzheng")){
+                    LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
+                    if (loginUser != null)
+                    {
+                        username = loginUser.getUsername();
+                    }
+                }
+                //客户端
+                if(applicationName.equals("zhongzheng-api")){
+                    ClientLoginUser  loginUser = SpringUtils.getBean(WxTokenService.class).getLoginUser(ServletUtils.getRequest());
+                    if (loginUser != null)
+                    {
+                        username = loginUser.getUser().getUserAccount();
+                    }
                 }
             }else{
                 TopLoginUser topLoginUser = SpringUtils.getBean(TopTokenService.class).getLoginUser(ServletUtils.getRequest());

+ 0 - 1
zhongzheng-framework/src/main/java/com/zhongzheng/framework/web/service/TokenService.java

@@ -85,7 +85,6 @@ public class TokenService
         String token = getToken(request);
         if (Validator.isNotEmpty(token))
         {
-            System.out.println(token+"令牌");
             String uuid = "";
             Claims claims = parseToken(token);
             // 解析对应的权限以及用户信息

+ 6 - 2
zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/service/impl/QuestionServiceImpl.java

@@ -299,14 +299,18 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
                         bAddBo.setSubjectId(subjectId);
                         bList.add(bAddBo);
                         addBo.setExamKnowledgeBusinessAddBoList(bList);
+                        addBo.setStatus(1);
                         knowledgeId = iExamKnowledgeService.insertByImportQuestionAddBo(addBo);
+                        System.out.println(knowledgeId+"新插入知识点");
                         if(Validator.isEmpty(knowledgeId)||knowledgeId==0){
                             //        errorLog+=knowledge+"-该知识点不存在\n";
                             question.setCause("该知识点不存在");
                             errorList.add(question);
                             continue;
                         }
-
+                        //新增进入redis
+                        String key = "KNO_"+knowledge;
+                        redisCache.setCacheObject(key,knowledgeId,3, TimeUnit.MINUTES);//3分钟
                     }
                     kIdList.add(knowledgeId);
                 }
@@ -1056,7 +1060,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
                 addItem.setType(QuestionBusiness.TYPE_QUESTION);
                 coll.add(addItem);
             }
-            iQuestionBusinessService.saveBatch(coll);
+            boolean result1  = iQuestionBusinessService.saveBatch(coll);
         }
         return errorLog;
     }

+ 26 - 26
zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/vo/QuestionExport.java

@@ -23,47 +23,33 @@ public class QuestionExport implements Serializable {
 
     private static final long serialVersionUID = 1L;
 
-    @Excel(name = "编号")
-    private String id;
-    /** 题目正文 */
-    @Excel(name = "题目内容")
-    private String content;
-
-    @Excel(name = "题目类型")
-    private String type;
 
-    @Excel(name = "正确答案")
-    private String answerQuestion;
-
-
-    @Excel(name = "答案解析")
-    private String analysisContent;
-    /** 问题内容 */
-    @Excel(name = "问题内容")
-    @ApiModelProperty("问题内容")
-    private String jsonStr;
-    /** 前缀名称 */
-    @Excel(name = "标题前缀")
-    private String prefixName;
+    private String id;
 
     /** 教育类型ID */
     @Excel(name = "教育类型")
     private String educationType;
+    /** 项目ID */
+    @Excel(name = "项目类型")
+    private String project;
     /** 业务层次id */
     @Excel(name = "业务层次")
     private String business;
     /** 科目id */
     @Excel(name = "科目")
     private String subject;
-    /** 项目ID */
-    @Excel(name = "项目类型")
-    private String project;
-
     @Excel(name = "知识点")
     private String knowledge;
+    /** 前缀名称 */
+    @Excel(name = "标题前缀")
+    private String prefixName;
 
-    private List<String> knowledgeList;
+    @Excel(name = "题目类型")
+    private String type;
 
+    /** 题目正文 */
+    @Excel(name = "题目内容")
+    private String content;
     @Excel(name = "选项1")
     private String v1;
     @Excel(name = "选项2")
@@ -76,6 +62,20 @@ public class QuestionExport implements Serializable {
     private String v5;
     @Excel(name = "选项6")
     private String v6;
+
+    @Excel(name = "正确答案")
+    private String answerQuestion;
+
+    @Excel(name = "答案解析")
+    private String analysisContent;
+    /** 问题内容 */
+
+    @ApiModelProperty("问题内容")
+    private String jsonStr;
+
+
+    private List<String> knowledgeList;
+
     @Excel(name = "失败原因")
     private String cause;
 

+ 1 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/course/service/impl/CourseBusinessServiceImpl.java

@@ -41,6 +41,7 @@ public class CourseBusinessServiceImpl extends ServiceImpl<CourseBusinessMapper,
     public CourseBusinessVo queryById(Long id){
         CourseBusinessQueryBo courseBusinessQueryBo = new CourseBusinessQueryBo();
         courseBusinessQueryBo.setId(id);
+        System.out.println(id+"业务ID");
         List<CourseBusinessVo> courseBusinessVos = entity2Vo(baseMapper.queryList(courseBusinessQueryBo));
         if (CollectionUtils.isEmpty(courseBusinessVos)){
             throw new IllegalArgumentException("请输入正确业务ID");

+ 113 - 19
zhongzheng-system/src/main/java/com/zhongzheng/modules/socket/service/WebSocketServer.java

@@ -1,12 +1,16 @@
 package com.zhongzheng.modules.socket.service;
 
+import cn.hutool.core.lang.Validator;
 import com.zhongzheng.common.exception.CustomException;
 import org.springframework.stereotype.Component;
 
+import javax.validation.Valid;
 import javax.websocket.*;
 import javax.websocket.server.PathParam;
 import javax.websocket.server.ServerEndpoint;
 import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.atomic.AtomicInteger;
 
@@ -17,7 +21,11 @@ public class WebSocketServer {
     private static AtomicInteger onlineNum = new AtomicInteger();
 
     //concurrent包的线程安全Set,用来存放每个客户端对应的WebSocketServer对象。
-    private static ConcurrentHashMap<String, Session> sessionPools = new ConcurrentHashMap<>();
+ //   private static ConcurrentHashMap<String, Session> sessionPools = new ConcurrentHashMap<>();
+    private static ConcurrentHashMap<String, Map<String,Session>> sessionPools = new ConcurrentHashMap<>(); //v是userAccount,v是Session
+    private static ConcurrentHashMap<String, String> namePools = new ConcurrentHashMap<>(); //key是tag,v是userAccount
+    private static ConcurrentHashMap<String, String> actionPools = new ConcurrentHashMap<>(); //存放每个会话的操作,key是tag,v是action
+
 
     //发送消息
     public void sendMessage(Session session, String message) throws IOException {
@@ -29,8 +37,9 @@ public class WebSocketServer {
         }
     }
     //给指定用户发送信息
-    public void sendInfo(String userName, String message){
-        Session session = sessionPools.get(userName);
+    public void sendInfo(String userAccount,String tag, String message){
+        Map<String,Session> sessionMap = sessionPools.get(userAccount);
+        Session session = sessionMap.get(tag);
         if(session==null){
             throw new CustomException("webSocket不在线",505);
         }
@@ -43,33 +52,85 @@ public class WebSocketServer {
 
     //建立连接成功调用
     @OnOpen
-    public void onOpen(Session session, @PathParam(value = "sid") String userName){
-        if(!sessionPools.containsKey(userName)){
-            addOnlineCount();
+    public void onOpen(Session session, @PathParam(value = "sid") String userAccount){
+        String tag = null;
+        if(Validator.isNotEmpty(userAccount)){
+            tag = session.getId(); //用户不同端标识码
+            if(!namePools.containsKey(tag)){
+                namePools.put(tag,userAccount);
+            }
+            if(sessionPools.containsKey(userAccount)){
+                Map<String,Session> sessionMap = sessionPools.get(userAccount);
+                //用户新的终端连接进来
+                if(!sessionMap.containsKey(tag)){
+                    sessionMap.put(tag,session);
+                    addOnlineCount();
+                }
+            }else{
+                //用户所有端都没连接
+                Map<String,Session> sessionMap = new HashMap<>();
+                sessionMap.put(tag,session);
+                sessionPools.put(userAccount, sessionMap);
+                addOnlineCount();
+            }
+            System.out.println(userAccount + "加入webSocket!当前人数为" + onlineNum);
+            try {
+                sendMessage(session, "欢迎" + userAccount + "加入连接!");
+            } catch (IOException e) {
+                e.printStackTrace();
+                delPeople(tag);
+            }
         }
-        sessionPools.put(userName, session);
-        System.out.println(userName + "加入webSocket!当前人数为" + onlineNum);
-        try {
-            sendMessage(session, "欢迎" + userName + "加入连接!");
-        } catch (IOException e) {
-            e.printStackTrace();
+    }
+
+    private String delPeople(String tag){
+        String userAccount = null;
+        if(namePools.containsKey(tag)){
+            userAccount =  namePools.get(tag);
+            namePools.remove(tag);
+            actionPools.remove(tag);
         }
+        if(Validator.isNotEmpty(userAccount)){
+            if(sessionPools.containsKey(userAccount)){
+                Map<String,Session> sessionMap = sessionPools.get(userAccount);
+                if(sessionMap.containsKey(tag)){
+                    sessionMap.remove(tag);
+                }
+                if(sessionMap.size()==0){
+                    sessionPools.remove(userAccount);
+                }
+            }
 
+        }
+        subOnlineCount();
+        return userAccount;
     }
 
     //关闭连接时调用
     @OnClose
-    public void onClose(@PathParam(value = "sid") String userName){
-        sessionPools.remove(userName);
-        subOnlineCount();
-        System.out.println(userName + "断开webSocket连接!当前人数为" + onlineNum);
+    public void onClose(Session session){
+        String tag = session.getId();
+
+        if (Validator.isNotEmpty(tag)) {
+            String userAccount = delPeople(tag);
+            System.out.println(userAccount + "断开webSocket连接!当前人数为" + onlineNum);
+        }
     }
 
     //收到客户端信息
     @OnMessage
-    public void onMessage(String message) throws IOException{
-        message = "客户端:" + message + ",已收到";
-        System.out.println(message);
+    public void onMessage(String message, Session session) throws IOException{
+        String tag = session.getId();
+        if(Validator.isNotEmpty(message)){
+            if (message.equals("doQuestion")) { //题库全部限制多开
+                doQuestion(tag,"doQuestion");
+            }
+            if (message.equals("doCourse")) { //课程继续教育限制多开
+                doQuestion(tag,"doCourse");
+            }
+        }
+   //     message = "客户端:" + message + ",已收到";
+   //    System.out.println(message+System.currentTimeMillis()/1000+namePools.get(session.getId()));
         /*for (Session session: sessionPools.values()) {
             try {
                 sendMessage(session, message);
@@ -95,4 +156,37 @@ public class WebSocketServer {
         onlineNum.decrementAndGet();
     }
 
+    //存储用户行为和发送下线消息给其他端
+    private boolean doQuestion(String tag,String nowAction){
+        String userAccount = null;
+        if(namePools.containsKey(tag)){
+            userAccount =  namePools.get(tag);
+            actionPools.put(tag,nowAction);
+        }
+        if(Validator.isNotEmpty(userAccount)){
+            if(sessionPools.containsKey(userAccount)){
+                Map<String,Session> sessionMap = sessionPools.get(userAccount); //获取用户得所有端会话
+                for(String key : sessionMap.keySet()){
+                   if(actionPools.containsKey(key)){
+                       String action =  actionPools.get(key); //获取用户所在的行为
+                       if(!key.equals(tag)){
+                           if(action.equals(nowAction)){
+                          //     System.out.println(key+"踢下线");
+                               Session other = sessionMap.get(key);
+                               //通知其他端下线
+                               try {
+                                   sendMessage(other, "offLine");
+                               } catch (IOException e) {
+                                   e.printStackTrace();
+                                   delPeople(tag);
+                               }
+                           }
+                       }
+                   }
+                }
+            }
+        }
+        return false;
+    }
+
 }