feat(): 车辆报文解析初版

baize
baize 2024-06-27 11:59:30 +08:00
parent f33be9fbcc
commit ea9876fed9
19 changed files with 371 additions and 119 deletions

View File

@ -0,0 +1,51 @@
package com.muyu.customer.business.domain;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import java.io.Serializable;
/**
* MessageDetail
*
* @author DeKangLiu
* Date 2024/6/26 20:48
*/
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class MessageDetail {
/**
* id
*/
private Integer id;
/**
* key
*/
private String key;
/**
*
*/
private Integer startBit;
/**
*
*/
private Integer stopBit;
/**
*
*/
private String lable;
/**
*
*/
private String type;
}

View File

@ -118,6 +118,9 @@ public class Vehicle extends BaseEntity {
@ApiModelProperty(name = "车辆类型", value = "车辆类型")
private String vehicleType;
// /** 报文详情对象 */
// private MessageDetail messageDetail;
/**
*
*/

View File

@ -0,0 +1,25 @@
package com.muyu.customer.business.domain.model;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
* VehicleMiddle
*
* @author DeKangLiu
* Date 2024/6/27 09:53
*/
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class VehicleMiddle {
private Integer id;
private Integer vehicleId;
private Integer messageId;
}

View File

@ -0,0 +1,88 @@
package com.muyu.customer.business.domain.model;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.muyu.common.core.annotation.Excel;
import com.muyu.customer.business.domain.MessageDetail;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.springframework.format.annotation.DateTimeFormat;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
/**
* VehicleModel
*
* @author DeKangLiu
* Date 2024/6/27 08:18
*/
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class VehicleModel {
/** 车辆id */
private Long id;
/** 车辆vin */
private String vin;
/** 品牌 */
private String brand;
/** 型号 */
private String model;
/** 生产日期 */
@JsonFormat(pattern = "yyyy-MM-dd")
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date productionDate;
/** 车身类型 */
private String bodyType;
/** 车身颜色 */
private String color;
/** 发动机排量 */
private BigDecimal engineCapacity;
/** 燃油类型 */
private String fuelType;
/** 变速器类型 */
private String transmission;
/** 驱动方式 */
private String driveType;
/** 行驶里程 */
private BigDecimal mileage;
/** 注册日期 */
@JsonFormat(pattern = "yyyy-MM-dd")
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date registrationDate;
/** 车牌号码 */
private String licenseNumber;
/** 持有者 */
private String holder;
/** 车辆类型 */
private String vehicleType;
/** 报文详情对象 */
private String[] messageDetail;
}

View File

@ -0,0 +1,27 @@
package com.muyu.customer.business.domain.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* FaultRecordVo
*
* @author DeKangLiu
* Date 2024/6/24 19:32
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class FaultRecordVo {
/**
*
*/
private String faultCode;
/**
* vin
*/
private String vin;
private String count;
private String faultLabel;
}

View File

@ -1,40 +0,0 @@
//package com.muyu.customer.business.domain;
//
//import com.muyu.common.core.annotation.Excel;
//import com.muyu.common.core.web.domain.BaseEntity;
//import lombok.AllArgsConstructor;
//import lombok.Data;
//import lombok.EqualsAndHashCode;
//import lombok.NoArgsConstructor;
//import lombok.experimental.SuperBuilder;
//
///**
// * 多数据源对象 EnterpriseInfo
// *
// * @author DeKangLiu
// * Date 2024/6/22 20:37
// */
//@Data
//@SuperBuilder
//@NoArgsConstructor
//@AllArgsConstructor
//@EqualsAndHashCode(callSuper = true)
////@TableName("entinfo")
//public class EnterPriseInfo extends BaseEntity {
// private static final long serialVersionUID = 1L;
//
// /** 数据源key */
// @Excel(name = "数据源key")
// private String entCode;
//
// /** 数据源ip */
// @Excel(name = "数据源ip")
// private String ip;
//
// /** 数据源端口 */
// @Excel(name = "数据源端口")
// private Integer port;
//
// /** 数据源ID */
// private Long id;
//}

View File

@ -1,24 +0,0 @@
//package com.muyu.customer.business.remote;
//
//import com.muyu.common.core.constant.ServiceNameConstants;
//import com.muyu.customer.business.remote.factory.RemoteBusinessFallbackFactory;
//import org.springframework.cloud.openfeign.FeignClient;
//import org.springframework.web.bind.annotation.GetMapping;
//import com.muyu.net.working.domain.DataSource;
//import java.util.List;
//
///**
// * 用户服务 RemoteBusinessService
// *
// * @author DeKangLiu
// * Date 2024/6/22 20:39
// */
//@FeignClient(
// contextId = "remoteBusinessService",
// value = ServiceNameConstants.SYSTEM_BUSINESS,
// fallbackFactory = RemoteBusinessFallbackFactory.class
//)
//public interface RemoteBusinessService {
// @GetMapping("/datasource/listAll")
// public List<DataSource> listAll();
//}

View File

@ -1,35 +0,0 @@
//package com.muyu.customer.business.remote.factory;
//
//import com.muyu.customer.business.remote.RemoteBusinessService;
//import com.muyu.net.working.domain.DataSource;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.cloud.openfeign.FallbackFactory;
//import org.springframework.stereotype.Component;
//
//import java.util.List;
//
///**
// * 熔断器 RemoteBusinessFallbackFactory
// *
// * @author DeKangLiu
// * Date 2024/6/22 20:41
// */
//@Component
//public class RemoteBusinessFallbackFactory implements FallbackFactory<RemoteBusinessService> {
// private static final Logger log = LoggerFactory.getLogger(RemoteBusinessFallbackFactory.class);
//
// @Override
// public RemoteBusinessService create (Throwable throwable) {
// log.error("用户服务调用失败:{}", throwable.getMessage());
// return new RemoteBusinessService() {
// /**
// * 获取所有企业信息
// */
// @Override
// public List<DataSource> listAll() {
// return null;
// }
// };
// }
//}

View File

@ -92,13 +92,13 @@ public void consumptionStartMessage(Message message, Channel channel) {
.vin(split[0])
.faultCode(split[1])
.faultLevel(split[2])
.startTime(date)
.endTime(date)
.build();
FaultRecord faultRecordOne = faultRecordService.selectFault(build);
log.info("查询到的故障为:{}",faultRecordOne);
faultRecordOne.setEndTime(faultRecord.getEndTime());
faultRecordOne.setEndTime(build.getEndTime());
// 进行修改故障表
faultRecordService.updateByFaultRecord(faultRecordOne);
faultRecordService.updateFault(faultRecordOne);
// 移除数据源,
DynamicDataSourceHolder.removeDynamicDataSourceKey();
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);

View File

@ -7,6 +7,7 @@ import com.muyu.customer.business.domain.FaultRecord;
import com.muyu.customer.business.domain.req.FaultRecordEditReq;
import com.muyu.customer.business.domain.req.FaultRecordQueryReq;
import com.muyu.customer.business.domain.req.FaultRecordSaveReq;
import com.muyu.customer.business.domain.vo.FaultRecordVo;
import com.muyu.customer.business.service.FaultRecordService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
@ -108,4 +109,11 @@ public class FaultRecordController extends BaseController {
public Result<String> remove(@PathVariable List<Long> ids) {
return toAjax(faultRecordService.removeBatchByIds(ids));
}
@Log(title = "柱状图",businessType = BusinessType.DELETE)
@GetMapping("/countList")
@ApiOperation("柱状图展示")
public Result<List<FaultRecordVo>> countList( ) {
return Result.success(faultRecordService.countList());
}
}

View File

@ -7,9 +7,13 @@ import java.util.concurrent.TimeUnit;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.muyu.common.core.utils.ServletUtils;
import com.muyu.common.redis.service.RedisService;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.customer.business.domain.MessageDetail;
import com.muyu.customer.business.domain.model.VehicleModel;
import com.muyu.customer.business.mapper.VehicleMapper;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
@ -27,6 +31,7 @@ import com.muyu.customer.business.domain.req.VehicleSaveReq;
import com.muyu.customer.business.domain.req.VehicleEditReq;
import com.muyu.customer.business.service.VehicleService;
import com.muyu.common.core.web.page.TableDataInfo;
import springfox.documentation.spring.web.json.Json;
/**
* Controller
@ -44,6 +49,8 @@ public class VehicleController extends BaseController {
private HttpServletRequest request;
@Autowired
private StringRedisTemplate redisTemplate;
@Autowired
private RedisService redisService;
/**
*
@ -69,6 +76,11 @@ public class VehicleController extends BaseController {
}
});
});
Integer enterpriseId = SecurityUtils.getLoginUser().getSysUser().getEnterpriseId();
for (Vehicle vehicle : list) {
List<MessageDetail> messageList = vehicleService.selectMessage(vehicle.getId());
redisTemplate.opsForHash().put(enterpriseId+"", vehicle.getVin(), JSON.toJSONString(messageList));
}
return getDataTable(list);
}
@ -93,8 +105,8 @@ public class VehicleController extends BaseController {
@RequiresPermissions("customerBusiness:vehicle:query")
@GetMapping(value = "/{id}")
@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class)
public Result<Vehicle> getInfo(@PathVariable("id") Long id) {
return Result.success(vehicleService.getById(id));
public Result<VehicleModel> getInfo(@PathVariable("id") Long id) {
return Result.success(vehicleService.selectById(id));
}
/**
@ -104,9 +116,9 @@ public class VehicleController extends BaseController {
@Log(title = "车辆录入", businessType = BusinessType.INSERT)
@PostMapping
@ApiOperation("新增车辆录入")
public Result<String> add(@RequestBody VehicleSaveReq vehicleSaveReq) {
public Result add(@RequestBody VehicleModel vehicleModel) {
return toAjax(vehicleService.save(Vehicle.saveBuild(vehicleSaveReq)));
return Result.success(vehicleService.add(vehicleModel));
}
/**
@ -132,6 +144,15 @@ public class VehicleController extends BaseController {
return toAjax(vehicleService.removeBatchByIds(ids));
}
/**
*
*/
@GetMapping("/MessageList")
public Result<List<MessageDetail>> MessageList() {
return Result.success(vehicleService.MessageList());
}
// @Autowired
// private VehicleMapper vehicleMapper;
//

View File

@ -3,6 +3,7 @@ package com.muyu.customer.business.mapper;
import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.muyu.customer.business.domain.FaultRecord;
import com.muyu.customer.business.domain.vo.FaultRecordVo;
/**
* Mapper
@ -12,7 +13,10 @@ import com.muyu.customer.business.domain.FaultRecord;
*/
public interface FaultRecordMapper extends BaseMapper<FaultRecord> {
void addRecord(FaultRecord build);
FaultRecord selectFault(FaultRecord build);
void updateFault(FaultRecord faultRecordOne);
List<FaultRecordVo> countList();
}

View File

@ -2,7 +2,11 @@ package com.muyu.customer.business.mapper;
import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.muyu.customer.business.domain.MessageDetail;
import com.muyu.customer.business.domain.Vehicle;
import com.muyu.customer.business.domain.model.VehicleMiddle;
import com.muyu.customer.business.domain.model.VehicleModel;
import org.apache.ibatis.annotations.Param;
/**
* Mapper
@ -12,4 +16,15 @@ import com.muyu.customer.business.domain.Vehicle;
*/
public interface VehicleMapper extends BaseMapper<Vehicle> {
List<MessageDetail> MessageList();
void add(VehicleModel vehicleModel);
void addMiddle(@Param("id") Long id, @Param("integer") Integer integer);
List<VehicleMiddle> selectMessageList(@Param("id") Long id);
VehicleModel selectId(@Param("id") Long id);
List<MessageDetail> selectMessage(@Param("id") Long id);
}

View File

@ -3,6 +3,7 @@ package com.muyu.customer.business.service;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.customer.business.domain.FaultRecord;
import com.muyu.customer.business.domain.vo.FaultRecordVo;
/**
* Service
@ -19,7 +20,10 @@ public interface FaultRecordService extends IService<FaultRecord> {
*/
public List<FaultRecord> list(FaultRecord faultRecord);
void addRecord(FaultRecord build);
FaultRecord selectFault(FaultRecord build);
void updateFault(FaultRecord faultRecordOne);
List<FaultRecordVo> countList();
}

View File

@ -1,8 +1,11 @@
package com.muyu.customer.business.service;
import java.util.List;
import com.muyu.customer.business.domain.MessageDetail;
import com.muyu.customer.business.domain.Vehicle;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.customer.business.domain.model.VehicleModel;
import com.muyu.customer.business.domain.req.VehicleQueryReq;
/**
@ -20,4 +23,12 @@ public interface VehicleService extends IService<Vehicle> {
*/
List<Vehicle> list(Vehicle vehicle);
List<MessageDetail> MessageList();
String add(VehicleModel vehicleModel);
VehicleModel selectById(Long id);
List<MessageDetail> selectMessage(Long id);
}

View File

@ -5,6 +5,7 @@ import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.common.core.utils.ObjUtils;
import com.muyu.customer.business.domain.FaultRecord;
import com.muyu.customer.business.domain.vo.FaultRecordVo;
import com.muyu.customer.business.mapper.FaultRecordMapper;
import com.muyu.customer.business.service.FaultRecordService;
import lombok.extern.slf4j.Slf4j;
@ -49,13 +50,19 @@ public class FaultRecordServiceImpl extends ServiceImpl<FaultRecordMapper, Fault
return list(queryWrapper);
}
@Override
public void addRecord(FaultRecord build) {
faultRecordMapper.addRecord(build);
}
@Override
public FaultRecord selectFault(FaultRecord build) {
return faultRecordMapper.selectFault(build);
}
@Override
public void updateFault(FaultRecord faultRecordOne) {
faultRecordMapper.updateFault(faultRecordOne);
}
@Override
public List<FaultRecordVo> countList() {
return faultRecordMapper.countList();
}
}

View File

@ -3,7 +3,11 @@ package com.muyu.customer.business.service.impl;
import java.util.List;
import com.muyu.common.core.utils.ObjUtils;
import com.muyu.customer.business.domain.MessageDetail;
import com.muyu.customer.business.domain.model.VehicleMiddle;
import com.muyu.customer.business.domain.model.VehicleModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.muyu.customer.business.mapper.VehicleMapper;
import com.muyu.customer.business.domain.Vehicle;
@ -20,6 +24,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@Slf4j
@Service
public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> implements VehicleService {
@Autowired
private VehicleMapper vehicleMapper;
/**
*
@ -95,4 +101,36 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> imp
return list(queryWrapper);
}
@Override
public List<MessageDetail> MessageList() {
return vehicleMapper.MessageList();
}
@Override
public String add(VehicleModel vehicleModel) {
vehicleMapper.add(vehicleModel);
for (String s : vehicleModel.getMessageDetail()) {
vehicleMapper.addMiddle(vehicleModel.getId(),Integer.valueOf(s));
}
System.out.println(vehicleModel.getId());
// MessageDetail messageDetail = vehicleModel.getMessageDetail();
return "成功";
}
@Override
public VehicleModel selectById(Long id) {
List<VehicleMiddle> vehicleMiddleList= vehicleMapper.selectMessageList(id);
VehicleModel vehicleModel= vehicleMapper.selectId(id);
return vehicleModel;
}
@Override
public List<MessageDetail> selectMessage(Long id) {
return vehicleMapper.selectMessage(id);
}
}

View File

@ -1,7 +1,7 @@
<?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">
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.muyu.customer.business.mapper.FaultRecordMapper">
<resultMap type="com.muyu.customer.business.domain.FaultRecord" id="FaultRecordResult">
@ -17,14 +17,38 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<sql id="selectFaultRecordVo">
select id, fault_code, vin, start_time, end_time, fault_level, fault_handle from fault_record
</sql>
<insert id="addRecord">
INSERT INTO fault_record
(`fault_code`, `vin`, `start_time`, `end_time`, `fault_level`, `fault_handle`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES
values(#{faultCode},#{vin},#{startTime},null,#{faultLevel},#{faultHandle},null,null,null,null,null)
</insert>
<update id="updateFault">
update fault_record set end_time=#{endTime} where id=#{id}
</update>
<select id="countList" resultType="com.muyu.customer.business.domain.vo.FaultRecordVo">
SELECT
fr.vin,
fr.fault_code,
COUNT(*) AS count,
fc.fault_label
FROM
fault_record fr
LEFT JOIN fault_code fc ON fr.fault_code = fc.fault_code
<where>
<if test=" max != null ">
and #{max} >= start_time
</if>
<if test=" min != null ">
and #{min} &lt;= end_time
</if>
</where>
GROUP BY
fr.vin,
fr.fault_code,
fc.fault_label ORDER BY count
</select>
<select id="selectFault" resultType="com.muyu.customer.business.domain.FaultRecord">
SELECT id,fault_code,vin,start_time,end_time,fault_level,fault_handle
FROM fault_record
WHERE fault_code =#{faultCode} AND vin = #{vin} AND end_time is NULL
</select>
</mapper>

View File

@ -31,4 +31,29 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<sql id="selectVehicleVo">
select id, vin, brand, model, production_date, body_type, color, engine_capacity, fuel_type, transmission, drive_type, mileage, registration_date, license_number, holder, vehicle_type, create_by, create_time, update_by, update_time, remark from vehicle
</sql>
<insert id="add" useGeneratedKeys="true" keyProperty="id">
insert into vehicle
(id, vin, brand, model, production_date, body_type, color, engine_capacity, fuel_type, transmission, drive_type, mileage, registration_date, license_number, holder, vehicle_type)
values
(#{id}, #{vin}, #{brand}, #{model}, #{productionDate}, #{bodyType}, #{color}, #{engineCapacity}, #{fuelType}, #{transmission}, #{driveType}, #{mileage}, #{registrationDate}, #{licenseNumber}, #{holder}, #{vehicleType})
</insert>
<insert id="addMiddle">
insert into vehicle_middle
(vehicle_id, message_id)
values
(#{id}, #{integer})
</insert>
<select id="MessageList" resultType="com.muyu.customer.business.domain.MessageDetail">
select * from message_detail
</select>
<select id="selectMessageList" resultType="com.muyu.customer.business.domain.model.VehicleMiddle">
select * from vehicle_middle where vehicle_id = #{id}
</select>
<select id="selectId" resultType="com.muyu.customer.business.domain.model.VehicleModel">
select * from vehicle where id = #{id}
</select>
<select id="selectMessage" resultType="com.muyu.customer.business.domain.MessageDetail">
select m.id,m.key,m.lable,m.start_bit,m.stop_bit,m.type
from message_detail m,vehicle_middle v where m.id = v.message_id and v.vehicle_id = #{id}
</select>
</mapper>