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

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

parent 5b7d534c
......@@ -65,12 +65,6 @@
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi-framework</artifactId>
</dependency>
<!-- hutool工具 -->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.9</version>
</dependency>
</dependencies>
</project>
......@@ -41,33 +41,33 @@ public class UserPhotoStorageServiceImpl extends ServiceImpl<UserPhotoStorageMap
public List<PhotoStorageVO> selectUserPhotoStorageList(UserPhotoStorageListRequest request)
{
List<UserPhotoStorage> userPhotoStorages = userPhotoStorageMapper.selectUserPhotoStorageList(request);
// 把查询出的数组按照时间分组
// 创建一个VOList,用于返回数据
List<PhotoStorageVO> photoStorageVOList = new ArrayList<>();
// 创建一个hashMap,用于存储分类图片
HashMap<String, List<UserPhotoStorage>> photoStorageMap = new HashMap<>();
// 遍历userPhotoStorages,往photoStorageMap里添加数据
for (UserPhotoStorage photoStorage : userPhotoStorages) {
// 计算出当前图片对象的创建时间: yyyy-MM-dd
String createTime = DateUtils.dateTime(photoStorage.getCreateTime());
// photoStorageVOList为空时直接添加一个数据组
if (CollUtil.isEmpty(photoStorageVOList)) {
addPhotoStorageInNotCreateTime(photoStorageVOList, photoStorage, createTime);
// Map里存在则取出value然后添加新的对象;则直接添加新的key-value
if (!photoStorageMap.containsKey(createTime)) {
List<UserPhotoStorage> photoStorageList = new ArrayList<>();
photoStorageList.add(photoStorage);
photoStorageMap.put(createTime, photoStorageList);
} else {
// 查看此时间有没有对应的对象
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.get(createTime).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());
return photoStorageVOList;
}
......
......@@ -43,7 +43,6 @@ public class UserPhotoStorageController extends BaseController
/**
* 查询用户照片存储列表
*/
@Anonymous
@ApiOperation("分页查询照片存储列表")
@PostMapping("/list")
public TableDataInfo<PhotoStorageVO> list(@Validated @RequestBody UserPhotoStorageListRequest request)
......@@ -56,7 +55,6 @@ public class UserPhotoStorageController extends BaseController
/**
* 新增用户照片存储
*/
@Anonymous
@ApiOperation("新增用户照片存储")
@Log(title = "用户照片存储", businessType = BusinessType.INSERT)
@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