|
|
@@ -0,0 +1,47 @@
|
|
|
+package cn.edu.nju.plagdemo.api.callbacks;
|
|
|
+
|
|
|
+import cn.edu.nju.plagdemo.model.FileStateEnum;
|
|
|
+import cn.edu.nju.plagdemo.model.form.plag.FileUploaderCallbackForm;
|
|
|
+import cn.edu.nju.plagdemo.model.po.plag.BaseFilePO;
|
|
|
+import cn.edu.nju.plagdemo.model.po.plag.DetectionFilePO;
|
|
|
+import cn.edu.nju.plagdemo.service.IBaseFileService;
|
|
|
+import cn.edu.nju.plagdemo.service.IDetectionFileService;
|
|
|
+import cn.edu.nju.plagdemo.utils.RestResult;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+@Api
|
|
|
+@Validated
|
|
|
+@RestController
|
|
|
+@RequestMapping("/ossCallback")
|
|
|
+public class OssCallback {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ IDetectionFileService detectionFileService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ IBaseFileService baseFileService;
|
|
|
+
|
|
|
+ @PostMapping(value = "/uploadSuccess")
|
|
|
+ public RestResult<?> onFileUploadSuccess(
|
|
|
+ @RequestBody FileUploaderCallbackForm fileUploaderCallbackForm
|
|
|
+ ){
|
|
|
+ if(fileUploaderCallbackForm.getFileType().equals("file")) {
|
|
|
+ DetectionFilePO detectionFilePO = new DetectionFilePO();
|
|
|
+ detectionFilePO.setId(fileUploaderCallbackForm.getFileId());
|
|
|
+ detectionFilePO.setState(FileStateEnum.SUCCESSFUL.getState());
|
|
|
+ detectionFileService.saveOrUpdate(detectionFilePO);
|
|
|
+ } else if(fileUploaderCallbackForm.getFileType().equals("basefile")){
|
|
|
+ BaseFilePO baseFilePO = new BaseFilePO();
|
|
|
+ baseFilePO.setId(fileUploaderCallbackForm.getFileId());
|
|
|
+ baseFilePO.setState(FileStateEnum.SUCCESSFUL.getState());
|
|
|
+ baseFileService.saveOrUpdate(baseFilePO);
|
|
|
+ }
|
|
|
+ return RestResult.OK;
|
|
|
+ }
|
|
|
+}
|