farm模块-批量上传
This commit is contained in:
@@ -19,7 +19,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
|||||||
* @author: binda
|
* @author: binda
|
||||||
* @date: 2025/8/14 19:43
|
* @date: 2025/8/14 19:43
|
||||||
*/
|
*/
|
||||||
@Tag(name = "弄成首页")
|
@Tag(name = "农场首页")
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/farm/home")
|
@RequestMapping("/farm/home")
|
||||||
@Validated
|
@Validated
|
||||||
|
|||||||
@@ -6,9 +6,11 @@ import java.time.LocalDateTime;
|
|||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.*;
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||||
|
import cn.iocoder.yudao.module.farm.framework.util.ImageCollectionUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设备信息 DO
|
* 设备信息 DO
|
||||||
@@ -100,17 +102,40 @@ public class DeviceInfoDO extends BaseDO {
|
|||||||
*/
|
*/
|
||||||
private LocalDateTime updatedAt;
|
private LocalDateTime updatedAt;
|
||||||
/**
|
/**
|
||||||
* 设备图片
|
* 设备图片(数据库存储为逗号分隔的字符串)
|
||||||
*/
|
*/
|
||||||
|
@TableField(value = "image")
|
||||||
private String image;
|
private String image;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 告警状态图片
|
* 设备图片集合(业务层使用)
|
||||||
*/
|
*/
|
||||||
|
@TableField(exist = false)
|
||||||
|
private List<String> imageList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 告警状态图片(数据库存储为逗号分隔的字符串)
|
||||||
|
*/
|
||||||
|
@TableField(value = "alarm_image")
|
||||||
private String alarmImage;
|
private String alarmImage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 离线状态图片
|
* 告警状态图片集合(业务层使用)
|
||||||
*/
|
*/
|
||||||
|
@TableField(exist = false)
|
||||||
|
private List<String> alarmImageList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 离线状态图片(数据库存储为逗号分隔的字符串)
|
||||||
|
*/
|
||||||
|
@TableField(value = "offline_image")
|
||||||
private String offlineImage;
|
private String offlineImage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 离线状态图片集合(业务层使用)
|
||||||
|
*/
|
||||||
|
@TableField(exist = false)
|
||||||
|
private List<String> offlineImageList;
|
||||||
/**
|
/**
|
||||||
* 分类图标
|
* 分类图标
|
||||||
*/
|
*/
|
||||||
@@ -136,9 +161,16 @@ public class DeviceInfoDO extends BaseDO {
|
|||||||
*/
|
*/
|
||||||
private String edgeInstanceUniqueId;
|
private String edgeInstanceUniqueId;
|
||||||
/**
|
/**
|
||||||
* 数据快照
|
* 数据快照(数据库存储为逗号分隔的字符串)
|
||||||
*/
|
*/
|
||||||
|
@TableField(value = "data_image")
|
||||||
private String dataImage;
|
private String dataImage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据快照集合(业务层使用)
|
||||||
|
*/
|
||||||
|
@TableField(exist = false)
|
||||||
|
private List<String> dataImageList;
|
||||||
/**
|
/**
|
||||||
* 基地id
|
* 基地id
|
||||||
*/
|
*/
|
||||||
@@ -157,4 +189,76 @@ public class DeviceInfoDO extends BaseDO {
|
|||||||
private String plotName;
|
private String plotName;
|
||||||
|
|
||||||
private String tenantId;
|
private String tenantId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取设备图片集合
|
||||||
|
*/
|
||||||
|
public List<String> getImageList() {
|
||||||
|
if (imageList == null) {
|
||||||
|
imageList = ImageCollectionUtil.toImageList(this.image);
|
||||||
|
}
|
||||||
|
return imageList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置设备图片集合
|
||||||
|
*/
|
||||||
|
public void setImageList(List<String> imageList) {
|
||||||
|
this.imageList = imageList;
|
||||||
|
this.image = ImageCollectionUtil.toDatabaseString(imageList);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取告警状态图片集合
|
||||||
|
*/
|
||||||
|
public List<String> getAlarmImageList() {
|
||||||
|
if (alarmImageList == null) {
|
||||||
|
alarmImageList = ImageCollectionUtil.toImageList(this.alarmImage);
|
||||||
|
}
|
||||||
|
return alarmImageList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置告警状态图片集合
|
||||||
|
*/
|
||||||
|
public void setAlarmImageList(List<String> alarmImageList) {
|
||||||
|
this.alarmImageList = alarmImageList;
|
||||||
|
this.alarmImage = ImageCollectionUtil.toDatabaseString(alarmImageList);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取离线状态图片集合
|
||||||
|
*/
|
||||||
|
public List<String> getOfflineImageList() {
|
||||||
|
if (offlineImageList == null) {
|
||||||
|
offlineImageList = ImageCollectionUtil.toImageList(this.offlineImage);
|
||||||
|
}
|
||||||
|
return offlineImageList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置离线状态图片集合
|
||||||
|
*/
|
||||||
|
public void setOfflineImageList(List<String> offlineImageList) {
|
||||||
|
this.offlineImageList = offlineImageList;
|
||||||
|
this.offlineImage = ImageCollectionUtil.toDatabaseString(offlineImageList);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取数据快照集合
|
||||||
|
*/
|
||||||
|
public List<String> getDataImageList() {
|
||||||
|
if (dataImageList == null) {
|
||||||
|
dataImageList = ImageCollectionUtil.toImageList(this.dataImage);
|
||||||
|
}
|
||||||
|
return dataImageList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置数据快照集合
|
||||||
|
*/
|
||||||
|
public void setDataImageList(List<String> dataImageList) {
|
||||||
|
this.dataImageList = dataImageList;
|
||||||
|
this.dataImage = ImageCollectionUtil.toDatabaseString(dataImageList);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,10 @@ import lombok.*;
|
|||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
import com.baomidou.mybatisplus.annotation.*;
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||||
|
import cn.iocoder.yudao.module.farm.framework.util.ImageCollectionUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 病虫草害库维护 DO
|
* 病虫草害库维护 DO
|
||||||
@@ -44,9 +46,16 @@ public class PestDiseaseWeedLibraryDO extends BaseDO {
|
|||||||
*/
|
*/
|
||||||
private String propose;
|
private String propose;
|
||||||
/**
|
/**
|
||||||
* 图片
|
* 图片(数据库存储为逗号分隔的字符串)
|
||||||
*/
|
*/
|
||||||
|
@TableField(value = "images")
|
||||||
private String images;
|
private String images;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图片集合(业务层使用)
|
||||||
|
*/
|
||||||
|
@TableField(exist = false)
|
||||||
|
private List<String> imageList;
|
||||||
/**
|
/**
|
||||||
* 0=启用,1=停用
|
* 0=启用,1=停用
|
||||||
*/
|
*/
|
||||||
@@ -69,4 +78,22 @@ public class PestDiseaseWeedLibraryDO extends BaseDO {
|
|||||||
private String plotName;
|
private String plotName;
|
||||||
|
|
||||||
private String tenantId;
|
private String tenantId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取图片集合
|
||||||
|
*/
|
||||||
|
public List<String> getImageList() {
|
||||||
|
if (imageList == null) {
|
||||||
|
imageList = ImageCollectionUtil.toImageList(this.images);
|
||||||
|
}
|
||||||
|
return imageList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置图片集合
|
||||||
|
*/
|
||||||
|
public void setImageList(List<String> imageList) {
|
||||||
|
this.imageList = imageList;
|
||||||
|
this.images = ImageCollectionUtil.toDatabaseString(imageList);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -4,8 +4,10 @@ import lombok.*;
|
|||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
import com.baomidou.mybatisplus.annotation.*;
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||||
|
import cn.iocoder.yudao.module.farm.framework.util.ImageCollectionUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品管理 DO
|
* 商品管理 DO
|
||||||
@@ -44,9 +46,17 @@ public class ProductManagementDO extends BaseDO {
|
|||||||
*/
|
*/
|
||||||
private String packingUnit;
|
private String packingUnit;
|
||||||
/**
|
/**
|
||||||
* 商品图片
|
* 商品图片(数据库存储为逗号分隔的字符串)
|
||||||
*/
|
*/
|
||||||
|
@TableField(value = "image")
|
||||||
private String image;
|
private String image;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品图片集合(业务层使用)
|
||||||
|
*/
|
||||||
|
@TableField(exist = false)
|
||||||
|
private List<String> imageList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品介绍
|
* 商品介绍
|
||||||
*/
|
*/
|
||||||
@@ -64,9 +74,16 @@ public class ProductManagementDO extends BaseDO {
|
|||||||
*/
|
*/
|
||||||
private String brandName;
|
private String brandName;
|
||||||
/**
|
/**
|
||||||
* 商标图片
|
* 商标图片(数据库存储为逗号分隔的字符串)
|
||||||
*/
|
*/
|
||||||
|
@TableField(value = "brand_image")
|
||||||
private String brandImage;
|
private String brandImage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商标图片集合(业务层使用)
|
||||||
|
*/
|
||||||
|
@TableField(exist = false)
|
||||||
|
private List<String> brandImageList;
|
||||||
/**
|
/**
|
||||||
* 商品认证
|
* 商品认证
|
||||||
*/
|
*/
|
||||||
@@ -89,4 +106,40 @@ public class ProductManagementDO extends BaseDO {
|
|||||||
private String plotName;
|
private String plotName;
|
||||||
|
|
||||||
private String tenantId;
|
private String tenantId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取商品图片集合
|
||||||
|
*/
|
||||||
|
public List<String> getImageList() {
|
||||||
|
if (imageList == null) {
|
||||||
|
imageList = ImageCollectionUtil.toImageList(this.image);
|
||||||
|
}
|
||||||
|
return imageList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置商品图片集合
|
||||||
|
*/
|
||||||
|
public void setImageList(List<String> imageList) {
|
||||||
|
this.imageList = imageList;
|
||||||
|
this.image = ImageCollectionUtil.toDatabaseString(imageList);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取商标图片集合
|
||||||
|
*/
|
||||||
|
public List<String> getBrandImageList() {
|
||||||
|
if (brandImageList == null) {
|
||||||
|
brandImageList = ImageCollectionUtil.toImageList(this.brandImage);
|
||||||
|
}
|
||||||
|
return brandImageList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置商标图片集合
|
||||||
|
*/
|
||||||
|
public void setBrandImageList(List<String> brandImageList) {
|
||||||
|
this.brandImageList = brandImageList;
|
||||||
|
this.brandImage = ImageCollectionUtil.toDatabaseString(brandImageList);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,10 @@ import lombok.*;
|
|||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
import com.baomidou.mybatisplus.annotation.*;
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||||
|
import cn.iocoder.yudao.module.farm.framework.util.ImageCollectionUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 物种库维护 DO
|
* 物种库维护 DO
|
||||||
@@ -48,9 +50,34 @@ public class SpeciesLibraryDO extends BaseDO {
|
|||||||
*/
|
*/
|
||||||
private Integer lifeCycle;
|
private Integer lifeCycle;
|
||||||
/**
|
/**
|
||||||
* 图片
|
* 图片集合(数据库存储为逗号分隔的字符串)
|
||||||
*/
|
*/
|
||||||
|
@TableField(value = "image")
|
||||||
private String image;
|
private String image;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图片集合(业务层使用)
|
||||||
|
*/
|
||||||
|
@TableField(exist = false)
|
||||||
|
private List<String> imageList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取图片集合
|
||||||
|
*/
|
||||||
|
public List<String> getImageList() {
|
||||||
|
if (imageList == null) {
|
||||||
|
imageList = ImageCollectionUtil.toImageList(this.image);
|
||||||
|
}
|
||||||
|
return imageList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置图片集合
|
||||||
|
*/
|
||||||
|
public void setImageList(List<String> imageList) {
|
||||||
|
this.imageList = imageList;
|
||||||
|
this.image = ImageCollectionUtil.toDatabaseString(imageList);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 0=启用,1=停用
|
* 0=启用,1=停用
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -4,9 +4,11 @@ import lombok.*;
|
|||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.*;
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||||
|
import cn.iocoder.yudao.module.farm.framework.util.ImageCollectionUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 气象灾害库维护 DO
|
* 气象灾害库维护 DO
|
||||||
@@ -41,9 +43,16 @@ public class WeatherDisasterLibraryDO extends BaseDO {
|
|||||||
*/
|
*/
|
||||||
private String propose;
|
private String propose;
|
||||||
/**
|
/**
|
||||||
* 图片
|
* 图片(数据库存储为逗号分隔的字符串)
|
||||||
*/
|
*/
|
||||||
|
@TableField(value = "images")
|
||||||
private String images;
|
private String images;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图片集合(业务层使用)
|
||||||
|
*/
|
||||||
|
@TableField(exist = false)
|
||||||
|
private List<String> imageList;
|
||||||
/**
|
/**
|
||||||
* 0=启用,1=停用
|
* 0=启用,1=停用
|
||||||
*/
|
*/
|
||||||
@@ -66,4 +75,22 @@ public class WeatherDisasterLibraryDO extends BaseDO {
|
|||||||
private String plotName;
|
private String plotName;
|
||||||
|
|
||||||
private String tenantId;
|
private String tenantId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取图片集合
|
||||||
|
*/
|
||||||
|
public List<String> getImageList() {
|
||||||
|
if (imageList == null) {
|
||||||
|
imageList = ImageCollectionUtil.toImageList(this.images);
|
||||||
|
}
|
||||||
|
return imageList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置图片集合
|
||||||
|
*/
|
||||||
|
public void setImageList(List<String> imageList) {
|
||||||
|
this.imageList = imageList;
|
||||||
|
this.images = ImageCollectionUtil.toDatabaseString(imageList);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,170 @@
|
|||||||
|
package cn.iocoder.yudao.module.farm.framework.util;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图片集合转换工具类
|
||||||
|
* 用于在数据库字符串(逗号分隔)和Java集合之间转换
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class ImageCollectionUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分隔符
|
||||||
|
*/
|
||||||
|
private static final String SEPARATOR = ",";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将图片集合转换为数据库存储的字符串
|
||||||
|
*
|
||||||
|
* @param imageList 图片集合
|
||||||
|
* @return 逗号分隔的字符串,如果集合为空则返回null
|
||||||
|
*/
|
||||||
|
public static String toDatabaseString(List<String> imageList) {
|
||||||
|
if (imageList == null || imageList.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// 过滤空字符串并去重
|
||||||
|
List<String> filteredList = imageList.stream()
|
||||||
|
.filter(StrUtil::isNotBlank)
|
||||||
|
.distinct()
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
if (filteredList.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return String.join(SEPARATOR, filteredList);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将数据库字符串转换为图片集合
|
||||||
|
*
|
||||||
|
* @param databaseString 数据库中的字符串
|
||||||
|
* @return 图片集合,如果字符串为空则返回空集合
|
||||||
|
*/
|
||||||
|
public static List<String> toImageList(String databaseString) {
|
||||||
|
if (StrUtil.isBlank(databaseString)) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return Arrays.stream(databaseString.split(SEPARATOR))
|
||||||
|
.map(String::trim)
|
||||||
|
.filter(StrUtil::isNotBlank)
|
||||||
|
.distinct()
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("转换图片集合失败,原始字符串: {}", databaseString, e);
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将单个图片URL转换为集合(兼容旧数据)
|
||||||
|
*
|
||||||
|
* @param singleImage 单个图片URL
|
||||||
|
* @return 图片集合
|
||||||
|
*/
|
||||||
|
public static List<String> singleToImageList(String singleImage) {
|
||||||
|
if (StrUtil.isBlank(singleImage)) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果已经是逗号分隔的格式,直接转换
|
||||||
|
if (singleImage.contains(SEPARATOR)) {
|
||||||
|
return toImageList(singleImage);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 单个图片,包装成集合
|
||||||
|
List<String> imageList = new ArrayList<>();
|
||||||
|
imageList.add(singleImage);
|
||||||
|
return imageList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将图片集合转换为单个图片URL(兼容旧接口)
|
||||||
|
* 取第一个图片,如果没有则返回null
|
||||||
|
*
|
||||||
|
* @param imageList 图片集合
|
||||||
|
* @return 第一个图片URL或null
|
||||||
|
*/
|
||||||
|
public static String imageListToSingle(List<String> imageList) {
|
||||||
|
if (imageList == null || imageList.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return imageList.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证图片集合是否有效
|
||||||
|
*
|
||||||
|
* @param imageList 图片集合
|
||||||
|
* @return 是否有效
|
||||||
|
*/
|
||||||
|
public static boolean isValidImageList(List<String> imageList) {
|
||||||
|
if (imageList == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查是否有空字符串
|
||||||
|
return imageList.stream().allMatch(StrUtil::isNotBlank);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取图片集合的大小
|
||||||
|
*
|
||||||
|
* @param imageList 图片集合
|
||||||
|
* @return 图片数量
|
||||||
|
*/
|
||||||
|
public static int getImageCount(List<String> imageList) {
|
||||||
|
if (imageList == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return imageList.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加图片到集合
|
||||||
|
*
|
||||||
|
* @param imageList 原图片集合
|
||||||
|
* @param newImage 新图片URL
|
||||||
|
* @return 新的图片集合
|
||||||
|
*/
|
||||||
|
public static List<String> addImage(List<String> imageList, String newImage) {
|
||||||
|
if (StrUtil.isBlank(newImage)) {
|
||||||
|
return imageList != null ? new ArrayList<>(imageList) : new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> result = imageList != null ? new ArrayList<>(imageList) : new ArrayList<>();
|
||||||
|
if (!result.contains(newImage)) {
|
||||||
|
result.add(newImage);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从集合中移除图片
|
||||||
|
*
|
||||||
|
* @param imageList 原图片集合
|
||||||
|
* @param imageToRemove 要移除的图片URL
|
||||||
|
* @return 新的图片集合
|
||||||
|
*/
|
||||||
|
public static List<String> removeImage(List<String> imageList, String imageToRemove) {
|
||||||
|
if (imageList == null || StrUtil.isBlank(imageToRemove)) {
|
||||||
|
return imageList != null ? new ArrayList<>(imageList) : new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> result = new ArrayList<>(imageList);
|
||||||
|
result.remove(imageToRemove);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,8 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|||||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
|
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
|
||||||
import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.*;
|
import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.*;
|
||||||
|
import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FileMultiUploadReqVO;
|
||||||
|
import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FileMultiUploadRespVO;
|
||||||
import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileDO;
|
import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileDO;
|
||||||
import cn.iocoder.yudao.module.infra.service.file.FileService;
|
import cn.iocoder.yudao.module.infra.service.file.FileService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import cn.hutool.crypto.digest.DigestUtil;
|
|||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FileCreateReqVO;
|
import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FileCreateReqVO;
|
||||||
@@ -41,13 +42,13 @@ public class FileServiceImpl implements FileService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传文件的前缀,是否包含日期(yyyyMMdd)
|
* 上传文件的前缀,是否包含日期(yyyyMMdd)
|
||||||
*
|
* <p>
|
||||||
* 目的:按照日期,进行分目录
|
* 目的:按照日期,进行分目录
|
||||||
*/
|
*/
|
||||||
static boolean PATH_PREFIX_DATE_ENABLE = true;
|
static boolean PATH_PREFIX_DATE_ENABLE = true;
|
||||||
/**
|
/**
|
||||||
* 上传文件的后缀,是否包含时间戳
|
* 上传文件的后缀,是否包含时间戳
|
||||||
*
|
* <p>
|
||||||
* 目的:保证文件的唯一性,避免覆盖
|
* 目的:保证文件的唯一性,避免覆盖
|
||||||
* 定制:可按需调整成 UUID、或者其他方式
|
* 定制:可按需调整成 UUID、或者其他方式
|
||||||
*/
|
*/
|
||||||
@@ -109,7 +110,6 @@ public class FileServiceImpl implements FileService {
|
|||||||
fileResult.setOriginalName(file.getOriginalFilename());
|
fileResult.setOriginalName(file.getOriginalFilename());
|
||||||
fileResult.setSize(file.getSize());
|
fileResult.setSize(file.getSize());
|
||||||
fileResult.setType(file.getContentType());
|
fileResult.setType(file.getContentType());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 上传文件
|
// 上传文件
|
||||||
byte[] content = IoUtil.readBytes(file.getInputStream());
|
byte[] content = IoUtil.readBytes(file.getInputStream());
|
||||||
@@ -119,6 +119,10 @@ public class FileServiceImpl implements FileService {
|
|||||||
fileResult.setUrl(url);
|
fileResult.setUrl(url);
|
||||||
fileResult.setSuccess(true);
|
fileResult.setSuccess(true);
|
||||||
successFiles.add(fileResult);
|
successFiles.add(fileResult);
|
||||||
|
FileClient client = fileConfigService.getMasterFileClient();
|
||||||
|
fileMapper.insert(new FileDO().setConfigId(client.getId())
|
||||||
|
.setName(fileResult.getOriginalName()).setUrl(url)
|
||||||
|
.setType(fileResult.getType()).setSize((int) file.getSize()));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// 设置失败结果
|
// 设置失败结果
|
||||||
fileResult.setSuccess(false);
|
fileResult.setSuccess(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user