|
@@ -6,22 +6,23 @@ import com.rf.fileCrack.base.rest.BaseController;
|
|
|
import com.rf.fileCrack.file.dao.model.FileEntity;
|
|
|
import com.rf.fileCrack.file.service.FileService;
|
|
|
import com.rf.fileCrack.socket.WebSocketServer;
|
|
|
+import com.rf.fileCrack.utils.FileUtil;
|
|
|
import com.rf.fileCrack.utils.Result;
|
|
|
import com.rf.fileCrack.utils.SendEmail;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.websocket.Session;
|
|
|
import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
+import java.io.IOException;
|
|
|
import java.text.DateFormat;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
@@ -52,11 +53,11 @@ public class FileController extends BaseController {
|
|
|
String fileName = "";
|
|
|
String FILEDIR = "./uploadFile/";
|
|
|
if (file == null) {
|
|
|
- throw new Exception("文件为空");
|
|
|
+ return fail("文件为空");
|
|
|
} else {
|
|
|
FileEntity fileEntity = new FileEntity();
|
|
|
if (!file.isEmpty()) {
|
|
|
- fileName = System.currentTimeMillis()+"-"+file.getOriginalFilename();
|
|
|
+ fileName = System.currentTimeMillis()+"-=-"+file.getOriginalFilename();
|
|
|
try {
|
|
|
File temp = new File(FILEDIR);
|
|
|
if (!temp.exists()) {
|
|
@@ -69,20 +70,107 @@ public class FileController extends BaseController {
|
|
|
fileEntity.setCallWord(callWord);
|
|
|
fileEntity.setCreateTime(DateUtil.now());
|
|
|
fileEntity.setUpdateTime(DateUtil.now());
|
|
|
+ fileEntity.setFileStatus("1");
|
|
|
fileEntity = this.fileService.save(fileEntity);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- throw new Exception("文件上传失败");
|
|
|
+ return fail("文件上传失败");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ WebSocketServer.sendInfo(fileEntity.getId());
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ //return fail("消息推送失败");
|
|
|
}
|
|
|
- JSONObject jsonObject = new JSONObject();
|
|
|
- jsonObject.put("fileId",fileEntity.getId());
|
|
|
- jsonObject.put("filePath",fileEntity.getFilePath());
|
|
|
- WebSocketServer.sendInfo(jsonObject.toJSONString());
|
|
|
- fileEntity.setFileStatus("2");
|
|
|
- this.fileService.save(fileEntity);
|
|
|
}
|
|
|
}
|
|
|
- return success(FILEDIR+fileName);
|
|
|
+ return success(null,"上传成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "文件下载")
|
|
|
+ @GetMapping("/fileDownload")
|
|
|
+ @ResponseBody
|
|
|
+ public Result download(HttpServletResponse response, @RequestParam String fileId ) throws Exception {
|
|
|
+ FileEntity fileEntity = null;
|
|
|
+ String fileName = "";
|
|
|
+ try {
|
|
|
+ fileEntity= this.fileService.findById(fileId);
|
|
|
+ String filePath = fileEntity.getFilePath();
|
|
|
+ File fileReturn = new File(filePath);
|
|
|
+ fileName = fileReturn.getName();
|
|
|
+ FileUtil.downloadFile(response,fileReturn,fileName,false);
|
|
|
+ }catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return fail("下载失败");
|
|
|
+ }
|
|
|
+ return success(null,"下载成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改文件状态
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "修改文件状态",notes = "参数包括:fileId:唯一标识,fileStatus:文件状态码 2--开始解密;3--解密完成。示例:{\"fileId\":\"8af1788593b4d21b0193b4d2281a0000\",\"fileStatus\":\"2\"}")
|
|
|
+ @PostMapping("/updateFileStatus")
|
|
|
+ @ResponseBody
|
|
|
+ public Result updateFileStatus(@RequestBody String jsonParam) {
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(jsonParam);
|
|
|
+ if (!jsonObject.containsKey("fileId") || StringUtils.isEmpty(jsonObject.getString("fileId")))
|
|
|
+ return failBadRequest(null, "用户id不能为空!");
|
|
|
+ if (!jsonObject.containsKey("fileStatus") || StringUtils.isEmpty(jsonObject.getString("fileStatus")))
|
|
|
+ return failBadRequest(null, "文件状态码不能为空!");
|
|
|
+ String fileId = jsonObject.getString("fileId");
|
|
|
+ FileEntity fileEntity = this.fileService.findById(fileId);
|
|
|
+ if (fileEntity == null){
|
|
|
+ return fail("用户id错误");
|
|
|
+ }
|
|
|
+ String fileStatus = jsonObject.getString("fileStatus");
|
|
|
+ fileEntity.setFileStatus(fileStatus);
|
|
|
+ fileEntity.setUpdateTime(DateUtil.now());
|
|
|
+ this.fileService.save(fileEntity);
|
|
|
+ return success(null,"修改成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改密码
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "修改密码",notes = "参数包括:fileId:唯一标识,password:密码。示例:{\"fileId\":\"8af1788593b4d21b0193b4d2281a0000\",\"password\":\"123456\"}")
|
|
|
+ @PostMapping("/updatePassword")
|
|
|
+ @ResponseBody
|
|
|
+ public Result updatePassword(@RequestBody String jsonParam) {
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(jsonParam);
|
|
|
+ if (!jsonObject.containsKey("fileId") || StringUtils.isEmpty(jsonObject.getString("fileId")))
|
|
|
+ return failBadRequest(null, "用户id不能为空!");
|
|
|
+ if (!jsonObject.containsKey("password") || StringUtils.isEmpty(jsonObject.getString("password")))
|
|
|
+ return failBadRequest(null, "新密码不能为空!");
|
|
|
+ String password = jsonObject.getString("password");
|
|
|
+ String fileId = jsonObject.getString("fileId");
|
|
|
+ FileEntity fileEntity = this.fileService.findById(fileId);
|
|
|
+ //根据邮箱查询用户信息
|
|
|
+ String email = fileEntity.getEmail();
|
|
|
+ if (email != null) {
|
|
|
+ SendEmail sendEmail = new SendEmail();
|
|
|
+ //破解密码
|
|
|
+ sendEmail.setPassword(password);
|
|
|
+ //破解的文件名
|
|
|
+ String[] fileNames = fileEntity.getFilePath().split("-=-");
|
|
|
+ String fileName = fileNames[fileNames.length - 1];
|
|
|
+ sendEmail.setFileName(fileName);
|
|
|
+
|
|
|
+ //设置要发送的邮箱
|
|
|
+ sendEmail.setReceiveMailAccount(email);
|
|
|
+ try {
|
|
|
+ sendEmail.Send();
|
|
|
+ fileEntity.setFileStatus("4");
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ fileEntity.setFileStatus("3");
|
|
|
+ }
|
|
|
+ fileEntity.setPassword(password);
|
|
|
+ fileEntity.setUpdateTime(DateUtil.now());
|
|
|
+ this.fileService.save(fileEntity);
|
|
|
+ return success(null,"修改成功");
|
|
|
}
|
|
|
|
|
|
}
|