Bladeren bron

修改在线客服

zhoufan 2 jaren geleden
bovenliggende
commit
f06352b0e7

+ 9 - 44
zxkf-api/src/main/java/api/controller/common/CommonController.java

@@ -1,8 +1,9 @@
1 1
 package api.controller.common;
2 2
 
3
-import com.alibaba.excel.util.StringUtils;
4 3
 import api.controller.BaseController;
5 4
 import api.model.AjaxResult;
5
+import api.util.helper.DateHelper;
6
+import api.util.helper.FileUploadHelper;
6 7
 import io.swagger.annotations.ApiOperation;
7 8
 import lombok.extern.slf4j.Slf4j;
8 9
 import org.springframework.web.bind.annotation.GetMapping;
@@ -18,7 +19,6 @@ import java.net.URL;
18 19
 import java.net.URLConnection;
19 20
 import java.net.URLEncoder;
20 21
 import java.util.HashMap;
21
-import java.util.UUID;
22 22
 
23 23
 /**
24 24
  * 通用请求处理
@@ -39,57 +39,24 @@ public class CommonController extends BaseController {
39 39
         if (files == null || files.length == 0) {
40 40
             return Error("无文件");
41 41
         }
42
-        //新文件名
43
-        StringBuilder newFileName;
44
-
45
-        //全部文件名,若多个,则逗号分隔
46
-        StringBuilder allFileNames = new StringBuilder();
47
-
48 42
         //上传路径
49
-        String fileSavePath = "files";
50
-
43
+        String fileSavePath = "files/common/"+ DateHelper.getDate();
51 44
         //若文件夹不存在,则创建文件夹
52 45
         File pFile = new File(fileSavePath);
53
-        if (!pFile.exists()) {
54
-            pFile.mkdirs();
55
-        }
46
+        if (!pFile.exists()) { pFile.mkdirs(); }
56 47
 
48
+        HashMap<String, String> fileInfo =new HashMap<>();
57 49
         //遍历所有文件
58 50
         for (MultipartFile file : files) {
59
-            //得到原始文件名
60
-            newFileName = new StringBuilder(file.getOriginalFilename());
61
-            //查询文件名中点号所处位置
62
-            int i = newFileName.lastIndexOf(".");
63
-            //若点号位置大于0,则文件名正常
64
-            if (i > 0) {
65
-                //在点号前拼接UUID防止文件重名
66
-                newFileName.insert(i, "_" + UUID.randomUUID().toString().substring(0, 5));
67
-            } else {
68
-                //若点号位置小于等于0,则文件名不规范
69
-                return Error("文件'" + newFileName + "'名称不规范");
70
-            }
51
+            String filePath="";
71 52
             try {
72
-                // 保存文件
73
-                file.transferTo(new File(pFile.getAbsolutePath()+"/" + newFileName));
74
-                //若全部文件名为空,则此为第一个文件,直接追加此文件名
75
-                if (StringUtils.isBlank(allFileNames.toString())) {
76
-                    allFileNames.append(newFileName);
77
-                } else {
78
-                    //若全部文件名不为空,则追加逗号和文件名
79
-                    allFileNames.append(",").append(newFileName).toString();
80
-                }
53
+                filePath= FileUploadHelper.upload(fileSavePath,file);
81 54
             } catch (IOException e) {
82
-                log.error("上传失败",e);
83
-                return Error("上传失败");
55
+                throw new RuntimeException(e);
84 56
             }
57
+            fileInfo.put(file.getOriginalFilename(),filePath);
85 58
         }
86 59
 
87
-        //返回全部文件名和文件路径
88
-        HashMap<String, String> fileInfo = new HashMap<String, String>(2) {{
89
-            put("fileNames", allFileNames.toString());
90
-            put("filePath", fileSavePath);
91
-        }};
92
-        //返回信息
93 60
         return Success("上传成功", fileInfo);
94 61
     }
95 62
 
@@ -105,8 +72,6 @@ public class CommonController extends BaseController {
105 72
             File file = new File(path);
106 73
             // 获取文件名
107 74
             String filename = file.getName();
108
-            // 获取文件后缀名
109
-            String e1xt = filename.substring(filename.lastIndexOf(".") + 1).toLowerCase();
110 75
 
111 76
             // 将文件写入输入流
112 77
             FileInputStream fileInputStream = new FileInputStream(file);

+ 7 - 6
zxkf-service/src/main/java/api/service/websocket/WebSocket.java

@@ -192,9 +192,9 @@ public class WebSocket {
192 192
                 msg.setKhUser(userCode);
193 193
                 msg.setKhSource(source);
194 194
                 String kf = khkfs.get(userCode);
195
-                if (StringHelper.isEmpty(kf)) {
195
+                if (StringHelper.isEmpty(kf)||servicers.get(kf)==2) {
196 196
                     kf = servicerQueue.poll();
197
-                    if(!StringHelper.isEmpty(kf)) {
197
+                    if (!StringHelper.isEmpty(kf)) {
198 198
                         servicerQueue.add(kf);
199 199
                         khkfs.put(userCode, kf);
200 200
                     }
@@ -260,8 +260,9 @@ public class WebSocket {
260 260
         String msg = "客户已下线";
261 261
         if(!(servicers.containsKey(kf)&&kfsessionPool.containsKey(kf))){
262 262
             msg = "此客服未签入";
263
-        }
264
-        else if (!StringHelper.isEmpty(kh)) {
263
+        } else if(servicers.get(kf)==2) {
264
+            msg = "此客服忙碌";
265
+        } else if (!StringHelper.isEmpty(kh)) {
265 266
             if (customers.containsKey(kh)) {
266 267
                 if (khkfs.containsKey(kh)) {
267 268
                     if (khkfs.get(kh).equals(kf) ) {
@@ -458,9 +459,9 @@ public class WebSocket {
458 459
         };
459 460
 
460 461
         String kf = khkfs.get(sendUser);
461
-        if (StringHelper.isEmpty(kf)) {
462
+        if (StringHelper.isEmpty(kf)||servicers.get(kf)==2) {
462 463
             kf = servicerQueue.poll();
463
-            if(!StringHelper.isEmpty(kf)) {
464
+            if (!StringHelper.isEmpty(kf)) {
464 465
                 servicerQueue.add(kf);
465 466
                 khkfs.put(sendUser, kf);
466 467
             }

+ 1 - 5
zxkf-util/pom.xml

@@ -63,11 +63,7 @@
63 63
                 </exclusion>
64 64
             </exclusions>
65 65
         </dependency>
66
-        <dependency>
67
-            <groupId>com.alibaba</groupId>
68
-            <artifactId>easyexcel</artifactId>
69
-            <version>3.0.5</version>
70
-        </dependency>
66
+        <!-- excel -->
71 67
         <dependency>
72 68
             <groupId>org.apache.poi</groupId>
73 69
             <artifactId>poi-ooxml</artifactId>