|
@@ -0,0 +1,69 @@
|
|
|
+package com.gyee.frame.controller;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.gyee.frame.common.dataSources.DataSource;
|
|
|
+import com.gyee.frame.common.dataSources.DataSourceType;
|
|
|
+import com.gyee.frame.common.domain.AjaxResult;
|
|
|
+import com.gyee.frame.mapper.ticket.GyeeversionMapper;
|
|
|
+import com.gyee.frame.model.ticket.Gyeeversion;
|
|
|
+import com.gyee.frame.service.ticket.FileService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.core.io.Resource;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.io.IOException;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("sys")
|
|
|
+public class AnonController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ FileService fileService;
|
|
|
+ @Autowired
|
|
|
+ GyeeversionMapper gyeeversionMapper;
|
|
|
+
|
|
|
+ @DataSource(value = DataSourceType.TICKET)
|
|
|
+ @GetMapping("version")
|
|
|
+ public AjaxResult version(){
|
|
|
+ QueryWrapper<Gyeeversion> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.eq("TYPE", "android");
|
|
|
+
|
|
|
+ Gyeeversion gyeeversion = gyeeversionMapper.selectOne(wrapper);
|
|
|
+ if (gyeeversion != null)
|
|
|
+ return AjaxResult.successData(gyeeversion.getVersion());
|
|
|
+
|
|
|
+ return AjaxResult.error();
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/downloadFile")
|
|
|
+ public ResponseEntity<Resource> downloadFile( HttpServletRequest request) {
|
|
|
+ // Load file as Resource
|
|
|
+ Resource resource = fileService.loadFileAsResource("D://sisphone.apk");
|
|
|
+
|
|
|
+ // Try to determine file's content type
|
|
|
+ String contentType = null;
|
|
|
+ try {
|
|
|
+ contentType = request.getServletContext().getMimeType(resource.getFile().getAbsolutePath());
|
|
|
+ } catch (IOException ex) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // Fallback to the default content type if type could not be determined
|
|
|
+ if(contentType == null) {
|
|
|
+ contentType = "application/octet-stream";
|
|
|
+ }
|
|
|
+
|
|
|
+ return ResponseEntity.ok()
|
|
|
+ .contentType(MediaType.parseMediaType(contentType))
|
|
|
+ .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + resource.getFilename() + "\"")
|
|
|
+ .body(resource);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|