|
|
@@ -4,6 +4,7 @@ import com.izouma.awesomeadmin.constant.AppConstant;
|
|
|
import com.izouma.awesomeadmin.dto.Page;
|
|
|
import com.izouma.awesomeadmin.dto.Result;
|
|
|
import com.izouma.awesomeadmin.model.PlayerInfo;
|
|
|
+import com.izouma.awesomeadmin.service.OSSFileService;
|
|
|
import com.izouma.awesomeadmin.service.PlayerInfoService;
|
|
|
import com.izouma.awesomeadmin.util.ExportExcelUtil;
|
|
|
import org.apache.shiro.authz.annotation.RequiresAuthentication;
|
|
|
@@ -13,12 +14,17 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+import org.springframework.web.multipart.MultipartHttpServletRequest;
|
|
|
+import org.springframework.web.multipart.commons.CommonsMultipartResolver;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* controller类
|
|
|
@@ -29,6 +35,8 @@ public class PlayerInfoController {
|
|
|
|
|
|
@Autowired
|
|
|
private PlayerInfoService playerInfoService;
|
|
|
+ @Autowired
|
|
|
+ private OSSFileService OSSFileService;
|
|
|
|
|
|
/**
|
|
|
* <p>获取全部记录。</p>
|
|
|
@@ -248,6 +256,60 @@ public class PlayerInfoController {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @RequestMapping(value = "/uploadResult")
|
|
|
+ @ResponseBody
|
|
|
+ public Result uploadResult(HttpServletRequest request, Integer id, String rank, String time) {
|
|
|
+ CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver(request.getSession().getServletContext());
|
|
|
+ if (multipartResolver.isMultipart(request)) {
|
|
|
+ PlayerInfo playerInfo = new PlayerInfo();
|
|
|
+ playerInfo.setId(id);
|
|
|
+ MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
|
|
|
+ Iterator it = multiRequest.getFileNames();
|
|
|
+ List<String> paths = new ArrayList<>();
|
|
|
+ String video = null;
|
|
|
+ while (it.hasNext()) {
|
|
|
+ MultipartFile file = multiRequest.getFile(it.next().toString());
|
|
|
+ if (file == null) continue;
|
|
|
+ try {
|
|
|
+ if ("video".equalsIgnoreCase(file.getName())) {
|
|
|
+ Random random = new Random();
|
|
|
+ StringBuilder randomCode = new StringBuilder();
|
|
|
+ for (int i = 0; i < 8; i++) {
|
|
|
+ randomCode.append(Integer.toString(random.nextInt(36), 36));
|
|
|
+ }
|
|
|
+ String ext = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
|
|
|
+ video = String.format("/var/videos/%s-%s%s", new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss").format(new Date()), randomCode, ext);
|
|
|
+ file.transferTo(new File(video));
|
|
|
+ playerInfo.setVideo(video);
|
|
|
+ } else if ("screenshot".equalsIgnoreCase(file.getName())) {
|
|
|
+ Random random = new Random();
|
|
|
+ StringBuilder randomCode = new StringBuilder();
|
|
|
+ for (int i = 0; i < 8; i++) {
|
|
|
+ randomCode.append(Integer.toString(random.nextInt(36), 36));
|
|
|
+ }
|
|
|
+ String ext = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
|
|
|
+ String fileType = file.getContentType().substring(0, file.getContentType().indexOf("/"));
|
|
|
+ String uploadPath = String.format("%s/%s-%s%s", fileType, new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss").format(new Date()), randomCode, ext);
|
|
|
+ String screenshot = OSSFileService.upload(file.getInputStream(), uploadPath);
|
|
|
+ playerInfo.setImage(screenshot);
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (rank != null && time != null) {
|
|
|
+ playerInfo.setRanking(Integer.valueOf(rank));
|
|
|
+ playerInfo.setLiveTime(time);
|
|
|
+ playerInfo.setVideo(video);
|
|
|
+ playerInfo.setStatusFlag(AppConstant.PlayerStatus.PROCESSED);
|
|
|
+ } else {
|
|
|
+ playerInfo.setStatusFlag(AppConstant.PlayerStatus.PROCESSED_FAIL);
|
|
|
+ }
|
|
|
+ playerInfoService.updatePlayerInfo(playerInfo);
|
|
|
+ return new Result(true, paths);
|
|
|
+ }
|
|
|
+ return new Result(false, "上传失败");
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|