官网后台图片上传
This commit is contained in:
parent
1adebed619
commit
97a246dcc1
|
@ -10,6 +10,7 @@ import com.ruoyi.common.core.domain.R;
|
||||||
import com.ruoyi.common.core.page.TableDataInfo;
|
import com.ruoyi.common.core.page.TableDataInfo;
|
||||||
import com.ruoyi.common.core.validate.QueryGroup;
|
import com.ruoyi.common.core.validate.QueryGroup;
|
||||||
import com.ruoyi.common.enums.BusinessType;
|
import com.ruoyi.common.enums.BusinessType;
|
||||||
|
import com.ruoyi.official.service.ISysImageService;
|
||||||
import com.ruoyi.system.domain.bo.SysOssBo;
|
import com.ruoyi.system.domain.bo.SysOssBo;
|
||||||
import com.ruoyi.system.domain.vo.SysOssVo;
|
import com.ruoyi.system.domain.vo.SysOssVo;
|
||||||
import com.ruoyi.system.service.ISysOssService;
|
import com.ruoyi.system.service.ISysOssService;
|
||||||
|
@ -46,6 +47,7 @@ public class SysOssController extends BaseController {
|
||||||
private String filePath;
|
private String filePath;
|
||||||
|
|
||||||
private final ISysOssService iSysOssService;
|
private final ISysOssService iSysOssService;
|
||||||
|
private final ISysImageService iSysImageService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询OSS对象存储列表
|
* 查询OSS对象存储列表
|
||||||
|
@ -94,16 +96,15 @@ public class SysOssController extends BaseController {
|
||||||
* @param file 文件数据
|
* @param file 文件数据
|
||||||
* @return 文件上传地址信息
|
* @return 文件上传地址信息
|
||||||
*/
|
*/
|
||||||
@Log(title = "OSS对象存储", businessType = BusinessType.INSERT)
|
@Log(title = "本地文件上传", businessType = BusinessType.INSERT)
|
||||||
@PostMapping("/addPartsUpload")
|
@PostMapping("/addPartsUpload")
|
||||||
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<>();
|
||||||
log.info("上传的文件名称:{}",file.getOriginalFilename());
|
|
||||||
//文件上传的地址从配置文件中获取
|
String filePath=System.getProperty("user.dir")+"/file/upload/";
|
||||||
log.info("上传的文件地址:{}",filePath);
|
|
||||||
try {
|
try {
|
||||||
if (file.isEmpty()) {
|
if (file.isEmpty()) {
|
||||||
return R.fail("上传文件不能为空");
|
return R.warn("文件为空");
|
||||||
}
|
}
|
||||||
|
|
||||||
String fileName = System.currentTimeMillis()+"-"+file.getOriginalFilename();
|
String fileName = System.currentTimeMillis()+"-"+file.getOriginalFilename();
|
||||||
|
@ -120,18 +121,15 @@ public class SysOssController extends BaseController {
|
||||||
file.transferTo(uploadFile);
|
file.transferTo(uploadFile);
|
||||||
String pathFan=filePath.replace("\\","/");
|
String pathFan=filePath.replace("\\","/");
|
||||||
//filePath获取到的地址斜杠是“ \ ”的(单斜杠是特殊符号,得用双斜杠代替),得换成“ / ”才能访问到
|
//filePath获取到的地址斜杠是“ \ ”的(单斜杠是特殊符号,得用双斜杠代替),得换成“ / ”才能访问到
|
||||||
|
|
||||||
map.put("url",filePath);
|
|
||||||
map.put("fileName",fileName);
|
|
||||||
|
|
||||||
log.info("替换后的文件名称:{}",pathFan+fileName);
|
|
||||||
SysOssVo sysOssVo = iSysOssService.uploadLocal(filePath, fileName);
|
|
||||||
map.put("ossId",sysOssVo.getOssId().toString());
|
|
||||||
|
|
||||||
//修改数据库
|
//修改数据库
|
||||||
|
Long image = iSysImageService.uploadImage(fileName,pathFan+fileName);
|
||||||
|
System.err.println("替换后:"+pathFan);
|
||||||
|
map.put("url",pathFan+fileName);
|
||||||
|
map.put("fileName",fileName);
|
||||||
|
map.put("ossId",image.toString());
|
||||||
return R.ok(map);
|
return R.ok(map);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
return R.fail("文件上传失败: "+e);
|
return R.warn("文件上传失败: "+e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
package com.ruoyi.official.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
import com.ruoyi.common.core.domain.BaseEntity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 本地图片上传信息对象 sys_image
|
||||||
|
*
|
||||||
|
* @author liuxiao
|
||||||
|
* @date 2024-07-09
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@TableName("sys_image")
|
||||||
|
public class SysImage extends BaseEntity {
|
||||||
|
|
||||||
|
private static final long serialVersionUID=1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对象存储主键
|
||||||
|
*/
|
||||||
|
@TableId(value = "id")
|
||||||
|
private Long id;
|
||||||
|
/**
|
||||||
|
* 文件名
|
||||||
|
*/
|
||||||
|
private String fileName;
|
||||||
|
/**
|
||||||
|
* URL地址
|
||||||
|
*/
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
}
|
|
@ -37,7 +37,6 @@ public class GwLableBo extends BaseEntity {
|
||||||
/**
|
/**
|
||||||
* 文件类型 0:图片 1:视频
|
* 文件类型 0:图片 1:视频
|
||||||
*/
|
*/
|
||||||
@NotBlank(message = "文件类型 0:图片 1:视频不能为空", groups = { AddGroup.class, EditGroup.class })
|
|
||||||
private String fileType;
|
private String fileType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,7 +48,6 @@ public class GwLableBo extends BaseEntity {
|
||||||
/**
|
/**
|
||||||
* 父菜单ID
|
* 父菜单ID
|
||||||
*/
|
*/
|
||||||
@NotNull(message = "父菜单ID不能为空", groups = { AddGroup.class, EditGroup.class })
|
|
||||||
private Long parentId;
|
private Long parentId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -67,7 +65,7 @@ public class GwLableBo extends BaseEntity {
|
||||||
/**
|
/**
|
||||||
* 菜单类型(M目录 C菜单)
|
* 菜单类型(M目录 C菜单)
|
||||||
*/
|
*/
|
||||||
@NotBlank(message = "菜单类型(M目录 C菜单)不能为空", groups = { AddGroup.class, EditGroup.class })
|
|
||||||
private String menuType;
|
private String menuType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -79,13 +77,11 @@ public class GwLableBo extends BaseEntity {
|
||||||
/**
|
/**
|
||||||
* 创建者id
|
* 创建者id
|
||||||
*/
|
*/
|
||||||
@NotNull(message = "创建者id不能为空", groups = { AddGroup.class, EditGroup.class })
|
|
||||||
private Long createUserId;
|
private Long createUserId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新者id
|
* 更新者id
|
||||||
*/
|
*/
|
||||||
@NotNull(message = "更新者id不能为空", groups = { AddGroup.class, EditGroup.class })
|
|
||||||
private Long updateUserId;
|
private Long updateUserId;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,6 @@ public class GwSlideshowBo extends BaseEntity {
|
||||||
/**
|
/**
|
||||||
* 摘要
|
* 摘要
|
||||||
*/
|
*/
|
||||||
@NotBlank(message = "摘要不能为空", groups = { AddGroup.class, EditGroup.class })
|
|
||||||
private String abstracts;
|
private String abstracts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
package com.ruoyi.official.domain.bo;
|
||||||
|
|
||||||
|
import com.ruoyi.common.core.validate.AddGroup;
|
||||||
|
import com.ruoyi.common.core.validate.EditGroup;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import javax.validation.constraints.*;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import com.ruoyi.common.core.domain.BaseEntity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 本地图片上传信息业务对象 sys_image
|
||||||
|
*
|
||||||
|
* @author liuxiao
|
||||||
|
* @date 2024-07-09
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class SysImageBo extends BaseEntity {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对象存储主键
|
||||||
|
*/
|
||||||
|
@NotNull(message = "对象存储主键不能为空", groups = { EditGroup.class })
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件名
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "文件名不能为空", groups = { AddGroup.class, EditGroup.class })
|
||||||
|
private String fileName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* URL地址
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "URL地址不能为空", groups = { AddGroup.class, EditGroup.class })
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
package com.ruoyi.official.domain.vo;
|
||||||
|
|
||||||
|
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||||
|
import com.alibaba.excel.annotation.ExcelProperty;
|
||||||
|
import com.ruoyi.common.annotation.ExcelDictFormat;
|
||||||
|
import com.ruoyi.common.convert.ExcelDictConvert;
|
||||||
|
import lombok.Data;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 本地图片上传信息视图对象 sys_image
|
||||||
|
*
|
||||||
|
* @author liuxiao
|
||||||
|
* @date 2024-07-09
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@ExcelIgnoreUnannotated
|
||||||
|
public class SysImageVo {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对象存储主键
|
||||||
|
*/
|
||||||
|
@ExcelProperty(value = "对象存储主键")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件名
|
||||||
|
*/
|
||||||
|
@ExcelProperty(value = "文件名")
|
||||||
|
private String fileName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* URL地址
|
||||||
|
*/
|
||||||
|
@ExcelProperty(value = "URL地址")
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.ruoyi.official.mapper;
|
||||||
|
|
||||||
|
import com.ruoyi.official.domain.SysImage;
|
||||||
|
import com.ruoyi.official.domain.vo.SysImageVo;
|
||||||
|
import com.ruoyi.common.core.mapper.BaseMapperPlus;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 本地图片上传信息Mapper接口
|
||||||
|
*
|
||||||
|
* @author liuxiao
|
||||||
|
* @date 2024-07-09
|
||||||
|
*/
|
||||||
|
public interface SysImageMapper extends BaseMapperPlus<SysImageMapper, SysImage, SysImageVo> {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
package com.ruoyi.official.service;
|
||||||
|
|
||||||
|
import com.ruoyi.official.domain.SysImage;
|
||||||
|
import com.ruoyi.official.domain.vo.SysImageVo;
|
||||||
|
import com.ruoyi.official.domain.bo.SysImageBo;
|
||||||
|
import com.ruoyi.common.core.page.TableDataInfo;
|
||||||
|
import com.ruoyi.common.core.domain.PageQuery;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 本地图片上传信息Service接口
|
||||||
|
*
|
||||||
|
* @author liuxiao
|
||||||
|
* @date 2024-07-09
|
||||||
|
*/
|
||||||
|
public interface ISysImageService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询本地图片上传信息
|
||||||
|
*/
|
||||||
|
SysImageVo queryById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询本地图片上传信息列表
|
||||||
|
*/
|
||||||
|
TableDataInfo<SysImageVo> queryPageList(SysImageBo bo, PageQuery pageQuery);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询本地图片上传信息列表
|
||||||
|
*/
|
||||||
|
List<SysImageVo> queryList(SysImageBo bo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增本地图片上传信息
|
||||||
|
*/
|
||||||
|
Boolean insertByBo(SysImageBo bo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改本地图片上传信息
|
||||||
|
*/
|
||||||
|
Boolean updateByBo(SysImageBo bo);
|
||||||
|
|
||||||
|
|
||||||
|
Long uploadImage(String fileName,String url);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验并批量删除本地图片上传信息信息
|
||||||
|
*/
|
||||||
|
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||||
|
}
|
|
@ -48,12 +48,12 @@ public class GwSlideshowServiceImpl implements IGwSlideshowService {
|
||||||
List<GwSlideshow> list = baseMapper.selectList(Wrappers.<GwSlideshow>lambdaQuery().orderByDesc(GwSlideshow::getCreateTime));
|
List<GwSlideshow> list = baseMapper.selectList(Wrappers.<GwSlideshow>lambdaQuery().orderByDesc(GwSlideshow::getCreateTime));
|
||||||
Map<String, Object> hashMap = new HashMap<>(16);
|
Map<String, Object> hashMap = new HashMap<>(16);
|
||||||
|
|
||||||
if(CollUtil.isNotEmpty(list)){
|
if(CollUtil.isNotEmpty(list)&&list.size()>1){
|
||||||
List<Long> collect = list.stream().map(GwSlideshow::getId).collect(Collectors.toList());
|
List<Long> collect = list.stream().map(GwSlideshow::getId).collect(Collectors.toList());
|
||||||
if (collect.contains(id)){
|
if (collect.contains(id)){
|
||||||
int currentSubscript = collect.indexOf(id);
|
int currentSubscript = collect.indexOf(id);
|
||||||
hashMap.put("previous",list.get(currentSubscript-1));
|
hashMap.put("previous",ObjectUtil.isNotEmpty(list.get(currentSubscript-1))?list.get(currentSubscript-1):null);
|
||||||
hashMap.put("nextArticle",list.get(currentSubscript+1));
|
hashMap.put("nextArticle",ObjectUtil.isNotEmpty(list.get(currentSubscript-1))?list.get(currentSubscript+1):null);
|
||||||
gwSlideshowVo.setSlideshowMap(hashMap);
|
gwSlideshowVo.setSlideshowMap(hashMap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,121 @@
|
||||||
|
package com.ruoyi.official.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
|
import com.ruoyi.common.core.page.TableDataInfo;
|
||||||
|
import com.ruoyi.common.core.domain.PageQuery;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import com.ruoyi.official.domain.bo.SysImageBo;
|
||||||
|
import com.ruoyi.official.domain.vo.SysImageVo;
|
||||||
|
import com.ruoyi.official.domain.SysImage;
|
||||||
|
import com.ruoyi.official.mapper.SysImageMapper;
|
||||||
|
import com.ruoyi.official.service.ISysImageService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 本地图片上传信息Service业务层处理
|
||||||
|
*
|
||||||
|
* @author liuxiao
|
||||||
|
* @date 2024-07-09
|
||||||
|
*/
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Service
|
||||||
|
public class SysImageServiceImpl implements ISysImageService {
|
||||||
|
|
||||||
|
private final SysImageMapper baseMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询本地图片上传信息
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public SysImageVo queryById(Long id){
|
||||||
|
return baseMapper.selectVoById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询本地图片上传信息列表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public TableDataInfo<SysImageVo> queryPageList(SysImageBo bo, PageQuery pageQuery) {
|
||||||
|
LambdaQueryWrapper<SysImage> lqw = buildQueryWrapper(bo);
|
||||||
|
Page<SysImageVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
||||||
|
return TableDataInfo.build(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询本地图片上传信息列表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<SysImageVo> queryList(SysImageBo bo) {
|
||||||
|
LambdaQueryWrapper<SysImage> lqw = buildQueryWrapper(bo);
|
||||||
|
return baseMapper.selectVoList(lqw);
|
||||||
|
}
|
||||||
|
|
||||||
|
private LambdaQueryWrapper<SysImage> buildQueryWrapper(SysImageBo bo) {
|
||||||
|
Map<String, Object> params = bo.getParams();
|
||||||
|
LambdaQueryWrapper<SysImage> lqw = Wrappers.lambdaQuery();
|
||||||
|
lqw.like(StringUtils.isNotBlank(bo.getFileName()), SysImage::getFileName, bo.getFileName());
|
||||||
|
lqw.eq(StringUtils.isNotBlank(bo.getUrl()), SysImage::getUrl, bo.getUrl());
|
||||||
|
return lqw;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增本地图片上传信息
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Boolean insertByBo(SysImageBo bo) {
|
||||||
|
SysImage add = BeanUtil.toBean(bo, SysImage.class);
|
||||||
|
validEntityBeforeSave(add);
|
||||||
|
boolean flag = baseMapper.insert(add) > 0;
|
||||||
|
if (flag) {
|
||||||
|
bo.setId(add.getId());
|
||||||
|
}
|
||||||
|
return flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改本地图片上传信息
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Boolean updateByBo(SysImageBo bo) {
|
||||||
|
SysImage update = BeanUtil.toBean(bo, SysImage.class);
|
||||||
|
validEntityBeforeSave(update);
|
||||||
|
return baseMapper.updateById(update) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long uploadImage(String fileName,String url) {
|
||||||
|
SysImageVo sysImageVo = baseMapper.selectVoOne(Wrappers.<SysImage>lambdaQuery().eq(SysImage::getFileName, fileName));
|
||||||
|
if (ObjectUtil.isNotEmpty(sysImageVo)) throw new RuntimeException("图片已存在,请勿重复添加!");
|
||||||
|
SysImage sysImage = new SysImage();
|
||||||
|
sysImage.setFileName(fileName);
|
||||||
|
sysImage.setUrl(url);
|
||||||
|
return baseMapper.insert(sysImage) > 0 ? sysImage.getId() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存前的数据校验
|
||||||
|
*/
|
||||||
|
private void validEntityBeforeSave(SysImage entity){
|
||||||
|
//TODO 做一些数据校验,如唯一约束
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除本地图片上传信息
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||||
|
if(isValid){
|
||||||
|
//TODO 做一些业务上的校验,判断是否需要校验
|
||||||
|
}
|
||||||
|
return baseMapper.deleteBatchIds(ids) > 0;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
package com.ruoyi.system.domain.vo;
|
package com.ruoyi.system.domain.vo;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
@ -10,6 +11,7 @@ import java.util.Date;
|
||||||
* @author Lion Li
|
* @author Lion Li
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
|
@Accessors(chain = true) //开启链式编程,setter方法返回的是this(也就是对象自己),代替了默认的返回值void
|
||||||
public class SysOssVo {
|
public class SysOssVo {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.ruoyi.system.service.impl;
|
package com.ruoyi.system.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.convert.Convert;
|
import cn.hutool.core.convert.Convert;
|
||||||
import cn.hutool.core.io.IoUtil;
|
import cn.hutool.core.io.IoUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
@ -60,13 +61,12 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
|
||||||
@Override
|
@Override
|
||||||
public List<SysOssVo> listByIds(Collection<Long> ossIds) {
|
public List<SysOssVo> listByIds(Collection<Long> ossIds) {
|
||||||
List<SysOssVo> list = new ArrayList<>();
|
List<SysOssVo> list = new ArrayList<>();
|
||||||
for (Long id : ossIds) {
|
Optional<Long> first = ossIds.stream().findFirst();
|
||||||
SysOssVo vo = SpringUtils.getAopProxy(this).getById(id);
|
List<SysOssVo> sysOssVos = baseMapper.selectVoList(Wrappers.<SysOss>lambdaQuery().eq(SysOss::getOssId, first.get()));
|
||||||
if (ObjectUtil.isNotNull(vo)) {
|
return CollUtil.isNotEmpty(sysOssVos)?sysOssVos.stream().map(itx->{
|
||||||
list.add(this.matchingUrl(vo));
|
System.out.println(itx.getUrl()+"/"+itx.getFileName());
|
||||||
}
|
return itx.setUrl(itx.getUrl()+"/"+itx.getFileName());
|
||||||
}
|
}).collect(Collectors.toList()):null;
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -110,7 +110,7 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
|
||||||
FileUtils.setAttachmentResponseHeader(response, sysOss.getOriginalName());
|
FileUtils.setAttachmentResponseHeader(response, sysOss.getOriginalName());
|
||||||
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE + "; charset=UTF-8");
|
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE + "; charset=UTF-8");
|
||||||
OssClient storage = OssFactory.instance();
|
OssClient storage = OssFactory.instance();
|
||||||
try(InputStream inputStream = storage.getObjectContent(sysOss.getUrl())) {
|
try (InputStream inputStream = storage.getObjectContent(sysOss.getUrl())) {
|
||||||
int available = inputStream.available();
|
int available = inputStream.available();
|
||||||
IoUtil.copy(inputStream, response.getOutputStream(), available);
|
IoUtil.copy(inputStream, response.getOutputStream(), available);
|
||||||
response.setContentLength(available);
|
response.setContentLength(available);
|
||||||
|
@ -144,13 +144,13 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SysOssVo uploadLocal(String imageUrl,String fileName) {
|
public SysOssVo uploadLocal(String imageUrl, String fileName) {
|
||||||
// 保存文件信息
|
// 保存文件信息
|
||||||
SysOss oss = new SysOss();
|
SysOss oss = new SysOss();
|
||||||
oss.setUrl(imageUrl);
|
oss.setUrl(imageUrl);
|
||||||
oss.setFileName(fileName);
|
oss.setFileName(fileName);
|
||||||
baseMapper.insert(oss);
|
baseMapper.insert(oss);
|
||||||
return BeanUtil.toBean(oss,SysOssVo.class);
|
return BeanUtil.toBean(oss, SysOssVo.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.ruoyi.official.mapper.SysImageMapper">
|
||||||
|
|
||||||
|
<resultMap type="com.ruoyi.official.domain.SysImage" id="SysImageResult">
|
||||||
|
<result property="id" column="id"/>
|
||||||
|
<result property="fileName" column="file_name"/>
|
||||||
|
<result property="url" column="url"/>
|
||||||
|
<result property="createTime" column="create_time"/>
|
||||||
|
<result property="createBy" column="create_by"/>
|
||||||
|
<result property="updateTime" column="update_time"/>
|
||||||
|
<result property="updateBy" column="update_by"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
|
||||||
|
</mapper>
|
|
@ -82,7 +82,7 @@
|
||||||
|
|
||||||
<el-table v-loading="loading" :data="lableList" @selection-change="handleSelectionChange">
|
<el-table v-loading="loading" :data="lableList" @selection-change="handleSelectionChange">
|
||||||
<el-table-column type="selection" width="55" align="center" />
|
<el-table-column type="selection" width="55" align="center" />
|
||||||
<el-table-column label="主键id" align="center" prop="id" v-if="true"/>
|
<el-table-column label="主键id" align="center" prop="id" v-if="false"/>
|
||||||
<el-table-column label="图片上传地址" align="center" prop="imageurl" />
|
<el-table-column label="图片上传地址" align="center" prop="imageurl" />
|
||||||
<el-table-column label="文件类型" align="center" prop="fileType" />
|
<el-table-column label="文件类型" align="center" prop="fileType" />
|
||||||
<el-table-column label="标签名称" align="center" prop="menuName" />
|
<el-table-column label="标签名称" align="center" prop="menuName" />
|
||||||
|
|
Loading…
Reference in New Issue
Block a user