Commit 8feb14c6 authored by gaoyingwei's avatar gaoyingwei

修改 上传文件

parent 3d7444ac
......@@ -26,6 +26,7 @@ import org.rcisoft.sys.ossinfo.entity.OssInfo;
import org.rcisoft.sys.ossinfo.service.OssInfoService;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List;
/**
......@@ -138,7 +139,7 @@ public class OssInfoController extends CyPaginationController<OssInfo> {
@ApiImplicitParams({@ApiImplicitParam(name = "file", value = "文件", required = true, dataType = "file")})
@PostMapping(value = "/fileUpload")
@ResponseBody
public CyResult comFileUpload(@RequestParam("file") MultipartFile file, @RequestParam("temp") String temp) {
public CyResult comFileUpload(@RequestParam("file") MultipartFile file, @RequestParam("temp") String temp) throws IOException {
return CyResultGenUtil.builder(new CyPersistModel(1),
CyMessCons.MESSAGE_ALERT_SUCCESS,
CyMessCons.MESSAGE_ALERT_ERROR,
......
......@@ -7,6 +7,7 @@ import org.rcisoft.core.model.CyPageInfo;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.util.List;
/**
......@@ -64,7 +65,7 @@ public interface OssInfoService {
*/
List<OssInfo> export(OssInfo ossInfo);
OssInfo filePath(MultipartFile file, String temp);
OssInfo filePath(MultipartFile file, String temp) throws IOException;
}
......@@ -18,6 +18,7 @@ import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.rcisoft.core.model.CyPageInfo;
import java.io.IOException;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
......@@ -128,7 +129,7 @@ public class OssInfoServiceImpl extends ServiceImpl<OssInfoRepository, OssInfo>
}
@Override
public OssInfo filePath(MultipartFile file, String temp) {
public OssInfo filePath(MultipartFile file, String temp) throws IOException {
OssInfo cyFileEntity = ossINfoUtil.filePath(file, temp);
baseMapper.insert(cyFileEntity);
cyFileEntity.setUrl(baseDiscovery + cyFileEntity.getUrl());
......
package org.rcisoft.sys.ossinfo.util;
import cn.hutool.core.io.FileUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.rcisoft.core.util.CyDateUtil;
import org.rcisoft.sys.ossinfo.entity.OssInfo;
import org.springframework.beans.factory.annotation.Value;
......@@ -30,7 +32,7 @@ public class OssINfoUtil {
@Value("${global.path.base_upload_location}")
private String baseUploadLocation;
public OssInfo filePath(MultipartFile multipartFile, String temp) {
public OssInfo filePath(MultipartFile multipartFile, String temp) throws IOException {
OssInfo cyFileEntity = new OssInfo();
// 原文件名
String originalName = multipartFile.getOriginalFilename();
......@@ -39,8 +41,14 @@ public class OssINfoUtil {
String finalSavingPath;
String savingPatternOrFullName = SAVING_PATTERN_UUID;
String savingAbsolutePath = baseUploadLocation + File.separator +
String savingAbsolutePath = "";
if (StringUtils.isNotBlank(temp))
savingAbsolutePath = baseUploadLocation + File.separator +
temp + File.separator + CyDateUtil.getSimpleDate("yyyyMMdd", new Date());
else
savingAbsolutePath = baseUploadLocation + File.separator +
CyDateUtil.getSimpleDate("yyyyMMdd", new Date());
// log.error("savingAbsolutePath"+savingAbsolutePath);
String returnFinalFileName = "";
label32:
{
......@@ -74,19 +82,31 @@ public class OssINfoUtil {
cyFileEntity.setPath(path);
cyFileEntity.setUrl(path);
cyFileEntity.setMd5(getMd5(multipartFile));
File dir = new File(savingAbsolutePath);
if (!dir.exists()) {
dir.mkdirs();
}
// File dir = new File(savingAbsolutePath);
// if (!dir.exists()) {
// dir.mkdirs();
// }
// if(!FileUtil.exist(savingAbsolutePath)){
// FileUtil.mkdir(savingAbsolutePath);
// }
// log.error("savingAbsolutePath"+savingAbsolutePath);
// log.error("finalSavingPath"+finalSavingPath);
// try {
File file = new File(finalSavingPath);
try {
if(!FileUtil.exist(file.getParentFile())){
FileUtil.mkdir(file.getParentFile());
log.error("file.getParentFile()"+file.getParentFile());
}
// log.error("file.getParentFile()"+file.getParentFile());
if (!file.exists() && file.createNewFile())
multipartFile.transferTo(file);
} catch (IllegalStateException var10) {
log.error(var10.getMessage());
} catch (IOException var11) {
log.error(var11.getMessage());
}
// } catch (IllegalStateException var10) {
// log.error(var10.getMessage());
// } catch (IOException var11) {
// log.error(var11.getMessage());
// }
return cyFileEntity;
}
......
......@@ -333,6 +333,7 @@
update sys_user
<trim prefix="SET" suffixOverrides=",">
<if test="entity.name != null and entity.name !='' ">name = #{entity.name},</if>
<if test="entity.faceAddress != null and entity.faceAddress !='' ">face_address = #{entity.faceAddress},</if>
<if test="entity.sex != null and entity.sex !=''">sex = #{entity.sex},</if>
<if test="entity.attendanceShow != null and entity.attendanceShow !=''">attendance_show =
#{entity.attendanceShow},
......
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