提交 085741a0 作者: obcy

【添加绑定解绑信息源接口】

上级 8c6cc457
...@@ -14,6 +14,7 @@ import com.zzsn.event.entity.*; ...@@ -14,6 +14,7 @@ import com.zzsn.event.entity.*;
import com.zzsn.event.es.EsService; import com.zzsn.event.es.EsService;
import com.zzsn.event.feign.api.RemoteModelService; import com.zzsn.event.feign.api.RemoteModelService;
import com.zzsn.event.service.*; import com.zzsn.event.service.*;
import com.zzsn.event.service.impl.ConfigurationMessageService;
import com.zzsn.event.util.*; import com.zzsn.event.util.*;
import com.zzsn.event.util.user.UserUtil; import com.zzsn.event.util.user.UserUtil;
import com.zzsn.event.util.user.UserVo; import com.zzsn.event.util.user.UserVo;
...@@ -97,7 +98,8 @@ public class SubjectManageController { ...@@ -97,7 +98,8 @@ public class SubjectManageController {
private PythonUtil pythonUtil; private PythonUtil pythonUtil;
@Autowired(required = false) @Autowired(required = false)
private RemoteModelService remoteModelService; private RemoteModelService remoteModelService;
@Autowired
private ConfigurationMessageService configurationMessageService;
@Value("${kafka.topic.subject.run:}") @Value("${kafka.topic.subject.run:}")
private String SUBJECT_MODEL_KAFKA_CHANNEL; private String SUBJECT_MODEL_KAFKA_CHANNEL;
...@@ -435,6 +437,8 @@ public class SubjectManageController { ...@@ -435,6 +437,8 @@ public class SubjectManageController {
@GetMapping(value = "/bindKeyWordsList") @GetMapping(value = "/bindKeyWordsList")
public Result<?> bindKeyWordsList(@RequestParam(name = "id") String id,@RequestParam(name = "bindingType",required = false) String bindingType) { public Result<?> bindKeyWordsList(@RequestParam(name = "id") String id,@RequestParam(name = "bindingType",required = false) String bindingType) {
List<KeyWordsPage> bindKeyWordsList = subjectKeywordsMapService.bindKeyWordsList(id,bindingType); List<KeyWordsPage> bindKeyWordsList = subjectKeywordsMapService.bindKeyWordsList(id,bindingType);
//同步配置到采集
configurationMessageService.bindKeyWordsSend(id);
return Result.OK(bindKeyWordsList); return Result.OK(bindKeyWordsList);
} }
......
package com.zzsn.event.controller.common; package com.zzsn.event.controller.common;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
...@@ -12,6 +13,7 @@ import com.zzsn.event.entity.InfoSourceGroup; ...@@ -12,6 +13,7 @@ import com.zzsn.event.entity.InfoSourceGroup;
import com.zzsn.event.service.*; import com.zzsn.event.service.*;
import com.zzsn.event.util.tree.Node; import com.zzsn.event.util.tree.Node;
import com.zzsn.event.vo.*; import com.zzsn.event.vo.*;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -43,6 +45,8 @@ public class RelationBindController { ...@@ -43,6 +45,8 @@ public class RelationBindController {
private CommonService commonService; private CommonService commonService;
@Autowired @Autowired
private InfoSourceGroupService infoSourceGroupService; private InfoSourceGroupService infoSourceGroupService;
@Autowired
private SubjectService subjectService;
/** /**
* 项目列表 * 项目列表
...@@ -149,6 +153,18 @@ public class RelationBindController { ...@@ -149,6 +153,18 @@ public class RelationBindController {
} }
/** /**
* 专题信息源绑定新
*
* @param subjectPage
* @return
*/
@ApiOperation(value = "专题信息源绑定", notes = "专题信息源绑定")
@PostMapping(value = "/infoSourceBindNew")
public Result<?> infoSourceBindNew(@RequestBody SubjectPage subjectPage) {
return subjectService.infoSourceBindNew(subjectPage);
}
/**
* 专题/事件信息源绑定删除(专题/事件配置页) * 专题/事件信息源绑定删除(专题/事件配置页)
* *
* @param subjectPage 参数 * @param subjectPage 参数
...@@ -161,6 +177,38 @@ public class RelationBindController { ...@@ -161,6 +177,38 @@ public class RelationBindController {
} }
/** /**
* 专题信息源绑定删除
*
* @param subjectPage
* @return
*/
@ApiOperation(value = "专题信息源绑定删除", notes = "专题信息源绑定删除")
@PostMapping(value = "/deleteBindInfoSourceNew")
public Result<?> deleteBindInfoSourceNew(@RequestBody SubjectPage subjectPage) {
String subjectId = subjectPage.getId();
List<String> bindIds = subjectPage.getBindIds();
if (org.springframework.util.StringUtils.isEmpty(subjectId)) {
return Result.FAIL("专题id不能为空");
}
if (StrUtil.isBlank(subjectPage.getSourceBindType())){
return Result.FAIL("解绑类型不能为空");
}
if (StrUtil.isBlank(subjectPage.getSourceType())){
return Result.FAIL("信息源类型不能为空");
}
if(CollectionUtil.isEmpty(bindIds) && ("1".equals(subjectPage.getSourceType()) || "2".equals(subjectPage.getSourceType()))){
return Result.FAIL("解绑绑定id不能为空");
}
if(CollectionUtil.isEmpty(subjectPage.getBindLabels()) && "3".equals(subjectPage.getSourceType() )){
return Result.FAIL("解绑标签不能为空");
}
subjectService.deleteBindNew(subjectPage);
return Result.OK("删除成功!");
}
/**
* 专题/事件绑定的信息源组列表(专题/事件配置页) * 专题/事件绑定的信息源组列表(专题/事件配置页)
* *
* @param subjectId 专题/事件id * @param subjectId 专题/事件id
......
...@@ -82,4 +82,9 @@ public interface ISubjectInfoSourceMapService extends IService<SubjectInfoSource ...@@ -82,4 +82,9 @@ public interface ISubjectInfoSourceMapService extends IService<SubjectInfoSource
* @date 2024/5/6 * @date 2024/5/6
*/ */
List<SubjectStatisticsVo> subjectRealBindInfoSources(List<String> subjectIds); List<SubjectStatisticsVo> subjectRealBindInfoSources(List<String> subjectIds);
/**
* 根据批量删除
*/
void deleteInfoSourceIds(String subjectId, List<String> infoSourceIds, Integer type);
} }
...@@ -162,4 +162,8 @@ public interface SubjectService extends IService<Subject> { ...@@ -162,4 +162,8 @@ public interface SubjectService extends IService<Subject> {
void send(String subjectId, String status); void send(String subjectId, String status);
List<KeyWordsPage> bindKeyWordsListByIdsAndBindType(List<String> ids, String bindingType); List<KeyWordsPage> bindKeyWordsListByIdsAndBindType(List<String> ids, String bindingType);
Result<?> infoSourceBindNew(SubjectPage subjectPage);
void deleteBindNew(SubjectPage subjectPage);
} }
...@@ -63,6 +63,11 @@ public class SubjectInfoSourceMapServiceImpl extends ServiceImpl<SubjectInfoSour ...@@ -63,6 +63,11 @@ public class SubjectInfoSourceMapServiceImpl extends ServiceImpl<SubjectInfoSour
} }
@Override @Override
public void deleteInfoSourceIds(String subjectId, List<String> infoSourceIds, Integer type) {
baseMapper.deleteInfoSourceIds(subjectId, infoSourceIds, type);
}
@Override
public List<String> subjectRealBindInfoSourceList(List<String> subjectIds) { public List<String> subjectRealBindInfoSourceList(List<String> subjectIds) {
return baseMapper.subjectRealBindInfoSourceList(subjectIds); return baseMapper.subjectRealBindInfoSourceList(subjectIds);
} }
......
...@@ -6,6 +6,7 @@ import cn.hutool.core.date.DateTime; ...@@ -6,6 +6,7 @@ import cn.hutool.core.date.DateTime;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
...@@ -96,6 +97,12 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, Subject> impl ...@@ -96,6 +97,12 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, Subject> impl
private IClbModelArrangeService clbModelArrangeService; private IClbModelArrangeService clbModelArrangeService;
@Autowired @Autowired
private ConfigurationMessageService configurationMessageService; private ConfigurationMessageService configurationMessageService;
@Autowired
private ScoreModelService scoreModelService;
@Autowired
private InfoSourceGroupService infoSourceGroupService;
@Autowired
private ISubjectInfoSourceMapService iSubjectInfoSourceMapService;
@Value("${python.subjectProcessorUrl}") @Value("${python.subjectProcessorUrl}")
private String subjectProcessorUrl; private String subjectProcessorUrl;
...@@ -722,5 +729,307 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, Subject> impl ...@@ -722,5 +729,307 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, Subject> impl
} }
@Override
@Transactional
public Result<?> infoSourceBindNew(SubjectPage subjectPage) {
String subjectId = subjectPage.getId();
List<String> bindIds = subjectPage.getBindIds();
if (org.springframework.util.StringUtils.isEmpty(subjectId)) {
return Result.FAIL("专题id不能为空");
}
if (StrUtil.isBlank(subjectPage.getSourceBindType())){
return Result.FAIL("解绑类型不能为空");
}
if (StrUtil.isBlank(subjectPage.getSourceType())){
return Result.FAIL("信息源类型不能为空");
}
if(CollectionUtil.isEmpty(bindIds) && ("1".equals(subjectPage.getSourceType()) || "2".equals(subjectPage.getSourceType()))){
return Result.FAIL("解绑绑定id不能为空");
}
if(CollectionUtil.isEmpty(subjectPage.getBindLabels()) && "3".equals(subjectPage.getSourceType() )){
return Result.FAIL("解绑标签不能为空");
}
//绑定信息源组
if (StrUtil.equals(subjectPage.getSourceType(),"1")) {
bindInfoSourceGroup(subjectPage);
}
//绑定信息源
if (StrUtil.equals(subjectPage.getSourceType(),"2")) {
bindInfoSource(subjectPage);
}
//绑定标签
if (StrUtil.equals(subjectPage.getSourceType(),"3")) {
bindLabels(subjectPage);
}
configurationMessageService.bindInfoSourceSend(subjectId);
return Result.OK("绑定成功");
}
@Override
@Transactional
public void deleteBindNew(SubjectPage subjectPage) {
//解绑信息源组
if (StrUtil.equals(subjectPage.getSourceType(),"1")) {
unBindInfoSourceGroup(subjectPage);
}
//解绑信息源
if (StrUtil.equals(subjectPage.getSourceType(),"2")) {
unBindInfoSource(subjectPage);
}
//解绑标签
if (StrUtil.equals(subjectPage.getSourceType(),"3")) {
unBindLabels(subjectPage);
}
configurationMessageService.bindInfoSourceSend(subjectPage.getId());
}
private void unBindInfoSourceGroup(SubjectPage subjectPage) {
String sourceBindType = subjectPage.getSourceBindType();
List<String> idList = subjectPage.getBindIds();
if(CollectionUtil.isEmpty(idList)){
return ;
}
if (StrUtil.equals(sourceBindType,"1")) {
//解绑通用信息源组
unbindInfoSource(subjectPage, idList, BindTypeEnum.INFO_SOURCE_GROUP.getvalue());
}
if (StrUtil.equals(sourceBindType,"2")) {
//解绑定向信息源组
unbindInfoSource(subjectPage, idList, BindTypeEnum.DIRECTIONA_INFO_SOURCE_GROUP.getvalue());
}
if (StrUtil.equals(sourceBindType,"3")) {
//解绑屏蔽信息源组
unbindInfoSource(subjectPage, idList, BindTypeEnum.EXCLUDE_INFO_SOURCE_GROUP.getvalue());
}
}
private void unBindLabels(SubjectPage subjectPage) {
String sourceBindType = subjectPage.getSourceBindType();
List<BindLabelVo> bindLabels = subjectPage.getBindLabels();
if(CollectionUtil.isEmpty(bindLabels)){
return ;
}
if (StrUtil.equals(sourceBindType,"1")) {
//解绑通用标签
unBindLabel(subjectPage, BindTypeEnum.INFO_SOURCE_LABEL.getvalue());
}
if (StrUtil.equals(sourceBindType,"2")) {
//解绑定向标签
unBindLabel(subjectPage, BindTypeEnum.DIRECTIONA_INFO_SOURCE_LABEL.getvalue());
}
if (StrUtil.equals(sourceBindType,"3")) {
//解绑屏蔽标签
unBindLabel(subjectPage, BindTypeEnum.EXCLUDE_INFO_SOURCE_LABEL.getvalue());
}
}
private void unBindLabel(SubjectPage subjectPage, Integer type) {
List<BindLabelVo> bindLabels = subjectPage.getBindLabels();
if(CollectionUtil.isEmpty(bindLabels)){
return ;
}
Set<String> labelCode = new HashSet<>();
Set<String> labelItemCode = new HashSet<>();
List<SubjectInfoSourceMap> mapList = new ArrayList<>();
for (BindLabelVo bindLabelVo : bindLabels) {
labelCode.add(bindLabelVo.getLabelCode());
labelItemCode.add(bindLabelVo.getLabelItemCode());
}
iSubjectInfoSourceMapService.remove(Wrappers.<SubjectInfoSourceMap>lambdaQuery()
.in(SubjectInfoSourceMap::getSourceId,labelCode)
.in(SubjectInfoSourceMap::getSourceItemId,labelItemCode)
.eq(SubjectInfoSourceMap::getSubjectId,subjectPage.getId())
.eq(SubjectInfoSourceMap::getType,type));
}
private void unBindInfoSource(SubjectPage subjectPage) {
String sourceBindType = subjectPage.getSourceBindType();
List<String> idList = subjectPage.getBindIds();
if(CollectionUtil.isEmpty(idList)){
return ;
}
if (StrUtil.equals(sourceBindType,"1")) {
//解绑通用信息源
unbindInfoSource(subjectPage, idList, BindTypeEnum.INFO_SOURCE.getvalue());
}
if (StrUtil.equals(sourceBindType,"2")) {
//解绑定向信息源
unbindInfoSource(subjectPage, idList, BindTypeEnum.DIRECTIONA_INFO_SOURCE.getvalue());
}
if (StrUtil.equals(sourceBindType,"3")) {
//解绑屏蔽信息源
unbindInfoSource(subjectPage, idList, BindTypeEnum.EXCLUDE_INFO_SOURCE.getvalue());
}
}
private void unbindInfoSource(SubjectPage subjectPage, List<String> idList, Integer bindType) {
iSubjectInfoSourceMapService.deleteInfoSourceIds(subjectPage.getId(), idList, bindType);
if (BindTypeEnum.INFO_SOURCE_GROUP.getvalue().equals(bindType)) {
//更改打分模型中的信息源组绑定情况
List<ScoreModelVo> scoreModelList = scoreModelService.queryScoreModel(subjectPage.getId(), null);
for (String groupId : idList) {
for (ScoreModelVo scoreModel : scoreModelList) {
JSONArray jsonArray = JSONArray.parseArray(scoreModel.getData().toString());
JSONObject jsonObject = jsonArray.getJSONObject(0);
JSONArray children = jsonObject.getJSONArray("children");
//若信息源打分配置中已经存在的有相同的,则去除掉这部分
for (int i = 0; i < children.size(); i++) {
String infoSourceGroupId = children.getJSONObject(i).getString("infoSourceGroupId");
if (groupId.equals(infoSourceGroupId)) {
children.remove(i);
break;
}
}
jsonObject.put("children", children);
jsonArray.remove(0);
jsonArray.add(0, jsonObject);
scoreModel.setData(jsonArray.toJSONString());
scoreModel.setChangeType(0);
//去除完之后,更新进去
scoreModelService.addOrUpdate(scoreModel,subjectPage.getCategory());
}
}
}
}
private void bindInfoSourceGroup(SubjectPage subjectPage) {
String sourceBindType = subjectPage.getSourceBindType();
List<String> idList = subjectPage.getBindIds();
if(CollectionUtil.isEmpty(idList)){
return ;
}
if (StrUtil.equals(sourceBindType,"1")) {
//绑定通用信息源组
bindInfoSource(subjectPage, idList, BindTypeEnum.INFO_SOURCE_GROUP.getvalue());
}
if (StrUtil.equals(sourceBindType,"2")) {
//绑定定向信息源组
bindInfoSource(subjectPage, idList, BindTypeEnum.DIRECTIONA_INFO_SOURCE_GROUP.getvalue());
}
if (StrUtil.equals(sourceBindType,"3")) {
//绑定屏蔽信息源组
bindInfoSource(subjectPage, idList, BindTypeEnum.EXCLUDE_INFO_SOURCE_GROUP.getvalue());
}
}
private void bindInfoSource(SubjectPage subjectPage, List<String> idList, Integer type) {
List<SubjectInfoSourceMap> mapList = new ArrayList<>();
for (String infoSourceId : idList) {
SubjectInfoSourceMap subjectInfoSourceMap = new SubjectInfoSourceMap();
subjectInfoSourceMap.setSourceId(infoSourceId);
subjectInfoSourceMap.setSubjectId(subjectPage.getId());
subjectInfoSourceMap.setType(type);
mapList.add(subjectInfoSourceMap);
}
if (BindTypeEnum.INFO_SOURCE_GROUP.getvalue().equals(type)) {
//判断打分模型是否存在过,若存在则更改
List<ScoreModelVo> scoreModelList = scoreModelService.queryScoreModel(subjectPage.getId(), null);
for (ScoreModelVo scoreModelVo : scoreModelList) {
String typeId = scoreModelVo.getType();
JSONArray jsonArray = JSONArray.parseArray(scoreModelVo.getData().toString());
JSONObject jsonObject = jsonArray.getJSONObject(0);
JSONArray children = jsonObject.getJSONArray("children");
int count = children.size();
//判断是否存在节点(没有则直接添加)
if (count == 0) {
for (int i = 0; i < idList.size(); i++) {
InfoSourceGroup group = infoSourceGroupService.getGroupById(idList.get(i));
if (group != null) {
String newId = typeId + "-1-" + (i + 1);
JSONObject childJsonObject = new JSONObject();
childJsonObject.put("name", group.getGroupName());
childJsonObject.put("id", newId);
childJsonObject.put("infoSourceGroupId", idList.get(i));
childJsonObject.put("fraction", 80);
children.add(childJsonObject);
}
}
} else {
String id = children.getJSONObject(count - 1).getString("id");
for (int i = 0; i < idList.size(); i++) {
InfoSourceGroup group = infoSourceGroupService.getGroupById(idList.get(i));
if (group != null) {
String newId = typeId + "-1-" + (Integer.parseInt(id.substring(id.lastIndexOf("-") + 1)) + i + 1);
JSONObject childJsonObject = new JSONObject();
childJsonObject.put("name", group.getGroupName());
childJsonObject.put("id", newId);
childJsonObject.put("infoSourceGroupId", idList.get(i));
childJsonObject.put("fraction", 80);
children.add(childJsonObject);
}
}
}
jsonObject.put("children", children);
jsonArray.remove(0);
jsonArray.add(0, jsonObject);
scoreModelVo.setData(jsonArray.toJSONString());
scoreModelVo.setChangeType(0);
//增加完之后,更新进去
scoreModelService.addOrUpdate(scoreModelVo,subjectPage.getCategory());
}
}
iSubjectInfoSourceMapService.saveBatch(mapList);
}
private void bindInfoSource(SubjectPage subjectPage) {
String sourceBindType = subjectPage.getSourceBindType();
List<String> idList = subjectPage.getBindIds();
if(CollectionUtil.isEmpty(idList)){
return ;
}
if (StrUtil.equals(sourceBindType,"1")) {
//绑定通用信息源
bindInfoSource(subjectPage, idList, BindTypeEnum.INFO_SOURCE.getvalue());
}
if (StrUtil.equals(sourceBindType,"2")) {
//绑定定向信息源
bindInfoSource(subjectPage, idList, BindTypeEnum.DIRECTIONA_INFO_SOURCE.getvalue());
}
if (StrUtil.equals(sourceBindType,"3")) {
//绑定屏蔽信息源
bindInfoSource(subjectPage, idList, BindTypeEnum.EXCLUDE_INFO_SOURCE.getvalue());
}
}
private void bindLabels(SubjectPage subjectPage) {
String subjectId = subjectPage.getId();
String sourceBindType = subjectPage.getSourceBindType();
List<BindLabelVo> bindLabels = subjectPage.getBindLabels();
if(CollectionUtil.isEmpty(bindLabels)){
return ;
}
if (StrUtil.equals(sourceBindType,"1")) {
//绑定通用标签信息源
bindLabels(subjectId, bindLabels, BindTypeEnum.INFO_SOURCE_LABEL.getvalue());
}
if (StrUtil.equals(sourceBindType,"2")) {
//绑定定向标签信息源
bindLabels(subjectId, bindLabels, BindTypeEnum.DIRECTIONA_INFO_SOURCE_LABEL.getvalue());
}
if (StrUtil.equals(sourceBindType,"3")) {
//绑定屏蔽标签信息源
bindLabels(subjectId, bindLabels, BindTypeEnum.EXCLUDE_INFO_SOURCE_LABEL.getvalue());
}
}
private void bindLabels(String subjectId, List<BindLabelVo> bindLabels, Integer bindType) {
List<SubjectInfoSourceMap> mapList = new ArrayList<>();
for (BindLabelVo infoSourceId : bindLabels) {
SubjectInfoSourceMap subjectInfoSourceMap = new SubjectInfoSourceMap();
subjectInfoSourceMap.setSourceId(infoSourceId.getLabelCode());
subjectInfoSourceMap.setSourceItemId(infoSourceId.getLabelItemCode());
subjectInfoSourceMap.setSubjectId(subjectId);
subjectInfoSourceMap.setType(bindType);
mapList.add(subjectInfoSourceMap);
}
iSubjectInfoSourceMapService.saveBatch(mapList);
}
} }
package com.zzsn.event.vo;
import lombok.Data;
import java.util.List;
@Data
public class BindLabelVo {
private String labelCode ;
private String labelItemCode ;
private List<BindLabelVo> labelItems;
}
...@@ -159,6 +159,22 @@ public class SubjectPage { ...@@ -159,6 +159,22 @@ public class SubjectPage {
/**预估状态*/ /**预估状态*/
private String estimateStatus; private String estimateStatus;
/**
* 信息源绑定-新
* */
//id(可以是信息源组id集合,可以是信息源id集合)
private List<String> bindIds;
//信息源标签
private List<BindLabelVo> bindLabels;
//绑定类型类型(1:通用 2:定向 3:屏蔽)
private String sourceBindType;
//信息源类型(1:信息源组 2:信息源 3:标签)
private String sourceType;
/**
* 信息源绑定-新end
* */
private List<ClbModelArrange> clbModelArranges; private List<ClbModelArrange> clbModelArranges;
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论