|
@@ -7,12 +7,16 @@ import com.hssx.ysofficial.service.ArticleService;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.hssx.ysofficial.utility.HttpRespMsg;
|
|
import com.hssx.ysofficial.utility.HttpRespMsg;
|
|
import org.hibernate.validator.constraints.EAN;
|
|
import org.hibernate.validator.constraints.EAN;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
+import java.io.File;
|
|
import java.sql.SQLOutput;
|
|
import java.sql.SQLOutput;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
/**
|
|
/**
|
|
* <p>
|
|
* <p>
|
|
@@ -24,6 +28,13 @@ import java.util.Map;
|
|
*/
|
|
*/
|
|
@Service
|
|
@Service
|
|
public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> implements ArticleService {
|
|
public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> implements ArticleService {
|
|
|
|
+
|
|
|
|
+ @Value("${upload.path}")
|
|
|
|
+ private String uploadPath;
|
|
|
|
+
|
|
|
|
+ @Value("${download.path}")
|
|
|
|
+ private String downloadPath;
|
|
|
|
+
|
|
@Resource
|
|
@Resource
|
|
private ArticleMapper articleMapper;
|
|
private ArticleMapper articleMapper;
|
|
|
|
|
|
@@ -56,11 +67,29 @@ public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> impl
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public HttpRespMsg editArticle(Article article){
|
|
|
|
|
|
+ public HttpRespMsg editArticle(Article article, MultipartFile multipartFile){
|
|
HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
if(article != null){
|
|
if(article != null){
|
|
Integer id = article.getId();
|
|
Integer id = article.getId();
|
|
- if(id == null){
|
|
|
|
|
|
+
|
|
|
|
+ if(multipartFile != null){
|
|
|
|
+ String fileName = multipartFile.getOriginalFilename();
|
|
|
|
+ File direction = new File(uploadPath);
|
|
|
|
+ String rand = UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
|
+ String suffix = fileName.substring(fileName.lastIndexOf("."));
|
|
|
|
+ String storedFileName = rand + suffix;
|
|
|
|
+ try {
|
|
|
|
+ File savedFile = new File(direction, storedFileName);
|
|
|
|
+ savedFile.createNewFile();
|
|
|
|
+ multipartFile.transferTo(savedFile);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ article.setImageUrl("/upload/" + storedFileName);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(id == -1){
|
|
|
|
+ article.setId(null);
|
|
article.setPosition(articleMapper.getNewPosition());
|
|
article.setPosition(articleMapper.getNewPosition());
|
|
articleMapper.insert(article);
|
|
articleMapper.insert(article);
|
|
}else{
|
|
}else{
|