diff --git a/cloud-modules/cloud-modules-template/pom.xml b/cloud-modules/cloud-modules-template/pom.xml new file mode 100644 index 0000000..fc32dc9 --- /dev/null +++ b/cloud-modules/cloud-modules-template/pom.xml @@ -0,0 +1,85 @@ + + + 4.0.0 + + com.muyu + cloud-modules + 3.6.3 + + + cloud-modules-template + + + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-sentinel + + + + + org.springframework.boot + spring-boot-starter-actuator + + + + + com.mysql + mysql-connector-j + + + + + com.muyu + cloud-common-datasource + + + + + com.muyu + cloud-common-datascope + + + + + com.muyu + cloud-common-log + + + + + com.muyu + cloud-common-api-doc + + + + + com.muyu + cloud-common-xxl + + + + + + 17 + 17 + UTF-8 + + + diff --git a/cloud-modules/cloud-modules-template/src/main/java/com/muyu/template/CloudTemplateApplication.java b/cloud-modules/cloud-modules-template/src/main/java/com/muyu/template/CloudTemplateApplication.java new file mode 100644 index 0000000..823f919 --- /dev/null +++ b/cloud-modules/cloud-modules-template/src/main/java/com/muyu/template/CloudTemplateApplication.java @@ -0,0 +1,27 @@ +package com.muyu.template; + +import com.muyu.common.security.annotation.EnableCustomConfig; +import com.muyu.common.security.annotation.EnableMyFeignClients; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * @author liuxinyue + * @Package:com.muyu.template + * @name:CloudTemplateApplication + * @Date:2024/9/30 10:36 + */ + +@EnableCustomConfig +//@EnableCustomSwagger2 +@EnableMyFeignClients +@SpringBootApplication +public class CloudTemplateApplication { + + public static void main(String[] args) { + + SpringApplication.run(CloudTemplateApplication.class, args); + + } + +} diff --git a/cloud-modules/cloud-modules-template/src/main/java/com/muyu/template/service/TemplateService.java b/cloud-modules/cloud-modules-template/src/main/java/com/muyu/template/service/TemplateService.java new file mode 100644 index 0000000..f6bc10a --- /dev/null +++ b/cloud-modules/cloud-modules-template/src/main/java/com/muyu/template/service/TemplateService.java @@ -0,0 +1,10 @@ +package com.muyu.template.service; + +/** + * @author liuxinyue + * @Package:com.muyu.template.service + * @name:TemplateService + * @Date:2024/9/30 10:57 + */ +public interface TemplateService { +} diff --git a/cloud-modules/cloud-modules-template/src/main/java/com/muyu/template/service/impl/TemplateServiceImpl.java b/cloud-modules/cloud-modules-template/src/main/java/com/muyu/template/service/impl/TemplateServiceImpl.java new file mode 100644 index 0000000..4e92057 --- /dev/null +++ b/cloud-modules/cloud-modules-template/src/main/java/com/muyu/template/service/impl/TemplateServiceImpl.java @@ -0,0 +1,19 @@ +package com.muyu.template.service.impl; + +import com.muyu.template.service.TemplateService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * @author liuxinyue + * @Package:com.muyu.template.service.impl + * @name:TemplateServiceImpl + * @Date:2024/9/30 10:57 + */ +@Service +public class TemplateServiceImpl implements TemplateService { + + + + +} diff --git a/cloud-modules/cloud-modules-template/src/main/resources/banner.txt b/cloud-modules/cloud-modules-template/src/main/resources/banner.txt new file mode 100644 index 0000000..0dd5eee --- /dev/null +++ b/cloud-modules/cloud-modules-template/src/main/resources/banner.txt @@ -0,0 +1,2 @@ +Spring Boot Version: ${spring-boot.version} +Spring Application Name: ${spring.application.name} diff --git a/cloud-modules/cloud-modules-template/src/main/resources/logback/dev.xml b/cloud-modules/cloud-modules-template/src/main/resources/logback/dev.xml new file mode 100644 index 0000000..0ea8333 --- /dev/null +++ b/cloud-modules/cloud-modules-template/src/main/resources/logback/dev.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + ${log.pattern} + + + + + + ${log.path}/info.log + + + + ${log.path}/info.%d{yyyy-MM-dd}.log + + 60 + + + ${log.pattern} + + + + INFO + + ACCEPT + + DENY + + + + + ${log.path}/error.log + + + + ${log.path}/error.%d{yyyy-MM-dd}.log + + 60 + + + ${log.pattern} + + + + ERROR + + ACCEPT + + DENY + + + + + + + + + + + + + + + + + + diff --git a/cloud-modules/cloud-modules-template/src/main/resources/logback/prod.xml b/cloud-modules/cloud-modules-template/src/main/resources/logback/prod.xml new file mode 100644 index 0000000..a8f7c06 --- /dev/null +++ b/cloud-modules/cloud-modules-template/src/main/resources/logback/prod.xml @@ -0,0 +1,81 @@ + + + + + + + + + + + + ${log.sky.pattern} + + + + + + ${log.path}/info.log + + + + ${log.path}/info.%d{yyyy-MM-dd}.log + + 60 + + + + + INFO + + ACCEPT + + DENY + + + + + ${log.path}/error.log + + + + ${log.path}/error.%d{yyyy-MM-dd}.log + + 60 + + + + + ERROR + + ACCEPT + + DENY + + + + + + + + ${log.sky.pattern} + + + + + + + + + + + + + + + + + + + + diff --git a/cloud-modules/cloud-modules-template/src/main/resources/logback/test.xml b/cloud-modules/cloud-modules-template/src/main/resources/logback/test.xml new file mode 100644 index 0000000..a8f7c06 --- /dev/null +++ b/cloud-modules/cloud-modules-template/src/main/resources/logback/test.xml @@ -0,0 +1,81 @@ + + + + + + + + + + + + ${log.sky.pattern} + + + + + + ${log.path}/info.log + + + + ${log.path}/info.%d{yyyy-MM-dd}.log + + 60 + + + + + INFO + + ACCEPT + + DENY + + + + + ${log.path}/error.log + + + + ${log.path}/error.%d{yyyy-MM-dd}.log + + 60 + + + + + ERROR + + ACCEPT + + DENY + + + + + + + + ${log.sky.pattern} + + + + + + + + + + + + + + + + + + + + diff --git a/cloud-modules/cloud-modules-template/src/main/resources/mapper/CarTypeMapper.xml b/cloud-modules/cloud-modules-template/src/main/resources/mapper/CarTypeMapper.xml new file mode 100644 index 0000000..63274cf --- /dev/null +++ b/cloud-modules/cloud-modules-template/src/main/resources/mapper/CarTypeMapper.xml @@ -0,0 +1,9 @@ + + + + + + + diff --git a/cloud-modules/cloud-modules-template/src/main/resources/mapper/EnterpriseMapper.xml b/cloud-modules/cloud-modules-template/src/main/resources/mapper/EnterpriseMapper.xml new file mode 100644 index 0000000..76e2c13 --- /dev/null +++ b/cloud-modules/cloud-modules-template/src/main/resources/mapper/EnterpriseMapper.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + insert into tb_enterprise + set enterprise_name = #{enterpriseName}, + enterprise_car_count = #{enterpriseCarCount}, + enterprise_fence_count = #{enterpriseFenceCount} + + + + + + + + + update tb_enterprise + set enterprise_name = #{enterpriseName}, + enterprise_car_count = #{enterpriseCarCount}, + enterprise_fence_count = #{enterpriseFenceCount} + where enterprise_id = #{enterpriseId} and enterprise_id != 0 + + + + + + + delete from tb_enterprise + where enterprise_id in + + #{one} + + + + + + diff --git a/cloud-modules/cloud-modules-template/src/main/resources/mapper/SysCarMapper.xml b/cloud-modules/cloud-modules-template/src/main/resources/mapper/SysCarMapper.xml new file mode 100644 index 0000000..792d531 --- /dev/null +++ b/cloud-modules/cloud-modules-template/src/main/resources/mapper/SysCarMapper.xml @@ -0,0 +1,83 @@ + + + + + INSERT INTO `four`.`sys_car` + ( `car_vin`, `car_type_id`, `state`, `car_motor_manufacturer`, `car_motor_model`, + `car_battery_manufacturer`, `car_battery_model`, `strategy_id`,`group_id`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`,) + VALUES (#{carVin}, #{carTypeId}, '1', #{carMotorManufacturer}, #{carMotorModel}, + #{carBatteryManufacturer}, #{carBatteryModel}, #{strategyId},#{groupId},#{createBy}, #{createTime}, #{updateBy}, #{updateTime}, #{remark}) + + + UPDATE `four`.`sys_car` + SET `car_vin` = #{carVin}, + `car_type_id` = #{carTypeId}, + `state` = #{state}, + `car_motor_manufacturer` = #{carMotorManufacturer}, + `car_motor_model` = #{carMotorModel}, + `car_battery_manufacturer` = #{carBatteryManufacturer}, + `car_battery_model` = #{carBatteryModel}, + `strategy_id` = #{strategyId}, + `group_id`=#{groupId} + `create_by` = #{createBy}, + `create_time` = #{createTime}, + `update_by` = #{updateBy}, + `update_time` = #{updateTime}, + `remark` = #{remark} WHERE `id` = #{id} + + + + + + + + + diff --git a/cloud-modules/cloud-modules-template/src/main/resources/mapper/TemplateNeedMapper.xml b/cloud-modules/cloud-modules-template/src/main/resources/mapper/TemplateNeedMapper.xml new file mode 100644 index 0000000..5ea4090 --- /dev/null +++ b/cloud-modules/cloud-modules-template/src/main/resources/mapper/TemplateNeedMapper.xml @@ -0,0 +1,10 @@ + + + + + + diff --git a/cloud-modules/cloud-modules-template/src/main/resources/mapper/WarnLogsMapper.xml b/cloud-modules/cloud-modules-template/src/main/resources/mapper/WarnLogsMapper.xml new file mode 100644 index 0000000..d837d31 --- /dev/null +++ b/cloud-modules/cloud-modules-template/src/main/resources/mapper/WarnLogsMapper.xml @@ -0,0 +1,31 @@ + + + + + INSERT INTO warn_logs VALUES + + (#{warnLogs.id}) + + + + + diff --git a/cloud-modules/cloud-modules-template/src/main/resources/mapper/WarnRuleMapper.xml b/cloud-modules/cloud-modules-template/src/main/resources/mapper/WarnRuleMapper.xml new file mode 100644 index 0000000..a18d318 --- /dev/null +++ b/cloud-modules/cloud-modules-template/src/main/resources/mapper/WarnRuleMapper.xml @@ -0,0 +1,23 @@ + + + + + + + + diff --git a/cloud-modules/cloud-modules-template/src/main/resources/mapper/WarnStrategyMapper.xml b/cloud-modules/cloud-modules-template/src/main/resources/mapper/WarnStrategyMapper.xml new file mode 100644 index 0000000..ce15729 --- /dev/null +++ b/cloud-modules/cloud-modules-template/src/main/resources/mapper/WarnStrategyMapper.xml @@ -0,0 +1,35 @@ + + + + + + + diff --git a/cloud-modules/pom.xml b/cloud-modules/pom.xml index a384525..0c01f75 100644 --- a/cloud-modules/pom.xml +++ b/cloud-modules/pom.xml @@ -24,6 +24,7 @@ saas cloud-modules-vehiclegateway cloud-event + cloud-modules-template cloud-modules diff --git a/cloud-modules/saas/saas-common/src/main/java/com/muyu/common/domain/Template.java b/cloud-modules/saas/saas-common/src/main/java/com/muyu/common/domain/Template.java index 70dbf2c..086116b 100644 --- a/cloud-modules/saas/saas-common/src/main/java/com/muyu/common/domain/Template.java +++ b/cloud-modules/saas/saas-common/src/main/java/com/muyu/common/domain/Template.java @@ -3,11 +3,13 @@ package com.muyu.common.domain; 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 io.swagger.v3.oas.annotations.tags.Tag; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; +import org.springframework.format.annotation.DateTimeFormat; import java.util.Date; @@ -47,5 +49,7 @@ public class Template { /** * 创建时间 */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date createTime; } diff --git a/cloud-modules/saas/saas-server/src/main/java/com/muyu/server/config/MqttConfigure.java b/cloud-modules/saas/saas-server/src/main/java/com/muyu/server/config/MqttConfigure.java index 41de3c7..dc3d1c1 100644 --- a/cloud-modules/saas/saas-server/src/main/java/com/muyu/server/config/MqttConfigure.java +++ b/cloud-modules/saas/saas-server/src/main/java/com/muyu/server/config/MqttConfigure.java @@ -23,7 +23,6 @@ public class MqttConfigure { @Autowired private TemplateService templateService; - @PostConstruct public void MQTTMonitoring(){ String topic = "vehicle"; diff --git a/cloud-modules/saas/saas-server/src/main/java/com/muyu/server/controller/TemplateController.java b/cloud-modules/saas/saas-server/src/main/java/com/muyu/server/controller/TemplateController.java index 36f5980..89dc512 100644 --- a/cloud-modules/saas/saas-server/src/main/java/com/muyu/server/controller/TemplateController.java +++ b/cloud-modules/saas/saas-server/src/main/java/com/muyu/server/controller/TemplateController.java @@ -6,13 +6,11 @@ import com.muyu.server.service.TemplateService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.AllArgsConstructor; +import lombok.extern.log4j.Log4j2; import org.apache.iotdb.rpc.IoTDBConnectionException; import org.apache.iotdb.rpc.StatementExecutionException; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.sql.SQLException; import java.util.List; @@ -25,6 +23,7 @@ import java.util.concurrent.ExecutionException; * @name:TemplateController * @Date:2024/9/20 12:12 */ +@Log4j2 @RestController @RequestMapping("/template") @AllArgsConstructor @@ -58,6 +57,18 @@ public class TemplateController { return Result.success(); } + /** + * 报文模版添加 + * @param template + * @return + */ + @PostMapping("/addTemplate") + @Operation(summary = "报文模版添加",description = "报文模版添加") + public Result addTemplate(@RequestBody Template template) { + boolean save = templateService.save(template); + log.info("添加的结果为:"+save); + return Result.success(); + } } diff --git a/cloud-modules/saas/saas-server/src/main/java/com/muyu/server/service/impl/MessageTemplateTypeServiceImpl.java b/cloud-modules/saas/saas-server/src/main/java/com/muyu/server/service/impl/MessageTemplateTypeServiceImpl.java index 1212ad0..2af6a7d 100644 --- a/cloud-modules/saas/saas-server/src/main/java/com/muyu/server/service/impl/MessageTemplateTypeServiceImpl.java +++ b/cloud-modules/saas/saas-server/src/main/java/com/muyu/server/service/impl/MessageTemplateTypeServiceImpl.java @@ -69,6 +69,7 @@ public class MessageTemplateTypeServiceImpl extends ServiceImpl findTemplateById(Integer templateId) { QueryWrapper messageTemplateTypeQueryWrapper = new QueryWrapper<>(); messageTemplateTypeQueryWrapper.eq("template_id",templateId); - return List.of(); + List messageTemplateTypes = messageTemplateTypeMapper.selectList(messageTemplateTypeQueryWrapper); + return messageTemplateTypes; } } diff --git a/cloud-modules/saas/saas-server/src/main/java/com/muyu/server/service/impl/TemplateServiceImpl.java b/cloud-modules/saas/saas-server/src/main/java/com/muyu/server/service/impl/TemplateServiceImpl.java index 34b0814..bfc2008 100644 --- a/cloud-modules/saas/saas-server/src/main/java/com/muyu/server/service/impl/TemplateServiceImpl.java +++ b/cloud-modules/saas/saas-server/src/main/java/com/muyu/server/service/impl/TemplateServiceImpl.java @@ -3,6 +3,7 @@ package com.muyu.server.service.impl; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson2.JSON; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.muyu.common.core.domain.Result; import com.muyu.common.domain.MessageTemplateType; import com.muyu.common.domain.SysCar; import com.muyu.common.domain.Template; @@ -46,69 +47,65 @@ public class TemplateServiceImpl extends ServiceImpl i @Override - public void messageParsing(String templateMessage) throws SQLException, IoTDBConnectionException, ClassNotFoundException, StatementExecutionException, ExecutionException, InterruptedException { + public void messageParsing(String messageStr) throws SQLException, IoTDBConnectionException, ClassNotFoundException, StatementExecutionException, ExecutionException, InterruptedException { - //给一个JSON对象 - JSONObject jsonObject = new JSONObject(); - //先截取出VIN码 然后根据VIN码查询这个车属于什么类型 - if (templateMessage.length() < 18) { - throw new RuntimeException("The vehicle message is incorrect"); - } - //将报文进行切割 - String[] hexArray = templateMessage.split(" "); + //根据空格切割数据 + String[] hexArray = messageStr.split(" "); StringBuilder result = new StringBuilder(); + //遍历十六进制数据转换为字符 for (String hex : hexArray) { int decimal = Integer.parseInt(hex, 16); result.append((char) decimal); } - //取出VIN码 - String carVin = result.substring(0, 18 - 1); - log.info("carVin码为:" + carVin); + //取出车辆VIN码 + String vehicleVin = result.substring(1, 18); + log.info("车辆VIN码: " + vehicleVin); //根据VIN码获取车辆信息 - SysCar carByVin = sysCarService.findCarByVin(carVin); - log.info("车辆信息为:" + carByVin); - //对应车辆所对应的报文模版 + SysCar carByVin = sysCarService.findCarByVin(vehicleVin); Integer templateId = carByVin.getTemplateId(); - - List templateTypeList; - - //key - String redisKey = "messageTemplateType" + templateId; - - //key存在 - if (redisTemplate.hasKey(redisKey)) { - - List list = redisTemplate.opsForList().range(redisKey, 0, -1); - - templateTypeList = list.stream().map(o -> JSON.parseObject(o.toString(), MessageTemplateType.class)) - .toList(); - - } else { - List templateTypeList1 = messageTemplateTypeService.findTemplateById(templateId); - templateTypeList = templateTypeList1; - templateTypeList.forEach( - templateType -> - redisTemplate.opsForList().rightPush( - redisKey, com.alibaba.fastjson.JSON.toJSONString(templateType) - ) - ); + List templateList; + //从redis缓存中获取报文模板数据 + try { + String redisKey = "messageTemplate" + templateId; + if (redisTemplate.hasKey(redisKey)) { + List list = redisTemplate.opsForList().range(redisKey, 0, -1); + templateList = list.stream() + .map(obj -> JSON.parseObject(obj.toString(), MessageTemplateType.class)) + .toList(); + log.info("Redis缓存查询成功"); + } else { + List byTemplateId = messageTemplateTypeService.findTemplateById(templateId); + log.info(byTemplateId); + templateList = byTemplateId; + templateList.forEach( + listResp -> + redisTemplate.opsForList().rightPush( + redisKey, JSON.toJSONString(listResp) + ) + ); + log.info("数据库查询成功"); + } + } catch (Exception e) { + throw new RuntimeException("获取报文模板失败"); } - //将模版里面有的配置进行循环 - for (MessageTemplateType messageTemplateType : templateTypeList) { - //开始位置 - Integer startIndex = messageTemplateType.getStartIndex() - 1; - //结束位置 - Integer endIndex = messageTemplateType.getEndIndex(); - //将每个解析后的字段都存入到JSON对象中 - jsonObject.put(messageTemplateType.getMessageField(), result.substring(startIndex, endIndex)); + //判断报文模板列表不为空 + if (templateList.isEmpty()) { + throw new RuntimeException("报文模版为空"); } + //存储报文模版解析后的数据 + JSONObject jsonObject = new JSONObject(); + for (MessageTemplateType messageValue : templateList) { + //起始位下标 + Integer startIndex = messageValue.getStartIndex() - 1; + //结束位下标 + Integer endIndex = messageValue.getEndIndex(); + //根据报文模版截取数据 - System.out.println("哈哈哈红红火火恍恍惚惚"); - log.info("解析后的报文是:" + jsonObject); - - + String value = result.substring(startIndex, endIndex); + //存入数据 + jsonObject.put(messageValue.getMessageField(), value); + } + System.out.println(jsonObject); } - - }