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

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

上级 1373ada7
......@@ -267,10 +267,7 @@ public class SubjectManageController {
*/
@GetMapping(value = "/statisticInfo")
private Result<?> statisticInfo(@RequestParam List<String> subjectIds) {
if(yjzxEnable){
return Result.OK(new ArrayList<>());
}
List<SubjectStatisticInfo> statisticInfoList = subjectService.statisticInfo(subjectIds);
List<SubjectStatisticInfo> statisticInfoList = subjectService.statisticInfo(subjectIds,yjzxEnable);
//异步更新专题统计信息表的数据
CompletableFuture.runAsync(() -> {
if (CollectionUtils.isNotEmpty(statisticInfoList)) {
......@@ -1277,8 +1274,9 @@ public class SubjectManageController {
List<String> infoSourceIds = new ArrayList<>();
for (SubjectBindSourceVO subjectBindSourceVO : subjectBindSourceVOS) {
infoSourceIds.add(subjectBindSourceVO.getWebSiteId());
//信息源下栏目id集合
List<String> infoColumnIds = subjectBindSourceVO.getColumnIds();
if (CollectionUtils.isEmpty(infoColumnIds)) {
if (CollectionUtils.isEmpty(infoColumnIds)) {//为空,则全选
String response = remoteGetColumnList(subjectBindSourceVO.getWebSiteId(), null, null, 1, 1000);
JSONObject jsonObject = JSONObject.parseObject(response);
if (jsonObject.getInteger("code") == 200) {
......@@ -1315,11 +1313,14 @@ public class SubjectManageController {
subjectInfoSourceMiddleMapService.saveBatch(dataList);
}
//专题栏目关系绑定
LambdaQueryWrapper<SubjectInfoSourceMap> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(SubjectInfoSourceMap::getSubjectId, subjectId)
.in(SubjectInfoSourceMap::getSourceId, columnIds)
.eq(SubjectInfoSourceMap::getType, 1);
List<SubjectInfoSourceMap> list = subjectInfoSourceMapService.list(queryWrapper);
List<SubjectInfoSourceMap> list = new ArrayList<>();
if (CollectionUtils.isNotEmpty(columnIds)) {
LambdaQueryWrapper<SubjectInfoSourceMap> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(SubjectInfoSourceMap::getSubjectId, subjectId)
.in(SubjectInfoSourceMap::getSourceId, columnIds)
.eq(SubjectInfoSourceMap::getType, 1);
list = subjectInfoSourceMapService.list(queryWrapper);
}
if (CollectionUtils.isNotEmpty(list)) {
List<String> existSourceIdList = list.stream().map(SubjectInfoSourceMap::getSourceId).collect(Collectors.toList());
columnIds.removeAll(existSourceIdList);
......
......@@ -104,6 +104,7 @@ public interface CommonMapper {
List<LabelItemMapVO> infoSourceLabelsBySidList(@Param("sidList") List<String> sidList);
List<SubjectSourceVO> bindSourceCount(@Param("subjectIds") List<String> subjectIds);
List<SubjectSourceVO> bindSourceCountYjzx(@Param("subjectIds") List<String> subjectIds);
List<SysDict> selectOldLabelTypeList();
......
......@@ -30,4 +30,5 @@ public interface SubjectAdditionMapper extends BaseMapper<SubjectAddition> {
int count(String subjectId, int type);
List<String> getSubjectBindInfoSourceIds(@Param("subjectId") String subjectId);
List<String> getSubjectBindInfoSourceIdsYjzx(@Param("subjectId") String subjectId);
}
......@@ -342,6 +342,35 @@
where b.source_id is null and x.id is not null group by a.subject_id
</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,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
......
......@@ -378,4 +378,30 @@
) y
)
</select>
</mapper>
\ No newline at end of file
<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>
......@@ -117,6 +117,13 @@ public interface CommonService {
*/
Map<String, Integer> bindSourceCount(List<String> subjectIds);
/**
* 按专题分组查询绑定信息源数量(研究中心环境)
* @param subjectIds 专题id列表
* @return
*/
Map<String, Integer> bindSourceCountYjzx(List<String> subjectIds);
List<SysDict> selectOldLabelTypeList();
List<SysDict> selectLeaderTypeList();
......
......@@ -46,10 +46,11 @@ public interface SubjectService extends IService<Subject> {
* 专题统计信息
*
* @param subjectIds 专题id集合
* @param yjzxEnable 是否研究中心环境
* @author lkg
* @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 {
}
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
public List<SysDict> selectOldLabelTypeList() {
......
......@@ -134,6 +134,9 @@ public class ConfigurationMessageService {
@Autowired
private ExternalSubjectInfoSourceMapService externalSubjectInfoSourceMapService;
@Value("${scheduling.yjzxEnable:false}")
Boolean yjzxEnable;
public void bindKeyWordsSend(String subjectId,Integer type) {
try {
remoteModelService.delSubjectCache(subjectId);
......@@ -318,8 +321,7 @@ public class ConfigurationMessageService {
if (StrUtil.isBlank(subjectId)) {
return new ArrayList<>();
}
return getBindIds(subjectId);
return getBindIds(subjectId,yjzxEnable);
}
......@@ -380,8 +382,14 @@ public class ConfigurationMessageService {
return excludeIds;
}
private List<String> getBindIds(String subjectId) {
return subjectAdditionMapper.getSubjectBindInfoSourceIds(subjectId);
private List<String> getBindIds(String subjectId,boolean yjzxEnable) {
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
}
@Override
public List<SubjectStatisticInfo> statisticInfo(List<String> subjectIds) {
public List<SubjectStatisticInfo> statisticInfo(List<String> subjectIds,boolean yjzxEnable) {
List<SubjectStatisticInfo> list = new ArrayList<>();
//按专题分组,统计绑定关键词组的数量
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<>();
List<Subject> subjects = baseMapper.selectBatchIds(subjectIds);
......
......@@ -35,13 +35,17 @@ public class SubjectStatisticTask {
@Value("${scheduling.yjzxEnable:false}")
Boolean yjzxEnable;
/**
* 专题各项数量指标统计
* 每天凌晨0点30分执行一次
*
* @author lkg
* @date 2025/9/15
*/
@Scheduled(cron = "0 30 0 * * ?")
public void statistic() {
if(yjzxEnable){
return;
}
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);
for (Subject subject : list) {
CompletableFuture.runAsync(() ->{
......@@ -49,7 +53,7 @@ public class SubjectStatisticTask {
try {
List<String> subjectIds = new ArrayList<>();
subjectIds.add(subjectId);
List<SubjectStatisticInfo> subjectStatisticInfos = subjectService.statisticInfo(subjectIds);
List<SubjectStatisticInfo> subjectStatisticInfos = subjectService.statisticInfo(subjectIds,yjzxEnable);
SubjectStatisticInfo statisticInfo = subjectStatisticInfos.get(0);
LambdaQueryWrapper<SubjectStatisticInfo> query = Wrappers.lambdaQuery();
query.eq(SubjectStatisticInfo::getSubjectId, subjectId);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论