提交 2fcfd142 作者: ZhangJingKun

初始化项目

上级
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.6/apache-maven-3.9.6-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.zzsn</groupId>
<artifactId>think-tank</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>think-tank</name>
<description>智库</description>
<properties>
<java.version>1.8</java.version>
<maven.test.skip>true</maven.test.skip>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!--mybatis plus-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.21</version>
</dependency>
<!-- excel工具包 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.2.10</version>
</dependency>
<!-- AutoPoi Excel工具类-->
<dependency>
<groupId>org.jeecgframework</groupId>
<artifactId>autopoi-web</artifactId>
<version>1.2.5</version>
<exclusions>
<exclusion>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- hutool工具类-->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.3.8</version>
</dependency>
<!-- json-->
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.25</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.83</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>2.3.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
<version>2.2.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
<version>3.2.6.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<resources>
<resource>
<directory>${project.basedir}/lib</directory>
<targetPath>BOOT-INF/lib/</targetPath>
<includes>
<include>**/*.jar</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project>
package com.zzsn.thinktank;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableAsync;
@SpringBootApplication
@EnableAsync
@MapperScan(value = {"com.zzsn.thinktank.mapper*"})
public class ThinkTankApplication {
public static void main(String[] args) {
SpringApplication.run(ThinkTankApplication.class, args);
}
}
package com.zzsn.thinktank.controller;
import com.zzsn.thinktank.service.CityAddressService;
import com.zzsn.thinktank.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* @Version 1.0
* @Author: ZhangJingKun
* @Date: 2024/3/9 15:54
* @Content: 地市信息查询
*/
@RestController
@RequestMapping("/api/cityAddress")
public class CityAddressController {
@Autowired
CityAddressService cityAddressService;
@GetMapping("/getCityList")
public Result<?> getCityList(){
return cityAddressService.getCityList();
}
/**
* 根据父pid查询所有子节点
* 要查询根节点下的子节点pid传 "0"
* 默认值为0
* @param pid
* @return
*/
@GetMapping("/getCityListByPid")
public Result<?> getCityListByPid(@RequestParam(name="pid",required=true) String pid){
//
if(pid == null || pid.length() == 0){
pid = "0";
}
return cityAddressService.getCityListByPid(pid);
}
}
package com.zzsn.thinktank.controller;
import com.zzsn.thinktank.service.EnterpriseService;
import com.zzsn.thinktank.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* @Version 1.0
* @Author: ZhangJingKun
* @Date: 2024/4/26 14:16
* @Content:
*/
@Slf4j
@RestController
@RequestMapping("/api/enterprise")
public class EnterpriseController {
@Autowired
EnterpriseService enterpriseService;
/**
* 企业查询
* @param pageNo
* @param pageSize
* @param socialCreditCode
* @param name
* @return
*/
@GetMapping("/pageList")
public Result<?> pageList(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
@RequestParam(name="socialCreditCode", required=false) String socialCreditCode,
@RequestParam(name="name", required=false) String name) {
return enterpriseService.pageList(pageNo, pageSize,socialCreditCode,name);
}
}
package com.zzsn.thinktank.controller;
import com.zzsn.thinktank.entity.ThinktankCategoryStructure;
import com.zzsn.thinktank.service.LeaderCategoryService;
import com.zzsn.thinktank.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
/**
* <p>
* 分类树前端控制器
* </p>
*
* @author obcy
* @since 2024-02-27
*/
@Slf4j
@RestController
@RequestMapping("/api/category")
public class LeaderCategoryController {
@Autowired
LeaderCategoryService leaderCategoryService;
/**
* 根据id查询分类树
* */
@GetMapping
public Result<?> getById(@RequestParam(name="id",required=true) String id){
log.info("根据id查询分类树:{}",id);
return Result.OK(leaderCategoryService.getById(id));
}
/**
* 新增分类树
*/
@PostMapping("/add")
public Result<?> add(@RequestBody ThinktankCategoryStructure characterCategoryStructure){
log.info("新增分类树:{}",characterCategoryStructure);
return leaderCategoryService.add(characterCategoryStructure);
}
/**
* 编辑分类树
* */
@PostMapping("/edit")
public Result<?> edit(@RequestBody ThinktankCategoryStructure characterCategoryStructure){
log.info("编辑分类树:{}",characterCategoryStructure);
return leaderCategoryService.edit(characterCategoryStructure);
}
/**
* 删除分类树
* */
@GetMapping("/del")
public Result<?> del(@RequestParam(name="id",required=true) String id){
log.info("删除分类树:{}",id);
return leaderCategoryService.del(id);
}
/**
* 查询分类树列表
* @param sign
* @param category
* @param pid
* @param httpServletRequest
* @return
*/
@GetMapping("/list")
public Result<?> list(
@RequestParam(name="sign",defaultValue = "1") String sign,
@RequestParam(name="category",required = false) String category,
@RequestParam(name="pid",defaultValue = "0") String pid,
HttpServletRequest httpServletRequest){
log.info("查询分类树列表:{}---{}---{}",sign,category,pid);
if (!"1".equals(sign)){
if (StringUtils.isBlank(pid)){
return Result.error("查询非顶级节点列表时需要pid参数");
}
}
return leaderCategoryService.lists(sign,pid,category);
}
/**
* 根据名称模糊查询所有节点及父节点
* @param category
* @param typeName
* @return
*/
@GetMapping("/getByName")
public Result<?> getByName(
@RequestParam(name="category",required = false) String category,
@RequestParam(name="typeName",required=false) String typeName){
log.info("根据名称模糊查询所有节点及父节点:{}---{}",category,typeName);
if(typeName == null || "".equals(typeName)){
//查询全部数据封装成树
return leaderCategoryService.getAll(category);
} else {
//根据typeName模糊查询节点和父节点
return leaderCategoryService.getByName(category,typeName);
}
}
// @GetMapping("/type")
// public Result<?> type(){
// return Result.OK(KnowTypeEnum.getAllAsMap());
// }
}
package com.zzsn.thinktank.controller;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @Version 1.0
* @Author: ZhangJingKun
* @Date: 2024/2/6 11:06
* @Content:
*/
@RestController
@RequestMapping("/api")
@Slf4j
public class ThinkTankController {
@GetMapping("/test")
public String test(){
log.info("hello!");
return "hello!";
}
}
package com.zzsn.thinktank.controller;
import com.zzsn.thinktank.entity.ThinktankBasicInfo;
import com.zzsn.thinktank.service.ThinktankBasicInfoService;
import com.zzsn.thinktank.vo.Result;
import com.zzsn.thinktank.vo.ThinktankBasicInfoListVo;
import com.zzsn.thinktank.vo.ThinktankBasicInfoVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ResourceLoader;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Map;
/**
* @Version 1.0
* @Author: ZhangJingKun
* @Date: 2024/4/24 10:28
* @Content:
*/
@Slf4j
@RestController
@RequestMapping("/api/basicinfo")
public class ThinktankBasicInfoController {
@Autowired
ThinktankBasicInfoService thinktankBasicInfoService;
/**
* 新增
* @param thinktankBasicInfo
* @return
*/
@PostMapping("/add")
public Result<?> add(@RequestBody ThinktankBasicInfo thinktankBasicInfo){
log.info("新增信息:{}",thinktankBasicInfo);
return thinktankBasicInfoService.add(thinktankBasicInfo);
}
/**
* 根据id主键删除
* @param id
* @return
*/
@GetMapping("/del")
public Result<?> del(@RequestParam(name="id",required=true) String id){
log.info("根据id删除:{}", id);
return thinktankBasicInfoService.del(id);
}
/**
* 根据id修改信息
* @param thinktankBasicInfo
* @return
*/
@PostMapping("/edit")
public Result<?> edit(@RequestBody ThinktankBasicInfo thinktankBasicInfo){
log.info("根据id修改信息:{}",thinktankBasicInfo);
if(thinktankBasicInfo.getId() == null)
return Result.error(400, "id不能为空");
return thinktankBasicInfoService.edit(thinktankBasicInfo);
}
/**
* 根据id主键查询
* @param id
* @return
*/
@GetMapping("getById")
public Result<?> getById(@RequestParam(name="id",required=true) String id){
log.info("根据id主键查询:{}",id);
ThinktankBasicInfoVo thinktankBasicInfo = thinktankBasicInfoService.getInfoById(id);
return Result.OK(thinktankBasicInfo);
}
@PostMapping("/list")
public Result<?> getList(@RequestBody ThinktankBasicInfoListVo thinktankBasicInfoListVo){
log.info("智库信息条件分页查询:{}", thinktankBasicInfoListVo);
Integer pageNo = thinktankBasicInfoListVo.getPageNo();
Integer pageSize= thinktankBasicInfoListVo.getPageSize();
if(pageNo < 1)
pageNo = 1;
if(pageSize < 0)
pageSize = 10;
Integer office = pageSize * (pageNo - 1);
thinktankBasicInfoListVo.setOffset(office);
return thinktankBasicInfoService.getList(thinktankBasicInfoListVo);
}
/**
* 模板下载
* @param response
*/
@GetMapping("/downloadTemplate")
public void downloadTemplate(HttpServletResponse response) {
thinktankBasicInfoService.downloadTemplate(response);
}
/**
* 批量导入数据
* @param
* @return
*/
@Transactional
@PostMapping("/batchImport")
public Result<?> batchImport( HttpServletRequest request) {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
if (fileMap.size() < 1) {
return Result.error("请上传文件!");
}
MultipartFile multipartFile = fileMap.get(new ArrayList<>(fileMap.keySet()).get(0));
Result result = thinktankBasicInfoService.batchImport(multipartFile);
return result;
}
@PostMapping("/batchExport")
public byte[] batchExport(@RequestBody ThinktankBasicInfoListVo thinktankBasicInfoListVo,HttpServletRequest request, HttpServletResponse response){
log.info("导出:{}", thinktankBasicInfoListVo);
// Integer pageNo = thinktankBasicInfoListVo.getPageNo();
// Integer pageSize= thinktankBasicInfoListVo.getPageSize();
// if(pageNo < 1)
// pageNo = 1;
// if(pageSize < 0)
// pageSize = 10;
// Integer office = pageSize * (pageNo - 1);
// thinktankBasicInfoListVo.setOffset(office);
return thinktankBasicInfoService.batchExport(thinktankBasicInfoListVo,request,response);
}
}
package com.zzsn.thinktank.controller;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zzsn.thinktank.entity.InfoSource;
import com.zzsn.thinktank.service.InfoSourceGroupMapService;
import com.zzsn.thinktank.service.InfoSourceService;
import com.zzsn.thinktank.vo.InfoSourceGroupPage;
import com.zzsn.thinktank.vo.InfoSourceVo;
import com.zzsn.thinktank.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @Version 1.0
* @Author: ZhangJingKun
* @Date: 2024/4/25 9:34
* @Content: 信息源绑定
*/
@Slf4j
@RestController
@RequestMapping("/api/bind")
public class ThinktankBindController {
@Autowired
private InfoSourceService infoSourceService;
@Autowired
private InfoSourceGroupMapService infoSourceGroupMapService;
/**
* 查询信息源组的绑定列表
* @param infoSourceVo
* @param ynBind
* @param groupId
* @param pageNo
* @param pageSize
* @return
*/
@GetMapping(value = "/bindList")
public Result<?> bindList(InfoSourceVo infoSourceVo,
@RequestParam(name="ynBind", required=true) Integer ynBind,
@RequestParam(name="groupId", required=true) String groupId,
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize) {
IPage<InfoSourceVo> pageList = infoSourceService.pageListByGroupId(infoSourceVo, ynBind, groupId, pageNo, pageSize);
return Result.OK(pageList);
}
/**
* 信息源分页列表查询
* @param infoSourceVo
* @param pageNo
* @param pageSize
* @param infoSourceTypeId
* @return
*/
@GetMapping(value = "/listByTypeId")
public Result<?> queryPageListByTypeId(InfoSourceVo infoSourceVo,
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
@RequestParam(name = "infoSourceTypeId", defaultValue = "") String infoSourceTypeId) {
IPage<InfoSourceVo> pageList = infoSourceService.pageListByTypeId(null,null,infoSourceVo, pageNo, pageSize, infoSourceTypeId);
return Result.OK(pageList);
}
/**
* 绑定信息源
*/
@PostMapping(value = "/bind")
public Result<?> bind(@RequestBody InfoSourceGroupPage infoSourceGroupPage) {
String message = infoSourceGroupMapService.bind(infoSourceGroupPage.getId(), infoSourceGroupPage.getInfoSourceIds());
return Result.OK(message);
}
/**
* 解绑信息源
*/
@PostMapping(value = "/unBound")
public Result<?> unBound(@RequestBody InfoSourceGroupPage infoSourceGroupPage) {
infoSourceGroupMapService.unBind(infoSourceGroupPage.getId(), infoSourceGroupPage.getInfoSourceIds());
return Result.OK("解绑成功!");
}
/**
* 提升信息源优先等级
* 批量紧急
* @param groupId 信息源组id
* @author
* @date
*/
/**
* 提升信息源优先等级
* 批量紧急
* @param groupId 信息源组id
* @return
*/
@GetMapping("/upLevel")
public Result<?> upLevel(@RequestParam("groupId") String groupId){
List<String> sourceIdList = infoSourceService.listByGroupId(groupId);
LambdaUpdateWrapper<InfoSource> update = Wrappers.lambdaUpdate();
update.set(InfoSource::getSiteLevel,1).in(InfoSource::getId,sourceIdList);
infoSourceService.update(update);
return Result.OK();
}
}
package com.zzsn.thinktank.controller;
import com.zzsn.thinktank.service.ThinktankTagService;
import com.zzsn.thinktank.vo.Result;
import com.zzsn.thinktank.vo.SysBaseLabelTypeVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* 标签查询相关接口
* @Version 1.0
* @Author: ZhangJingKun
* @Date: 2024/3/20 18:26
* @Content:
*/
@Slf4j
@RestController
@RequestMapping("/api/tag")
public class ThinktankTagController {
@Autowired
ThinktankTagService thinktankTagService;
/**
* 查询所有标签分类
* @return
*/
@GetMapping("/getTagTypeList")
public Result<?> getTagTypeList(){
log.info("查询所有标签分类");
SysBaseLabelTypeVo vo = thinktankTagService.getTagTypeList();
return Result.OK(vo);
}
/**
* 查询标签列表
* @param id
* @param name
* @return
*/
@GetMapping("/getTagList")
public Result<?> getTagList(@RequestParam(name="id",required=false) String id,
@RequestParam(name="name",required=false) String name){
log.info("查询标签列表:{}---{}",id,name);
return thinktankTagService.getTagList(id, name);
}
/**
* 根据标签分页
* @param tagId
* @return
*/
@GetMapping("/getCharacterListByTag")
public Result<?> getCharacterListByTag(@RequestParam(name="tagId",required=true) String tagId,
@RequestParam(name="pageNo",required=false) Integer pageNo,
@RequestParam(name="pageSize",required=false) Integer pageSize){
log.info("根据标签分页查询人物:{}---{}---{}",tagId,pageNo,pageSize);
if(pageNo == null || pageNo < 1)
pageNo = 1;
if(pageSize == null || pageSize < 0)
pageSize = 10;
return thinktankTagService.getCharacterListByTag(tagId,pageNo,pageSize);
}
//热门标签
@GetMapping("/getTopTag")
public Result<?> getTopTag(){
Result result = thinktankTagService.getTopTag();
log.info("热门标签:{}",result.getResult());
return result;
}
}
package com.zzsn.thinktank.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("city_address")
public class CityAddress {
private String id;
private String name;
private String pid;
}
package com.zzsn.thinktank.entity;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
/**
* @Description: 信息源表
* @Author: jeecg-boot
* @Date: 2022-01-18
* @Version: V1.0
*/
@Data
@TableName("info_source")
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
public class InfoSource implements Serializable {
private static final long serialVersionUID = 1L;
/**主键*/
@TableId(type = IdType.ASSIGN_ID)
private String id;
/**信息源编码*/
private String infoSourceCode;
/**信息源名称*/
private String webSiteName;
/**栏目名称*/
private String siteName;
/**栏目地址*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String siteUri;
/**微博认证方式(1:个人微博 2:官方微博)*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String authMode;
/**功能介绍,微博认证描述*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String remarks;
/**公众号BIZ*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String biz;
/**是否大V*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private int ynBigV;
/**网站重要级别*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String siteLevel;
/**国家*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String country;
/**地区*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String area;
/**语种*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String language;
/**境外、公共、翻墙*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String checkedList;
/**历史数据URL*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String hisUriExp;
/**历史数据开始时间*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
@DateTimeFormat(pattern="yyyy-MM-dd")
private java.util.Date hisDateStartTime;
/**历史数据结束时间*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
@DateTimeFormat(pattern="yyyy-MM-dd")
private java.util.Date hisDateEndTime;
/**是否历史所有数据*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String ynHisDataAll;
/**状态*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String status;
/**列表页URL*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String listUrl;
/**表达式类型*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String listExpressionType;
/**匹配资讯的url*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String informationUrl;
/**匹配资讯标题*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String informationTitle;
/**匹配资讯发布时间*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String informationPublishDate;
/**匹配资讯来源*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String informationSource;
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String infoBlockPosition;
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String linkLocation;
/**自定义实体*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private Object extractInfo;
/**爬取深度*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private Integer crawlDepth;
/**页码url*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String pageUrl;
/**匹配页码*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String matchPage;
/**开始页码*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private Integer pageStart;
/**结束页码*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private Integer pageEnd;
/**是否所有页*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String ynPageAll;
/**表达式类型*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String detailExpressionType;
/**详情页表URL*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String detailUrl;
/**匹配详情页标题*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String detailExpressionTitle;
/**匹配详情页时间*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String detailExpressionPublishDate;
/**匹配详情页来源*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String detailExpressionSource;
/**匹配详情页作者*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String detailExpressionAuthor;
/**匹配详情页摘要*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String detailExpressionSummary;
/**匹配详情页正文*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String detailExpressionContent;
/**自定义实体*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private Object detailInfo;
/**是否下载附件*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String ynDownload;
/**数据表格页URL*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String formUrl;
/**数据表格标题*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String formTitle;
/**表达式类型*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private Integer formType;
/**数据表格表达式*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String dataFormExpression;
/**自定义*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private Object dataFormInfo;
/**页码URL*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String dataPageUrl;
/**页码规则*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String dataPageRule;
/**开始页码*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private Integer dataPageStart;
/**结束页码*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private Integer dataPageEnd;
/**是否所有页码*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String ynDataPageAll;
/**数据类型*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private Integer dataType;
/**数据格式*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private Integer dataFormat;
/**数据存储方式*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private Integer dataStorageMode;
/**数据存储信息*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private Object dataStorageInfo;
/**是否动态爬取*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private Integer ynDynamicCrawl;
/**是否需要登陆*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private Integer ynLogin;
/**登陆域名*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String domainName;
/**登陆链接*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String link;
/**登陆账号*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String account;
/**登陆密码*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String password;
/**userAgent*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String userAgent;
/**referer*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String referer;
/**cookies*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String cookies;
/**headers*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String headers;
/**其它参数*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String otherInfo;
/**爬虫类别*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private Integer crawlType;
/**爬虫名称*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String crawlName;
/**爬虫地址*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String crawlAddress;
/**参数*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private Object parameter;
/**设置方式(1:自由设置 2:cron表达式)*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private Integer setMode;
/**定时方式(1:时间间隔 2:立即执行)*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String timerMode;
/**定时单位(1分;2小时;3日;4月)*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String unit;
/**定时数值*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private Integer space;
/**cron表达式*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String cron;
/**说明*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String explaination;
/**创建人*/
private String createBy;
/**创建日期*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
private java.util.Date createTime;
/**更新人*/
private String updateBy;
/**更新日期*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
private java.util.Date updateTime;
/**所属部门*/
private String sysOrgCode;
/**验证结果*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String verification;
/**所属单位*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String company;
/**所属行业*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String industry;
/**权威性*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String authority;
/**可信度*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String reliability;
/**原创度*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String originality;
/**父网站*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String parentSite;
/**是否保存快照(1:保存 0:不保存)*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String ynSnapshot;
}
package com.zzsn.thinktank.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.util.Date;
/**
* @Description: 信息源组和信息源关联表
* @Author: jeecg-boot
* @Date: 2021-11-24
* @Version: V1.0
*/
@Data
@TableName("thinktank_info_source_group_map")
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
public class InfoSourceGroupMap implements Serializable {
private static final long serialVersionUID = 1L;
/**主键*/
@TableId(type = IdType.ASSIGN_ID)
private String id;
/**信息源组id*/
@Excel(name = "信息源组id", width = 15)
private String groupId;
/**信息源id*/
@Excel(name = "信息源id", width = 15)
private String sourceId;
/**创建人*/
private String createBy;
/**创建日期*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
private Date createTime;
/**更新人*/
private String updateBy;
/**更新日期*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
private Date updateTime;
/**所属部门*/
private String sysOrgCode;
}
package com.zzsn.thinktank.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("label_entity")
public class LabelEntity {
private String id;
private String name;
private String synonym;
private String explanation;
private long level;
private String topId;
private String pathIds;
private long status;
private long sort;
private String createBy;
private java.sql.Timestamp createTime;
private String updateBy;
private java.sql.Timestamp updateTime;
private String sysOrgCode;
private String pid;
private String hasChild;
}
package com.zzsn.thinktank.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("sys_base_domestic_region")
public class SysBaseDomesticRegion {
//主键id
private String id;
//名称
private String name;
//编码
private String code;
//节点id绝对路径
private String pathIds;
//层级
private Long level;
//父id
private String pid;
//是否有子节点
private String hasChild;
}
package com.zzsn.thinktank.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* @Description: 企业基本信息表-新企业表
*/
@Data
@TableName("sys_base_enterprise")
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
public class SysBaseEnterprise implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键
*/
@TableId(type = IdType.ASSIGN_ID)
private String id;
/**
* 统一社会信用代码
*/
private String socialCreditCode;
/**
* 企业原文名称
*/
private String originalName;
/**
* 企业中文名称
*/
private String name;
/**
* 法定代表人
*/
private String legalPerson;
/**
* 电话
*/
private String officialPhone;
/**
* 官网
*/
private String officialUrl;
/**
* 邮箱
*/
private String officialEmail;
/**
* 地址
*/
private String address;
/**
* 简介
*/
private String briefInfo;
private String briefInfoTranlate;
/**
* 登记状态
*/
private String registerStatus;
/**
* 成立日期
*/
private String incorporationDate;
/**
* 注册资本
*/
private String capital;
/**
* 实缴资本
*/
private String paidCapital;
/**
* 核准日期
*/
private String approvalDate;
/**
* 组织机构代码
*/
private String organizationCode;
/**
* 工商注册号
*/
private String registerNo;
/**
* 纳税人识别号
*/
private String taxpayerNo;
/**
* 企业类型
*/
private String type;
/**
* 营业期限自
*/
private String businessStartDate;
/**
* 营业期限至
*/
private String businessEndDate;
/**
* 纳税人资质
*/
private String taxpayerQualification;
/**
* 所属行业
*/
private String industry;
/**
* 所属地区(来源与爬来的, 存储省市县)
*/
private String region;
/***/
private String regionName;
/**
* 所属省
*/
private String province;
/**
* 所属市
*/
private String city;
/**
* 所属县
*/
private String county;
/**
* 登记机关
*/
private String registerDepartment;
/**
* 人员规模
*/
private String scale;
/**
* 参保人数
*/
private String insured;
/**
* 曾用名
*/
private String beforeName;
/**
* 企业简称
*/
private String shortName;
/**
* 英文名
*/
private String englishName;
/**
* 进出口企业代码
*/
private String importExportEnterpriseCode;
/**
* 经营范围
*/
private String businessRange;
/**
* 企业logo地址
*/
private String logo;
/**
* 企查查企业Id
*/
private String qccId;
/**
* 状态: (0保留,1删除)
*/
private Integer status;
/**
* 创建人
*/
private String createBy;
/**
* 创建日期
*/
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
/**
* 更新人
*/
private String updateBy;
/**
* 更新日期
*/
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
/**
* 所属部门
*/
private String sysOrgCode;
/**
* 是否国内(1-是;0-否)
*/
private Integer ynDomestic;
/**
* 所属国家/地区名称
*/
private String countryName;
/**
* 信息来源网站的更新日期
*/
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date sourceUpdateTime;
/**
* 名称首字母
*/
private String initial;
@TableField(exist = false)
private Map<String, Object> labelOrder;
/**
* 世界500强排序
*/
@TableField(exist = false)
private Integer orderTop500;
/**
* 是否跳转:0-否 1-是
*/
@TableField(exist = false)
private String ifJump;
/**
* 股票代码
*/
@TableField(exist = false)
private String stockCode;
/**
* 标签
*/
// @TableField(exist = false)
// private List<Label> labels;
/**
* 是否有财务数据, 1-否,1-是 *
*/
@TableField(exist = false)
private Integer financeMark;
/**
* 股票代码
*/
@TableField(exist = false)
private String securitiesCode;
}
package com.zzsn.thinktank.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
/**
* @Description: 标签类别
* @Author: jeecg-boot
* @Date: 2022-05-12
* @Version: V1.0
*/
@Data
@TableName("sys_base_label_type")
public class SysBaseLabelType implements Serializable {
private static final long serialVersionUID = 1L;
/**主键*/
@TableId(type = IdType.ASSIGN_ID)
private String id;
/**标签编码*/
@Excel(name = "标签编码", width = 15)
private String labelCode;
/**标签名称*/
@Excel(name = "标签名称", width = 15)
private String labelName;
/**标签标识*/
@Excel(name = "标签标识", width = 15)
private String labelMark;
/**说明*/
@Excel(name = "说明", width = 15)
private String explanation;
/**创建人*/
private String createBy;
/**创建日期*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
private java.util.Date createTime;
/**更新人*/
private String updateBy;
/**更新日期*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
private java.util.Date updateTime;
/**所属部门*/
private String sysOrgCode;
/**父级节点*/
@Excel(name = "父级节点", width = 15)
private String pid;
/**是否有子节点*/
@Excel(name = "是否有子节点", width = 15, dicCode = "yn")
private String hasChild;
/**排序*/
private Integer orderNo;
/**顶层id*/
private String topId;
/**标签类别(如企业、自定义等)*/
private String labelType;
/**标签类型(0-非自定义;1-自定义)*/
private Integer category;
}
package com.zzsn.thinktank.entity;
import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("thinktank_basic_info")
public class ThinktankBasicInfo extends Model<ThinktankBasicInfo> {
//主键
@TableId(value = "id", type = IdType.ASSIGN_ID)
private String id;
//智库机构编码
private String codeId;
//中文全称
private String chineseWhole;
//中文简称
private String chineseSimple;
//英文全称
private String englishWhole;
//英文简称
private String englishSimple;
//原文全称
private String originalWhole;
//原文简称
private String originalSimple;
//官网
private String officialWebsite;
//标签id 多个标签使用逗号分隔
private String tagId;
//标签名称 多个标签使用逗号分隔
private String tagName;
//成立时间
private String establishTime;
//是否收费 1是 0否 默认为空值
private Integer charge;
//国内外
private String countryWithinExternal;
//所属国家/地区 ID
private String belongCountryId;
//所属国家/地区
private String belongCountry;
//所在地区
private String region;
//地址
private String address;
//创办单位/所属单位 企业信用代码
private String belongUnitCode;
//创办单位/所属单位
private String belongUnit;
//机构头像
private String headSculpture;
//简介
private String biographicalNotes;
//属性 区分智库机构、咨询公司、新闻媒体
private String attribute;
//启停状态 1启 0停
private Integer status;
//创建人
private String createBy;
//创建时间
@TableField(fill = FieldFill.INSERT)
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
//更新人
private String updateBy;
//更新时间
@TableField(fill = FieldFill.UPDATE)
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
}
package com.zzsn.thinktank.entity;
import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
/**
* <p>
*5.1 人物分类体系表 character_category_structure
* </p>
*
* @since
*/
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("thinktank_category_structure")
public class ThinktankCategoryStructure extends Model<ThinktankCategoryStructure>
{
private static final long serialVersionUID = 1L;
/**
* 主键
*/
@TableId(value = "id", type = IdType.ASSIGN_ID)
private String id;
/**
* 类别名称 公安部 财政部
*/
@TableField("type_name")
private String typeName;
/**
*类别编码
*/
@TableField("type_code")
private String typeCode;
/**
* 创建人
*/
@TableField("create_by")
private String createBy;
/**
* 创建时间
*/
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
//@TableField("create_time")
@TableField(fill = FieldFill.INSERT)
private Date createTime;
/**
* 更新人
*/
@TableField("update_by")
private String updateBy;
/**
* 更新时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
//@TableField("update_time")
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
/**
* 所属部门
*/
@TableField("sys_org_code")
private String sysOrgCode;
/**
* 父级节点id
*/
@TableField("pid")
private String pid;
/**
* 是否有子节点0,没有 1,有
*/
@TableField("has_child")
private String hasChild;
/**
* 分类类型: 领导人 专家 企业高管
*/
@TableField("category")
private String category;
/**
* 状态0启用,1禁用
*/
@TableField("status")
private Integer status;
/**
* 节点绝对路径
*/
@TableField("full_path")
private String fullPath;
/**
* 描述
*/
@TableField("description")
private String description;
/**
* 排序
*/
@TableField("sort")
private Long sort;
}
package com.zzsn.thinktank.entity;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("thinktank_tag_top")
public class ThinktankTagTop {
private String id;
private String name;
private Integer countNum;
//创建时间
@TableField(fill = FieldFill.INSERT)
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
}
package com.zzsn.thinktank.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzsn.thinktank.entity.CityAddress;
import com.zzsn.thinktank.entity.SysBaseDomesticRegion;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/**
* @Version 1.0
* @Author: ZhangJingKun
* @Date: 2024/3/9 16:00
* @Content:
*/
@Mapper
public interface CityAddressMapper extends BaseMapper<SysBaseDomesticRegion> {
@Select("select * from city_address where pid = #{pid}")
List<CityAddress> getCityList(String pid);
}
package com.zzsn.thinktank.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzsn.thinktank.entity.SysBaseEnterprise;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* @Version 1.0
* @Author: ZhangJingKun
* @Date: 2024/4/26 14:27
* @Content:
*/
@Mapper
public interface EnterpriseMapper extends BaseMapper<SysBaseEnterprise> {
List<SysBaseEnterprise> pageList(Integer office, Integer pageSize, String socialCreditCode, String name);
Integer pageListCount(String socialCreditCode, String name);
List<SysBaseEnterprise> getListByName(String name);
}
package com.zzsn.thinktank.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzsn.thinktank.entity.InfoSourceGroupMap;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @Description: 信息源组和信息源关联表
* @Author: jeecg-boot
* @Date: 2021-11-24
* @Version: V1.0
*/
public interface InfoSourceGroupMapMapper extends BaseMapper<InfoSourceGroupMap> {
InfoSourceGroupMap query(@Param("sourceId") String sourceId, @Param("groupId") String groupId);
void deleteBySourceId(@Param("sourceId") String sourceId);
void deleteBySourceIds(@Param("groupId") String groupId, @Param("sourceIds") List<String> sourceIds);
}
package com.zzsn.thinktank.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzsn.thinktank.entity.InfoSource;
import com.zzsn.thinktank.vo.InfoSourceVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @Version 1.0
* @Author: ZhangJingKun
* @Date: 2024/4/25 9:50
* @Content:
*/
@Mapper
public interface InfoSourceMapper extends BaseMapper<InfoSource> {
List<InfoSourceVo> pageListByGroupId(@Param("infoSourceVo") InfoSourceVo infoSourceVo, @Param("ynBind") Integer ynBind, @Param("groupId") String groupId, @Param("offset") Integer offset, @Param("pageSize") Integer pageSize);
Integer totalCountByGroupId(@Param("infoSourceVo") InfoSourceVo infoSourceVo, @Param("ynBind") Integer ynBind, @Param("groupId") String groupId);
List<InfoSourceVo> pageList(@Param("customerId") String customerId,@Param("userId") String userId,@Param("infoSourceVo") InfoSourceVo infoSourceVo, @Param("typeIds") List<String> typeIds, @Param("offset") Integer offset, @Param("pageSize") Integer pageSize);
List<InfoSourceVo> listBySidList(@Param("customerId") String customerId,@Param("userId") String userId,List<String> collect);
Integer totalCount(@Param("customerId") String customerId,@Param("userId") String userId,@Param("infoSourceVo") InfoSourceVo infoSourceVo, @Param("typeIds") List<String> typeIds);
List<String> listByGroupId(@Param("groupId") String groupId);
}
package com.zzsn.thinktank.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzsn.thinktank.entity.ThinktankCategoryStructure;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/**
* <p>
* Mapper 接口
* </p>
*
* @author obcy
* @since 2024-01-04
*/
@Mapper
public interface LeaderCategoryMapper extends BaseMapper<ThinktankCategoryStructure> {
@Select("select * from character_category_structure limit 10")
List<ThinktankCategoryStructure> getListTop();
}
package com.zzsn.thinktank.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzsn.thinktank.entity.ThinktankBasicInfo;
import com.zzsn.thinktank.vo.ThinktankBasicInfoExportVo;
import com.zzsn.thinktank.vo.ThinktankBasicInfoListVo;
import com.zzsn.thinktank.vo.ThinktankBasicInfoVo;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* @Version 1.0
* @Author: ZhangJingKun
* @Date: 2024/4/24 10:34
* @Content:
*/
@Mapper
public interface ThinktankBasicInfoMapper extends BaseMapper<ThinktankBasicInfo> {
List<ThinktankBasicInfoVo> getList(ThinktankBasicInfoListVo thinktankBasicInfoListVo);
Integer getCount(ThinktankBasicInfoListVo thinktankBasicInfoListVo);
List<ThinktankBasicInfoExportVo> getExportList(ThinktankBasicInfoListVo thinktankBasicInfoListVo);
}
package com.zzsn.thinktank.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzsn.thinktank.entity.LabelEntity;
import com.zzsn.thinktank.entity.SysBaseLabelType;
import com.zzsn.thinktank.vo.SysBaseLabelTypeVo;
import com.zzsn.thinktank.vo.SysLabelVo;
import com.zzsn.thinktank.entity.ThinktankTagTop;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/**
* @Version 1.0
* @Author: ZhangJingKun
* @Date: 2024/3/21 11:05
* @Content:
*/
@Mapper
public interface ThinktankTagMapper extends BaseMapper<LabelEntity> {
List<ThinktankTagTop> getTopTag();
SysBaseLabelType getSysBaseLabelTypeById(String id);
List<SysBaseLabelType> getgetSysBaseLabelTypeListByPid(String id);
List<SysLabelVo> queryCustomLabel(List<String> ids, String name);
List<SysBaseLabelTypeVo> getTagTypeListAll();
@Select("select * from thinktank_tag_top " +
"where 1=1 " +
"and id = #{tagId} " +
"limit 1")
ThinktankTagTop getById(String tagName);
}
package com.zzsn.thinktank.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzsn.thinktank.entity.ThinktankTagTop;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
/**
* @Version 1.0
* @Author: ZhangJingKun
* @Date: 2024/3/22 14:07
* @Content:
*/
@Mapper
public interface ThinktankTagTopMapper extends BaseMapper<ThinktankTagTop> {
@Select("select * from thinktank_tag_top " +
"where 1=1 " +
"and name = #{tagName} " +
"limit 1")
ThinktankTagTop getByName(String tagName);
}
package com.zzsn.thinktank.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zzsn.thinktank.entity.SysBaseDomesticRegion;
import com.zzsn.thinktank.vo.Result;
/**
* @Version 1.0
* @Author: ZhangJingKun
* @Date: 2024/3/9 15:56
* @Content:
*/
public interface CityAddressService extends IService<SysBaseDomesticRegion> {
Result<?> getCityList();
Result<?> getCityListByPid(String pid);
}
package com.zzsn.thinktank.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zzsn.thinktank.entity.SysBaseEnterprise;
import com.zzsn.thinktank.vo.Result;
import java.util.List;
/**
* @Version 1.0
* @Author: ZhangJingKun
* @Date: 2024/4/26 14:24
* @Content:
*/
public interface EnterpriseService extends IService<SysBaseEnterprise> {
Result<?> pageList(Integer pageNo, Integer pageSize, String socialCreditCode, String name);
List<SysBaseEnterprise> getListByName(String name);
}
package com.zzsn.thinktank.service;
public interface IGeneratorIdService {
// 通过队列拿id;
Long getId();
Long getOrderId();
// 通过加锁拿id, 不建议使用;
// Long nextId();
//通过redis生成
String getIdNo();
}
package com.zzsn.thinktank.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zzsn.thinktank.entity.InfoSourceGroupMap;
import java.util.List;
/**
* @Description: 信息源组和信息源关联表
* @Author:
* @Date:
* @Version:
*/
public interface InfoSourceGroupMapService extends IService<InfoSourceGroupMap> {
/**信息源与信息源组的绑定关联关系*/
String bind(String groupId, List<String> sourceIds);
/**根据信息源ids删除映射关系*/
void unBind(String groupId, List<String> sourceIds);
List<InfoSourceGroupMap> getSourceGroupMap(List groupIds);
}
package com.zzsn.thinktank.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zzsn.thinktank.entity.InfoSource;
import com.zzsn.thinktank.vo.InfoSourceVo;
import java.util.List;
/**
* @Version 1.0
* @Author: ZhangJingKun
* @Date: 2024/4/25 9:43
* @Content:
*/
public interface InfoSourceService extends IService<InfoSource> {
/**
* 根据分类id获取信息源列表(ynBind=0 :查询没有绑定该组的信息源列表 ynBind=1 :查询绑定该组的信息源列表 )
*/
IPage<InfoSourceVo> pageListByGroupId (InfoSourceVo infoSourceVo, Integer ynBind, String groupId, Integer pageNo, Integer pageSize);
/**
* 根据分类id获取信息源列表
*/
IPage<InfoSourceVo> pageListByTypeId (String customerId, String userId, InfoSourceVo infoSourceVo, Integer pageNo, Integer pageSize, String infoSourceTypeId);
/**
* 获取信息源组下的信息源id集合
*/
List<String> listByGroupId(String groupId);
}
package com.zzsn.thinktank.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zzsn.thinktank.entity.ThinktankCategoryStructure;
import com.zzsn.thinktank.vo.Result;
/**
* <p>
* 服务类
* </p>
*
* @author obcy
* @since 2024-01-04
*/
public interface LeaderCategoryService extends IService<ThinktankCategoryStructure> {
/**根节点父ID的值*/
public static final String ROOT_PID_VALUE = "0";
/**树节点有子节点状态值*/
public static final String HASCHILD = "1";
/**树节点无子节点状态值*/
public static final String NOCHILD = "0";
Result<?> add(ThinktankCategoryStructure characterCategoryStructure);
Result<?> edit(ThinktankCategoryStructure characterCategoryStructure);
Result<?> del(String id);
Result<?> lists(String sign, String pid, String category);
Result<?> getByName(String category, String typeName);
Result<?> getAll(String category);
/**
* 通过id获取子节点列表
* @param id id
* @return
*/
//List<CharacterCategoryStructure> getTreeListBy(String id);
/**
* 根据userId获取列表
* @param userId
* @return
*/
//List<String> getKnowledgeListByUserId(String userId, List<String> knowProjectIdList);
//List<KbAuthuserKnowledgeprojectMap> getKnowledgeProjectListByUserId(String userId);
}
package com.zzsn.thinktank.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zzsn.thinktank.entity.ThinktankBasicInfo;
import com.zzsn.thinktank.vo.Result;
import com.zzsn.thinktank.vo.ThinktankBasicInfoListVo;
import com.zzsn.thinktank.vo.ThinktankBasicInfoVo;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @Version 1.0
* @Author: ZhangJingKun
* @Date: 2024/4/24 10:31
* @Content:
*/
public interface ThinktankBasicInfoService extends IService<ThinktankBasicInfo> {
Result<?> add(ThinktankBasicInfo thinktankBasicInfo);
Result<?> del(String id);
Result<?> edit(ThinktankBasicInfo thinktankBasicInfo);
ThinktankBasicInfoVo getInfoById(String id);
Result<?> getList(ThinktankBasicInfoListVo thinktankBasicInfoListVo);
void downloadTemplate(HttpServletResponse response);
Result batchImport(MultipartFile multipartFile);
byte[] batchExport(ThinktankBasicInfoListVo thinktankBasicInfoListVo, HttpServletRequest request, HttpServletResponse response);
}
package com.zzsn.thinktank.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zzsn.thinktank.entity.LabelEntity;
import com.zzsn.thinktank.entity.ThinktankTagTop;
import com.zzsn.thinktank.vo.Result;
import com.zzsn.thinktank.vo.SysBaseLabelTypeVo;
import java.util.List;
/**
* @Version 1.0
* @Author: ZhangJingKun
* @Date: 2024/3/21 11:04
* @Content:
*/
public interface ThinktankTagService extends IService<LabelEntity> {
Result<?> getTagList(String id, String name);
Result<?> getCharacterListByTag(String tagId, Integer offset, Integer pageSize);
void addTagTop(ThinktankTagTop thinktankTagTop);
Result<?> getTopTag();
SysBaseLabelTypeVo getTagTypeList();
void addTagTop(String tagId);
List<LabelEntity> getListByIds(String[] ids);
}
package com.zzsn.thinktank.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzsn.thinktank.entity.SysBaseDomesticRegion;
import com.zzsn.thinktank.mapper.CityAddressMapper;
import com.zzsn.thinktank.service.CityAddressService;
import com.zzsn.thinktank.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @Version 1.0
* @Author: ZhangJingKun
* @Date: 2024/3/9 15:59
* @Content:
*/
@Service
public class CityAddressServiceImpl extends ServiceImpl<CityAddressMapper, SysBaseDomesticRegion> implements CityAddressService {
@Autowired
CityAddressMapper cityAddressServiceMapper;
@Override
public Result<?> getCityList() {
//List<CityAddress> list = cityAddressServiceMapper.getCityList(pid);
List<SysBaseDomesticRegion> list = super.list();
return Result.OK(list);
}
@Override
public Result<?> getCityListByPid(String pid) {
LambdaQueryWrapper<SysBaseDomesticRegion> lambdaQuery = Wrappers.lambdaQuery();
lambdaQuery.eq(SysBaseDomesticRegion::getPid, pid);
List<SysBaseDomesticRegion> list = cityAddressServiceMapper.selectList(lambdaQuery);
return Result.OK(list);
}
}
package com.zzsn.thinktank.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzsn.thinktank.entity.SysBaseDomesticRegion;
import com.zzsn.thinktank.entity.SysBaseEnterprise;
import com.zzsn.thinktank.mapper.EnterpriseMapper;
import com.zzsn.thinktank.service.EnterpriseService;
import com.zzsn.thinktank.vo.Result;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @Version 1.0
* @Author: ZhangJingKun
* @Date: 2024/4/26 14:25
* @Content:
*/
@Service
public class EnterpriseServiceImpl extends ServiceImpl<EnterpriseMapper, SysBaseEnterprise> implements EnterpriseService {
@Override
public Result<?> pageList(Integer pageNo, Integer pageSize, String socialCreditCode, String name) {
IPage page = new Page();
//查询列表
Integer office = pageSize * (pageNo - 1);
List<SysBaseEnterprise> list = baseMapper.pageList(office, pageSize, socialCreditCode, name);
page.setRecords(list);
//查询总数
Integer total = baseMapper.pageListCount(socialCreditCode, name);
page.setTotal(total);
page.setCurrent(pageNo);
page.setSize(pageSize);
return Result.OK(page);
}
@Override
public List<SysBaseEnterprise> getListByName(String name) {
return baseMapper.getListByName(name);
}
}
package com.zzsn.thinktank.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzsn.thinktank.entity.InfoSourceGroupMap;
import com.zzsn.thinktank.entity.ThinktankBasicInfo;
import com.zzsn.thinktank.mapper.InfoSourceGroupMapMapper;
import com.zzsn.thinktank.service.InfoSourceGroupMapService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.util.List;
/**
* @Description: 信息源组和信息源关联表
* @Author:
* @Date:
* @Version:
*/
@Service
public class InfoSourceGroupMapServiceImpl extends ServiceImpl<InfoSourceGroupMapMapper, InfoSourceGroupMap> implements InfoSourceGroupMapService {
@Autowired
private InfoSourceGroupMapMapper infoSourceGroupMapMapper;
@Override
@Transactional //抛出异常回滚
public String bind (String groupId, List<String> sourceIds){
String message = "绑定成功!";
if(!StringUtils.isEmpty(groupId) && sourceIds != null && sourceIds.size() > 0){
for(String sourceId : sourceIds){
//判断是否绑定过
QueryWrapper<InfoSourceGroupMap> queryWrapper = new QueryWrapper<InfoSourceGroupMap>();
queryWrapper.eq("group_id", groupId);
queryWrapper.eq("source_id", sourceId);
//todo:query in loop
List<InfoSourceGroupMap> list = infoSourceGroupMapMapper.selectList(queryWrapper);
if (list.size() <= 0) {
InfoSourceGroupMap infoSourceGroupMap = new InfoSourceGroupMap();
infoSourceGroupMap.setGroupId(groupId);
infoSourceGroupMap.setSourceId(sourceId);
infoSourceGroupMapMapper.insert(infoSourceGroupMap);
} else {
message = "部分已经绑定信息源成功过滤,未绑定的信息源已经绑定!";
}
}
}
return message;
}
@Override
public void unBind(String groupId, List<String> sourceIds){
if(!StringUtils.isEmpty(groupId) && sourceIds != null && sourceIds.size() > 0){
infoSourceGroupMapMapper.deleteBySourceIds(groupId, sourceIds);
}
}
@Override
public List<InfoSourceGroupMap> getSourceGroupMap(List groupIds) {
LambdaQueryWrapper<InfoSourceGroupMap> lambdaQuery = Wrappers.lambdaQuery();
lambdaQuery.in(InfoSourceGroupMap::getGroupId,groupIds);
List<InfoSourceGroupMap> list = baseMapper.selectList(lambdaQuery);
return list;
}
}
package com.zzsn.thinktank.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzsn.thinktank.entity.InfoSource;
import com.zzsn.thinktank.mapper.InfoSourceMapper;
import com.zzsn.thinktank.service.InfoSourceService;
import com.zzsn.thinktank.util.PageBuilderParser;
import com.zzsn.thinktank.vo.InfoSourceVo;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.w3c.dom.Document;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @Version 1.0
* @Author: ZhangJingKun
* @Date: 2024/4/25 9:49
* @Content:
*/
@Service
public class InfoSourceServiceImpl extends ServiceImpl<InfoSourceMapper, InfoSource> implements InfoSourceService {
/**
* 根据分类id获取信息源列表(ynBind=0 :查询没有绑定该组的信息源列表 ynBind=1 :查询绑定该组的信息源列表 )
*/
@Override
public IPage<InfoSourceVo> pageListByGroupId(InfoSourceVo infoSourceVo, Integer ynBind, String groupId, Integer pageNo, Integer pageSize) {
int offset = (pageNo - 1) * pageSize;
//查询列表
List<InfoSourceVo> pageList = baseMapper.pageListByGroupId(infoSourceVo, ynBind, groupId, offset, pageSize);
//获取总条数
Integer count = baseMapper.totalCountByGroupId(infoSourceVo, ynBind, groupId);
IPage<InfoSourceVo> pageData = new Page<>(pageNo, pageSize, count);
pageData.setRecords(pageList);
return pageData;
}
/**
* 根据分类id获取信息源列表
*/
@Override
public IPage<InfoSourceVo> pageListByTypeId(String customerId, String userId, InfoSourceVo infoSourceVo, Integer pageNo, Integer pageSize, String infoSourceTypeId) {
int offset = (pageNo - 1) * pageSize;
//查询类别id的所有明细id
List<String> typeIds = new ArrayList<>();
// if (!StringUtils.isEmpty(infoSourceTypeId) && !"0".equals(infoSourceTypeId)) {
// String ids = infoSourceTypeService.queryTreeChildLeafIds(infoSourceTypeId);
// typeIds = Arrays.asList(ids.split(","));
// }
//查询列表
long startTime1 = System.currentTimeMillis();
List<InfoSourceVo> pageList = baseMapper.pageList(customerId,userId,infoSourceVo, typeIds, offset, pageSize);
System.out.println("分页查询耗时::" + (System.currentTimeMillis() - startTime1));
//build groupNames
List<String> idList = pageList.stream().map(InfoSourceVo::getId).collect(Collectors.toList());
if(idList.isEmpty()){
return new Page<>(pageNo, pageSize, 0);
}
List<InfoSourceVo> groupNameList = baseMapper.listBySidList(customerId,userId,idList);
Map<String, InfoSourceVo> groupNameMap = groupNameList.stream().collect(Collectors.toMap(InfoSourceVo::getSourceId, value -> value));
//预警标签
long startTime2 = System.currentTimeMillis();
for (InfoSourceVo infoSourceVo1 : pageList) {
if (null != groupNameMap.get(infoSourceVo1.getId())) {
infoSourceVo1.setInfoSourceGroupNames(groupNameMap.get(infoSourceVo1.getId()).getInfoSourceGroupNames());
}
//判断该条信息源是否可以立即执行和下载(现在是定制python爬虫,并且存储方式是文件存储的支持)
infoSourceVo1.setDownLoad(false);
infoSourceVo1.setExecute(false);
if (infoSourceVo1.getCrawlType() == 2) {
//立即执行操作判断
if (infoSourceVo1.getSetMode() == 1 && "2".equals(infoSourceVo1.getTimerMode())) {
infoSourceVo1.setExecute(true);
}
//下载判断
if (infoSourceVo1.getDataStorageMode() == 2) {
infoSourceVo1.setDownLoad(true);
}
}
//列表详情转换成前端格式
reverseTransForm(infoSourceVo1);
}
System.out.println("数据组装耗时::" + (System.currentTimeMillis() - startTime2));
//获取总条数
Integer count = baseMapper.totalCount(customerId,userId,infoSourceVo, typeIds);
IPage<InfoSourceVo> pageData = new Page<>(pageNo, pageSize, count);
pageData.setRecords(pageList);
return pageData;
}
//数据库查询时,逆向转化成前端展示结构
private void reverseTransForm(InfoSourceVo infoSourceVo) {
try {
PageBuilderParser pageBuilderParser = new PageBuilderParser();
//标题
if (!StringUtils.isEmpty(infoSourceVo.getDetailExpressionTitle())) {
String info = infoSourceVo.getDetailExpressionTitle();
Document document = PageBuilderParser.xmlGetDocument(info);
infoSourceVo.setDetailExpressionTitle(pageBuilderParser.parserStr(document, "title/exp"));
if (!StringUtils.isEmpty(pageBuilderParser.parserStr(document, "title/attr"))) {
infoSourceVo.setTitleExtractionMethodType(1);
infoSourceVo.setTitleExtractionMethod(pageBuilderParser.parserStr(document, "title/attr"));
} else if (!StringUtils.isEmpty(pageBuilderParser.parserStr(document, "title/subtraction"))) {
infoSourceVo.setTitleExtractionMethodType(2);
infoSourceVo.setTitleExtractionMethod(pageBuilderParser.parserStr(document, "title/subtraction"));
}
}
//时间
if (!StringUtils.isEmpty(infoSourceVo.getDetailExpressionPublishDate())) {
String info = infoSourceVo.getDetailExpressionPublishDate();
Document document = PageBuilderParser.xmlGetDocument(info);
infoSourceVo.setDetailExpressionPublishDate(pageBuilderParser.parserStr(document, "publish_date/exp"));
if (!StringUtils.isEmpty(pageBuilderParser.parserStr(document, "publish_date/attr"))) {
infoSourceVo.setPublishDateExtractionMethodType(1);
infoSourceVo.setPublishDateExtractionMethod(pageBuilderParser.parserStr(document, "publish_date/attr"));
} else if (!StringUtils.isEmpty(pageBuilderParser.parserStr(document, "publish_date/subtraction"))) {
infoSourceVo.setPublishDateExtractionMethodType(2);
infoSourceVo.setPublishDateExtractionMethod(pageBuilderParser.parserStr(document, "publish_date/subtraction"));
}
}
//作者
if (!StringUtils.isEmpty(infoSourceVo.getDetailExpressionAuthor())) {
String info = infoSourceVo.getDetailExpressionAuthor();
Document document = PageBuilderParser.xmlGetDocument(info);
infoSourceVo.setDetailExpressionAuthor(pageBuilderParser.parserStr(document, "author/exp"));
if (!StringUtils.isEmpty(pageBuilderParser.parserStr(document, "author/attr"))) {
infoSourceVo.setAuthorExtractionMethodType(1);
infoSourceVo.setAuthorExtractionMethod(pageBuilderParser.parserStr(document, "author/attr"));
} else if (!StringUtils.isEmpty(pageBuilderParser.parserStr(document, "author/subtraction"))) {
infoSourceVo.setAuthorExtractionMethodType(2);
infoSourceVo.setAuthorExtractionMethod(pageBuilderParser.parserStr(document, "author/subtraction"));
}
}
//来源
if (!StringUtils.isEmpty(infoSourceVo.getDetailExpressionSource())) {
String info = infoSourceVo.getDetailExpressionSource();
Document document = PageBuilderParser.xmlGetDocument(info);
infoSourceVo.setDetailExpressionSource(pageBuilderParser.parserStr(document, "origin/exp"));
if (!StringUtils.isEmpty(pageBuilderParser.parserStr(document, "origin/attr"))) {
infoSourceVo.setSourceExtractionMethodType(1);
infoSourceVo.setSourceExtractionMethod(pageBuilderParser.parserStr(document, "origin/attr"));
} else if (!StringUtils.isEmpty(pageBuilderParser.parserStr(document, "origin/subtraction"))) {
infoSourceVo.setSourceExtractionMethodType(2);
infoSourceVo.setSourceExtractionMethod(pageBuilderParser.parserStr(document, "origin/subtraction"));
}
}
//摘要
if (!StringUtils.isEmpty(infoSourceVo.getDetailExpressionSummary())) {
String info = infoSourceVo.getDetailExpressionSummary();
Document document = PageBuilderParser.xmlGetDocument(info);
infoSourceVo.setDetailExpressionSummary(pageBuilderParser.parserStr(document, "summary/exp"));
if (!StringUtils.isEmpty(pageBuilderParser.parserStr(document, "summary/attr"))) {
infoSourceVo.setSummaryExtractionMethodType(1);
infoSourceVo.setSummaryExtractionMethod(pageBuilderParser.parserStr(document, "summary/attr"));
} else if (!StringUtils.isEmpty(pageBuilderParser.parserStr(document, "summary/subtraction"))) {
infoSourceVo.setSummaryExtractionMethodType(2);
infoSourceVo.setSummaryExtractionMethod(pageBuilderParser.parserStr(document, "summary/subtraction"));
}
}
//正文
if (!StringUtils.isEmpty(infoSourceVo.getDetailExpressionContent())) {
String info = infoSourceVo.getDetailExpressionContent();
Document document = PageBuilderParser.xmlGetDocument(info);
infoSourceVo.setDetailExpressionContent(pageBuilderParser.parserStr(document, "content/exp"));
if (!StringUtils.isEmpty(pageBuilderParser.parserStr(document, "content/attr"))) {
infoSourceVo.setContentExtractionMethodType(1);
infoSourceVo.setContentExtractionMethod(pageBuilderParser.parserStr(document, "content/attr"));
} else if (!StringUtils.isEmpty(pageBuilderParser.parserStr(document, "content/subtraction"))) {
infoSourceVo.setContentExtractionMethodType(2);
infoSourceVo.setContentExtractionMethod(pageBuilderParser.parserStr(document, "content/subtraction"));
}
}
} catch (Exception e) {
//
}
}
@Override
public List<String> listByGroupId(String groupId) {
return baseMapper.listByGroupId(groupId);
}
}
package com.zzsn.thinktank.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzsn.thinktank.entity.ThinktankCategoryStructure;
import com.zzsn.thinktank.mapper.LeaderCategoryMapper;
import com.zzsn.thinktank.service.LeaderCategoryService;
import com.zzsn.thinktank.vo.CharacterCategoryStructureTreeVo;
import com.zzsn.thinktank.vo.Result;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import java.util.stream.Collectors;
/**
* <p>
* 分类树服务实现类
* </p>
*
* @author
* @since
*/
@Service
public class LeaderCategoryServiceImpl extends ServiceImpl<LeaderCategoryMapper, ThinktankCategoryStructure> implements LeaderCategoryService {
@Override
@Transactional
public Result<?> add(ThinktankCategoryStructure characterCategoryStructure) {
//判断是否有父节点,没有则为根节点,pid的值为0
if (StringUtils.isBlank(characterCategoryStructure.getPid())){
characterCategoryStructure.setPid(LeaderCategoryService.ROOT_PID_VALUE);
}else {
ThinktankCategoryStructure parent = super.getById(characterCategoryStructure.getPid());
if(parent!=null && !LeaderCategoryService.HASCHILD.equals(parent.getHasChild())){
parent.setHasChild(LeaderCategoryService.HASCHILD);
super.updateById(parent);
}
}
//characterCategoryStructure.setStatus(0);
characterCategoryStructure.setHasChild(LeaderCategoryService.NOCHILD);
/**第一次保存赋默认值*/
characterCategoryStructure.setFullPath("0");
characterCategoryStructure.setCreateTime(new Date());
super.save(characterCategoryStructure);
if (LeaderCategoryService.ROOT_PID_VALUE.equals(characterCategoryStructure.getPid())){
characterCategoryStructure.setFullPath(characterCategoryStructure.getId());
}else {
ThinktankCategoryStructure parent = super.getById(characterCategoryStructure.getPid());
characterCategoryStructure.setFullPath(parent.getFullPath() +","+ characterCategoryStructure.getId());
}
super.updateById(characterCategoryStructure);
return Result.OK();
}
@Override
@Transactional
public Result<?> edit(ThinktankCategoryStructure characterCategoryStructure) {
ThinktankCategoryStructure byId = super.getById(characterCategoryStructure.getId());
if (ObjectUtils.isEmpty(byId)){
return Result.error("未找到对应的分类id");
}
String oldPid = byId.getPid();
String newPid = characterCategoryStructure.getPid();
if(!oldPid.equals(newPid)) {
/**处理之前父节点的hasChild字段*/
updateOldParentNode(oldPid);
if(StringUtils.isBlank(newPid) || LeaderCategoryService.ROOT_PID_VALUE.equals(newPid)){
characterCategoryStructure.setPid(LeaderCategoryService.ROOT_PID_VALUE);
newPid = characterCategoryStructure.getPid();
}
/**处理新的父节点的hasChild字段*/
if(!LeaderCategoryService.ROOT_PID_VALUE.equals(characterCategoryStructure.getPid())) {
super.update(Wrappers.<ThinktankCategoryStructure>lambdaUpdate().set(ThinktankCategoryStructure::getHasChild,LeaderCategoryService.HASCHILD).eq(ThinktankCategoryStructure::getId,newPid));
}
characterCategoryStructure.setUpdateTime(new Date());
super.updateById(characterCategoryStructure);
/**处理本节点的所有子节点的绝对路径*/
List<ThinktankCategoryStructure> list = super.list(Wrappers.<ThinktankCategoryStructure>lambdaQuery().like(ThinktankCategoryStructure::getFullPath,characterCategoryStructure.getId()));
if (CollectionUtil.isNotEmpty(list)){
String finalNewPid = newPid;
if (!LeaderCategoryService.ROOT_PID_VALUE.equals(finalNewPid)) {
/**非根节点 移动到其他非根节点*/
ThinktankCategoryStructure projectPid = super.getById(finalNewPid);
if (!LeaderCategoryService.ROOT_PID_VALUE.equals(oldPid)) {
String id = characterCategoryStructure.getId();
String fullPath = characterCategoryStructure.getFullPath();
String replace = fullPath.replace(id, "");
list.forEach(e->{
e.setFullPath(projectPid.getFullPath()+"," + e.getFullPath().replace(replace, ""));
});
}else {
/**根节点 移动到其他非根节点*/
list.forEach(e->{
e.setFullPath(projectPid.getFullPath()+","+e.getFullPath());
});
}
}else {
String id = characterCategoryStructure.getId();
String fullPath = characterCategoryStructure.getFullPath();
String replace = fullPath.replace(id, "");
/**移动到根节点*/
list.forEach(e->{
e.setFullPath(e.getFullPath().replace(replace, ""));
});
}
}
super.updateBatchById(list);
}else {
characterCategoryStructure.setUpdateTime(new Date());
super.updateById(characterCategoryStructure);
}
return Result.OK();
}
@Override
public Result<?> del(String id) {
ThinktankCategoryStructure byId = super.getById(id);
super.remove(Wrappers.<ThinktankCategoryStructure>lambdaQuery().like(ThinktankCategoryStructure::getFullPath,id));
if (StringUtils.isNotBlank(byId.getPid())&&!LeaderCategoryService.ROOT_PID_VALUE.equals(byId.getPid())){
updateOldParentNodeDel(byId.getPid());
}
return Result.OK();
}
@Override
public Result<?> lists(String sign, String pid, String category) {
List<ThinktankCategoryStructure> characterCategoryStructure ;
if ("1".equals(sign)&&"0".equals(pid)){
characterCategoryStructure = super.list(Wrappers.<ThinktankCategoryStructure>lambdaQuery()
.eq(ThinktankCategoryStructure::getPid, LeaderCategoryService.ROOT_PID_VALUE)
.eq(StrUtil.isNotBlank(category),ThinktankCategoryStructure::getCategory,category));
}else {
characterCategoryStructure = super.list(Wrappers.<ThinktankCategoryStructure>lambdaQuery()
.eq(ThinktankCategoryStructure::getPid,pid)
.eq(StrUtil.isNotBlank(category),ThinktankCategoryStructure::getCategory,category));
}
return Result.OK(characterCategoryStructure);
}
@Override
public Result<?> getByName(String category, String typeName) {
//根据名称模糊查询
List<ThinktankCategoryStructure> characterCategoryStructure = super.list(Wrappers.<ThinktankCategoryStructure>lambdaQuery()
.like(ThinktankCategoryStructure::getTypeName,typeName)
.eq(StrUtil.isNotBlank(category),ThinktankCategoryStructure::getCategory,category));
//根据所有子节点的pid路径查询所有父节点
Set<String> idSet = new HashSet<>();
for (ThinktankCategoryStructure categoryStructure : characterCategoryStructure) {
String fullPath = categoryStructure.getFullPath();
String[] pidArr = fullPath.split(",");
idSet.addAll(Arrays.asList(pidArr));
}
List<ThinktankCategoryStructure> characterCategoryStructurePid = super.list(
Wrappers.<ThinktankCategoryStructure>lambdaQuery()
.in(ThinktankCategoryStructure::getId, idSet)
);
//将查询的所有数据汇总到一个map中并根据id去重
Map<String, CharacterCategoryStructureTreeVo> map = new HashMap<>();
for (ThinktankCategoryStructure categoryStructure : characterCategoryStructure) {
CharacterCategoryStructureTreeVo ccstvo = new CharacterCategoryStructureTreeVo();
BeanUtils.copyProperties(categoryStructure, ccstvo);
map.put(ccstvo.getId(), ccstvo);
}
for (ThinktankCategoryStructure categoryStructure : characterCategoryStructurePid) {
CharacterCategoryStructureTreeVo ccstvo = new CharacterCategoryStructureTreeVo();
BeanUtils.copyProperties(categoryStructure, ccstvo);
map.put(ccstvo.getId(), ccstvo);
}
//所有数据的list列表
Collection<CharacterCategoryStructureTreeVo> list = map.values();
List<CharacterCategoryStructureTreeVo> collect = list.stream()
// 找出所有顶级(pid = 0 为顶级)
.filter(o -> StrUtil.equals("0", o.getPid()))
//给当前的父级的 children 设置子级
.peek(o -> o.setChildren(getChildList(o, list)))
//收集
.collect(Collectors.toList());
return Result.OK(collect);
}
@Override
public Result<?> getAll(String category) {
//根据名称模糊查询
List<ThinktankCategoryStructure> characterCategoryStructure = super.list(Wrappers.<ThinktankCategoryStructure>lambdaQuery()
.eq(StrUtil.isNotBlank(category),ThinktankCategoryStructure::getCategory,category));
List<CharacterCategoryStructureTreeVo> list = new ArrayList<>();
for (ThinktankCategoryStructure categoryStructure : characterCategoryStructure) {
CharacterCategoryStructureTreeVo ccstvo = new CharacterCategoryStructureTreeVo();
BeanUtils.copyProperties(categoryStructure, ccstvo);
list.add(ccstvo);
}
List<CharacterCategoryStructureTreeVo> collect = list.stream()
// 找出所有顶级(pid = 0 为顶级)
.filter(o -> StrUtil.equals("0", o.getPid()))
//给当前的父级的 children 设置子级
.peek(o -> o.setChildren(getChildList(o, list)))
//收集
.collect(Collectors.toList());
return Result.OK(collect);
}
// 根据当前父类 找出子类, 并通过递归找出子类的子类
private List<CharacterCategoryStructureTreeVo> getChildList(CharacterCategoryStructureTreeVo projectLeader, Collection<CharacterCategoryStructureTreeVo> list) {
return list.stream()
//筛选出父节点id == parentId 的所有对象 => list
.filter(o -> StrUtil.equals(String.valueOf(projectLeader.getId()), o.getPid()))
.peek(o -> o.setChildren(getChildList(o, list)))
.collect(Collectors.toList());
}
private void updateOldParentNode(String pid) {
if(!LeaderCategoryService.ROOT_PID_VALUE.equals(pid)) {
Integer count = baseMapper.selectCount(Wrappers.<ThinktankCategoryStructure>lambdaQuery().eq(ThinktankCategoryStructure::getPid,pid));
if(count==null || count<=1) {
super.update(Wrappers.<ThinktankCategoryStructure>lambdaUpdate().set(ThinktankCategoryStructure::getHasChild,LeaderCategoryService.NOCHILD).eq(ThinktankCategoryStructure::getId,pid));
}
}
}
/**
* 根据所传pid查询旧的父级节点的子节点并修改相应状态值
* @param pid
*/
private void updateOldParentNodeDel(String pid) {
if(!LeaderCategoryService.ROOT_PID_VALUE.equals(pid)) {
Integer count = baseMapper.selectCount(Wrappers.<ThinktankCategoryStructure>lambdaQuery().eq(ThinktankCategoryStructure::getPid,pid));
if(count==null || count<1) {
super.update(Wrappers.<ThinktankCategoryStructure>lambdaUpdate().set(ThinktankCategoryStructure::getHasChild,LeaderCategoryService.NOCHILD).eq(ThinktankCategoryStructure::getId,pid));
}
}
}
}
package com.zzsn.thinktank.service.impl;
import com.zzsn.thinktank.service.IGeneratorIdService;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.support.atomic.RedisAtomicLong;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.concurrent.ConcurrentLinkedQueue;
/**
* 雪花算法生成id
*/
@Component
@Slf4j
public class SnowFlakeGeneratorId implements IGeneratorIdService {
@Autowired
private StringRedisTemplate stringRedisTemplate;
private final static int MAX_QUEUE = 128;
private final static int DEFAULT_MACHINE_BIT_NUM = 6; //机器标识占用的位数
private final static int DEFAULT_PORT_BIT_NUM = 4; //端口占用的位数
private final static long START_STAMP = 1641286225129L; //起始时间
// 线程安全队列
private final ConcurrentLinkedQueue<Long> queue = new ConcurrentLinkedQueue<>();
private final ConcurrentLinkedQueue<Long> orderQueue = new ConcurrentLinkedQueue<>();
/**
* 可分配的位数
*/
private final static int REMAIN_BIT_NUM = 22;
private static final String FINANCE = "THINK_TANK_CODE:";
private final static int NUM = 8;
private static final String ZKG = "ZKG";
@Value("${server.port}")
private String port;
@PostConstruct
public void init() {
int portBitNum = DEFAULT_PORT_BIT_NUM;
int sequenceBitNum = REMAIN_BIT_NUM - portBitNum - machineBitNum;
this.maxSequenceValue = ~(-1 << sequenceBitNum);
machineBitLeftOffset = sequenceBitNum;
portBitLeftOffset = portBitNum + sequenceBitNum;
timestampBitLeftOffset = portBitNum + machineBitNum + sequenceBitNum;
this.portId = Integer.parseInt(port) & 15;
this.machineId = getMachineId() & 63;
productIdToQueue(queue, MAX_QUEUE);
productIdToQueue(orderQueue, MAX_QUEUE);
}
public Long getId() {
Long peek = queue.poll();
if (queue.size() <= MAX_QUEUE / 2) {
productIdToQueue(queue, MAX_QUEUE / 2);
}
return peek;
}
public Long getOrderId() {
Long peek = orderQueue.poll();
if (orderQueue.size() <= MAX_QUEUE / 2) {
productIdToQueue(orderQueue, MAX_QUEUE / 2);
}
return peek;
}
@Override
public String getIdNo() {
return getId(FINANCE, NUM);
}
//根据规则生成id(规则:格式化日期(截取后六位)+递增值(8位数))
private String getId(String prefix, int num){
String redisKey = getRedisKey(prefix);
Date expireDate = getExpireDate();
//返回当前redis中的key的最大值
long seq = generate(stringRedisTemplate, redisKey, expireDate);
//获取当天的日期,格式为yyyyMMdd
String date = new SimpleDateFormat("yyyyMMdd").format(expireDate);
//生成八位的序列号,如果seq不够四位,seq前面补0,
//如果seq位数超过了八位,那么无需补0直接返回当前的seq
String sequence = StringUtils.leftPad(Long.toString(seq), num, "0");
StringBuffer sb = new StringBuffer()
.append(ZKG)
.append("-")
.append(date)
.append("-")
.append(sequence);
return sb.toString();
}
//获取redis--key
@SneakyThrows
private String getRedisKey(String prefix){
if (StringUtils.isEmpty(prefix)){
throw new Exception("前缀不能为空!");
}
//用作存放redis中的key前缀
String PREFIX_KEY = "CodeGenerateUtil::";
return PREFIX_KEY + prefix;
}
//获取缓存过期时间点
private Date getExpireDate(){
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 23);
calendar.set(Calendar.MINUTE, 59);
calendar.set(Calendar.SECOND, 59);
//设置过期时间,这里设置为当天的23:59:59
return calendar.getTime();
}
//获取redis缓存
private long generate(StringRedisTemplate stringRedisTemplate, String key, Date expireTime) {
//RedisAtomicLong为原子类,根据传入的key和redis链接工厂创建原子类
RedisAtomicLong counter = new RedisAtomicLong(key,stringRedisTemplate.getConnectionFactory());
//设置过期时间
counter.expireAt(expireTime);
//返回redis中key的值
return counter.incrementAndGet();
}
/**
* 产生下一个ID
*/
public synchronized Long nextId() {
long currentStamp = getTimeMill();
if (currentStamp < lastStamp) {
throw new RuntimeException(String.format("Clock moved backwards. Refusing to generate id for %d milliseconds", lastStamp - currentStamp));
}
//新的毫秒,序列从0开始,否则序列自增
if (currentStamp == lastStamp) {
sequence = (sequence + 1) & this.maxSequenceValue;
if (sequence == 0L) {
//Twitter源代码中的逻辑是循环,直到下一个毫秒
lastStamp = tilNextMillis();
// throw new IllegalStateException("sequence over flow");
}
} else {
sequence = 0L;
}
lastStamp = currentStamp;
return (currentStamp - START_STAMP) << timestampBitLeftOffset | portId << portBitLeftOffset | machineId << machineBitLeftOffset | sequence;
}
private void productIdToQueue(ConcurrentLinkedQueue<Long> queue, Integer num) {
new Thread(() -> {
for (int i = 0; i < num; i++) {
queue.add(nextId());
}
}).start();
}
private Integer getMachineId() {
InetAddress addr = null;
try {
addr = InetAddress.getLocalHost();
} catch (UnknownHostException e) {
e.printStackTrace();
}
/*获取本机IP*/
assert addr != null;
String ip = addr.getHostAddress();
log.info("本机IP : {} ", ip);
return Integer.parseInt(ip.split("\\.")[3]);
}
private final int machineBitNum = DEFAULT_MACHINE_BIT_NUM;
/**
* idc编号
*/
private long portId;
/**
* 机器编号
*/
private long machineId;
/**
* 当前序列号
*/
private long sequence = 0L;
/**
* 上次最新时间戳
*/
private long lastStamp = -1L;
/**
* idc偏移量:一次计算出,避免重复计算
*/
private int portBitLeftOffset;
/**
* 机器id偏移量:一次计算出,避免重复计算
*/
private int machineBitLeftOffset;
/**
* 时间戳偏移量:一次计算出,避免重复计算
*/
private int timestampBitLeftOffset;
/**
* 最大序列值:一次计算出,避免重复计算
*/
private int maxSequenceValue;
private long getTimeMill() {
return System.currentTimeMillis();
}
private long tilNextMillis() {
long timestamp = getTimeMill();
while (timestamp <= lastStamp) {
timestamp = getTimeMill();
}
return timestamp;
}
}
\ No newline at end of file
package com.zzsn.thinktank.service.impl;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzsn.thinktank.entity.*;
import com.zzsn.thinktank.mapper.ThinktankBasicInfoMapper;
import com.zzsn.thinktank.service.*;
import com.zzsn.thinktank.util.DateUtil;
import com.zzsn.thinktank.util.EsUtil;
import com.zzsn.thinktank.util.ExcelExportUtil;
import com.zzsn.thinktank.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Workbook;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;
import org.springframework.util.ResourceUtils;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLEncoder;
import java.util.*;
import java.util.stream.Collectors;
/**
* @Version 1.0
* @Author: ZhangJingKun
* @Date: 2024/4/24 10:32
* @Content:
*/
@Slf4j
@Service
public class ThinktankBasicInfoServiceImpl extends ServiceImpl<ThinktankBasicInfoMapper, ThinktankBasicInfo> implements ThinktankBasicInfoService {
@Autowired
ThinktankBasicInfoMapper thinktankBasicInfoMapper;
//生成id
@Autowired
IGeneratorIdService generatorIdService;
//左侧分类树
@Autowired
LeaderCategoryService leaderCategoryService;
//标签
@Autowired
ThinktankTagService thinktankTagService;
//所属单位
@Autowired
EnterpriseService enterpriseService;
//信息源关联
@Autowired
InfoSourceGroupMapService infoSourceGroupMapService;
@Autowired
EsUtil esUtil;
@Value("${files.storage}")
String filesStorage;
private static final String IMPORT_TEMP = "think-tank-import-temp.xlsx";
private static final String IMPORT_TEMP_NAME = "智库信息导入模板.xlsx";
@Override
public Result<?> add(ThinktankBasicInfo thinktankBasicInfo) {
String id = Long.toString(generatorIdService.getOrderId());
thinktankBasicInfo.setId(id);
String codeId = generatorIdService.getIdNo();
thinktankBasicInfo.setCodeId(codeId);
//标签
String tagId = thinktankBasicInfo.getTagId();
if(tagId != null && tagId.length() > 0){
String[] ids = tagId.split(",");
List<LabelEntity> list = thinktankTagService.getListByIds(ids);
List<String> nameList = new ArrayList<>();
for (LabelEntity labelEntity : list) {
String name = labelEntity.getName();
nameList.add(name);
}
String tagName = nameList.stream().collect(Collectors.joining(","));
thinktankBasicInfo.setTagName(tagName);
}
//类别
String belongCountryId = thinktankBasicInfo.getBelongCountryId();
ThinktankCategoryStructure tcs = leaderCategoryService.getById(belongCountryId);
if(tcs != null){
String typeName = tcs.getTypeName();
thinktankBasicInfo.setBelongCountry(typeName);
}
thinktankBasicInfo.setCreateTime(new Date());
boolean b = this.save(thinktankBasicInfo);
Result result = Result.OK();
if(!b){
result.error500("保存失败!");
}
return result;
}
@Override
public Result<?> del(String id) {
String[] idArr = id.split(",");
List<String> ids = Arrays.asList(idArr);
boolean b = this.removeByIds(ids);
Result result = Result.OK();
if(!b){
result.error500("删除失败!");
}
return result;
}
@Override
public Result<?> edit(ThinktankBasicInfo thinktankBasicInfo) {
//标签
String tagId = thinktankBasicInfo.getTagId();
if(tagId != null && tagId.length() > 0){
String[] ids = tagId.split(",");
List<LabelEntity> list = thinktankTagService.getListByIds(ids);
List<String> nameList = new ArrayList<>();
for (LabelEntity labelEntity : list) {
String name = labelEntity.getName();
nameList.add(name);
}
String tagName = nameList.stream().collect(Collectors.joining(","));
thinktankBasicInfo.setTagName(tagName);
}
//类别
String belongCountryId = thinktankBasicInfo.getBelongCountryId();
ThinktankCategoryStructure tcs = leaderCategoryService.getById(belongCountryId);
String typeName = tcs.getTypeName();
thinktankBasicInfo.setBelongCountry(typeName);
thinktankBasicInfo.setUpdateTime(new Date());
boolean b = this.updateById(thinktankBasicInfo);
Result result = Result.OK();
if(!b){
result.error500("修改失败!");
}
return result;
}
@Override
public ThinktankBasicInfoVo getInfoById(String id) {
ThinktankBasicInfo info = this.getById(id);
if(info == null){
return null;
}
ThinktankBasicInfoVo infoVo = new ThinktankBasicInfoVo();
BeanUtils.copyProperties(info, infoVo);
List<ThinktankBasicInfoVo> list = new ArrayList<>();
list.add(infoVo);
List<String> groupIds = new ArrayList<>();
for (ThinktankBasicInfoVo thinktankBasicInfoVo : list) {
groupIds.add(thinktankBasicInfoVo.getId());
}
List<InfoSourceGroupMap> infoSourceGroupMapList = infoSourceGroupMapService.getSourceGroupMap(groupIds);
List<InfoSourceGroupCountVo> countVoList = new ArrayList<>();
List<String> sidList = new ArrayList<>();
for (InfoSourceGroupMap infoSourceGroupMap : infoSourceGroupMapList) {
InfoSourceGroupCountVo infoSourceGroupCountVo = new InfoSourceGroupCountVo();
BeanUtils.copyProperties(infoSourceGroupMap, infoSourceGroupCountVo);
countVoList.add(infoSourceGroupCountVo);
sidList.add(infoSourceGroupMap.getSourceId());
}
//查询es
BoolQueryBuilder boolQuerylist = QueryBuilders.boolQuery();
boolQuerylist.must(QueryBuilders.termsQuery("sid",sidList));
Map<String, Long> mapGroup = null;
try {
mapGroup = esUtil.groupBy("basedata", "sid", boolQuerylist, 100);
} catch (IOException e) {
log.error("ES查询失败");
e.printStackTrace();
}
if(mapGroup != null && mapGroup.size() > 0){
for (InfoSourceGroupCountVo infoSourceGroupCountVo : countVoList) {
String sourceId = infoSourceGroupCountVo.getSourceId();
Long countInfo = mapGroup.get(sourceId);
if(countInfo == null){
countInfo = 0L;
}
infoSourceGroupCountVo.setInfoCount(Math.toIntExact(countInfo));
}
}
//统计关联信息源数量
Map<String, List<InfoSourceGroupCountVo>> studentsByGrade = countVoList.stream()
.collect(Collectors.groupingBy(InfoSourceGroupCountVo::getGroupId));
for (ThinktankBasicInfoVo thinktankBasicInfoVo : list) {
// String id = thinktankBasicInfoVo.getId();
List<InfoSourceGroupCountVo> listVo = studentsByGrade.get(thinktankBasicInfoVo.getId());
if(listVo == null){
thinktankBasicInfoVo.setCollectionCount(0);
thinktankBasicInfoVo.setInfoSourceCount(0);
} else {
thinktankBasicInfoVo.setInfoSourceCount(listVo.size());
int count = 0;
for (InfoSourceGroupCountVo infoSourceGroupCountVo : listVo) {
count += infoSourceGroupCountVo.getInfoCount();
}
thinktankBasicInfoVo.setCollectionCount(count);
}
}
return list.get(0);
}
@Override
public Result<?> getList(ThinktankBasicInfoListVo thinktankBasicInfoListVo) {
IPage page = new Page();
//查询列表
List<ThinktankBasicInfoVo> list = thinktankBasicInfoMapper.getList(thinktankBasicInfoListVo);
page.setRecords(list);
//查询总数
Integer total = thinktankBasicInfoMapper.getCount(thinktankBasicInfoListVo);
page.setTotal(total);
Integer pageNo = thinktankBasicInfoListVo.getPageNo();
Integer pageSize= thinktankBasicInfoListVo.getPageSize();
page.setCurrent(pageNo);
page.setSize(pageSize);
if(list.size() == 0){
return Result.OK(page);
}
//信息源
List<String> groupIds = new ArrayList<>();
for (ThinktankBasicInfoVo thinktankBasicInfoVo : list) {
groupIds.add(thinktankBasicInfoVo.getId());
}
List<InfoSourceGroupMap> infoSourceGroupMapList = infoSourceGroupMapService.getSourceGroupMap(groupIds);
List<InfoSourceGroupCountVo> countVoList = new ArrayList<>();
List<String> sidList = new ArrayList<>();
for (InfoSourceGroupMap infoSourceGroupMap : infoSourceGroupMapList) {
InfoSourceGroupCountVo infoSourceGroupCountVo = new InfoSourceGroupCountVo();
BeanUtils.copyProperties(infoSourceGroupMap, infoSourceGroupCountVo);
countVoList.add(infoSourceGroupCountVo);
sidList.add(infoSourceGroupMap.getSourceId());
}
//查询es
BoolQueryBuilder boolQuerylist = QueryBuilders.boolQuery();
boolQuerylist.must(QueryBuilders.termsQuery("sid",sidList));
Map<String, Long> mapGroup = null;
try {
mapGroup = esUtil.groupBy("basedata", "sid", boolQuerylist, 100);
} catch (IOException e) {
log.error("ES查询失败");
e.printStackTrace();
}
if(mapGroup != null && mapGroup.size() > 0){
for (InfoSourceGroupCountVo infoSourceGroupCountVo : countVoList) {
String sourceId = infoSourceGroupCountVo.getSourceId();
Long countInfo = mapGroup.get(sourceId);
if(countInfo == null){
countInfo = 0L;
}
infoSourceGroupCountVo.setInfoCount(Math.toIntExact(countInfo));
}
}
//统计关联信息源数量
Map<String, List<InfoSourceGroupCountVo>> studentsByGrade = countVoList.stream()
.collect(Collectors.groupingBy(InfoSourceGroupCountVo::getGroupId));
for (ThinktankBasicInfoVo thinktankBasicInfoVo : list) {
String id = thinktankBasicInfoVo.getId();
List<InfoSourceGroupCountVo> listVo = studentsByGrade.get(id);
if(listVo == null){
thinktankBasicInfoVo.setCollectionCount(0);
thinktankBasicInfoVo.setInfoSourceCount(0);
} else {
thinktankBasicInfoVo.setInfoSourceCount(listVo.size());
int count = 0;
for (InfoSourceGroupCountVo infoSourceGroupCountVo : listVo) {
count += infoSourceGroupCountVo.getInfoCount();
}
thinktankBasicInfoVo.setCollectionCount(count);
}
}
//记录热门标签
String tagId = thinktankBasicInfoListVo.getTagId();
if(tagId != null && tagId.length() >0){
String[] tagIdArr = tagId.split(",");
for (String s : tagIdArr) {
thinktankTagService.addTagTop(s);
}
}
return Result.OK(page);
}
@Override
public void downloadTemplate(HttpServletResponse response) {
String filePath = filesStorage + IMPORT_TEMP;
File file = new File(filePath);
try {
// 将文件写入输入流
FileInputStream fileInputStream = new FileInputStream(file);
InputStream fis = new BufferedInputStream(fileInputStream);
byte[] buffer = new byte[fis.available()];
fis.read(buffer);
fis.close();
// 清空response
response.reset();
// 设置response的Header
response.setCharacterEncoding("UTF-8");
//Content-Disposition的作用:告知浏览器以何种方式显示响应返回的文件,用浏览器打开还是以附件的形式下载到本地保存
//attachment表示以附件方式下载 inline表示在线打开 "Content-Disposition: inline; filename=文件名.mp3"
// filename表示文件的默认名称,因为网络传输只支持URL编码的相关支付,因此需要将文件名URL编码后进行传输,前端收到后需要反编码才能获取到真正的名称
response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(IMPORT_TEMP_NAME, "UTF-8"));
// 告知浏览器文件的大小
response.addHeader("Content-Length", "" + file.length());
OutputStream outputStream = new BufferedOutputStream(response.getOutputStream());
response.setContentType("application/octet-stream");
outputStream.write(buffer);
outputStream.flush();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public Result batchImport(MultipartFile multipartFile) {
int index = multipartFile.getOriginalFilename().lastIndexOf(".");
String fileSuffix = multipartFile.getOriginalFilename().substring(index + 1);
if ("xls".equals(fileSuffix) || "xlsx".equals(fileSuffix)) {
//文件校验
if (!this.checkExcel(multipartFile)) {
log.error("excel格式不对");
return Result.error("模版有误,请使用正确的模板!");
}
String msg = doExcel(multipartFile,fileSuffix);
return Result.OK(msg);
} else {
return Result.error("不支持的文件类型!");
}
}
private boolean checkExcel(MultipartFile multipartFile) {
Workbook workbook = ExcelExportUtil.getWorkbook(multipartFile);
if (workbook != null) {
List<String> list = ExcelExportUtil.getSheetTitles(workbook);
return list != null
&& list.contains("序号")
&& list.contains("智库机构编码")
&& list.contains("中文全称")
&& list.contains("中文简称")
&& list.contains("英文全称")
&& list.contains("英文简称")
&& list.contains("原文全称")
&& list.contains("原文简称")
&& list.contains("官网")
&& list.contains("所属国家")
&& list.contains("标签")
&& list.contains("简介")
&& list.contains("成立时间")
&& list.contains("是否收费(1-是;0-否)")
&& list.contains("地址")
&& list.contains("创办单位/所属单位")
&& list.contains("属性")
;
}
return false;
}
private String doExcel(MultipartFile multipartFile,String fileSuffix){
List<List<String>> excelLists = null;
try {
byte[] fileData = multipartFile.getBytes();
excelLists = ExcelExportUtil.readExcel(new ByteArrayInputStream(fileData), 1, 17);
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
String msg = "";
int i = 0;//记录成功数量
int j = 0;//记录失败数量
if(excelLists != null && excelLists.size() > 0){
//处理数据
List<ThinktankBasicInfo> infoList = new ArrayList<>();
for (List<String> list : excelLists) {
ThinktankBasicInfo thinktankBasicInfo = new ThinktankBasicInfo();
if(StringUtils.isNotEmpty(list.get(1))) thinktankBasicInfo.setCodeId(list.get(1));
if(StringUtils.isNotEmpty(list.get(2))) thinktankBasicInfo.setChineseWhole(list.get(2));
if(StringUtils.isNotEmpty(list.get(3))) thinktankBasicInfo.setChineseSimple(list.get(3));
if(StringUtils.isNotEmpty(list.get(4))) thinktankBasicInfo.setEnglishWhole(list.get(4));
if(StringUtils.isNotEmpty(list.get(5))) thinktankBasicInfo.setEnglishSimple(list.get(5));
if(StringUtils.isNotEmpty(list.get(6))) thinktankBasicInfo.setOriginalWhole(list.get(6));
if(StringUtils.isNotEmpty(list.get(7))) thinktankBasicInfo.setOriginalSimple(list.get(7));
if(StringUtils.isNotEmpty(list.get(8))) thinktankBasicInfo.setOfficialWebsite(list.get(8));
if(StringUtils.isNotEmpty(list.get(9))) thinktankBasicInfo.setBelongCountry(list.get(9));
if(StringUtils.isNotEmpty(list.get(10))) thinktankBasicInfo.setTagName(list.get(10));
if(StringUtils.isNotEmpty(list.get(11))) thinktankBasicInfo.setBiographicalNotes(list.get(11));
if(StringUtils.isNotEmpty(list.get(12))) thinktankBasicInfo.setEstablishTime(list.get(12));
//是否收费
if(StringUtils.isNotEmpty(list.get(13))){
String chargeStr = list.get(13);
try {
Integer charge = Integer.valueOf(chargeStr);
thinktankBasicInfo.setCharge(charge);
} catch (Exception e) {
thinktankBasicInfo.setCharge(-1);
log.error("是否收费转换失败:{},{}",list.get(1),list.get(13));
}
}
if(StringUtils.isNotEmpty(list.get(14))) thinktankBasicInfo.setAddress(list.get(14));
if(StringUtils.isNotEmpty(list.get(15))) thinktankBasicInfo.setBelongUnit(list.get(15));
if(StringUtils.isNotEmpty(list.get(15))) thinktankBasicInfo.setAttribute(list.get(16));
infoList.add(thinktankBasicInfo);
}
//国家列表
List<ThinktankCategoryStructure> listCategoryStructure = leaderCategoryService.list();
Map<String, String> mapCategoryStructure = new HashMap<>();
for (ThinktankCategoryStructure thinktankCategoryStructure : listCategoryStructure) {
mapCategoryStructure.put(thinktankCategoryStructure.getTypeName(),thinktankCategoryStructure.getId());
}
//标签列表
Map<String, String> mapTag = new HashMap<>();//标签名称列表
Result result = thinktankTagService.getTagList(null,null);
List<SysLabelVo> list = (List<SysLabelVo>) result.getResult();
for (SysLabelVo labelVo : list) {
mapTag.put(labelVo.getName(),labelVo.getId());
}
StringBuffer sb = new StringBuffer();
for (ThinktankBasicInfo thinktankBasicInfo : infoList) {
boolean b = true;
//id
String codeId = thinktankBasicInfo.getCodeId();
LambdaQueryWrapper<ThinktankBasicInfo> lambdaQuery = Wrappers.lambdaQuery();
lambdaQuery.eq(ThinktankBasicInfo::getCodeId,codeId);
List<ThinktankBasicInfo> listBasicInfo = thinktankBasicInfoMapper.selectList(lambdaQuery);
if(listBasicInfo.size() > 0){
thinktankBasicInfo.setId(listBasicInfo.get(0).getId());
} else {
thinktankBasicInfo.setId(Long.toString(generatorIdService.getOrderId()));
}
//国家
String belongCountry = thinktankBasicInfo.getBelongCountry();
String belongCountryId = mapCategoryStructure.get(belongCountry);
if(StringUtils.isEmpty(belongCountryId)){
b = false;
sb.append("智库机构编码为'" + codeId + "'的国家’" + belongCountry +"‘数据库没有,导入失败;\n");
} else {
thinktankBasicInfo.setBelongCountryId(belongCountryId);
}
//标签
String tagName = thinktankBasicInfo.getTagName();
if(tagName != null && tagName.length() > 0){
String[] tagNameArr = tagName.split(",");
List<String> tagIdList = new ArrayList<>();
for (String s : tagNameArr) {
String tagId = mapTag.get(s);
if(StringUtils.isEmpty(tagId)){
b = false;
sb.append("智库机构编码为'" + codeId + "'的标签'" + s +"'数据库没有,导入失败;\n");
} else {
tagIdList.add(tagId);
}
}
String tagId = String.join(",", tagIdList);
thinktankBasicInfo.setTagId(tagId);
}
//所属单位
String belongUnit = thinktankBasicInfo.getBelongUnit();
List<SysBaseEnterprise> listEnter = enterpriseService.getListByName(belongUnit);
if(listEnter.size() > 0){
SysBaseEnterprise enter = listEnter.get(0);
String belongUnitCode = enter.getSocialCreditCode();
thinktankBasicInfo.setBelongUnitCode(belongUnitCode);
} else {
b = false;
sb.append("智库机构编码为'" + codeId + "'的创办单位/所属单位'" + belongUnit +"'数据库没有,导入失败;\n");
}
//成立时间
String establishTime = thinktankBasicInfo.getEstablishTime();
if(!DateUtil.isDate(establishTime)){
b = false;
sb.append("智库机构编码为'" + codeId + "'的成立时间'" + belongUnit +"'格式错误,导入失败;\n");
}
if(b){
this.saveOrUpdate(thinktankBasicInfo);
i++;
} else {
j++;
}
}
sb.append("请重新修改后再次上传。");
msg = "导入完成!\n"
+ "导入成功数量:" + i + "\n"
+ "导入失败数量:" + j + "\n"
+ "其中:\n"
+sb.toString();
}
if(j > 0){
return msg;
}
return "true";
}
@Override
public byte[] batchExport(ThinktankBasicInfoListVo thinktankBasicInfoListVo, HttpServletRequest request, HttpServletResponse response) {
List<ThinktankBasicInfoExportVo> list = this.getExportList(thinktankBasicInfoListVo);
log.info("{}",list.size());
int i = 1;
for (ThinktankBasicInfoExportVo thinktankBasicInfoVo : list) {
thinktankBasicInfoVo.setInfoSourceId(String.valueOf(i++));
}
try {
ExcelWriter writer = ExcelUtil.getWriter();
writer.addHeaderAlias("infoSourceId", "序号");
writer.addHeaderAlias("id", "智库机构ID");
writer.addHeaderAlias("codeId", "智库机构编码");
writer.addHeaderAlias("chineseWhole", "中文全称");
writer.addHeaderAlias("chineseSimple", "中文简称");
writer.addHeaderAlias("englishWhole", "英文全称");
writer.addHeaderAlias("englishSimple", "英文简称");
writer.addHeaderAlias("originalWhole", "原文全称");
writer.addHeaderAlias("originalSimple", "原文简称");
writer.addHeaderAlias("officialWebsite", "官网");
writer.addHeaderAlias("belongCountry", "所属国家");
writer.addHeaderAlias("tagName", "标签");
writer.addHeaderAlias("biographicalNotes", "简介");
writer.addHeaderAlias("establishTime", "成立时间");
writer.addHeaderAlias("charge", "是否收费(1-是;0-否)");
writer.addHeaderAlias("address", "地址");
writer.addHeaderAlias("belongUnit", "创办单位/所属单位");
writer.addHeaderAlias("collectionCount", "信息采集数量");
writer.addHeaderAlias("infoSourceCount", "关联信息源数量");
writer.addHeaderAlias("infoSourceCode", "关联信息源编码");
writer.addHeaderAlias("webSiteName", "关联信息源名称");
writer.addHeaderAlias("siteName", "栏目名称");
writer.addHeaderAlias("siteUri", "网址");
writer.addHeaderAlias("count", "信息源采集数量");
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
// 一次性写出内容,使用默认样式,强制输出标题
writer.write(list, true);
//out为OutputStream,需要写出到的目标流
writer.flush(outputStream);
// 关闭writer,释放内存
writer.close();
return outputStream.toByteArray();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public List<ThinktankBasicInfoExportVo> getExportList(ThinktankBasicInfoListVo thinktankBasicInfoListVo) {
//查询列表
List<ThinktankBasicInfoExportVo> list = thinktankBasicInfoMapper.getExportList(thinktankBasicInfoListVo);
if(list.size() == 0){
return list;
}
//信息源
List<String> groupIds = new ArrayList<>();
for (ThinktankBasicInfoExportVo thinktankBasicInfoVo : list) {
groupIds.add(thinktankBasicInfoVo.getId());
}
List<InfoSourceGroupMap> infoSourceGroupMapList = infoSourceGroupMapService.getSourceGroupMap(groupIds);
List<InfoSourceGroupCountVo> countVoList = new ArrayList<>();
List<String> sidList = new ArrayList<>();
for (InfoSourceGroupMap infoSourceGroupMap : infoSourceGroupMapList) {
InfoSourceGroupCountVo infoSourceGroupCountVo = new InfoSourceGroupCountVo();
BeanUtils.copyProperties(infoSourceGroupMap, infoSourceGroupCountVo);
countVoList.add(infoSourceGroupCountVo);
sidList.add(infoSourceGroupMap.getSourceId());
}
//查询es
BoolQueryBuilder boolQuerylist = QueryBuilders.boolQuery();
boolQuerylist.must(QueryBuilders.termsQuery("sid",sidList));
Map<String, Long> mapGroup = null;
try {
mapGroup = esUtil.groupBy("basedata", "sid", boolQuerylist, 100);
} catch (IOException e) {
log.error("ES查询失败");
e.printStackTrace();
}
if(mapGroup != null && mapGroup.size() > 0){
for (InfoSourceGroupCountVo infoSourceGroupCountVo : countVoList) {
String sourceId = infoSourceGroupCountVo.getSourceId();
Long countInfo = mapGroup.get(sourceId);
if(countInfo == null){
countInfo = 0L;
}
infoSourceGroupCountVo.setInfoCount(Math.toIntExact(countInfo));
}
}
//统计关联信息源数量
Map<String, List<InfoSourceGroupCountVo>> studentsByGrade = countVoList.stream()
.collect(Collectors.groupingBy(InfoSourceGroupCountVo::getGroupId));
for (ThinktankBasicInfoExportVo thinktankBasicInfoVo : list) {
String infoSourceId = thinktankBasicInfoVo.getInfoSourceId();
Long count = mapGroup.get(infoSourceId);
if(count == null){
thinktankBasicInfoVo.setCount(0);
} else {
thinktankBasicInfoVo.setCount(Math.toIntExact(count));
}
String id = thinktankBasicInfoVo.getId();
List<InfoSourceGroupCountVo> listVo = studentsByGrade.get(id);
if(listVo == null){
thinktankBasicInfoVo.setCollectionCount(0);
thinktankBasicInfoVo.setInfoSourceCount(0);
} else {
thinktankBasicInfoVo.setInfoSourceCount(listVo.size());
int sum = 0;
for (InfoSourceGroupCountVo infoSourceGroupCountVo : listVo) {
sum += infoSourceGroupCountVo.getInfoCount();
}
thinktankBasicInfoVo.setCollectionCount(sum);
}
}
return list;
}
}
package com.zzsn.thinktank.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzsn.thinktank.entity.LabelEntity;
import com.zzsn.thinktank.entity.SysBaseLabelType;
import com.zzsn.thinktank.entity.ThinktankTagTop;
import com.zzsn.thinktank.mapper.ThinktankTagMapper;
import com.zzsn.thinktank.mapper.ThinktankTagTopMapper;
import com.zzsn.thinktank.service.ThinktankBasicInfoService;
import com.zzsn.thinktank.service.ThinktankTagService;
import com.zzsn.thinktank.vo.Result;
import com.zzsn.thinktank.vo.SysBaseLabelTypeVo;
import com.zzsn.thinktank.vo.SysLabelVo;
import com.zzsn.thinktank.vo.ThinktankBasicInfoListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.*;
/**
* @Version 1.0
* @Author: ZhangJingKun
* @Date: 2024/3/21 11:04
* @Content:
*/
@Service
public class ThinktankTagServiceImpl extends ServiceImpl<ThinktankTagMapper, LabelEntity> implements ThinktankTagService {
@Autowired
ThinktankTagMapper thinktankTagMapper;
@Autowired
ThinktankTagTopMapper thinktankTagTopMapper;
@Autowired
ThinktankBasicInfoService thinktankBasicInfoService;
@Value("${sys_base_label_type_id}")
private String sys_base_label_type_id;
@Override
public Result<?> getTagList(String id, String name) {
if(id == null || id.length() == 0){
id = sys_base_label_type_id;
}
List<SysBaseLabelType> endNodes = getEndNodes(id);
List<String> ids = new ArrayList<>();
if (CollectionUtil.isEmpty(endNodes)){
ids.add(id);
}else {
endNodes.forEach(e->ids.add(e.getId()));
}
// List<SysLabelVo> pageList = null;
// pageList = baseMapper.queryCustomLabel(sysLabelVo, offset, pageSize);
List<SysLabelVo> pageList = thinktankTagMapper.queryCustomLabel(ids,name);
return Result.OK(pageList);
}
@Override
public Result<?> getCharacterListByTag(String tagId, Integer pageNo, Integer pageSize) {
ThinktankBasicInfoListVo thinktankBasicInfoListVo = new ThinktankBasicInfoListVo();
thinktankBasicInfoListVo.setPageNo(pageNo);
thinktankBasicInfoListVo.setPageSize(pageSize);
Integer office = pageSize * (pageNo - 1);
thinktankBasicInfoListVo.setOffset(office);
thinktankBasicInfoListVo.setTagId(tagId);
return thinktankBasicInfoService.getList(thinktankBasicInfoListVo);
}
@Override
public void addTagTop(ThinktankTagTop thinktankTagTop){
thinktankTagTopMapper.insert(thinktankTagTop);
}
@Override
public Result<?> getTopTag() {
List<ThinktankTagTop> list = thinktankTagMapper.getTopTag();
return Result.OK(list);
}
@Override
public SysBaseLabelTypeVo getTagTypeList() {
// List<SysBaseLabelTypeVo> allList = new ArrayList<>();
//SysBaseLabelTypeVo sysBaseLabelTypeVo = new SysBaseLabelTypeVo();
//sysBaseLabelTypeVo.setId("0");
// sysBaseLabelTypeVo.setLabelName("所有");
// sysBaseLabelTypeVo.setPid("0");
// sysBaseLabelTypeVo.setHasChild("1");
List<SysBaseLabelTypeVo> list = thinktankTagMapper.getTagTypeListAll();
//只获取人物服务相关的类别
List<SysBaseLabelTypeVo> treeList = getBaseLabelTreeList(list,sys_base_label_type_id);
// sysBaseLabelTypeVo.setChildren(treeList);
// allList.add(sysBaseLabelTypeVo);
// return allList;
if(treeList.size()==1)
return treeList.get(0);
return null;
}
@Override
public void addTagTop(String tagId){
ThinktankTagTop characterTagTop = thinktankTagMapper.getById(tagId);
if (characterTagTop == null){
LabelEntity labelEntity = this.getById(tagId);
ThinktankTagTop newTagTop = new ThinktankTagTop();
newTagTop.setId(tagId);
newTagTop.setName(labelEntity.getName());
newTagTop.setCountNum(1);
thinktankTagTopMapper.insert(newTagTop);
} else {
characterTagTop.setCountNum(characterTagTop.getCountNum() + 1);
thinktankTagTopMapper.updateById(characterTagTop);
}
}
@Override
public List<LabelEntity> getListByIds(String[] ids) {
LambdaQueryWrapper<LabelEntity> lambdaQuery = Wrappers.lambdaQuery();
lambdaQuery.in(LabelEntity::getId, ids);
List<LabelEntity> list = thinktankTagMapper.selectList(lambdaQuery);
return list;
}
/**
* 根据标签类别id查询所有的末端节点
* @param id
* @return
*/
public List<SysBaseLabelType> getEndNodes(String id){
List<SysBaseLabelType> list = new ArrayList<>();
//SysBaseLabelType byId = super.getById(id);
SysBaseLabelType byId = thinktankTagMapper.getSysBaseLabelTypeById(id);
if (ObjectUtil.isEmpty(byId)){
return list;
}
if ("0".equals(byId.getHasChild())){
return list;
}
return getnodes(list,id);
}
/**
* 递归查询
* @param list
* @param id
* @return
*/
private List<SysBaseLabelType> getnodes(List<SysBaseLabelType> list,String id){
//List<SysBaseLabelType> child = super.list(Wrappers.<SysBaseLabelType>lambdaQuery().eq(SysBaseLabelType::getPid, id));
List<SysBaseLabelType> child = thinktankTagMapper.getgetSysBaseLabelTypeListByPid(id);
child.forEach(e -> {
if ("0".equals(e.getHasChild())){
list.add(e);
}else {
getnodes(list,e.getId());
}
});
return list;
}
//获取树状结构
private List<SysBaseLabelTypeVo> getBaseLabelTreeList(List<SysBaseLabelTypeVo> baseLabelTypeList, String id){
List<SysBaseLabelTypeVo> topList = new ArrayList<>();
baseLabelTypeList.forEach(e->{
if (id.equals(e.getId())) {
topList.add(e);
}
});
for (SysBaseLabelTypeVo sysLabelVo : topList) {
setBaseLabelChildren(sysLabelVo, baseLabelTypeList);
}
return topList;
}
//递归获取树形结构数据
private void setBaseLabelChildren(SysBaseLabelTypeVo parent, List<SysBaseLabelTypeVo> list) {
Set<SysBaseLabelTypeVo> children = getBaseLabelChildren(list, parent.getId());
parent.setChildren(new ArrayList<>(children));
for (SysBaseLabelTypeVo sysLabelVo : children) {
setBaseLabelChildren(sysLabelVo, list);
}
}
private Set<SysBaseLabelTypeVo> getBaseLabelChildren(List<SysBaseLabelTypeVo> list, String id) {
Set<SysBaseLabelTypeVo> children = new HashSet<>();
for (SysBaseLabelTypeVo sysLabelVo : list) {
if (sysLabelVo.getPid().equals(id)) {
children.add(sysLabelVo);
}
}
return children;
}
}
package com.zzsn.thinktank.util;
import org.apache.commons.lang3.time.DateUtils;
import java.text.ParseException;
/**
* @Version 1.0
* @Author: ZhangJingKun
* @Date: 2024/4/3 11:08
* @Content: 日期处理
*/
public class DateUtil {
/**
* 支持的日期格式
*/
private static final String[] froms = {"yyyy","yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss"};
/**
* 根据支持的日期格式校验字符串是否符合格式
* @param dateStr
* @return 通过校验返回true, 未通过校验返回false
*/
public static boolean isValidDate(String dateStr){
try {
DateUtils.parseDateStrictly(dateStr, froms);
return true;
} catch (ParseException e) {
return false;
}
}
/**
* 根据支持的日期格式校验字符串是否符合格式
* @param dateStr
* @return 通过校验返回true, 未通过校验返回false ,如果待校验字符串未空,则返回true
*/
public static boolean isDate(String dateStr){
if(dateStr != null && dateStr.length() > 0){
return isValidDate(dateStr);
} else {
return true;
}
}
}
package com.zzsn.thinktank.util;
import lombok.Data;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
@ConfigurationProperties(prefix = "es1")
@Configuration
@Data
public class Elasticsearch1Config {
private String endpoint1;
private Integer endpoint1port;
private String endpoint2;
private Integer endpoint2port;
private String endpoint3;
private Integer endpoint3port;
private String username;
private String password;
@Bean
@Primary
public RestHighLevelClient elasticsearch1Client() {
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
RestClientBuilder builder = RestClient.builder(
new HttpHost(endpoint1, endpoint1port, "http"),
new HttpHost(endpoint2, endpoint2port, "http"),
new HttpHost(endpoint3, endpoint3port, "http"))
.setHttpClientConfigCallback(httpClientBuilder -> {
httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
// 设置连接超时时间和套接字超时时间
RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
requestConfigBuilder.setConnectTimeout(300000); // 连接超时时间为300秒
requestConfigBuilder.setSocketTimeout(300000); // 套接字超时时间为300秒
httpClientBuilder.setDefaultRequestConfig(requestConfigBuilder.build());
return httpClientBuilder;
});
return new RestHighLevelClient(builder);
}
// @Bean
// public RestHighLevelClient elasticsearch1Client() {
// final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
//
// credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
//
// RestClientBuilder builder = RestClient.builder(HttpHost.create(endpoints))
// .setHttpClientConfigCallback(httpClientBuilder -> {
// httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
// return httpClientBuilder;
// });
//
// return new RestHighLevelClient(builder);
// }
// @Bean
// public RestHighLevelClient elasticsearch1Client() {
// RestHighLevelClient client = new RestHighLevelClient(
// RestClient.builder(
// new HttpHost("",9200,"http"),
// new HttpHost("",9200,"http")
// )
// );
// return client;
//
// }
}
package com.zzsn.thinktank.util;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zzsn.thinktank.vo.GroupResult;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.DocWriteResponse;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.bulk.BulkItemResponse;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.support.WriteRequest;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.core.MainResponse;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.CreateIndexResponse;
import org.elasticsearch.client.indices.GetIndexRequest;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.TermQueryBuilder;
import org.elasticsearch.index.reindex.BulkByScrollResponse;
import org.elasticsearch.index.reindex.DeleteByQueryRequest;
import org.elasticsearch.index.reindex.UpdateByQueryRequest;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptType;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.Aggregations;
import org.elasticsearch.search.aggregations.BucketOrder;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
import org.elasticsearch.search.sort.SortOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.lang.reflect.Field;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
/**
* Description: es数据操作工具类
* Author: EDY
* Date: 2023/7/28
*/
@Component
@Slf4j
public class EsUtil {
/*es客户端*/
@Autowired
@Qualifier("elasticsearch1Client")
RestHighLevelClient client;
/**
* 获取节点相关信息
*
* @return
*/
public Map<String, Object> getEsInfo() {
try {
Map<String, Object> map = new HashMap<>();
//获取Es相关集群信息
MainResponse response = client.info(RequestOptions.DEFAULT);
String clusterName = response.getClusterName();
String clusterUuid = response.getClusterUuid();
String nodeName = response.getNodeName();
MainResponse.Version version = response.getVersion();
String buildDate = version.getBuildDate();
String buildFlavor = version.getBuildFlavor();
String buildHash = version.getBuildHash();
String buildType = version.getBuildType();
String luceneVersion = version.getLuceneVersion();
String minimumIndexCompatibilityVersion = version.getMinimumIndexCompatibilityVersion();
String minimumWireCompatibilityVersion = version.getMinimumWireCompatibilityVersion();
String number = version.getNumber();
map.put("clusterName", clusterName);
map.put("clusterUuid", clusterUuid);
map.put("nodeName", nodeName);
map.put("version", version);
map.put("buildDate", buildDate);
map.put("buildFlavor", buildFlavor);
map.put("buildHash", buildHash);
map.put("buildType", buildType);
map.put("luceneVersion", luceneVersion);
map.put("minimumIndexCompatibilityVersion", minimumIndexCompatibilityVersion);
map.put("minimumWireCompatibilityVersion", minimumWireCompatibilityVersion);
map.put("number", number);
return map;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
/**
* 获取低级客户端
*
* @return
*/
public RestClient getLowLevelClient() {
return client.getLowLevelClient();
}
/**
* 创建索引
*
* @param index
* @return
*/
public boolean indexCreate(String index) {
try {
if (!indexExist(index)) {
CreateIndexRequest request = new CreateIndexRequest(index);
CreateIndexResponse createIndexResponse = client.indices().create(request, RequestOptions.DEFAULT);
log.info(createIndexResponse.isAcknowledged() ? "创建索引[{}]成功" : "创建索引[{}]失败", index);
return createIndexResponse.isAcknowledged();
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
/**
* 判断索引是否存在
*
* @param indices
* @return
*/
@SneakyThrows
public boolean indexExist(String... indices) {
GetIndexRequest request = new GetIndexRequest(indices);
return client.indices().exists(request, RequestOptions.DEFAULT);
}
/**
* 删除索引
*
* @param index
* @return
*/
@SneakyThrows
public boolean deleteIndex(String index) {
DeleteIndexRequest request = new DeleteIndexRequest(index);
AcknowledgedResponse delete = client.indices().delete(request, RequestOptions.DEFAULT);
return delete.isAcknowledged();
}
/**
* 判断doc是否存在
*
* @param index
* @param id
* @return
*/
@SneakyThrows
public boolean docExists(String index, String id) {
GetRequest request = new GetRequest(index, id);
//禁用提取_source
request.fetchSourceContext(new FetchSourceContext(false));
//禁用获取存储的字段
request.storedFields("_none_");
boolean exists = client.exists(request, RequestOptions.DEFAULT);
return exists;
}
/**
* 插入数据
*
* @param index
* @param id
* @param object
* @return
*/
public String docSaveByEntity(String index, String id, Object object) {
return docSaveByJson(index, id, JSON.toJSONString(object, SerializerFeature.WriteMapNullValue));
}
public void docSaveByEntityAsync(String index, String id, Object object) {
docSaveByJsonAsync(index, id, JSON.toJSONString(object, SerializerFeature.WriteMapNullValue));
}
public String docSaveByMap(String index, String id, Map<String, Object> map) {
try {
IndexRequest request = new IndexRequest(index).id(id)
.source(map);
IndexResponse indexResponse = client.index(request, RequestOptions.DEFAULT);
return indexResponse.getId();
} catch (IOException e) {
e.printStackTrace();
}
return index;
}
/**
* 批量插入数据
*
* @param index 索引库
* @param list List<ESBaseData> 批量保存的list,根据实际需求实体集成ESBaseData
*/
public <T> void docSaveBulkany(String index, List<T> list) {
BulkRequest request = new BulkRequest();
request.timeout(TimeValue.timeValueMinutes(10));
for (int i = 0; i < list.size(); i++) {
T b = list.get(i);
String id = null;
try {
Field field = b.getClass().getDeclaredField("id");
field.setAccessible(true);
id = (String)field.get(b);
} catch (NoSuchFieldException e) {
log.info("实体没有id字段");
continue;
} catch (IllegalAccessException e) {
log.info("无权限访问id字段");
continue;
}
request.add(new IndexRequest(index).id(id).source(
JSON.toJSONString(list.get(i)), XContentType.JSON
));
}
try {
BulkResponse bulk = client.bulk(request, RequestOptions.DEFAULT);
BulkItemResponse[] bulkItemResponses = bulk.getItems();
int length = bulkItemResponses.length;
for (int i = 0; i < length; ++i) {
BulkItemResponse response = bulkItemResponses[i];
if (response.isFailed()) {
log.info("批量保存[{}]过程中,id为[{}]的保存失败,失败原因[{}]", response.getIndex(), response.getId(), response.getFailureMessage());
} else {
// log.info("批量保存[{}]过程中,id为[{}]的保存成功,状态[{}],version[{}]", response.getIndex(), response.getId(), response.status(), response.getVersion());
}
}
} catch (IOException e) {
e.printStackTrace();
log.warn("批量[{}]保存失败", index);
}
}
/**
* 批量插入数据(异步)
* @param index 索引库
* @param list List<ESBaseData> 批量保存的list,根据实际需求实体集成ESBaseData
*/
public <T> void docSaveBulkAsync(String index,List<T> list){
BulkRequest request = new BulkRequest();
request.timeout(TimeValue.timeValueMinutes(10));
for (int i = 0; i < list.size(); i++) {
T b = list.get(i);
String id = null;
try {
Field field = b.getClass().getDeclaredField("id");
field.setAccessible(true);
id = (String)field.get(b);
} catch (NoSuchFieldException e) {
log.info("实体没有id字段");
continue;
} catch (IllegalAccessException e) {
log.info("无权限访问id字段");
continue;
}
request.add(new IndexRequest(index).id(id).source(
JSON.toJSONString(list.get(i)), XContentType.JSON
));
}
client.bulkAsync(request, RequestOptions.DEFAULT, new ActionListener<BulkResponse>() {
@Override
public void onResponse(BulkResponse bulkItemResponses) {
BulkItemResponse[] bulkItems = bulkItemResponses.getItems();
int length = bulkItems.length;
for(int i = 0; i < length; ++i) {
BulkItemResponse response = bulkItems[i];
if (response.isFailed()) {//查看所有请求失败结果
log.info("批量保存[{}]过程中,id为[{}]的保存失败,失败原因[{}]",response.getIndex(),response.getId(),response.getFailureMessage());
}else{//请求成功的
log.info("批量保存[{}]过程中,id为[{}]的保存成功,状态[{}],version[{}]",response.getIndex(),response.getId(),response.status(),response.getVersion());
}
}
}
@Override
public void onFailure(Exception e) {
log.warn("批量[{}]保存失败,失败原因[{}]",index,e.getMessage());
}
});
}
/**
* 批量更新操作,根据指定的查询条件和字段信息,更新符合条件的文档的指定字段值。
* 方法名:updataBatchByQuery,表示批量更新文档的方法。
* 参数:index,指定要更新的索引名称。
* 参数:boolQuery,BoolQueryBuilder对象,表示更新文档的查询条件。
* 参数:modifyColum,表示要更新的字段名。
* 参数:modifyColumValue,表示要更新的字段值。
* 方法抛出了IOException和InterruptedException异常。
* 创建了一个UpdateByQueryRequest对象,传入了要更新的索引名称。
* 设置查询条件,使用setQuery方法,传入BoolQueryBuilder对象。
* 设置更新脚本,使用setScript方法,传入Script对象。脚本使用painless语言,通过ctx._source.字段名 = 字段值的方式来更新文档的指定字段值。
* 调用client.updateByQuery方法,传入UpdateByQueryRequest对象和默认的RequestOptions,执行批量更新操作,并返回BulkByScrollResponse对象。
* */
public void updataBatchByQuery(String index, BoolQueryBuilder boolQuery, String modifyColum, String modifyColumValue) throws IOException, InterruptedException {
UpdateByQueryRequest request = new UpdateByQueryRequest(index);
request.setQuery(boolQuery);
request.setScript(new Script(ScriptType.INLINE, "painless", "ctx._source."+modifyColum+" = '"+modifyColumValue+"'", Collections.emptyMap()));
BulkByScrollResponse response = client.updateByQuery(request, RequestOptions.DEFAULT);
long updated = response.getUpdated();
log.info("更新条数{}",updated);
}
/**
* 批量更新操作,根据指定的查询条件和多个字段的映射关系,更新符合条件的文档的多个字段的值。
* 方法名:updataMoreColumBatchByQuery,表示批量更新文档的多个字段的方法。
* 参数:index,指定要更新的索引名称。
* 参数:boolQuery,BoolQueryBuilder对象,表示更新文档的查询条件。
* 参数:modifyColum_value,表示要更新的多个字段名和对应的字段值的映射关系。
* 方法抛出了IOException和InterruptedException异常。
* 创建了一个UpdateByQueryRequest对象,传入了要更新的索引名称。
* 设置查询条件,使用setQuery方法,传入BoolQueryBuilder对象。
* 调用getIdOrCode方法,传入多个字段名和字段值的映射关系,获取更新脚本。
* 设置更新脚本,使用setScript方法,传入Script对象。脚本使用painless语言,通过ctx._source.字段名 = 字段值的方式来更新文档的多个字段的值。
* 调用client.updateByQuery方法,传入UpdateByQueryRequest对象和默认的RequestOptions,执行批量更新操作,并返回BulkByScrollResponse对象。
* Collections.emptyMap()是setScript脚本的参数,此方法没有设置其他参数,使用一个空的map
* */
public void updataMoreColumBatchByQuery(String index, BoolQueryBuilder boolQuery, Map<String,String> modifyColum_value) throws IOException, InterruptedException {
UpdateByQueryRequest request = new UpdateByQueryRequest(index);
request.setQuery(boolQuery);
request.setScript(new Script(ScriptType.INLINE, "painless", getIdOrCode(modifyColum_value), Collections.emptyMap()));
BulkByScrollResponse response = client.updateByQuery(request, RequestOptions.DEFAULT);
long updated = response.getUpdated();
log.info("更新条数{}",updated);
}
private String getIdOrCode(Map<String,String> colum_value){
StringBuffer script = new StringBuffer();
colum_value.forEach((colum,value)->{
script.append("ctx._source."+colum+" = '"+value+"';");
});
return script.toString();
}
/**
* 这段代码是一个用于获取Elasticsearch索引中某个字段的最大值的方法。
* getColumMax方法:
* 参数:index表示索引名称,boolQuery表示查询条件,colum表示要获取最大值的字段名。
* 创建一个搜索请求SearchRequest,并将index作为参数传入。
* 创建一个搜索源构建器SearchSourceBuilder,并设置其大小为0(即只返回聚合结果,不返回具体文档)。
* 如果boolQuery不为空,则将其设置为搜索源构建器的查询条件。
* 创建一个TermsAggregationBuilder聚合器,用于按照字段colum进行聚合。
* 设置聚合器的大小为1,表示只返回一个聚合结果。
* 设置聚合器的排序方式为按照聚合桶的键值降序排序。
* 将聚合器添加到搜索源构建器中。
* 将搜索源构建器设置为搜索请求的源。
* 使用client.search方法执行搜索请求,返回一个SearchResponse对象。
* 从SearchResponse中获取聚合结果Aggregations。
* 根据聚合结果中的聚合器名称"groupByColum"获取到对应的Terms聚合器。
* 从Terms聚合器中获取聚合桶codeBuckets,即按照字段colum聚合后的结果。
* 如果聚合桶不为空,则返回第一个聚合桶的键值转换为字符串;否则返回null。
* 如果执行搜索请求过程中发生异常,则打印异常堆栈并返回null。
* 该方法的作用是执行一个查询请求,按照指定字段进行聚合,并获取聚合结果中的最大值。返回的最大值是一个字符串类型。
* */
public String getColumMax(String index, BoolQueryBuilder boolQuery,String colum){
SearchRequest searchRequest = new SearchRequest(index);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.size(0);
if (ObjectUtil.isNotEmpty(boolQuery)){
searchSourceBuilder.query(boolQuery);
}
TermsAggregationBuilder aggregation = AggregationBuilders.terms("groupByColum")
.field(colum)
.size(1)
.order(BucketOrder.key(false));
searchSourceBuilder.aggregation(aggregation);
searchRequest.source(searchSourceBuilder);
try {
SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT);
Aggregations aggregations = response.getAggregations();
Terms groupCode = aggregations.get("groupByColum");
List<? extends Terms.Bucket> codeBuckets = groupCode.getBuckets();
return CollectionUtil.isNotEmpty(codeBuckets)? codeBuckets.get(0).getKeyAsString() : null;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* 根据文档id更新
* 参数:index表示索引名称,id表示文档的id,args表示要更新的字段和对应的值。
* 首先判断args是否为空,如果为空则直接返回。
* 创建一个更新请求UpdateRequest,并将index和id作为参数传入。
* 使用XContentBuilder构建要更新的内容,将args中的字段和值添加到contentBuilder中。
* 将contentBuilder设置为更新请求的内容。
* 使用client.update方法执行更新请求,返回一个UpdateResponse对象。
* 根据UpdateResponse的结果进行处理,如果更新成功,则打印日志;如果没有进行任何更改,则打印日志;如果更新失败,则打印日志。*/
public void updateById(String index,String id , Map<String,Object> args) throws IOException {
if (CollectionUtil.isEmpty(args)){
return;
}
// 执行更新请求
UpdateResponse response = client.update(createUpdateRequest(index,id,args), RequestOptions.DEFAULT);
// 处理更新的响应结果
if (response.getResult() == DocWriteResponse.Result.UPDATED) {
// log.info("{}修改操作处理成功",id);
} else if (response.getResult() == DocWriteResponse.Result.NOOP) {
// log.info("{}没有进行任何更改",id);
} else {
log.info("{}更新失败eeeeeeeeeeeeeeeeeeeeeeeee",id);
}
}
/**整体更新*/
public boolean updateById(String index, String id, JSONObject jsonStr) {
UpdateRequest request = new UpdateRequest(index, id);
//刷新策略,默认
request.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
request.setRefreshPolicy("true");
request.doc(jsonStr, XContentType.JSON);
try {
UpdateResponse response = client.update(request, RequestOptions.DEFAULT);
return response.status() == RestStatus.OK;
} catch (IOException e) {
e.printStackTrace();
log.warn("更新doc失败, _index=[{}], _id=[{}],_jsonStr=[{}]", index, id, jsonStr);
}
return false;
}
/**
* 根据id更新,批量更新
* 参数:index表示索引名称,batch表示要批量更新的文档,其中batch是一个Map,key为文档的id,value为要更新的字段和对应的值。
* 首先判断batch是否为空,如果为空则直接返回。
* 创建一个批量请求BulkRequest。
* 遍历batch中的每个文档,将每个文档的id和要更新的字段和值创建一个更新请求UpdateRequest,并将其添加到bulkRequest中。
* 使用client.bulk方法执行批量更新请求,返回一个BulkResponse对象。
* 根据BulkResponse的结果进行处理,如果有更新失败的情况,则打印日志;如果全部更新成功,则打印日志。
* */
public void bulkUpdateDocuments(String index, Map<String , Map<String,Object> > batch) throws IOException {
if(CollectionUtil.isEmpty(batch)){
return;
}
BulkRequest bulkRequest = new BulkRequest();
// 添加批量更新的请求
batch.forEach((id,args)->{
try {
bulkRequest.add(createUpdateRequest(index,id,args));
} catch (IOException e) {
log.info("添加更新请求异常");
}
});
// 添加更多的更新请求
// 执行批量更新请求
BulkResponse bulkResponse = client.bulk(bulkRequest, RequestOptions.DEFAULT);
// 处理批量更新的响应结果
if (bulkResponse.hasFailures()) {
// 处理失败的情况
log.info("批量更新失败{}",batch);
} else {
// 处理成功的情况
log.info("批量更新成功{}",batch);
}
}
/**
* 创建更新请求对象
* 参数:index表示索引名称,documentId表示文档的id,args表示要更新的字段和对应的值。
* 创建一个更新请求UpdateRequest,并将index和documentId作为参数传入。
* 使用XContentBuilder构建要更新的内容,将args中的字段和值添加到contentBuilder中。
* 将contentBuilder设置为更新请求的内容。
* 返回更新请求UpdateRequest对象。*/
private UpdateRequest createUpdateRequest(String index,String documentId, Map<String,Object> args) throws IOException {
UpdateRequest request = new UpdateRequest(index, documentId);
// 创建要更新的内容
XContentBuilder contentBuilder = XContentFactory.jsonBuilder();
contentBuilder.startObject();
args.forEach((fieldName,fieldValue) ->
{
try {
contentBuilder.field(fieldName, fieldValue);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
);
contentBuilder.endObject();
// 设置更新请求的内容
request.doc(contentBuilder);
return request;
}
/**
* 根据id删除doc
*
* @param index
* @param id
* @return
*/
public Boolean delById(String index, String id) {
try {
DeleteRequest deleteRequest = new DeleteRequest(index, id);
DeleteResponse delete = client.delete(deleteRequest, RequestOptions.DEFAULT);
if (delete.status() == RestStatus.OK) {
log.info("DELETE /{}/_doc/{}/\r\n", index, id);
return true;
}
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
public void delByIdAsync(String index, String id) {
DeleteRequest request = new DeleteRequest(index, id);
try {
client.deleteAsync(request, RequestOptions.DEFAULT, new ActionListener<DeleteResponse>() {
@Override
public void onResponse(DeleteResponse deleteResponse) {
log.info("删除doc成功, _index=[{}], _id=[{}]", index, deleteResponse.getId());
}
@Override
public void onFailure(Exception e) {
e.printStackTrace();
log.warn("删除doc失败, _index=[{}], _id=[{}]", index, id);
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 根据id批量删除
*
* */
public void delByIds(String index,List<String> ids){
if(CollectionUtil.isEmpty(ids)){
return;
}
// 创建BulkRequest对象
BulkRequest bulkRequest = new BulkRequest();
ids.forEach(e -> {
// 添加多个DeleteRequest对象
bulkRequest.add(new DeleteRequest(index, e));
});
// 执行批量请求
try {
BulkResponse bulk = client.bulk(bulkRequest, RequestOptions.DEFAULT);
// 处理批量更新的响应结果
if (bulk.hasFailures()) {
// 处理失败的情况
log.info("批量删除失败{}",ids);
} else {
// 处理成功的情况
log.info("批量删除成功{}",ids);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
/**
* 根据id批量删除,List中的字符串需要满足 索引库名称-id格式,如 subjectdatabase2024==76578897678687656785
*
* */
public void delByIds(List<String> index_id){
if(CollectionUtil.isEmpty(index_id)){
return;
}
// 创建BulkRequest对象
BulkRequest bulkRequest = new BulkRequest();
index_id.forEach(e -> {
String[] split = e.split("==");
String index = split[0];
String id = split[1];
// 添加多个DeleteRequest对象
bulkRequest.add(new DeleteRequest(index, id));
});
// 执行批量请求
try {
BulkResponse bulk = client.bulk(bulkRequest, RequestOptions.DEFAULT);
// 处理批量更新的响应结果
if (bulk.hasFailures()) {
// 处理失败的情况
log.info("批量删除失败{}",index_id);
} else {
// 处理成功的情况
log.info("批量删除成功{}",index_id);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
/**
* 根据条件删除
*
* @param index
* @param query
* @return
*/
public Long delByQuery(final String index, QueryBuilder query) {
try {
DeleteByQueryRequest request = new DeleteByQueryRequest(index);
request.setQuery(query).setRefresh(true);
BulkByScrollResponse bulkByScrollResponse = client.deleteByQuery(request, RequestOptions.DEFAULT);
return bulkByScrollResponse.getDeleted();
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
/**索引库所有数据分页查询**/
public <T> List<T> getAllPageList (String index,Integer page, Integer pagesize, Class<T> entry) throws Exception {
List<T> list = new ArrayList<>();
SearchRequest searchRequest = new SearchRequest(index);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
//创建查询对象
searchSourceBuilder.query(QueryBuilders.matchAllQuery());
//排序createDate
searchSourceBuilder.sort("publishDate", SortOrder.ASC);
searchSourceBuilder.size(pagesize);
searchSourceBuilder.from((page - 1)*pagesize);
searchRequest.source(searchSourceBuilder);
SearchResponse search = client.search(searchRequest, RequestOptions.DEFAULT);
SearchHit[] hits = search.getHits().getHits();
if (hits.length>0){
List<SearchHit> collect = Arrays.stream(hits).collect(Collectors.toList());
collect.forEach( e -> {
T t = JSON.parseObject(e.getSourceAsString(), entry);
list.add(t);
});
return list;
}
return list;
}
/**
* 根据index,id索引文件
*
* @param index
* @param id
* @return
*/
public <T> T getInfoByid(String index, String id, Class<T> entry) {
T res = null;
try {
GetRequest searchRequest = new GetRequest(index, id);
GetResponse documentFields = client.get(searchRequest, RequestOptions.DEFAULT);
res = JSON.parseObject(documentFields.getSourceAsString(), entry);
return res;
} catch (IOException e) {
log.warn("查询doc异常,index=[{}],id=[{}], ex=[{}]", index, id, e.getMessage());
}
return res;
}
/**
* 根据id查询各类资讯详情
* */
public <T> T getInfoByid1(String index, String id, Class<T> entry){
try {
SearchRequest searchRequest = new SearchRequest(index);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
TermQueryBuilder termQueryBuilder = QueryBuilders.termQuery("id", id);
searchSourceBuilder.query(termQueryBuilder);
searchRequest.source(searchSourceBuilder);
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
SearchHit[] hits = searchResponse.getHits().getHits();
T res = null;
if (hits.length>0){
res = JSON.parseObject(hits[0].getSourceAsString(), entry);
}
return res;
} catch (IOException e) {
log.info("查询异常{}",e.getMessage(),e);
return null;
}
}
/**
* 通用查询,
* */
public <T> List<T> queryList(String index, QueryBuilder queryBuilder, Class<T> entry,int size) {
List<T> list = new ArrayList<>();
try {
SearchRequest searchRequest = new SearchRequest(index);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.size(size);
searchSourceBuilder.query(queryBuilder);
searchRequest.source(searchSourceBuilder);
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
// 处理搜索结果
SearchHit[] hits = searchResponse.getHits().getHits();
if (hits.length>0){
Arrays.stream(hits).forEach(e -> {
String index1 = e.getIndex();
T t = JSON.parseObject(e.getSourceAsString(), entry);
try {
Field field = entry.getDeclaredField("index");
field.setAccessible(true);
field.set(t,index1);
} catch (Exception ex) {
log.info("设置索引名异常");
}
list.add(t);
});
}
return list;
} catch (IOException e) {
log.info("查询异常{}",e.getMessage(),e);
return list;
}
}
/**
* 通用分页查询
* */
public <T> Page<T> queryPage(String index, QueryBuilder queryBuilder, Class<T> entry, Integer pageNo, Integer pageSize) {
List<T> list = new ArrayList<>();
Page<T> pageData = new Page<>(pageNo, pageSize);
try {
SearchRequest searchRequest = new SearchRequest(index);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
//设置分页参数
searchSourceBuilder.size(pageSize);
searchSourceBuilder.from((pageNo - 1) * pageSize);
//默认最大数量是10000,设置为true后,显示准确数量
searchSourceBuilder.sort("id", SortOrder.ASC);
searchSourceBuilder.trackTotalHits(true);
searchSourceBuilder.query(queryBuilder);
searchRequest.source(searchSourceBuilder);
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
// 处理搜索结果
SearchHit[] hits = searchResponse.getHits().getHits();
if (hits.length>0){
Arrays.stream(hits).forEach(e -> {
T t = JSON.parseObject(e.getSourceAsString(), entry);
list.add(t);
});
}
pageData.setTotal(searchResponse.getHits().getTotalHits().value);
pageData.setRecords(list);
return pageData;
} catch (IOException e) {
log.info("查询异常{}",e.getMessage(),e);
return pageData;
}
}
/**
* 通用分页查询
* */
public <T> Page<T> queryPage(String index, SearchSourceBuilder searchSourceBuilder, Class<T> entry, Integer pageNo, Integer pageSize) throws IOException {
List<T> list = new ArrayList<>();
Page<T> pageData = new Page<>(pageNo, pageSize);
SearchRequest searchRequest = new SearchRequest(index);
searchSourceBuilder.size(pageSize);
searchSourceBuilder.from((pageNo - 1) * pageSize);
//默认最大数量是10000,设置为true后,显示准确数量
searchSourceBuilder.trackTotalHits(true);
searchRequest.source(searchSourceBuilder);
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
// 处理搜索结果
SearchHit[] hits = searchResponse.getHits().getHits();
if (hits.length>0){
Arrays.stream(hits).forEach(e -> {
T t = com.alibaba.fastjson.JSON.parseObject(e.getSourceAsString(), entry);
try {
Field field = entry.getDeclaredField("index");
field.setAccessible(true);
field.set(t,e.getIndex());
} catch (Exception ex) {
log.info("设置索引名异常");
}
list.add(t);
});
}
pageData.setTotal(searchResponse.getHits().getTotalHits().value);
pageData.setRecords(list);
return pageData;
}
/**
* 非聚合类查询,通用结果集封装
* */
public <T> List<T> queryPageBase(String index, Class<T> entry,SearchSourceBuilder searchSourceBuilder) throws IOException {
List<T> list = new ArrayList<>();
SearchRequest searchRequest = new SearchRequest(index);
searchRequest.source(searchSourceBuilder);
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
// 处理搜索结果
SearchHit[] hits = searchResponse.getHits().getHits();
if (hits.length>0){
Arrays.stream(hits).forEach(e -> {
T t = JSON.parseObject(e.getSourceAsString(), entry);
list.add(t);
});
}
return list;
}
/**
* es对查询数据进行分组
* */
public List<GroupResult> group(String index, String group_column) throws IOException {
// 创建 SearchRequest 请求
SearchRequest searchRequest = new SearchRequest(index);
// 创建 SearchSourceBuilder
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.size(0);
// 创建 BoolQueryBuilder
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
// 添加查询条件
boolQueryBuilder.must(QueryBuilders.matchAllQuery());
// 添加聚合操作
TermsAggregationBuilder termsAggregationBuilder = AggregationBuilders.terms("source_address").field(group_column).size(500000);
termsAggregationBuilder.subAggregation(AggregationBuilders.count("count_source_address").field(group_column));
searchSourceBuilder.aggregation(termsAggregationBuilder);
// 设置查询超时时间
searchSourceBuilder.timeout(TimeValue.timeValueSeconds(50));
// 设置查询源
searchSourceBuilder.query(boolQueryBuilder);
searchRequest.source(searchSourceBuilder);
// 执行查询请求
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
// 解析聚合结果
Terms sidTerms = searchResponse.getAggregations().get("source_address");
List<GroupResult> res = new ArrayList<>();
for (Terms.Bucket sidBucket : sidTerms.getBuckets()) {
String source_address = sidBucket.getKeyAsString();
long count = sidBucket.getDocCount();
if (count>1){
res.add(new GroupResult().setName(source_address).setCount(count));
}
}
return res;
}
/**
* 根据查询条件对某列进行分组
* */
public Map<String,Long> groupBy( String index, String group_column,QueryBuilder queryBuilder,int size) throws IOException {
// 创建 SearchRequest 请求
SearchRequest searchRequest = new SearchRequest(index);
// 创建 SearchSourceBuilder
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.size(0);
// 添加聚合操作
TermsAggregationBuilder termsAggregationBuilder = AggregationBuilders.terms("group_column").field(group_column).size(size);
termsAggregationBuilder.subAggregation(AggregationBuilders.count("group_column").field(group_column));
searchSourceBuilder.aggregation(termsAggregationBuilder);
// 设置查询超时时间
searchSourceBuilder.timeout(TimeValue.timeValueSeconds(50));
// 设置查询源
searchSourceBuilder.query(queryBuilder);
searchRequest.source(searchSourceBuilder);
// 执行查询请求
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
// 解析聚合结果
Terms sidTerms = searchResponse.getAggregations().get("group_column");
Map<String,Long> map = new HashMap<>();
for (Terms.Bucket sidBucket : sidTerms.getBuckets()) {
String source_address = sidBucket.getKeyAsString();
long count = sidBucket.getDocCount();
map.put(source_address, count);
}
return map;
}
/**
* 根据查询条件对某列进行分组
* */
public List<GroupResult> groupByDep( String index, String group_column,QueryBuilder queryBuilder,int size) throws IOException {
// 创建 SearchRequest 请求
SearchRequest searchRequest = new SearchRequest(index);
// 创建 SearchSourceBuilder
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.size(0);
// 添加聚合操作
TermsAggregationBuilder termsAggregationBuilder = AggregationBuilders.terms("group_column").field(group_column).size(size);
termsAggregationBuilder.subAggregation(AggregationBuilders.count("group_column").field(group_column));
searchSourceBuilder.aggregation(termsAggregationBuilder);
// 设置查询超时时间
searchSourceBuilder.timeout(TimeValue.timeValueSeconds(50));
// 设置查询源
searchSourceBuilder.query(queryBuilder);
searchRequest.source(searchSourceBuilder);
// 执行查询请求
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
// 解析聚合结果
Terms sidTerms = searchResponse.getAggregations().get("group_column");
List<GroupResult> res = new ArrayList<>();
for (Terms.Bucket sidBucket : sidTerms.getBuckets()) {
String source_address = sidBucket.getKeyAsString();
long count = sidBucket.getDocCount();
if (count>1) {
res.add(new GroupResult().setName(source_address).setCount(count));
}
}
return res;
}
/**
* 保存json
*
* @param index
* @param id
* @param jsonStr
* @return
*/
public String docSaveByJson(String index, String id, String jsonStr) {
try {
IndexRequest request = new IndexRequest(index)
.id(id)
.source(jsonStr, XContentType.JSON);
IndexResponse indexResponse = client.index(request, RequestOptions.DEFAULT);
return indexResponse.getId();
} catch (IOException e) {
log.warn("同步保存doc失败, _index=[{}], _id=[{}]", index, id);
}
return index;
}
/**
* 异步创建doc
*
* @param index
* @param id
* @param jsonStr
* @return
*/
public void docSaveByJsonAsync(String index, String id, String jsonStr) {
IndexRequest request = new IndexRequest(index);
request.id(id);
request.source(jsonStr, XContentType.JSON);
client.indexAsync(request, RequestOptions.DEFAULT, new ActionListener<IndexResponse>() {
@Override
public void onResponse(IndexResponse indexResponse) {
log.info("异步保存doc, _index=[{}], _id=[{}]成功, _version=[{}], _result=[{}]", index, indexResponse.getId(), indexResponse.getVersion(), indexResponse.getResult());
}
@Override
public void onFailure(Exception e) {
e.printStackTrace();
log.warn("异步保存失败,尝试同步方式保存doc, ex=[{}]", e.getMessage());
try {
IndexResponse response = client.index(request, RequestOptions.DEFAULT);
DocWriteResponse.Result result = response.getResult();
if (!(result == DocWriteResponse.Result.UPDATED || result == DocWriteResponse.Result.CREATED)) {
log.warn("同步保存doc失败,_index=[{}], _id=[{}], _body=[{}]", index, id, jsonStr);
}
} catch (IOException io) {
io.printStackTrace();
}
}
});
}
/**
* 根据索引名称获取带有当前年的索引名称 subjectdatabase --> subjectdatabase_2023
* @param index
* @return
*/
public String getIndexYear(String index){
return index + "_" + LocalDateTime.now().getYear();
}
/**
* 根据id更新,批量更新
* 参数:index表示索引名称,batch表示要批量更新的文档,其中batch是一个Map,key为文档的id,value为要更新的字段和对应的值。
* 首先判断batch是否为空,如果为空则直接返回。
* 创建一个批量请求BulkRequest。
* 遍历batch中的每个文档,将每个文档的id和要更新的字段和值创建一个更新请求UpdateRequest,并将其添加到bulkRequest中。
* 使用client.bulk方法执行批量更新请求,返回一个BulkResponse对象。
* 根据BulkResponse的结果进行处理,如果有更新失败的情况,则打印日志;如果全部更新成功,则打印日志。
* */
public void bulkUpdateDocuments(Map<String , Map<String,Object> > batch) throws IOException {
if(CollectionUtil.isEmpty(batch)){
return;
}
BulkRequest bulkRequest = new BulkRequest();
// 添加批量更新的请求
batch.forEach((idIndex,args)->{
String[] split = idIndex.split("-");
String id = split[0];
String index = split[1];
try {
bulkRequest.add(createUpdateRequest(index,id,args));
} catch (IOException e) {
log.info("添加更新请求异常");
}
});
// 添加更多的更新请求
// 执行批量更新请求
BulkResponse bulkResponse = client.bulk(bulkRequest, RequestOptions.DEFAULT);
// 处理批量更新的响应结果
if (bulkResponse.hasFailures()) {
// 处理失败的情况
log.info("批量更新失败{}",batch);
} else {
// 处理成功的情况
log.info("批量更新成功{}",batch);
}
}
public boolean docUpdateById(String index, String id, String jsonStr) {
UpdateRequest request = new UpdateRequest(index, id);
//刷新策略,默认
request.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
request.setRefreshPolicy("true");
request.doc(jsonStr, XContentType.JSON);
try {
UpdateResponse response = client.update(request, RequestOptions.DEFAULT);
return response.status() == RestStatus.OK;
} catch (IOException e) {
e.printStackTrace();
log.warn("更新doc失败, _index=[{}], _id=[{}],_jsonStr=[{}]", index, id, jsonStr);
}
return false;
}
public boolean docEditByEntity(String index, String id, Object object) {
return docUpdateById(index, id, JSON.toJSONString(object));
}
}
package com.zzsn.thinktank.util;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.support.ExcelTypeEnum;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLEncoder;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
@Slf4j
public class ExcelExportUtil {
private static final String XLS = "xls";
private static final String XLSX = "xlsx";
private static final String SPLIT = ".";
/**
* 读取excel数据
*
* @param firstRow 第一行有用数据(0表示第一行)
* @param columnNum 有用数据的总列数
* @return java.util.List<java.util.List < java.lang.String>>
*/
public static List<List<String>> readExcel(InputStream inputStream, Integer firstRow, Integer columnNum) throws Exception {
List<List<String>> dataList = new ArrayList<>();
//获取整个excel
XSSFWorkbook hb = new XSSFWorkbook(inputStream);
int sheets = hb.getNumberOfSheets();
for (int i = 0; i < sheets; i++) {
XSSFSheet sheet = hb.getSheetAt(i);
//第一行
int firstRowNum = sheet.getFirstRowNum();
//最后一行
int lastRowNum = sheet.getPhysicalNumberOfRows();
for (int j = firstRowNum + firstRow; j < lastRowNum; j++) {
//获取行
XSSFRow row = sheet.getRow(j);
if (row != null) {
List<String> list = new ArrayList<>();
for (int m = 0; m < columnNum; m++) {
String data = ExcelExportUtil.getValue(row.getCell(m)).trim();
list.add(data);
}
dataList.add(list);
}
}
}
return dataList;
}
public static String getValue(XSSFCell xssfCell) {
if (xssfCell == null || xssfCell.toString().trim().equals("")) {
return "";
}
int cellType = xssfCell.getCellType();
if (cellType == HSSFCell.CELL_TYPE_NUMERIC) {
if (HSSFDateUtil.isCellDateFormatted(xssfCell)) {
return TimeUtil.getDateString(xssfCell.getDateCellValue());
} else {
//防止数字变成科学计数法的形式
DecimalFormat df = new DecimalFormat("0");
return df.format(xssfCell.getNumericCellValue());
}
} else {
return xssfCell.getStringCellValue();
}
}
public static File getFileDir() {
// 构建上传文件的存放 "文件夹" 路径
String fileDirPath = new String("src/main/resources/static/uploadFiles" );
File fileDir = new File(fileDirPath);
if (!fileDir.exists()) {
// 递归生成文件夹
fileDir.mkdirs();
}
return fileDir;
}
/**
* 导出
* @param data
* @param sheetName
* @param filePath
* @param clazz
* @throws Exception
*/
public static Boolean writeExcelFront(List data, String sheetName, String filePath, Class clazz) throws Exception {
//表头样式
System.out.println("开始写入");
WriteCellStyle headWriteCellStyle = new WriteCellStyle();
//设置表头居中对齐
headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
//内容样式
WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
//设置内容靠左对齐
contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.LEFT);
HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
int total = data.size();//总数
int max = 50000;//每sheet页允许最大数
int avg = total / max;//sheet页个数
ExcelWriter excelWriter= EasyExcel.write(filePath, clazz).excelType(ExcelTypeEnum.XLSX).registerWriteHandler(horizontalCellStyleStrategy).build();
try{
for (int j = 0; j < avg + 1; j++) {
String sheetnames=sheetName;
int num = j * max;
List dataList1 = new ArrayList<>();
if (StringUtils.isNotBlank(sheetnames)) {
sheetnames = sheetnames + (j + 1);
} else {
sheetnames = j + "";
}
for (int n = num; n < total; n++) {//n即为每个sheet页应该开始的数
if(n>=num+50000){
break;
}
dataList1.add(data.get(n));//从总的list数据里面取出该处于哪个sheet页的数据,然后加进exportList,exportList即为当前sheet页应该有的数据
}
WriteSheet writeSheet = EasyExcel.writerSheet(j, sheetnames).build();
excelWriter.write(dataList1,writeSheet);
}
}finally {
// 千万别忘记finish 会帮忙关闭流
if (excelWriter != null) {
excelWriter.finish();
}
}
System.out.println("写入完成");
return true;
}
public static void download(HttpServletResponse response, String filePath, boolean delete) throws UnsupportedEncodingException {
File file = new File(filePath);
if (file.exists()) {
response.setHeader("Content-Disposition", "attachment;fileName=" + URLEncoder.encode(file.getName(), "utf8"));
//加上设置大小 下载下来的excel文件才不会在打开前提示修复
response.addHeader("Content-Length", String.valueOf(file.length()));
byte[] buffer = new byte[1024];
//输出流
OutputStream os = null;
FileInputStream fis = null;
BufferedInputStream bis = null;
try {
fis = new FileInputStream(file);
bis = new BufferedInputStream(fis);
os = response.getOutputStream();
int i = bis.read(buffer);
while (i != -1) {
os.write(buffer);
os.flush();
i = bis.read(buffer);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (os != null) {
os.close();
}
if (fis != null) {
fis.close();
}
if (bis != null) {
bis.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
if (delete) {
//文件下载结束后,删除上传到项目的文件
file.delete();
}
}
}
/**
* 获取Excel表头信息
* @param workbook
* @return
*/
public static List<String> getSheetTitles(Workbook workbook) {
// 拿第一个sheet表
Sheet sheet = workbook.getSheetAt(0);
// 校验sheet是否合法
if (Objects.isNull(sheet)) {
return null;
}
// 获取第一行数据(假如第一行就是列名)
Row sheetTitleRow = sheet.getRow(sheet.getFirstRowNum());
// 取出最后一列
short lastCellNum = sheetTitleRow.getLastCellNum();
List<String> sheetTitleList = new LinkedList<>();
for (int i = 0; i < lastCellNum; i++) {
// 取出每一列的名
String cellValue = sheetTitleRow.getCell(i).getStringCellValue();
sheetTitleList.add(cellValue);
}
return sheetTitleList;
}
/**
* 获取Excel表信息
* @param file
* @return
*/
public static Workbook getWorkbook(MultipartFile file) {
Workbook workbook = null;
try {
// 获取Excel后缀名
String fileName = file.getOriginalFilename();
if (StringUtils.isEmpty(fileName) || fileName.lastIndexOf(SPLIT) < 0) {
log.warn("解析Excel失败,因为获取到的Excel文件名非法!");
return null;
}
String fileType = fileName.substring(fileName.lastIndexOf(SPLIT) + 1);
// 获取Excel工作簿
if (fileType.equalsIgnoreCase(XLS)) {
workbook = new HSSFWorkbook(file.getInputStream());
} else if (fileType.equalsIgnoreCase(XLSX)) {
workbook = new XSSFWorkbook(file.getInputStream());
}
} catch (IOException e) {
e.printStackTrace();
}
return workbook;
}
//多个sheet
public static void exportExcelData(XSSFWorkbook workbook, int sheetNum, List<String> keyList, List<List<String>> rows, String sheetName) {
Sheet sheet = workbook.createSheet();
//多个sheet
workbook.setSheetName(sheetNum,sheetName);
sheet.setDefaultColumnWidth(20);
sheet.setDefaultRowHeight((short) 400);
XSSFCellStyle titleStyle = ExcelExportUtil.getHeaderStyle(workbook);
XSSFCellStyle rowStrStyle = ExcelExportUtil.getRowStrStyle(workbook);
// 产生表格标题行
Row row = sheet.createRow(0);
row.setHeight((short) 400);
Cell cell;
List<String> colData = new ArrayList<>(keyList);
for (int i = 0; i < colData.size(); i++) {
cell = row.createCell(i, CellType.STRING);
cell.setCellStyle(titleStyle);
cell.setCellValue(new XSSFRichTextString(colData.get(i)));
}
// 数据行
for (int m = 0; m < rows.size(); m++) {
List<String> rowData = rows.get(m);
row = sheet.createRow(m + 1);
row.setHeight((short) 400);
int i=0;
for (String rowDatum : rowData) {
createCell(rowStrStyle, row, i, rowDatum);
i++;
}
}
}
private static void createCell(XSSFCellStyle rowStrStyle, Row row, int index , String value){
Cell cell = row.createCell(index, CellType.STRING);
cell.setCellStyle(rowStrStyle);
cell.setCellValue(value);
}
/**
* 获取标题栏样式
*
* @param workbook
* @return
*/
private static XSSFCellStyle getHeaderStyle(XSSFWorkbook workbook) {
// 生成一个样式
XSSFCellStyle style = workbook.createCellStyle();
// 设置这些样式
style.setFillForegroundColor(IndexedColors.SKY_BLUE.index);
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
style.setBorderBottom(BorderStyle.THIN);
style.setBorderLeft(BorderStyle.THIN);
style.setBorderRight(BorderStyle.THIN);
style.setBorderTop(BorderStyle.THIN);
style.setAlignment(HorizontalAlignment.CENTER);
// style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00"));
// 生成一个字体
XSSFFont font = workbook.createFont();
font.setColor(IndexedColors.BLACK.index);
font.setFontHeightInPoints((short) 9);
// 把字体应用到当前的样式
style.setFont(font);
return style;
}
/**
* 获取字符串型内容栏样式
*
* @return
*/
private static XSSFCellStyle getRowStrStyle(XSSFWorkbook workbook) {
// 生成一个样式
XSSFCellStyle style = workbook.createCellStyle();
// 设置这些样式
style.setBorderBottom(BorderStyle.THIN);
style.setBorderLeft(BorderStyle.THIN);
style.setBorderRight(BorderStyle.THIN);
style.setBorderTop(BorderStyle.THIN);
style.setAlignment(HorizontalAlignment.CENTER);
// 生成一个字体
XSSFFont font = workbook.createFont();
font.setColor(IndexedColors.BLACK.index);
font.setFontHeightInPoints((short) 9);
font.setBold(true);
// 把字体应用到当前的样式
style.setFont(font);
return style;
}
}
package com.zzsn.thinktank.util;
import org.w3c.dom.*;
import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.*;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
public class PageBuilderParser {
public String parserStr(Object doc, String path)
throws XPathExpressionException {
String ret = "";
Object obj = parser(doc, path);
if (obj == null) {
return ret;
}
if (obj instanceof NodeList) {
StringBuffer buffer = new StringBuffer();
NodeList nodeList = (NodeList) obj;
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
String txt = getNodeText(node);
buffer.append(txt);
if (i != nodeList.getLength() - 1) {
buffer.append(" ");
}
}
ret = buffer.toString();
} else if (obj instanceof Node) {
String s = getNodeText((Node) obj);
ret = s;
} else if (obj instanceof String) {
ret = (String) obj;
} else if (obj instanceof Number) {
Number number = (Number) obj;
ret = number.toString();
} else if (obj instanceof Boolean) {
Boolean number = (Boolean) obj;
ret = number.toString();
}
ret = StringUtil.trimWhiteSpace(ret);
ret = StringUtil.normalizeHtmlTransf(ret);
return ret;
}
public Object parser(Object doc, String path) throws XPathExpressionException {
if (path == null || path.trim().length() == 0) {
return null;
}
XPathFactory factory = XPathFactory.newInstance();
XPath xPath = factory.newXPath();
XPathExpression expression = xPath.compile(path);
Object object = null;
try {
object = expression.evaluate(doc, XPathConstants.NODESET);
return (NodeList) object;
} catch (XPathExpressionException e) {
try {
object = expression.evaluate(doc, XPathConstants.NODE);
return (Node) object;
} catch (XPathExpressionException e1) {
try {
object = expression.evaluate(doc, XPathConstants.STRING);
return (String) object;
} catch (XPathExpressionException e2) {
try {
object = expression.evaluate(doc, XPathConstants.NUMBER);
return (Number) object;
} catch (XPathExpressionException e3) {
try {
object = expression.evaluate(doc, XPathConstants.BOOLEAN);
return (Boolean) object;
} catch (XPathExpressionException e4) {
// TODO Auto-generated catch block
e4.printStackTrace();
}
}
}
}
}
return object;
}
public String getNodeText(Node node) {
String s = "";
if (node.getNodeType() == Node.TEXT_NODE) {
s = node.getTextContent();
} else if (node.getNodeType() == Node.ELEMENT_NODE) {
s = getNodeTextRec((Element) node);
} else if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
s = ((Attr) node).getValue();
} else if (node.getNodeType() == Node.CDATA_SECTION_NODE) {
s = node.getNodeValue();
}
s = StringUtil.trimWhiteSpace(s);
s = StringUtil.normalizeHtmlTransf(s);
return s;
}
private String getNodeTextRec(Element elem) {
StringBuffer buffer = new StringBuffer();
NodeList nodeList = elem.getChildNodes();
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
if (node.getNodeType() == Node.TEXT_NODE) {
String txt = node.getTextContent();
buffer.append(StringUtil.trimWhiteSpace(txt));
} else if (node.getNodeType() == Node.ELEMENT_NODE) {
buffer.append(getNodeTextRec((Element) node));
}
}
return buffer.toString();
}
public static Document xmlGetDocument(String pageBody)
throws ParserConfigurationException, SAXException, IOException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
InputStream is = new ByteArrayInputStream(pageBody.getBytes());
Document document = builder.parse(is);
return document;
}
}
package com.zzsn.thinktank.util;
import org.springframework.util.StringUtils;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class StringUtil {
public static boolean convertBoolean(String s, boolean b) {
if (s == null) {
return b;
}
if (s.equals("0")) {
return false;
}
if (s.equals("1")) {
return true;
}
return b;
}
public static String convertBooleanToString(boolean b) {
String s = b ? "1" : "0";
return s;
}
public static String trimWhiteSpace(String str) {
String s = replaceBlank(str);
String ret = s.trim();
return ret;
}
public static String replaceBlank(String str) {
/* String dest = "";
if (str != null) {
Pattern p = Pattern.compile("\\s*|\t|\r|\n");su
Matcher m = p.matcher(str);
dest = m.replaceAll("");
}*/
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
boolean bspace = Character.isWhitespace(c);
if (bspace) {
c = ' ';
}
buffer.append(c);
}
return buffer.toString();
}
//获取分隔符[和]之间的子串,如aa[abc]bbb->abc
public static List<String> getSubStrs(String str, String start, String end) {
List<String> resultStrs = new ArrayList<String>();
if (str == null || str.trim().length() == 0) {
return resultStrs;
}
String ptnstr = String.format("%s([^%s%s]+)%s", start, start, end, end);
// String ptnstr1 = "\\[([^\\[\\]]+)\\]";
Pattern pattern = Pattern.compile(ptnstr);
Matcher matcher = pattern.matcher(str);
while (matcher.find()) {
String substr = matcher.group(1);
resultStrs.add(substr);
}
return resultStrs;
}
//fromStr:aaa123bb, origStr:aaa[xxx]bb, replaceStr:[xxx]. return:123
public static String getHomologousWord(String replaceStr,
String origStr, String fromStr) {
String retStr = null;
int pos = origStr.indexOf(replaceStr);
if (pos == -1) {
return retStr;
}
String start = origStr.substring(0, pos);
String end = origStr.substring(pos + replaceStr.length());
if (start.length() > 0 && !fromStr.startsWith(start)) {
return retStr;
}
if (end.length() > 0 && !fromStr.endsWith(end)) {
return retStr;
}
retStr = fromStr.substring(start.length(),
fromStr.length() - end.length());
return retStr;
}
public static String trimBeginningBracket(String s) {
String ret = s;
if (s.length() == 0) {
return s;
}
Map<Character, Character> braketPeers
= new HashMap<Character, Character>();
braketPeers.put('【', '】');
braketPeers.put('[', ']');
braketPeers.put('[', ']');
braketPeers.put('(', ')');
braketPeers.put('(', ')');
braketPeers.put('〔', '〕');
String searchStr = s;
while (searchStr.length() > 0) {
char beginc = searchStr.charAt(0);
Character value = braketPeers.get(beginc);
if (value == null) {
break;
}
int endPos = -1;
for (int i = 1; i < searchStr.length(); i++) {
if (searchStr.charAt(i) == value) {
endPos = i;
break;
}
}
if (endPos >= 0) {
ret = searchStr.substring(endPos + 1);
searchStr = ret;
} else {
break;
}
}
return ret;
}
public static String trimMiddleBracket(String s) {
String ret = s;
if (s.length() == 0) {
return s;
}
Map<Character, Character> braketPeers = new HashMap<Character, Character>();
String[] brakets = {"】", "]", "]", ")", ")", "〕"};
braketPeers.put('【', '】');
braketPeers.put('[', ']');
braketPeers.put('[', ']');
braketPeers.put('(', ')');
braketPeers.put('(', ')');
braketPeers.put('〔', '〕');
String searchStr = s;
int index = 0;
while (searchStr.length() > 0) {
int startPos = -1;
Character value = null;
for (int i = index; i < searchStr.length(); i++) {
boolean findLeftBraket = false;
value = searchStr.charAt(i);
for (Character key : braketPeers.keySet()) {
if (value.equals(key)) {
startPos = i;
findLeftBraket = true;
break;
}
}
if (findLeftBraket) {
break;
}
}
int endPos = -1;
for (int i = startPos + 1; i < searchStr.length(); i++) {
if (null != braketPeers.get(value) && searchStr.charAt(i) == braketPeers.get(value)) {
endPos = i;
break;
}
}
if (endPos >= startPos) {
if (startPos >= 0) {
searchStr = searchStr.substring(0, startPos) + searchStr.substring(endPos + 1, searchStr.length());
}
} else {
searchStr = searchStr.replace(value.toString(), "");
index = startPos;
}
if (startPos < 0) {
ret = searchStr;
break;
}
}
for (String bs : brakets) {
ret = ret.replace(bs.toString(), "");
}
return ret;
}
public static String trimEnddingBracket(String s) {
String ret = s;
if (s.length() == 0) {
return s;
}
Map<Character, Character> braketPeers
= new HashMap<Character, Character>();
braketPeers.put('】', '【');
braketPeers.put(']', '[');
braketPeers.put(')', '(');
braketPeers.put(')', '(');
braketPeers.put('〕', '〔');
int endPos = s.length() - 1;
String searchStr = s;
while (endPos >= 0) {
char endc = searchStr.charAt(endPos);
Character value = braketPeers.get(endc);
if (value == null) {
break;
}
int startPos = -1;
for (int i = searchStr.length() - 2; i >= 0; i--) {
if (searchStr.charAt(i) == value) {
startPos = i;
break;
}
}
if (startPos >= 0) {
ret = searchStr.substring(0, startPos);
searchStr = ret;
}
endPos = startPos - 1;
}
return ret;
}
public static String delCharNotChinese(String s) {
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (isChinese(c)) {
buffer.append(c);
}
}
return buffer.toString();
}
public static boolean isChinese(char c) {
if (c >= 0x4e00 && c <= 0x9fa5) {
return true;
}
return false;
}
public static String toBanjiao(String s) {
if (s == null || s.length() == 0) {
return s;
}
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c >= 65281 && c <= 65374) {
c = (char) (c - 65248);
} else if (c == 12288) { // 空格
c = (char) 32;
}
buffer.append(c);
}
return buffer.toString();
}
public static String listToString(List<String> arr) {
StringBuffer buffer = new StringBuffer();
if (arr == null) {
return buffer.toString();
}
for (int i = 0; i < arr.size(); i++) {
buffer.append(arr.get(i));
if (i != arr.size() - 1) {
buffer.append(";");
}
}
return buffer.toString();
}
public static List<String> stringToList(String str) {
List<String> strs = new ArrayList<String>();
if (str == null) {
return strs;
}
String[] ss = str.split(";");
for (String s : ss) {
if (s.trim().length() == 0) {
continue;
}
strs.add(s);
}
return strs;
}
public static String normalizeHtmlTransf(String s) {
String ret = s.replaceAll("&bull;", "·");
ret = ret.replaceAll("&middot;", "·");
ret = ret.replaceAll("&nbsp;", " ");
ret = ret.replaceAll("&quot;", "\"");
ret = ret.replaceAll("&amp;", "&");
ret = ret.replace('・', '·');
ret = ret.replace("&ldquo;", "\"");
ret = ret.replace("&rdquo;", "\"");
ret = ret.replace("&hellip;", "...");
ret = ret.replace("&lt;", "<");
ret = ret.replace("&gt;", ">");
ret = ret.replace("&mdash;", "—");
ret = ret.replace("&ndash;", "–");
ret = ret.replace("&tilde;", "~");
ret = ret.replace("&lsquo;", "'");
ret = ret.replace("&rsquo;", "'");
ret = ret.replace("&sbquo;", ",");
ret = ret.replace("&lsaquo;", "‹");
ret = ret.replace("&rsaquo;", "›");
ret = ret.replace("&hellip;", "…");
// ret = ret.replace("|", " ");
return ret;
}
public static String normalizeSegTransf(String s) {
String ret = s.replaceAll("\r\n;", " ");
ret = ret.replace("\n", "");
ret = ret.replace("|", " ");
return ret;
}
/**
* @Description 获取srcList中在text存在的集合(包含频次)
* @author kongliufeng
* @创建时间 2020/9/3 18:41
* @Version 1.0
*/
public static Map<String, Integer> getHitWordsAndTimes(Collection<String> srcList, String text){
Map<String, Integer> map = new HashMap<>();
if(srcList==null || StringUtils.isEmpty(text)){
return map;
}
for (String s : srcList) {
int i = countKeyWordInContent(s, text);
if(i>0){
map.put(s,i);
}
}
return map;
}
/**
* @Description 判断一个词是否在文本中
* @author kongliufeng
* @创建时间 2020/9/3 18:26
* @Version 1.0
*/
public static Boolean isKeyWordInText(String keyWord, String text){
if(keyWord==null || text==null)
return false;
int leng = text.length();
int j = 0;
for (int i = 0; i < leng; i++){
if (text.charAt(i) == keyWord.charAt(j)){
j++;
if (j == keyWord.length()){
return true;
}
}
else{
i = i - j;
j = 0;
}
}
return false;
}
/**
* @Description 计算一个词在一个文本中的次数
* @author kongliufeng
* @创建时间 2020/8/27 19:56
* @Version 1.0
*/
public static int countKeyWordInContent(String keyword, String srcContent){
if(keyword==null ||keyword.trim().equals("")){
return 0;
}
int count = 0;
int leng = srcContent.length();
int j = 0;
for (int i = 0; i < leng; i++){
if (srcContent.charAt(i) == keyword.charAt(j)){
j++;
if (j == keyword.length()){
count++;
j = 0;
}
}
else{
i = i - j;
j = 0;
}
}
return count;
}
/**
* @Description 在文本中根据自定义组合词匹配,返回匹配中的词
* 例如:组合词如:(产业链|供应链)+主席 == 主席+供应链;产业链+主席
*
* 括号里面是或
* @author kongliufeng
* @创建时间 2020/9/9 10:05
* @Version 1.0
*/
public static String matchComposeWords(String content , String composeWords){
if(content==null || composeWords == null)
return null;
String[] matchGroups = composeWords.split(";");
StringBuilder sb = new StringBuilder();
Boolean isMatch = false;
for(String group :matchGroups){//分组,匹配其中之一即可
String[] allContent = group.split("\\+");
Boolean allContentHit = true;
StringBuilder groupMatch = new StringBuilder();
for(String ss :allContent){//全部需要匹配
Boolean orContentHit = false;
String[] orContent = ss.replaceAll("[()]", "").split("\\|");
for(String sss:orContent){//匹配其一即可跳出
//isKeyWordInText(sss,content)
if(content.contains(sss)){
//sb.append(sss).append(",");
groupMatch.append(sss).append(",");
orContentHit=true;
break;
}
}
if(orContentHit){
continue;
}else{
allContentHit = false;
break;
}
}
if(allContentHit){
sb.append(groupMatch);
isMatch = true;
break;
}
}
if(isMatch){
return sb.toString();
}else{
return null;
}
}
}
package com.zzsn.thinktank.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class TimeUtil {
static SimpleDateFormat format;
private static Pattern patDate0 = Pattern.compile("\\d+-\\d{1,2}-\\d+");
private static Pattern patDate1 = Pattern.compile("\\d+[-\\s/年月日]\\d{1,2}-\\d+", Pattern.CASE_INSENSITIVE);
private static Pattern patDate2 = Pattern.compile("\\d+\\s+[A-Z][a-z]+\\s+\\d+");
private static Pattern patDate3 = Pattern.compile("[A-Z][a-z.]+\\s+\\d{1,2},\\s+\\d+");
private static Pattern patDate4 = Pattern.compile("\\d+年\\d+月\\d+日");
private static Pattern patDate4_1 = Pattern.compile("\\d+年\\d+月\\d+号");
private static Pattern patDate5 = Pattern.compile("\\d+/\\d{1,2}/\\d+");
private static Pattern patDate6 = Pattern.compile("\\d+\\.\\d+\\.\\d+");
private static Date thresholdDate = null;
private static SimpleDateFormat formatter0 = new SimpleDateFormat("yyyy-MM-dd");
private static SimpleDateFormat formatter0_1 = new SimpleDateFormat("yy-MM-dd");
private static SimpleDateFormat formatter2 = new SimpleDateFormat("dd MMM yyyy", Locale.ENGLISH);
private static SimpleDateFormat formatter3_1 = new SimpleDateFormat("MMM dd, yyyy", Locale.ENGLISH);
private static SimpleDateFormat formatter3_2 = new SimpleDateFormat("MMM. dd, yyyy", Locale.ENGLISH);
private static SimpleDateFormat formatter4 = new SimpleDateFormat("yyyy年MM月dd");
private static SimpleDateFormat formatter5_1 = new SimpleDateFormat("yyyy/MM/dd");
private static SimpleDateFormat formatter5_2 = new SimpleDateFormat("dd/MM/yyyy");
private static SimpleDateFormat formatter5_4 = new SimpleDateFormat("yy/MM/dd");
private static SimpleDateFormat formatter5_3 = new SimpleDateFormat("dd/MM/yy");
private static SimpleDateFormat formatter6 = new SimpleDateFormat("yyyy.MM.dd");
private static SimpleDateFormat formatter6_1 = new SimpleDateFormat("dd.MM.yyyy");
public static String dateToString(Date date) {
format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return TimeUtil.format.format(date);
}
public static String getPublishDate(String raw) {
if (raw == null) {
return null;
}
Date date = transDate(raw);
if (date != null) {
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("Asia/Shanghai"));
c.setTime(date);
Pattern p = Pattern.compile("(\\d{1,2})[:|:](\\d{1,2})([:|:]\\d{1,2}){0,1}");
Matcher m = p.matcher(raw);
while (m.find()) {
String hour = m.group(1);
if (hour != null) {
c.set(Calendar.HOUR_OF_DAY, Integer.parseInt(hour));
}
String minute = m.group(2);
if (minute != null) {
c.set(Calendar.MINUTE, Integer.parseInt(minute));
}
String second = m.group(3);
if (second != null) {
c.set(Calendar.SECOND, Integer.parseInt(second.replaceAll("[::]", "")));
}
}
return format(c.getTime(), "yyyy-MM-dd");
} else {
return null;
}
}
private static String format(Date d, String format) {
if (d == null)
return "";
SimpleDateFormat myFormatter = new SimpleDateFormat(format);
return myFormatter.format(d);
}
private static Date transDate(String content) {
try {
Matcher dateMatcher = null;
Date date = null;
if (((dateMatcher = patDate0.matcher(content)).find() && ((date = transDate(dateMatcher.group(), 0)) != null))
|| ((dateMatcher = patDate1.matcher(content)).find() && ((date = transDate(dateMatcher.group(), 1)) != null))
|| ((dateMatcher = patDate2.matcher(content)).find() && ((date = transDate(dateMatcher.group(), 2)) != null))
|| ((dateMatcher = patDate3.matcher(content)).find() && ((date = transDate(dateMatcher.group(), 3)) != null))
|| ((dateMatcher = patDate4.matcher(content)).find() && ((date = transDate(dateMatcher.group(), 4)) != null))
|| ((dateMatcher = patDate4_1.matcher(content)).find() && ((date = transDate(dateMatcher.group(), 4)) != null))
|| ((dateMatcher = patDate5.matcher(content)).find() && ((date = transDate(dateMatcher.group(), 5)) != null))
|| ((dateMatcher = patDate6.matcher(content)).find() && ((date = transDate(dateMatcher.group(), 6)) != null))
) {
return date;
}
return null;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
private static Date transDate(String source, int type) {
try {
if (thresholdDate == null) {
thresholdDate = formatter0.parse("1970-01-01");
}
Date date = null;
switch (type) {
case 0:
date = formatter0.parse(source);
if (date.before(thresholdDate)) {
date = formatter0_1.parse(source);
if (date.before(thresholdDate)) {
return null;
}
}
break;
case 1:
//date = formatter1.parse(source);
break;
case 2:
date = formatter2.parse(source);
break;
case 3:
try {
date = formatter3_1.parse(source);
} catch (Exception e) {
date = null;
}
if (date == null) {
date = formatter3_2.parse(source);
}
break;
case 4:
date = formatter4.parse(source);
break;
case 5:
try {
date = formatter5_1.parse(source);
} catch (Exception e) {
date = null;
}
if ((date == null) || (date.before(thresholdDate))) {
date = formatter5_2.parse(source);
}
if ((date == null) || (date.before(thresholdDate))) {
date = formatter5_3.parse(source);
}
if ((date == null) || (date.before(thresholdDate))) {
date = formatter5_4.parse(source);
}
break;
case 6:
try {
date = formatter6.parse(source);
} catch (ParseException e) {
date = null;
}
if ((date == null) || (date.before(thresholdDate))) {
date = formatter6_1.parse(source);
}
break;
}
if ((date != null) && (date.before(thresholdDate))) {
return null;
}
return date;
} catch (Exception e) {
return null;
}
}
/**
* 获取前7天的时间
* @param date
* @return
*/
public static String beforeWeek(Date date){
format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar c = Calendar.getInstance();
//设置为指定日期
c.setTime(date);
c.add(Calendar.DATE,-7);
Date time = c.getTime();
return format.format(time);
}
/**
* 获取前30天的时间
* @param date
* @return
*/
public static String beforeMonth(Date date){
format = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
//设置为指定日期
c.setTime(date);
c.add(Calendar.DATE,-30);
return format.format(c.getTime()) + " 00:00:00";
}
public static String getDateString(Date date) {
format = new SimpleDateFormat("yyyy-MM-dd");
return TimeUtil.format.format(date);
}
public static Date StringToDate(String dateString) throws ParseException {
format = new SimpleDateFormat("yyyy-MM-dd");
return format.parse(dateString);
}
public static String dateConvert(String dateString) throws ParseException {
format = new SimpleDateFormat("MM/dd/yyyy");
Date parse = format.parse(dateString);
return getDateString(parse);
}
/**
* 获取指定某一天的开始时间戳
*
* @param timeStamp 毫秒级时间戳
* @param timeZone 如 GMT+8:00
* @return
*/
public static Long getDailyStartTime(Long timeStamp, String timeZone) {
Calendar calendar = Calendar.getInstance();
calendar.setTimeZone(TimeZone.getTimeZone(timeZone));
calendar.setTimeInMillis(timeStamp);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTimeInMillis();
}
/**
* 获取指定某一天的结束时间戳
*
* @param timeStamp 毫秒级时间戳
* @param timeZone 如 GMT+8:00
* @return
*/
public static Long getDailyEndTime(Long timeStamp, String timeZone) {
Calendar calendar = Calendar.getInstance();
calendar.setTimeZone(TimeZone.getTimeZone(timeZone));
calendar.setTimeInMillis(timeStamp);
calendar.set(Calendar.HOUR_OF_DAY, 23);
calendar.set(Calendar.MINUTE, 59);
calendar.set(Calendar.SECOND, 59);
calendar.set(Calendar.MILLISECOND, 999);
return calendar.getTimeInMillis();
}
/**
* 判断两个时间是否为同一天
* @param date1
* @param date2
* @return
*/
public static boolean isSameDay(final Date date1, final Date date2) {
if(date1 == null || date2 == null) {
return false;
}
final Calendar cal1 = Calendar.getInstance();
cal1.setTime(date1);
final Calendar cal2 = Calendar.getInstance();
cal2.setTime(date2);
return isSame(cal1, cal2);
}
private static boolean isSame(final Calendar cal1, final Calendar cal2) {
if (cal1 == null || cal2 == null) {
return false;
}
return (cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA) &&
cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) &&
cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR));
}
}
package com.zzsn.thinktank.vo;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* <p>
*5.1 人物分类体系表 分类树
* </p>
*
* @since
*/
@Data
public class CharacterCategoryStructureTreeVo extends Model<CharacterCategoryStructureTreeVo>
{
private static final long serialVersionUID = 1L;
/**
* 主键
*/
private String id;
/**
* 类别名称 公安部 财政部
*/
private String typeName;
/**
*类别编码
*/
private String typeCode;
/**
* 创建人
*/
private String createBy;
/**
* 创建时间
*/
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
/**
* 更新人
*/
private String updateBy;
/**
* 更新时间
*/
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
/**
* 所属部门
*/
private String sysOrgCode;
/**
* 父级节点id
*/
private String pid;
/**
* 是否有子节点0,没有 1,有
*/
private String hasChild;
/**
* 分类类型: 领导人 专家 企业高管
*/
private String category;
/**
* 状态0启用,1禁用
*/
private Integer status;
/**
* 节点绝对路径
*/
private String fullPath;
/**
* 描述
*/
private String description;
/**
* 排序
*/
private Long sort;
/**
* 子节点
*/
private List<CharacterCategoryStructureTreeVo> children = new ArrayList<>();
}
package com.zzsn.thinktank.vo;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* Description:
*
* @author: EDY
* @since: 2023/10/24
*/
@Data
@Accessors(chain = true)
public class GroupResult {
private String name;
private Long count;
}
package com.zzsn.thinktank.vo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.util.Date;
/**
* @Description: 信息源组和信息源关联表
* @Author: jeecg-boot
* @Date: 2021-11-24
* @Version: V1.0
*/
@Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
public class InfoSourceGroupCountVo implements Serializable {
private static final long serialVersionUID = 1L;
/**主键*/
private String id;
/**信息源组id*/
private String groupId;
/**信息源id*/
private String sourceId;
/**信息源采集资讯数量**/
private Integer infoCount;
}
package com.zzsn.thinktank.vo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.List;
@Data
public class InfoSourceGroupPage {
/**
* 主键
*/
@TableId(type = IdType.ASSIGN_ID)
private String id;
/**
* 组编码
*/
@Excel(name = "组编码", width = 15)
private String groupCode;
/**
* 信息源组名称
*/
@Excel(name = "信息源组名称", width = 15)
private String groupName;
/**
* 绑定信息源组的信息源ids
*/
@Excel(name = "绑定信息源组的信息源ids", width = 15)
private List<String> infoSourceIds;
/**
* 组类别id
*/
@Excel(name = "组类别ids", width = 15)
private List<String> groupTypeIds;
private String typeIds;
private String typeId;
/**
* 组类别名称
*/
@Excel(name = "组类别名称", width = 15)
private String groupTypeNames;
/**
* 分组说明
*/
@Excel(name = "分组说明", width = 15)
private String groupRemark;
/**
* 状态
*/
@Excel(name = "状态", width = 15, dicCode = "use_status")
private Integer status;
/**
* 创建人
*/
private String createBy;
/**
* 创建日期
*/
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private java.util.Date createTime;
/**
* 更新人
*/
private String updateBy;
/**
* 更新日期
*/
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private java.util.Date updateTime;
/**
* 所属部门
*/
private String sysOrgCode;
/**
* 信息源类别
*/
private Integer sourceType;
/**
* 信息源权重(以组设置)
*/
private Integer weight;
/**
* 专题绑定信息源的主键id
*/
private String subjectInfoSourceId;
private Integer infoSourceNum;
private String groupTypeId;
}
package com.zzsn.thinktank.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Data
public class InfoSourceVo {
/**主键*/
private String id;
/****************************基本信息********************************/
/**信息源编码*/
private String infoSourceCode;
/**信息源名称,微信公众号名称,微博名称*/
private String webSiteName;
/**栏目名称*/
private String siteName;
/**栏目URL,微信公众号URL,微博URL*/
private String siteUri;
/**微博认证方式(1:个人微博 2:官方微博)*/
private String authMode;
/**功能介绍,微博认证描述*/
private String remarks;
/**公众号BIZ*/
private String biz;
/**是否大V*/
private int ynBigV;
/**权威性*/
private String authority;
/**信息源类别ids*/
private String infoSourceTypeId;
private String infoSourceTypeName;
/**信息源性质ids*/
private List<String> infoSourceNatureIds;
private String natureIds;
private String infoSourceNatureNames;
/**信息源组名称*/
private String infoSourceGroupNames;
/**网站重要级别*/
private String siteLevel;
/**国家*/
private String country;
/**地区*/
private String area;
/**语种*/
private String language;
/**是否(境外、公共、翻墙)*/
private String checkedList;
/**历史数据URL*/
private String hisUriExp;
/**历史数据开始时间*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
@DateTimeFormat(pattern="yyyy-MM-dd")
private Date hisDateStartTime;
/**历史数据结束时间*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
@DateTimeFormat(pattern="yyyy-MM-dd")
private Date hisDateEndTime;
/**是否历史所有数据*/
private String ynHisDataAll;
/**状态*/
private String status;
/****************************列表页********************************/
/**列表页URL*/
private String listUrl;
/**表达式类型*/
private String listExpressionType;
/**匹配资讯的url*/
private String informationUrl;
/**匹配资讯标题*/
private String informationTitle;
/**匹配资讯发布时间*/
private String informationPublishDate;
/**匹配资讯来源*/
private String informationSource;
/**列表信息块位置*/
private String infoBlockPosition;
/**抽取链接定位*/
private String linkLocation;
/**自定义实体*/
private Object extractInfo;
/**爬取深度*/
private Integer crawlDepth;
/**页码url*/
private String pageUrl;
/**匹配页码*/
private String matchPage;
/**开始页码*/
private int pageStart;
/**结束页码*/
private int pageEnd;
/**是否所有页*/
private String ynPageAll;
/**预警标签*/
private List<Map<String,Object>> warningTag;
/****************************详情页********************************/
/**详情页表URL*/
private int detailUrl;
/**表达式类型*/
private String detailExpressionType;
/**匹配详情页标题*/
private String detailExpressionTitle;
private Integer titleExtractionMethodType;
private String titleExtractionMethod;
/**匹配详情页时间*/
private String detailExpressionPublishDate;
private Integer publishDateExtractionMethodType;
private String publishDateExtractionMethod;
/**匹配详情页来源*/
private String detailExpressionSource;
private Integer sourceExtractionMethodType;
private String sourceExtractionMethod;
/**匹配详情页作者*/
private String detailExpressionAuthor;
private Integer authorExtractionMethodType;
private String authorExtractionMethod;
/**匹配详情页摘要*/
private String detailExpressionSummary;
private Integer summaryExtractionMethodType;
private String summaryExtractionMethod;
/**匹配详情页正文*/
private String detailExpressionContent;
private Integer contentExtractionMethodType;
private String contentExtractionMethod;
/**自定义实体*/
private Object detailInfo;
/**是否下载附件*/
private String ynDownload;
/****************************数据页********************************/
/**数据表格页URL*/
private String formUrl;
/**数据表格标题*/
private String formTitle;
/**表达式类型*/
private String formType;
/**数据表格表达式*/
private String dataFormExpression;
/**自定义*/
private Object dataFormInfo;
/**页码URL*/
private String dataPageUrl;
/**页码规则*/
private String dataPageRule;
/**开始页码*/
private int dataPageStart;
/**结束页码*/
private int dataPageEnd;
/**是否所有页码*/
private String ynDataPageAll;
/****************************存储设置********************************/
/**数据类型*/
private int dataType;
/**数据格式*/
private int dataFormat;
/**数据存储方式*/
private int dataStorageMode;
/**数据存储信息*/
private Object dataStorageInfo;
/****************************爬取设置********************************/
/**是否动态爬取*/
private int ynDynamicCrawl;
/**是否需要登陆*/
private int ynLogin;
/**登陆域名*/
private String domainName;
/**登陆链接*/
private String link;
/**登陆账号*/
private String account;
/**登陆密码*/
private String passWord;
/**userAgent*/
private String userAgent;
/**Referer*/
private String referer;
/**cookies*/
private String cookies;
/**headers*/
private String headers;
/**其它参数*/
private String otherInfo;
/****************************爬虫设置********************************/
/**爬虫类别*/
private int crawlType;
/**爬虫名称*/
private String crawlName;
/**爬虫地址*/
private String crawlAddress;
/**参数*/
private Object parameter;
/****************************调度设置********************************/
/**设置方式(1:自由设置 2:cron表达式)*/
private Integer setMode;
/**定时方式(1:时间间隔 2:立即执行)*/
private String timerMode;
/**定时单位(1分;2小时;3日;4月)*/
private String unit;
/**定时数值*/
private Integer space;
/**cron表达式*/
private String cron;
/**说明*/
private String explaination;
/**是否下载*/
private Boolean downLoad;
/**是否立即执行*/
private Boolean execute;
/**验证结果*/
private String verification;
/**所属单位*/
private String company;
/**所属行业*/
private String industry;
/**可信度*/
private String reliability;
/**原创度*/
private String originality;
/**父网站*/
private String parentSite;
/**是否保存快照(1:保存 0:不保存)*/
private String ynSnapshot;
private String sourceId;
/**创建人*/
private String createBy;
/**创建日期*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
private Date createTime;
/**更新人*/
private String updateBy;
/**更新日期*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
private Date updateTime;
}
package com.zzsn.thinktank.vo;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import java.io.Serializable;
/**
* 接口返回数据格式
* @author scott
* @email jeecgos@163.com
* @date 2019年1月19日
*/
@Data
public class Result<T> implements Serializable {
private static final long serialVersionUID = 1L;
/** {@code 200 OK} (HTTP/1.0 - RFC 1945) */
private static final Integer SC_OK_200 = 200;
/** {@code 500 Server Error} (HTTP/1.0 - RFC 1945) */
private static final Integer SC_INTERNAL_SERVER_ERROR_500 = 500;
/**访问权限认证未通过 510*/
private static final Integer SC_JEECG_NO_AUTHZ = 510;
/**
* 成功标志
*/
private boolean success = true;
/**
* 返回处理消息
*/
private String message = "操作成功!";
/**
* 返回代码
*/
private Integer code = 0;
/**
* 返回数据对象 data
*/
private T result;
/**
* 时间戳
*/
private long timestamp = System.currentTimeMillis();
/**
* python接口返回
*/
private String handleMsg;
/**
* python接口返回状态
*/
private boolean isHandleSuccess;
/**
* python接口返回状态
*/
private String logs;
/**
* 返回数据对象 data
*/
private T resultData;
public Result() {
}
public Result<T> success(String message) {
this.message = message;
this.code = SC_OK_200;
this.success = true;
return this;
}
public static<T> Result<T> OK() {
Result<T> r = new Result<T>();
r.setSuccess(true);
r.setCode(SC_OK_200);
r.setMessage("成功");
return r;
}
public static<T> Result<T> OK(T data) {
Result<T> r = new Result<T>();
r.setSuccess(true);
r.setCode(SC_OK_200);
r.setResult(data);
return r;
}
public static<T> Result<T> OK(String msg, T data) {
Result<T> r = new Result<T>();
r.setSuccess(true);
r.setCode(SC_OK_200);
r.setMessage(msg);
r.setResult(data);
return r;
}
public static Result<Object> error(String msg) {
return error(SC_INTERNAL_SERVER_ERROR_500, msg);
}
public static Result<Object> error(int code, String msg) {
Result<Object> r = new Result<Object>();
r.setCode(code);
r.setMessage(msg);
r.setSuccess(false);
return r;
}
public Result<T> error500(String message) {
this.message = message;
this.code = SC_INTERNAL_SERVER_ERROR_500;
this.success = false;
return this;
}
/**
* 无权限访问返回结果
*/
public static Result<Object> noauth(String msg) {
return error(SC_JEECG_NO_AUTHZ, msg);
}
@JsonIgnore
private String onlTable;
}
\ No newline at end of file
package com.zzsn.thinktank.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.springframework.format.annotation.DateTimeFormat;
@Data
public class SysBaseLabelTypeVo {
/**主键*/
private String id;
/**标签名称*/
private String labelName;
/**标签标识*/
private String labelMark;
/**说明*/
private String explanation;
/**创建人*/
private String createBy;
/**创建日期*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
private java.util.Date createTime;
/**更新人*/
private String updateBy;
/**更新日期*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
private java.util.Date updateTime;
/**所属部门*/
private String sysOrgCode;
/**父级节点*/
private String pid;
/**是否有子节点*/
@Excel(name = "是否有子节点", width = 15, dicCode = "yn")
private String hasChild;
/**排序*/
private Integer orderNo;
/**顶层id*/
private String topId;
/**标签类别(如企业、自定义等)*/
private String labelType;
/**下级节点*/
private java.util.List<SysBaseLabelTypeVo> children;
}
package com.zzsn.thinktank.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.List;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public class SysLabelVo {
/**
* 主键
*/
private String id;
/**
* 名称
*/
private String name;
/**
* 近义词
*/
private String synonym;
/**
* 说明
*/
private String explanation;
/**
* 层级
*/
private Integer level;
/**
* 一级主键id
*/
private String topId;
/**
* 所有id
*/
private String pathIds;
/**
* 状态
*/
private Integer status;
/**
* 排序
*/
private Integer sort;
/**
* 创建人
*/
private String createBy;
/**
* 创建日期
*/
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private java.util.Date createTime;
/**
* 更新人
*/
private String updateBy;
/**
* 更新日期
*/
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private java.util.Date updateTime;
/**
* 所属部门
*/
private String sysOrgCode;
/**
* 父级节点
*/
private String pid;
/**
* 是否有子节点
*/
private String hasChild;
/**
* 属于哪个标签(表sys_base_label_type的主键id)
*/
private String labelTypeId;
/**
* 标签类别(如企业、自定义等)
*/
private String labelType;
/**
* 标签标识
*/
private String labelMark;
/**
* 下级节点
*/
private List<SysLabelVo> children;
private Boolean isLeaf;
/**
* 具体标签的id集合
*/
private List<String> labelIdList;
private String queryParam;
private String dataType = "";
/**
* 专题字段
*/
private Integer category;
/**
* 词条名称
*/
private String itemText;
/**
* 词条代码
*/
private String itemValue;
/**
* 描述
*/
private String description;
/**
* 排序值
*/
private String sortOrder;
/**
* 字典id
*/
private String dictId;
/**唯一编码(前端回显)*/
private String code;
}
package com.zzsn.thinktank.vo;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ThinktankBasicInfoExportVo extends Model<ThinktankBasicInfoExportVo> {
//主键
private String id;
//序号
//private Integer rn;
//智库机构编码
private String codeId;
//中文全称
private String chineseWhole;
//中文简称
private String chineseSimple;
//英文全称
private String englishWhole;
//英文简称
private String englishSimple;
//原文全称
private String originalWhole;
//原文简称
private String originalSimple;
//官网
private String officialWebsite;
//所属国家/地区 ID
// private String belongCountryId;
//所属国家/地区
private String belongCountry;
//标签id 多个标签使用逗号分隔
// private String tagId;
//标签名称 多个标签使用逗号分隔
private String tagName;
//简介
private String biographicalNotes;
//成立时间
private String establishTime;
//是否收费 1是 0否 默认为空值
private Integer charge;
//地址
private String address;
//创办单位/所属单位
private String belongUnit;
//采集信息总量
private Integer collectionCount;
//绑定信息源个数
private Integer infoSourceCount;
//关联信息源id
private String infoSourceId;
//关联信息源编码
private String infoSourceCode;
//关联信息源名称
private String webSiteName;
//栏目名称
private String siteName;
//网址
private String siteUri;
//信息源采集数量
private Integer count;
//国内外
// private String countryWithinExternal;
//所在地区
// private String region;
//创办单位/所属单位 企业信用代码
// private String belongUnitCode;
//机构头像
// private String headSculpture;
//属性 区分智库机构、咨询公司、新闻媒体
// private String attribute;
//启停状态 1启 0停
// private Integer status;
//创建人
// private String createBy;
//创建时间
// @TableField(fill = FieldFill.INSERT)
// @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
// @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
// private Date createTime;
//更新人
// private String updateBy;
//更新时间
// @TableField(fill = FieldFill.INSERT)
// @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
// @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
// private Date updateTime;
}
package com.zzsn.thinktank.vo;
import lombok.Data;
/**
* @Version 1.0
* @Author: ZhangJingKun
* @Date: 2024/2/29 17:54
* @Content:
*/
@Data
public class ThinktankBasicInfoListVo {
//当前页码,默认值为1
private Integer pageNo = 1;
//分页偏移量 根据 pageNo 和 pageSize 计算得到
private Integer offset;
//每页数量,默认值为10
private Integer pageSize = 10;
//排序字段,多个排序字段用逗号分隔
private String column = "id";
//降序DESC 升序 ASC 默认为DESC
private String order = "DESC";
//关键词
private String keyword;
//智库机构编码
private String codeId;
//智库机构名称
private String thinktankName;
//类别 根据左侧树id
private String typeId;
//标签
private String tagId;
}
package com.zzsn.thinktank.vo;
import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ThinktankBasicInfoVo extends Model<ThinktankBasicInfoVo> {
//主键
private String id;
//智库机构编码
private String codeId;
//中文全称
private String chineseWhole;
//中文简称
private String chineseSimple;
//英文全称
private String englishWhole;
//英文简称
private String englishSimple;
//原文全称
private String originalWhole;
//原文简称
private String originalSimple;
//官网
private String officialWebsite;
//标签id 多个标签使用逗号分隔
private String tagId;
//标签名称 多个标签使用逗号分隔
private String tagName;
//成立时间
private String establishTime;
//是否收费 1是 0否 默认为空值
private Integer charge;
//国内外
private String countryWithinExternal;
//所属国家/地区 ID
private String belongCountryId;
//所属国家/地区
private String belongCountry;
//所在地区
private String region;
//地址
private String address;
//创办单位/所属单位 企业信用代码
private String belongUnitCode;
//创办单位/所属单位
private String belongUnit;
//机构头像
private String headSculpture;
//简介
private String biographicalNotes;
//属性 区分智库机构、咨询公司、新闻媒体
private String attribute;
//启停状态 1启 0停
private Integer status;
//创建人
private String createBy;
//创建时间
@TableField(fill = FieldFill.INSERT)
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
//更新人
private String updateBy;
//更新时间
@TableField(fill = FieldFill.INSERT)
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
//采集信息总量
private Integer collectionCount;
//绑定信息源个数
private Integer infoSourceCount;
}
server:
port: 9099
servlet:
context-path: /thinktank
spring:
servlet:
multipart:
#单个上传文件大小
max-file-size: 100MB
#总上传文件大小
max-request-size: 1000MB
datasource:
url: jdbc:mysql://114.116.44.11:3306/clb_project?useUnicode=true&characterEncoding=utf-8&AllowPublicKeyRetrieval=True&serverTimezone=Asia/Shanghai&autoReconnect=true&rewriteBatchedStatements=true
username: ciglobal
password: qwer@9988&zzsn
redis:
database: 0
host: 114.116.90.53
password: clbzzsn
port: 6380
kafka:
bootstrap-servers: 114.115.159.144:9092
consumer:
group-id: groupName
auto-offset-reset: earliest
key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
mybatis-plus:
mapper-locations: mapper/*.xml
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
map-underscore-to-camel-case: true
#生产es集群
es1:
endpoint1: 114.115.215.250
endpoint1port: 9700
endpoint2: 114.116.19.92
endpoint2port: 9700
endpoint3: 114.116.54.108
endpoint3port: 9200
username: elastic
password: zzsn9988
sys_base_label_type_id: 1783029731298439170
files:
#storage: D:\\thinktank\\
storage: /zzsn/clb/thinktank/
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false">
<!--定义日志文件的存储地址 -->
<property name="LOG_HOME" value="../clbLogs/thinktank" />
<!--<property name="COLOR_PATTERN" value="%black(%contextName-) %red(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) %boldMagenta( %replace(%caller{1}){'\t|Caller.{1}0|\r\n', ''})- %gray(%msg%xEx%n)" />-->
<!-- 控制台输出 -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50}:%L - %msg%n</pattern>-->
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %highlight(%-5level) %cyan(%logger{50}:%L) - %msg%n</pattern>
</encoder>
</appender>
<!-- 按照每天生成日志文件 -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_HOME}/thinktank.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!--日志文件输出的文件名 -->
<FileNamePattern>${LOG_HOME}/thinktank-%d{yyyy-MM-dd}.%i.log</FileNamePattern>
<!--日志文件保留天数 -->
<MaxHistory>10</MaxHistory>
<maxFileSize>10MB</maxFileSize>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符 -->
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50}:%L - %msg%n</pattern>
</encoder>
</appender>
<!--myibatis log configure -->
<logger name="com.apache.ibatis" level="TRACE" />
<logger name="java.sql.Connection" level="DEBUG" />
<logger name="java.sql.Statement" level="DEBUG" />
<logger name="java.sql.PreparedStatement" level="DEBUG" />
<!-- 日志输出级别 -->
<root level="INFO">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</root>
</configuration>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zzsn.thinktank.mapper.ThinktankBasicInfoMapper">
<select id="getList" resultType="com.zzsn.thinktank.vo.ThinktankBasicInfoVo">
select
id,code_id,chinese_whole,chinese_simple,english_whole,english_simple,original_whole,original_simple,official_website,tag_id,tag_name,establish_time,charge,country_within_external,belong_country_id,belong_country,region,address,belong_unit_code,belong_unit,head_sculpture,biographical_notes,attribute,status,create_by,create_time,update_by,update_time
from thinktank_basic_info a
where 1 = 1
<if test="codeId != null and codeId != ''">
AND a.code_id = #{codeId}
</if>
<if test="typeId != null and typeId != ''">
AND a.belong_country_id = #{typeId}
</if>
<if test="thinktankName != null and thinktankName != ''">
AND a.chinese_whole like '%${thinktankName}%'
</if>
<if test="tagId != null and tagId != ''">
<foreach item="item" index="index" collection="tagId.split(',')">
AND a.tag_id like '%${item}%'
</foreach>
</if>
<if test="keyword != null and keyword != ''">
AND CONCAT_WS(',',code_id,chinese_whole,chinese_simple,english_whole,english_simple,original_whole,original_simple,official_website,tag_name,country_within_external,belong_country,region,address,belong_unit_code,belong_unit,biographical_notes,attribute)
like '%${keyword}%'
</if>
<if test="order != null and order != ''">
ORDER BY ${column} ${order}
</if>
limit #{offset}, #{pageSize}
</select>
<select id="getCount" resultType="int">
select
count(1)
from thinktank_basic_info a
where 1 = 1
<if test="codeId != null and codeId != ''">
AND a.code_id = #{codeId}
</if>
<if test="typeId != null and typeId != ''">
AND a.belong_country_id = #{typeId}
</if>
<if test="thinktankName != null and thinktankName != ''">
AND a.chinese_whole like '%${thinktankName}%'
</if>
<if test="tagId != null and tagId != ''">
<foreach item="item" index="index" collection="tagId.split(',')">
AND a.tag_id like '%${item}%'
</foreach>
</if>
<if test="keyword != null and keyword != ''">
AND CONCAT_WS(',',code_id,chinese_whole,chinese_simple,english_whole,english_simple,original_whole,original_simple,official_website,tag_name,country_within_external,belong_country,region,address,belong_unit_code,belong_unit,biographical_notes,attribute)
like '%${keyword}%'
</if>
</select>
<select id="getExportList" resultType="com.zzsn.thinktank.vo.ThinktankBasicInfoExportVo">
select
a.id, a.code_id, a.chinese_whole, a.chinese_simple, a.english_whole, a.english_simple, a.original_whole, a.original_simple, a.official_website, a.belong_country, a.tag_name, a.biographical_notes, a.establish_time, a.charge, a.address, a.belong_unit,
c.id as infoSourceId, c.info_source_code, c.web_site_name, c.site_name, c.site_uri
from thinktank_basic_info a
LEFT JOIN thinktank_info_source_group_map b
on a.id = b.group_id
LEFT JOIN info_source c
on b.source_id = c.id
where 1 = 1
<if test="codeId != null and codeId != ''">
AND a.code_id = #{codeId}
</if>
<if test="typeId != null and typeId != ''">
AND a.belong_country_id = #{typeId}
</if>
<if test="thinktankName != null and thinktankName != ''">
AND a.chinese_whole like '%${thinktankName}%'
</if>
<if test="tagId != null and tagId != ''">
<foreach item="item" index="index" collection="tagId.split(',')">
AND a.tag_id like '%${item}%'
</foreach>
</if>
<if test="keyword != null and keyword != ''">
AND CONCAT_WS(',',code_id,chinese_whole,chinese_simple,english_whole,english_simple,original_whole,original_simple,official_website,tag_name,country_within_external,belong_country,region,address,belong_unit_code,belong_unit,biographical_notes,attribute)
like '%${keyword}%'
</if>
<if test="order != null and order != ''">
ORDER BY ${column} ${order}
</if>
</select>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zzsn.thinktank.mapper.ThinktankTagMapper">
<select id="getTopTag" resultType="com.zzsn.thinktank.entity.ThinktankTagTop">
select *
from thinktank_tag_top
order by count_num desc
limit 10
</select>
<select id="getSysBaseLabelTypeById" resultType="com.zzsn.thinktank.entity.SysBaseLabelType">
select * from sys_base_label_type
where 1=1
and id = #{id}
</select>
<select id="getgetSysBaseLabelTypeListByPid" resultType="com.zzsn.thinktank.entity.SysBaseLabelType">
select * from sys_base_label_type
where 1=1
and pid = #{id}
</select>
<select id="queryCustomLabel" resultType="com.zzsn.thinktank.vo.SysLabelVo">
select b.*, a.label_id as labelTypeId, a.label_type as labelType, c.label_mark as labelMark from sys_base_label_type_map a
inner join label_entity b on a.relation_id = b.id and b.pid = 0
left join sys_base_label_type c on a.label_id = c.id
where 1=1
<if test="ids!=null and ids.size()>0">
and a.label_id in
<foreach collection="ids" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
<if test="name!=null and name != ''">
and b.name like concat('%',#{name},'%')
</if>
order by b.create_time
</select>
<select id="getTagTypeListAll" resultType="com.zzsn.thinktank.vo.SysBaseLabelTypeVo">
select * from sys_base_label_type
where 1=1
and category = 1
</select>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zzsn.thinktank.mapper.EnterpriseMapper">
<select id="pageList" resultType="com.zzsn.thinktank.entity.SysBaseEnterprise">
select * from sys_base_enterprise
where 1=1
<if test="socialCreditCode != null and socialCreditCode != ''">
and social_credit_code = #{socialCreditCode}
</if>
<if test="name != null and name != ''">
and name like '%${name}%'
</if>
limit ${office},${pageSize}
</select>
<select id="pageListCount" resultType="Integer">
select count(1) from sys_base_enterprise
where 1=1
<if test="socialCreditCode != null and socialCreditCode != ''">
and social_credit_code = #{socialCreditCode}
</if>
<if test="name != null and name != ''">
and name like '%${name}%'
</if>
</select>
<select id="getListByName" resultType="com.zzsn.thinktank.entity.SysBaseEnterprise">
select * from sys_base_enterprise
where 1=1
and name = #{name}
</select>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zzsn.thinktank.mapper.InfoSourceGroupMapMapper">
<select id="query" resultType="com.zzsn.thinktank.entity.InfoSourceGroupMap">
select * from thinktank_info_source_group_map where source_id = #{sourceId} and group_id = #{groupId}
</select>
<delete id="deleteBySourceId" >
delete from thinktank_info_source_group_map
WHERE source_id = #{sourceId}
</delete>
<delete id="deleteBySourceIds" >
delete from thinktank_info_source_group_map
WHERE group_id = #{groupId}
<if test="sourceIds!=null and sourceIds.size()>0">
and source_id in
<foreach collection="sourceIds" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
</delete>
</mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zzsn.thinktank.mapper.InfoSourceMapper">
<select id="pageListByGroupId" resultType="com.zzsn.thinktank.vo.InfoSourceVo">
SELECT c.*, g.infoSourceNatureNames, j.infoSourceTypeId,j.infoSourceTypeName from (
SELECT a.* from info_source a
LEFT JOIN info_source_type_map b ON b.source_id = a.id
where 1 = 1
<if test="ynBind == 0">
and a.id not in (SELECT distinct source_id FROM thinktank_info_source_group_map WHERE group_id = #{groupId})
</if>
<if test="ynBind == 1">
and a.id in (SELECT distinct source_id FROM thinktank_info_source_group_map WHERE group_id = #{groupId})
</if>
<if test="infoSourceVo.infoSourceTypeId!=null and infoSourceVo.infoSourceTypeId>0">
and b.type_id = #{infoSourceVo.infoSourceTypeId}
</if>
<if test="infoSourceVo.webSiteName!=null and infoSourceVo.webSiteName != ''">
and a.web_site_name like CONCAT('%',#{infoSourceVo.webSiteName},'%')
</if>
<if test="infoSourceVo.siteName!=null and infoSourceVo.siteName != ''">
and a.site_name like CONCAT('%',#{infoSourceVo.siteName},'%')
</if>
<if test="infoSourceVo.siteUri!=null and infoSourceVo.siteUri != ''">
and a.site_uri like CONCAT('%',#{infoSourceVo.siteUri},'%')
</if>
<if test="infoSourceVo.status!=null and infoSourceVo.status != ''">
and a.status = #{infoSourceVo.status}
</if>
limit #{offset}, #{pageSize}
)c
LEFT JOIN (
SELECT e.source_id, GROUP_CONCAT(f.nature_name SEPARATOR ',') as infoSourceNatureNames from
info_source_properties_map e
LEFT JOIN info_source_nature f ON f.id = e.nature_id
GROUP BY e.source_id) g ON c.id = g.source_id
LEFT JOIN (
SELECT h.source_id, i.id as infoSourceTypeId,i.type_name as infoSourceTypeName from info_source_type_map h
LEFT JOIN info_source_type i ON i.id = h.type_id
GROUP BY h.source_id,i.type_name) j ON c.id = j.source_id
</select>
<select id="totalCountByGroupId" resultType="Integer">
SELECT count(1) from (
SELECT distinct b.source_id from thinktank_info_source_group_map b
inner join info_source a on b.source_id = a.id
where b.group_id = #{groupId}
<if test="infoSourceVo.webSiteName!=null and infoSourceVo.webSiteName != ''">
and a.web_site_name like CONCAT('%',#{infoSourceVo.webSiteName},'%')
</if>
<if test="infoSourceVo.siteName!=null and infoSourceVo.siteName != ''">
and a.site_name like CONCAT('%',#{infoSourceVo.siteName},'%')
</if>
<if test="infoSourceVo.siteUri!=null and infoSourceVo.siteUri != ''">
and a.site_uri = #{infoSourceVo.siteUri}
</if>
<if test="infoSourceVo.status!=null and infoSourceVo.status != ''">
and a.status = #{infoSourceVo.status}
</if>
)c
</select>
<select id="pageList" resultType="com.zzsn.thinktank.vo.InfoSourceVo">
SELECT d.*, c.type_name as infoSourceTypeName, c.id as infoSourceTypeId from
<choose>
<when test="userId != null and userId != ''">
(
select s.* from info_source s inner join thinktank_info_source_group_map sgm on s.id = sgm.source_id
inner join sys_user_data_permission dp on dp.permission_id = sgm.group_id
where dp.user_id = #{userId}
)
</when>
<when test="customerId != null and customerId != ''">
(
select s.* from info_source s inner join thinktank_info_source_group_map sgm on s.id = sgm.source_id
inner join customer_data_permission_map m on m.permission_id = sgm.group_id
where m.customer_id = #{customerId}
)
</when>
<otherwise>
info_source
</otherwise>
</choose>
d
LEFT JOIN info_source_type_map b ON b.source_id = d.id
LEFT JOIN info_source_type c ON b.type_id = c.id
where 1 = 1
<if test="typeIds!=null and typeIds.size()>0">
and b.type_id in
<foreach collection="typeIds" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
<if test="infoSourceVo.id!=null and infoSourceVo.id!=''">
and d.id = #{infoSourceVo.id}
</if>
<if test="infoSourceVo.webSiteName!=null and infoSourceVo.webSiteName != ''">
and d.web_site_name like CONCAT('%',#{infoSourceVo.webSiteName},'%')
</if>
<if test="infoSourceVo.siteName!=null and infoSourceVo.siteName != ''">
and d.site_name like CONCAT('%',#{infoSourceVo.siteName},'%')
</if>
<if test="infoSourceVo.infoSourceCode!=null and infoSourceVo.infoSourceCode != ''">
and d.info_source_code = #{infoSourceVo.infoSourceCode}
</if>
<if test="infoSourceVo.siteUri!=null and infoSourceVo.siteUri != ''">
and d.site_uri like CONCAT('%',#{infoSourceVo.siteUri},'%')
</if>
<if test="infoSourceVo.status!=null and infoSourceVo.status != ''">
and d.status = #{infoSourceVo.status}
</if>
<if test="infoSourceVo.crawlType!=null and infoSourceVo.crawlType != 0">
and d.crawl_type = #{infoSourceVo.crawlType}
</if>
<if test="infoSourceVo.createBy!=null and infoSourceVo.createBy != ''">
and d.create_by = #{infoSourceVo.createBy}
</if>
<if test="infoSourceVo.verification!=null and infoSourceVo.verification != ''">
and d.verification = #{infoSourceVo.verification}
</if>
ORDER BY b.source_id desc
limit #{offset}, #{pageSize}
</select>
<select id="listBySidList" resultType="com.zzsn.thinktank.vo.InfoSourceVo">
SELECT h.source_id, GROUP_CONCAT(j.group_name SEPARATOR ',') as infoSourceGroupNames,
GROUP_CONCAT(j.id SEPARATOR ',') as infoSourceGroupIds from thinktank_info_source_group_map h
LEFT JOIN
<choose>
<when test="userId !=null and userId != ''">
( select s.* from info_source_group s inner join sys_user_data_permission dp
on s.id=dp.permission_id and dp.user_id = #{userId} )
</when>
<when test="customerId !=null and customerId != ''">
( select s.* from info_source_group s inner join customer_data_permission_map m
on s.id=m.permission_id and m.customer_id = #{customerId} )
</when>
<otherwise>
info_source_group
</otherwise>
</choose>
j ON j.id = h.group_id
where h.source_id in
<foreach collection="collect" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
GROUP BY h.source_id
</select>
<select id="totalCount" resultType="Integer">
SELECT count(1) from
<choose>
<when test="userId != null and userId != ''">
(
select s.id from info_source s inner join thinktank_info_source_group_map sgm on s.id = sgm.source_id
inner join sys_user_data_permission dp on dp.permission_id = sgm.group_id
where dp.user_id = #{userId}
)
</when>
<when test="customerId != null and customerId != ''">
(
select s.id from info_source s inner join thinktank_info_source_group_map sgm on s.id = sgm.source_id
inner join customer_data_permission_map m on m.permission_id = sgm.group_id
where m.customer_id = #{customerId}
)
</when>
<otherwise>
info_source
</otherwise>
</choose>
d
LEFT JOIN info_source_type_map b ON b.source_id = d.id
where 1 = 1
<if test="typeIds!=null and typeIds.size()>0">
and b.type_id in
<foreach collection="typeIds" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
<if test="infoSourceVo.id !=null and infoSourceVo.id !=''">
and d.id = #{infoSourceVo.id}
</if>
<if test="infoSourceVo.webSiteName!=null and infoSourceVo.webSiteName != ''">
and d.web_site_name like CONCAT('%',#{infoSourceVo.webSiteName},'%')
</if>
<if test="infoSourceVo.siteName!=null and infoSourceVo.siteName != ''">
and d.site_name like CONCAT('%',#{infoSourceVo.siteName},'%')
</if>
<if test="infoSourceVo.infoSourceCode!=null and infoSourceVo.infoSourceCode != ''">
and d.info_source_code = #{infoSourceVo.infoSourceCode}
</if>
<if test="infoSourceVo.siteUri!=null and infoSourceVo.siteUri != ''">
and d.site_uri like CONCAT('%',#{infoSourceVo.siteUri},'%')
</if>
<if test="infoSourceVo.status!=null and infoSourceVo.status != ''">
and d.status = #{infoSourceVo.status}
</if>
<if test="infoSourceVo.crawlType!=null and infoSourceVo.crawlType != 0">
and d.crawl_type = #{infoSourceVo.crawlType}
</if>
<if test="infoSourceVo.createBy!=null and infoSourceVo.createBy != ''">
and d.create_by = #{infoSourceVo.createBy}
</if>
<if test="infoSourceVo.verification!=null and infoSourceVo.verification != ''">
and d.verification = #{infoSourceVo.verification}
</if>
</select>
<select id="listByGroupId" resultType="String">
SELECT a.id from info_source a
INNER JOIN thinktank_info_source_group_map b ON b.source_id = a.id
where b.group_id = #{groupId}
</select>
</mapper>
package com.zzsn.thinktank;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class ThinkTankApplicationTests {
@Test
void contextLoads() {
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论