增加业务

master
冯凯 2023-12-07 08:17:52 +08:00
parent f25d3d8d01
commit d6b59915be
8 changed files with 115 additions and 18 deletions

View File

@ -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>

View File

@ -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);
} }

View File

@ -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);
}
}
}

View File

@ -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 {
@ -13,7 +14,7 @@ public interface FaultService {
* @return RespFaultCode * @return RespFaultCode
*/ */
Result<List<RespFaultCode>> queryFaultCode (); Result<List<RespFaultCode>> queryFaultCode ();
/** /**
* - * -
* *
@ -22,7 +23,7 @@ public interface FaultService {
* @return 0/1 * @return 0/1
*/ */
Result insertFaultCode (ReqFault reqFault); Result insertFaultCode (ReqFault reqFault);
/** /**
* - * -
* *
@ -31,7 +32,7 @@ public interface FaultService {
* @return 0/1 * @return 0/1
*/ */
Result updateFaultCode (ReqFault reqFault); Result updateFaultCode (ReqFault reqFault);
/** /**
* - * -
* *
@ -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);
} }

View File

@ -17,11 +17,11 @@ import javax.annotation.Resource;
@Service @Service
@Log4j2 @Log4j2
public class CarManageServiceImpl implements CarManageService { public class CarManageServiceImpl implements CarManageService {
@Resource @Resource
CarManageMapper carMapper; CarManageMapper carMapper;
/** /**
* *
* *
@ -42,6 +42,11 @@ 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;
}
} }

View File

@ -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
@ -30,7 +31,7 @@ import java.util.Optional;
public class FaultServiceImpl implements FaultService { public class FaultServiceImpl implements FaultService {
@Autowired @Autowired
FaultMapper faultMapper; 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对象 .map (a -> new RespFaultCode (a.getId (), a.getCode (), a.getName (), a.getStatus ())) // 使用map方法将A对象转换为B对象
.toList ()); .toList ());
} }
/** /**
* - * -
* *
@ -60,7 +61,7 @@ public class FaultServiceImpl implements FaultService {
.map (code -> faultMapper.insert (code) > 0 ? Result.success ("insert 成功") : Result.error ("insert 失败")) .map (code -> faultMapper.insert (code) > 0 ? Result.success ("insert 成功") : Result.error ("insert 失败"))
.orElse (Result.error ("添加操作异常")); .orElse (Result.error ("添加操作异常"));
} }
/** /**
* - * -
* *
@ -80,8 +81,8 @@ public class FaultServiceImpl implements FaultService {
} }
return Result.error ("操作状态不为 'u'"); return Result.error ("操作状态不为 'u'");
} }
/** /**
* - * -
* *
@ -89,13 +90,13 @@ public class FaultServiceImpl implements FaultService {
* *
* @return 0/1 * @return 0/1
*/ */
@Override @Override
public Result deleteFaultCode (ReqFault reqFault) { public Result deleteFaultCode (ReqFault reqFault) {
String operation = reqFault.getOperation (); String operation = reqFault.getOperation ();
String code = reqFault.getOperationKey (); String code = reqFault.getOperationKey ();
String operationStatus = reqFault.getOperationStatus (); String operationStatus = reqFault.getOperationStatus ();
return switch (operation) { return switch (operation) {
case "d" -> { case "d" -> {
if (Objects.equals (operationStatus, "0")) { if (Objects.equals (operationStatus, "0")) {
@ -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);
}
} }

View File

@ -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

View File

@ -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>