1、替换swagger,可直接 doc.html访问接口
2、提供socket获取扫码枪数据(待测试)
11个文件已修改
2个文件已添加
406 ■■■■ 已修改文件
hangzhoumesParent/common/pom.xml 29 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
hangzhoumesParent/common/servicebase/src/main/java/com/mes/common/config/Swagger2Config.java 117 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/CacheGlassModuleApplication.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
hangzhoumesParent/moduleService/CacheVerticalGlassModule/src/main/java/com/mes/CacheVerticalClassModuleApplication.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
hangzhoumesParent/moduleService/GlassStorageModule/src/main/java/com/mes/GlassStorageApplication.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
hangzhoumesParent/moduleService/LoadGlassModule/src/main/java/com/mes/LoadGlassModuleApplication.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
hangzhoumesParent/moduleService/TemperingGlassModule/src/main/java/com/mes/TemperingGlassModuleApplication.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/UnLoadGlassApplication.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/config/SocketConfig.java 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/job/Downpush.java 34 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/tools/SocketUtil.java 168 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/resources/application.yml 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
hangzhoumesParent/pom.xml 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
hangzhoumesParent/common/pom.xml
@@ -136,23 +136,22 @@
                </exclusion>
            </exclusions>
        </dependency>
        <!--        2.0~2.2    Knife4j 2.0.0 ~ 2.0.6-->
        <dependency>
            <groupId>com.github.xiaoymin</groupId>
            <artifactId>knife4j-spring-boot-starter</artifactId>
            <version>2.0.9</version>
        </dependency>
        <!--                2.0~2.2    Knife4j 2.0.0 ~ 2.0.6-->
        <!--        <dependency>-->
        <!--            <groupId>com.github.xiaoymin</groupId>-->
        <!--            <artifactId>knife4j-spring-boot-starter</artifactId>-->
        <!--            <version>2.0.6</version>-->
        <!--            <groupId>io.springfox</groupId>-->
        <!--            <artifactId>springfox-swagger2</artifactId>-->
        <!--            <version>2.7.0</version>-->
        <!--        </dependency>-->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.7.0</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.7.0</version>
        </dependency>
        <!--        <dependency>-->
        <!--            <groupId>io.springfox</groupId>-->
        <!--            <artifactId>springfox-swagger-ui</artifactId>-->
        <!--            <version>2.7.0</version>-->
        <!--        </dependency>-->
        <!--hutool java验证方法类-->
        <dependency>
hangzhoumesParent/common/servicebase/src/main/java/com/mes/common/config/Swagger2Config.java
@@ -3,19 +3,12 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.*;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.contexts.SecurityContext;
import springfox.documentation.spring.web.plugins.Docket;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
 * @author zhan_py
@@ -25,54 +18,82 @@
@Configuration
public class Swagger2Config {
    @Bean
    public Docket webApiConfig() {
        List<Parameter> pars = new ArrayList<>();
        ParameterBuilder tokenPar = new ParameterBuilder();
        tokenPar.name("userId")
                .description("用户token")
                //.defaultValue(JwtHelper.createToken(1L, "admin"))
                .defaultValue("1")
                .modelRef(new ModelRef("string"))
                .parameterType("header")
                .required(false)
                .build();
        pars.add(tokenPar.build());
    public Docket moduleDocket() {
        return docket("mes接口文档", "com.mes");
    }
    private Docket docket(String groupName, String basePackages) {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("webApi")
                .apiInfo(webApiInfo())
                .groupName(groupName)
                .apiInfo(apiInfo())
                .select()
                //只显示api路径下的页面
                .apis(RequestHandlerSelectors.basePackage("com.mes"))
                .apis(RequestHandlerSelectors.basePackage(basePackages))
                .paths(PathSelectors.any())
                .build()
                .globalOperationParameters(pars)
                .securitySchemes(Collections.EMPTY_LIST)
                .securityContexts(Arrays.asList(securityContext()));
    }
    private SecurityContext securityContext() {
        return SecurityContext.builder()
                .securityReferences(defaultAuth())
                .forPaths(PathSelectors.any())
                .build();
    }
    private List<SecurityReference> defaultAuth() {
        AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
        AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
        authorizationScopes[0] = authorizationScope;
        return Arrays.asList(new SecurityReference("Authorization", authorizationScopes));
    }
    private ApiInfo webApiInfo() {
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("网站-API文档")
                .description("本文档描述了mes网站微服务接口定义")
                .version("1.0")
                .contact(new Contact("zhan_py", "", ""))
                .title("mes接口文档系统")
                .description("mesApi接口文档系统")
                .license("Powered By mes")
                .licenseUrl("http://127.0.0.1")
                .termsOfServiceUrl("http://127.0.0.1")
                .contact(new Contact("mes", "http://127.0.0.1", "beibo@mes.com"))
                .version("V1.0.0")
                .build();
    }
//    @Bean
//    public Docket webApiConfig() {
//        List<Parameter> pars = new ArrayList<>();
//        ParameterBuilder tokenPar = new ParameterBuilder();
//        tokenPar.name("userId")
//                .description("用户token")
//                .defaultValue("1")
//                .modelRef(new ModelRef("string"))
//                .parameterType("header")
//                .required(false)
//                .build();
//        pars.add(tokenPar.build());
//
//        return new Docket(DocumentationType.SWAGGER_2)
//                .apiInfo(webApiInfo())
//                .select()
//                //只显示api路径下的页面
//                .apis(RequestHandlerSelectors.basePackage("com.mes"))
//                .paths(PathSelectors.any())
//                .build()
//                .globalOperationParameters(pars)
//                .securitySchemes(Collections.EMPTY_LIST)
//                .securityContexts(Arrays.asList(securityContext()));
//    }
//
//    private SecurityContext securityContext() {
//        return SecurityContext.builder()
//                .securityReferences(defaultAuth())
//                .forPaths(PathSelectors.any())
//                .build();
//    }
//
//    private List<SecurityReference> defaultAuth() {
//        AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
//        AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
//        authorizationScopes[0] = authorizationScope;
//        return Arrays.asList(new SecurityReference("Authorization", authorizationScopes));
//    }
//
//
//    private ApiInfo webApiInfo() {
//        return new ApiInfoBuilder()
//                .title("网站-API文档")
//                .description("本文档描述了mes网站微服务接口定义")
//                .version("1.0")
//                .contact(new Contact("zhan_py", "", ""))
//                .build();
//    }
}
hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/CacheGlassModuleApplication.java
@@ -6,7 +6,7 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.scheduling.annotation.EnableScheduling;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
/**
 * @Author : zhoush
@@ -17,7 +17,7 @@
@SpringBootApplication
@MapperScan("com.mes.*.mapper")
@EnableDiscoveryClient
@EnableSwagger2
@EnableSwagger2WebMvc
@EnableScheduling
public class CacheGlassModuleApplication {
hangzhoumesParent/moduleService/CacheVerticalGlassModule/src/main/java/com/mes/CacheVerticalClassModuleApplication.java
@@ -6,7 +6,7 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.scheduling.annotation.EnableScheduling;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
/**
 * @Author : zhoush
@@ -15,7 +15,7 @@
 */
@Slf4j
@SpringBootApplication
@EnableSwagger2
@EnableSwagger2WebMvc
@EnableDiscoveryClient
@MapperScan(basePackages = "com.mes.*.mapper")
@EnableScheduling
hangzhoumesParent/moduleService/GlassStorageModule/src/main/java/com/mes/GlassStorageApplication.java
@@ -6,7 +6,7 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.scheduling.annotation.EnableScheduling;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
/**
 * @Author : zhoush
@@ -15,7 +15,7 @@
 */
@Slf4j
@SpringBootApplication
@EnableSwagger2
@EnableSwagger2WebMvc
@EnableDiscoveryClient
@MapperScan(basePackages = "com.mes.*.mapper")
@EnableScheduling
hangzhoumesParent/moduleService/LoadGlassModule/src/main/java/com/mes/LoadGlassModuleApplication.java
@@ -6,7 +6,7 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.scheduling.annotation.EnableScheduling;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
/**
 * @Author : zhoush
@@ -15,7 +15,7 @@
 */
@Slf4j
@SpringBootApplication
@EnableSwagger2
@EnableSwagger2WebMvc
@EnableDiscoveryClient
@EnableScheduling
@MapperScan(basePackages = "com.mes.*.mapper")
hangzhoumesParent/moduleService/TemperingGlassModule/src/main/java/com/mes/TemperingGlassModuleApplication.java
@@ -6,7 +6,7 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.scheduling.annotation.EnableScheduling;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
/**
 * @Author : zhoush
@@ -15,7 +15,7 @@
 */
@Slf4j
@SpringBootApplication
@EnableSwagger2
@EnableSwagger2WebMvc
@EnableDiscoveryClient
@EnableScheduling
@MapperScan(basePackages = "com.mes.*.mapper")
hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/UnLoadGlassApplication.java
@@ -6,7 +6,7 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.scheduling.annotation.EnableScheduling;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
/**
 * @Author : zhoush
@@ -15,7 +15,7 @@
 */
@Slf4j
@SpringBootApplication
@EnableSwagger2
@EnableSwagger2WebMvc
@EnableDiscoveryClient
@MapperScan(basePackages = "com.mes.*.mapper")
@EnableScheduling
hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/config/SocketConfig.java
New file
@@ -0,0 +1,26 @@
package com.mes.config;
import com.mes.tools.SocketUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
 * @Author : zhoush
 * @Date: 2024/9/2 15:42
 * @Description:
 */
@Configuration
public class SocketConfig {
    @Value("${mes.scan.ip}")
    private String scanIp;
    @Value("${mes.scan.port}")
    private Integer scanPort;
    @Bean
    public SocketUtil getSocketUtil() {
        return new SocketUtil(scanIp, scanPort);
    }
}
hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/job/Downpush.java
@@ -14,6 +14,7 @@
import com.mes.downworkstation.entity.DownWorkstation;
import com.mes.downworkstation.service.DownWorkstationService;
import com.mes.tools.DateUtil;
import com.mes.tools.SocketUtil;
import com.mes.tools.WebSocketServer;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
@@ -38,8 +39,8 @@
    private DownGlassInfoService downGlassInfoService;
    @Autowired
    private DownGlassTaskService downGlassTaskService;
    @Autowired
    SocketUtil socketUtil;
    @Autowired
    private RedisUtil redisUtil;
@@ -188,4 +189,33 @@
            }
        }
    }
    @Scheduled(fixedDelay = Long.MAX_VALUE)
    public void scanCodeTask() {
        while (true) {
            try {
                if (socketUtil.openSocket()) {
                    String data = socketUtil.receiveData();
                    if (StringUtils.isNotBlank(data)) {
                        log.info("扫描数据:" + data);
                        //发送扫描数据
                        //todo:按照玻璃id获取玻璃信息返回给前端界面,具体需要哪些数据待确认
                        ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("scanCode");
                        if (sendwServer != null) {
                            for (WebSocketServer webserver : sendwServer) {
                                if (webserver != null && webserver.session.isOpen()) {
                                    webserver.sendMessage(data);
                                }
                            }
                        }
                    }
                } else {
                    log.info("socket连接失败");
                }
            } catch (Exception e) {
                log.info("socke执行过程中发生异常");
            }
        }
    }
}
hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/tools/SocketUtil.java
New file
@@ -0,0 +1,168 @@
package com.mes.tools;
import lombok.extern.slf4j.Slf4j;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
/**
 * @Author : zhoush
 * @Date: 2024/9/2 15:32
 * @Description:
 */
@Slf4j
public class SocketUtil {
    private final String host;
    private final int port;
    private final int connectionTimeout;
    private final int soTimeout;
    private Socket socket;
    private DataOutputStream dataOutputStream;
    private DataInputStream dataInputStream;
    public SocketUtil(String host, int port) {
        this(host, port, 5000, 5000);
    }
    public SocketUtil(String host, int port, int connectionTimeout, int soTimeout) {
        this.host = host;
        this.port = port;
        this.connectionTimeout = connectionTimeout;
        this.soTimeout = soTimeout;
    }
    /**
     * 打开Socket连接
     *
     * @return 是否成功打开Socket连接
     */
    public boolean openSocket() {
        try {
            socket = new Socket();
            InetSocketAddress socketAddress = new InetSocketAddress(host, port);
            socket.setReuseAddress(true);
            socket.setSoTimeout(soTimeout);
            socket.connect(socketAddress, connectionTimeout);
            dataOutputStream = new DataOutputStream(socket.getOutputStream());
            dataInputStream = new DataInputStream(socket.getInputStream());
        } catch (Exception e) {
            log.error("打开Socket连接失败:", e);
            return false;
        }
        return true;
    }
    public boolean sendData(String data) {
        return sendData(data, "utf-8");
    }
    /**
     * 发送请求数据。
     *
     * @param data    数据
     * @param charset 字符集
     * @return 是否发送成功
     */
    public boolean sendData(String data, String charset) {
        boolean isSend = true;
        try {
            byte[] bytes = data.getBytes(charset);
            dataOutputStream.writeInt(bytes.length);
            dataOutputStream.write(bytes);
        } catch (IOException e) {
            log.error("发送数据失败:", e);
            isSend = false;
        }
        return isSend;
    }
    /**
     * 接收响应数据
     */
    public String receiveData() {
        return receiveData("UTF-8");
    }
    /**
     * 接收响应数据
     */
    public String receiveData(String charset) {
        String returnStr = null;
        byte[] data;
        try {
            int length = dataInputStream.readInt();
            if (length > 0) {
                data = new byte[length];
                dataInputStream.readFully(data);
                returnStr = new String(data, charset);
            }
        } catch (IOException e) {
            log.error("接收数据失败:", e);
        }
        return returnStr;
    }
    /**
     * 关闭Socket连接和输入输出流
     */
    public void close() {
        try {
            if (dataInputStream != null) {
                dataInputStream.close();
            }
        } catch (IOException e) {
            log.error("关闭输入流失败:", e);
        }
        try {
            if (dataOutputStream != null) {
                dataOutputStream.close();
            }
        } catch (IOException e) {
            log.error("关闭输出流失败:", e);
        }
        try {
            if (socket != null) {
                socket.close();
            }
        } catch (IOException e) {
            log.error("关闭Socket失败:", e);
        }
    }
    /**
     * Socket短连接发送请求数据
     *
     * @param host        host
     * @param port        端口
     * @param requestData 请求数据
     * @return 响应数据
     */
    public static String send(String host, int port, String requestData) {
        SocketUtil socketUtil = new SocketUtil(host, port);
        String resp = null;
        try {
            if (socketUtil.openSocket()) {
                if (socketUtil.sendData(requestData)) {
                    resp = socketUtil.receiveData();
                } else {
                    log.error("SocketUtil.send发送数据失败");
                }
            } else {
                log.error("SocketUtil.openSocket打开Socket失败");
            }
        } catch (Exception e) {
            log.error("SocketUtil.send发送请求失败:", e);
        } finally {
            socketUtil.close();
        }
        return resp;
    }
}
hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/resources/application.yml
@@ -21,3 +21,6 @@
  throughWidth: 3000
  throughHeight: 2500
  threshold: 5      #下片的最大阈值
  scan:
    ip: 127.0.0.1
    port: 5000
hangzhoumesParent/pom.xml
@@ -42,6 +42,11 @@
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.plugin</groupId>
                <artifactId>spring-plugin-core</artifactId>
                <version>2.0.0.RELEASE</version>
            </dependency>
        </dependencies>
    </dependencyManagement>