提交 3117c3b8 作者: yanxin

专题绑定信息源查询逻辑修改

上级 8e77f4a4
...@@ -103,7 +103,7 @@ public class RelationBindController { ...@@ -103,7 +103,7 @@ public class RelationBindController {
} }
subjectIdList.add(subjectId); subjectIdList.add(subjectId);
} }
IPage<InfoSourceVo> pageList = infoSourceService.bindInfoSourceList(infoSourceCondition, subjectIdList, pageNo, pageSize); IPage<InfoSourceVo> pageList = infoSourceService.bindInfoSourcePageList(infoSourceCondition, subjectIdList, pageNo, pageSize);
return Result.OK(pageList); return Result.OK(pageList);
} }
......
...@@ -102,4 +102,6 @@ public interface CommonMapper { ...@@ -102,4 +102,6 @@ public interface CommonMapper {
* @date 2025/2/5 * @date 2025/2/5
*/ */
List<LabelItemMapVO> infoSourceLabelsBySidList(@Param("sidList") List<String> sidList); List<LabelItemMapVO> infoSourceLabelsBySidList(@Param("sidList") List<String> sidList);
List<SubjectSourceVO> bindSourceCount(@Param("subjectIds") List<String> subjectIds);
} }
package com.zzsn.event.mapper; package com.zzsn.event.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zzsn.event.vo.InfoSourceCondition; import com.zzsn.event.vo.InfoSourceCondition;
import com.zzsn.event.vo.InfoSourceVo; import com.zzsn.event.vo.InfoSourceVo;
...@@ -62,13 +63,12 @@ public interface InfoSourceMapper extends BaseMapper<InfoSource> { ...@@ -62,13 +63,12 @@ public interface InfoSourceMapper extends BaseMapper<InfoSource> {
Long bindSourceIdCount(@Param("infoSourceVo") InfoSourceCondition infoSourceCondition, @Param("subjectIds") List<String> subjectIds); Long bindSourceIdCount(@Param("infoSourceVo") InfoSourceCondition infoSourceCondition, @Param("subjectIds") List<String> subjectIds);
/** /**
*
*
* @param subjectIds 专题id集合 * @param subjectIds 专题id集合
* @param sourceIds
* @author lkg * @author lkg
* @date 2025/2/6 * @date 2025/2/6
*/ */
List<InfoSourceVo> bindGroupSourceIdList(@Param("subjectIds") List<String> subjectIds); List<InfoSourceVo> bindGroupSourceIdList(@Param("subjectIds") List<String> subjectIds, @Param("sourceIds")List<String> sourceIds);
/** /**
* 专题直接屏蔽的信息源列表(不包括专题屏蔽的信息源组下的信息源) * 专题直接屏蔽的信息源列表(不包括专题屏蔽的信息源组下的信息源)
...@@ -128,4 +128,6 @@ public interface InfoSourceMapper extends BaseMapper<InfoSource> { ...@@ -128,4 +128,6 @@ public interface InfoSourceMapper extends BaseMapper<InfoSource> {
* @date 2025/1/4 * @date 2025/1/4
*/ */
Set<String> directSourceColumnSet(@Param("webSiteNames") List<String> webSiteNames); Set<String> directSourceColumnSet(@Param("webSiteNames") List<String> webSiteNames);
IPage<InfoSourceVo> bindSourceIdPageList(Page<InfoSourceVo> page, @Param("infoSourceVo") InfoSourceCondition infoSourceCondition, @Param("subjectIds") List<String> subjectIds);
} }
...@@ -179,4 +179,68 @@ ...@@ -179,4 +179,68 @@
#{item} #{item}
</foreach> </foreach>
</select> </select>
<select id="bindSourceCount" resultType="com.zzsn.event.vo.SubjectSourceVO">
select a.subject_id,count(*) count from
(select distinct x.source_id,x.subject_id from (
select m.source_id,n.subject_id from subject_info_source_map n
inner join info_source_group_map m on n.source_id = m.group_id
where n.type in(2,5)
<if test="subjectIds != null and subjectIds.size() > 0">
and n.subject_id in
<foreach collection="subjectIds" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
union
select sm.source_id,sm.subject_id from subject_info_source_map sm where sm.type in(1,6)
<if test="subjectIds != null and subjectIds.size() > 0">
and sm.subject_id in
<foreach collection="subjectIds" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
union
select m.entity_code as source_id,n.subject_id from subject_info_source_map n
inner join clb_label_info_source_map m on n.source_id = m.label_code and n.source_item_id = m.label_item_code
where n.type in(12,15)
<if test="subjectIds != null and subjectIds.size() > 0">
and n.subject_id in
<foreach collection="subjectIds" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
) x) a LEFT JOIN
(select distinct x.source_id,x.subject_id from (
select m.source_id,n.subject_id from subject_info_source_map n
inner join info_source_group_map m on n.source_id = m.group_id
where n.type = 4
<if test="subjectIds != null and subjectIds.size() > 0">
and n.subject_id in
<foreach collection="subjectIds" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
union
select sm.source_id,sm.subject_id from subject_info_source_map sm where sm.type = 3
<if test="subjectIds != null and subjectIds.size() > 0">
and sm.subject_id in
<foreach collection="subjectIds" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
union
select m.entity_code as source_id,n.subject_id from subject_info_source_map n
inner join clb_label_info_source_map m on n.source_id = m.label_code and n.source_item_id = m.label_item_code
where n.type = 14
<if test="subjectIds != null and subjectIds.size() > 0">
and n.subject_id in
<foreach collection="subjectIds" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
) x) b
on (a.subject_id = b.subject_id and a.source_id = b.source_id)
where b.source_id is null group by a.subject_id
</select>
</mapper> </mapper>
...@@ -123,6 +123,88 @@ ...@@ -123,6 +123,88 @@
order by x.create_time order by x.create_time
limit #{offset},#{pageSize} limit #{offset},#{pageSize}
</select> </select>
<select id="bindSourceIdPageList" resultType="com.zzsn.event.vo.InfoSourceVo">
select x.* from info_source x left join
(
select a.source_id from
(select distinct x.source_id from (
select m.source_id from subject_info_source_map n
inner join info_source_group_map m on n.source_id = m.group_id
where n.type in(2,5)
<if test="subjectIds != null and subjectIds.size() > 0">
and n.subject_id in
<foreach collection="subjectIds" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
union
select sm.source_id from subject_info_source_map sm where sm.type in(1,6)
<if test="subjectIds != null and subjectIds.size() > 0">
and sm.subject_id in
<foreach collection="subjectIds" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
union
select m.entity_code as source_id from subject_info_source_map n
inner join clb_label_info_source_map m on n.source_id = m.label_code and n.source_item_id = m.label_item_code
where n.type in(12,15)
<if test="subjectIds != null and subjectIds.size() > 0">
and n.subject_id in
<foreach collection="subjectIds" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
) x) a LEFT JOIN
(select distinct x.source_id from (
select m.source_id from subject_info_source_map n
inner join info_source_group_map m on n.source_id = m.group_id
where n.type = 4
<if test="subjectIds != null and subjectIds.size() > 0">
and n.subject_id in
<foreach collection="subjectIds" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
union
select sm.source_id from subject_info_source_map sm where sm.type = 3
<if test="subjectIds != null and subjectIds.size() > 0">
and sm.subject_id in
<foreach collection="subjectIds" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
union
select m.entity_code as source_id from subject_info_source_map n
inner join clb_label_info_source_map m on n.source_id = m.label_code and n.source_item_id = m.label_item_code
where n.type = 14
<if test="subjectIds != null and subjectIds.size() > 0">
and n.subject_id in
<foreach collection="subjectIds" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
) x) b
on (a.source_id = b.source_id)
where b.source_id is null
) bind on (x.id = bind.source_id)
where bind.source_id is not null
<if test="infoSourceVo.webSiteName!=null and infoSourceVo.webSiteName != ''">
and x.web_site_name like CONCAT('%',#{infoSourceVo.webSiteName},'%')
</if>
<if test="infoSourceVo.siteName!=null and infoSourceVo.siteName != ''">
and x.site_name like CONCAT('%',#{infoSourceVo.siteName},'%')
</if>
<if test="infoSourceVo.siteUri!=null and infoSourceVo.siteUri != ''">
and x.site_uri = #{infoSourceVo.siteUri}
</if>
<if test="infoSourceVo.status!=null and infoSourceVo.status != ''">
and x.status = #{infoSourceVo.status}
</if>
<if test="infoSourceVo.crawlType!=null and infoSourceVo.crawlType != 0">
and x.crawl_type = #{infoSourceVo.crawlType}
</if>
</select>
<select id="bindSourceIdCount" resultType="Long"> <select id="bindSourceIdCount" resultType="Long">
select count(1) from select count(1) from
...@@ -220,6 +302,12 @@ ...@@ -220,6 +302,12 @@
</foreach> </foreach>
</if> </if>
GROUP BY source_id ) GROUP BY source_id )
<if test="sourceIds != null and sourceIds.size() > 0">
and iso.id in
<foreach collection="sourceIds" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
</select> </select>
<select id="unBindSourcePageList" resultType="com.zzsn.event.vo.InfoSourceVo"> <select id="unBindSourcePageList" resultType="com.zzsn.event.vo.InfoSourceVo">
select s.id,s.info_source_code,s.web_site_name,s.site_name,s.site_uri,s.status,s.create_time from info_source s select s.id,s.info_source_code,s.web_site_name,s.site_name,s.site_uri,s.status,s.create_time from info_source s
......
...@@ -7,6 +7,7 @@ import com.zzsn.event.vo.*; ...@@ -7,6 +7,7 @@ import com.zzsn.event.vo.*;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
/** /**
...@@ -108,4 +109,11 @@ public interface CommonService { ...@@ -108,4 +109,11 @@ public interface CommonService {
* @date 2025/2/5 * @date 2025/2/5
*/ */
List<LabelItemMapVO> infoSourceLabelsBySidList(List<String> sidList); List<LabelItemMapVO> infoSourceLabelsBySidList(List<String> sidList);
/**
* 按专题分组查询绑定信息源数量
* @param subjectIds 专题id列表
* @return
*/
Map<String, Integer> bindSourceCount(List<String> subjectIds);
} }
...@@ -106,4 +106,6 @@ public interface IInfoSourceService extends IService<InfoSource> { ...@@ -106,4 +106,6 @@ public interface IInfoSourceService extends IService<InfoSource> {
* @date 2025/1/4 * @date 2025/1/4
*/ */
Set<String> directSourceColumnSet(List<String> webSiteNames); Set<String> directSourceColumnSet(List<String> webSiteNames);
IPage<InfoSourceVo> bindInfoSourcePageList(InfoSourceCondition infoSourceCondition, List<String> subjectIdList, Integer pageNo, Integer pageSize);
} }
...@@ -349,6 +349,18 @@ public class CommonServiceImpl implements CommonService { ...@@ -349,6 +349,18 @@ public class CommonServiceImpl implements CommonService {
return clbLabelItems; return clbLabelItems;
} }
@Override
public Map<String, Integer> bindSourceCount(List<String> subjectIds) {
Map<String, Integer> map = new HashMap<>();
List<SubjectSourceVO> bindList = commonMapper.bindSourceCount(subjectIds);
if (CollectionUtils.isNotEmpty(bindList)) {
for (SubjectSourceVO subjectSourceVO : bindList) {
map.put(subjectSourceVO.getSubjectId(), subjectSourceVO.getCount());
}
}
return map;
}
//获取树状结构 //获取树状结构
private List<ModelVO> getTreeList(List<ModelVO> authTypeList){ private List<ModelVO> getTreeList(List<ModelVO> authTypeList){
List<ModelVO> topList = new ArrayList<>(); List<ModelVO> topList = new ArrayList<>();
......
...@@ -11,7 +11,6 @@ import com.zzsn.event.entity.InfoSource; ...@@ -11,7 +11,6 @@ import com.zzsn.event.entity.InfoSource;
import com.zzsn.event.es.EsService; import com.zzsn.event.es.EsService;
import com.zzsn.event.mapper.InfoSourceMapper; import com.zzsn.event.mapper.InfoSourceMapper;
import com.zzsn.event.service.IInfoSourceService; import com.zzsn.event.service.IInfoSourceService;
import com.zzsn.event.util.CodeGenerateUtil;
import com.zzsn.event.vo.InfoSourceCondition; import com.zzsn.event.vo.InfoSourceCondition;
import com.zzsn.event.vo.InfoSourceVo; import com.zzsn.event.vo.InfoSourceVo;
import com.zzsn.event.vo.NumVO; import com.zzsn.event.vo.NumVO;
...@@ -51,7 +50,7 @@ public class InfoSourceServiceImpl extends ServiceImpl<InfoSourceMapper, InfoSou ...@@ -51,7 +50,7 @@ public class InfoSourceServiceImpl extends ServiceImpl<InfoSourceMapper, InfoSou
List<InfoSourceVo> pageList = new ArrayList<>(); List<InfoSourceVo> pageList = new ArrayList<>();
List<String> bindList = baseMapper.bindSourceIdList(infoSourceCondition,subjectIds,offset,pageSize); List<String> bindList = baseMapper.bindSourceIdList(infoSourceCondition,subjectIds,offset,pageSize);
if (CollectionUtils.isNotEmpty(bindList)) { if (CollectionUtils.isNotEmpty(bindList)) {
List<InfoSourceVo> infoSourceVos = baseMapper.bindGroupSourceIdList(subjectIds); List<InfoSourceVo> infoSourceVos = baseMapper.bindGroupSourceIdList(subjectIds, bindList);
Map<String, InfoSourceVo> collect1 = infoSourceVos.stream().collect(Collectors.toMap(InfoSourceVo::getId, Function.identity(), (exist, replace) -> exist)); Map<String, InfoSourceVo> collect1 = infoSourceVos.stream().collect(Collectors.toMap(InfoSourceVo::getId, Function.identity(), (exist, replace) -> exist));
pageList = baseMapper.queryInfoSource(bindList,subjectIds); pageList = baseMapper.queryInfoSource(bindList,subjectIds);
for (InfoSourceVo infoSourceVo1 : pageList) { for (InfoSourceVo infoSourceVo1 : pageList) {
...@@ -151,4 +150,69 @@ public class InfoSourceServiceImpl extends ServiceImpl<InfoSourceMapper, InfoSou ...@@ -151,4 +150,69 @@ public class InfoSourceServiceImpl extends ServiceImpl<InfoSourceMapper, InfoSou
public Set<String> directSourceColumnSet(List<String> webSiteNames) { public Set<String> directSourceColumnSet(List<String> webSiteNames) {
return baseMapper.directSourceColumnSet(webSiteNames); return baseMapper.directSourceColumnSet(webSiteNames);
} }
@Override
public IPage<InfoSourceVo> bindInfoSourcePageList(InfoSourceCondition infoSourceCondition, List<String> subjectIds, Integer pageNo, Integer pageSize) {
Page<InfoSourceVo> page = new Page<>(pageNo, pageSize);
IPage<InfoSourceVo> pageList = baseMapper.bindSourceIdPageList(page, infoSourceCondition, subjectIds);
//补充附加字段
if(pageList!=null && CollectionUtils.isNotEmpty(pageList.getRecords())){
List<String> sourceIds = pageList.getRecords().stream().map(InfoSourceVo::getId).collect(Collectors.toList());
//以下查询逻辑有问题,需要重构
List<InfoSourceVo> infoSourceVos = baseMapper.bindGroupSourceIdList(subjectIds,sourceIds);
Map<String, InfoSourceVo> collect1 = infoSourceVos.stream().collect(Collectors.toMap(InfoSourceVo::getId, Function.identity(), (exist, replace) -> exist));
for (InfoSourceVo infoSourceVo1 : pageList.getRecords()){
//数据配置0 = {InfoSourceVo@15933} "InfoSourceVo(id=1534709283536326658, infoSourceCode=null, webSiteName=国资小新, siteName=国资小新, siteUri=https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=MjM5MDIxNjczNA==&scene=124#wechat_redirect, authMode=null, remarks=null, biz=null, ynBigV=0, authority=null, infoSourceTypeId=null, infoSourceTypeName=null, infoSourceNatureIds=null, natureIds=null, infoSourceNatureNames=null, infoSourceGroupNames=null, siteLevel=null, country=null, area=null, language=null, checkedList=null, hisUriExp=null, hisDateStartTime=null, hisDateEndTime=null, ynHisDataAll=null, status=1, listUrl=null, listExpressionType=null, informationUrl=null, informationTitle=null, informationPublishDate=null, informationSource=null, infoBlockPosition=null, linkLocation=null, extractInfo=null, crawlDepth=null, pageUrl=null, matchPage=null, pageStart=0, pageEnd=0, ynPageAll=null, detailUrl=0, detailExpressionType=null, detailExpressionTitle=null, titleExtractionMethodType=null, titleExtractionMethod=null, detailExpressi"…视图
if (ObjectUtil.isEmpty(infoSourceVo1.getIsFreeCheck())){
InfoSourceVo infoSourceVo2 = collect1.get(infoSourceVo1.getId());
if (infoSourceVo2 != null) {
infoSourceVo1.setIsFreeCheck(infoSourceVo2.getIsFreeCheck());
}
}
if (ObjectUtil.isEmpty(infoSourceVo1.getIsExemptKeyword())){
InfoSourceVo infoSourceVo2 = collect1.get(infoSourceVo1.getId());
if (infoSourceVo2 != null) {
infoSourceVo1.setIsExemptKeyword(infoSourceVo2.getIsExemptKeyword());
}
}
//性质
if (StringUtils.isNotEmpty(infoSourceVo1.getNatureIds())) {
String natureIds = infoSourceVo1.getNatureIds();
List<String> natureIdList = Arrays.asList(natureIds.split(","));
infoSourceVo1.setInfoSourceNatureIds(natureIdList);
}
/*//采集量
NumVO totalCollectCount = esService.count(infoSourceVo1.getId(), null, null, 1);
//总采集量
infoSourceVo1.setTotalCount(totalCollectCount.getCount());
Date endTime = new Date();
DateTime startTime = DateUtil.offsetDay(endTime, -30);
//月采集量
NumVO monthCollectCount = esService.count(infoSourceVo1.getId(), DateUtil.formatDate(startTime), DateUtil.formatDate(endTime), 2);
infoSourceVo1.setMonthCount(monthCollectCount.getCount());
List<NumVO> children = monthCollectCount.getChildren();
Map<String, List<NumVO>> collect = children.stream().collect(Collectors.groupingBy(NumVO::getKey));
//周采集量
long weekCount = 0L;
List<DateTime> rangeToList = DateUtil.rangeToList(DateUtil.offsetDay(endTime, -7), endTime, DateField.DAY_OF_YEAR);
for (DateTime dateTime : rangeToList) {
List<NumVO> countVOS = collect.get(DateUtil.formatDate(dateTime));
if (CollectionUtils.isNotEmpty(countVOS)) {
weekCount += countVOS.get(0).getCount();
}
}
infoSourceVo1.setWeekCount(weekCount);
//昨日采集量
DateTime yesterday = DateUtil.yesterday();
List<NumVO> countVOS = collect.get(DateUtil.formatDate(yesterday));
if (CollectionUtils.isNotEmpty(countVOS)) {
infoSourceVo1.setYesterdayCount(countVOS.get(0).getCount());
} else {
infoSourceVo1.setYesterdayCount(0L);
}*/
}
}
return pageList;
}
} }
...@@ -114,17 +114,18 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, Subject> impl ...@@ -114,17 +114,18 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, Subject> impl
//按专题分组,统计绑定关键词组的数量 //按专题分组,统计绑定关键词组的数量
Map<String, Integer> keyWordsNumMap = commonService.bindKeyWordsCountList(idList).stream().collect(Collectors.toMap(SubjectPage::getId, SubjectPage::getKeyWordsNum)); Map<String, Integer> keyWordsNumMap = commonService.bindKeyWordsCountList(idList).stream().collect(Collectors.toMap(SubjectPage::getId, SubjectPage::getKeyWordsNum));
//按专题分组,统计绑定信息源的数量 //按专题分组,统计绑定信息源的数量
Map<String, List<SubjectSourceVO>> collect = commonService.bindSourceList(idList).stream().collect(Collectors.groupingBy(SubjectSourceVO::getSubjectId)); //Map<String, List<SubjectSourceVO>> collect = commonService.bindSourceList(idList).stream().collect(Collectors.groupingBy(SubjectSourceVO::getSubjectId));
Map<String, Integer> infoSourceNumMap = new HashMap<>(); Map<String, Integer> sourceCountMap = commonService.bindSourceCount(idList);
for (Map.Entry<String, List<SubjectSourceVO>> entry : collect.entrySet()) { // Map<String, Integer> infoSourceNumMap = new HashMap<>();
String subjectId = entry.getKey(); // for (Map.Entry<String, List<SubjectSourceVO>> entry : collect.entrySet()) {
List<SubjectSourceVO> value = entry.getValue(); // String subjectId = entry.getKey();
infoSourceNumMap.put(subjectId, value.size()); // List<SubjectSourceVO> value = entry.getValue();
} // infoSourceNumMap.put(subjectId, value.size());
// }
//查询每个专题绑定的信息源数量及关键词数量 //查询每个专题绑定的信息源数量及关键词数量
for (SubjectPage subjectPage1 : records) { for (SubjectPage subjectPage1 : records) {
int keyWordsNum = null == keyWordsNumMap.get(subjectPage1.getId()) ? 0 : keyWordsNumMap.get(subjectPage1.getId()); int keyWordsNum = null == keyWordsNumMap.get(subjectPage1.getId()) ? 0 : keyWordsNumMap.get(subjectPage1.getId());
int infoSourceNum = null == infoSourceNumMap.get(subjectPage1.getId()) ? 0 : infoSourceNumMap.get(subjectPage1.getId()); int infoSourceNum = null == sourceCountMap.get(subjectPage1.getId()) ? 0 : sourceCountMap.get(subjectPage1.getId());
subjectPage1.setInfoSourceNum(infoSourceNum); subjectPage1.setInfoSourceNum(infoSourceNum);
subjectPage1.setKeyWordsNum(keyWordsNum); subjectPage1.setKeyWordsNum(keyWordsNum);
} }
......
...@@ -12,6 +12,7 @@ import lombok.Data; ...@@ -12,6 +12,7 @@ import lombok.Data;
public class SubjectSourceVO { public class SubjectSourceVO {
private String subjectId; private String subjectId;
private String sourceId; private String sourceId;
private Integer count;
//绑定定向信息源时使用(研究中心) //绑定定向信息源时使用(研究中心)
private String webSiteName; private String webSiteName;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论