| | |
| | | package com.ruoyi.web.controller.common; |
| | | |
| | | import org.apache.coyote.AbstractProtocol; |
| | | import com.ruoyi.common.config.RuoYiConfig; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | |
| | | import com.ruoyi.framework.config.ServerConfig; |
| | | import org.apache.catalina.connector.Connector; |
| | | import org.apache.catalina.startup.Tomcat; |
| | | import org.apache.coyote.AbstractProtocol; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.management.MBeanServer; |
| | | import javax.management.MalformedObjectNameException; |
| | | import javax.management.ObjectName; |
| | | import javax.management.Query; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.lang.management.ManagementFactory; |
| | | import java.net.InetAddress; |
| | | import java.net.ServerSocket; |
| | | import java.util.Set; |
| | | |
| | | /** |
| | | * 通用请求处理 |
| | |
| | | */ |
| | | @PostMapping("/common/upload") |
| | | public AjaxResult uploadFile(MultipartFile file) throws Exception { |
| | | int tomcatPort = getTomcatPort(); |
| | | //这个省人民是8099,所以直接写死 |
| | | int tomcatPort = 8099; |
| | | try { |
| | | // 上传文件路径 |
| | | String filePath = RuoYiConfig.getUploadPath(); |
| | | // 上传并返回新文件名称 |
| | | String fileName = FileUploadUtils.upload(filePath, file); |
| | | String url = serverConfig.getUrl() + fileName; |
| | | String url1 = serverConfig.getUrl(); |
| | | log.info("url1的值old :{}", url1); |
| | | //这里的8032不是tomcat的,所以要转成tomcat的 |
| | | url1 = url1.replace("8032", "8099"); |
| | | log.info("url1的值new :{}", url1); |
| | | String url = url1 + fileName; |
| | | AjaxResult ajax = AjaxResult.success(); |
| | | ajax.put("fileName", fileName); |
| | | ajax.put("url", url); |
| | |
| | | } |
| | | } |
| | | |
| | | private static int getTomcatPort() { |
| | | int port = 0; |
| | | Tomcat tomcat = new Tomcat(); |
| | | Connector connector = tomcat.getConnector(); |
| | | if (connector != null) { |
| | | AbstractProtocol protocol = (AbstractProtocol) connector.getProtocolHandler(); |
| | | port = protocol.getPort(); |
| | | } |
| | | return port; |
| | | } |
| | | |
| | | /** |
| | | * 本地资源通用下载 |