提交 d9c4d7ef 作者: 925993793@qq.com

本地处理智库和信息源的绑定关系

上级 9918e8dc
package com.zzsn.thinktank.entity;
import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import java.util.Date;
import java.io.Serializable;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* <p>
* 信息源表
* </p>
*
* @author obcy
* @since 2025-06-19
*/
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("info_source_main")
public class InfoSourceMain extends Model<InfoSourceMain> {
private static final long serialVersionUID = 1L;
/**
* 主键
*/
@TableId(value = "id", type = IdType.ASSIGN_ID)
private String id;
/**
* 信息源编码
*/
@TableField("code")
private String code;
/**
* 信息源名称
*/
@TableField("info_name")
private String infoName;
/**
* 类型
*/
@TableField("type")
private Integer type;
/**
* 地址
*/
@TableField("info_address")
private String infoAddress;
/**
* 别名
*/
@TableField("alias")
private String alias;
/**
* 是否原创性校验1 校验 0否
*/
@TableField("original_check")
private Integer originalCheck;
/**
* 校验列表
*/
@TableField("check_list")
private String checkList;
/**
* 主办单位
*/
@TableField("organizer")
private String organizer;
/**
* 地区全路径
*/
@TableField("area_full_paths")
private String areaFullPaths;
/**
* 地区名称
*/
@TableField("area")
private String area;
/**
* 是否翻墙
*/
@TableField("skip_wall")
private Integer skipWall;
/**
* 网站刷新速度
*/
@TableField("refresh_speed")
private Integer refreshSpeed;
/**
* 创建时间
*/
@TableField("create_time")
private Date createTime;
/**
* 更新时间
*/
@TableField("update_time")
private Date updateTime;
/**
* 创建人
*/
@TableField("create_by")
private String createBy;
/**
* 更新人
*/
@TableField("update_by")
private String updateBy;
@TableField("del_flag")
@TableLogic
private Integer delFlag;
/**是否免过关键词 0否 1是*/
@TableField(exist = false)
private Integer isExemptKeyword;
/**是否免审核 0否 1是*/
@TableField(exist = false)
private Integer isFreeCheck;
/**专题绑定的信息源的类型,定向或者非定向*/
@TableField(exist = false)
private String subjectInfoSourceType;
/**
* 信息源类别
*/
@TableField(exist = false)
private Integer sourceType;
/**
* 专题绑定信息源的主键id
*/
@TableField(exist = false)
private String subjectInfoSourceId;
@Override
protected Serializable pkVal() {
return this.id;
}
}
package com.zzsn.thinktank.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzsn.thinktank.entity.InfoSourceMain;
import org.apache.ibatis.annotations.Mapper;
/**
* <p>
* 信息源表 Mapper 接口
* </p>
*
* @author obcy
* @since 2025-06-19
*/
@Mapper
public interface InfoSourceMainMapper extends BaseMapper<InfoSourceMain> {
}
package com.zzsn.thinktank.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zzsn.thinktank.entity.InfoSourceMain;
/**
* <p>
* 信息源表 服务类
* </p>
*
* @author obcy
* @since 2025-06-19
*/
public interface InfoSourceMainService extends IService<InfoSourceMain> {
}
package com.zzsn.thinktank.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzsn.thinktank.entity.InfoSourceMain;
import com.zzsn.thinktank.mapper.InfoSourceMainMapper;
import com.zzsn.thinktank.service.InfoSourceMainService;
import org.springframework.stereotype.Service;
import java.util.*;
/**
* <p>
* 信息源表 服务实现类
* </p>
*
* @author obcy
* @since 2025-06-19
*/
@Service
public class InfoSourceMainServiceImpl extends ServiceImpl<InfoSourceMainMapper, InfoSourceMain> implements InfoSourceMainService {
}
package com.zzsn.thinktank; package com.zzsn.thinktank;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zzsn.thinktank.entity.InfoSourceGroupMap;
import com.zzsn.thinktank.entity.InfoSourceMain;
import com.zzsn.thinktank.entity.ThinktankBasicInfo;
import com.zzsn.thinktank.service.*;
import com.zzsn.thinktank.vo.DataChangeVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Slf4j
@SpringBootTest @SpringBootTest
class ThinkTankApplicationTests { class ThinkTankApplicationTests {
@Autowired
private ThinktankBasicInfoService thinktankBasicInfoService;
@Resource
private DataImportService dataImportService;
@Test @Test
void contextLoads() { void contextLoads() {
List<DataChangeVO> influencePositionList = dataImportService.dictItemList("Influence");
Map<String, String> influencePositionMap = influencePositionList.stream().collect(Collectors.toMap(DataChangeVO::getDescription, DataChangeVO::getValue, (value1, value2) -> value1));
LambdaQueryWrapper<ThinktankBasicInfo> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.select(ThinktankBasicInfo::getId, ThinktankBasicInfo::getInfluencePosition);
List<ThinktankBasicInfo> list = thinktankBasicInfoService.list(queryWrapper);
for (int i = 0; i < list.size(); i++) {
ThinktankBasicInfo thinktankBasicInfo = list.get(i);
String influencePosition = thinktankBasicInfo.getInfluencePosition();
if (influencePosition != null) {
StringBuilder sb = new StringBuilder();
for (String s : influencePosition.split(",")) {
String value = influencePositionMap.get(s);
sb.append(",").append(value);
}
thinktankBasicInfo.setInfluencePosition(sb.substring(1));
}
log.info("共-{},第-{}个,更新完成", list.size(), i + 1);
}
thinktankBasicInfoService.updateBatchById(list);
System.out.println("结束");
} }
@Autowired
private InfoSourceGroupMapService infoSourceGroupMapService;
@Autowired
private InfoSourceMainService infoSourceMainService;
@Test
public void handlerBindData() {
ExcelReader reader = ExcelUtil.getReader("C:\\Users\\lenovo\\Desktop\\202509智库优化信息源绑定.xlsx", 0);
List<List<Object>> read = reader.read(1,296);
for (List<Object> objects : read) {
String code = objects.get(0).toString();
String infoSourceCode = objects.get(6).toString();
if (StringUtils.isNotEmpty(code) && StringUtils.isNotEmpty(infoSourceCode)) {
LambdaQueryWrapper<ThinktankBasicInfo> wrapper = Wrappers.lambdaQuery();
wrapper.eq(ThinktankBasicInfo::getCodeId, code);
ThinktankBasicInfo one = thinktankBasicInfoService.getOne(wrapper);
if (one != null) {
LambdaQueryWrapper<InfoSourceMain> query = Wrappers.lambdaQuery();
query.eq(InfoSourceMain::getCode, infoSourceCode);
InfoSourceMain infoSourceMain = infoSourceMainService.getOne(query);
if (infoSourceMain != null) {
LambdaQueryWrapper<InfoSourceGroupMap> queryWrapper = Wrappers.lambdaQuery();
String infoSourceId = infoSourceMain.getId();
queryWrapper.eq(InfoSourceGroupMap::getGroupId, one.getId()).eq(InfoSourceGroupMap::getSourceId, infoSourceId);
int count = infoSourceGroupMapService.count(queryWrapper);
if (count == 0) {
InfoSourceGroupMap infoSourceGroupMap = new InfoSourceGroupMap();
infoSourceGroupMap.setGroupId(one.getId());
infoSourceGroupMap.setSourceId(infoSourceId);
infoSourceGroupMap.setType(31);
infoSourceGroupMap.setCreateTime(new Date());
infoSourceGroupMapService.save(infoSourceGroupMap);
}
log.info("{},智库绑定信息源处理完毕", one.getChineseWhole());
} else {
log.info("{},信息源未找到", infoSourceCode);
}
} else {
log.info("{},智库未找到", code);
}
} else {
log.info("数据为空");
}
//break;
}
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论