fex():修改故障判断代码
parent
5edc2a8c05
commit
3d8b02a00e
|
@ -0,0 +1,19 @@
|
|||
package com.muyu.cloud.annotate;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* @Author:weiran
|
||||
* @Package:com.muyu.cloud.annotate
|
||||
* @Project:cloud-server-8
|
||||
* @name:FaultField
|
||||
* @Date:2024/9/24 9:16
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface FaultField {
|
||||
String name(); //假设FaultCondition中有一个相同名字的字段或可以映射到它的字段
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
package com.muyu.cloud.faultmanage.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Author:weiran
|
||||
* @Package:com.muyu.cloud.faultmanage.domain
|
||||
* @Project:cloud-server-8
|
||||
* @name:CarInformation
|
||||
* @Date:2024/9/23 22:29
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@SuperBuilder
|
||||
@TableName(value = "企业车辆管理实体类",autoResultMap = true)
|
||||
public class CarInformation {
|
||||
|
||||
/**
|
||||
* 车辆Id
|
||||
*/
|
||||
private Long carInformationId;
|
||||
/**
|
||||
* 车辆唯一VIN固定(不可修改)
|
||||
*/
|
||||
private String carInformationVIN;
|
||||
/**
|
||||
* 车牌号
|
||||
*/
|
||||
private String carInformationLicensePlate;
|
||||
|
||||
/**
|
||||
* 车辆品牌
|
||||
*/
|
||||
private String carInformationBrand;
|
||||
|
||||
/**
|
||||
* 车辆颜色
|
||||
*/
|
||||
private String carInformationColor;
|
||||
|
||||
/**
|
||||
* 车辆驾驶员
|
||||
*/
|
||||
private String carInformationDriver;
|
||||
|
||||
/**
|
||||
* 车检到期日期
|
||||
* 固定(不可修改)
|
||||
*/
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||
@JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd")
|
||||
private Date carInformationExamineEnddata;
|
||||
|
||||
/**
|
||||
* 车辆电机厂商
|
||||
*/
|
||||
private String carInformationMotorManufacturer;
|
||||
|
||||
/**
|
||||
* 车辆电机型号
|
||||
*/
|
||||
private String carInformationMotorModel;
|
||||
|
||||
/**
|
||||
* 车辆电池厂商
|
||||
*/
|
||||
private String carInformationBatteryManufacturer;
|
||||
|
||||
/**
|
||||
* 车辆电池型号
|
||||
*/
|
||||
private String carInformationBatteryModel;
|
||||
|
||||
/**
|
||||
* 车辆电子围栏外键ID
|
||||
*/
|
||||
private Integer carInformationFence;
|
||||
|
||||
/**
|
||||
* 车辆类型外键ID
|
||||
*/
|
||||
private Integer carInformationType;
|
||||
|
||||
/**
|
||||
* 是否重点车辆 (0否默认 1是 )
|
||||
*/
|
||||
private Integer carInformationFocus;
|
||||
|
||||
/**
|
||||
* 启用状态(1.在线 2.离线 3.已断开 4.待连接 5.维修中)
|
||||
*/
|
||||
private Integer carInformationState;
|
||||
|
||||
|
||||
//车辆类型表
|
||||
/**
|
||||
* 车辆类型ID
|
||||
*/
|
||||
private Integer carTypeId;
|
||||
/**
|
||||
* 车辆类型名
|
||||
*/
|
||||
private String carTypeName;
|
||||
|
||||
//电子围栏
|
||||
/**
|
||||
*电子围栏ID
|
||||
*/
|
||||
private Integer fenceid;
|
||||
|
||||
/**
|
||||
* 电子围栏名
|
||||
*/
|
||||
private String fencename;
|
||||
}
|
|
@ -18,9 +18,12 @@ import lombok.experimental.SuperBuilder;
|
|||
@NoArgsConstructor
|
||||
@SuperBuilder
|
||||
public class Vehicle {
|
||||
|
||||
private String type; // 可以是枚举或字符串
|
||||
// 其他车辆相关的字段和方法
|
||||
|
||||
// getter 和 setter 省略
|
||||
/**
|
||||
* 车辆VIN 唯一标识
|
||||
*/
|
||||
private String VIN;
|
||||
/**
|
||||
* g故障信息
|
||||
*/
|
||||
private String faultmessage;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package com.muyu.cloud.faultmanage.domain.message;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* @Author:weiran
|
||||
* @Package:com.muyu.cloud.faultmanage.domain.message
|
||||
* @Project:cloud-server-8
|
||||
* @name:User
|
||||
* @Date:2024/9/23 9:34
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@SuperBuilder
|
||||
public class User {
|
||||
|
||||
private Integer id;
|
||||
private String username;
|
||||
private String email;
|
||||
}
|
|
@ -79,10 +79,18 @@ public class FaultConditionController {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* 故障规则删除
|
||||
* @param carconditionId
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/faultconditiondel/{carconditionId}")
|
||||
@Operation(summary = "删除规则",description = "删除故障规则")
|
||||
public Result faultconditiondel(@PathVariable("carconditionId") long carconditionId){
|
||||
faultConditionService.removeById(carconditionId);
|
||||
return Result.success(null,"规则删除成功");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.muyu.cloud.faultmanage.controller;
|
||||
|
||||
import com.muyu.cloud.faultmanage.domain.CarFaultRule;
|
||||
import com.muyu.cloud.faultmanage.domain.FaultCondition;
|
||||
import com.muyu.cloud.faultmanage.domain.FaultRule;
|
||||
import com.muyu.cloud.faultmanage.domain.req.FaultConditionListReq;
|
||||
|
@ -9,6 +10,7 @@ import io.swagger.v3.oas.annotations.Operation;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
@ -31,17 +33,27 @@ public class FaultRuleController {
|
|||
private FaultRuleService faultRuleService;
|
||||
|
||||
|
||||
// /**
|
||||
// * 车辆故障检测
|
||||
// * @return
|
||||
// */
|
||||
// @PostMapping("/check-faults")
|
||||
// @Operation(summary = "检查故障",description = "进行故障检查")
|
||||
// public Result checkfaults(@Validated FaultRule faultRule){
|
||||
// String checkfaults = faultRuleService.checkfaults(faultRule);
|
||||
// return Result.success(checkfaults);
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* 车辆故障检测
|
||||
* 故障参数匹配检查
|
||||
* @param carFaultRule
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/check-faults")
|
||||
@Operation(summary = "检查故障",description = "进行故障检查")
|
||||
public Result checkfaults(@Validated FaultRule faultRule){
|
||||
String checkfaults = faultRuleService.checkfaults(faultRule);
|
||||
return Result.success(checkfaults);
|
||||
@PostMapping("/cheakfaults")
|
||||
@Operation(summary = "故障参数匹配检查",description = "获取报文数据与故障参数进行比较")
|
||||
public Result cheakfaults(@Validated @RequestBody CarFaultRule carFaultRule){
|
||||
faultRuleService.checkfault(carFaultRule);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -35,8 +35,8 @@ public class MessageController {
|
|||
*/
|
||||
@PostMapping("/sendmessage")
|
||||
@Operation(summary = "发送消息",description = "站内信消息发送")
|
||||
public Result sendmessage(@Validated MessageSendReq messageSendReq, HttpServletRequest request){
|
||||
messageService.sendmessage(messageSendReq,request);
|
||||
public Result sendmessage(@Validated MessageSendReq messageSendReq){
|
||||
messageService.sendmessage(messageSendReq);
|
||||
return Result.success(null,"发送成功");
|
||||
}
|
||||
|
||||
|
@ -65,10 +65,17 @@ public class MessageController {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查看未读的消息
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/unread")
|
||||
@Operation(summary = "查看未读的消息",description = "查看未读的消息")
|
||||
public Result unread(){
|
||||
return Result.success(messageService.unread());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
package com.muyu.cloud.faultmanage.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.muyu.cloud.faultmanage.domain.FaultRule;
|
||||
import com.muyu.cloud.faultmanage.domain.CarFaultRule;
|
||||
import com.muyu.cloud.faultmanage.domain.CarInformation;
|
||||
import com.muyu.cloud.faultmanage.domain.FaultCondition;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:weiran
|
||||
|
@ -12,5 +17,9 @@ import org.apache.ibatis.annotations.Mapper;
|
|||
* @Date:2024/9/19 22:11
|
||||
*/
|
||||
@Mapper
|
||||
public interface FaultRuleMapper extends BaseMapper<FaultRule> {
|
||||
public interface FaultRuleMapper extends BaseMapper<CarFaultRule> {
|
||||
|
||||
CarInformation selectTypeByVIN(@Param("vin") String vin);
|
||||
|
||||
List<FaultCondition> selectruleByType(@Param("carInformationType") Integer carInformationType);
|
||||
}
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
package com.muyu.cloud.faultmanage.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.cloud.faultmanage.domain.FaultCondition;
|
||||
import com.muyu.cloud.faultmanage.domain.CarFaultRule;
|
||||
import com.muyu.cloud.faultmanage.domain.FaultRule;
|
||||
import com.muyu.cloud.faultmanage.domain.req.FaultConditionListReq;
|
||||
import com.muyu.cloud.faultmanage.domain.resp.FaultConditionTotalListResp;
|
||||
import com.muyu.cloud.faultmanage.domain.Vehicle;
|
||||
|
||||
/**
|
||||
* @Author:weiran
|
||||
|
@ -13,13 +12,19 @@ import com.muyu.cloud.faultmanage.domain.resp.FaultConditionTotalListResp;
|
|||
* @name:FaultRuleService
|
||||
* @Date:2024/9/19 22:10
|
||||
*/
|
||||
public interface FaultRuleService extends IService<FaultRule> {
|
||||
public interface FaultRuleService extends IService<CarFaultRule> {
|
||||
|
||||
// /**
|
||||
// * 车辆故障检测
|
||||
// * @return
|
||||
// */
|
||||
// String checkfaults(FaultRule faultRule);
|
||||
|
||||
|
||||
/**
|
||||
* 车辆故障检测
|
||||
* 故障参数匹配检查
|
||||
* @param carFaultRule
|
||||
* @return
|
||||
*/
|
||||
String checkfaults(FaultRule faultRule);
|
||||
|
||||
|
||||
Vehicle checkfault(CarFaultRule carFaultRule);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public interface MessageService extends IService<Message> {
|
|||
* @param messageSendReq
|
||||
* @return
|
||||
*/
|
||||
void sendmessage(MessageSendReq messageSendReq, HttpServletRequest request);
|
||||
void sendmessage(MessageSendReq messageSendReq);
|
||||
|
||||
/**
|
||||
* 消息查看
|
||||
|
|
|
@ -2,8 +2,7 @@ package com.muyu.cloud.faultmanage.service.impl;
|
|||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.cloud.faultmanage.domain.FaultCondition;
|
||||
import com.muyu.cloud.faultmanage.domain.FaultRule;
|
||||
import com.muyu.cloud.faultmanage.domain.*;
|
||||
import com.muyu.cloud.faultmanage.domain.req.FaultConditionListReq;
|
||||
import com.muyu.cloud.faultmanage.domain.resp.FaultCodeListResp;
|
||||
import com.muyu.cloud.faultmanage.domain.resp.FaultCodeTotalListResp;
|
||||
|
@ -15,6 +14,7 @@ import com.muyu.common.core.utils.StringUtils;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
@ -28,46 +28,82 @@ import java.util.List;
|
|||
*/
|
||||
|
||||
@Service
|
||||
public class FaultRuleServiceImpl extends ServiceImpl<FaultRuleMapper, FaultRule> implements FaultRuleService {
|
||||
public class FaultRuleServiceImpl extends ServiceImpl<FaultRuleMapper, CarFaultRule> implements FaultRuleService {
|
||||
|
||||
@Autowired
|
||||
private FaultRuleMapper faultRuleMapper;
|
||||
|
||||
// /**
|
||||
// * 车辆故障检测
|
||||
// * @return
|
||||
// */
|
||||
// @Override
|
||||
// public String checkfaults(FaultRule faultRule) {
|
||||
// //获取触发条件
|
||||
// LambdaQueryWrapper<FaultRule> queryWrapper = new LambdaQueryWrapper<>();
|
||||
// if (Long.valueOf(faultRule.getFaultcodeId())!=null && faultRule.getFaultcodeId()!=0){
|
||||
// queryWrapper.eq(FaultRule::getFaultcodeId, faultRule.getFaultcodeId());
|
||||
// }
|
||||
// List<FaultRule> faultRuleList = this.list(queryWrapper);
|
||||
// for (FaultRule rule : faultRuleList) {
|
||||
// //单个值比较
|
||||
// if (faultRule.getSingleThreshold()!=null && faultRule.getMaxThreshold()==null && faultRule.getMinThreshold()==null){
|
||||
// //大于阈值
|
||||
// if (faultRule.getConditionContent().contains(">") || faultRule.getConditionContent().contains("大于")){
|
||||
// if (faultRule.getThreshold().compareTo(rule.getSingleThreshold())>0){
|
||||
// return "数据超过阈值,出现异常";
|
||||
// }
|
||||
// }
|
||||
// //小于阈值
|
||||
// if (faultRule.getConditionContent().contains("<") || faultRule.getConditionContent().contains("小于")){
|
||||
// if (faultRule.getThreshold().compareTo(rule.getSingleThreshold())<0){
|
||||
// return "数据过低,出现异常";
|
||||
// }
|
||||
// }
|
||||
// }else { //区间值比较
|
||||
// if (faultRule.getThreshold().compareTo(rule.getMinThreshold())<0 || faultRule.getThreshold().compareTo(rule.getMaxThreshold())>0){
|
||||
// return "数据不在可控范围内,出现异常";
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return "判断出现异常";
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* 车辆故障检测
|
||||
* 故障参数匹配检查
|
||||
* @param carFaultRule
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String checkfaults(FaultRule faultRule) {
|
||||
//获取触发条件
|
||||
LambdaQueryWrapper<FaultRule> queryWrapper = new LambdaQueryWrapper<>();
|
||||
if (Long.valueOf(faultRule.getFaultcodeId())!=null && faultRule.getFaultcodeId()!=0){
|
||||
queryWrapper.eq(FaultRule::getFaultcodeId, faultRule.getFaultcodeId());
|
||||
}
|
||||
List<FaultRule> faultRuleList = this.list(queryWrapper);
|
||||
for (FaultRule rule : faultRuleList) {
|
||||
//单个值比较
|
||||
if (faultRule.getSingleThreshold()!=null && faultRule.getMaxThreshold()==null && faultRule.getMinThreshold()==null){
|
||||
//大于阈值
|
||||
if (faultRule.getConditionContent().contains(">") || faultRule.getConditionContent().contains("大于")){
|
||||
if (faultRule.getThreshold().compareTo(rule.getSingleThreshold())>0){
|
||||
return "数据超过阈值,出现异常";
|
||||
public Vehicle checkfault(CarFaultRule carFaultRule) {
|
||||
//根据车辆VIN判断它属于什么类型的车辆
|
||||
CarInformation carInformation = faultRuleMapper.selectTypeByVIN(carFaultRule.getVin());
|
||||
Integer carInformationType = carInformation.getCarInformationType();
|
||||
//根据车辆类型,查询表获取对应的类型的故障规则
|
||||
List<FaultCondition> faultConditionList = faultRuleMapper.selectruleByType(carInformationType);
|
||||
//获取当前类的所有字段,不包括继承的
|
||||
Class<? extends CarFaultRule> carFaultRuleClass = carFaultRule.getClass();
|
||||
Field[] declaredFields = carFaultRuleClass.getDeclaredFields();
|
||||
for (Field declaredField : declaredFields) {
|
||||
//确保可以访问私有字段
|
||||
declaredField.setAccessible(true);
|
||||
try {
|
||||
//获取字段的值
|
||||
Object value = declaredField.get(carFaultRule);
|
||||
if (value != null && (!declaredField.getType().isPrimitive() && declaredField.get(carFaultRule)!=null)) {
|
||||
// 遍历faultConditionList,查找匹配的FaultCondition
|
||||
for (FaultCondition faultCondition : faultConditionList) {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
//小于阈值
|
||||
if (faultRule.getConditionContent().contains("<") || faultRule.getConditionContent().contains("小于")){
|
||||
if (faultRule.getThreshold().compareTo(rule.getSingleThreshold())<0){
|
||||
return "数据过低,出现异常";
|
||||
}
|
||||
}
|
||||
}else { //区间值比较
|
||||
if (faultRule.getThreshold().compareTo(rule.getMinThreshold())<0 || faultRule.getThreshold().compareTo(rule.getMaxThreshold())>0){
|
||||
return "数据不在可控范围内,出现异常";
|
||||
}
|
||||
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
return "判断出现异常";
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -12,10 +12,10 @@ import com.muyu.common.security.service.TokenService;
|
|||
import com.muyu.common.security.utils.SecurityUtils;
|
||||
import com.muyu.common.system.domain.LoginUser;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.Data;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
|
@ -44,7 +44,7 @@ public class MessageServiceImpl extends ServiceImpl<MessageMapper,Message> imple
|
|||
* @return
|
||||
*/
|
||||
@Override
|
||||
public void sendmessage(MessageSendReq messageSendReq, HttpServletRequest request) {
|
||||
public void sendmessage(MessageSendReq messageSendReq) {
|
||||
String token = SecurityUtils.getToken();// 获取当前Token
|
||||
LoginUser loginUser = tokenService.getLoginUser(token); // 获取当前登录用户
|
||||
if (loginUser == null) {
|
||||
|
@ -120,4 +120,7 @@ public class MessageServiceImpl extends ServiceImpl<MessageMapper,Message> imple
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
package com.muyu.cloud.faultmanage.service.message;
|
||||
|
||||
import com.muyu.cloud.faultmanage.domain.message.Message;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
|
||||
/**
|
||||
* @Author:weiran
|
||||
* @Package:com.muyu.cloud.faultmanage.service.messageDao
|
||||
* @Project:cloud-server-8
|
||||
* @name:MessageDao
|
||||
* @Date:2024/9/23 9:42
|
||||
*/
|
||||
|
||||
/**
|
||||
* 数据访问层,使用JDBC进行基本的数据库操作
|
||||
*/
|
||||
public class MessageDao {
|
||||
|
||||
|
||||
private Connection connection;
|
||||
|
||||
|
||||
public MessageDao(Connection connection){
|
||||
this.connection=connection;
|
||||
}
|
||||
|
||||
public void sendMessage(Message message) throws Exception{
|
||||
String sql="INSERT INTO `eight`.`car_fault_message` (`id`, `sender`, `receiver`, `content`, `status`, `create_time`, `user_id`) " +
|
||||
"VALUES (NULL, NULL, NULL, NULL, NULL, NULL, NULL)";
|
||||
try(PreparedStatement pstmt=connection.prepareStatement(sql)){
|
||||
pstmt.setString(1, message.getContent());
|
||||
pstmt.setString(2, message.getSender());
|
||||
pstmt.setString(3, message.getReceiver());
|
||||
pstmt.setObject(4, message.getCreateTime());
|
||||
pstmt.executeUpdate();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
package com.muyu.cloud.faultmanage.service.message;
|
||||
|
||||
import com.muyu.cloud.faultmanage.domain.message.Message;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Author:weiran
|
||||
* @Package:com.muyu.cloud.faultmanage.service.message
|
||||
* @Project:cloud-server-8
|
||||
* @name:MessageService
|
||||
* @Date:2024/9/23 9:48
|
||||
*/
|
||||
|
||||
/**
|
||||
* 业务逻辑层将负责实现消息的发送逻辑
|
||||
*/
|
||||
public class MessageService {
|
||||
|
||||
private MessageDao messageDao;
|
||||
|
||||
public MessageService(MessageDao messageDao){
|
||||
this.messageDao=messageDao;
|
||||
}
|
||||
|
||||
public void sendMessage(String content,String sender,String receiver){
|
||||
|
||||
// 定义一个DateTimeFormatter对象,用于格式化日期时间为yyyy-MM-dd HH:mm:ss
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
// 获取当前日期和时间
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
// 使用formatter格式化当前日期和时间
|
||||
String formattedDateTime = now.format(formatter);
|
||||
// 使用formatter将字符串解析回LocalDateTime
|
||||
LocalDateTime parsedDateTime = LocalDateTime.parse(formattedDateTime, formatter);
|
||||
// 然后按照上面的步骤将LocalDateTime转换为Date
|
||||
ZonedDateTime zdt = parsedDateTime.atZone(ZoneId.systemDefault());
|
||||
Date date = Date.from(zdt.toInstant());
|
||||
|
||||
|
||||
Message message = new Message();
|
||||
message.setContent(content);
|
||||
message.setSender(sender);
|
||||
message.setReceiver(receiver);
|
||||
message.setCreateTime(date);
|
||||
|
||||
try {
|
||||
messageDao.sendMessage(message);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
<?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.muyu.cloud.faultmanage.mapper.FaultRuleMapper">
|
||||
<resultMap id="CarInformationResult" type="com.muyu.cloud.faultmanage.domain.CarInformation">
|
||||
<id property="carInformationId" column="car_information_id"></id>
|
||||
<result property="carInformationVIN" column="car_information_VIN"></result>
|
||||
<result property="carInformationLicensePlate" column="car_information_license_plate"></result>
|
||||
<result property="carInformationBrand" column="car_information_brand"></result>
|
||||
<result property="carInformationDriver" column="car_information_driver"></result>
|
||||
<result property="carInformationMotorManufacturer" column="car_information_motor_manufacturer"></result>
|
||||
<result property="carInformationMotorModel" column="car_information_motorModel"></result>
|
||||
<result property="carInformationBatteryManufacturer" column="car_information_battery_manufacturer"></result>
|
||||
<result property="carInformationBatteryModel" column="car_information_battery_model"></result>
|
||||
<result property="carInformationFence" column="car_information_fence"></result>
|
||||
<result property="carInformationType" column="car_information_type"></result>
|
||||
<result property="carInformationFocus" column="car_informationfocus"></result>
|
||||
<result property="carInformationState" column="car_information_state"></result>
|
||||
<result property="carTypeName" column="car_type_name"></result>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="FaultCoditionResult" type="com.muyu.cloud.faultmanage.domain.FaultCondition">
|
||||
<id property="carconditionId" column="carcondition_id"></id>
|
||||
<result property="carTypeId" column="car_type_id"></result>
|
||||
<result property="messageTypeId" column="message_type_id"></result>
|
||||
<result property="faultconditionIdentification" column="faultcondition_identification"></result>
|
||||
<result property="carTypeName" column="car_type_name"></result>
|
||||
<result property="messageTypeName" column="message_type_name"></result>
|
||||
<result property="messageTypeCode" column="message_type_code"></result>
|
||||
</resultMap>
|
||||
|
||||
|
||||
<sql id="selectTypeByVIN">
|
||||
select
|
||||
car_information.*,
|
||||
car_type.car_type_name
|
||||
from
|
||||
car_information
|
||||
left join car_type on car_information.car_information_type=car_type.car_type_id
|
||||
</sql>
|
||||
|
||||
<sql id="selectfaultconditionlist">
|
||||
SELECT
|
||||
car_fault_condition.*,
|
||||
car_type.car_type_name,
|
||||
car_fault_label.message_type_name,
|
||||
car_fault_label.message_type_code
|
||||
FROM
|
||||
car_fault_condition
|
||||
LEFT JOIN car_type ON car_fault_condition.car_type_id = car_type.car_type_id
|
||||
LEFT JOIN car_fault_label ON car_fault_condition.message_type_id = car_fault_label.message_type_id
|
||||
</sql>
|
||||
|
||||
|
||||
<select id="selectTypeByVIN" resultType="com.muyu.cloud.faultmanage.domain.CarInformation">
|
||||
<include refid="selectTypeByVIN"></include>
|
||||
<where>
|
||||
and car_information.car_information_VIN=#{vin}
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectruleByType" resultType="com.muyu.cloud.faultmanage.domain.FaultCondition">
|
||||
<include refid="selectfaultconditionlist"></include>
|
||||
<where>
|
||||
and car_fault_condition.car_type_id=#{carInformationType}
|
||||
</where>
|
||||
</select>
|
||||
|
||||
</mapper>
|
Loading…
Reference in New Issue