本地上传图片

This commit is contained in:
liuxiao 2024-07-15 15:56:28 +08:00
parent b23367b873
commit 56b2a3a889
7 changed files with 33 additions and 17 deletions

View File

@ -44,7 +44,7 @@ import java.util.Map;
public class SysOssController extends BaseController { public class SysOssController extends BaseController {
@Value("${file.BASE_FILE_SAVE_PATH}") @Value("${file.BASE_FILE_SAVE_PATH}")
private String filePath; private String uploadPath;
private final ISysOssService iSysOssService; private final ISysOssService iSysOssService;
private final ISysImageService iSysImageService; private final ISysImageService iSysImageService;
@ -65,9 +65,9 @@ public class SysOssController extends BaseController {
*/ */
@SaCheckPermission("system:oss:list") @SaCheckPermission("system:oss:list")
@GetMapping("/listByIds/{ossIds}") @GetMapping("/listByIds/{ossIds}")
public R<List<SysOssVo>> listByIds(@NotEmpty(message = "主键不能为空") public R<List<String>> listByIds(@NotEmpty(message = "主键不能为空")
@PathVariable Long[] ossIds) { @PathVariable Long[] ossIds) {
List<SysOssVo> list = iSysOssService.listByIds(Arrays.asList(ossIds)); List<String> list = iSysOssService.listByIds(Arrays.asList(ossIds));
return R.ok(list); return R.ok(list);
} }
@ -101,7 +101,7 @@ public class SysOssController extends BaseController {
public R<Map<String, String>> addPartsUpload(@RequestPart("file") MultipartFile file) { public R<Map<String, String>> addPartsUpload(@RequestPart("file") MultipartFile file) {
Map<String,String> map=new HashMap<>(); Map<String,String> map=new HashMap<>();
String filePath=System.getProperty("user.dir")+"/file/upload/"; String filePath=uploadPath+"/file/upload/";
try { try {
if (file.isEmpty()) { if (file.isEmpty()) {
return R.warn("文件为空"); return R.warn("文件为空");

View File

@ -172,4 +172,4 @@ sms:
sdkAppId: sdkAppId:
--- # 文件上传路径 --- # 文件上传路径
file: file:
BASE_FILE_SAVE_PATH: ./image BASE_FILE_SAVE_PATH: /www/wwwroot/guanwang/web/image

View File

@ -129,6 +129,7 @@ security:
- /**/*.html - /**/*.html
- /**/*.css - /**/*.css
- /**/*.js - /**/*.js
- /**/*.jpg
- # 配置白名单 - # 配置白名单
- /official/slideshow/** - /official/slideshow/**
# 公共路径 # 公共路径

View File

@ -33,7 +33,7 @@ public class FileChunkFilelistController extends BaseController {
/** /**
* 查询已上传文件记录列表 * 查询已上传文件记录列表
*/ */
@SaCheckPermission("official:chunkFilelist:list") /*@SaCheckPermission("official:chunkFilelist:list")*/
@GetMapping("/list") @GetMapping("/list")
public TableDataInfo<FileChunkFilelistVo> list(FileChunkFilelistBo bo, PageQuery pageQuery) { public TableDataInfo<FileChunkFilelistVo> list(FileChunkFilelistBo bo, PageQuery pageQuery) {
return iFileChunkFilelistService.queryPageList(bo, pageQuery); return iFileChunkFilelistService.queryPageList(bo, pageQuery);

View File

@ -3,6 +3,7 @@ package com.ruoyi.official.service.impl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.PageQuery; import com.ruoyi.common.core.domain.PageQuery;
@ -16,6 +17,7 @@ import com.ruoyi.official.domain.vo.GwSlideshowVo;
import com.ruoyi.official.domain.GwSlideshow; import com.ruoyi.official.domain.GwSlideshow;
import com.ruoyi.official.mapper.GwSlideshowMapper; import com.ruoyi.official.mapper.GwSlideshowMapper;
import com.ruoyi.official.service.IGwSlideshowService; import com.ruoyi.official.service.IGwSlideshowService;
import org.springframework.transaction.annotation.Transactional;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
@ -112,6 +114,7 @@ public class GwSlideshowServiceImpl implements IGwSlideshowService {
* 修改新闻信息 * 修改新闻信息
*/ */
@Override @Override
@Transactional(rollbackFor = Exception.class)
public Boolean updateByBo(GwSlideshowBo bo) { public Boolean updateByBo(GwSlideshowBo bo) {
GwSlideshow update = BeanUtil.toBean(bo, GwSlideshow.class); GwSlideshow update = BeanUtil.toBean(bo, GwSlideshow.class);
validEntityBeforeSave(update); validEntityBeforeSave(update);
@ -124,15 +127,26 @@ public class GwSlideshowServiceImpl implements IGwSlideshowService {
private void validEntityBeforeSave(GwSlideshow entity) { private void validEntityBeforeSave(GwSlideshow entity) {
//TODO 做一些数据校验,如唯一约束 //TODO 做一些数据校验,如唯一约束
//存在已置顶的数据不允许添加编辑 //存在已置顶的数据不允许添加编辑
if (ObjectUtil.isNotEmpty(entity.getId())) { /* if (ObjectUtil.isNotEmpty(entity.getId())) {
//编辑 //编辑
boolean exists = baseMapper.exists(Wrappers.<GwSlideshow>lambdaQuery().eq(GwSlideshow::getIsTop, "1")); GwSlideshowVo slideshowVo = baseMapper.selectVoOne(Wrappers.<GwSlideshow>lambdaQuery().eq(GwSlideshow::getIsTop, "1"));
if (exists && entity.getIsTop().equals("1")) throw new RuntimeException("已存在置顶的图片信息!"); if (!(ObjectUtil.equal(slideshowVo.getId(),entity.getId()))) throw new RuntimeException("已存在置顶的图片信息!");
} else { } else {
//新增 //新增
boolean exists = baseMapper.exists(Wrappers.<GwSlideshow>lambdaQuery().eq(GwSlideshow::getIsTop, "1")); boolean exists = baseMapper.exists(Wrappers.<GwSlideshow>lambdaQuery().eq(GwSlideshow::getIsTop, "1"));
if (exists && entity.getIsTop().equals("1")) throw new RuntimeException("已存在置顶的图片信息!"); if (exists && entity.getIsTop().equals("1")) throw new RuntimeException("已存在置顶的图片信息!");
} }*/
if (!ObjectUtil.equal(entity.getIsTop(),"1"))return;
//存在想置顶得数据将原来得数据修改为非置顶
List<GwSlideshowVo> vos = baseMapper.selectVoList(Wrappers.<GwSlideshow>lambdaQuery().eq(GwSlideshow::getIsTop, "1"));
if ( CollUtil.isEmpty(vos)) return;
UpdateWrapper<GwSlideshow> updateWrapper = new UpdateWrapper<>();
vos.stream().forEach(ixt->{
// updateWrapper.("id", list).set("is_top", "0");
updateWrapper.eq("id",ixt.getId()).set("is_top", "0");
baseMapper.update(BeanUtil.toBean(ixt,GwSlideshow.class),updateWrapper);
});
} }

View File

@ -21,7 +21,7 @@ public interface ISysOssService {
TableDataInfo<SysOssVo> queryPageList(SysOssBo sysOss, PageQuery pageQuery); TableDataInfo<SysOssVo> queryPageList(SysOssBo sysOss, PageQuery pageQuery);
List<SysOssVo> listByIds(Collection<Long> ossIds); List<String> listByIds(Collection<Long> ossIds);
SysOssVo getById(Long ossId); SysOssVo getById(Long ossId);

View File

@ -17,6 +17,9 @@ import com.ruoyi.common.utils.BeanCopyUtils;
import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.file.FileUtils; import com.ruoyi.common.utils.file.FileUtils;
import com.ruoyi.common.utils.spring.SpringUtils; import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.official.domain.SysImage;
import com.ruoyi.official.domain.vo.SysImageVo;
import com.ruoyi.official.mapper.SysImageMapper;
import com.ruoyi.oss.core.OssClient; import com.ruoyi.oss.core.OssClient;
import com.ruoyi.oss.entity.UploadResult; import com.ruoyi.oss.entity.UploadResult;
import com.ruoyi.oss.enumd.AccessPolicyType; import com.ruoyi.oss.enumd.AccessPolicyType;
@ -48,6 +51,7 @@ import java.util.stream.Collectors;
public class SysOssServiceImpl implements ISysOssService, OssService { public class SysOssServiceImpl implements ISysOssService, OssService {
private final SysOssMapper baseMapper; private final SysOssMapper baseMapper;
private final SysImageMapper sysImageMapper;
@Override @Override
public TableDataInfo<SysOssVo> queryPageList(SysOssBo bo, PageQuery pageQuery) { public TableDataInfo<SysOssVo> queryPageList(SysOssBo bo, PageQuery pageQuery) {
@ -59,14 +63,11 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
} }
@Override @Override
public List<SysOssVo> listByIds(Collection<Long> ossIds) { public List<String> listByIds(Collection<Long> ossIds) {
List<SysOssVo> list = new ArrayList<>(); List<SysOssVo> list = new ArrayList<>();
Optional<Long> first = ossIds.stream().findFirst(); Optional<Long> first = ossIds.stream().findFirst();
List<SysOssVo> sysOssVos = baseMapper.selectVoList(Wrappers.<SysOss>lambdaQuery().eq(SysOss::getOssId, first.get())); List<SysImageVo> sysImageVos = sysImageMapper.selectVoList(Wrappers.<SysImage>lambdaQuery().eq(SysImage::getId, first.get()));
return CollUtil.isNotEmpty(sysOssVos)?sysOssVos.stream().map(itx->{ return CollUtil.isNotEmpty(sysImageVos)?sysImageVos.stream().filter(ObjectUtil::isNotEmpty).map(SysImageVo::getUrl).collect(Collectors.toList()):null;
System.out.println(itx.getUrl()+"/"+itx.getFileName());
return itx.setUrl(itx.getUrl()+"/"+itx.getFileName());
}).collect(Collectors.toList()):null;
} }
@Override @Override