Commit fcde211d authored by 周健威's avatar 周健威

修改代码

parent 45b44dd0
...@@ -14,6 +14,8 @@ import com.upyuns.platform.rs.universal.service.UploadZipService; ...@@ -14,6 +14,8 @@ import com.upyuns.platform.rs.universal.service.UploadZipService;
import com.upyuns.platform.rs.universal.utils.ImgBase64Util; import com.upyuns.platform.rs.universal.utils.ImgBase64Util;
import com.upyuns.platform.rs.universal.utils.PublicMsg; import com.upyuns.platform.rs.universal.utils.PublicMsg;
import com.upyuns.platform.rs.universal.vo.Ueditor; import com.upyuns.platform.rs.universal.vo.Ueditor;
import com.upyuns.platform.rs.website.entity.FileData;
import com.upyuns.platform.rs.website.entity.GainData;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.Data; import lombok.Data;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -141,16 +143,24 @@ public class UploadController{ ...@@ -141,16 +143,24 @@ public class UploadController{
@RequestParam(value = "prefix",defaultValue = "admin")String prefix @RequestParam(value = "prefix",defaultValue = "admin")String prefix
)throws Exception { )throws Exception {
String contentType = file.getContentType(); //图片文件类型 String contentType = file.getContentType(); //图片文件类型
// String fileName = file.getOriginalFilename(); //图片名字
/* if (!contentType.equals("image/jpeg") && !contentType.equals("image/gif")&&!contentType.equals("image/png")) {
return JsonResultUtil.createFailedResult(2001,"格式不对!!!");
}*/
// if (file.getSize() > MAX_DRIVING_LICENSE_SIZE) {
// return JsonResultUtil.createFailedResult(2002,"大小超过限制!!!");
// }
return JsonResultUtil.createSuccessResultWithObj(uploadService.uploadFileAndGetFileInfo(file,prefix)); return JsonResultUtil.createSuccessResultWithObj(uploadService.uploadFileAndGetFileInfo(file,prefix));
} }
/**
* 上传成果文件
* @param file
* @param prefix gainDataId
* @return
* @throws Exception
*/
@RequestMapping(value = "/app/unauth/admin/uploadGainFile", method = RequestMethod.POST)
public ObjectRestResponse uploadGainFile(
@RequestParam("file") MultipartFile file,
@RequestParam(value = "prefix",defaultValue = "admin")String prefix
)throws Exception {
FileData data = uploadService.uploadGainFile(file,prefix);
return ObjectRestResponse.succ(data);
}
// @PostMapping("/app/unauth/download") // @PostMapping("/app/unauth/download")
// public byte[] downloadFile(@RequestBody String fileUrl) { // public byte[] downloadFile(@RequestBody String fileUrl) {
......
...@@ -38,8 +38,13 @@ import java.util.concurrent.TimeUnit; ...@@ -38,8 +38,13 @@ import java.util.concurrent.TimeUnit;
public class UploadService { public class UploadService {
public static final DateTimeFormatter DEFAULT_DATE_TIME_FORMATTER = DateTimeFormat.forPattern("yyyy-MM-dd"); public static final DateTimeFormatter DEFAULT_DATE_TIME_FORMATTER = DateTimeFormat.forPattern("yyyy-MM-dd");
public static final DateTimeFormatter GAINFILE_DATE_TIME_FORMATTER = DateTimeFormat.forPattern("yyMMdd");
@Value("${universal.baseUploadPath}") @Value("${universal.baseUploadPath}")
private String baseUploadPath ; private String baseUploadPath ;
@Value("${universal.gaindataPath}")
private String gaindataPath ;
@Value("${universal.videoUploadPath}") @Value("${universal.videoUploadPath}")
private String videoUploadPath ; private String videoUploadPath ;
...@@ -138,6 +143,37 @@ public class UploadService { ...@@ -138,6 +143,37 @@ public class UploadService {
return fileData; return fileData;
} }
public FileData uploadGainFile(MultipartFile file, String prefix) throws Exception{
//创建本日存放目录
DateTime now = DateTime.now();
String dirPath = "/"+prefix;
String todayStr = now.toString(GAINFILE_DATE_TIME_FORMATTER);
String redisNoKey = RedisKey.UPLOAD_FILE_NO_PREFIX + now.toString(DEFAULT_DATE_TIME_FORMATTER);
Long no = redisTemplate.opsForValue().increment(redisNoKey);
if(no.equals(1l)){
redisTemplate.expire(redisNoKey,1, TimeUnit.DAYS);
}
String noStr = todayStr + "_" + no;
String fileName = file.getOriginalFilename();
String realFileRelPath = gaindataPath + dirPath + "/" + noStr + fileName.substring(fileName.lastIndexOf("."));
String filetype = fileName.substring(fileName.lastIndexOf("."));
long fileSize = file.getSize();
double fileSizeInMB = (double) fileSize / (1024 * 1024); // 转换为 MB
double roundedFileSizeInMB = Math.round(fileSizeInMB * 100.0) / 100.0; // 保留两位小数
String fileSizeString = String.format("%.2f MB", roundedFileSizeInMB);
//文件存放路径
String filePath = baseUploadPath + realFileRelPath;
//将文件写入指定位置
FileUtils.copyInputStreamToFile(file.getInputStream(), new File(filePath));
realFileRelPath=xx_url+SystemConfig.XXMP_URL+realFileRelPath;
FileData fileData = new FileData();
fileData.setFilename(fileName);
fileData.setFiletype(filetype);
fileData.setFilesize(fileSizeString);
fileData.setFileurl(realFileRelPath);
fileData.setFilepath(filePath);
return fileData;
}
// public String uploadFile250(MultipartFile file, String prefix) throws Exception { // public String uploadFile250(MultipartFile file, String prefix) throws Exception {
//// // 创建本日存放目录 //// // 创建本日存放目录
......
...@@ -71,6 +71,7 @@ public class FileData implements Serializable { ...@@ -71,6 +71,7 @@ public class FileData implements Serializable {
@Column(name = "crt_time") @Column(name = "crt_time")
@ApiModelProperty(value = "创建时间", hidden = true ) @ApiModelProperty(value = "创建时间", hidden = true )
private Date crtTime; private Date crtTime;
@ApiModelProperty(value = "文件服务器路径")
private String filepath;
} }
...@@ -103,6 +103,16 @@ public class GainData implements Serializable { ...@@ -103,6 +103,16 @@ public class GainData implements Serializable {
@Column(name = "menu_id") @Column(name = "menu_id")
@ApiModelProperty(value = "菜单id") @ApiModelProperty(value = "菜单id")
private Integer menuId; private Integer menuId;
@Column(name = "data_path")
@ApiModelProperty(value = "数据路径")
private String dataPath;
@Column(name = "gtdata_path")
@ApiModelProperty(value = "gtdata路径")
private String gtdataPath;
@Column(name = "has_gtdata")
@ApiModelProperty(value = "是否已经存储gtdata 0--未处理;1--已处理;2--已更新")
private Integer hasGtdata;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment