编写故障日志的代码与站内信的代码

dev.saas.customer
冷调 2024-09-21 19:55:46 +08:00
parent 063dff79a1
commit 43d806b857
18 changed files with 462 additions and 145 deletions

View File

@ -1,93 +1,93 @@
package com.muyu.breakdown.DTO; //package com.muyu.breakdown.DTO;
//
//
import com.muyu.breakdown.domain.Messages; //import com.muyu.breakdown.domain.Messages;
import org.springframework.beans.factory.annotation.Autowired; //import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; //import org.springframework.stereotype.Component;
//
import java.sql.*; //import java.sql.*;
import java.util.*; //import java.util.*;
//
/** ///**
* @ ToolIntelliJ IDEA // * @ ToolIntelliJ IDEA
* @ AuthorCHX // * @ AuthorCHX
* @ Date2024-09-18-15:00 // * @ Date2024-09-18-15:00
* @ Version1.0 // * @ Version1.0
* @ Description // * @ Description数据库连接层
* @author Lenovo // * @author Lenovo
*/ // */
@Component //@Component
public class MessageDTO { //public class MessageDTO {
private static final String DB_URL = "jdbc:mysql://106.54.193.225:3306/one"; // private static final String DB_URL = "jdbc:mysql://106.54.193.225:3306/one";
private static final String USER = "root"; // private static final String USER = "root";
private static final String PASSWORD = "bawei2112A"; // private static final String PASSWORD = "bawei2112A";
//
// 2. 建立数据库连接 // // 2. 建立数据库连接
Connection connection; // Connection connection;
// 构造函数,初始化数据库连接 // // 构造函数,初始化数据库连接
// 保存消息到数据库 // // 保存消息到数据库
public void saveMessage(Messages message) { // public void saveMessage(Messages message) {
String sql = "INSERT INTO sys_messages (sender_id, receiver_id, content) VALUES (?, ?, ?)"; // String sql = "INSERT INTO sys_messages (sender_id, receiver_id, content) VALUES (?, ?, ?)";
try { // try {
Class.forName("com.mysql.cj.jdbc.Driver"); // Class.forName("com.mysql.cj.jdbc.Driver");
} catch (ClassNotFoundException e) { // } catch (ClassNotFoundException e) {
throw new RuntimeException(e); // throw new RuntimeException(e);
} // }
try { // try {
connection = DriverManager.getConnection(DB_URL, USER, PASSWORD); // connection = DriverManager.getConnection(DB_URL, USER, PASSWORD);
} catch (SQLException e) { // } catch (SQLException e) {
throw new RuntimeException(e); // throw new RuntimeException(e);
} // }
try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) { // try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
preparedStatement.setInt(1, message.getSenderId()); // preparedStatement.setInt(1, message.getSenderId());
preparedStatement.setInt(2, message.getReceiverId()); // preparedStatement.setInt(2, message.getReceiverId());
preparedStatement.setString(3, message.getContent()); // preparedStatement.setString(3, message.getContent());
// 执行添加操作 // // 执行添加操作
preparedStatement.executeUpdate(); // preparedStatement.executeUpdate();
} catch (SQLException e) { // } catch (SQLException e) {
throw new RuntimeException(e); // throw new RuntimeException(e);
} // }
try { // try {
connection.close(); // connection.close();
} catch (SQLException e) { // } catch (SQLException e) {
throw new RuntimeException(e); // throw new RuntimeException(e);
} // }
} // }
//
// 获取所有消息 // // 获取所有消息
public List<Messages> getAllMessages(int receiverId){ // public List<Messages> getAllMessages(int receiverId){
String sql = "SELECT * FROM sys_messages WHERE receiver_id = ?"; // String sql = "SELECT * FROM sys_messages WHERE receiver_id = ?";
try { // try {
Class.forName("com.mysql.cj.jdbc.Driver"); // Class.forName("com.mysql.cj.jdbc.Driver");
} catch (ClassNotFoundException e) { // } catch (ClassNotFoundException e) {
throw new RuntimeException(e); // throw new RuntimeException(e);
} // }
List<Messages> messages = new ArrayList<>(); // List<Messages> messages = new ArrayList<>();
try { // try {
connection = DriverManager.getConnection(DB_URL, USER, PASSWORD); // connection = DriverManager.getConnection(DB_URL, USER, PASSWORD);
} catch (SQLException e) { // } catch (SQLException e) {
throw new RuntimeException(e); // throw new RuntimeException(e);
} // }
try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) { // try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
preparedStatement.setInt(1, receiverId); // preparedStatement.setInt(1, receiverId);
// 执行查询操作 // // 执行查询操作
ResultSet rs = preparedStatement.executeQuery(); // ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) { // while (rs.next()) {
Messages message = new Messages(rs.getInt("sender_id"), receiverId, rs.getString("content")); // Messages message = new Messages(rs.getInt("sender_id"), receiverId, rs.getString("content"));
//
// 添加到消息列表 // // 添加到消息列表
messages.add(message); // messages.add(message);
} // }
} catch (SQLException e) { // } catch (SQLException e) {
throw new RuntimeException(e); // throw new RuntimeException(e);
} // }
try { // try {
connection.close(); // connection.close();
} catch (SQLException e) { // } catch (SQLException e) {
throw new RuntimeException(e); // throw new RuntimeException(e);
} // }
// 返回消息列表 // // 返回消息列表
return messages; // return messages;
} // }
//
} //}

View File

@ -52,16 +52,4 @@ public class FaultLog extends BaseEntity{
@Excel(name = "结束报警时间", width = 30, dateFormat = "yyyy-MM-dd") @Excel(name = "结束报警时间", width = 30, dateFormat = "yyyy-MM-dd")
private Date endTime; private Date endTime;
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("faultCode", getFaultCode())
.append("carVin", getCarVin())
.append("startTime", getStartTime())
.append("endTime", getEndTime())
.toString();
}
} }

View File

@ -0,0 +1,23 @@
package com.muyu.breakdown.domain;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
* @ ToolIntelliJ IDEA
* @ AuthorCHX
* @ Date2024-09-20-15:31
* @ Version1.0
* @ Description
* @author Lenovo
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder
public class MessageMap {
private String key;
private String value;
}

View File

@ -27,26 +27,13 @@ public class Messages {
@Excel(name = "消息ID") @Excel(name = "消息ID")
private Long id; private Long id;
@Excel(name = "发送者ID") @Excel(name = "发送者ID")
private Integer senderId; private String senderId;
@Excel(name = "接收者ID") @Excel(name = "接收者ID")
private Integer receiverId; private String receiverId;
@Excel(name = "消息内容") @Excel(name = "消息内容")
private String content; private String content;
@Excel(name = "发送时间") @Excel(name = "发送时间")
private Date createTime; private Date createTime;
@Excel(name = "消息状态") @Excel(name = "消息状态")
private String status; private String status;
public Messages(int senderId, int receiverId, String content) {
this.senderId = senderId;
this.receiverId = receiverId;
this.content = content;
}
public Messages(Integer senderId, Integer receiverId, String content, Date createTime) {
this.senderId = senderId;
this.receiverId = receiverId;
this.content = content;
this.createTime = createTime;
}
} }

View File

@ -0,0 +1,43 @@
package com.muyu.breakdown.domain;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
* @ ToolIntelliJ IDEA
* @ AuthorCHX
* @ Date2024-09-20-15:35
* @ Version1.0
* @ Description
* @author Lenovo
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder
@TableName("sys_car_message")
public class SysCarMessage {
/**
* id
*/
private Integer id;
/**
*
*/
private String modelCode;
/**
*
*/
private String messageTypeCode;
/**
*
*/
private String messageStartIndex;
/**
*
*/
private String messageEndIndex;
}

View File

@ -0,0 +1,56 @@
package com.muyu.breakdown.config;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
*
* */
@Configuration
public class RabbitMQConfig {
// 1.生命注册fanout模式的交换机
@Bean
public FanoutExchange fanoutExchange(){
//1.fanout模式的路由名称 2.是否持久化 3. 是否自动删除
return new FanoutExchange("fanout",true,false);
}
// 2.生命队列 sms.fanout.queue email.fanout.queue,duanxin.fanout.queue
@Bean
public Queue duanxinQueue(){
return new Queue("duanxin",true);
}
@Bean
public Queue emailQueue(){
return new Queue("email",false);
}
@Bean
public Queue smsQueue(){
return new Queue("sms",false);
}
// 3.完成绑定关系(队列和交换机完成绑定关系
@Bean
public Binding duanxinExchange(){
return BindingBuilder.bind(duanxinQueue()).to(fanoutExchange());
}
@Bean
public Binding emailExchange(){
return BindingBuilder.bind(emailQueue()).to(fanoutExchange());
}
@Bean
public Binding smsExchange(){
return BindingBuilder.bind(smsQueue()).to(fanoutExchange());
}
// 4.生命注册fanout模式的交换机
}

View File

@ -0,0 +1,62 @@
package com.muyu.breakdown.config;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.HashMap;
/**
*
* */
@Configuration
public class RabbitMQDirectConfig {
/**
* fanout Direct Binding
* */
// 1.生命注册fanout模式的交换机
@Bean
public DirectExchange directExchange(){
//1.fanout模式的路由名称 2.是否持久化 3. 是否自动删除
return new DirectExchange("direct",true,false);
}
// 2.生命队列 sms.fanout.queue email.fanout.queue,duanxin.fanout.queue
@Bean
public Queue directduanxinQueue(){
HashMap<String, Object> map = new HashMap<>();
map.put("x-delayed-letter-exchange","direct");
map.put("x-delayed-routing-key","directduanxin");
map.put("x-message-ttl",10000);
return QueueBuilder.durable("directduanxin").withArguments(map).build();
}
@Bean
public Queue directemailQueue(){
return new Queue("directemail",false);
}
@Bean
public Queue directsmsQueue(){
return new Queue("directsms",false);
}
// 3.完成绑定关系(队列和交换机完成绑定关系
@Bean
public Binding directduanxinExchange(){
return BindingBuilder.bind(directduanxinQueue()).to(directExchange()).with("directduanxin");
}
@Bean
public Binding directemailExchange(){
return BindingBuilder.bind(directemailQueue()).to(directExchange()).with("directemail");
}
@Bean
public Binding directsmsExchange(){
return BindingBuilder.bind(directsmsQueue()).to(directExchange()).with("directsms");
}
// 4.生命注册fanout模式的交换机
}

View File

@ -0,0 +1,59 @@
package com.muyu.breakdown.config;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
*
* */
@Configuration
public class RabbitMQTopicConfig {
/**
* fanout Direct Binding
* */
// 1.生命注册fanout模式的交换机
@Bean
public TopicExchange topicExchange(){
//1.fanout模式的路由名称 2.是否持久化 3. 是否自动删除
return new TopicExchange("topic",true,false);
}
// 2.生命队列 sms.fanout.queue email.fanout.queue,duanxin.fanout.queue
@Bean
public Queue topicduanxinQueue(){
return new Queue("topicduanxin.test.one",true);
}
@Bean
public Queue topicemailQueue(){
return new Queue("topicemail.test.two",false);
}
@Bean
public Queue topicsmsQueue(){
return new Queue("topicsms.test.three",false);
}
// 3.完成绑定关系(队列和交换机完成绑定关系
@Bean
public Binding topicduanxinExchange(){
return BindingBuilder.bind(topicduanxinQueue()).to(topicExchange()).with("topic.#");
}
@Bean
public Binding topicemailExchange(){
return BindingBuilder.bind(topicemailQueue()).to(topicExchange()).with("topic.*");
}
@Bean
public Binding topicsmsExchange(){
return BindingBuilder.bind(topicsmsQueue()).to(topicExchange()).with("topic.test.#");
}
// 4.生命注册fanout模式的交换机
}

View File

@ -1,6 +1,7 @@
package com.muyu.breakdown.controller; package com.muyu.breakdown.controller;
import com.muyu.breakdown.domain.BreakDown; import com.muyu.breakdown.domain.BreakDown;
import com.muyu.breakdown.domain.MessageMap;
import com.muyu.breakdown.service.BreakDownService; import com.muyu.breakdown.service.BreakDownService;
import com.muyu.common.core.domain.Result; import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil; import com.muyu.common.core.utils.poi.ExcelUtil;
@ -15,6 +16,7 @@ import org.springframework.web.bind.annotation.*;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @ ToolIntelliJ IDEA * @ ToolIntelliJ IDEA
@ -105,5 +107,9 @@ public class BreakDownController extends BaseController {
return success(); return success();
} }
public Result getMessages(MessageMap messageMap) {
Map<String,String> messages =breakDownService.getMessages(messageMap);
return Result.success(messages);
}
} }

View File

@ -1,5 +1,6 @@
package com.muyu.breakdown.controller; package com.muyu.breakdown.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.muyu.breakdown.domain.Messages; import com.muyu.breakdown.domain.Messages;
import com.muyu.breakdown.service.BreakDownService; import com.muyu.breakdown.service.BreakDownService;
import com.muyu.breakdown.service.StationMessageService; import com.muyu.breakdown.service.StationMessageService;
@ -23,15 +24,19 @@ import java.util.List;
public class StationMessageController extends BaseController { public class StationMessageController extends BaseController {
@Autowired @Autowired
private StationMessageService stationMessageService; private StationMessageService stationMessageService;
@PostMapping("/send")
public void sendMessage(@RequestBody Messages messages) {
stationMessageService.sendMessage(messages.getSenderId(), messages.getReceiverId(), messages.getContent());
}
@GetMapping("/{userId}")
public List<Messages> getMessages(@PathVariable("userId") int userId) {
return stationMessageService.getUserMessages(userId);
}
/**
* id
* @param receiverId id
* @return
*/
@GetMapping("/getMessageList")
public Result<List<Messages>> list(@RequestParam("receiverId") String receiverId){
List<Messages> list = stationMessageService.list(new LambdaQueryWrapper<>() {{
eq(Messages::getReceiverId, receiverId);
}});
return Result.success(list);
}
} }

View File

@ -0,0 +1,20 @@
package com.muyu.breakdown.controller;
import com.muyu.breakdown.service.SysCarMessageService;
import com.muyu.common.core.web.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
/**
* @ ToolIntelliJ IDEA
* @ AuthorCHX
* @ Date2024-09-20-15:41
* @ Version1.0
* @ Description
* @author Lenovo
*/
@RestController
public class SysCarMessageController extends BaseController {
@Autowired
private SysCarMessageService sysCarMessageService;
}

View File

@ -0,0 +1,17 @@
package com.muyu.breakdown.mapper;
import com.github.yulichang.base.MPJBaseMapper;
import com.muyu.breakdown.domain.SysCarMessage;
import org.apache.ibatis.annotations.Mapper;
/**
* @ ToolIntelliJ IDEA
* @ AuthorCHX
* @ Date2024-09-20-15:54
* @ Version1.0
* @ Description
* @author Lenovo
*/
@Mapper
public interface SysCarMessageMapper extends MPJBaseMapper<SysCarMessage> {
}

View File

@ -2,8 +2,10 @@ package com.muyu.breakdown.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.breakdown.domain.BreakDown; import com.muyu.breakdown.domain.BreakDown;
import com.muyu.breakdown.domain.MessageMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @ ToolIntelliJ IDEA * @ ToolIntelliJ IDEA
@ -37,4 +39,5 @@ public interface BreakDownService extends IService<BreakDown> {
*/ */
Boolean checkIdUnique(BreakDown breakDown); Boolean checkIdUnique(BreakDown breakDown);
Map<String, String> getMessages(MessageMap messageMap);
} }

View File

@ -14,7 +14,6 @@ import java.util.List;
* @author Lenovo * @author Lenovo
*/ */
public interface StationMessageService extends IService<Messages> { public interface StationMessageService extends IService<Messages> {
void sendMessage(Integer senderId, Integer receiverId, String content);
List<Messages> getUserMessages(int userId); List<Messages> getMessageList(String receiverId);
} }

View File

@ -0,0 +1,15 @@
package com.muyu.breakdown.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.breakdown.domain.SysCarMessage;
/**
* @ ToolIntelliJ IDEA
* @ AuthorCHX
* @ Date2024-09-20-15:42
* @ Version1.0
* @ Description
* @author Lenovo
*/
public interface SysCarMessageService extends IService<SysCarMessage> {
}

View File

@ -3,13 +3,22 @@ package com.muyu.breakdown.service.impl;
import cn.hutool.core.lang.Assert; import cn.hutool.core.lang.Assert;
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.fasterxml.jackson.databind.ObjectMapper;
import com.muyu.breakdown.domain.BreakDown; import com.muyu.breakdown.domain.BreakDown;
import com.muyu.breakdown.domain.MessageMap;
import com.muyu.breakdown.domain.SysCarMessage;
import com.muyu.breakdown.mapper.BreakDownMapper; import com.muyu.breakdown.mapper.BreakDownMapper;
import com.muyu.breakdown.service.BreakDownService; import com.muyu.breakdown.service.BreakDownService;
import com.muyu.breakdown.service.SysCarMessageService;
import com.muyu.common.core.utils.StringUtils; import com.muyu.common.core.utils.StringUtils;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @ ToolIntelliJ IDEA * @ ToolIntelliJ IDEA
@ -21,6 +30,11 @@ import java.util.List;
*/ */
@Service @Service
public class BreakDownServiceImpl extends ServiceImpl<BreakDownMapper, BreakDown> implements BreakDownService { public class BreakDownServiceImpl extends ServiceImpl<BreakDownMapper, BreakDown> implements BreakDownService {
@Autowired
private SysCarMessageService sysCarMessageService;
@Autowired
private RabbitTemplate rabbitTemplate;
/** /**
* *
* *
@ -68,5 +82,16 @@ public class BreakDownServiceImpl extends ServiceImpl<BreakDownMapper, BreakDown
return this.count(queryWrapper) > 0; return this.count(queryWrapper) > 0;
} }
@Override
public Map<String, String> getMessages(MessageMap messageMap) {
return null;
}
// @RabbitListener(queues = "car.message.queue")
// private void sendMessage(String message) {
//
// }
} }

View File

@ -1,16 +1,13 @@
package com.muyu.breakdown.service.impl; package com.muyu.breakdown.service.impl;
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.muyu.breakdown.DTO.MessageDTO;
import com.muyu.breakdown.domain.Messages; import com.muyu.breakdown.domain.Messages;
import com.muyu.breakdown.mapper.StationMessageMapper; import com.muyu.breakdown.mapper.StationMessageMapper;
import com.muyu.breakdown.service.StationMessageService; import com.muyu.breakdown.service.StationMessageService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List; import java.util.List;
/** /**
@ -26,20 +23,13 @@ import java.util.List;
public class StationMessageServiceImpl public class StationMessageServiceImpl
extends ServiceImpl<StationMessageMapper, Messages> extends ServiceImpl<StationMessageMapper, Messages>
implements StationMessageService { implements StationMessageService {
@Autowired @Autowired
private MessageDTO messageDTO; private StationMessageMapper stationMessageMapper;
@Override @Override
public void sendMessage(Integer senderId, Integer receiverId, String content) { public List<Messages> getMessageList(String receiverId) {
Messages message = new Messages(senderId, receiverId, content);
// 保存消息到数据库
messageDTO.saveMessage(message);
} return null;
@Override
public List<Messages> getUserMessages(int userId) {
// 获取用户收到的消息
return messageDTO.getAllMessages(userId);
} }
} }

View File

@ -0,0 +1,19 @@
package com.muyu.breakdown.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.breakdown.domain.SysCarMessage;
import com.muyu.breakdown.mapper.SysCarMessageMapper;
import com.muyu.breakdown.service.SysCarMessageService;
import org.springframework.stereotype.Service;
/**
* @ ToolIntelliJ IDEA
* @ AuthorCHX
* @ Date2024-09-20-15:42
* @ Version1.0
* @ Description
* @author Lenovo
*/
@Service
public class SysCarMessageServiceImpl extends ServiceImpl<SysCarMessageMapper, SysCarMessage> implements SysCarMessageService {
}