|  |  |  | 
|---|
|  |  |  | import com.zy.asrs.service.AppVersionService; | 
|---|
|  |  |  | import com.zy.common.web.BaseController; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Value; | 
|---|
|  |  |  | import org.springframework.core.io.ClassPathResource; | 
|---|
|  |  |  | import org.springframework.util.ClassUtils; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.servlet.http.HttpServletResponse; | 
|---|
|  |  |  | import java.io.*; | 
|---|
|  |  |  | import java.net.InetAddress; | 
|---|
|  |  |  | import java.net.UnknownHostException; | 
|---|
|  |  |  | import java.text.SimpleDateFormat; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  | public class AppVersionController extends BaseController { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${server.port}") | 
|---|
|  |  |  | private String port; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private AppVersionService appVersionService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | response.setStatus(404); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @RequestMapping("/appVersion/downloadApp/{filename}/qrDownload") | 
|---|
|  |  |  | public void qrDownload(@PathVariable String filename, HttpServletResponse response) { | 
|---|
|  |  |  | @RequestMapping("/appVersion/downloadApp/getIp") | 
|---|
|  |  |  | public R qrDownload() { | 
|---|
|  |  |  | String ipAddress = ""; | 
|---|
|  |  |  | String url = ""; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | ClassPathResource pathResource = new ClassPathResource("appVersion/" + filename); | 
|---|
|  |  |  | File file = pathResource.getFile(); | 
|---|
|  |  |  | InputStream inputStream = pathResource.getInputStream(); | 
|---|
|  |  |  | //输出文件 | 
|---|
|  |  |  | InputStream fis = new BufferedInputStream(inputStream); | 
|---|
|  |  |  | byte[] buffer = new byte[fis.available()]; | 
|---|
|  |  |  | fis.read(buffer); | 
|---|
|  |  |  | fis.close(); | 
|---|
|  |  |  | response.reset(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //获取文件的名字再浏览器下载页面 | 
|---|
|  |  |  | String name = file.getName(); | 
|---|
|  |  |  | response.addHeader("Content-Disposition", "attachment;filename=" + new String(name.getBytes(), "iso-8859-1")); | 
|---|
|  |  |  | response.addHeader("Content-Length", "" + file.length()); | 
|---|
|  |  |  | OutputStream out = new BufferedOutputStream(response.getOutputStream()); | 
|---|
|  |  |  | response.setContentType("application/octet-stream"); | 
|---|
|  |  |  | out.write(buffer); | 
|---|
|  |  |  | out.flush(); | 
|---|
|  |  |  | out.close(); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | InetAddress inetAddress = InetAddress.getLocalHost(); | 
|---|
|  |  |  | ipAddress = inetAddress.getHostAddress(); | 
|---|
|  |  |  | System.out.println("本机IP地址:" + ipAddress); | 
|---|
|  |  |  | } catch (UnknownHostException e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | response.setStatus(404); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | url = "http://" + ipAddress + ":" + port; | 
|---|
|  |  |  | return R.ok().add(url); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|