Procházet zdrojové kódy

Merge branch 'master' of https://git.steerinfo.com/XTEMS/xt-ems-api

# Conflicts:
#	src/main/java/com/steerinfo/ems/emsgmpcjh/controller/EmsGmPcJhController.java
lirl před 3 roky
rodič
revize
11286c0c02

+ 4 - 0
pom.xml

@@ -134,6 +134,10 @@
 			<artifactId>axis2-transport-http</artifactId>
 			<version>1.8.0</version>
 		</dependency>
+		<dependency>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter-websocket</artifactId>
+		</dependency>
 	</dependencies>
 
 	<build>

+ 10 - 10
src/main/java/com/steerinfo/auth/shiro/config/ShiroConfig.java

@@ -1,12 +1,8 @@
 package com.steerinfo.auth.shiro.config;
 
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.servlet.Filter;
-
+import com.steerinfo.auth.shiro.cache.CustomCacheManager;
+import com.steerinfo.auth.shiro.jwt.JwtStatelessAccessControlFilter;
+import com.steerinfo.auth.shiro.realm.UserModularRealmAuthenticator;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.shiro.authc.pam.AllSuccessfulStrategy;
 import org.apache.shiro.authc.pam.ModularRealmAuthenticator;
@@ -21,9 +17,11 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 
-import com.steerinfo.auth.shiro.cache.CustomCacheManager;
-import com.steerinfo.auth.shiro.jwt.JwtStatelessAccessControlFilter;
-import com.steerinfo.auth.shiro.realm.UserModularRealmAuthenticator;
+import javax.servlet.Filter;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
 
 /**
  * Shiro权限配置
@@ -175,6 +173,8 @@ public class ShiroConfig {
         filterChainDefinitionMap.put(versionBefore + "/ifmesemsswapfile/**", AUTH_ANON);
         filterChainDefinitionMap.put(versionBefore + "/ifmesemsproductorder/**", AUTH_ANON);
         filterChainDefinitionMap.put(versionBefore + "/mesemsdieseloils/**", AUTH_ANON);
+        // websocket不拦截
+        filterChainDefinitionMap.put("/websocket/**", AUTH_ANON);
     }
     
 }

+ 75 - 0
src/main/java/com/steerinfo/ems/Utils/WebSocket.java

@@ -0,0 +1,75 @@
+package com.steerinfo.ems.Utils;
+
+import org.springframework.stereotype.Component;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.websocket.OnClose;
+import javax.websocket.OnMessage;
+import javax.websocket.OnOpen;
+import javax.websocket.Session;
+import javax.websocket.server.PathParam;
+import javax.websocket.server.ServerEndpoint;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.CopyOnWriteArraySet;
+
+/**
+ * @author Shadow
+ * @create 2021-09-18 14:54
+ * @project xt-ems-api
+ */
+@ServerEndpoint("/websocket/{shopId}")
+@RestController
+@Component
+//此注解相当于设置访问URL
+public class WebSocket {
+
+    private Session session;
+
+    private static CopyOnWriteArraySet<WebSocket> webSockets =new CopyOnWriteArraySet<>();
+    private static Map<String,Session> sessionPool = new HashMap<String,Session>();
+
+    @OnOpen
+    public void onOpen(Session session, @PathParam(value="shopId")String shopId) {
+        this.session = session;
+        webSockets.add(this);
+        sessionPool.put(shopId, session);
+        System.out.println("【websocket消息】有新的连接,总数为:"+webSockets.size());
+    }
+
+    @OnClose
+    public void onClose() {
+        webSockets.remove(this);
+        System.out.println("【websocket消息】连接断开,总数为:"+webSockets.size());
+    }
+
+    @OnMessage
+    public void onMessage(String message) {
+        System.out.println("【websocket消息】收到客户端消息:"+message);
+    }
+
+    // 此为广播消息
+    public void sendAllMessage(String message) {
+        for(WebSocket webSocket : webSockets) {
+            System.out.println("【websocket消息】广播消息:"+message);
+            try {
+                webSocket.session.getAsyncRemote().sendText(message);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+    // 此为单点消息
+    public void sendOneMessage(String shopId, String message) {
+        Session session = sessionPool.get(shopId);
+        if (session != null) {
+            try {
+                session.getAsyncRemote().sendText(message);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+}

+ 26 - 0
src/main/java/com/steerinfo/ems/Utils/WebSocketConfig.java

@@ -0,0 +1,26 @@
+package com.steerinfo.ems.Utils;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.socket.config.annotation.EnableWebSocket;
+import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
+import org.springframework.web.socket.server.standard.ServerEndpointExporter;
+
+/**
+ * @author Shadow
+ * @create 2021-09-18 14:49
+ * @project xt-ems-api
+ */
+@Configuration
+@EnableWebSocket
+public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
+    /**
+     * 注入ServerEndpointExporter,
+     * 这个bean会自动注册使用了@ServerEndpoint注解声明的Websocket endpoint
+     */
+    @Bean
+    public ServerEndpointExporter serverEndpointExporter() {
+        return new ServerEndpointExporter();
+    }
+
+}

+ 16 - 0
src/main/java/com/steerinfo/ftp/uploadfile/controller/UploadFileController.java

@@ -129,6 +129,22 @@ public class UploadFileController extends BaseRESTfulController {
         }
       return success();
     }
+
+    @PutMapping(value = "/batchupdate", produces  = "application/json;charset=UTF-8")
+    public RESTfulResult batchupdate(@RequestBody UploadFile[] models) {
+        String userId = JwtUtil.getUseridByToken();
+        for (int i = 0; i < models.length; i++) {
+            UploadFile model = models[i];
+            if (model.getId() == null || model.getId().equals("")) {
+                return failed(null, "id为空");
+            }
+            model.setUpdateMan(userId);
+            model.setUpdateTime(new Date());
+            uploadFileService.modify(model);
+        }
+        return success();
+    }
+
     @PostMapping("/file")
     public RESTfulResult fileUpload( @ModelAttribute MultipartFile file, String type){
         try {

+ 3 - 0
src/main/java/com/steerinfo/ftp/uploadfile/mapper/UploadFileMapper.xml

@@ -246,6 +246,9 @@
       <if test="updateTime != null">
         UPDATE_TIME = #{updateTime,jdbcType=TIMESTAMP},
       </if>
+      <if test="fileType != null">
+        FILE_TYPE = #{fileType,jdbcType=VARCHAR},
+      </if>
     </set>
     where ID = #{id,jdbcType=VARCHAR}
   </update>

+ 10 - 9
src/main/java/com/steerinfo/ftp/uploadfile/utils/FtpFileUtil.java

@@ -3,7 +3,6 @@ package com.steerinfo.ftp.uploadfile.utils;
 import com.steerinfo.framework.utils.io.IOUtils;
 import com.steerinfo.framework.utils.text.Charsets;
 import org.apache.commons.net.ftp.*;
-import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 
 import javax.servlet.http.HttpServletResponse;
@@ -33,24 +32,26 @@ public class FtpFileUtil {
      *   ftp服务器ip地址
      *   相关配置放在application.properties 中
      */
-    @Value("${custom.config.file-server.ip}")
-     String FTP_ADDRESS;
+    //@Value("${custom.config.file-server.ip}")
+    // String FTP_ADDRESS;
+    private String FTP_ADDRESS="172.16.90.238";
 
     /**
      *  端口号
      */
-    @Value("${custom.config.file-server.port}")
-    Integer FTP_PORT;
+    //@Value("${custom.config.file-server.port}")
+    //Integer FTP_PORT;
+    private Integer FTP_PORT=21;
     /**
      * 用户名
      */
-    @Value("${custom.config.file-ftp-user}")
-    String FTP_USERNAME;
+    //@Value("${custom.config.file-ftp-user}")
+    private String FTP_USERNAME="ftptest";
     /**
      * 密码
      */
-    @Value("${custom.config.file-ftp-password}")
-    String FTP_PASSWORD;
+    //@Value("${custom.config.file-ftp-password}")
+    private String FTP_PASSWORD="at286315";
 
     private FTPClient ftpClient = new FTPClient();
     private static final String SPOT = ".";

+ 6 - 1
src/main/resources/application.yml

@@ -1,2 +1,7 @@
 api:
-  version:v1
+  version:v1
+spring:
+  servlet:
+    multipart:
+      max-file-size: 10MB
+      max-request-size: 10MB

+ 9 - 9
src/main/resources/bootstrap.yml

@@ -10,15 +10,15 @@ spring:
       #默认值为0.1f,现在为了测试设置100%采集
       percentage: 1.0
   cloud:
-    config:
-      fail-fast: true
-      discovery:
-        enabled: true
-        service-id: config-server
+    #    config:
+    #      fail-fast: true
+    #      discovery:
+    #        enabled: true
+    #        service-id: config-server
     bus:
       trace:
-       enabled: true
-      enabled: true
+        enabled: false
+      enabled: false
 server:
   port: ${SERVER_PORT:8086}
   tomcat:
@@ -26,7 +26,7 @@ server:
 eureka:
   client:
     serviceUrl:
-      defaultZone: http://root:root@${EUREKA_HOST:localhost}:${EUREKA_PORT:8019}/eureka/
+      defaultZone: http://root:root@${EUREKA_HOST:172.16.90.238}:${EUREKA_PORT:8086}/eureka/
     metadata-map:
       cluster: ribbon
   instance:
@@ -43,4 +43,4 @@ management:
   endpoints:
     web:
       exposure:
-        include: '*'
+        include: '*'