初始化仓库
parent
6246174a98
commit
f56163e112
|
@ -0,0 +1,106 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-modules</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>cloud-modules-breakdown</artifactId>
|
||||
|
||||
<description>
|
||||
cloud-modules-breakdown故障模块
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- SpringCloud Alibaba Nacos -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringCloud Alibaba Nacos Config -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringCloud Alibaba Sentinel -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringBoot Actuator -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Mysql Connector -->
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MuYu Common DataSource -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-datasource</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MuYu Common DataScope -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-datascope</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MuYu Common Log -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-log</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 接口模块 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-api-doc</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- XllJob定时任务 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-xxl</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-rabbit</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,21 @@
|
|||
package com.muyu.breakdown;
|
||||
|
||||
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 muyu
|
||||
*/
|
||||
@EnableCustomConfig
|
||||
//@EnableCustomSwagger2
|
||||
@EnableMyFeignClients
|
||||
@SpringBootApplication
|
||||
public class CloudBreakdownApplication {
|
||||
public static void main (String[] args) {
|
||||
SpringApplication.run(CloudBreakdownApplication.class, args);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
package com.muyu.breakdown.controller;
|
||||
|
||||
import com.muyu.breakdown.domain.SysCarFault;
|
||||
import com.muyu.breakdown.service.SysCarFaultService;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.utils.poi.ExcelUtil;
|
||||
import com.muyu.common.core.web.controller.BaseController;
|
||||
import com.muyu.common.core.web.page.TableDataInfo;
|
||||
import com.muyu.common.security.annotation.RequiresPermissions;
|
||||
import com.muyu.common.security.utils.SecurityUtils;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassDescription:
|
||||
* @JdkVersion: 1.8
|
||||
* @Author: YZL
|
||||
* @Created: 2024/9/20 11:00
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/breakdown")
|
||||
public class SysCarFaultController extends BaseController
|
||||
{
|
||||
@Resource
|
||||
private SysCarFaultService sysCarFaultService;
|
||||
|
||||
/**
|
||||
* 查询车辆故障管理列表
|
||||
*/
|
||||
@RequiresPermissions("breakdown:breakdown:list")
|
||||
@GetMapping("/list")
|
||||
public Result<TableDataInfo<SysCarFault>> list(SysCarFault sysCarFault)
|
||||
{
|
||||
startPage();
|
||||
List<SysCarFault> list = sysCarFaultService.selectSysCarFaultList(sysCarFault);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出车辆故障管理列表
|
||||
*/
|
||||
@RequiresPermissions("breakdown:breakdown:export")
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, SysCarFault sysCarFault)
|
||||
{
|
||||
List<SysCarFault> list = sysCarFaultService.selectSysCarFaultList(sysCarFault);
|
||||
ExcelUtil<SysCarFault> util = new ExcelUtil<SysCarFault>(SysCarFault.class);
|
||||
util.exportExcel(response, list, "车辆故障管理数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取车辆故障管理详细信息
|
||||
*/
|
||||
@RequiresPermissions("breakdown:breakdown:query")
|
||||
@GetMapping(value = "/{id}")
|
||||
public Result<List<SysCarFault>> getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return success(sysCarFaultService.selectSysCarFaultById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增车辆故障管理
|
||||
*/
|
||||
@RequiresPermissions("breakdown:breakdown:add")
|
||||
@PostMapping
|
||||
public Result<Integer> add(
|
||||
@Validated @RequestBody SysCarFault sysCarFault)
|
||||
{
|
||||
if (sysCarFaultService.checkIdUnique(sysCarFault)) {
|
||||
return error("新增 车辆故障管理 '" + sysCarFault + "'失败,车辆故障管理已存在");
|
||||
}
|
||||
sysCarFault.setCreateBy(SecurityUtils.getUsername());
|
||||
return toAjax(sysCarFaultService.save(sysCarFault));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改车辆故障管理
|
||||
*/
|
||||
@RequiresPermissions("breakdown:breakdown:edit")
|
||||
@PutMapping
|
||||
public Result<Integer> edit(
|
||||
@Validated @RequestBody SysCarFault sysCarFault)
|
||||
{
|
||||
if (!sysCarFaultService.checkIdUnique(sysCarFault)) {
|
||||
return error("修改 车辆故障管理 '" + sysCarFault + "'失败,车辆故障管理不存在");
|
||||
}
|
||||
sysCarFault.setUpdateBy(SecurityUtils.getUsername());
|
||||
return toAjax(sysCarFaultService.updateById(sysCarFault));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除车辆故障管理
|
||||
*/
|
||||
@RequiresPermissions("breakdown:breakdown:remove")
|
||||
@DeleteMapping("/{ids}")
|
||||
public Result<Integer> remove(@PathVariable("ids") Long[] ids)
|
||||
{
|
||||
sysCarFaultService.removeBatchByIds(Arrays.asList(ids));
|
||||
return success();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,116 @@
|
|||
package com.muyu.breakdown.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.muyu.common.core.annotation.Excel;
|
||||
import com.muyu.common.core.web.domain.BaseEntity;
|
||||
import lombok.*;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
/**
|
||||
* @ClassDescription: 车辆故障管理对象
|
||||
* @JdkVersion: 1.8
|
||||
* @Author: YZL
|
||||
* @Created: 2024/9/20 10:56
|
||||
*/
|
||||
@Data
|
||||
@Setter
|
||||
@Getter
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("sys_car_fault")
|
||||
public class SysCarFault extends BaseEntity{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 参数主键 */
|
||||
@TableId( type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/** 故障码编码 */
|
||||
@Excel(name = "故障码编码")
|
||||
private String faultCode;
|
||||
|
||||
/** 故障名 */
|
||||
@Excel(name = "故障名")
|
||||
private String faultName;
|
||||
|
||||
/** 故障类型 */
|
||||
@Excel(name = "故障类型")
|
||||
private Long typeId;
|
||||
|
||||
/** 车辆VIN码 */
|
||||
@Excel(name = "车辆VIN码")
|
||||
private String carVin;
|
||||
|
||||
/** 故障标签 */
|
||||
@Excel(name = "故障标签")
|
||||
private String faultLabel;
|
||||
|
||||
/** 故障组 */
|
||||
@Excel(name = "故障组")
|
||||
private String faultGroup;
|
||||
|
||||
/** 故障位 */
|
||||
@Excel(name = "故障位")
|
||||
private String faultBit;
|
||||
|
||||
/** 故障值 */
|
||||
@Excel(name = "故障值")
|
||||
private String faultValue;
|
||||
|
||||
/** 故障级别 (0.低 ,2.中 ,3.高) */
|
||||
@Excel(name = "故障级别 (0.低 ,2.中 ,3.高)")
|
||||
private Long faultRank;
|
||||
|
||||
/** 故障描述信息 */
|
||||
@Excel(name = "故障描述信息")
|
||||
private String faultDesc;
|
||||
|
||||
/** 故障最小阈值 */
|
||||
@Excel(name = "故障最小阈值")
|
||||
private String faultMinThreshold;
|
||||
|
||||
/** 故障最大阈值 */
|
||||
@Excel(name = "故障最大阈值")
|
||||
private String faultMaxThreshold;
|
||||
|
||||
/** 启用状态(1.待处理 2.处理中 3.已处理 4.忽略) */
|
||||
@Excel(name = "启用状态(1.待处理 2.处理中 3.已处理 4.忽略)")
|
||||
private Long status;
|
||||
|
||||
/** 是否警告(0.开启 1.禁止) */
|
||||
@Excel(name = "是否警告(0.开启 1.禁止)")
|
||||
private Long warnStatus;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("id", getId())
|
||||
.append("faultCode", getFaultCode())
|
||||
.append("faultName", getFaultName())
|
||||
.append("typeId", getTypeId())
|
||||
.append("carVin", getCarVin())
|
||||
.append("faultLabel", getFaultLabel())
|
||||
.append("faultGroup", getFaultGroup())
|
||||
.append("faultBit", getFaultBit())
|
||||
.append("faultValue", getFaultValue())
|
||||
.append("faultRank", getFaultRank())
|
||||
.append("faultDesc", getFaultDesc())
|
||||
.append("faultMinThreshold", getFaultMinThreshold())
|
||||
.append("faultMaxThreshold", getFaultMaxThreshold())
|
||||
.append("status", getStatus())
|
||||
.append("warnStatus", getWarnStatus())
|
||||
.append("remark", getRemark())
|
||||
.append("createBy", getCreateBy())
|
||||
.append("createTime", getCreateTime())
|
||||
.append("updateBy", getUpdateBy())
|
||||
.append("updateTime", getUpdateTime())
|
||||
.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.muyu.breakdown.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.muyu.common.core.web.domain.BaseEntity;
|
||||
import lombok.*;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* @ClassDescription:
|
||||
* @JdkVersion: 1.8
|
||||
* @Author: YZL
|
||||
* @Created: 2024/9/20 11:34
|
||||
*/
|
||||
@Data
|
||||
@Setter
|
||||
@Getter
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("sys_car_fault_type")
|
||||
public class SysCarFaultType {
|
||||
private Long faultTypeId;
|
||||
private String faultTypeName;
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.muyu.breakdown.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.muyu.breakdown.domain.SysCarFault;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @ClassDescription: 车辆故障管理Mapper接口
|
||||
* @JdkVersion: 1.8
|
||||
* @Author: YZL
|
||||
* @Created: 2024/9/20 10:57
|
||||
*/
|
||||
@Mapper
|
||||
public interface SysCarFaultMapper extends BaseMapper<SysCarFault>{
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package com.muyu.breakdown.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.breakdown.domain.SysCarFault;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassDescription: 车辆故障管理Service接口
|
||||
* @JdkVersion: 1.8
|
||||
* @Author: YZL
|
||||
* @Created: 2024/9/20 10:57
|
||||
*/
|
||||
public interface SysCarFaultService extends IService<SysCarFault> {
|
||||
/**
|
||||
* 精确查询车辆故障管理
|
||||
*
|
||||
* @param id 车辆故障管理主键
|
||||
* @return 车辆故障管理
|
||||
*/
|
||||
public SysCarFault selectSysCarFaultById(Long id);
|
||||
|
||||
/**
|
||||
* 查询车辆故障管理列表
|
||||
*
|
||||
* @param sysCarFault 车辆故障管理
|
||||
* @return 车辆故障管理集合
|
||||
*/
|
||||
public List<SysCarFault> selectSysCarFaultList(SysCarFault sysCarFault);
|
||||
|
||||
/**
|
||||
* 判断 车辆故障管理 id是否唯一
|
||||
* @param sysCarFault 车辆故障管理
|
||||
* @return 结果
|
||||
*/
|
||||
Boolean checkIdUnique(SysCarFault sysCarFault);
|
||||
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
package com.muyu.breakdown.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.breakdown.domain.SysCarFault;
|
||||
import com.muyu.breakdown.mapper.SysCarFaultMapper;
|
||||
import com.muyu.breakdown.service.SysCarFaultService;
|
||||
import com.muyu.common.core.utils.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassDescription: 车辆故障管理Service业务层处理
|
||||
* @JdkVersion: 1.8
|
||||
* @Author: YZL
|
||||
* @Created: 2024/9/20 10:58
|
||||
*/
|
||||
@Service
|
||||
public class SysCarFaultServiceImpl
|
||||
extends ServiceImpl<SysCarFaultMapper, SysCarFault>
|
||||
implements SysCarFaultService {
|
||||
|
||||
/**
|
||||
* 精确查询车辆故障管理
|
||||
*
|
||||
* @param id 车辆故障管理主键
|
||||
* @return 车辆故障管理
|
||||
*/
|
||||
@Override
|
||||
public SysCarFault selectSysCarFaultById(Long id)
|
||||
{
|
||||
LambdaQueryWrapper<SysCarFault> queryWrapper = new LambdaQueryWrapper<>();
|
||||
Assert.notNull(id, "id不可为空");
|
||||
queryWrapper.eq(SysCarFault::getId, id);
|
||||
return this.getOne(queryWrapper);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询车辆故障管理列表
|
||||
*
|
||||
* @param sysCarFault 车辆故障管理
|
||||
* @return 车辆故障管理
|
||||
*/
|
||||
@Override
|
||||
public List<SysCarFault> selectSysCarFaultList(SysCarFault sysCarFault)
|
||||
{
|
||||
LambdaQueryWrapper<SysCarFault> queryWrapper = new LambdaQueryWrapper<>();
|
||||
if (StringUtils.isNotEmpty(sysCarFault.getFaultCode())){
|
||||
queryWrapper.eq(SysCarFault::getFaultCode, sysCarFault.getFaultCode());
|
||||
}
|
||||
if (StringUtils.isNotEmpty(sysCarFault.getFaultBit())){
|
||||
queryWrapper.eq(SysCarFault::getFaultBit, sysCarFault.getFaultBit());
|
||||
}
|
||||
if (sysCarFault.getFaultRank()!=null){
|
||||
queryWrapper.eq(SysCarFault::getFaultRank, sysCarFault.getFaultRank());
|
||||
}
|
||||
return this.list(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 唯一 判断
|
||||
* @param sysCarFault 车辆故障管理
|
||||
* @return 车辆故障管理
|
||||
*/
|
||||
@Override
|
||||
public Boolean checkIdUnique(SysCarFault sysCarFault) {
|
||||
LambdaQueryWrapper<SysCarFault> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(SysCarFault::getId, sysCarFault.getId());
|
||||
return this.count(queryWrapper) > 0;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
Spring Boot Version: ${spring-boot.version}
|
||||
Spring Application Name: ${spring.application.name}
|
|
@ -0,0 +1,60 @@
|
|||
# Tomcat
|
||||
server:
|
||||
port: 9702
|
||||
|
||||
# nacos线上地址
|
||||
nacos:
|
||||
addr: 47.101.53.251:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: four
|
||||
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
|
||||
# Spring
|
||||
spring:
|
||||
amqp:
|
||||
deserialization:
|
||||
trust:
|
||||
all: true
|
||||
main:
|
||||
allow-bean-definition-overriding: true
|
||||
application:
|
||||
# 应用名称
|
||||
name: cloud-breakdown
|
||||
profiles:
|
||||
# 环境配置
|
||||
active: dev
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: ${nacos.addr}
|
||||
# nacos用户名
|
||||
username: ${nacos.user-name}
|
||||
# nacos密码
|
||||
password: ${nacos.password}
|
||||
# 命名空间
|
||||
namespace: ${nacos.namespace}
|
||||
config:
|
||||
# 服务注册地址
|
||||
server-addr: ${nacos.addr}
|
||||
# nacos用户名
|
||||
username: ${nacos.user-name}
|
||||
# nacos密码
|
||||
password: ${nacos.password}
|
||||
# 命名空间
|
||||
namespace: ${nacos.namespace}
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
shared-configs:
|
||||
# 系统共享配置
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
# 系统环境Config共享配置
|
||||
- application-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
# xxl-job 配置文件
|
||||
- application-xxl-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
# rabbit 配置文件
|
||||
- application-rabbit-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
logging:
|
||||
level:
|
||||
com.muyu.breakdown.mapper: DEBUG
|
|
@ -0,0 +1,74 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||
<!-- 日志存放路径 -->
|
||||
<property name="log.path" value="logs/cloud-breakdown"/>
|
||||
<!-- 日志输出格式 -->
|
||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
|
||||
<!-- 控制台输出 -->
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- 系统日志输出 -->
|
||||
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/info.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>INFO</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/error.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>ERROR</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- 系统模块日志级别控制 -->
|
||||
<logger name="com.muyu" level="info"/>
|
||||
<!-- Spring日志级别控制 -->
|
||||
<logger name="org.springframework" level="warn"/>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="console"/>
|
||||
</root>
|
||||
|
||||
<!--系统操作日志-->
|
||||
<root level="info">
|
||||
<appender-ref ref="file_info"/>
|
||||
<appender-ref ref="file_error"/>
|
||||
</root>
|
||||
</configuration>
|
|
@ -0,0 +1,81 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||
<!-- 日志存放路径 -->
|
||||
<property name="log.path" value="logs/cloud-breakdown"/>
|
||||
<!-- 日志输出格式 -->
|
||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
<property name="log.sky.pattern" value="%d{HH:mm:ss.SSS} %yellow([%tid]) [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
|
||||
<!-- 控制台输出 -->
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>${log.sky.pattern}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- 系统日志输出 -->
|
||||
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/info.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>INFO</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/error.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>ERROR</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- 使用gRpc将日志发送到skywalking服务端 -->
|
||||
<appender name="GRPC_LOG" class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.log.GRPCLogClientAppender">
|
||||
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
|
||||
<layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
|
||||
<Pattern>${log.sky.pattern}</Pattern>
|
||||
</layout>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- 系统模块日志级别控制 -->
|
||||
<logger name="com.muyu" level="info"/>
|
||||
<!-- Spring日志级别控制 -->
|
||||
<logger name="org.springframework" level="warn"/>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="GRPC_LOG"/>
|
||||
<appender-ref ref="console"/>
|
||||
</root>
|
||||
|
||||
<!--系统操作日志-->
|
||||
<root level="info">
|
||||
<appender-ref ref="file_info"/>
|
||||
<appender-ref ref="file_error"/>
|
||||
</root>
|
||||
</configuration>
|
|
@ -0,0 +1,81 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||
<!-- 日志存放路径 -->
|
||||
<property name="log.path" value="logs/cloud-breakdown"/>
|
||||
<!-- 日志输出格式 -->
|
||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
<property name="log.sky.pattern" value="%d{HH:mm:ss.SSS} %yellow([%tid]) [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
|
||||
<!-- 控制台输出 -->
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>${log.sky.pattern}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- 系统日志输出 -->
|
||||
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/info.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>INFO</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/error.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>ERROR</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- 使用gRpc将日志发送到skywalking服务端 -->
|
||||
<appender name="GRPC_LOG" class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.log.GRPCLogClientAppender">
|
||||
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
|
||||
<layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
|
||||
<Pattern>${log.sky.pattern}</Pattern>
|
||||
</layout>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- 系统模块日志级别控制 -->
|
||||
<logger name="com.muyu" level="info"/>
|
||||
<!-- Spring日志级别控制 -->
|
||||
<logger name="org.springframework" level="warn"/>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="GRPC_LOG"/>
|
||||
<appender-ref ref="console"/>
|
||||
</root>
|
||||
|
||||
<!--系统操作日志-->
|
||||
<root level="info">
|
||||
<appender-ref ref="file_info"/>
|
||||
<appender-ref ref="file_error"/>
|
||||
</root>
|
||||
</configuration>
|
|
@ -0,0 +1,130 @@
|
|||
<?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.muyu.breakdown.mapper.SysCarFaultMapper">
|
||||
|
||||
<resultMap type="com.muyu.breakdown.domain.SysCarFault" id="SysCarFaultResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="faultCode" column="fault_code" />
|
||||
<result property="faultName" column="fault_name" />
|
||||
<result property="typeId" column="type_id" />
|
||||
<result property="carVin" column="car_vin" />
|
||||
<result property="faultLabel" column="fault_label" />
|
||||
<result property="faultGroup" column="fault_group" />
|
||||
<result property="faultBit" column="fault_bit" />
|
||||
<result property="faultValue" column="fault_value" />
|
||||
<result property="faultRank" column="fault_rank" />
|
||||
<result property="faultDesc" column="fault_desc" />
|
||||
<result property="faultMinThreshold" column="fault_min_threshold" />
|
||||
<result property="faultMaxThreshold" column="fault_max_threshold" />
|
||||
<result property="status" column="status" />
|
||||
<result property="warnStatus" column="warn_status" />
|
||||
<result property="remark" column="remark" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectSysCarFaultVo">
|
||||
select id, fault_code, fault_name, type_id, car_vin, fault_label, fault_group, fault_bit, fault_value, fault_rank, fault_desc, fault_min_threshold, fault_max_threshold, status, warn_status, remark, create_by, create_time, update_by, update_time from sys_car_fault
|
||||
</sql>
|
||||
|
||||
<select id="selectSysCarFaultList" parameterType="com.muyu.breakdown.domain.SysCarFault" resultMap="SysCarFaultResult">
|
||||
<include refid="selectSysCarFaultVo"/>
|
||||
<where>
|
||||
<if test="faultCode != null and faultCode != ''"> and fault_code = #{faultCode}</if>
|
||||
<if test="faultBit != null and faultBit != ''"> and fault_bit = #{faultBit}</if>
|
||||
<if test="faultRank != null "> and fault_rank = #{faultRank}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectSysCarFaultById" parameterType="Long" resultMap="SysCarFaultResult">
|
||||
<include refid="selectSysCarFaultVo"/>
|
||||
where id = #{id}
|
||||
</select>
|
||||
|
||||
<insert id="insertSysCarFault" parameterType="com.muyu.breakdown.domain.SysCarFault" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into sys_car_fault
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="faultCode != null and faultCode != ''">fault_code,</if>
|
||||
<if test="faultName != null">fault_name,</if>
|
||||
<if test="typeId != null">type_id,</if>
|
||||
<if test="carVin != null">car_vin,</if>
|
||||
<if test="faultLabel != null">fault_label,</if>
|
||||
<if test="faultGroup != null">fault_group,</if>
|
||||
<if test="faultBit != null">fault_bit,</if>
|
||||
<if test="faultValue != null">fault_value,</if>
|
||||
<if test="faultRank != null">fault_rank,</if>
|
||||
<if test="faultDesc != null">fault_desc,</if>
|
||||
<if test="faultMinThreshold != null">fault_min_threshold,</if>
|
||||
<if test="faultMaxThreshold != null">fault_max_threshold,</if>
|
||||
<if test="status != null">status,</if>
|
||||
<if test="warnStatus != null">warn_status,</if>
|
||||
<if test="remark != null">remark,</if>
|
||||
<if test="createBy != null">create_by,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
<if test="updateBy != null">update_by,</if>
|
||||
<if test="updateTime != null">update_time,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="faultCode != null and faultCode != ''">#{faultCode},</if>
|
||||
<if test="faultName != null">#{faultName},</if>
|
||||
<if test="typeId != null">#{typeId},</if>
|
||||
<if test="carVin != null">#{carVin},</if>
|
||||
<if test="faultLabel != null">#{faultLabel},</if>
|
||||
<if test="faultGroup != null">#{faultGroup},</if>
|
||||
<if test="faultBit != null">#{faultBit},</if>
|
||||
<if test="faultValue != null">#{faultValue},</if>
|
||||
<if test="faultRank != null">#{faultRank},</if>
|
||||
<if test="faultDesc != null">#{faultDesc},</if>
|
||||
<if test="faultMinThreshold != null">#{faultMinThreshold},</if>
|
||||
<if test="faultMaxThreshold != null">#{faultMaxThreshold},</if>
|
||||
<if test="status != null">#{status},</if>
|
||||
<if test="warnStatus != null">#{warnStatus},</if>
|
||||
<if test="remark != null">#{remark},</if>
|
||||
<if test="createBy != null">#{createBy},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
<if test="updateBy != null">#{updateBy},</if>
|
||||
<if test="updateTime != null">#{updateTime},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateSysCarFault" parameterType="com.muyu.breakdown.domain.SysCarFault">
|
||||
update sys_car_fault
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="faultCode != null and faultCode != ''">fault_code = #{faultCode},</if>
|
||||
<if test="faultName != null">fault_name = #{faultName},</if>
|
||||
<if test="typeId != null">type_id = #{typeId},</if>
|
||||
<if test="carVin != null">car_vin = #{carVin},</if>
|
||||
<if test="faultLabel != null">fault_label = #{faultLabel},</if>
|
||||
<if test="faultGroup != null">fault_group = #{faultGroup},</if>
|
||||
<if test="faultBit != null">fault_bit = #{faultBit},</if>
|
||||
<if test="faultValue != null">fault_value = #{faultValue},</if>
|
||||
<if test="faultRank != null">fault_rank = #{faultRank},</if>
|
||||
<if test="faultDesc != null">fault_desc = #{faultDesc},</if>
|
||||
<if test="faultMinThreshold != null">fault_min_threshold = #{faultMinThreshold},</if>
|
||||
<if test="faultMaxThreshold != null">fault_max_threshold = #{faultMaxThreshold},</if>
|
||||
<if test="status != null">status = #{status},</if>
|
||||
<if test="warnStatus != null">warn_status = #{warnStatus},</if>
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
<if test="createBy != null">create_by = #{createBy},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteSysCarFaultById" parameterType="Long">
|
||||
delete from sys_car_fault where id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteSysCarFaultByIds" parameterType="String">
|
||||
delete from sys_car_fault where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
|
@ -0,0 +1,59 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-modules</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
<artifactId>cloud-modules-wechat</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>4.9.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.thoughtworks.xstream</groupId>
|
||||
<artifactId>xstream</artifactId>
|
||||
<version>1.4.20</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.34</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
<version>3.3.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<version>3.3.2</version>
|
||||
</dependency>
|
||||
<!-- DOM4J是 dom4j.org 出品的一个开源XML解析包-->
|
||||
<dependency>
|
||||
<groupId>org.dom4j</groupId>
|
||||
<artifactId>dom4j</artifactId>
|
||||
<version>2.1.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2</artifactId>
|
||||
<version>2.0.43</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,18 @@
|
|||
package com.muyu.wechat;
|
||||
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* @ClassDescription:
|
||||
* @JdkVersion: 1.8
|
||||
* @Author: YZL
|
||||
* @Created: 2024/9/19 14:26
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class CloudWeChatApplication {
|
||||
public static void main (String[] args) {
|
||||
SpringApplication.run(CloudWeChatApplication.class, args);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,155 @@
|
|||
package com.muyu.wechat.controller;
|
||||
|
||||
|
||||
import com.muyu.wechat.domain.Message;
|
||||
import com.muyu.wechat.message.Article;
|
||||
import com.muyu.wechat.message.NewMessage;
|
||||
import com.muyu.wechat.util.TokenUtil;
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
import io.micrometer.common.util.StringUtils;
|
||||
import jakarta.servlet.ServletInputStream;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.DocumentException;
|
||||
import org.dom4j.Element;
|
||||
import org.dom4j.io.SAXReader;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @ClassDescription:
|
||||
* @JdkVersion: 1.8
|
||||
* @Author: YZL
|
||||
* @Created: 2024/9/19 20:26
|
||||
*/
|
||||
@RestController
|
||||
public class WxTestController {
|
||||
|
||||
|
||||
@PostMapping("/")
|
||||
public String receiveMessage(HttpServletRequest request) {
|
||||
ServletInputStream inputStream = null;
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
try {
|
||||
inputStream = request.getInputStream();
|
||||
SAXReader saxReader = new SAXReader();
|
||||
//读取request输入流,获得Document对象
|
||||
Document document = saxReader.read(inputStream);
|
||||
//获得root结点
|
||||
Element rootElement = document.getRootElement();
|
||||
//获取所有的子节点
|
||||
List<Element> elements = rootElement.elements();
|
||||
for (Element element : elements) {
|
||||
map.put(element.getName(), element.getStringValue());
|
||||
}
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (DocumentException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
System.out.println(map);
|
||||
//回复消息
|
||||
String message = "";
|
||||
if ("图文".equals(map.get("Content"))) {
|
||||
message = getReplyNewsMessage(map);
|
||||
} else {
|
||||
message = getReplyMessage(map);
|
||||
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得回复的消息内容
|
||||
*
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
private String getReplyMessage(HashMap<String, String> map) {
|
||||
Message message = new Message();
|
||||
message.setToUserName(map.get("FromUserName"));
|
||||
message.setFromUserName(map.get("ToUserName"));
|
||||
// message.setMsgType(map.get("MsgType"));
|
||||
message.setMsgType("text");
|
||||
message.setCreateTime(System.currentTimeMillis() / 1000);
|
||||
message.setContent("自动回复:您好");
|
||||
//XStream将java对象转换为xml字符串
|
||||
XStream xStream = new XStream();
|
||||
xStream.processAnnotations(Message.class);
|
||||
String xml = xStream.toXML(message);
|
||||
return xml;
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/")
|
||||
public String check(@RequestParam("signature") String signature, @RequestParam("timestamp") String timestamp,
|
||||
@RequestParam("nonce") String nonce, @RequestParam("echostr") String echostr) {
|
||||
|
||||
//1.将token、timestamp、nonce三个参数进行字典排序
|
||||
String token = "asdasd";
|
||||
List<String> list = Arrays.asList(token, timestamp, nonce);
|
||||
//排序
|
||||
Collections.sort(list);
|
||||
//2.将三个参数字符串拼接成一个字符串进行sha1加密
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (String s : list) {
|
||||
stringBuilder.append(s);
|
||||
}
|
||||
//加密
|
||||
try {
|
||||
MessageDigest instance = MessageDigest.getInstance("sha1");
|
||||
//使用sha1进行加密,获得byte数组
|
||||
byte[] digest = instance.digest(stringBuilder.toString().getBytes());
|
||||
StringBuilder sum = new StringBuilder();
|
||||
for (byte b : digest) {
|
||||
sum.append(Integer.toHexString((b >> 4) & 15));
|
||||
sum.append(Integer.toHexString(b & 15));
|
||||
}
|
||||
//3.开发者获得加密后的字符串可与signature对比,标识该请求来源于微信
|
||||
if (!StringUtils.isEmpty(signature) && signature.equals(sum.toString())) {
|
||||
return echostr;
|
||||
}
|
||||
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@PostMapping("/test")
|
||||
public void test() {
|
||||
String accessToken = TokenUtil.getAccessToken();
|
||||
System.out.println(accessToken);
|
||||
}
|
||||
|
||||
private String getReplyNewsMessage(Map<String, String> map) {
|
||||
NewMessage newsMessage = new NewMessage();
|
||||
newsMessage.setToUserName(map.get("FromUserName"));
|
||||
newsMessage.setFromUserName(map.get("ToUserName"));
|
||||
newsMessage.setMsgType("news");
|
||||
newsMessage.setCreateTime(System.currentTimeMillis() / 1000);
|
||||
newsMessage.setArticleCount(1);
|
||||
List<Article> articles = new ArrayList<>();
|
||||
Article article = new Article();
|
||||
article.setTitle("oneone哦恩恩");
|
||||
article.setDescription("详细描述--------------信息");
|
||||
article.setUrl("https://www.baidu.com");
|
||||
article.setPicUrl("http://mmbiz.qpic.cn/mmbiz_jpg/RiaWwmABEMmkFKQMeQZLLYaxknlzE9CxSozVSH42iaXiaQcia5hPPUicuNYbS8dG99zsMZ1ic266ialM42Mbn8SkN54kA/0");
|
||||
articles.add(article);
|
||||
newsMessage.setArticles(articles);
|
||||
//XStream将java对象转换为xml字符串
|
||||
XStream xStream = new XStream();
|
||||
xStream.processAnnotations(NewMessage.class);
|
||||
String xml = xStream.toXML(newsMessage);
|
||||
return xml;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package com.muyu.wechat.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @ClassDescription:
|
||||
* @JdkVersion: 1.8
|
||||
* @Author: YZL
|
||||
* @Created: 2024/9/19 20:26
|
||||
*/
|
||||
@Data
|
||||
public class AccessToken {
|
||||
|
||||
|
||||
private String access_token;
|
||||
|
||||
private Long expires_in;
|
||||
|
||||
public void setExpiresTime(Long expiresIn) {
|
||||
this.expires_in = System.currentTimeMillis() + expiresIn * 1000;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.muyu.wechat.domain;
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @ClassDescription:
|
||||
* @JdkVersion: 1.8
|
||||
* @Author: YZL
|
||||
* @Created: 2024/9/19 20:26
|
||||
*/
|
||||
@Data
|
||||
@XStreamAlias("xml")
|
||||
public class Message {
|
||||
@XStreamAlias("ToUserName")
|
||||
private String toUserName;
|
||||
|
||||
@XStreamAlias("FromUserName")
|
||||
private String fromUserName;
|
||||
|
||||
@XStreamAlias("CreateTime")
|
||||
private Long createTime;
|
||||
|
||||
@XStreamAlias("MsgType")
|
||||
private String msgType;
|
||||
|
||||
@XStreamAlias("Content")
|
||||
private String content;
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.muyu.wechat.message;
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @ClassDescription:
|
||||
* @JdkVersion: 1.8
|
||||
* @Author: YZL
|
||||
* @Created: 2024/9/19 20:26
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@XStreamAlias("item")
|
||||
public class Article {
|
||||
@XStreamAlias("Title")
|
||||
private String title;
|
||||
@XStreamAlias("Description")
|
||||
private String description;
|
||||
@XStreamAlias("PicUrl")
|
||||
private String picUrl;
|
||||
@XStreamAlias("Url")
|
||||
private String url;
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package com.muyu.wechat.message;
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassDescription:
|
||||
* @JdkVersion: 1.8
|
||||
* @Author: YZL
|
||||
* @Created: 2024/9/19 20:26
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@XStreamAlias("xml")
|
||||
public class NewMessage {
|
||||
@XStreamAlias("ToUserName")
|
||||
private String toUserName;
|
||||
@XStreamAlias("FromUserName")
|
||||
private String fromUserName;
|
||||
@XStreamAlias("CreateTime")
|
||||
private long createTime;
|
||||
@XStreamAlias("MsgType")
|
||||
private String msgType;
|
||||
@XStreamAlias("ArticleCount")
|
||||
private int articleCount;
|
||||
@XStreamAlias("Articles")
|
||||
private List<Article> articles;
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package com.muyu.wechat.util;
|
||||
|
||||
import okhttp3.*;
|
||||
|
||||
import java.io.IOException;
|
||||
/**
|
||||
* @ClassDescription:
|
||||
* @JdkVersion: 1.8
|
||||
* @Author: YZL
|
||||
* @Created: 2024/9/19 20:26
|
||||
*/
|
||||
public class OkHttpUtils {
|
||||
|
||||
private static final OkHttpClient client = new OkHttpClient();
|
||||
|
||||
public static String sendGetRequest(String urlString) {
|
||||
Request request = new Request.Builder()
|
||||
.url(urlString)
|
||||
.build();
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
return response.body().string();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String sendPostRequest(String urlString, String params) {
|
||||
RequestBody requestBody = RequestBody.create(params, MediaType.parse("application/json; charset=utf-8"));
|
||||
Request request = new Request.Builder()
|
||||
.url(urlString)
|
||||
.post(requestBody)
|
||||
.build();
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
return response.body().string();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package com.muyu.wechat.util;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
|
||||
import com.muyu.wechat.domain.AccessToken;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @ClassDescription:
|
||||
* @JdkVersion: 1.8
|
||||
* @Author: YZL
|
||||
* @Created: 2024/9/19 20:26
|
||||
*/
|
||||
@Component
|
||||
public class TokenUtil {
|
||||
private final static String APP_ID = "wx1d843111e24945c4";
|
||||
|
||||
private final static String APP_SECRET = "f625fc9e03e6bb5f4959b51f0650f1a8";
|
||||
|
||||
private static AccessToken accessToken = new AccessToken();
|
||||
|
||||
|
||||
public static void getToken() {
|
||||
String url = String.format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s", APP_ID, APP_SECRET);
|
||||
String request = OkHttpUtils.sendGetRequest(url);
|
||||
AccessToken wechatToken = JSON.parseObject(request, AccessToken.class);
|
||||
if (wechatToken != null) {
|
||||
accessToken.setExpiresTime(wechatToken.getExpires_in());
|
||||
accessToken.setAccess_token(wechatToken.getAccess_token());
|
||||
}
|
||||
}
|
||||
|
||||
public static String getAccessToken() {
|
||||
getToken();
|
||||
return accessToken.getAccess_token();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
# Tomcat
|
||||
server:
|
||||
port: 12000
|
|
@ -15,6 +15,8 @@
|
|||
<module>cloud-modules-template</module>
|
||||
<module>cloud-modules-fence</module>
|
||||
<module>cloud-modules-car</module>
|
||||
<module>cloud-modules-wechat</module>
|
||||
<module>cloud-modules-breakdown</module>
|
||||
<module>cloud-car</module>
|
||||
</modules>
|
||||
|
||||
|
|
Loading…
Reference in New Issue