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 com.yxt.demo.system.utils.ResultBean;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
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.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author dimengzhe
|
* @Author dimengzhe
|
||||||
* @Date 2023/4/24 14:26
|
* @Date 2023/4/24 14:26
|
||||||
* @Description
|
* @Description
|
||||||
*/
|
*/
|
||||||
@Api(value = "")
|
@Api(value = "自主资源")
|
||||||
public interface SysResourcesFeign {
|
public interface SysResourcesFeign {
|
||||||
|
|
||||||
@ApiOperation(value = "上传")
|
@ApiOperation(value = "上传")
|
||||||
@RequestMapping("/upload")
|
@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());
|
SysUser sysUser = sysUserMapper.selectByNameAndUserName(sysInfo.getInfoId(), sysInfo.getName());
|
||||||
if (sysUser != null){
|
if (sysUser != null){
|
||||||
sysInfo.setUserSid(sysUser.getSid());
|
sysInfo.setUserSid(sysUser.getSid());
|
||||||
baseMapper.insert(sysInfo);
|
sysInfoMapper.insert(sysInfo);
|
||||||
sysUser.setInfoSid(sysInfo.getSid());
|
sysUser.setInfoSid(sysInfo.getSid());
|
||||||
sysUser.setModifyTime(new Date());
|
sysUser.setModifyTime(new Date());
|
||||||
sysUserMapper.updateById(sysUser);
|
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.bind.annotation.RestController;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author dimengzhe
|
* @Author dimengzhe
|
||||||
* @Date 2023/4/24 14:26
|
* @Date 2023/4/24 14:26
|
||||||
@@ -22,7 +24,12 @@ public class SysResourcesRest implements SysResourcesFeign {
|
|||||||
private SysResourcesService sysResourcesService;
|
private SysResourcesService sysResourcesService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResultBean upload(MultipartFile file) {
|
public ResultBean upload(MultipartFile multipartFile, String type) {
|
||||||
return sysResourcesService.upload(file);
|
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.api.sys_resources.SysResources;
|
||||||
import com.yxt.demo.system.jdbc.service.MybatisBaseService;
|
import com.yxt.demo.system.jdbc.service.MybatisBaseService;
|
||||||
import com.yxt.demo.system.utils.ResultBean;
|
import com.yxt.demo.system.utils.ResultBean;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.servlet.ServletOutputStream;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.UUID;
|
import java.io.FileInputStream;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author dimengzhe
|
* @Author dimengzhe
|
||||||
@@ -18,19 +22,53 @@ import java.util.UUID;
|
|||||||
@Service
|
@Service
|
||||||
public class SysResourcesService extends MybatisBaseService<SysResourcesMapper, SysResources> {
|
public class SysResourcesService extends MybatisBaseService<SysResourcesMapper, SysResources> {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SysResourcesMapper sysResourcesMapper;
|
||||||
|
|
||||||
@Value("${reggie.path}")
|
@Value("${reggie.path}")
|
||||||
private String basePath;
|
private String basePath;
|
||||||
|
|
||||||
public ResultBean upload(MultipartFile file) {
|
public ResultBean upload(MultipartFile multipartFile, String type) {
|
||||||
String filename = file.getOriginalFilename();
|
ResultBean rb = ResultBean.fireFail();
|
||||||
String substring = filename.substring(filename.lastIndexOf("."));
|
String filename = multipartFile.getOriginalFilename();
|
||||||
String fileName = UUID.randomUUID().toString() + substring;
|
// int startIndex = filename.replaceAll("\\\\", "/").lastIndexOf("/");
|
||||||
|
// String substring = filename.substring(startIndex + 1).substring(0, filename.indexOf("."));
|
||||||
File file1 = new File(basePath);
|
File file1 = new File(basePath);
|
||||||
if (!file1.exists()){
|
if (!file1.exists()){
|
||||||
file1.mkdirs();
|
file1.mkdirs();
|
||||||
}
|
}
|
||||||
try {
|
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){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user