报文解析
parent
ad84ffb8c2
commit
d3810706f5
|
@ -66,17 +66,13 @@
|
||||||
<artifactId>cloud-common-log</artifactId>
|
<artifactId>cloud-common-log</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!--apache.kafka<-->
|
||||||
<!-- XllJob定时任务 -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.muyu</groupId>
|
<groupId>org.apache.kafka</groupId>
|
||||||
<artifactId>cloud-common-xxl</artifactId>
|
<artifactId>kafka-clients</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.muyu</groupId>
|
|
||||||
<artifactId>cloud-common-rabbit</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- MuYu Common System-->
|
<!-- MuYu Common System-->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -1,18 +1,23 @@
|
||||||
package com.muyu.car;
|
package com.muyu.car;
|
||||||
|
|
||||||
|
import com.muyu.car.service.CarMessageService;
|
||||||
import com.muyu.common.security.annotation.EnableCustomConfig;
|
import com.muyu.common.security.annotation.EnableCustomConfig;
|
||||||
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cache.annotation.EnableCaching;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
@EnableCustomConfig
|
@EnableCustomConfig
|
||||||
@EnableMyFeignClients
|
@EnableMyFeignClients
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
|
@EnableCaching
|
||||||
public class CarApplication {
|
public class CarApplication {
|
||||||
public static void main(String[] args){
|
public static void main(String[] args){
|
||||||
SpringApplication.run(CarApplication.class,args);
|
SpringApplication.run(CarApplication.class,args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.muyu.car.controller;
|
package com.muyu.car.controller;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.muyu.car.domain.CarMessage;
|
import com.muyu.car.domain.CarMessage;
|
||||||
import com.muyu.car.service.CarMessageService;
|
import com.muyu.car.service.CarMessageService;
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
|
@ -7,10 +8,7 @@ import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -66,58 +64,22 @@ public class CarMessageController {
|
||||||
return Result.success(updateCarMessage,"修改成功");
|
return Result.success(updateCarMessage,"修改成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试分割字符
|
||||||
|
*/
|
||||||
|
@PostMapping("/inciseCarMessage")
|
||||||
|
@Operation(summary = "解析报文处理", description = "解析报文测试")
|
||||||
|
public Result<JSONObject> inciseCarMessage(@RequestParam(name = "testString") String testString){
|
||||||
|
JSONObject carMessage = carMessageService.inciseCarMessage(testString);
|
||||||
|
return Result.success(carMessage);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 测试分割字符
|
* 测试分割字符
|
||||||
*/
|
*/
|
||||||
public class MessageParser{
|
|
||||||
public static void main(String[] args) {
|
|
||||||
String message = "01 02 03 " +
|
|
||||||
"04,05,06,07,08,09," +
|
|
||||||
"10,11,12,13,14,15,16" +
|
|
||||||
",17,18,19,20,21,22,23," +
|
|
||||||
"24,25,26,27,28,29,30" +
|
|
||||||
",31,32,33,34,35,36,37," +
|
|
||||||
"38,39,40,41,42,43,44,45," +
|
|
||||||
"46";
|
|
||||||
|
|
||||||
|
|
||||||
String[] split = message.split(",");
|
|
||||||
for (int i = 0; i < split.length; i++) {
|
|
||||||
System.out.println(split[i]);
|
|
||||||
if(i == 0){
|
|
||||||
System.out.println("开始");
|
|
||||||
}else if(i == split.length - 1){
|
|
||||||
System.out.println("结束");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
System.out.println(split.length);
|
|
||||||
System.out.println(message.length());
|
|
||||||
|
|
||||||
System.out.println(message.substring(0,1));
|
|
||||||
System.out.println(message.substring(1,2));
|
|
||||||
System.out.println(message.substring(2,3));
|
|
||||||
System.out.println(message.substring(3,4));
|
|
||||||
System.out.println(message.substring(4,5));
|
|
||||||
System.out.println(message.substring(5,6));
|
|
||||||
System.out.println(message.substring(6,7));
|
|
||||||
System.out.println(message.substring(7,8));
|
|
||||||
System.out.println(message.substring(8,9));
|
|
||||||
System.out.println(message.substring(9,10));
|
|
||||||
System.out.println(message.substring(10,11));
|
|
||||||
System.out.println(message.substring(11,12));
|
|
||||||
System.out.println(message.substring(12,13));
|
|
||||||
System.out.println(message.substring(13,14));
|
|
||||||
System.out.println(message.substring(14,15));
|
|
||||||
System.out.println(message.substring(15,16));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,105 @@
|
||||||
|
package com.muyu.car.domain.resp;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.bouncycastle.crypto.Digest;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Tag(
|
||||||
|
name = "测试代码行",
|
||||||
|
description = "车INdsa"
|
||||||
|
)
|
||||||
|
public class CarINdsa {
|
||||||
|
|
||||||
|
private Long testmessageId;
|
||||||
|
private String testmessagename;
|
||||||
|
private Integer testmessagetodo;
|
||||||
|
private String testmessageagon;
|
||||||
|
private Integer testmessagetest;
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private Date dayend;
|
||||||
|
private String testmessagehid;
|
||||||
|
private Integer testmessageyou;
|
||||||
|
private Digest testmessageertug;
|
||||||
|
private String testmessagebug;
|
||||||
|
private Integer testmessagedata;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -6,11 +6,13 @@ import com.muyu.car.domain.CarMessage;
|
||||||
import com.muyu.car.domain.req.CarInformationAddReq;
|
import com.muyu.car.domain.req.CarInformationAddReq;
|
||||||
import com.muyu.car.domain.req.CarInformationListReq;
|
import com.muyu.car.domain.req.CarInformationListReq;
|
||||||
import com.muyu.car.domain.req.CarInformationUpdReq;
|
import com.muyu.car.domain.req.CarInformationUpdReq;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
|
@Tag(name = "车辆基础信息表")
|
||||||
public interface CarInformationMapper {
|
public interface CarInformationMapper {
|
||||||
/**
|
/**
|
||||||
* 企业车辆管理列表
|
* 企业车辆管理列表
|
||||||
|
|
|
@ -2,11 +2,13 @@ package com.muyu.car.mapper;
|
||||||
|
|
||||||
import com.muyu.car.domain.Packettemplate;
|
import com.muyu.car.domain.Packettemplate;
|
||||||
import com.muyu.car.domain.req.PackettemplateAddReq;
|
import com.muyu.car.domain.req.PackettemplateAddReq;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
|
@Tag(name = "保温分类表")
|
||||||
public interface PackettemplateMapper {
|
public interface PackettemplateMapper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.muyu.car.service;
|
package com.muyu.car.service;
|
||||||
|
|
||||||
import cn.hutool.json.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.muyu.car.domain.CarMessage;
|
import com.muyu.car.domain.CarMessage;
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,9 @@ import com.muyu.car.mapper.CarInformationMapper;
|
||||||
import com.muyu.car.service.CarInformationService;
|
import com.muyu.car.service.CarInformationService;
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import org.apache.poi.ss.formula.functions.IDStarAlgorithm;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
@ -52,6 +54,14 @@ public class CarInformationServiceImpl implements CarInformationService {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Result adfv(IDStarAlgorithm starAlgorithm){
|
||||||
|
String str="afavav sdvaedvgafa sefse";
|
||||||
|
|
||||||
|
return Result.success(starAlgorithm);
|
||||||
|
return Result.error(402,"添加车辆失败");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result updatecarInformation(CarInformationUpdReq carInformationUpdReq) {
|
public Result updatecarInformation(CarInformationUpdReq carInformationUpdReq) {
|
||||||
Integer updatecarInformation = carInformationMapper.updatecarInformation(carInformationUpdReq);
|
Integer updatecarInformation = carInformationMapper.updatecarInformation(carInformationUpdReq);
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
package com.muyu.car.service.Impl;
|
package com.muyu.car.service.Impl;
|
||||||
|
|
||||||
import cn.hutool.json.JSONObject;
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.muyu.car.domain.CarInformation;
|
import com.muyu.car.domain.CarInformation;
|
||||||
import com.muyu.car.domain.CarMessage;
|
import com.muyu.car.domain.CarMessage;
|
||||||
import com.muyu.car.mapper.CarInformationMapper;
|
import com.muyu.car.mapper.CarInformationMapper;
|
||||||
|
@ -14,6 +15,7 @@ import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@ -62,6 +64,7 @@ public class CarMessageServiceImpl implements CarMessageService {
|
||||||
return Result.error( 402,"修改失败");
|
return Result.error( 402,"修改失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JSONObject inciseCarMessage(String testString) {
|
public JSONObject inciseCarMessage(String testString) {
|
||||||
//根据空格拆分切割数据字符串
|
//根据空格拆分切割数据字符串
|
||||||
|
@ -74,36 +77,38 @@ public class CarMessageServiceImpl implements CarMessageService {
|
||||||
stringBuilder.append((char) inciseindex);
|
stringBuilder.append((char) inciseindex);
|
||||||
}
|
}
|
||||||
//切取车辆VIN
|
//切取车辆VIN
|
||||||
String substring = stringBuilder.substring(1, 18);
|
String substring = stringBuilder.substring(0, 17);
|
||||||
log.info("车辆的VIN码:" + substring);
|
log.info("车辆的VIN码:" + substring);
|
||||||
//根据给定的vehicleVin(车辆VIN号)获取对应的模板车辆分类carMessageCartype
|
//根据给定的vehicleVin(车辆VIN号)获取对应的模板车辆分类carMessageCartype
|
||||||
Integer selectcared = Math.toIntExact(carMessageMapper.selectcarMessageCartype(substring));
|
Long selectcared = carMessageMapper.selectcarMessageCartype(substring);
|
||||||
//根据给定的vehicleVin(车辆VIN号)获取对应的模板信息
|
//根据给定的vehicleVin(车辆VIN号)获取对应的模板信息
|
||||||
List<CarInformation> carInformations = carMessageMapper.selectcarInformationType(substring);
|
// List<CarInformation> carInformations = carMessageMapper.selectcarInformationType(substring);
|
||||||
|
//创建接受数据的数组
|
||||||
|
List<CarMessage> carMessagesList ;
|
||||||
|
|
||||||
List<CarMessage> carMessagesList = null;
|
try{
|
||||||
|
String redisKey = "carMessageList" + selectcared;
|
||||||
|
if (redisTemplate.hasKey(redisKey)){
|
||||||
|
List<Objects> list = redisTemplate.opsForList().range(redisKey , 0, -1);
|
||||||
|
carMessagesList =
|
||||||
|
list.stream().map(objects ->
|
||||||
|
JSON.parseObject(objects.toString(), CarMessage.class))
|
||||||
|
.toList();
|
||||||
|
log.info("Redis缓存查询成功");
|
||||||
|
}else {
|
||||||
|
carMessagesList = carMessageMapper.selectCarMessageList(Math.toIntExact(selectcared));
|
||||||
|
|
||||||
if (redisTemplate.hasKey("carMessageList" + selectcared)){
|
carMessagesList.forEach(
|
||||||
List<CarMessage>arrayList = new ArrayList<>();
|
listReq -> redisTemplate.opsForList().rightPushAll(redisKey, (Collection<Objects>) listReq)
|
||||||
List<Objects> list = redisTemplate.opsForList().range("carMessageList" + selectcared, 0, -1);
|
);
|
||||||
for (Objects objstring : list) {
|
log.info("数据库查询成功");
|
||||||
String objString = objstring.toString();
|
|
||||||
CarMessage carMessage = JSON.parseObject(objString, CarMessage.class);
|
|
||||||
arrayList.add(carMessage);
|
|
||||||
}
|
|
||||||
log.info("Redis查询到了");
|
|
||||||
carMessagesList = arrayList;
|
|
||||||
}else {
|
|
||||||
List<CarMessage> list = carMessageMapper.selectCarMessageList(selectcared);
|
|
||||||
for (CarMessage carMessage : list) {
|
|
||||||
redisTemplate.opsForList().rightPushAll("carMessageList" + selectcared , JSON.toJSONString(carMessage));
|
|
||||||
}
|
|
||||||
log.info("数据库查询成功");
|
|
||||||
|
|
||||||
carMessagesList = list;
|
|
||||||
}
|
}
|
||||||
|
log.info("获取失败,请重试");
|
||||||
|
}catch(Exception e){
|
||||||
|
throw new RuntimeException("获取报文模板失败");
|
||||||
|
}
|
||||||
//判断报文模板 列表 不为空
|
//判断报文模板 列表 不为空
|
||||||
if(carMessagesList == null){
|
if(carMessagesList.isEmpty()){
|
||||||
throw new RuntimeException("报文模版为空");
|
throw new RuntimeException("报文模版为空");
|
||||||
}
|
}
|
||||||
//存储报文模板解析后的数据
|
//存储报文模板解析后的数据
|
||||||
|
@ -116,12 +121,12 @@ public class CarMessageServiceImpl implements CarMessageService {
|
||||||
//根据报文模板获取保温截取位置
|
//根据报文模板获取保温截取位置
|
||||||
String value = stringBuilder.substring(startIndex, endIndex);
|
String value = stringBuilder.substring(startIndex, endIndex);
|
||||||
//存入数据
|
//存入数据
|
||||||
jsonObject.put(carMessage.)
|
jsonObject.put(carMessage.getMessageTypeName(), value);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
return jsonObject;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,7 +122,7 @@
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectcarMessageCartype" resultType="java.lang.Long">
|
<select id="selectcarMessageCartype" resultType="java.lang.Long">
|
||||||
SELECT car_message_type
|
SELECT `car_information`.car_Information_Type
|
||||||
FROM `car_information`
|
FROM `car_information`
|
||||||
WHERE `car_information`.car_information_VIN = #{carInformationVIN}
|
WHERE `car_information`.car_information_VIN = #{carInformationVIN}
|
||||||
</select>
|
</select>
|
||||||
|
|
Loading…
Reference in New Issue