提交 64a6b75a 作者: 925993793@qq.com

自定义专题数量统计接口逻辑优化

上级 1373ada7
...@@ -267,10 +267,7 @@ public class SubjectManageController { ...@@ -267,10 +267,7 @@ public class SubjectManageController {
*/ */
@GetMapping(value = "/statisticInfo") @GetMapping(value = "/statisticInfo")
private Result<?> statisticInfo(@RequestParam List<String> subjectIds) { private Result<?> statisticInfo(@RequestParam List<String> subjectIds) {
if(yjzxEnable){ List<SubjectStatisticInfo> statisticInfoList = subjectService.statisticInfo(subjectIds,yjzxEnable);
return Result.OK(new ArrayList<>());
}
List<SubjectStatisticInfo> statisticInfoList = subjectService.statisticInfo(subjectIds);
//异步更新专题统计信息表的数据 //异步更新专题统计信息表的数据
CompletableFuture.runAsync(() -> { CompletableFuture.runAsync(() -> {
if (CollectionUtils.isNotEmpty(statisticInfoList)) { if (CollectionUtils.isNotEmpty(statisticInfoList)) {
...@@ -1277,8 +1274,9 @@ public class SubjectManageController { ...@@ -1277,8 +1274,9 @@ public class SubjectManageController {
List<String> infoSourceIds = new ArrayList<>(); List<String> infoSourceIds = new ArrayList<>();
for (SubjectBindSourceVO subjectBindSourceVO : subjectBindSourceVOS) { for (SubjectBindSourceVO subjectBindSourceVO : subjectBindSourceVOS) {
infoSourceIds.add(subjectBindSourceVO.getWebSiteId()); infoSourceIds.add(subjectBindSourceVO.getWebSiteId());
//信息源下栏目id集合
List<String> infoColumnIds = subjectBindSourceVO.getColumnIds(); List<String> infoColumnIds = subjectBindSourceVO.getColumnIds();
if (CollectionUtils.isEmpty(infoColumnIds)) { if (CollectionUtils.isEmpty(infoColumnIds)) {//为空,则全选
String response = remoteGetColumnList(subjectBindSourceVO.getWebSiteId(), null, null, 1, 1000); String response = remoteGetColumnList(subjectBindSourceVO.getWebSiteId(), null, null, 1, 1000);
JSONObject jsonObject = JSONObject.parseObject(response); JSONObject jsonObject = JSONObject.parseObject(response);
if (jsonObject.getInteger("code") == 200) { if (jsonObject.getInteger("code") == 200) {
...@@ -1315,11 +1313,14 @@ public class SubjectManageController { ...@@ -1315,11 +1313,14 @@ public class SubjectManageController {
subjectInfoSourceMiddleMapService.saveBatch(dataList); subjectInfoSourceMiddleMapService.saveBatch(dataList);
} }
//专题栏目关系绑定 //专题栏目关系绑定
List<SubjectInfoSourceMap> list = new ArrayList<>();
if (CollectionUtils.isNotEmpty(columnIds)) {
LambdaQueryWrapper<SubjectInfoSourceMap> queryWrapper = Wrappers.lambdaQuery(); LambdaQueryWrapper<SubjectInfoSourceMap> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(SubjectInfoSourceMap::getSubjectId, subjectId) queryWrapper.eq(SubjectInfoSourceMap::getSubjectId, subjectId)
.in(SubjectInfoSourceMap::getSourceId, columnIds) .in(SubjectInfoSourceMap::getSourceId, columnIds)
.eq(SubjectInfoSourceMap::getType, 1); .eq(SubjectInfoSourceMap::getType, 1);
List<SubjectInfoSourceMap> list = subjectInfoSourceMapService.list(queryWrapper); list = subjectInfoSourceMapService.list(queryWrapper);
}
if (CollectionUtils.isNotEmpty(list)) { if (CollectionUtils.isNotEmpty(list)) {
List<String> existSourceIdList = list.stream().map(SubjectInfoSourceMap::getSourceId).collect(Collectors.toList()); List<String> existSourceIdList = list.stream().map(SubjectInfoSourceMap::getSourceId).collect(Collectors.toList());
columnIds.removeAll(existSourceIdList); columnIds.removeAll(existSourceIdList);
......
...@@ -104,6 +104,7 @@ public interface CommonMapper { ...@@ -104,6 +104,7 @@ public interface CommonMapper {
List<LabelItemMapVO> infoSourceLabelsBySidList(@Param("sidList") List<String> sidList); List<LabelItemMapVO> infoSourceLabelsBySidList(@Param("sidList") List<String> sidList);
List<SubjectSourceVO> bindSourceCount(@Param("subjectIds") List<String> subjectIds); List<SubjectSourceVO> bindSourceCount(@Param("subjectIds") List<String> subjectIds);
List<SubjectSourceVO> bindSourceCountYjzx(@Param("subjectIds") List<String> subjectIds);
List<SysDict> selectOldLabelTypeList(); List<SysDict> selectOldLabelTypeList();
......
...@@ -30,4 +30,5 @@ public interface SubjectAdditionMapper extends BaseMapper<SubjectAddition> { ...@@ -30,4 +30,5 @@ public interface SubjectAdditionMapper extends BaseMapper<SubjectAddition> {
int count(String subjectId, int type); int count(String subjectId, int type);
List<String> getSubjectBindInfoSourceIds(@Param("subjectId") String subjectId); List<String> getSubjectBindInfoSourceIds(@Param("subjectId") String subjectId);
List<String> getSubjectBindInfoSourceIdsYjzx(@Param("subjectId") String subjectId);
} }
...@@ -342,6 +342,35 @@ ...@@ -342,6 +342,35 @@
where b.source_id is null and x.id is not null group by a.subject_id where b.source_id is null and x.id is not null group by a.subject_id
</select> </select>
<select id="bindSourceCountYjzx" resultType="com.zzsn.event.vo.SubjectSourceVO">
select a.subject_id,count(*) count from
(select distinct x.source_id,x.subject_id from (
select sm.source_id,sm.subject_id from subject_info_source_map sm where sm.type = 1
<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 isoo.id as source_id,smm.subject_id
FROM
subject_info_source_map smm
INNER JOIN clb_label_main_source_map lam ON smm.source_id = lam.label_code
AND smm.source_item_id = lam.label_item_code
INNER JOIN info_source_main im ON lam.entity_code = im.id
INNER JOIN info_source isoo ON im.id = isoo.info_source_id
WHERE
smm.type = 312
<if test="subjectIds != null and subjectIds.size() > 0">
and smm.subject_id in
<foreach collection="subjectIds" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
) x) a group by a.subject_id
</select>
<select id="selectOldLabelTypeList" resultType="com.zzsn.event.feign.entity.SysDict"> <select id="selectOldLabelTypeList" resultType="com.zzsn.event.feign.entity.SysDict">
select id,if(pid='0','1',pid) parentId,label_name dictName,has_child hasChild,if(has_child=0,'1',null) isDict from sys_base_label_type select id,if(pid='0','1',pid) parentId,label_name dictName,has_child hasChild,if(has_child=0,'1',null) isDict from sys_base_label_type
where id not IN ('1602218529184993281','1602220733056864258') and category = 0 where id not IN ('1602218529184993281','1602220733056864258') and category = 0
......
...@@ -378,4 +378,30 @@ ...@@ -378,4 +378,30 @@
) y ) y
) )
</select> </select>
<select id="getSubjectBindInfoSourceIdsYjzx" resultType="java.lang.String">
SELECT
distinct x.id
FROM
(
SELECT
iso.id
FROM
subject_info_source_map sm
INNER JOIN info_source iso ON sm.source_id = iso.id
WHERE
sm.type = 1
AND sm.subject_id = #{subjectId} UNION
SELECT
isoo.id
FROM
subject_info_source_map smm
INNER JOIN clb_label_main_source_map lam ON smm.source_id = lam.label_code
AND smm.source_item_id = lam.label_item_code
INNER JOIN info_source_main im ON lam.entity_code = im.id
INNER JOIN info_source isoo ON im.id = isoo.info_source_id
WHERE
smm.type = 312
AND smm.subject_id = #{subjectId}
) x
</select>
</mapper> </mapper>
...@@ -117,6 +117,13 @@ public interface CommonService { ...@@ -117,6 +117,13 @@ public interface CommonService {
*/ */
Map<String, Integer> bindSourceCount(List<String> subjectIds); Map<String, Integer> bindSourceCount(List<String> subjectIds);
/**
* 按专题分组查询绑定信息源数量(研究中心环境)
* @param subjectIds 专题id列表
* @return
*/
Map<String, Integer> bindSourceCountYjzx(List<String> subjectIds);
List<SysDict> selectOldLabelTypeList(); List<SysDict> selectOldLabelTypeList();
List<SysDict> selectLeaderTypeList(); List<SysDict> selectLeaderTypeList();
......
...@@ -46,10 +46,11 @@ public interface SubjectService extends IService<Subject> { ...@@ -46,10 +46,11 @@ public interface SubjectService extends IService<Subject> {
* 专题统计信息 * 专题统计信息
* *
* @param subjectIds 专题id集合 * @param subjectIds 专题id集合
* @param yjzxEnable 是否研究中心环境
* @author lkg * @author lkg
* @date 2024/12/18 * @date 2024/12/18
*/ */
List<SubjectStatisticInfo> statisticInfo(List<String> subjectIds); List<SubjectStatisticInfo> statisticInfo(List<String> subjectIds,boolean yjzxEnable);
/** /**
* 专题详情(包含专题分类、专题项目) * 专题详情(包含专题分类、专题项目)
......
...@@ -381,6 +381,17 @@ public class CommonServiceImpl implements CommonService { ...@@ -381,6 +381,17 @@ public class CommonServiceImpl implements CommonService {
} }
return map; return map;
} }
@Override
public Map<String, Integer> bindSourceCountYjzx(List<String> subjectIds) {
Map<String, Integer> map = new HashMap<>();
List<SubjectSourceVO> bindList = commonMapper.bindSourceCountYjzx(subjectIds);
if (CollectionUtils.isNotEmpty(bindList)) {
for (SubjectSourceVO subjectSourceVO : bindList) {
map.put(subjectSourceVO.getSubjectId(), subjectSourceVO.getCount());
}
}
return map;
}
@Override @Override
public List<SysDict> selectOldLabelTypeList() { public List<SysDict> selectOldLabelTypeList() {
......
...@@ -134,6 +134,9 @@ public class ConfigurationMessageService { ...@@ -134,6 +134,9 @@ public class ConfigurationMessageService {
@Autowired @Autowired
private ExternalSubjectInfoSourceMapService externalSubjectInfoSourceMapService; private ExternalSubjectInfoSourceMapService externalSubjectInfoSourceMapService;
@Value("${scheduling.yjzxEnable:false}")
Boolean yjzxEnable;
public void bindKeyWordsSend(String subjectId,Integer type) { public void bindKeyWordsSend(String subjectId,Integer type) {
try { try {
remoteModelService.delSubjectCache(subjectId); remoteModelService.delSubjectCache(subjectId);
...@@ -318,8 +321,7 @@ public class ConfigurationMessageService { ...@@ -318,8 +321,7 @@ public class ConfigurationMessageService {
if (StrUtil.isBlank(subjectId)) { if (StrUtil.isBlank(subjectId)) {
return new ArrayList<>(); return new ArrayList<>();
} }
return getBindIds(subjectId,yjzxEnable);
return getBindIds(subjectId);
} }
...@@ -380,8 +382,14 @@ public class ConfigurationMessageService { ...@@ -380,8 +382,14 @@ public class ConfigurationMessageService {
return excludeIds; return excludeIds;
} }
private List<String> getBindIds(String subjectId) { private List<String> getBindIds(String subjectId,boolean yjzxEnable) {
return subjectAdditionMapper.getSubjectBindInfoSourceIds(subjectId); List<String> ids;
if (yjzxEnable) {
ids = subjectAdditionMapper.getSubjectBindInfoSourceIdsYjzx(subjectId);
} else {
ids = subjectAdditionMapper.getSubjectBindInfoSourceIds(subjectId);
}
return ids;
} }
......
...@@ -206,12 +206,17 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, Subject> impl ...@@ -206,12 +206,17 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, Subject> impl
} }
@Override @Override
public List<SubjectStatisticInfo> statisticInfo(List<String> subjectIds) { public List<SubjectStatisticInfo> statisticInfo(List<String> subjectIds,boolean yjzxEnable) {
List<SubjectStatisticInfo> list = new ArrayList<>(); List<SubjectStatisticInfo> list = new ArrayList<>();
//按专题分组,统计绑定关键词组的数量 //按专题分组,统计绑定关键词组的数量
Map<String, Integer> keyWordsNumMap = commonService.bindKeyWordsCountList(subjectIds).stream().collect(Collectors.toMap(SubjectPage::getId, SubjectPage::getKeyWordsNum)); Map<String, Integer> keyWordsNumMap = commonService.bindKeyWordsCountList(subjectIds).stream().collect(Collectors.toMap(SubjectPage::getId, SubjectPage::getKeyWordsNum));
//按专题分组,统计绑定信息源的数量 //按专题分组,统计绑定信息源的数量
Map<String, Integer> sourceCountMap = commonService.bindSourceCount(subjectIds); Map<String, Integer> sourceCountMap;
if (yjzxEnable) {
sourceCountMap = commonService.bindSourceCountYjzx(subjectIds);
} else {
sourceCountMap = commonService.bindSourceCount(subjectIds);
}
//绑定全部信息源的专题 //绑定全部信息源的专题
Map<String, Integer> infoSourceNumMap = new HashMap<>(); Map<String, Integer> infoSourceNumMap = new HashMap<>();
List<Subject> subjects = baseMapper.selectBatchIds(subjectIds); List<Subject> subjects = baseMapper.selectBatchIds(subjectIds);
......
...@@ -35,13 +35,17 @@ public class SubjectStatisticTask { ...@@ -35,13 +35,17 @@ public class SubjectStatisticTask {
@Value("${scheduling.yjzxEnable:false}") @Value("${scheduling.yjzxEnable:false}")
Boolean yjzxEnable; Boolean yjzxEnable;
/**
* 专题各项数量指标统计
* 每天凌晨0点30分执行一次
*
* @author lkg
* @date 2025/9/15
*/
@Scheduled(cron = "0 30 0 * * ?") @Scheduled(cron = "0 30 0 * * ?")
public void statistic() { public void statistic() {
if(yjzxEnable){
return;
}
LambdaQueryWrapper<Subject> queryWrapper = Wrappers.lambdaQuery(); LambdaQueryWrapper<Subject> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.select(Subject::getId).eq(Subject::getSubjectType, 1); queryWrapper.select(Subject::getId).eq(Subject::getSubjectType, 1).eq(Subject::getStatus, 1);
List<Subject> list = subjectService.list(queryWrapper); List<Subject> list = subjectService.list(queryWrapper);
for (Subject subject : list) { for (Subject subject : list) {
CompletableFuture.runAsync(() ->{ CompletableFuture.runAsync(() ->{
...@@ -49,7 +53,7 @@ public class SubjectStatisticTask { ...@@ -49,7 +53,7 @@ public class SubjectStatisticTask {
try { try {
List<String> subjectIds = new ArrayList<>(); List<String> subjectIds = new ArrayList<>();
subjectIds.add(subjectId); subjectIds.add(subjectId);
List<SubjectStatisticInfo> subjectStatisticInfos = subjectService.statisticInfo(subjectIds); List<SubjectStatisticInfo> subjectStatisticInfos = subjectService.statisticInfo(subjectIds,yjzxEnable);
SubjectStatisticInfo statisticInfo = subjectStatisticInfos.get(0); SubjectStatisticInfo statisticInfo = subjectStatisticInfos.get(0);
LambdaQueryWrapper<SubjectStatisticInfo> query = Wrappers.lambdaQuery(); LambdaQueryWrapper<SubjectStatisticInfo> query = Wrappers.lambdaQuery();
query.eq(SubjectStatisticInfo::getSubjectId, subjectId); query.eq(SubjectStatisticInfo::getSubjectId, subjectId);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论