Commit 2ed08e25 authored by 盖献康's avatar 盖献康

查询素材库 - 按照时间进行分组显示(修改)

parent 5b7d534c
...@@ -65,12 +65,6 @@ ...@@ -65,12 +65,6 @@
<groupId>com.ruoyi</groupId> <groupId>com.ruoyi</groupId>
<artifactId>ruoyi-framework</artifactId> <artifactId>ruoyi-framework</artifactId>
</dependency> </dependency>
<!-- hutool工具 -->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.9</version>
</dependency>
</dependencies> </dependencies>
</project> </project>
...@@ -41,33 +41,33 @@ public class UserPhotoStorageServiceImpl extends ServiceImpl<UserPhotoStorageMap ...@@ -41,33 +41,33 @@ public class UserPhotoStorageServiceImpl extends ServiceImpl<UserPhotoStorageMap
public List<PhotoStorageVO> selectUserPhotoStorageList(UserPhotoStorageListRequest request) public List<PhotoStorageVO> selectUserPhotoStorageList(UserPhotoStorageListRequest request)
{ {
List<UserPhotoStorage> userPhotoStorages = userPhotoStorageMapper.selectUserPhotoStorageList(request); List<UserPhotoStorage> userPhotoStorages = userPhotoStorageMapper.selectUserPhotoStorageList(request);
// 把查询出的数组按照时间分组 // 创建一个VOList,用于返回数据
List<PhotoStorageVO> photoStorageVOList = new ArrayList<>(); List<PhotoStorageVO> photoStorageVOList = new ArrayList<>();
// 创建一个hashMap,用于存储分类图片
HashMap<String, List<UserPhotoStorage>> photoStorageMap = new HashMap<>();
// 遍历userPhotoStorages,往photoStorageMap里添加数据
for (UserPhotoStorage photoStorage : userPhotoStorages) { for (UserPhotoStorage photoStorage : userPhotoStorages) {
// 计算出当前图片对象的创建时间: yyyy-MM-dd
String createTime = DateUtils.dateTime(photoStorage.getCreateTime()); String createTime = DateUtils.dateTime(photoStorage.getCreateTime());
// photoStorageVOList为空时直接添加一个数据组 // Map里存在则取出value然后添加新的对象;则直接添加新的key-value
if (CollUtil.isEmpty(photoStorageVOList)) { if (!photoStorageMap.containsKey(createTime)) {
addPhotoStorageInNotCreateTime(photoStorageVOList, photoStorage, createTime); List<UserPhotoStorage> photoStorageList = new ArrayList<>();
photoStorageList.add(photoStorage);
photoStorageMap.put(createTime, photoStorageList);
} else { } else {
// 查看此时间有没有对应的对象 photoStorageMap.get(createTime).add(photoStorage);
PhotoStorageVO storageVO = new PhotoStorageVO();
int num = 0;
for (PhotoStorageVO photoStorageVO : photoStorageVOList) {
if (photoStorageVO.getCreateTime().equals(createTime)) {
num++;
storageVO = photoStorageVO;
}
}
// num为0表示,没有此时间的对象,直接添加一个数据组;则取出此时间对象,往集合里新插入一条数据
if (num == 0) {
addPhotoStorageInNotCreateTime(photoStorageVOList, photoStorage, createTime);
} else {
List<UserPhotoStorage> userPhotoStorageList = storageVO.getUserPhotoStorageList();
userPhotoStorageList.add(photoStorage);
} }
} }
// 遍历photoStorageMap,将value赋值给photoStorageVOList
for (Map.Entry<String, List<UserPhotoStorage>> entry : photoStorageMap.entrySet()) {
// entry.getValue()以时间降序排列
entry.getValue().sort(Comparator.comparing(UserPhotoStorage::getCreateTime).reversed());
PhotoStorageVO photoStorageVO = PhotoStorageVO.builder()
.createTime(entry.getKey())
.userPhotoStorageList(entry.getValue()).build();
photoStorageVOList.add(photoStorageVO);
} }
// 根据时间倒序排序 // photoStorageVOList以创建时间降序排列
photoStorageVOList.sort(Comparator.comparing(PhotoStorageVO::getCreateTime).reversed()); photoStorageVOList.sort(Comparator.comparing(PhotoStorageVO::getCreateTime).reversed());
return photoStorageVOList; return photoStorageVOList;
} }
......
...@@ -43,7 +43,6 @@ public class UserPhotoStorageController extends BaseController ...@@ -43,7 +43,6 @@ public class UserPhotoStorageController extends BaseController
/** /**
* 查询用户照片存储列表 * 查询用户照片存储列表
*/ */
@Anonymous
@ApiOperation("分页查询照片存储列表") @ApiOperation("分页查询照片存储列表")
@PostMapping("/list") @PostMapping("/list")
public TableDataInfo<PhotoStorageVO> list(@Validated @RequestBody UserPhotoStorageListRequest request) public TableDataInfo<PhotoStorageVO> list(@Validated @RequestBody UserPhotoStorageListRequest request)
...@@ -56,7 +55,6 @@ public class UserPhotoStorageController extends BaseController ...@@ -56,7 +55,6 @@ public class UserPhotoStorageController extends BaseController
/** /**
* 新增用户照片存储 * 新增用户照片存储
*/ */
@Anonymous
@ApiOperation("新增用户照片存储") @ApiOperation("新增用户照片存储")
@Log(title = "用户照片存储", businessType = BusinessType.INSERT) @Log(title = "用户照片存储", businessType = BusinessType.INSERT)
@PostMapping("/create") @PostMapping("/create")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment