完成市场Bot展示与Bot模糊检索功能

This commit is contained in:
tonglin 2022-07-31 16:45:39 +08:00
parent 2abce0257f
commit 192c0f4286
38 changed files with 995 additions and 0 deletions

8
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

19
.idea/compiler.xml Normal file
View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile default="true" name="Default" enabled="true" />
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="SoftBot" />
</profile>
</annotationProcessing>
</component>
<component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
<module name="SoftBot" options="-parameters" />
</option>
</component>
</project>

6
.idea/encodings.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
</component>
</project>

20
.idea/jarRepositories.xml Normal file
View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
</component>
</project>

14
.idea/misc.xml Normal file
View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
</set>
</option>
</component>
</project>

124
.idea/uiDesigner.xml Normal file
View File

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

150
pom.xml Normal file
View File

@ -0,0 +1,150 @@
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.gitlink</groupId>
<artifactId>SoftBot</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<!-- es插件 -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.2</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-data-jdbc</artifactId>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-jdbc</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.4</version>
</dependency>
<!--用来非空校验-->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<!--DevTools 热部署的坐标-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<!-- 当前这个项目被继承之后,这个不向下传递-->
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.49</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-redis -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>clothing-manage</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!-- 没有该配置 热部署的devtools不生效-->
<configuration>
<fork>true</fork>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,14 @@
package com.gitlink.softbot;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
@SpringBootApplication
public class SoftBotApplication {
public static void main(String[] args) {
SpringApplication.run(SoftBotApplication.class,args);
}
}

View File

@ -0,0 +1,20 @@
package com.gitlink.softbot.config;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.RestClients;
import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration;
public class ElasticSearchConfig extends AbstractElasticsearchConfiguration {
@Value("${es-url}")
private String esUrl;
@Override
public RestHighLevelClient elasticsearchClient() {
final ClientConfiguration clientConfiguration = ClientConfiguration.builder()
.connectedTo(esUrl)
.build();
return RestClients.create(clientConfiguration).rest();
}
}

View File

@ -0,0 +1,44 @@
package com.gitlink.softbot.controller;
import com.gitlink.softbot.entity.es.MarketBot;
import com.gitlink.softbot.global.exception.BotException;
import com.gitlink.softbot.global.vo.Result;
import com.gitlink.softbot.service.market.IMarketService;
import com.gitlink.softbot.vo.MarketBotPagesVO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
@RestController()
public class MarketController {
@Resource
IMarketService marketService;
@GetMapping("/tt")
public String tt(){
return "asd";
}
@PostMapping("/getMarketBotsByFunc")
public Result<MarketBotPagesVO> getMarketBot(@RequestParam String func,@RequestParam int pageIndex,@RequestParam int pageSize) throws BotException {
MarketBotPagesVO marketBotPagesVO = marketService.getMarketBotByCategory(func,pageIndex,pageSize);
Result<MarketBotPagesVO> result = new Result<>();
result.setCode(200);
result.setMessage("success!");
result.setData(marketBotPagesVO);
return result;
}
@PostMapping("/getContentsLike")
public Result<MarketBotPagesVO> getMarketBotsLike(@RequestParam String keyword,@RequestParam int pageIndex,@RequestParam int pageSize) throws BotException{
MarketBotPagesVO marketBotPagesVO = marketService.getMarketBotByNameLike(keyword,pageIndex,pageSize);
Result<MarketBotPagesVO> result = new Result<>();
result.setCode(200);
result.setMessage("success!");
result.setData(marketBotPagesVO);
return result;
}
}

View File

@ -0,0 +1,7 @@
package com.gitlink.softbot.dao.db;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gitlink.softbot.entity.db.Bot;
public interface BotMapper extends BaseMapper<Bot> {
}

View File

@ -0,0 +1,12 @@
package com.gitlink.softbot.dao.es;
import com.gitlink.softbot.entity.es.MarketBot;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import java.util.List;
public interface MarketBotRepository extends ElasticsearchRepository<MarketBot,Integer> {
public List<MarketBot> findByMarketNameLike(String keyword,int pageIndex,int pageSize);
}

View File

@ -0,0 +1,46 @@
package com.gitlink.softbot.entity.db;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("bot")
public class Bot {
@TableId
private int id;
private String botId;
private String botName;
private String botDes;
private String webhook;
private int isPublic;
private String logo;
private int state;
private String clientId;
private String clientSecret;
private String webUrl;
private int category;
private Date updateTime;
private Date createTime;
}

View File

@ -0,0 +1,65 @@
package com.gitlink.softbot.entity.es;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import java.util.Date;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Document(indexName = "marketbot")
public class MarketBot {
/** 主键**/
@Id
private int id;
/** botid**/
private String botId;
/** 上市名称**/
@Field(type = FieldType.Text)
private String marketName;
/** 市场描述**/
@Field(type = FieldType.Text)
private String marketDesc;
/** 主要功能**/
@Field(type = FieldType.Text)
private String firstFunc;
/** 次要功能**/
private String secondFunc;
/** webhook**/
private String webhook;
/** 是否接收开发协议0代表节后1代表没接收没接收协议是不允许上市的**/
private int isReceiveAg1;
/** 是否接收平台协议0代表节后1代表没接收没接收协议是不允许上市的**/
private int isReceiveAg2;
/** 上市时间**/
@Field(type = FieldType.Date)
private Date marketTime;
/** 安装次数**/
@Field(type = FieldType.Integer)
private int installNum;
/** 创建时间**/
private Date createTime;
/** 更新时间**/
private Date updateTime;
}

View File

@ -0,0 +1,7 @@
package com.gitlink.softbot.global.exception;
public class BotException extends Exception{
public BotException(String message){
super(message);
}
}

View File

@ -0,0 +1,21 @@
package com.gitlink.softbot.global.exception.advice;
import com.gitlink.softbot.global.exception.BotException;
import com.gitlink.softbot.global.vo.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import javax.servlet.http.HttpServletRequest;
@RestControllerAdvice
public class GlobalExceptionAdvice {
@ExceptionHandler(value = BotException.class)
public Result<String> handleCouponException(
HttpServletRequest request, BotException exception
){
Result<String> response = new Result<>(-1,"business error!");
response.setData(exception.getMessage());
return response;
}
}

View File

@ -0,0 +1,22 @@
package com.gitlink.softbot.global.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> implements Serializable {
private Integer code;
private String message;
private T data;
public Result(Integer code,String message){
this.code = code;
this.message = message;
}
}

View File

@ -0,0 +1,22 @@
package com.gitlink.softbot.service.market;
import com.gitlink.softbot.entity.es.MarketBot;
import com.gitlink.softbot.global.exception.BotException;
import com.gitlink.softbot.vo.MarketBotPagesVO;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public interface IMarketService {
public MarketBotPagesVO getMarketBotByCategory (String func, int pageIndex, int pageSize) throws BotException;
public void saveMarketBot(MarketBot marketBot);
public Optional<MarketBot> getMarketBot(Integer id);
public void deleteMarketBot(Integer id);
public MarketBotPagesVO getMarketBotByNameLike(String keyword,int pageIndex,int pageSize) throws BotException;
}

View File

@ -0,0 +1,174 @@
package com.gitlink.softbot.service.market.impl;
import com.alibaba.fastjson.JSON;
import com.gitlink.softbot.dao.es.MarketBotRepository;
import com.gitlink.softbot.entity.es.MarketBot;
import com.gitlink.softbot.global.exception.BotException;
import com.gitlink.softbot.service.market.IMarketService;
import com.gitlink.softbot.vo.MarketBotPagesVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.lucene.search.TotalHits;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.index.query.*;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.sort.FieldSortBuilder;
import org.elasticsearch.search.sort.SortOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
@Service
@Slf4j
public class MarketService implements IMarketService {
@Autowired
private RestHighLevelClient restHighLevelClient;
@Autowired
MarketBotRepository marketBotRepository;
@Override
public void saveMarketBot(MarketBot marketBot) {
marketBotRepository.save(marketBot);
}
@Override
public Optional<MarketBot> getMarketBot(Integer id) {
return marketBotRepository.findById(id);
}
@Override
public void deleteMarketBot(Integer id) {
marketBotRepository.deleteById(id);
}
@Override
public MarketBotPagesVO getMarketBotByNameLike(String keyword, int pageIndex, int pageSize) throws BotException{
List<MarketBot> botList = new ArrayList<>();
log.info("执行Bot通过上市名称模糊查询keyword:{},pageIndex:{},pageSize:{}",keyword,pageIndex,pageSize);
long total=0;
if (StringUtils.isBlank(keyword)){
throw new BotException("keyword is null!");
}
try{
//1.创建请求
SearchRequest searchRequest = new SearchRequest("marketbot");
//分页
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.from((pageIndex-1)*pageSize+1).size(pageSize);
// QueryBuilder queryBuilder = QueryBuilders.boolQuery();
MultiMatchQueryBuilder matchQueryBuilder = QueryBuilders.multiMatchQuery(keyword, "marketName","marketDesc");
//多个条件组合
searchSourceBuilder.query(matchQueryBuilder);
//设置排序
searchSourceBuilder.sort(new FieldSortBuilder("installNum").order(SortOrder.DESC));
searchSourceBuilder.sort(new FieldSortBuilder("marketTime").order(SortOrder.DESC));
//设置一个可选的超时时间控制检索时间
searchSourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
searchRequest.source(searchSourceBuilder);
//2.执行检索请求获取检索结果
SearchResponse searchResponse = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT);
//3.解析检索结果
SearchHits hits = searchResponse.getHits();
total = hits.getTotalHits().value;
SearchHit[] searchHits = hits.getHits();
for (SearchHit hit : searchHits){
String index = hit.getIndex();//索引
String id = hit.getId();//文档id
log.info("根据marketName查询索引为{},ID为{}",index,id);
String sourceAsString = hit.getSourceAsString();
MarketBot marketBot = JSON.parseObject(sourceAsString,MarketBot.class);
botList.add(marketBot);
}
}catch (Exception e){
throw new BotException(e.getMessage());
}
MarketBotPagesVO marketBotPagesVO = new MarketBotPagesVO();
marketBotPagesVO.setBotList(botList);
marketBotPagesVO.setTotal(total);
marketBotPagesVO.setPageIndex(pageIndex);
marketBotPagesVO.setPageSize(pageSize);
return marketBotPagesVO;
}
@Override
public MarketBotPagesVO getMarketBotByCategory(String func, int pageIndex, int pageSize) throws BotException{
log.info("执行Bot根据种类检索操作func:{},pageIndex:{},pageSize{}",func,pageIndex,pageSize);
BoolQueryBuilder bdq = QueryBuilders.boolQuery();
List<MarketBot> botList = new ArrayList<>();
long total=0;
if (StringUtils.isBlank(func)){
throw new BotException("func is null");
}
try {
//1.创建检索请求
SearchRequest searchRequest = new SearchRequest("marketbot");
//分页
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.from((pageIndex-1)*pageSize+1).size(pageSize);
QueryBuilder queryBuilder = QueryBuilders.boolQuery();
//查询条件一
MatchPhraseQueryBuilder mpql = QueryBuilders.matchPhraseQuery("firstFunc", func);
((BoolQueryBuilder) queryBuilder).must(mpql);
//多个条件组合
searchSourceBuilder.query(queryBuilder);
//设置排序
searchSourceBuilder.sort(new FieldSortBuilder("installNum").order(SortOrder.DESC));
searchSourceBuilder.sort(new FieldSortBuilder("marketTime").order(SortOrder.DESC));
//设置一个可选的超时时间控制检索时间
searchSourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
searchRequest.source(searchSourceBuilder);
//2.执行检索请求获取检索结果
SearchResponse searchResponse = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT);
//3.解析检索结果
SearchHits hits = searchResponse.getHits();
total = hits.getTotalHits().value;
SearchHit[] searchHits = hits.getHits();
for (SearchHit hit : searchHits){
String index = hit.getIndex();//索引
String id = hit.getId();//文档id
log.info("根据func查询,索引为:{},ID为{}",index,id);
String sourceAsString = hit.getSourceAsString();
MarketBot marketBot = JSON.parseObject(sourceAsString,MarketBot.class);
botList.add(marketBot);
}
}catch (IOException ioException){
throw new BotException(ioException.getMessage());
}
MarketBotPagesVO marketBotPagesVO = new MarketBotPagesVO();
marketBotPagesVO.setBotList(botList);
marketBotPagesVO.setTotal(total);
marketBotPagesVO.setPageIndex(pageIndex);
marketBotPagesVO.setPageSize(pageSize);
return marketBotPagesVO;
}
}

View File

@ -0,0 +1,19 @@
package com.gitlink.softbot.vo;
import com.gitlink.softbot.entity.es.MarketBot;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@AllArgsConstructor
@NoArgsConstructor
@Data
public class MarketBotPagesVO {
private int pageIndex;
private int pageSize;
private long total;
private List<MarketBot> botList;
}

View File

@ -0,0 +1,58 @@
server:
port: 1000
es-url:
127.0.0.1:9200
spring:
datasource:
username: root
password: 123456
url: jdbc:mysql://localhost:3306/soft_bot?useUnicode=true&characterEncoding=UTF-8
driver-class-name: com.mysql.cj.jdbc.Driver
elasticsearch:
rest:
uris: http://127.0.0.1:9200
devtools:
restart:
enabled: true
additional-paths: src/main/java
poll-interval: 3000
quiet-period: 1000
mvc:
view:
prefix: /WEB-INF/jsp/
suffix: .jsp
thymeleaf:
prefix: classpath:/templates/
suffix: .html
encoding: UTF-8
redis:
database: 0
host: 101.35.140.79
port: 6379
# password:
# 连接超时时间
timeout: 10000
password: 123456
mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
mapper-locations: classpath:mapper/*.xml
#mybatis:
# mapper-locations: classpath:mapper/*.xml
# type-aliases-package: com.bishe.supermarket.pojo
# configuration:
# map-underscore-to-camel-case: true
#showSql
logging:
level:
com:
example:
mapper : debug

View File

@ -0,0 +1,55 @@
package com.gitlink.softbot.service.market;
import com.alibaba.fastjson.JSON;
import com.gitlink.softbot.entity.es.MarketBot;
import com.gitlink.softbot.global.exception.BotException;
import com.gitlink.softbot.vo.MarketBotPagesVO;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Date;
import java.util.List;
import java.util.Optional;
@SpringBootTest
@RunWith(SpringRunner.class)
public class MarketServiceTest {
@Autowired
IMarketService service;
@Test
public void test() throws BotException {
for (int i = 60; i < 80; i++) {
MarketBot marketBot = new MarketBot();
marketBot.setBotId("asd"+i);
marketBot.setMarketDesc("童asdasdas林");
marketBot.setMarketName("qqq");
marketBot.setId(i);
marketBot.setMarketTime(new Date());
marketBot.setCreateTime(new Date());
marketBot.setFirstFunc("监管");
marketBot.setInstallNum(800-i);
marketBot.setIsReceiveAg1(0);
marketBot.setIsReceiveAg2(0);
marketBot.setUpdateTime(new Date());
marketBot.setWebhook("asdasd");
marketBot.setSecondFunc("asdasdas");
service.saveMarketBot(marketBot);
Optional<MarketBot> optionalMarketBot = service.getMarketBot(i);
if (optionalMarketBot.isPresent()){
System.out.println("结果"+JSON.toJSONString(marketBot));
}
}
MarketBotPagesVO marketBotPagesVO = service.getMarketBotByCategory("监管",3,12);
System.out.println(JSON.toJSONString(marketBotPagesVO));
MarketBotPagesVO marketBotPagesVO1 = service.getMarketBotByNameLike("",3,12);
System.out.println(JSON.toJSONString(marketBotPagesVO1));
}
}

View File

@ -0,0 +1,58 @@
server:
port: 1000
es-url:
127.0.0.1:9200
spring:
datasource:
username: root
password: 123456
url: jdbc:mysql://localhost:3306/soft_bot?useUnicode=true&characterEncoding=UTF-8
driver-class-name: com.mysql.cj.jdbc.Driver
elasticsearch:
rest:
uris: http://127.0.0.1:9200
devtools:
restart:
enabled: true
additional-paths: src/main/java
poll-interval: 3000
quiet-period: 1000
mvc:
view:
prefix: /WEB-INF/jsp/
suffix: .jsp
thymeleaf:
prefix: classpath:/templates/
suffix: .html
encoding: UTF-8
redis:
database: 0
host: 101.35.140.79
port: 6379
# password:
# 连接超时时间
timeout: 10000
password: 123456
mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
mapper-locations: classpath:mapper/*.xml
#mybatis:
# mapper-locations: classpath:mapper/*.xml
# type-aliases-package: com.bishe.supermarket.pojo
# configuration:
# map-underscore-to-camel-case: true
#showSql
logging:
level:
com:
example:
mapper : debug

Binary file not shown.