增加业务
parent
f25d3d8d01
commit
d6b59915be
|
@ -35,6 +35,11 @@
|
||||||
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- SpringBoot Actuator -->
|
<!-- SpringBoot Actuator -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
|
|
@ -3,6 +3,9 @@ package com.dragon.car.service.mapper;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.dragon.car.domain.FaultCode;
|
import com.dragon.car.domain.FaultCode;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author zhn
|
* @author zhn
|
||||||
|
@ -10,4 +13,6 @@ import org.apache.ibatis.annotations.Mapper;
|
||||||
**/
|
**/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface FaultMapper extends BaseMapper<FaultCode> {
|
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.car.domain.resp.RespFaultCode;
|
||||||
import com.dragon.common.core.domain.Result;
|
import com.dragon.common.core.domain.Result;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface FaultService {
|
public interface FaultService {
|
||||||
|
@ -40,4 +41,6 @@ public interface FaultService {
|
||||||
* @return 返回 0/1
|
* @return 返回 0/1
|
||||||
*/
|
*/
|
||||||
Result deleteFaultCode (ReqFault reqFault);
|
Result deleteFaultCode (ReqFault reqFault);
|
||||||
|
|
||||||
|
void insertFaultRecord(HashMap<String,String> map);
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,5 +43,10 @@ public class CarManageServiceImpl implements CarManageService {
|
||||||
return Result.success (i > 0 ? "车辆上线" : "上线失败");
|
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;
|
package com.dragon.car.service.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.dragon.car.domain.FaultCode;
|
import com.dragon.car.domain.FaultCode;
|
||||||
import com.dragon.car.domain.req.ReqFault;
|
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.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.text.ParseException;
|
||||||
import java.util.Objects;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Optional;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author zhn
|
* @author zhn
|
||||||
|
@ -113,4 +114,24 @@ public class FaultServiceImpl implements FaultService {
|
||||||
default -> Result.error ("操作状态不为 'd'");
|
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:
|
shared-configs:
|
||||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
- 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:
|
mybatis-plus:
|
||||||
configuration:
|
configuration:
|
||||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
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