Commit 88b1f2cf authored by 王飞's avatar 王飞

Merge branch 'gaixiankang' into 'dev'

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

See merge request !101
parents acc1f43f 2ed08e25
......@@ -65,7 +65,6 @@
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi-framework</artifactId>
</dependency>
</dependencies>
</project>
package com.ruoyi.domain.vo;
import com.ruoyi.domain.UserPhotoStorage;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
import java.util.List;
/**
* 照片存储VO类
* @author gxk
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class PhotoStorageVO {
/**
* 图片的创建时间
*/
private String createTime;
/**
* 图片数组
*/
private List<UserPhotoStorage> userPhotoStorageList;
}
......@@ -4,6 +4,7 @@ import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.domain.UserPhotoStorage;
import com.ruoyi.domain.vo.PhotoStorageVO;
import com.ruoyi.web.request.UserPhotoStorageCreateRequest;
import com.ruoyi.web.request.UserPhotoStorageListRequest;
......@@ -21,7 +22,7 @@ public interface UserPhotoStorageService extends IService<UserPhotoStorage>
* @param request 用户照片存储
* @return 用户照片存储集合
*/
public List<UserPhotoStorage> selectUserPhotoStorageList(UserPhotoStorageListRequest request);
public List<PhotoStorageVO> selectUserPhotoStorageList(UserPhotoStorageListRequest request);
/**
* 新增用户照片存储
......
package com.ruoyi.service.impl;
import java.util.List;
import java.util.*;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.domain.vo.PhotoStorageVO;
import com.ruoyi.framework.websocket.WebSocketUsers;
import com.ruoyi.service.UserPhotoStorageService;
import com.ruoyi.web.request.UserPhotoStorageCreateRequest;
......@@ -36,9 +38,53 @@ public class UserPhotoStorageServiceImpl extends ServiceImpl<UserPhotoStorageMap
* @return 用户照片存储
*/
@Override
public List<UserPhotoStorage> selectUserPhotoStorageList(UserPhotoStorageListRequest request)
public List<PhotoStorageVO> selectUserPhotoStorageList(UserPhotoStorageListRequest request)
{
return userPhotoStorageMapper.selectUserPhotoStorageList(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());
// Map里存在则取出value然后添加新的对象;则直接添加新的key-value
if (!photoStorageMap.containsKey(createTime)) {
List<UserPhotoStorage> photoStorageList = new ArrayList<>();
photoStorageList.add(photoStorage);
photoStorageMap.put(createTime, photoStorageList);
} else {
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;
}
/**
* 在photoStorageVOList数据没有此时间时新增一条新数据
* @param photoStorageVOList
* @param photoStorage
* @param createTime
*/
private void addPhotoStorageInNotCreateTime(List<PhotoStorageVO> photoStorageVOList, UserPhotoStorage photoStorage, String createTime) {
List<UserPhotoStorage> photoStorageChildren = new ArrayList<>();
photoStorageChildren.add(photoStorage);
PhotoStorageVO photoStorageVO = PhotoStorageVO.builder()
.createTime(createTime)
.userPhotoStorageList(photoStorageChildren).build();
photoStorageVOList.add(photoStorageVO);
}
/**
......
......@@ -5,6 +5,7 @@ import java.util.List;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.domain.vo.PhotoStorageVO;
import com.ruoyi.service.UserPhotoStorageService;
import com.ruoyi.web.request.UserPhotoStorageCreateRequest;
import com.ruoyi.web.request.UserPhotoStorageEditRequest;
......@@ -42,20 +43,18 @@ public class UserPhotoStorageController extends BaseController
/**
* 查询用户照片存储列表
*/
@Anonymous
@ApiOperation("分页查询照片存储列表")
@PostMapping("/list")
public TableDataInfo<UserPhotoStorage> list(@Validated @RequestBody UserPhotoStorageListRequest request)
public TableDataInfo<PhotoStorageVO> list(@Validated @RequestBody UserPhotoStorageListRequest request)
{
startPage();
List<UserPhotoStorage> list = userPhotoStorageService.selectUserPhotoStorageList(request);
// startPage();
List<PhotoStorageVO> list = userPhotoStorageService.selectUserPhotoStorageList(request);
return getDataTable(list);
}
/**
* 新增用户照片存储
*/
@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