update store diary attachment
This commit is contained in:
@@ -34,6 +34,8 @@ public interface AttachmentMapper extends BaseMapper<Attachment, String>, RawMap
|
||||
|
||||
List<Attachment> selectAllByBizIdList(Attachment.BizType bizType, Collection<String> bizIdList, List<String> attachTypes);
|
||||
|
||||
List<Attachment> selectImageByBizIdList(Attachment.BizType bizType, Collection<String> bizIdList, String attachType);
|
||||
|
||||
long countByBizId(Attachment.BizType bizType, String bizId, List<String> attachTypes);
|
||||
|
||||
@Select("SELECT * FROM attachment WHERE `is_destroyed` = FALSE AND `destroy_at` < " + UNIX_TIME)
|
||||
|
||||
@@ -45,6 +45,12 @@ public interface AttachmentService extends BaseService<Attachment, String> {
|
||||
*/
|
||||
List<Attachment> listByBizId(Attachment.BizType bizType, String bizId, String... attachTypes);
|
||||
|
||||
default Map<String, Attachment> mapFirstImageByIdList(Attachment.BizType bizType, Collection<String> bizIdList) {
|
||||
return mapFirstImageByIdList(bizType, bizIdList, null);
|
||||
}
|
||||
|
||||
Map<String, Attachment> mapFirstImageByIdList(Attachment.BizType bizType, Collection<String> bizIdList, String attachType);
|
||||
|
||||
/**
|
||||
* 根据多个业务 ID 批量获取附件
|
||||
*
|
||||
|
||||
+8
-1
@@ -34,10 +34,12 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -244,9 +246,14 @@ public class AttachmentServiceImplement extends AbstractEntityService<Attachment
|
||||
return mapper.selectAllByBizIdList(bizType, List.of(bizId), List.of(attachTypes));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Attachment> mapFirstImageByIdList(Attachment.BizType bizType, Collection<String> bizIdList, String attachType) {
|
||||
return mapper.selectImageByBizIdList(bizType, new HashSet<>(bizIdList), attachType).stream().collect(Collectors.toMap(Attachment::getBizId, Function.identity()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, List<Attachment>> mapByBizIdList(Attachment.BizType bizType, Collection<String> bizIdList, String... attachTypes) {
|
||||
return mapper.selectAllByBizIdList(bizType, bizIdList, List.of(attachTypes)).stream().collect(Collectors.groupingBy(Attachment::getBizId));
|
||||
return mapper.selectAllByBizIdList(bizType, new HashSet<>(bizIdList), List.of(attachTypes)).stream().collect(Collectors.groupingBy(Attachment::getBizId));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
||||
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||
import com.imyeyu.api.modules.gao.service.GaoStoreDiaryService;
|
||||
import com.imyeyu.api.modules.gao.service.GaoStoreScopeService;
|
||||
import com.imyeyu.api.modules.gao.vo.GaoStoreDiaryPage;
|
||||
import com.imyeyu.api.modules.user.entity.User;
|
||||
import com.imyeyu.api.modules.user.service.UserLoginService;
|
||||
import com.imyeyu.api.modules.user.service.UserService;
|
||||
@@ -16,7 +17,6 @@ import com.imyeyu.java.bean.timi.TimiException;
|
||||
import com.imyeyu.spring.annotation.AOPLog;
|
||||
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||
import com.imyeyu.spring.bean.PageResult;
|
||||
import com.imyeyu.api.modules.gao.vo.GaoStoreDiaryPage;
|
||||
import com.imyeyu.spring.util.ResponseView;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -25,6 +25,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/// GAO 门店日记接口
|
||||
///
|
||||
/// @author Codex
|
||||
@@ -55,7 +58,16 @@ public class GaoStoreDiaryController {
|
||||
TimiException.required(page.getEndCreatedAt(), "未找到门店日记结束时间");
|
||||
TimiException.requiredTrue(page.getBeginCreatedAt() < page.getEndCreatedAt(), "门店日记时间范围无效");
|
||||
page.setStoreId(storeScopeService.resolveStoreId(page.getStoreId()));
|
||||
return service.page(page);
|
||||
PageResult<Article> result = service.page(page);
|
||||
{
|
||||
List<String> articleIdList = result.getList().stream().map(Article::getId).toList();
|
||||
Map<String, Attachment> attachMap = attachmentService.mapFirstImageByIdList(Attachment.BizType.ARTICLE, articleIdList);
|
||||
for (Article article : result.getList()) {
|
||||
Attachment attachment = attachMap.get(article.getId());
|
||||
article.setAttachmentList(TimiJava.ofList(attachment));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// 查询门店日记详情
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.imyeyu.api.modules.gao.service;
|
||||
|
||||
import com.imyeyu.api.modules.common.entity.Article;
|
||||
import com.imyeyu.spring.bean.PageResult;
|
||||
import com.imyeyu.api.modules.gao.vo.GaoStoreDiaryPage;
|
||||
import com.imyeyu.spring.bean.PageResult;
|
||||
|
||||
/// GAO 门店日记服务
|
||||
///
|
||||
|
||||
+1
-2
@@ -6,12 +6,11 @@ import com.imyeyu.api.modules.common.entity.Attachment;
|
||||
import com.imyeyu.api.modules.common.mapper.ArticleMapper;
|
||||
import com.imyeyu.api.modules.common.service.ArticleService;
|
||||
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||
import com.imyeyu.api.modules.gao.service.GaoStoreDiaryService;
|
||||
import com.imyeyu.api.modules.gao.mapper.GaoStoreDiaryMapper;
|
||||
import com.imyeyu.api.modules.gao.service.GaoStoreDiaryService;
|
||||
import com.imyeyu.api.modules.gao.vo.GaoStoreDiaryPage;
|
||||
import com.imyeyu.java.TimiJava;
|
||||
import com.imyeyu.java.bean.timi.TimiException;
|
||||
import com.imyeyu.spring.bean.Page;
|
||||
import com.imyeyu.spring.bean.PageResult;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -1,6 +1,54 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.imyeyu.api.modules.common.mapper.AttachmentMapper">
|
||||
<select id="selectImageByBizIdList" resultType="com.imyeyu.api.modules.common.entity.Attachment">
|
||||
SELECT
|
||||
`ranked`.`id`,
|
||||
`ranked`.`biz_type`,
|
||||
`ranked`.`biz_id`,
|
||||
`ranked`.`attach_type`,
|
||||
`ranked`.`mongo_id`,
|
||||
`ranked`.`title`,
|
||||
`ranked`.`name`,
|
||||
`ranked`.`mime_type`,
|
||||
`ranked`.`metadata`,
|
||||
`ranked`.`size`,
|
||||
`ranked`.`md5`,
|
||||
`ranked`.`uploader_ip`,
|
||||
`ranked`.`is_destroyed`,
|
||||
`ranked`.`created_at`,
|
||||
`ranked`.`updated_at`,
|
||||
`ranked`.`deleted_at`,
|
||||
`ranked`.`destroy_at`
|
||||
FROM (
|
||||
SELECT
|
||||
`attachment`.*,
|
||||
ROW_NUMBER() OVER (
|
||||
PARTITION BY `attachment`.`biz_id`
|
||||
ORDER BY `attachment`.`created_at`, `attachment`.`id`
|
||||
) AS `row_num`
|
||||
FROM `attachment`
|
||||
WHERE
|
||||
`biz_type` = #{bizType}
|
||||
<if test="bizIdList != null and !bizIdList.isEmpty()">
|
||||
AND `biz_id` IN
|
||||
<foreach collection="bizIdList" item="bizId" separator="," open="(" close=")">
|
||||
#{bizId}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="bizIdList == null or bizIdList.isEmpty()">
|
||||
AND FALSE
|
||||
</if>
|
||||
AND `mime_type` LIKE "image/%"
|
||||
AND `deleted_at` IS NULL
|
||||
AND (`destroy_at` IS NULL OR UNIX_TIMESTAMP() < `destroy_at`)
|
||||
<if test="attachType != null and !attachType.isEmpty()">
|
||||
AND `attach_type` = #{attachType}
|
||||
</if>
|
||||
) `ranked`
|
||||
WHERE `ranked`.`row_num` = 1
|
||||
ORDER BY `ranked`.`created_at`, `ranked`.`id`
|
||||
</select>
|
||||
<select id="selectAllByBizIdList" resultType="com.imyeyu.api.modules.common.entity.Attachment">
|
||||
SELECT
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user