attachment修复
This commit is contained in:
parent
88bd3352d5
commit
f1477eb60d
@ -21,9 +21,8 @@ public class ConfigController {
|
||||
AttachmentService attachmentService;
|
||||
@RequestMapping("/updateConfig")
|
||||
public String updateConfig(Config config){
|
||||
Date date=new Date();
|
||||
try {
|
||||
config.setUpdatetime(date.getTime());
|
||||
|
||||
if (config.getName().equals("")||config.getValue().equals("")){
|
||||
return "配置文件不能为空!";
|
||||
}
|
||||
@ -44,8 +43,7 @@ public class ConfigController {
|
||||
if (config.getName().equals("")||config.getValue().equals("")){
|
||||
return "属性值不能为空";
|
||||
}else {
|
||||
Date date=new Date();
|
||||
config.setUpdatetime(date.getTime());
|
||||
|
||||
return configService.addConfig(config);
|
||||
}
|
||||
}catch (NullPointerException e){
|
||||
|
@ -15,7 +15,7 @@ public interface AttachmentDao {
|
||||
|
||||
Attachment selectByPrimaryKey(Long id);
|
||||
|
||||
int updateByPrimaryKeySelective(Attachment record);
|
||||
int updateByPrimaryKeySelective(Attachment attachment);
|
||||
|
||||
int updateByPrimaryKey(Attachment record);
|
||||
}
|
@ -10,9 +10,11 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public interface AttachmentService {
|
||||
HashMap<String,String> upload(MultipartFile file,String cate,Long id) throws IOException;
|
||||
HashMap<String,String> upload(MultipartFile file,String cate) throws IOException;
|
||||
|
||||
public HashMap<String,String>storeFile(MultipartFile multipartFile,String cate) throws IOException;
|
||||
public HashMap<String,String>updateFile(MultipartFile multipartFile,String cate,Config config) throws IOException;
|
||||
|
||||
public HashMap<String,String>storeFile(MultipartFile multipartFile,String cate,Long id) throws IOException;
|
||||
|
||||
public Attachment selectAttachment(Long id);
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import com.lovenav.entity.Config;
|
||||
import com.lovenav.service.AttachmentService;
|
||||
import com.lovenav.utils.MD5Utils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.checkerframework.checker.units.qual.C;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
@ -29,12 +30,12 @@ public class AttachmentServiceImpl implements AttachmentService {
|
||||
AttachmentDao attachmentDao;
|
||||
|
||||
@Override
|
||||
public HashMap<String,String> upload(MultipartFile file,String cate,Long id) throws IOException {
|
||||
HashMap<String, String> map = storeFile(file,cate,id);
|
||||
public HashMap<String,String> upload(MultipartFile file,String cate) throws IOException {
|
||||
HashMap<String, String> map = storeFile(file,cate);
|
||||
return map;
|
||||
}
|
||||
@Override
|
||||
public HashMap<String, String> storeFile(MultipartFile multipartFile,String cate,Long id) throws IOException {
|
||||
public HashMap<String, String> storeFile(MultipartFile multipartFile,String cate) throws IOException {
|
||||
HashMap<String,String> map = new HashMap<>();
|
||||
Attachment attachment=new Attachment();
|
||||
File path = null;
|
||||
@ -66,7 +67,8 @@ public class AttachmentServiceImpl implements AttachmentService {
|
||||
attachment.setSuffix(suffix);
|
||||
attachment.setMd5(MD5Utils.md5(upload.getAbsolutePath()+ relPath));
|
||||
attachment.setStorage("local");
|
||||
attachment.setId(id);
|
||||
// attachment.setId(id);
|
||||
|
||||
attachmentDao.insertSelective(attachment);
|
||||
map.put("id", String.valueOf(attachment.getId()));
|
||||
multipartFile.transferTo(fileUp);
|
||||
@ -80,6 +82,56 @@ public class AttachmentServiceImpl implements AttachmentService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, String> updateFile(MultipartFile multipartFile, String cate, Config config) throws IOException {
|
||||
HashMap<String,String> map = new HashMap<>();
|
||||
Attachment attachment=new Attachment();
|
||||
File path = null;
|
||||
try {
|
||||
path = new File(ResourceUtils.getURL("classpath:").getPath());
|
||||
File upload = new File(path.getAbsolutePath(),"static/"+cate+"/");
|
||||
Date date=new Date();
|
||||
|
||||
DateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
DateFormat format1 = new SimpleDateFormat("yyyyMM");
|
||||
String date1=format.format(date);
|
||||
String fileName = multipartFile.getOriginalFilename();//文件全名
|
||||
String date2=format1.format(date);
|
||||
File parentDir = new File(upload.getAbsolutePath()+"/" + date2);
|
||||
if(!upload.exists()){
|
||||
upload.mkdirs();
|
||||
}
|
||||
if(!parentDir.exists()){
|
||||
parentDir.mkdirs();
|
||||
}
|
||||
String suffix = suffix(fileName);//文件后缀
|
||||
String finalFileName=UUID.randomUUID().toString().replaceAll("-","");
|
||||
String relPath = "/" + date2 + "/" + finalFileName + suffix;
|
||||
File fileUp = new File(upload.getAbsolutePath()+ relPath);
|
||||
|
||||
attachment.setCreatetime(date);
|
||||
attachment.setFileName(finalFileName);
|
||||
attachment.setPath(upload.getAbsolutePath()+ "/" + date2 + "/");
|
||||
attachment.setSuffix(suffix);
|
||||
attachment.setMd5(MD5Utils.md5(upload.getAbsolutePath()+ relPath));
|
||||
attachment.setStorage("local");
|
||||
attachment.setId(Long.valueOf(config.getValue()));
|
||||
// attachment.setId(id);
|
||||
attachmentDao.updateByPrimaryKeySelective(attachment);
|
||||
// map.put("id", String.valueOf(attachment.getId()));
|
||||
map.put("msg","更新成功!");
|
||||
map.put("id", String.valueOf(attachment.getId()));
|
||||
multipartFile.transferTo(fileUp);
|
||||
map.put("url", "/img" + relPath);
|
||||
log.info(relPath);
|
||||
return map;
|
||||
} catch (FileNotFoundException e) {
|
||||
throw e;
|
||||
} catch (IOException e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Attachment selectAttachment(Long id) {
|
||||
Attachment attachment=attachmentDao.selectByPrimaryKey(id);
|
||||
|
@ -6,6 +6,7 @@ import com.lovenav.service.ConfigService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
@Service
|
||||
public class ConfigServiceImpl implements ConfigService {
|
||||
@ -18,6 +19,8 @@ public class ConfigServiceImpl implements ConfigService {
|
||||
|
||||
@Override
|
||||
public int updateConfig(Config config) {
|
||||
Date date=new Date();
|
||||
config.setUpdatetime(date.getTime());
|
||||
if (configDao.selectByName(config.getName())==null){
|
||||
return 2;
|
||||
}
|
||||
@ -29,6 +32,8 @@ public class ConfigServiceImpl implements ConfigService {
|
||||
if(configDao.selectByName(config.getName())!=null){
|
||||
return "该配置文件已经存在!";
|
||||
}else {
|
||||
Date date=new Date();
|
||||
config.setUpdatetime(date.getTime());
|
||||
int result=configDao.insertSelective(config);
|
||||
if (result==1){
|
||||
return "添加成功!";
|
||||
|
Loading…
Reference in New Issue
Block a user