增加业务
parent
f25d3d8d01
commit
d6b59915be
|
@ -35,6 +35,11 @@
|
|||
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringBoot Actuator -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
|
|
@ -3,6 +3,9 @@ package com.dragon.car.service.mapper;
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.dragon.car.domain.FaultCode;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author zhn
|
||||
|
@ -10,4 +13,6 @@ import org.apache.ibatis.annotations.Mapper;
|
|||
**/
|
||||
@Mapper
|
||||
public interface FaultMapper extends BaseMapper<FaultCode> {
|
||||
|
||||
void insertFaultRecord(@Param("vin") String vin, @Param("faultCode") String faultCode, @Param("startTime") Date startTime);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package com.dragon.car.service.rabbit;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.rabbitmq.client.Channel;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* @author 冯凯
|
||||
* @version 1.0
|
||||
* @description:
|
||||
* @date 2023/12/6 22:01
|
||||
*/
|
||||
@Component
|
||||
@Log4j2
|
||||
public class ListenFaultCode {
|
||||
|
||||
@RabbitListener(queuesToDeclare = {@Queue(value = "fault_Dqueue")})
|
||||
public void consumerSubscribe(String mesg, Message message, Channel channel) {
|
||||
log.info("收到消息【{}】", JSONObject.parseObject(mesg, HashMap.class));
|
||||
try {
|
||||
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ import com.dragon.car.domain.req.ReqFault;
|
|||
import com.dragon.car.domain.resp.RespFaultCode;
|
||||
import com.dragon.common.core.domain.Result;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public interface FaultService {
|
||||
|
@ -13,7 +14,7 @@ public interface FaultService {
|
|||
* @return RespFaultCode 故障返回实体类
|
||||
*/
|
||||
Result<List<RespFaultCode>> queryFaultCode ();
|
||||
|
||||
|
||||
/**
|
||||
* 故障管理-新增
|
||||
*
|
||||
|
@ -22,7 +23,7 @@ public interface FaultService {
|
|||
* @return 返回 0/1
|
||||
*/
|
||||
Result insertFaultCode (ReqFault reqFault);
|
||||
|
||||
|
||||
/**
|
||||
* 故障管理-修改
|
||||
*
|
||||
|
@ -31,7 +32,7 @@ public interface FaultService {
|
|||
* @return 返回 0/1
|
||||
*/
|
||||
Result updateFaultCode (ReqFault reqFault);
|
||||
|
||||
|
||||
/**
|
||||
* 故障管理-删除
|
||||
*
|
||||
|
@ -40,4 +41,6 @@ public interface FaultService {
|
|||
* @return 返回 0/1
|
||||
*/
|
||||
Result deleteFaultCode (ReqFault reqFault);
|
||||
|
||||
void insertFaultRecord(HashMap<String,String> map);
|
||||
}
|
||||
|
|
|
@ -17,11 +17,11 @@ import javax.annotation.Resource;
|
|||
@Service
|
||||
@Log4j2
|
||||
public class CarManageServiceImpl implements CarManageService {
|
||||
|
||||
|
||||
@Resource
|
||||
CarManageMapper carMapper;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 初始化车辆
|
||||
*
|
||||
|
@ -42,6 +42,11 @@ public class CarManageServiceImpl implements CarManageService {
|
|||
}
|
||||
return Result.success (i > 0 ? "车辆上线" : "上线失败");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Result carAdd(String vin, String carName, String carType, String carColor, String carBrand, String carModel, String carEngine, String carPrice, String carImg) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.dragon.car.service.service.impl;
|
||||
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.dragon.car.domain.FaultCode;
|
||||
import com.dragon.car.domain.req.ReqFault;
|
||||
|
@ -10,9 +11,9 @@ import com.dragon.common.core.domain.Result;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author zhn
|
||||
|
@ -30,7 +31,7 @@ import java.util.Optional;
|
|||
public class FaultServiceImpl implements FaultService {
|
||||
@Autowired
|
||||
FaultMapper faultMapper;
|
||||
|
||||
|
||||
/**
|
||||
* 故障管理-查询
|
||||
*
|
||||
|
@ -44,7 +45,7 @@ public class FaultServiceImpl implements FaultService {
|
|||
.map (a -> new RespFaultCode (a.getId (), a.getCode (), a.getName (), a.getStatus ())) // 使用map方法将A对象转换为B对象
|
||||
.toList ());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 故障管理-新增
|
||||
*
|
||||
|
@ -60,7 +61,7 @@ public class FaultServiceImpl implements FaultService {
|
|||
.map (code -> faultMapper.insert (code) > 0 ? Result.success ("insert 成功") : Result.error ("insert 失败"))
|
||||
.orElse (Result.error ("添加操作异常"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 故障管理-修改
|
||||
*
|
||||
|
@ -80,8 +81,8 @@ public class FaultServiceImpl implements FaultService {
|
|||
}
|
||||
return Result.error ("操作状态不为 'u'");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 故障管理-删除
|
||||
*
|
||||
|
@ -89,13 +90,13 @@ public class FaultServiceImpl implements FaultService {
|
|||
*
|
||||
* @return 返回 0/1
|
||||
*/
|
||||
|
||||
|
||||
@Override
|
||||
public Result deleteFaultCode (ReqFault reqFault) {
|
||||
String operation = reqFault.getOperation ();
|
||||
String code = reqFault.getOperationKey ();
|
||||
String operationStatus = reqFault.getOperationStatus ();
|
||||
|
||||
|
||||
return switch (operation) {
|
||||
case "d" -> {
|
||||
if (Objects.equals (operationStatus, "0")) {
|
||||
|
@ -113,4 +114,24 @@ public class FaultServiceImpl implements FaultService {
|
|||
default -> Result.error ("操作状态不为 'd'");
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertFaultRecord(HashMap<String, String> map) {
|
||||
Date startTime=new Date();
|
||||
String s = map.get("startTime");
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
try {
|
||||
startTime= format.parse(map.get("startTime"));
|
||||
} catch (ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
faultMapper.insertFaultRecord(map.get("vin"),map.get("faultCode"),startTime);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws ParseException {
|
||||
String time="2021-09-23 10:00:00";
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Date parse = format.parse(time);
|
||||
System.out.println(parse);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,19 @@ spring:
|
|||
# 共享配置
|
||||
shared-configs:
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
rabbitmq:
|
||||
host: 182.254.222.21
|
||||
port: 5672
|
||||
template:
|
||||
mandatory: true
|
||||
listener:
|
||||
simple:
|
||||
prefetch: 1 # 每次取一条消息消费 消费完成取下一条
|
||||
acknowledge-mode: manual # 设置消费端手动ack确认
|
||||
retry:
|
||||
enabled: true # 支持重试
|
||||
publisher-confirms: true #确认消息已发送到交换机(Exchange)
|
||||
publisher-returns: true #确认消息已发送到队列(Queue)
|
||||
mybatis-plus:
|
||||
configuration:
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
<?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.dragon.car.service.mapper.FaultMapper">
|
||||
|
||||
|
||||
<insert id="insertFaultRecord">
|
||||
insert into fault_record_new
|
||||
(vin, fault_code, start_time)
|
||||
values
|
||||
(#{vin}, #{faultCode}, #{startTime}))
|
||||
</insert>
|
||||
</mapper>
|
Loading…
Reference in New Issue