|
@@ -12,6 +12,12 @@ 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.apache.http.HttpEntity;
|
|
|
+import org.apache.http.HttpResponse;
|
|
|
+import org.apache.http.client.methods.HttpPost;
|
|
|
+import org.apache.http.entity.mime.MultipartEntityBuilder;
|
|
|
+import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
+import org.apache.http.impl.client.HttpClients;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.stereotype.Controller;
|
|
@@ -77,7 +83,13 @@ public class FileController extends BaseController {
|
|
|
return fail("文件上传失败");
|
|
|
}
|
|
|
try {
|
|
|
- WebSocketServer.sendInfo(fileEntity.getId());
|
|
|
+ HttpResponse response = HttpClient(fileEntity.getFilePath(),fileEntity.getId());
|
|
|
+ if (response.getStatusLine().getStatusCode() == 200){
|
|
|
+ fileEntity.setFileStatus("2");
|
|
|
+ fileEntity.setUpdateTime(DateUtil.now());
|
|
|
+ this.fileService.save(fileEntity);
|
|
|
+ }
|
|
|
+ //WebSocketServer.sendInfo(fileEntity.getId());
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
//return fail("消息推送失败");
|
|
@@ -139,12 +151,19 @@ public class FileController extends BaseController {
|
|
|
public Result updatePassword(@RequestBody String jsonParam) {
|
|
|
JSONObject jsonObject = JSONObject.parseObject(jsonParam);
|
|
|
if (!jsonObject.containsKey("fileId") || StringUtils.isEmpty(jsonObject.getString("fileId")))
|
|
|
- return failBadRequest(null, "用户id不能为空!");
|
|
|
+ return failBadRequest(null, "uuid不能为空!");
|
|
|
if (!jsonObject.containsKey("password") || StringUtils.isEmpty(jsonObject.getString("password")))
|
|
|
- return failBadRequest(null, "新密码不能为空!");
|
|
|
+ return failBadRequest(null, "密码不能为空!");
|
|
|
String password = jsonObject.getString("password");
|
|
|
String fileId = jsonObject.getString("fileId");
|
|
|
FileEntity fileEntity = this.fileService.findById(fileId);
|
|
|
+ if (fileEntity == null){
|
|
|
+ return failBadRequest(null, "uuid错误!");
|
|
|
+ }
|
|
|
+ fileEntity.setPassword(password);
|
|
|
+ fileEntity.setUpdateTime(DateUtil.now());
|
|
|
+ fileEntity.setFileStatus("3");
|
|
|
+ this.fileService.save(fileEntity);
|
|
|
//根据邮箱查询用户信息
|
|
|
String email = fileEntity.getEmail();
|
|
|
if (email != null) {
|
|
@@ -161,16 +180,35 @@ public class FileController extends BaseController {
|
|
|
try {
|
|
|
sendEmail.Send();
|
|
|
fileEntity.setFileStatus("4");
|
|
|
+ fileEntity.setUpdateTime(DateUtil.now());
|
|
|
+ this.fileService.save(fileEntity);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- } else {
|
|
|
- fileEntity.setFileStatus("3");
|
|
|
}
|
|
|
- fileEntity.setPassword(password);
|
|
|
- fileEntity.setUpdateTime(DateUtil.now());
|
|
|
- this.fileService.save(fileEntity);
|
|
|
return success(null,"修改成功");
|
|
|
}
|
|
|
|
|
|
+ public static HttpResponse HttpClient(String filePath, String fileId) {
|
|
|
+ CloseableHttpClient httpclient = HttpClients.createDefault();
|
|
|
+ HttpPost httpPost = new HttpPost("http://10.113.248.201:9999/api/uploadfile/?file_uuid="+fileId);
|
|
|
+ MultipartEntityBuilder builder = MultipartEntityBuilder.create();
|
|
|
+ builder.addBinaryBody("file", new File(filePath));
|
|
|
+ HttpEntity multipart = builder.build();
|
|
|
+ httpPost.setEntity(multipart);
|
|
|
+ HttpResponse response = null;
|
|
|
+ try {
|
|
|
+ response = httpclient.execute(httpPost);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ httpclient.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+
|
|
|
}
|