Merge remote-tracking branch 'origin/master'
# Conflicts: # bwie-modules/bwie-ask/pom.xml # bwie-modules/bwie-home/src/main/java/com/bwie/home/controller/HouseController.javamaster
commit
2470ddb753
|
@ -0,0 +1,40 @@
|
||||||
|
package com.bwie.common.domain;
|
||||||
|
|
||||||
|
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.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 咨询表
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@TableName("advice")
|
||||||
|
public class Advice {
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
private Long adviceId; //咨讯
|
||||||
|
private String adviceTitle; //咨讯标题
|
||||||
|
private String adviceConment; //咨讯内容
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private Date adviceTime; //咨讯上传时间
|
||||||
|
private String adviceCome; //咨讯来源
|
||||||
|
private Integer adviceStatus; //咨讯状态
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private Date craeteTime;
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private Date updateTime;
|
||||||
|
private Integer isDelete;
|
||||||
|
}
|
|
@ -42,6 +42,7 @@ public class House {
|
||||||
private String serviceIntroduction; //服务介绍
|
private String serviceIntroduction; //服务介绍
|
||||||
private Integer managerStatus; //房源管理状态
|
private Integer managerStatus; //房源管理状态
|
||||||
private String source; //数据来源
|
private String source; //数据来源
|
||||||
|
private Integer houseOldNew; //房型类型 【0-新房 1-二手房 2-出租房】
|
||||||
private Long brokerId; //经纪人id
|
private Long brokerId; //经纪人id
|
||||||
private Integer isSuccess; //是否交易成功【0-成功 1-失败】
|
private Integer isSuccess; //是否交易成功【0-成功 1-失败】
|
||||||
private Integer verify; //是否验真【0-已验真 1-未验真】
|
private Integer verify; //是否验真【0-已验真 1-未验真】
|
||||||
|
|
|
@ -8,6 +8,9 @@ import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 房源审核表
|
||||||
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Builder
|
@Builder
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
package com.bwie.common.domain.request;
|
||||||
|
|
||||||
|
import com.bwie.common.domain.Advice;
|
||||||
|
import com.bwie.common.domain.House;
|
||||||
|
import com.bwie.common.domain.User;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class VoIndexList {
|
||||||
|
|
||||||
|
private List<House> newHouse;
|
||||||
|
|
||||||
|
private List<String> houseImage;
|
||||||
|
|
||||||
|
private List<Advice> adviceList;
|
||||||
|
|
||||||
|
private List<House> oldHouse;
|
||||||
|
|
||||||
|
private List<User> userInfo;
|
||||||
|
|
||||||
|
}
|
|
@ -18,82 +18,72 @@
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<elasticsearch.version>7.17.0</elasticsearch.version>
|
<elasticsearch.version>7.17.0</elasticsearch.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<!-- 系统公共 依赖 -->
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.baomidou</groupId>
|
|
||||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
|
||||||
<version>3.4.2</version>
|
|
||||||
</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>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.alipay.sdk</groupId>
|
|
||||||
<artifactId>alipay-sdk-java</artifactId>
|
|
||||||
<version>4.22.110.ALL</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>cn.hutool</groupId>
|
|
||||||
<artifactId>hutool-all</artifactId>
|
|
||||||
<version>5.7.20</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>org.junit.vintage</groupId>
|
|
||||||
<artifactId>junit-vintage-engine</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.cloud</groupId>
|
|
||||||
<artifactId>spring-cloud-commons</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.bwie</groupId>
|
<groupId>com.bwie</groupId>
|
||||||
<artifactId>bwie-common</artifactId>
|
<artifactId>bwie-common</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>xin.altitude.cms.common</groupId>
|
||||||
|
<artifactId>ucode-cms-common</artifactId>
|
||||||
|
<version>1.3.4</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- SpringBoot Web-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.elasticsearch.client</groupId>
|
||||||
|
<artifactId>elasticsearch-rest-high-level-client</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- Druid -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba</groupId>
|
<groupId>com.alibaba</groupId>
|
||||||
<artifactId>druid</artifactId>
|
<artifactId>druid-spring-boot-starter</artifactId>
|
||||||
<version>1.0.20</version>
|
<version>1.2.8</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- Mysql Connector -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- Mybatis 依赖配置 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mybatis.spring.boot</groupId>
|
||||||
|
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||||
|
<version>2.2.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Pagehelper -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.pagehelper</groupId>
|
||||||
|
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
||||||
|
<version>1.4.1</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- test -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
<version>3.8.1</version>
|
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>1.8</source>
|
<excludes>
|
||||||
<target>1.8</target>
|
<exclude>
|
||||||
<encoding>UTF-8</encoding>
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
</exclude>
|
||||||
|
</excludes>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Tomcat
|
# Tomcat
|
||||||
server:
|
server:
|
||||||
port: 9003
|
port: 9004
|
||||||
# Spring
|
# Spring
|
||||||
spring:
|
spring:
|
||||||
main:
|
main:
|
||||||
|
|
|
@ -66,4 +66,21 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<excludes>
|
||||||
|
<exclude>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
</exclude>
|
||||||
|
</excludes>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
package com.bwie.chat;
|
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
||||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
|
||||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
|
||||||
|
|
||||||
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
|
|
||||||
@EnableDiscoveryClient
|
|
||||||
public class ChatApp {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
SpringApplication.run(ChatApp.class);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.bwie.chat;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||||
|
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class ChatApplication extends SpringBootServletInitializer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
|
||||||
|
return builder.sources(ChatApplication.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(ChatApplication.class, args);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,151 @@
|
||||||
|
package com.bwie.chat.component;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.bwie.chat.config.ThreadPoolExecutorConfig;
|
||||||
|
import com.bwie.chat.vo.Message;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.websocket.*;
|
||||||
|
import javax.websocket.server.PathParam;
|
||||||
|
import javax.websocket.server.ServerEndpoint;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注意在websocket通信中只能传string
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@ServerEndpoint("/socket/{username}")
|
||||||
|
public class WebSocketServer {
|
||||||
|
//静态变量,用于记录当前在线连接数,应该把他设计为线程安全
|
||||||
|
private static AtomicInteger onlineNum=new AtomicInteger();
|
||||||
|
private final ThreadPoolExecutorConfig thread;
|
||||||
|
// 存储当前对象
|
||||||
|
public static final Map<String, Session> sessionMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
public WebSocketServer(ThreadPoolExecutorConfig thread) {
|
||||||
|
this.thread = thread;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void addOnlineCount(){
|
||||||
|
onlineNum.incrementAndGet();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void subOnlineCount(){
|
||||||
|
onlineNum.decrementAndGet();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AtomicInteger getOnlineNum(){
|
||||||
|
return onlineNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 建立连接
|
||||||
|
/***
|
||||||
|
* 1.把登录用户存到sessionMap中
|
||||||
|
* 2.发送给所有人当前登录人员信息
|
||||||
|
*/
|
||||||
|
@OnOpen
|
||||||
|
public void onOpen(Session session, @PathParam("username") String username) {
|
||||||
|
CompletableFuture.supplyAsync(()->{
|
||||||
|
System.out.println("当前用户名=="+username);
|
||||||
|
sessionMap.put(username, session);
|
||||||
|
addOnlineCount();
|
||||||
|
System.out.println(username+"成功连接,当前人数为"+onlineNum);
|
||||||
|
// 发送登录人员消息给所有的客户端
|
||||||
|
sendAllMessage(setUserList());
|
||||||
|
return "打开连接";
|
||||||
|
},thread.threadPoolExecutor());
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//关闭连接
|
||||||
|
/**
|
||||||
|
* 1.把登出的用户从sessionMap中剃除
|
||||||
|
* 2.发送给所有人当前登录人员信息
|
||||||
|
*/
|
||||||
|
@OnClose
|
||||||
|
public void onClose(@PathParam("username") String username) {
|
||||||
|
CompletableFuture.supplyAsync(()->{
|
||||||
|
sessionMap.remove(username);
|
||||||
|
subOnlineCount();
|
||||||
|
System.out.println(username+"断开连接,当前人数为"+onlineNum);
|
||||||
|
sendAllMessage(setUserList());
|
||||||
|
return "关闭连接";
|
||||||
|
},thread.threadPoolExecutor());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 接收处理客户端发来的数据
|
||||||
|
*/
|
||||||
|
@OnMessage
|
||||||
|
public void onMessage(String message) {
|
||||||
|
// 解析消息为java对象
|
||||||
|
Message msg = JSON.parseObject(message, Message.class);
|
||||||
|
if(StringUtils.isEmpty(msg.getTo())){
|
||||||
|
sendAllMessage(JSON.toJSONString(msg));
|
||||||
|
}else{
|
||||||
|
Session sessionTo = sessionMap.get(msg.getTo());
|
||||||
|
sendMessage(message,sessionTo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnError
|
||||||
|
public void onError(Session session, Throwable error) {
|
||||||
|
System.out.println("发生错误");
|
||||||
|
error.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String setUserList(){
|
||||||
|
ArrayList<String> list = new ArrayList<>();
|
||||||
|
for(String key:sessionMap.keySet()){
|
||||||
|
list.add(key);
|
||||||
|
}
|
||||||
|
Message message = new Message();
|
||||||
|
message.setUserNames(list);
|
||||||
|
return JSON.toJSONString(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 服务端发送消息给指定客户端
|
||||||
|
private void sendMessage(String message, Session toSession) {
|
||||||
|
CompletableFuture.supplyAsync(()->{
|
||||||
|
|
||||||
|
try {
|
||||||
|
synchronized (toSession){
|
||||||
|
toSession.getBasicRemote().sendText(message);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return "指定发送";
|
||||||
|
},thread.threadPoolExecutor());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// 服务端发送消息给所有客户端
|
||||||
|
private void sendAllMessage(String message) {
|
||||||
|
CompletableFuture.supplyAsync(()->{
|
||||||
|
for (Session session : sessionMap.values()) {
|
||||||
|
try {
|
||||||
|
synchronized (session) {
|
||||||
|
session.getBasicRemote().sendText(message);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "系统群发";
|
||||||
|
},thread.threadPoolExecutor());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.bwie.chat.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class CorsConfig implements WebMvcConfigurer {
|
||||||
|
@Override
|
||||||
|
public void addCorsMappings(CorsRegistry registry) {
|
||||||
|
// 设置允许跨域的路由
|
||||||
|
registry.addMapping("/**")
|
||||||
|
// 设置允许跨域请求的域名
|
||||||
|
.allowedOriginPatterns("*")
|
||||||
|
// 是否允许证书(cookies)
|
||||||
|
.allowCredentials(true)
|
||||||
|
// 设置允许的方法
|
||||||
|
.allowedMethods("*")
|
||||||
|
// 跨域允许时间
|
||||||
|
.maxAge(3600);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
package com.bwie.chat.config;
|
||||||
|
|
||||||
|
import com.bwie.chat.vo.ThreadPoolExecutorProperties;
|
||||||
|
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
|
||||||
|
@Log4j2
|
||||||
|
@Configuration
|
||||||
|
public class ThreadPoolExecutorConfig {
|
||||||
|
// @Value("${chat.coreSize}")
|
||||||
|
// private Integer coreSize;
|
||||||
|
// @Value("${gmall.coreMax}")
|
||||||
|
// private Integer coreMax;
|
||||||
|
|
||||||
|
private final ThreadPoolExecutorProperties threadPoolExecutorProperties;
|
||||||
|
|
||||||
|
public ThreadPoolExecutorConfig(ThreadPoolExecutorProperties threadPoolExecutorProperties) {
|
||||||
|
this.threadPoolExecutorProperties = threadPoolExecutorProperties;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ThreadPoolExecutor threadPoolExecutor(){
|
||||||
|
// int coreSize = 3 * Runtime.getRuntime().availableProcessors();
|
||||||
|
// int coreMax = coreSize + 30;
|
||||||
|
log.info("size:"+threadPoolExecutorProperties.getCoreSize()+"max:"+threadPoolExecutorProperties.getCoreMax());
|
||||||
|
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(threadPoolExecutorProperties.getCoreSize(), threadPoolExecutorProperties.getCoreMax(), 5, TimeUnit.SECONDS,
|
||||||
|
new LinkedBlockingQueue<>(100));
|
||||||
|
return threadPoolExecutor;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -4,11 +4,16 @@ import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
|
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
public class WebSocketConfig {
|
public class WebSocketConfig {
|
||||||
|
/**
|
||||||
|
* 使用springboot内置tomcat需要该bean,打war包则注释掉该bean
|
||||||
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public ServerEndpointExporter serverEndpointExporter() {
|
public ServerEndpointExporter serverEndpointExporter() {
|
||||||
return new ServerEndpointExporter();
|
return new ServerEndpointExporter();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,39 +0,0 @@
|
||||||
package com.bwie.chat.controller;
|
|
||||||
|
|
||||||
import com.bwie.chat.service.ChatServiceImpl;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
public class ChatController {
|
|
||||||
// @RequestMapping("im")
|
|
||||||
// public ModelAndView page() {
|
|
||||||
// return new ModelAndView("ws");
|
|
||||||
// }
|
|
||||||
private final ChatServiceImpl chatService;
|
|
||||||
|
|
||||||
public ChatController(ChatServiceImpl chatService) {
|
|
||||||
this.chatService = chatService;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* @Description: 消息推送
|
|
||||||
* @Method: pushToWeb
|
|
||||||
* @Param: [message, toUserId]
|
|
||||||
* @Update:
|
|
||||||
* @since: 1.0.0
|
|
||||||
* @Return: org.springframework.http.ResponseEntity<java.lang.String>
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@RequestMapping("/push")
|
|
||||||
public ResponseEntity<String> pushToWeb(@RequestParam String message, Long toUserId) throws Exception {
|
|
||||||
|
|
||||||
boolean flag = chatService.sendInfo(message, toUserId.toString());
|
|
||||||
return flag == true ? ResponseEntity.ok("消息推送成功...") :
|
|
||||||
ResponseEntity.ok("消息推送失败,用户不在线...");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,29 +0,0 @@
|
||||||
package com.bwie.chat.entry;
|
|
||||||
|
|
||||||
public enum CodeEnum {
|
|
||||||
// 成功
|
|
||||||
SERVER_TO(0,"首次连接,推送消息"),
|
|
||||||
SESSION_ID(1,"连接id"),
|
|
||||||
MESSAGE(2,"消息"),
|
|
||||||
ONLINE_USERS(3,"在线用户"),
|
|
||||||
NOTICE(4,"公告"),
|
|
||||||
NOT_USERNAME(401,"没有用户名"),
|
|
||||||
SUCCESS(200,"操作成功");
|
|
||||||
|
|
||||||
int code;
|
|
||||||
String msg;
|
|
||||||
|
|
||||||
CodeEnum(int code, String errorMessage) {
|
|
||||||
this.code = code;
|
|
||||||
this.msg = errorMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCode() {
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMsg() {
|
|
||||||
return msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,188 +0,0 @@
|
||||||
//package com.bwie.chat.handle;
|
|
||||||
//
|
|
||||||
//import com.bwie.chat.entry.CodeEnum;
|
|
||||||
//import com.bwie.common.domain.User;
|
|
||||||
//import com.bwie.common.result.Result;
|
|
||||||
//import com.mysql.cj.protocol.x.Notice;
|
|
||||||
//import lombok.extern.slf4j.Slf4j;
|
|
||||||
//import org.springframework.web.socket.*;
|
|
||||||
//
|
|
||||||
//import java.io.IOException;
|
|
||||||
//import java.time.format.DateTimeFormatter;
|
|
||||||
//import java.util.ArrayList;
|
|
||||||
//import java.util.List;
|
|
||||||
//import java.util.Map;
|
|
||||||
//import java.util.Set;
|
|
||||||
//import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
//import java.util.stream.Collectors;
|
|
||||||
//
|
|
||||||
//@Slf4j
|
|
||||||
//public class WebScoketHandle implements WebSocketHandler {
|
|
||||||
// // 存放 sessionId 与 session
|
|
||||||
// private static Map<String,WebSocketSession> SESSIONS = new ConcurrentHashMap<>();
|
|
||||||
// // 在线用户列表
|
|
||||||
// private static List<User> ONLINE_USERS = new ArrayList<>();
|
|
||||||
// // 消息列表
|
|
||||||
// private static List <Message> msgList = new ArrayList<>();
|
|
||||||
// // 公告
|
|
||||||
// private static Notice notice = new Notice();
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * WebSocket 连接建立后调用的方法,通常用于处理连接建立后的业务逻辑。
|
|
||||||
// * @param session
|
|
||||||
// * @throws Exception
|
|
||||||
// */
|
|
||||||
// @Override
|
|
||||||
// public void afterConnectionEstablished(WebSocketSession session) throws Exception {
|
|
||||||
// log.info("WebSocket 连接已打开:" + session.getId());
|
|
||||||
// // 获取请求路径 判断是否携带用户名
|
|
||||||
// String uri = session.getUri().toString();
|
|
||||||
// // ws://localhost:8080/username=zxwy&id=1
|
|
||||||
// log.info(uri);
|
|
||||||
// // 获取id 与 用户名
|
|
||||||
// String id = uri.substring(uri.lastIndexOf('=')+1);
|
|
||||||
// uri = uri.substring(0,uri.lastIndexOf('&'));
|
|
||||||
// String username = uri.substring(uri.lastIndexOf('=')+1);
|
|
||||||
//
|
|
||||||
// if ("".equals(username)){
|
|
||||||
// session.sendMessage(new TextMessage(JsonUtils.toJson(Result.error(CodeEnum.NOT_USERNAME))));
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// User user = new User();
|
|
||||||
// user.setUsername(username);
|
|
||||||
// user.setId(Integer.valueOf(id));
|
|
||||||
//
|
|
||||||
// // 判断当前用户是否已经连接过
|
|
||||||
// List<User> onlineUser = ONLINE_USERS.stream()
|
|
||||||
// .filter(tmp -> tmp.getId()==user.getId())
|
|
||||||
// .collect(Collectors.toList());
|
|
||||||
// // 如果存在相同用户已经登录 删除之前登录的session并关闭
|
|
||||||
// if (onlineUser.size() != 0){
|
|
||||||
// delSessionById(onlineUser.get(0).getId());
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// SESSIONS.put(session.getId(),session);
|
|
||||||
// // 将用户添加到在线列表
|
|
||||||
// ONLINE_USERS.add(user);
|
|
||||||
//
|
|
||||||
// session.getAttributes().put(session.getId(),user);
|
|
||||||
// session.getAttributes().put("sessionId",session.getId());
|
|
||||||
//
|
|
||||||
// // 将连接id推送给前端
|
|
||||||
// session.sendMessage(new TextMessage(JsonUtils.toJson(Result.set(CodeEnum.SESSION_ID,session.getId(),null))));
|
|
||||||
// // 推送在线列表
|
|
||||||
// pushOnlineUser();
|
|
||||||
// // 推送公告
|
|
||||||
// pushNotice(session);
|
|
||||||
// // 首次连接推送所有消息
|
|
||||||
// session.sendMessage(new TextMessage(JsonUtils.toJson(Result.set(CodeEnum.SERVER_TO,null,msgList))));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * handleTextMessage: 处理接收到的文本消息。
|
|
||||||
// * @param session
|
|
||||||
// * @param message 前端发送的消息
|
|
||||||
// * @throws Exception
|
|
||||||
// */
|
|
||||||
// @Override
|
|
||||||
// public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
|
|
||||||
// log.info("收到 WebSocket 消息:" + message.getPayload().toString());
|
|
||||||
//
|
|
||||||
// Result result = JsonUtils.parse(message.getPayload().toString(),Result.class);
|
|
||||||
// userMsg userMsg = JsonUtils.parse(result.getData().toString(), userMsg.class);
|
|
||||||
// String username = userMsg.getUser().getUsername();
|
|
||||||
// long id = userMsg.getUser().getId();
|
|
||||||
// if (username == null || "".equals(username)){
|
|
||||||
// session.sendMessage(new TextMessage(JsonUtils.toJson(Result.error(CodeEnum.NOT_USERNAME))));
|
|
||||||
// }
|
|
||||||
// String mtext = userMsg.getMessageInput();
|
|
||||||
// // 指令 清空消息
|
|
||||||
// if (mtext.substring(0,1).equals("$")){
|
|
||||||
// if (mtext.equals("$clear")&&id==1){
|
|
||||||
// msgList.removeAll(msgList);
|
|
||||||
// broadcast(JsonUtils.toJson(Result.set(CodeEnum.SERVER_TO,null,msgList)));
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// // 指令 发送公告
|
|
||||||
// if (mtext.substring(0,3).equals("$gg")&&id==1){
|
|
||||||
// notice.setTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss")));
|
|
||||||
// notice.setGg(mtext.substring(3));
|
|
||||||
// broadcast(JsonUtils.toJson(Result.set(CodeEnum.NOTICE,null,notice)));
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// // 普通消息
|
|
||||||
// Message msg = new Message();
|
|
||||||
// msg.setId(msgList.size());
|
|
||||||
// msg.setSender(username);
|
|
||||||
// msg.setTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss")));
|
|
||||||
// msg.setText(mtext);
|
|
||||||
// // 广播消息给所有连接的客户端
|
|
||||||
// msgList.add(msg);
|
|
||||||
// if (msgList.size()==60)
|
|
||||||
// msgList.remove(0);
|
|
||||||
// broadcast(JsonUtils.toJson(Result.set(CodeEnum.MESSAGE,session.getId(),msg)));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
|
|
||||||
// log.info("WebSocket 连接错误:" + session.getId() + ", " + exception.getMessage());
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws Exception {
|
|
||||||
// log.info("WebSocket 连接已关闭:" + session.getId());
|
|
||||||
// // 移除session id与websocket连接的映射关系
|
|
||||||
// User user = (User) session.getAttributes().get(session.getId());
|
|
||||||
// ONLINE_USERS.remove(user);
|
|
||||||
// String sessionId = (String) session.getAttributes().get("sessionId");
|
|
||||||
// if (sessionId != null) {
|
|
||||||
// SESSIONS.remove(sessionId);
|
|
||||||
// session.close();
|
|
||||||
// }
|
|
||||||
// pushOnlineUser();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public boolean supportsPartialMessages() {
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private void broadcast(String message) throws IOException {
|
|
||||||
// Set<Map.Entry<String, WebSocketSession>> entries = SESSIONS.entrySet();
|
|
||||||
// for (Map.Entry<String, WebSocketSession> sessions : entries) {
|
|
||||||
// if(sessions.getValue().isOpen()){
|
|
||||||
// sessions.getValue().sendMessage(new TextMessage(message));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // 推送在线列表
|
|
||||||
// private void pushOnlineUser() throws Exception{
|
|
||||||
//
|
|
||||||
// broadcast(JsonUtils.toJson(Result.set(CodeEnum.ONLINE_USERS,null,ONLINE_USERS)));
|
|
||||||
// }
|
|
||||||
// // 推送公告
|
|
||||||
// private void pushNotice(WebSocketSession session) throws Exception{
|
|
||||||
// session.sendMessage(new TextMessage(JsonUtils.toJson
|
|
||||||
// (Result.set(CodeEnum.NOTICE,null,notice))));
|
|
||||||
// }
|
|
||||||
// private void delSessionById(long id) throws Exception{
|
|
||||||
// Set<Map.Entry<String, WebSocketSession>> entries = SESSIONS.entrySet();
|
|
||||||
// for (Map.Entry<String, WebSocketSession> sessions : entries) {
|
|
||||||
// User user = (User)sessions.getValue().getAttributes().get(sessions.getValue().getId());
|
|
||||||
// if (user.getId()==id){
|
|
||||||
// String sessionId = (String) sessions.getValue().getAttributes().get("sessionId");
|
|
||||||
// if (sessionId != null) {
|
|
||||||
// SESSIONS.remove(sessionId);
|
|
||||||
// sessions.getValue().close();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//}
|
|
|
@ -1,4 +0,0 @@
|
||||||
package com.bwie.chat.mapper;
|
|
||||||
|
|
||||||
public interface ChatMapper {
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
package com.bwie.chat.service;
|
|
||||||
|
|
||||||
public interface ChatService {
|
|
||||||
// public boolean sendInfo(String message, String toUserId);
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,170 +0,0 @@
|
||||||
package com.bwie.chat.service;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import javax.websocket.OnClose;
|
|
||||||
import javax.websocket.OnMessage;
|
|
||||||
import javax.websocket.OnOpen;
|
|
||||||
import javax.websocket.Session;
|
|
||||||
import javax.websocket.server.PathParam;
|
|
||||||
import javax.websocket.server.ServerEndpoint;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
/**
|
|
||||||
* @Class: ChatServiceImpl
|
|
||||||
* @Description: 连接、消息管理
|
|
||||||
*/
|
|
||||||
//@ServerEndpoint("/ws/{userId}")
|
|
||||||
@Component
|
|
||||||
public class ChatServiceImpl{
|
|
||||||
//日志
|
|
||||||
static Log log = LogFactory.getLog(ChatServiceImpl.class);
|
|
||||||
//在线数量
|
|
||||||
private static final AtomicInteger onlineCount = new AtomicInteger(0);
|
|
||||||
//处理客户端连接socket
|
|
||||||
private static Map<String, ChatServiceImpl> webSocketMap = new
|
|
||||||
ConcurrentHashMap<>();
|
|
||||||
//会话信息
|
|
||||||
private Session session;
|
|
||||||
//用户信息
|
|
||||||
private String userId = "";
|
|
||||||
/*
|
|
||||||
* @Description: 打开WebSokcet连接
|
|
||||||
* @Method: onOPen
|
|
||||||
* @Param: [userId, session]
|
|
||||||
* @Update:
|
|
||||||
* @since: 1.0.0
|
|
||||||
* @Return: void
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@OnOpen
|
|
||||||
public void onOPen(@PathParam("userId") String userId, Session session) {
|
|
||||||
//处理session和用户信息
|
|
||||||
this.session = session;
|
|
||||||
this.userId = userId;
|
|
||||||
if (webSocketMap.containsKey(userId)) {
|
|
||||||
webSocketMap.remove(userId);
|
|
||||||
webSocketMap.put(userId, this);
|
|
||||||
} else {
|
|
||||||
webSocketMap.put(userId, this);
|
|
||||||
//增加在线人数
|
|
||||||
addOnlineCount();
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
//处理连接成功消息的发送
|
|
||||||
sendMessage("Server>>>>远程WebSoket连接成功");
|
|
||||||
log.info("用户" + userId + "成功连接,当前的在线人数为" +
|
|
||||||
getOnlineCount());
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* @Description: 关闭连接
|
|
||||||
* @Method: onClose
|
|
||||||
* @Param: []
|
|
||||||
* @Update:
|
|
||||||
* @since: 1.0.0
|
|
||||||
* @Return: void
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@OnClose
|
|
||||||
public void onClose() {
|
|
||||||
if (webSocketMap.containsKey(userId)) {
|
|
||||||
webSocketMap.remove(userId);
|
|
||||||
subOnlineCount();
|
|
||||||
}
|
|
||||||
log.info("用户退出....");
|
|
||||||
}
|
|
||||||
public static void subOnlineCount() {
|
|
||||||
ChatServiceImpl.onlineCount.decrementAndGet();
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* @Description:消息中转
|
|
||||||
* @Method: onMessage
|
|
||||||
* @Param: [message, session]
|
|
||||||
* @Update:
|
|
||||||
* @since: 1.0.0
|
|
||||||
* @Return: void
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@OnMessage
|
|
||||||
public void onMessage(String message, Session session) {
|
|
||||||
if (StringUtils.isNotEmpty(message)) {
|
|
||||||
try {
|
|
||||||
//解析消息
|
|
||||||
JSONObject jsonObject = JSON.parseObject(message);
|
|
||||||
String toUserId = jsonObject.getString("toUserId");
|
|
||||||
String msg = jsonObject.getString("msg");
|
|
||||||
if (StringUtils.isNotEmpty(toUserId)&&webSocketMap.containsKey(toUserId)) {
|
|
||||||
webSocketMap.get(toUserId).sendMessage(msg);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* @Description: 服务端向客户端发送数据
|
|
||||||
* @Method: sendMessage
|
|
||||||
* @Param: [s]
|
|
||||||
* @Update:
|
|
||||||
* @since: 1.0.0
|
|
||||||
* @Return: void
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public void sendMessage(String s) throws IOException {
|
|
||||||
this.session.getBasicRemote().sendText(s);
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* @Description: 获取在线人数的数量
|
|
||||||
* @Method: getOnlineCount
|
|
||||||
* @Param: []
|
|
||||||
* @Update:
|
|
||||||
* @since: 1.0.0
|
|
||||||
* @Return: java.util.concurrent.atomic.AtomicInteger
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public static AtomicInteger getOnlineCount() {
|
|
||||||
return onlineCount;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* @Description: 增加在线人数
|
|
||||||
* @Method: addOnlineCount
|
|
||||||
* @Param: []
|
|
||||||
* @Update:
|
|
||||||
* @since: 1.0.0
|
|
||||||
* @Return: void
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public static void addOnlineCount() {
|
|
||||||
ChatServiceImpl.onlineCount.incrementAndGet();
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* @Description: 服务器消息推送
|
|
||||||
* @Method: sendInfo
|
|
||||||
* @Param: [message, userId]
|
|
||||||
* @Update:
|
|
||||||
* @since: 1.0.0
|
|
||||||
* @Return: void
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
public static boolean sendInfo(String message, String userId) throws IOException {
|
|
||||||
boolean flag=true;
|
|
||||||
if (StringUtils.isNotEmpty(userId) && webSocketMap.containsKey(userId))
|
|
||||||
{
|
|
||||||
webSocketMap.get(userId).sendMessage(message);
|
|
||||||
} else {
|
|
||||||
log.error("用户" + userId + "不在线");
|
|
||||||
flag=false;
|
|
||||||
}
|
|
||||||
return flag;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
package com.bwie.chat.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class Message {
|
||||||
|
// 时间
|
||||||
|
private String time;
|
||||||
|
// 接收方
|
||||||
|
private String to;
|
||||||
|
// 发送方
|
||||||
|
private String from;
|
||||||
|
// 消息
|
||||||
|
private String msg;
|
||||||
|
// 登录用户名
|
||||||
|
private List<String> userNames;
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.bwie.chat.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@ConfigurationProperties(prefix = "chat")
|
||||||
|
@Data
|
||||||
|
public class ThreadPoolExecutorProperties {
|
||||||
|
private Integer coreSize;
|
||||||
|
private Integer coreMax;
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
# Tomcat
|
||||||
|
server:
|
||||||
|
port: 9003
|
||||||
|
# Spring
|
||||||
|
spring:
|
||||||
|
main:
|
||||||
|
allow-circular-references: true
|
||||||
|
allow-bean-definition-overriding: true
|
||||||
|
jackson:
|
||||||
|
date-format: yyyy-MM-dd HH:mm:ss
|
||||||
|
time-zone: GMT+8
|
||||||
|
application:
|
||||||
|
# 应用名称
|
||||||
|
name: bwie-chat
|
||||||
|
profiles:
|
||||||
|
# 环境配置
|
||||||
|
active: dev
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
discovery:
|
||||||
|
# 服务注册地址
|
||||||
|
server-addr: 124.221.177.197:8848
|
||||||
|
config:
|
||||||
|
# 配置中心地址
|
||||||
|
server-addr: 124.221.177.197:8848
|
||||||
|
# 配置文件格式
|
||||||
|
file-extension: yml
|
||||||
|
# 共享配置
|
||||||
|
shared-configs:
|
||||||
|
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
|
chat:
|
||||||
|
coreSize: 21
|
||||||
|
coreMax: 51
|
|
@ -53,6 +53,13 @@
|
||||||
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
||||||
<version>1.4.1</version>
|
<version>1.4.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- xxl-job依赖 -->
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.xuxueli</groupId>
|
||||||
|
<artifactId>xxl-job-core</artifactId>
|
||||||
|
<version>2.3.1</version>
|
||||||
|
</dependency>
|
||||||
<!--爬虫jsoup-->
|
<!--爬虫jsoup-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jsoup</groupId>
|
<groupId>org.jsoup</groupId>
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.bwie.home.controller;
|
package com.bwie.home.controller;
|
||||||
|
|
||||||
import com.bwie.common.domain.House;
|
import com.bwie.common.domain.House;
|
||||||
import com.bwie.common.domain.Order;
|
|
||||||
import com.bwie.common.domain.request.HouseEsRequest;
|
import com.bwie.common.domain.request.HouseEsRequest;
|
||||||
|
import com.bwie.common.domain.request.VoIndexList;
|
||||||
import com.bwie.common.result.Result;
|
import com.bwie.common.result.Result;
|
||||||
import com.bwie.home.job.Reptile;
|
import com.bwie.home.job.Reptile;
|
||||||
import com.bwie.home.service.HomeListService;
|
import com.bwie.home.service.HomeListService;
|
||||||
|
@ -33,11 +33,7 @@ public class HouseController {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//添加订单表
|
|
||||||
@PostMapping("/wayOrdersPayment")
|
|
||||||
public Result wayOrdersPayment(@RequestBody Order order){
|
|
||||||
return homeListService.wayOrdersPayment(order);
|
|
||||||
}
|
|
||||||
@GetMapping("/shouall")
|
@GetMapping("/shouall")
|
||||||
public Result<List<House>> shouall(){
|
public Result<List<House>> shouall(){
|
||||||
return homeListService.shouall();
|
return homeListService.shouall();
|
||||||
|
@ -49,18 +45,10 @@ public class HouseController {
|
||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/addTwoHouse")
|
@GetMapping("/index")
|
||||||
public Result addTwoHouse(@RequestBody House house){
|
public Result<VoIndexList> getIndexList(){
|
||||||
return homeListService.addTwoHouse(house);
|
return Result.success(
|
||||||
|
houseService.getIndexList()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/chaId")
|
|
||||||
public Result<House> chaId(@RequestParam Integer houseId){
|
|
||||||
return homeListService.chaId(houseId);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,6 @@ public class ReptileJob {
|
||||||
reptile.reptile(bkUrl);
|
reptile.reptile(bkUrl);
|
||||||
redisCache.redisTemplate.opsForList().rightPush(url, bkUrl);
|
redisCache.redisTemplate.opsForList().rightPush(url, bkUrl);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.bwie.home.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.bwie.common.domain.Advice;
|
||||||
|
|
||||||
|
public interface AdviceMapper extends BaseMapper<Advice> {
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.bwie.home.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.bwie.common.domain.User;
|
||||||
|
|
||||||
|
public interface UserMapper extends BaseMapper<User> {
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.bwie.home.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.bwie.common.domain.Advice;
|
||||||
|
|
||||||
|
public interface AdviceService extends IService<Advice> {
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ package com.bwie.home.service;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.bwie.common.domain.House;
|
import com.bwie.common.domain.House;
|
||||||
import com.bwie.common.domain.request.HouseEsRequest;
|
import com.bwie.common.domain.request.HouseEsRequest;
|
||||||
|
import com.bwie.common.domain.request.VoIndexList;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -14,4 +15,10 @@ public interface HouseService extends IService<House> {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<HouseEsRequest> getHouseEsList();
|
List<HouseEsRequest> getHouseEsList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取首页信息
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
VoIndexList getIndexList();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.bwie.home.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.bwie.common.domain.User;
|
||||||
|
|
||||||
|
public interface UserService extends IService<User> {
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.bwie.home.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.bwie.common.domain.Advice;
|
||||||
|
import com.bwie.home.mapper.AdviceMapper;
|
||||||
|
import com.bwie.home.service.AdviceService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class AdviceServiceImpl extends ServiceImpl<AdviceMapper, Advice>
|
||||||
|
implements AdviceService {
|
||||||
|
|
||||||
|
}
|
|
@ -2,20 +2,19 @@ package com.bwie.home.service.impl;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.bwie.common.domain.DictionaryType;
|
import com.bwie.common.domain.*;
|
||||||
import com.bwie.common.domain.House;
|
|
||||||
import com.bwie.common.domain.HouseImages;
|
|
||||||
import com.bwie.common.domain.HouseType;
|
|
||||||
import com.bwie.common.domain.request.HouseEsRequest;
|
import com.bwie.common.domain.request.HouseEsRequest;
|
||||||
|
import com.bwie.common.domain.request.VoIndexList;
|
||||||
import com.bwie.home.mapper.HouseMapper;
|
import com.bwie.home.mapper.HouseMapper;
|
||||||
import com.bwie.home.service.DictionaryTypeService;
|
import com.bwie.home.service.*;
|
||||||
import com.bwie.home.service.HouseImagesService;
|
|
||||||
import com.bwie.home.service.HouseService;
|
|
||||||
import com.bwie.home.service.HouseTypeService;
|
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@ -25,13 +24,22 @@ public class HouseServiceImpl extends ServiceImpl<HouseMapper, House>
|
||||||
private final HouseTypeService houseTypeService;
|
private final HouseTypeService houseTypeService;
|
||||||
private final DictionaryTypeService dictionaryTypeService;
|
private final DictionaryTypeService dictionaryTypeService;
|
||||||
private final HouseImagesService houseImagesService;
|
private final HouseImagesService houseImagesService;
|
||||||
|
private final UserService userService;
|
||||||
|
private final AdviceService adviceService;
|
||||||
|
private final Executor executor;
|
||||||
|
|
||||||
|
|
||||||
public HouseServiceImpl(HouseTypeService houseTypeService,
|
public HouseServiceImpl(HouseTypeService houseTypeService,
|
||||||
DictionaryTypeService dictionaryTypeService,
|
DictionaryTypeService dictionaryTypeService,
|
||||||
HouseImagesService houseImagesService) {
|
HouseImagesService houseImagesService,
|
||||||
|
UserService userService,
|
||||||
|
AdviceService adviceService, Executor executor) {
|
||||||
this.houseTypeService = houseTypeService;
|
this.houseTypeService = houseTypeService;
|
||||||
this.dictionaryTypeService = dictionaryTypeService;
|
this.dictionaryTypeService = dictionaryTypeService;
|
||||||
this.houseImagesService = houseImagesService;
|
this.houseImagesService = houseImagesService;
|
||||||
|
this.userService = userService;
|
||||||
|
this.adviceService = adviceService;
|
||||||
|
this.executor = executor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -56,4 +64,63 @@ public class HouseServiceImpl extends ServiceImpl<HouseMapper, House>
|
||||||
|
|
||||||
return esRequestList;
|
return esRequestList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VoIndexList getIndexList() {
|
||||||
|
|
||||||
|
CountDownLatch countDownLatch = new CountDownLatch(5);
|
||||||
|
VoIndexList voIndexList = new VoIndexList();
|
||||||
|
|
||||||
|
//横幅信息
|
||||||
|
CompletableFuture<List<HouseImages>> f1 = CompletableFuture.supplyAsync(() -> {
|
||||||
|
List<HouseImages> list = houseImagesService.list(new LambdaQueryWrapper<HouseImages>().eq(HouseImages::getHouseId, 0));
|
||||||
|
countDownLatch.countDown();
|
||||||
|
return list;
|
||||||
|
}, executor);
|
||||||
|
|
||||||
|
// 经纪人信息
|
||||||
|
CompletableFuture<List<User>> f2 = CompletableFuture.supplyAsync(() -> {
|
||||||
|
List<User> list = userService.list();
|
||||||
|
countDownLatch.countDown();
|
||||||
|
return list;
|
||||||
|
}, executor);
|
||||||
|
|
||||||
|
//咨询
|
||||||
|
CompletableFuture<List<Advice>> f3 = CompletableFuture.supplyAsync(() -> {
|
||||||
|
List<Advice> list = adviceService.list();
|
||||||
|
countDownLatch.countDown();
|
||||||
|
return list;
|
||||||
|
}, executor);
|
||||||
|
|
||||||
|
//新房
|
||||||
|
CompletableFuture<List<House>> f4 = CompletableFuture.supplyAsync(() -> {
|
||||||
|
List<House> list = this.list(new LambdaQueryWrapper<House>().last("LIMIT" + 5));
|
||||||
|
countDownLatch.countDown();
|
||||||
|
return list;
|
||||||
|
}, executor);
|
||||||
|
|
||||||
|
//二手房
|
||||||
|
CompletableFuture<List<House>> f5 = CompletableFuture.supplyAsync(() -> {
|
||||||
|
List<House> list = this.list(new LambdaQueryWrapper<House>().last("LIMIT" + 5));
|
||||||
|
countDownLatch.countDown();
|
||||||
|
return list;
|
||||||
|
}, executor);
|
||||||
|
|
||||||
|
try {
|
||||||
|
countDownLatch.await();
|
||||||
|
List<HouseImages> houseImages = f1.get();
|
||||||
|
List<String> imageList = houseImages.stream().map(HouseImages::getImageAddr).collect(Collectors.toList());
|
||||||
|
voIndexList.setHouseImage(imageList);//横幅信息
|
||||||
|
voIndexList.setUserInfo(f2.get());
|
||||||
|
voIndexList.setAdviceList(f3.get());
|
||||||
|
// voIndexList.setNewHouse(f4.get());
|
||||||
|
// voIndexList.setOldHouse(f5.get());
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return voIndexList;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.bwie.home.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.bwie.common.domain.User;
|
||||||
|
import com.bwie.home.mapper.UserMapper;
|
||||||
|
import com.bwie.home.service.UserService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
|
||||||
|
implements UserService {
|
||||||
|
}
|
|
@ -19,6 +19,7 @@ public class UserController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserService userService;
|
private UserService userService;
|
||||||
|
|
||||||
|
|
||||||
public UserController(UserService userService) {
|
public UserController(UserService userService) {
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
}
|
}
|
||||||
|
@ -29,6 +30,7 @@ public class UserController {
|
||||||
|
|
||||||
return Result.success(
|
return Result.success(
|
||||||
userService.login(loginRequest)
|
userService.login(loginRequest)
|
||||||
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,10 +16,14 @@
|
||||||
<module>bwie-Alipay</module>
|
<module>bwie-Alipay</module>
|
||||||
</modules>
|
</modules>
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>8</maven.compiler.source>
|
|
||||||
<maven.compiler.target>8</maven.compiler.target>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
|
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||||
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.elasticsearch</groupId>
|
<groupId>org.elasticsearch</groupId>
|
||||||
|
|
2
pom.xml
2
pom.xml
|
@ -25,7 +25,9 @@
|
||||||
<maven.compiler.source>8</maven.compiler.source>
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
<maven.compiler.target>8</maven.compiler.target>
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.elasticsearch</groupId>
|
<groupId>org.elasticsearch</groupId>
|
||||||
|
|
Loading…
Reference in New Issue