2023-01-06 15:17:37 +08:00
|
|
|
package com.ai.da.controller;
|
|
|
|
|
|
|
|
|
|
import com.ai.da.common.context.UserContext;
|
|
|
|
|
import com.ai.da.common.response.PageBaseResponse;
|
|
|
|
|
import com.ai.da.common.response.PageResponse;
|
|
|
|
|
import com.ai.da.common.response.Response;
|
|
|
|
|
import com.ai.da.common.utils.CopyUtil;
|
2023-10-18 16:51:08 +08:00
|
|
|
import com.ai.da.common.utils.MinioUtil;
|
2023-01-06 15:17:37 +08:00
|
|
|
import com.ai.da.mapper.entity.Account;
|
|
|
|
|
import com.ai.da.mapper.entity.Collection;
|
|
|
|
|
import com.ai.da.mapper.entity.UserLikeGroup;
|
|
|
|
|
import com.ai.da.model.dto.*;
|
|
|
|
|
import com.ai.da.model.vo.*;
|
|
|
|
|
import com.ai.da.service.*;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
import com.google.common.base.Function;
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import io.swagger.annotations.ApiParam;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.util.Assert;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import javax.validation.Valid;
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.math.RoundingMode;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Api(tags = "History模块(saved Collection)")
|
|
|
|
|
@Slf4j
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/api/history")
|
|
|
|
|
public class SavedCollectionController {
|
|
|
|
|
@Resource
|
|
|
|
|
private UserLikeGroupService userLikeGroupService;
|
|
|
|
|
@Resource
|
|
|
|
|
private UserLikeService userLikeService;
|
|
|
|
|
@Resource
|
|
|
|
|
private AccountService accountService;
|
2023-10-18 16:51:08 +08:00
|
|
|
@Resource
|
|
|
|
|
private MinioUtil minioUtil;
|
2023-01-06 15:17:37 +08:00
|
|
|
|
|
|
|
|
@ApiOperation(value = "History用户分页分组列表")
|
|
|
|
|
@PostMapping("/queryUserGroup")
|
|
|
|
|
public Response<PageBaseResponse<UserLikeGroupVO>> queryUserGroup(@Valid @RequestBody QueryHistoryPageDTO query) {
|
|
|
|
|
AuthPrincipalVo authPrincipalVo = UserContext.getUserHolder();
|
|
|
|
|
// 分页数据
|
|
|
|
|
QueryWrapper<UserLikeGroup> queryWrapper = new QueryWrapper<>();
|
|
|
|
|
|
|
|
|
|
queryWrapper.eq("account_id", authPrincipalVo.getId());
|
2023-10-20 14:47:18 +08:00
|
|
|
if (!StringUtils.isEmpty(query.getCollectionName())) {
|
2023-01-06 15:17:37 +08:00
|
|
|
queryWrapper.like("name", query.getCollectionName());
|
|
|
|
|
}
|
2023-10-20 14:47:18 +08:00
|
|
|
if (Objects.nonNull(query.getStartDate())) {
|
2023-01-06 15:17:37 +08:00
|
|
|
queryWrapper.ge("update_date", new Date(query.getStartDate()));
|
|
|
|
|
}
|
2023-10-20 14:47:18 +08:00
|
|
|
if (Objects.nonNull(query.getEndDate())) {
|
2023-01-06 15:17:37 +08:00
|
|
|
queryWrapper.le("update_date", new Date(query.getEndDate()));
|
|
|
|
|
}
|
|
|
|
|
queryWrapper.orderByDesc("id");
|
|
|
|
|
IPage<UserLikeGroup> page = userLikeGroupService.getBaseMapper().selectPage(
|
|
|
|
|
new Page<>(query.getPage(), query.getSize()), queryWrapper);
|
2023-10-20 14:47:18 +08:00
|
|
|
if (CollectionUtils.isEmpty(page.getRecords())) {
|
2023-01-06 15:17:37 +08:00
|
|
|
return Response.success(PageBaseResponse.success(new Page<>()));
|
|
|
|
|
}
|
|
|
|
|
List<Long> groupIds = page.getRecords().stream().map(UserLikeGroup::getId).collect(Collectors.toList());
|
|
|
|
|
List<UserLikeVO> groupDetails = userLikeService.getGroupDetails(groupIds);
|
2023-10-20 14:47:18 +08:00
|
|
|
Assert.notEmpty(groupDetails, "History detail does not exist!");
|
|
|
|
|
Map<Long, List<UserLikeVO>> groupDetailMap = groupDetails.stream()
|
2023-01-06 15:17:37 +08:00
|
|
|
.collect(Collectors.groupingBy(UserLikeVO::getUserLikeGroupId));
|
|
|
|
|
|
2023-10-20 14:47:18 +08:00
|
|
|
Account account = accountService.getById(authPrincipalVo.getId());
|
2023-01-06 15:17:37 +08:00
|
|
|
IPage<UserLikeGroupVO> convert = page.convert((Function<UserLikeGroup, UserLikeGroupVO>) group -> {
|
2023-10-20 14:47:18 +08:00
|
|
|
if (group != null) {
|
|
|
|
|
UserLikeGroupVO userLikeGroupVO = CopyUtil.copyObject(group, UserLikeGroupVO.class);
|
|
|
|
|
userLikeGroupVO.setUpdateDate(group.getUpdateDate().getTime());
|
2023-01-06 15:17:37 +08:00
|
|
|
userLikeGroupVO.setAuthor(account.getUserName());
|
|
|
|
|
//count 和detail
|
|
|
|
|
List<UserLikeVO> details = groupDetailMap.get(group.getId());
|
2023-10-18 16:51:08 +08:00
|
|
|
for (UserLikeVO detail : details) {
|
|
|
|
|
detail.setUrl(minioUtil.getPresignedUrl(detail.getUrl(), 24 * 60));
|
|
|
|
|
}
|
2023-01-06 15:17:37 +08:00
|
|
|
userLikeGroupVO.setGroupDetails(details);
|
2023-10-20 14:47:18 +08:00
|
|
|
userLikeGroupVO.setSketchCount(CollectionUtils.isEmpty(details) ? 0 : details.size());
|
2023-01-06 15:17:37 +08:00
|
|
|
return userLikeGroupVO;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
});
|
|
|
|
|
return Response.success(PageBaseResponse.success(convert));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "History用户分组详情,目前弃用 ")
|
|
|
|
|
@GetMapping("/getUserGroupDetail")
|
|
|
|
|
public Response<List<UserLikeVO>> getUserGroupDetail(
|
|
|
|
|
@ApiParam("用户分组id") @RequestParam("userGroupId") Long userGroupId) {
|
|
|
|
|
return Response.success(userLikeService.getGroupDetail(userGroupId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "History修改用户分组名")
|
|
|
|
|
@PostMapping("/updateUserGroupName")
|
|
|
|
|
public Response<HistoryUpdateVO> updateUserGroupName(@Valid @RequestBody HistoryUpdateDTO historyUpdateDTO) {
|
|
|
|
|
return Response.success(userLikeGroupService.updateUserGroupName(historyUpdateDTO.getUserGroupId()
|
2023-10-20 14:47:18 +08:00
|
|
|
, historyUpdateDTO.getUserGroupName(), historyUpdateDTO.getTimeZone()));
|
2023-01-06 15:17:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "History删除用户分组")
|
|
|
|
|
@PostMapping("/deleteUserGroup")
|
|
|
|
|
public Response<Boolean> deleteUserGroup(@Valid @RequestBody HistoryDeleteDTO deleteDTO) {
|
|
|
|
|
userLikeGroupService.deleteUserGroup(deleteDTO.getUserGroupId());
|
|
|
|
|
userLikeService.deleteByUserGroupId(deleteDTO.getUserGroupId());
|
|
|
|
|
return Response.success(Boolean.TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "History choose")
|
|
|
|
|
@GetMapping("/choose")
|
|
|
|
|
public Response<UserLikeChooseVO> choose(
|
2023-10-20 14:47:18 +08:00
|
|
|
@ApiParam("用户分组id") @RequestParam("userGroupId") Long userGroupId) {
|
2023-01-06 15:17:37 +08:00
|
|
|
return Response.success(userLikeGroupService.choose(userGroupId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|