5-10 版本修改
This commit is contained in:
@@ -3,18 +3,28 @@ package com.yxt.demo.system.api.sys_resources;
|
||||
import com.yxt.demo.system.utils.ResultBean;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* @Author dimengzhe
|
||||
* @Date 2023/4/24 14:26
|
||||
* @Description
|
||||
*/
|
||||
@Api(value = "")
|
||||
@Api(value = "自主资源")
|
||||
public interface SysResourcesFeign {
|
||||
|
||||
@ApiOperation(value = "上传")
|
||||
@RequestMapping("/upload")
|
||||
ResultBean upload(MultipartFile file);
|
||||
ResultBean upload(@RequestParam("multipartFile") MultipartFile multipartFile, String type);
|
||||
|
||||
@ApiOperation(value = "下载")
|
||||
@RequestMapping("/download/{name}")
|
||||
ResultBean download(@PathVariable String name, HttpServletResponse response);
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ public class SysInfoService extends MybatisBaseService<SysInfoMapper, SysInfo> {
|
||||
SysUser sysUser = sysUserMapper.selectByNameAndUserName(sysInfo.getInfoId(), sysInfo.getName());
|
||||
if (sysUser != null){
|
||||
sysInfo.setUserSid(sysUser.getSid());
|
||||
baseMapper.insert(sysInfo);
|
||||
sysInfoMapper.insert(sysInfo);
|
||||
sysUser.setInfoSid(sysInfo.getSid());
|
||||
sysUser.setModifyTime(new Date());
|
||||
sysUserMapper.updateById(sysUser);
|
||||
|
||||
@@ -8,6 +8,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* @Author dimengzhe
|
||||
* @Date 2023/4/24 14:26
|
||||
@@ -22,7 +24,12 @@ public class SysResourcesRest implements SysResourcesFeign {
|
||||
private SysResourcesService sysResourcesService;
|
||||
|
||||
@Override
|
||||
public ResultBean upload(MultipartFile file) {
|
||||
return sysResourcesService.upload(file);
|
||||
public ResultBean upload(MultipartFile multipartFile, String type) {
|
||||
return sysResourcesService.upload(multipartFile,type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultBean download(String name, HttpServletResponse response) {
|
||||
return sysResourcesService.download(name, response);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,16 @@ package com.yxt.demo.system.biz.sys_resources;
|
||||
import com.yxt.demo.system.api.sys_resources.SysResources;
|
||||
import com.yxt.demo.system.jdbc.service.MybatisBaseService;
|
||||
import com.yxt.demo.system.utils.ResultBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.util.UUID;
|
||||
import java.io.FileInputStream;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
/**
|
||||
* @Author dimengzhe
|
||||
@@ -18,19 +22,53 @@ import java.util.UUID;
|
||||
@Service
|
||||
public class SysResourcesService extends MybatisBaseService<SysResourcesMapper, SysResources> {
|
||||
|
||||
@Autowired
|
||||
private SysResourcesMapper sysResourcesMapper;
|
||||
|
||||
@Value("${reggie.path}")
|
||||
private String basePath;
|
||||
|
||||
public ResultBean upload(MultipartFile file) {
|
||||
String filename = file.getOriginalFilename();
|
||||
String substring = filename.substring(filename.lastIndexOf("."));
|
||||
String fileName = UUID.randomUUID().toString() + substring;
|
||||
public ResultBean upload(MultipartFile multipartFile, String type) {
|
||||
ResultBean rb = ResultBean.fireFail();
|
||||
String filename = multipartFile.getOriginalFilename();
|
||||
// int startIndex = filename.replaceAll("\\\\", "/").lastIndexOf("/");
|
||||
// String substring = filename.substring(startIndex + 1).substring(0, filename.indexOf("."));
|
||||
File file1 = new File(basePath);
|
||||
if (!file1.exists()){
|
||||
file1.mkdirs();
|
||||
}
|
||||
try {
|
||||
file.transferTo(new File(basePath+fileName));
|
||||
multipartFile.transferTo(new File(basePath+filename));
|
||||
SysResources sysResources = new SysResources();
|
||||
sysResources.setFilePath(basePath+filename);
|
||||
sysResources.setContent(filename);
|
||||
sysResources.setType(type);
|
||||
int insert = sysResourcesMapper.insert(sysResources);
|
||||
if (insert == 0){
|
||||
return rb.setMsg("上传失败");
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
return rb.setMsg("上传失败");
|
||||
}
|
||||
return rb.success();
|
||||
}
|
||||
|
||||
public ResultBean download(String name, HttpServletResponse response) {
|
||||
try {
|
||||
FileInputStream fileInputStream = new FileInputStream(new File(basePath + name));
|
||||
ServletOutputStream outputStream = response.getOutputStream();
|
||||
response.setContentType("application/octet-stream;charset=UTF-8");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setHeader("Content-Disposition","attachment;filename="+ URLEncoder.encode(name, "UTF-8"));
|
||||
int len = 0;
|
||||
byte[] bytes = new byte[1024];
|
||||
while ((len = fileInputStream.read(bytes)) != -1){
|
||||
outputStream.write(bytes,0,len);
|
||||
outputStream.flush();
|
||||
}
|
||||
outputStream.close();
|
||||
fileInputStream.close();
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user