Merge remote-tracking branch 'origin/master'
# Conflicts: # bwie-modules/bwie-home/src/main/java/com/bwie/home/controller/HouseController.javamaster
commit
f51e3064c4
|
@ -116,5 +116,6 @@
|
|||
<artifactId>fastjson2</artifactId>
|
||||
<version>2.0.42</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
package com.bwie.common.domain;
|
||||
|
||||
public class Abc {
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.bwie.common.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Chat {
|
||||
private Long ChatId;
|
||||
private Long sendId;
|
||||
private Long receiveId;
|
||||
private String chatText;
|
||||
private Integer isUp;
|
||||
@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;
|
||||
private Integer isRead;
|
||||
}
|
|
@ -8,6 +8,7 @@ import lombok.Builder;
|
|||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
|
@ -44,5 +45,5 @@ public class House {
|
|||
private Date createTime; //创建时间
|
||||
private Date updateTime; //最近更新时间
|
||||
private Integer isDelete; //逻辑删除字段
|
||||
|
||||
private Long dictionaryTypeId;
|
||||
}
|
||||
|
|
|
@ -19,4 +19,5 @@ public class HouseImages {
|
|||
private Long id; //id
|
||||
private Long houseId; //房型id
|
||||
private String imageAddr; //图片地址
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
package com.bwie.common.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
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 Info {
|
||||
/*
|
||||
id
|
||||
*/
|
||||
private Long userId;
|
||||
/*
|
||||
姓名
|
||||
*/
|
||||
private String userName;
|
||||
/*
|
||||
手机号
|
||||
*/
|
||||
private String userTel;
|
||||
|
||||
/*
|
||||
公司
|
||||
*/
|
||||
private String company;
|
||||
/*
|
||||
积分
|
||||
*/
|
||||
private Integer point;
|
||||
|
||||
/*
|
||||
登陆人身份【0-经纪人 1-用户】
|
||||
*/
|
||||
private Integer userRole;
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.bwie.common.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Message {
|
||||
private Long messageId;
|
||||
private Long userId;
|
||||
private String messageText;
|
||||
private Integer isUp;
|
||||
@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;
|
||||
private Integer isRead;
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -8,7 +8,6 @@ import org.springframework.context.annotation.Configuration;
|
|||
import org.springframework.validation.ObjectError;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
package com.bwie.common.remote.house;
|
||||
|
||||
import com.bwie.common.domain.House;
|
||||
import com.bwie.common.domain.request.HouseEsRequest;
|
||||
|
||||
import com.bwie.common.remote.house.factory.RemoteHouseFactory;
|
||||
import com.bwie.common.result.Result;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -17,4 +19,7 @@ import java.util.List;
|
|||
public interface RemoteHouseService {
|
||||
@GetMapping("/list")
|
||||
public Result<List<HouseEsRequest>> getHouseEsList();
|
||||
|
||||
@PostMapping("/shouall")
|
||||
public Result<List<House>> shouall();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.bwie.common.remote.house.factory;
|
||||
|
||||
import com.bwie.common.domain.House;
|
||||
import com.bwie.common.domain.request.HouseEsRequest;
|
||||
|
||||
import com.bwie.common.remote.house.RemoteHouseService;
|
||||
|
@ -21,6 +22,12 @@ public class RemoteHouseFactory implements FallbackFactory<RemoteHouseService> {
|
|||
log.error("远程调用失败:[{}]",cause.getMessage(),cause);
|
||||
return Result.error(cause.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<List<House>> shouall(){
|
||||
log.error("远程调用失败:[{}]",cause.getMessage(),cause);
|
||||
return Result.error(cause.getMessage());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,186 @@
|
|||
package com.bwie.chat.handle;
|
||||
|
||||
import com.bwie.chat.entry.CodeEnum;
|
||||
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.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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.bwie.es;
|
||||
|
||||
import com.bwie.common.handler.GlobalExceptionHandle;
|
||||
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;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
|
||||
@EnableFeignClients("com.bwie.**")
|
||||
@EnableDiscoveryClient
|
||||
public class EsApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(EsApplication.class);
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ import com.bwie.common.result.Result;
|
|||
import com.bwie.es.service.EsService;
|
||||
|
||||
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
@ -14,6 +15,7 @@ import java.util.List;
|
|||
|
||||
@Component
|
||||
@Log4j2
|
||||
|
||||
public class SyncHouseData {
|
||||
|
||||
private final RemoteHouseService remoteHouseService;
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
package com.bwie.home.controller;
|
||||
|
||||
import com.bwie.common.domain.House;
|
||||
import com.bwie.common.domain.request.HouseEsRequest;
|
||||
import com.bwie.common.result.Result;
|
||||
import com.bwie.home.job.Reptile;
|
||||
import com.bwie.home.service.HomeListService;
|
||||
import com.bwie.home.service.HouseService;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
|
@ -16,11 +17,11 @@ import java.util.List;
|
|||
public class HouseController {
|
||||
|
||||
private final HouseService houseService;
|
||||
private final Reptile reptile;
|
||||
|
||||
public HouseController(HouseService houseService, Reptile reptile) {
|
||||
private final HomeListService homeListService;
|
||||
public HouseController(HouseService houseService, HomeListService homeListService) {
|
||||
this.houseService = houseService;
|
||||
this.reptile = reptile;
|
||||
this.homeListService = homeListService;
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
|
@ -31,10 +32,8 @@ public class HouseController {
|
|||
}
|
||||
|
||||
|
||||
@GetMapping("/addHouse")
|
||||
private Result<String> getAddHouse() throws IOException {
|
||||
reptile.reptile();
|
||||
return Result.success();
|
||||
@PostMapping("/shouall")
|
||||
public Result<List<House>> shouall(){
|
||||
return homeListService.shouall();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
package com.bwie.home.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.bwie.common.domain.House;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface HomeListMapper extends BaseMapper<House> {
|
||||
List<House> shouall();
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package com.bwie.home.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.bwie.common.domain.House;
|
||||
import com.bwie.common.result.Result;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public interface HomeListService extends IService<House> {
|
||||
public Result<List<House>> shouall();
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.bwie.home.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.bwie.common.domain.House;
|
||||
import com.bwie.common.result.Result;
|
||||
import com.bwie.home.mapper.HomeListMapper;
|
||||
import com.bwie.home.service.HomeListService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class HomeListServiceImpl extends ServiceImpl<HomeListMapper,House> implements HomeListService {
|
||||
private final HomeListMapper listMapper;
|
||||
public HomeListServiceImpl(HomeListMapper listMapper) {
|
||||
this.listMapper = listMapper;
|
||||
}
|
||||
@Override
|
||||
public Result<List<House>> shouall(){
|
||||
List<House> list = listMapper.shouall();
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
<?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.bwie.home.mapper.HomeListMapper">
|
||||
<select id="shouall" resultType="com.bwie.common.domain.House">
|
||||
select * from house where is_success = 0
|
||||
</select>
|
||||
</mapper>
|
|
@ -8,18 +8,15 @@
|
|||
<artifactId>house_project</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>bwie-modules</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>bwie-system</module>
|
||||
<module>bwie-group</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
|
Loading…
Reference in New Issue