可以对资源进行增删改
This commit is contained in:
@@ -3,6 +3,10 @@ package com.quinn.common;
|
||||
public interface QuinnConstant {
|
||||
|
||||
String LINK_SUFFIX = ".";
|
||||
|
||||
String LINK_KEY_WORD = ",";
|
||||
|
||||
String LINK_DATE_STR = "_";
|
||||
/**
|
||||
* REDIS PATTEN
|
||||
*/
|
||||
@@ -11,5 +15,9 @@ public interface QuinnConstant {
|
||||
String GUN = "The emperor's new clothes";
|
||||
|
||||
String SOURCE_KEY = "SOURCE_KEY_";
|
||||
/**
|
||||
* PASSWORD //TODO 可以配置数据库MD5加密
|
||||
*/
|
||||
String SOURCE_PASSWORD = "926462";
|
||||
|
||||
}
|
||||
|
||||
14
src/main/java/com/quinn/common/SourceType.java
Normal file
14
src/main/java/com/quinn/common/SourceType.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package com.quinn.common;
|
||||
|
||||
public enum SourceType {
|
||||
|
||||
/**
|
||||
* OSS文件
|
||||
*/
|
||||
OSS,
|
||||
/**
|
||||
* 百度网盘
|
||||
*/
|
||||
BAIDU
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.quinn.config;
|
||||
|
||||
import com.quinn.common.SourceType;
|
||||
import com.quinn.service.impl.UserServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -27,6 +28,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
http.authorizeRequests()
|
||||
.antMatchers("/","/index").permitAll()
|
||||
.antMatchers("/register","/login","/toLogin").permitAll()
|
||||
.antMatchers("/tracy/mcgrady/lmq/love/wn").permitAll()
|
||||
.antMatchers("/*").authenticated();
|
||||
|
||||
// 登录配置
|
||||
|
||||
@@ -26,11 +26,19 @@ public class LoginController {
|
||||
@Autowired
|
||||
UserInfoService userInfoService;
|
||||
|
||||
@GetMapping({"/","/index"})
|
||||
@GetMapping({"/","/index","/source/view/index",
|
||||
"/tracy/mcgrady/lmq/love/wn/index",
|
||||
"/blog/read/index"
|
||||
})
|
||||
public String index(){
|
||||
return "index";
|
||||
}
|
||||
|
||||
@GetMapping("/error/check")
|
||||
public String error(){
|
||||
return "error/check";
|
||||
}
|
||||
|
||||
@GetMapping("/toLogin")
|
||||
public String toLogin(){
|
||||
return "login";
|
||||
|
||||
@@ -22,7 +22,8 @@ import java.util.List;
|
||||
* @author limqsh
|
||||
* @since 2020-06-28
|
||||
*/
|
||||
@Controller
|
||||
//@Controller
|
||||
@Deprecated
|
||||
public class QuestionCategoryController {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -35,7 +35,8 @@ import java.util.UUID;
|
||||
* @author limqsh
|
||||
* @since 2020-06-28
|
||||
*/
|
||||
@Controller
|
||||
//@Controller
|
||||
@Deprecated
|
||||
public class QuestionController {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.quinn.controller;
|
||||
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
/**
|
||||
* <p>
|
||||
* 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author limqsh
|
||||
* @since 2022-05-03
|
||||
*/
|
||||
@Controller
|
||||
public class SourceCommentController {
|
||||
|
||||
}
|
||||
|
||||
@@ -4,11 +4,13 @@ package com.quinn.controller;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.quinn.common.QuinnConstant;
|
||||
import com.quinn.common.SourceType;
|
||||
import com.quinn.pojo.*;
|
||||
import com.quinn.pojo.param.QuerySource;
|
||||
import com.quinn.service.SourceCategoryService;
|
||||
import com.quinn.service.SourceCommentService;
|
||||
import com.quinn.service.SourceService;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.ui.Model;
|
||||
@@ -53,6 +55,10 @@ public class SourceController {
|
||||
if (!CollectionUtils.isEmpty(sourceList)){
|
||||
sourceList.forEach(x ->{
|
||||
x.setSourceLink(QuinnConstant.GUN);
|
||||
x.setKeyWord1(QuinnConstant.GUN);
|
||||
x.setKeyWord2(QuinnConstant.GUN);
|
||||
x.setKeyWord3(QuinnConstant.GUN);
|
||||
x.setSourceContent(QuinnConstant.GUN);
|
||||
});
|
||||
}
|
||||
model.addAttribute("sourceList",sourceList);
|
||||
@@ -97,7 +103,10 @@ public class SourceController {
|
||||
if (!CollectionUtils.isEmpty(sourceList)){
|
||||
sourceList.forEach(x ->{
|
||||
x.setSourceLink(QuinnConstant.GUN);
|
||||
x.setSourceContent("");
|
||||
x.setKeyWord1(QuinnConstant.GUN);
|
||||
x.setKeyWord2(QuinnConstant.GUN);
|
||||
x.setKeyWord3(QuinnConstant.GUN);
|
||||
x.setSourceContent(QuinnConstant.GUN);
|
||||
});
|
||||
}
|
||||
model.addAttribute("sourceList",sourceList);
|
||||
@@ -113,9 +122,13 @@ public class SourceController {
|
||||
*/
|
||||
@GetMapping("/source/view/{sid}")
|
||||
public String read(@PathVariable("sid") String sid, Model model){
|
||||
Source source = sourceService.hotResource(sid);
|
||||
Source source = sourceService.view(sid);
|
||||
if(source != null){
|
||||
source.setSourceLink(QuinnConstant.GUN);
|
||||
source.setKeyWord1(QuinnConstant.GUN);
|
||||
source.setKeyWord2(QuinnConstant.GUN);
|
||||
source.setKeyWord3(QuinnConstant.GUN);
|
||||
source.setSourceType(QuinnConstant.GUN);
|
||||
}
|
||||
model.addAttribute("source",source);
|
||||
List<SourceComment> commentList = sourceCommentService.list(new QueryWrapper<SourceComment>().eq("topic_id", sid).orderByDesc("gmt_create"));
|
||||
@@ -129,13 +142,19 @@ public class SourceController {
|
||||
* @param sid
|
||||
* @throws IOException
|
||||
*/
|
||||
@GetMapping("/source/download/{sid}")
|
||||
@PostMapping("/source/download/{sid}")
|
||||
public void download(HttpServletResponse response, @PathVariable("sid") String sid) throws IOException {
|
||||
Source source = sourceService.getOne(new QueryWrapper<Source>().eq("id", sid));
|
||||
//通知浏览器以附件形式下载
|
||||
response.setHeader("Content-Disposition",
|
||||
"attachment;filename=" + source.getEnName() + QuinnConstant.LINK_SUFFIX + source.getFileType());
|
||||
this.sourceService.downloadSource(response.getOutputStream(),source);
|
||||
Source source = sourceService.getOne(new QueryWrapper<Source>().eq("sid", sid));
|
||||
if (source!=null){
|
||||
if (SourceType.OSS.name().equals(source.getSourceType())){
|
||||
//通知浏览器以附件形式下载
|
||||
response.setHeader("Content-Disposition",
|
||||
"attachment;filename=" + source.getEnName() + QuinnConstant.LINK_SUFFIX + source.getFileType());
|
||||
this.sourceService.downloadSource(response,source);
|
||||
}else {
|
||||
this.sourceService.downloadForBaidu(response,source);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addParam(QueryWrapper<Source> sourceQuery, String name, int category) {
|
||||
|
||||
110
src/main/java/com/quinn/controller/SourceUploadController.java
Normal file
110
src/main/java/com/quinn/controller/SourceUploadController.java
Normal file
@@ -0,0 +1,110 @@
|
||||
package com.quinn.controller;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.quinn.common.QuinnConstant;
|
||||
import com.quinn.pojo.Source;
|
||||
import com.quinn.pojo.SourceCategory;
|
||||
import com.quinn.service.SourceCategoryService;
|
||||
import com.quinn.service.SourceService;
|
||||
import com.quinn.vo.SourceDeleteForm;
|
||||
import com.quinn.vo.SourceUpdateForm;
|
||||
import com.quinn.vo.SourceWriteForm;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author limqsh
|
||||
* @since 2022-05-03
|
||||
*/
|
||||
@Controller
|
||||
public class SourceUploadController {
|
||||
|
||||
@Resource
|
||||
SourceCategoryService sourceCategoryService;
|
||||
@Resource
|
||||
SourceService sourceService;
|
||||
|
||||
// 写文章
|
||||
@GetMapping("/tracy/mcgrady/lmq/love/wn")
|
||||
public String toWrite(Model model){
|
||||
// 分类信息
|
||||
List<SourceCategory> categoryList = sourceCategoryService.list(null);
|
||||
model.addAttribute("categoryList",categoryList);
|
||||
return "source/uploadSource";
|
||||
}
|
||||
|
||||
@PostMapping("/tracy/mcgrady/lmq/love/wn")
|
||||
public synchronized String write(MultipartFile file, SourceWriteForm sourceWriteForm) throws IOException {
|
||||
if (!QuinnConstant.SOURCE_PASSWORD.equals(sourceWriteForm.getUploadPassWord())){
|
||||
return "error/check";
|
||||
}
|
||||
sourceService.uploadNewSource(file,sourceWriteForm);
|
||||
// 重定向到列表页面
|
||||
return "redirect:/source";
|
||||
}
|
||||
|
||||
// 编辑信息
|
||||
@GetMapping("/tracy/mcgrady/lmq/love/wn/{sid}")
|
||||
public String toEdit(@PathVariable("sid") String sid, Model model){
|
||||
Source source = sourceService.getOne(new QueryWrapper<Source>().eq("sid",sid));
|
||||
source.setKeyWord1(concatKeyWord(source.getKeyWord2()) + concatKeyWord(source.getKeyWord2()) + concatKeyWord(source.getKeyWord3()));
|
||||
model.addAttribute("source",source);
|
||||
// 分类信息
|
||||
List<SourceCategory> categoryList = sourceCategoryService.list(null);
|
||||
model.addAttribute("categoryList",categoryList);
|
||||
return "source/editorSource";
|
||||
}
|
||||
|
||||
private String concatKeyWord(String keyWord) {
|
||||
if (!StringUtils.isEmpty(keyWord)) {
|
||||
return keyWord + QuinnConstant.LINK_KEY_WORD;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
// 编辑信息
|
||||
@PostMapping("/tracy/mcgrady/lmq/love/wn/update")
|
||||
public String toEdit(MultipartFile file, SourceUpdateForm sourceUpdateForm) throws IOException {
|
||||
if (!QuinnConstant.SOURCE_PASSWORD.equals(sourceUpdateForm.getUploadPassWord())){
|
||||
return "error/check";
|
||||
}
|
||||
sourceService.updateSource(file,sourceUpdateForm);
|
||||
// 重定向详情页面
|
||||
return "redirect:/source/view/" + sourceUpdateForm.getSid();
|
||||
}
|
||||
|
||||
// 编辑信息
|
||||
@PostMapping("/tracy/mcgrady/lmq/love/wn/del")
|
||||
public void toEdit(HttpServletResponse response, SourceDeleteForm sourceDeleteForm) throws IOException {
|
||||
PrintWriter writer = response.getWriter();
|
||||
if (!QuinnConstant.SOURCE_PASSWORD.equals(sourceDeleteForm.getUploadPassWord())){
|
||||
writer.write("/error/check");
|
||||
writer.flush();
|
||||
writer.close();
|
||||
return;
|
||||
}
|
||||
sourceService.deleteSource(sourceDeleteForm.getSid());
|
||||
// 重定向详情页面
|
||||
writer.write("/source");
|
||||
writer.flush();
|
||||
writer.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author limqsh
|
||||
@@ -31,6 +31,9 @@ public class Source implements Serializable {
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty(value = "资源ID")
|
||||
private String sid;
|
||||
|
||||
@ApiModelProperty(value = "资源名")
|
||||
private String sourceName;
|
||||
|
||||
|
||||
@@ -2,8 +2,12 @@ package com.quinn.service;
|
||||
|
||||
import com.quinn.pojo.Source;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.quinn.vo.SourceUpdateForm;
|
||||
import com.quinn.vo.SourceWriteForm;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
@@ -19,17 +23,38 @@ public interface SourceService extends IService<Source> {
|
||||
|
||||
/**
|
||||
* 下载对应的资源
|
||||
* @param outputStream
|
||||
* @param response
|
||||
* @param source
|
||||
* @throws IOException
|
||||
*/
|
||||
void downloadSource(ServletOutputStream outputStream, Source source) throws IOException;
|
||||
void downloadSource(HttpServletResponse response, Source source) throws IOException;
|
||||
|
||||
void downloadForBaidu(HttpServletResponse response, Source source) throws IOException;
|
||||
|
||||
/**
|
||||
* 点击对应的资源
|
||||
* @throws IOException
|
||||
* @return
|
||||
*/
|
||||
Source hotResource(String sid);
|
||||
Source view(String sid);
|
||||
|
||||
/**
|
||||
* 上传新资源
|
||||
* @param file
|
||||
* @param sourceWriteForm
|
||||
*/
|
||||
void uploadNewSource(MultipartFile file, SourceWriteForm sourceWriteForm) throws IOException;
|
||||
|
||||
/**
|
||||
* 更新资源
|
||||
* @param file
|
||||
* @param sourceUpdateForm
|
||||
*/
|
||||
void updateSource(MultipartFile file, SourceUpdateForm sourceUpdateForm) throws IOException;
|
||||
|
||||
/**
|
||||
* 删除资源
|
||||
* @param sid
|
||||
*/
|
||||
void deleteSource(String sid);
|
||||
}
|
||||
|
||||
@@ -2,20 +2,29 @@ package com.quinn.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.quinn.common.QuinnConstant;
|
||||
import com.quinn.common.SourceType;
|
||||
import com.quinn.mapper.SourceCategoryMapper;
|
||||
import com.quinn.pojo.Source;
|
||||
import com.quinn.mapper.SourceMapper;
|
||||
import com.quinn.pojo.SourceCategory;
|
||||
import com.quinn.service.SourceService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.quinn.utils.OSSClientUtil;
|
||||
import com.quinn.utils.QuinnUtils;
|
||||
import com.quinn.utils.RedisUtils;
|
||||
import com.quinn.vo.SourceUpdateForm;
|
||||
import com.quinn.vo.SourceWriteForm;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -32,14 +41,16 @@ public class SourceServiceImpl extends ServiceImpl<SourceMapper, Source> impleme
|
||||
OSSClientUtil ossClientUtil;
|
||||
@Resource
|
||||
RedisUtils redisUtils;
|
||||
@Resource
|
||||
SourceCategoryMapper sourceCategoryMapper;
|
||||
|
||||
@Override
|
||||
public void downloadSource(ServletOutputStream outputStream, Source source) throws IOException {
|
||||
public void downloadSource(HttpServletResponse response, Source source) throws IOException {
|
||||
String sourceLink = source.getSourceLink();
|
||||
addDownLoadRecord(source);
|
||||
// 读取文件内容。
|
||||
BufferedInputStream in = new BufferedInputStream(ossClientUtil.downloadFile(sourceLink));
|
||||
BufferedOutputStream out = new BufferedOutputStream(outputStream);
|
||||
BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());
|
||||
byte[] buffer = new byte[1024];
|
||||
int lenght = 0;
|
||||
while ((lenght = in.read(buffer)) != -1) {
|
||||
@@ -55,26 +66,137 @@ public class SourceServiceImpl extends ServiceImpl<SourceMapper, Source> impleme
|
||||
}
|
||||
|
||||
@Override
|
||||
public Source hotResource(String sid) {
|
||||
Source source = getOne(new QueryWrapper<Source>().eq("id", sid));
|
||||
public void downloadForBaidu(HttpServletResponse response, Source source) throws IOException {
|
||||
addDownLoadRecord(source);
|
||||
PrintWriter writer = response.getWriter();
|
||||
writer.write(source.getSourceLink());
|
||||
writer.flush();
|
||||
writer.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Source view(String sid) {
|
||||
Source source = getOne(new QueryWrapper<Source>().eq("sid", sid));
|
||||
addDownLoadRecord(source);
|
||||
return source;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uploadNewSource(MultipartFile file, SourceWriteForm sourceWriteForm) throws IOException {
|
||||
// 先进行文件上传成功再落地
|
||||
String fileType = "";
|
||||
String fileLink = sourceWriteForm.getSourceLink();
|
||||
if (file != null && !file.isEmpty() && SourceType.OSS.name().equals(sourceWriteForm.getSourceType())){
|
||||
String originalFilename = file.getOriginalFilename();
|
||||
fileType = originalFilename.substring(originalFilename.lastIndexOf(QuinnConstant.LINK_SUFFIX)).toLowerCase();
|
||||
fileLink = ossClientUtil.uploadFile(QuinnUtils.getUuid() + QuinnConstant.LINK_DATE_STR
|
||||
+ QuinnUtils.getStrFromDate(new Date()), file.getInputStream());
|
||||
}
|
||||
// 构建问题对象
|
||||
Source source = new Source();
|
||||
source.setSid(QuinnUtils.getUuid());
|
||||
source.setEnName(sourceWriteForm.getEnName());
|
||||
source.setFileType(fileType);
|
||||
source.setSourceName(sourceWriteForm.getTitle());
|
||||
source.setDetail(sourceWriteForm.getSubContent());
|
||||
source.setSourceContent(sourceWriteForm.getContent());
|
||||
String keyWords = sourceWriteForm.getKeyWords();
|
||||
if (!StringUtils.isEmpty(keyWords)){
|
||||
//兼容中英文逗号
|
||||
keyWords = keyWords.replaceAll(",",",");
|
||||
String[] split = keyWords.split(QuinnConstant.LINK_KEY_WORD);
|
||||
source.setKeyWord1(split[0]);
|
||||
if (split.length > 1){
|
||||
source.setKeyWord2(split[1]);
|
||||
if (split.length > 2){
|
||||
source.setKeyWord3(split[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
source.setSourceType(sourceWriteForm.getSourceType());
|
||||
source.setSourceLink(fileLink);
|
||||
|
||||
// 类型
|
||||
source.setCategoryId(sourceWriteForm.getCategoryId());
|
||||
SourceCategory category = sourceCategoryMapper.selectById(sourceWriteForm.getCategoryId());
|
||||
source.setCategoryName(category.getCategory());
|
||||
source.setDownRecord(0);
|
||||
source.setGmtCreate(QuinnUtils.getTime());
|
||||
source.setGmtUpdate(QuinnUtils.getTime());
|
||||
// 存储对象
|
||||
save(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSource(MultipartFile file, SourceUpdateForm sourceUpdateForm) throws IOException {
|
||||
Source before = getOne(new QueryWrapper<Source>().eq("sid",sourceUpdateForm.getSid()));
|
||||
String fileType = before.getFileType();
|
||||
// 先进行文件上传成功再落地
|
||||
String fileLink = before.getSourceLink();
|
||||
if (file != null && !file.isEmpty() && SourceType.OSS.name().equals(sourceUpdateForm.getSourceType())){
|
||||
// 上传了新文件,需要删除之前的文件
|
||||
ossClientUtil.deleteFile(before.getSourceLink());
|
||||
String originalFilename = file.getOriginalFilename();
|
||||
fileType = originalFilename.substring(originalFilename.lastIndexOf(QuinnConstant.LINK_SUFFIX)).toLowerCase();
|
||||
fileLink = ossClientUtil.uploadFile(QuinnUtils.getUuid() + QuinnConstant.LINK_DATE_STR
|
||||
+ QuinnUtils.getStrFromDate(new Date()), file.getInputStream());
|
||||
}else if (!SourceType.OSS.name().equals(sourceUpdateForm.getSourceType()) && !StringUtils.isEmpty(sourceUpdateForm.getSourceLink())){
|
||||
fileLink = sourceUpdateForm.getSourceLink();
|
||||
}
|
||||
before.setEnName(sourceUpdateForm.getEnName());
|
||||
before.setFileType(fileType);
|
||||
before.setSourceName(sourceUpdateForm.getSourceName());
|
||||
before.setDetail(sourceUpdateForm.getDetail());
|
||||
before.setSourceContent(sourceUpdateForm.getSourceContent());
|
||||
String keyWords = sourceUpdateForm.getKeyWords();
|
||||
if (!StringUtils.isEmpty(keyWords)){
|
||||
//兼容中英文逗号
|
||||
keyWords = keyWords.replaceAll(",",",");
|
||||
String[] split = keyWords.split(QuinnConstant.LINK_KEY_WORD);
|
||||
before.setKeyWord1(split[0]);
|
||||
if (split.length > 1){
|
||||
before.setKeyWord2(split[1]);
|
||||
if (split.length > 2){
|
||||
before.setKeyWord3(split[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
before.setSourceType(sourceUpdateForm.getSourceType());
|
||||
before.setSourceLink(fileLink);
|
||||
|
||||
// 类型
|
||||
before.setCategoryId(sourceUpdateForm.getCategoryId());
|
||||
SourceCategory category = sourceCategoryMapper.selectById(sourceUpdateForm.getCategoryId());
|
||||
before.setCategoryName(category.getCategory());
|
||||
before.setGmtUpdate(QuinnUtils.getTime());
|
||||
updateById(before);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteSource(String sid) {
|
||||
Source before = getOne(new QueryWrapper<Source>().eq("sid",sid));
|
||||
if (SourceType.OSS.name().equals(before.getSourceType())){
|
||||
// 上传了新文件,需要删除之前的文件
|
||||
ossClientUtil.deleteFile(before.getSourceLink());
|
||||
}
|
||||
removeById(before);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新页码
|
||||
* @param source
|
||||
*/
|
||||
private void addDownLoadRecord(Source source) {
|
||||
String downLoadTime = redisUtils.get(QuinnConstant.SOURCE_KEY + source.getId());
|
||||
String downLoadTime = redisUtils.get(QuinnConstant.SOURCE_KEY + source.getSid());
|
||||
int downTimes = 0;
|
||||
if (StringUtils.isEmpty(downLoadTime)){
|
||||
downTimes = source.getDownRecord() + 1;
|
||||
}else {
|
||||
downTimes = Integer.parseInt(downLoadTime) + 1;
|
||||
}
|
||||
redisUtils.set(QuinnConstant.SOURCE_KEY + source.getId(),downTimes + "");
|
||||
redisUtils.set(QuinnConstant.SOURCE_KEY + source.getSid(),downTimes + "");
|
||||
source.setDownRecord(source.getDownRecord() + 1);
|
||||
updateById(source);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -49,8 +49,10 @@ public class OSSClientUtil {
|
||||
private String url;
|
||||
private OSSClient ossClient;
|
||||
|
||||
public String upload(String filename, InputStream file) {
|
||||
return uploadImg(file, filename);
|
||||
String SAVE_DIR = "data/recovery/";
|
||||
|
||||
public String uploadFile(String filename, InputStream file) {
|
||||
return uploadFile(file, filename);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,28 +61,23 @@ public class OSSClientUtil {
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
public String uploadImg(MultipartFile file) throws IOException {
|
||||
public String uploadFile(MultipartFile file) throws IOException {
|
||||
String originalFilename = file.getOriginalFilename();
|
||||
return uploadImg(file.getInputStream(), originalFilename);
|
||||
return uploadFile(file.getInputStream(), originalFilename);
|
||||
}
|
||||
|
||||
public String uploadImg(InputStream inputStream, String originalFilename) {
|
||||
private String uploadFile(InputStream inputStream, String fileName) {
|
||||
String backUrl = "";
|
||||
try {
|
||||
ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
|
||||
String substring = originalFilename.substring(originalFilename.lastIndexOf(".")).toLowerCase();
|
||||
Random random = new Random();
|
||||
String name = random.nextInt(10000) + System.currentTimeMillis() + substring;
|
||||
backUrl = "imageDir/" + name;
|
||||
backUrl = SAVE_DIR + fileName;
|
||||
// 上传文件
|
||||
ossClient.putObject(bucketName, backUrl, inputStream);
|
||||
ossClient.setObjectAcl(bucketName, backUrl, CannedAccessControlList.PublicRead);
|
||||
// 判断是否上传成功
|
||||
boolean uploadResult = ossClient.doesObjectExist(bucketName, backUrl);
|
||||
|
||||
if (uploadResult) {
|
||||
backUrl = getImgUrl(name);
|
||||
} else {
|
||||
if (!uploadResult) {
|
||||
backUrl = "";
|
||||
}
|
||||
} finally {
|
||||
@@ -112,4 +109,14 @@ public class OSSClientUtil {
|
||||
return ossObject.getObjectContent();
|
||||
}
|
||||
|
||||
public void deleteFile(String objName){
|
||||
// ossObject包含文件所在的存储空间名称、文件名称、文件元信息以及一个输入流。
|
||||
ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
|
||||
try {
|
||||
ossClient.deleteObject(bucketName,objName);
|
||||
}catch (Exception e){
|
||||
log.error("删除失败",e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.quinn.utils;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -8,6 +9,8 @@ public class QuinnUtils {
|
||||
|
||||
static boolean printFlag = true;
|
||||
|
||||
private final static SimpleDateFormat sdf = new SimpleDateFormat( "yyyyMMdd");
|
||||
|
||||
public static String getUuid(){
|
||||
return UUID.randomUUID().toString().replaceAll("-","");
|
||||
}
|
||||
@@ -16,6 +19,10 @@ public class QuinnUtils {
|
||||
return new Timestamp(new Date().getTime());
|
||||
}
|
||||
|
||||
public static String getStrFromDate(Date date){
|
||||
return sdf.format(date);
|
||||
}
|
||||
|
||||
public static void print(String msg){
|
||||
if (printFlag){
|
||||
System.out.println("quinn:=>"+msg);
|
||||
|
||||
@@ -10,12 +10,12 @@ import lombok.experimental.Accessors;
|
||||
@Accessors(chain = true)
|
||||
public class QuestionWriteForm {
|
||||
|
||||
@ApiModelProperty(value = "问题标题")
|
||||
@ApiModelProperty(value = "标题")
|
||||
private String title;
|
||||
@ApiModelProperty(value = "问题内容")
|
||||
@ApiModelProperty(value = "内容")
|
||||
private String content;
|
||||
|
||||
@ApiModelProperty(value = "问题分类id")
|
||||
@ApiModelProperty(value = "分类")
|
||||
private Integer categoryId;
|
||||
|
||||
@ApiModelProperty(value = "作者id")
|
||||
|
||||
27
src/main/java/com/quinn/vo/SourceDeleteForm.java
Normal file
27
src/main/java/com/quinn/vo/SourceDeleteForm.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package com.quinn.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author limqsh
|
||||
* @since 2022-05-03
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
public class SourceDeleteForm {
|
||||
|
||||
@ApiModelProperty(value = "资源ID")
|
||||
private String sid;
|
||||
|
||||
@ApiModelProperty(value = "管理员密码")
|
||||
private String uploadPassWord;
|
||||
|
||||
}
|
||||
54
src/main/java/com/quinn/vo/SourceUpdateForm.java
Normal file
54
src/main/java/com/quinn/vo/SourceUpdateForm.java
Normal file
@@ -0,0 +1,54 @@
|
||||
package com.quinn.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author limqsh
|
||||
* @since 2022-05-03
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
public class SourceUpdateForm {
|
||||
|
||||
@ApiModelProperty(value = "资源ID")
|
||||
private String sid;
|
||||
|
||||
@ApiModelProperty(value = "资源名")
|
||||
private String sourceName;
|
||||
|
||||
@ApiModelProperty(value = "描述")
|
||||
private String detail;
|
||||
|
||||
@ApiModelProperty(value = "资源内容")
|
||||
private String sourceContent;
|
||||
|
||||
@ApiModelProperty(value = "关键字")
|
||||
private String keyWords;
|
||||
|
||||
@ApiModelProperty(value = "资源类型")
|
||||
private String sourceType;
|
||||
|
||||
@ApiModelProperty(value = "资源链接")
|
||||
private String sourceLink;
|
||||
|
||||
@ApiModelProperty(value = "类别ID")
|
||||
private Integer categoryId;
|
||||
|
||||
@ApiModelProperty(value = "类别名")
|
||||
private String categoryName;
|
||||
|
||||
@ApiModelProperty(value = "英文名")
|
||||
private String enName;
|
||||
|
||||
@ApiModelProperty(value = "管理员密码")
|
||||
private String uploadPassWord;
|
||||
|
||||
}
|
||||
34
src/main/java/com/quinn/vo/SourceWriteForm.java
Normal file
34
src/main/java/com/quinn/vo/SourceWriteForm.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package com.quinn.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
public class SourceWriteForm {
|
||||
|
||||
@ApiModelProperty(value = "标题")
|
||||
private String title;
|
||||
@ApiModelProperty(value = "简介")
|
||||
private String subContent;
|
||||
@ApiModelProperty(value = "内容")
|
||||
private String content;
|
||||
@ApiModelProperty(value = "英文名")
|
||||
private String enName;
|
||||
@ApiModelProperty(value = "摘要")
|
||||
private String keyWords;
|
||||
|
||||
@ApiModelProperty(value = "分类")
|
||||
private Integer categoryId;
|
||||
|
||||
@ApiModelProperty(value = "文档类型")
|
||||
private String sourceType;
|
||||
@ApiModelProperty(value = "文档路径")
|
||||
private String sourceLink;
|
||||
|
||||
@ApiModelProperty(value = "管理员密码")
|
||||
private String uploadPassWord;
|
||||
}
|
||||
Reference in New Issue
Block a user