diff --git a/src/main/java/com/ctrip/zeus/service/model/ArchiveService.java b/src/main/java/com/ctrip/zeus/service/model/ArchiveService.java index 1ef24245..37b2a56e 100644 --- a/src/main/java/com/ctrip/zeus/service/model/ArchiveService.java +++ b/src/main/java/com/ctrip/zeus/service/model/ArchiveService.java @@ -3,6 +3,7 @@ package com.ctrip.zeus.service.model; import com.ctrip.zeus.model.entity.Group; import com.ctrip.zeus.model.entity.Archive; import com.ctrip.zeus.model.entity.Slb; + import java.util.List; /** @@ -42,4 +43,8 @@ public interface ArchiveService { Archive getVsArchive(Long vsId, int version) throws Exception; Archive getLatestVsArchive(Long vsId) throws Exception; + + List getVsArchives(Long[] vsIds, Integer[] versions) throws Exception; + + List getGroupArchives(Long[] groupIds, Integer[] versions) throws Exception; } diff --git a/src/main/java/com/ctrip/zeus/service/model/impl/ArchiveServiceImpl.java b/src/main/java/com/ctrip/zeus/service/model/impl/ArchiveServiceImpl.java index 4df3668e..41545ef9 100644 --- a/src/main/java/com/ctrip/zeus/service/model/impl/ArchiveServiceImpl.java +++ b/src/main/java/com/ctrip/zeus/service/model/impl/ArchiveServiceImpl.java @@ -141,4 +141,42 @@ public class ArchiveServiceImpl implements ArchiveService { MetaVsArchiveDo d = archiveVsDao.findMaxVersionByVs(vsId, ArchiveVsEntity.READSET_FULL); return new Archive().setId(d.getVsId()).setContent(d.getContent()).setVersion(d.getVersion()); } + + @Override + public List getVsArchives(Long[] vsIds, Integer[] versions) throws Exception { + String[] pairs = new String[vsIds.length]; + for (int i = 0; i < pairs.length; i++) { + pairs[i] = vsIds[i] + "," + versions[i]; + } + List list = archiveVsDao.findAllByVsAndVersion(vsIds, pairs, ArchiveVsEntity.READSET_IDONLY); + Long[] ids = new Long[list.size()]; + for (int i = 0; i < ids.length; i++) { + ids[i] = list.get(i).getId(); + } + list = archiveVsDao.findAllByIds(ids, ArchiveVsEntity.READSET_FULL); + List result = new ArrayList<>(list.size()); + for (MetaVsArchiveDo d : list) { + result.add(new Archive().setId(d.getVsId()).setContent(d.getContent()).setVersion(d.getVersion())); + } + return result; + } + + @Override + public List getGroupArchives(Long[] groupIds, Integer[] versions) throws Exception { + String[] pairs = new String[groupIds.length]; + for (int i = 0; i < pairs.length; i++) { + pairs[i] = groupIds[i] + "," + versions[i]; + } + List list = archiveGroupDao.findAllByGroupAndVersion(groupIds, pairs, ArchiveGroupEntity.READSET_IDONLY); + Long[] ids = new Long[list.size()]; + for (int i = 0; i < ids.length; i++) { + ids[i] = list.get(i).getId(); + } + list = archiveGroupDao.findAllByIds(ids, ArchiveGroupEntity.READSET_FULL); + List result = new ArrayList<>(list.size()); + for (ArchiveGroupDo d : list) { + result.add(C.toGroupArchive(d)); + } + return result; + } } \ No newline at end of file diff --git a/src/main/resources/META-INF/dal/jdbc/meta-group.xml b/src/main/resources/META-INF/dal/jdbc/meta-group.xml index e0a6a61e..a01e6a79 100644 --- a/src/main/resources/META-INF/dal/jdbc/meta-group.xml +++ b/src/main/resources/META-INF/dal/jdbc/meta-group.xml @@ -88,7 +88,23 @@ + + + + + + + + + + + FROM + WHERE in ${ids} + ]]> + + @@ -144,6 +160,19 @@ ]]> + + + + + + FROM ( + SELECT id, concat(group_id, ',', version) as g_v FROM archive_group + WHERE group_id in ${ids} ) ag + WHERE ag.g_v in ${pairs} + ]]> + + diff --git a/src/main/resources/META-INF/dal/jdbc/meta-vs.xml b/src/main/resources/META-INF/dal/jdbc/meta-vs.xml index 26a8ec47..23fb83c5 100644 --- a/src/main/resources/META-INF/dal/jdbc/meta-vs.xml +++ b/src/main/resources/META-INF/dal/jdbc/meta-vs.xml @@ -28,7 +28,23 @@ + + + + + + + + + + + FROM
+ WHERE in ${ids} + ]]> + + + + + + + + FROM ( + SELECT id, concat(vs_id, ',', version) as vs_v FROM archive_vs + WHERE vs_id in ${ids} ) av + WHERE av.vs_v in ${pairs} + ]]> + +