1.
luofl
2025-02-23 8c4f42c77afb6690fcc48ac219ae044173fd77dd
1.
4个文件已修改
1个文件已删除
6个文件已添加
377 ■■■■ 已修改文件
springcloud_k8s_panzhihuazhihuishequ/common/pom.xml 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/config_server/src/main/resources/application.yml 38 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/pom.xml 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/ServiceSangeshenbianApplication.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/annotation/DistributedLock.java 34 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/aspectj/DistributedLockAspect.java 138 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/config/RedissonConfig.java 57 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/controller/TestController.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/enums/AuditStatusEnum.java 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/enums/ProcessStatusEnum.java 34 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/vo/WorkOrderVO.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/common/pom.xml
@@ -26,6 +26,7 @@
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.24</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
springcloud_k8s_panzhihuazhihuishequ/config_server/src/main/resources/application.yml
@@ -11,31 +11,31 @@
    serviceUrl:
      defaultZone: http://${EUREKA_URL:localhost}:8192/eureka
spring:
  application:
    name: huacheng-config
  cloud:
    config:
      server:
        git:
          uri: http://gitlab.nhys.cdnhxx.com:9380/huanghongfa/config-repo.git
#          search-paths: adminConfig
          username: huanghongfa
          password: huanghongfa123456
          default-label: huacheng
#          basedir: F:\nahan\config-repo\config-repo
#spring:
#  application:
#    name: huacheng-config
#  profiles:
#    active: native
#
#  cloud:
#    config:
#      server:
#        native:
#          search-locations: file:E:\\work\\config\\config-repo
#        git:
#          uri: http://gitlab.nhys.cdnhxx.com:9380/huanghongfa/config-repo.git
##          search-paths: adminConfig
#          username: huanghongfa
#          password: huanghongfa123456
#          default-label: huacheng
##          basedir: F:\nahan\config-repo\config-repo
spring:
  application:
    name: huacheng-config
  profiles:
    active: native
  cloud:
    config:
      server:
        native:
          search-locations: file:F:\lfl\config-repo-huacheng
management:
  endpoints:
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/pom.xml
@@ -63,6 +63,13 @@
        </dependency>
        <dependency>
            <groupId>org.redisson</groupId>
            <artifactId>redisson</artifactId>
            <version>3.10.1</version>
        </dependency>
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
        </dependency>
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/ServiceSangeshenbianApplication.java
@@ -1,5 +1,6 @@
package com.panzhihua.sangeshenbian;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
@@ -7,16 +8,19 @@
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
 * Hello world!
 *
 */
@SpringCloudApplication
@EnableSwagger2
@EnableFeignClients(basePackages = {"com.panzhihua.common.service"})
@EnableEurekaClient
@EnableCircuitBreaker
@ComponentScan({"com.panzhihua.sangeshenbian", "com.panzhihua.common"})
@MapperScan("com.panzhihua.sangeshenbian.dao")
@EnableScheduling
public class ServiceSangeshenbianApplication
{
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/annotation/DistributedLock.java
New file
@@ -0,0 +1,34 @@
package com.panzhihua.sangeshenbian.annotation;
import java.lang.annotation.*;
/**
 * @Descreption: 分布式锁注解
 * @Author: lfl
 */
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface DistributedLock {
    /**
     * 锁名字(没有EL解析)
     */
    String lockName() default "";
    /**
     * 锁前缀(有EL解析)
     */
    String lockNamePre() default "";
    /**
     * 锁后缀(有EL解析)
     */
    String lockNamePost() default "";
    /**
     * 锁前后缀拼接分隔符
     */
    String separator() default "_";
}
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/aspectj/DistributedLockAspect.java
New file
@@ -0,0 +1,138 @@
package com.panzhihua.sangeshenbian.aspectj;
import com.panzhihua.sangeshenbian.annotation.DistributedLock;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.lang.reflect.Method;
import java.util.Objects;
/**
 * @Desecription: 分布式锁切面
 * 注意!!!分布式锁不能加在事务方法当中:因为当锁释放,事务还没有提交
 */
@Aspect
@Component
@Slf4j
public class DistributedLockAspect {
    @Resource
    private RedissonClient redissonClient;
    /**
     * @Descreption: 定义切面:以注解为切面
     */
    @Pointcut("@annotation(com.panzhihua.sangeshenbian.annotation.DistributedLock)")
    public void distributedLockAspect() {
    }
    @Around(value = "distributedLockAspect()")
    public Object doAround(ProceedingJoinPoint pjp) throws Throwable {
        //切点所在的类
        MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
        Method method = methodSignature.getMethod();
        //
        DistributedLock annotation = method.getAnnotation(DistributedLock.class);
        String lockName = getLockName(annotation, pjp.getArgs(), method);
        //log.info("lockName:"+lockName);
        RLock lock = redissonClient.getLock(lockName);
        lock.lock();
        try {
            return pjp.proceed();
        } finally {
            if (lock.isLocked() && lock.isHeldByCurrentThread()) {
                //释放锁
                lock.unlock();
            }
        }
    }
    /**
     * @Descreption: 获取锁名字,优先获取注解中锁名
     */
    private String getLockName(DistributedLock distributedLock, Object[] args, Method method) {
        //优先获取注解名称
        if (StringUtils.isNotBlank(distributedLock.lockName())) {
            return distributedLock.lockName();
        }
        //根据参数匹配有参数就使用动态参数,没有就使用定义参数
        String lockNamePre = distributedLock.lockNamePre();
        String lockNamePost = distributedLock.lockNamePost();
        String separator = distributedLock.separator();
        String preExpression = parseExpression(lockNamePre, method, args);
        String postExpression = parseExpression(lockNamePost, method, args);
        StringBuilder sb = new StringBuilder();
        if (StringUtils.isNotBlank(preExpression)) {
            sb.append(preExpression);
        } else {
            sb.append(lockNamePre);
        }
        sb.append(separator);
        if (StringUtils.isNotBlank(postExpression)) {
            sb.append(postExpression);
        } else {
            sb.append(lockNamePost);
        }
        return sb.toString();
    }
    /**
     * el表达式解析
     *
     * @param expressionString 解析值
     * @param method           方法
     * @param args             参数
     * @return
     */
    private String parseExpression(String expressionString, Method method, Object[] args) {
        //获取被拦截方法参数名列表
        LocalVariableTableParameterNameDiscoverer discoverer = new LocalVariableTableParameterNameDiscoverer();
        String[] paramNameArr = discoverer.getParameterNames(method);
        //SPEL解析
        ExpressionParser parser = new SpelExpressionParser();
        StandardEvaluationContext context = new StandardEvaluationContext();
        for (int i = 0; i < Objects.requireNonNull(paramNameArr).length; i++) {
            context.setVariable(paramNameArr[i], args[i]);
        }
        return parser.parseExpression(expressionString).getValue(context, String.class);
    }
//    ==========================示例=============================
    //    //固定静态参数锁:product_lock
//    @DistributedLock(lockName = "product_lock")
//    @GetMapping(value = "/test1")
//    public void test1() {
//        System.out.println("执行事务");
//    }
//
//    //未匹配到参数,因此仍然是静态参数锁:#param1_#param2
//    @DistributedLock(lockNamePre = "#param1", lockNamePost = "#param2")
//    @GetMapping(value = "/test2")
//    public void test2() {
//        System.out.println("执行事务");
//    }
//
    //匹配到参数,动态参数锁:hello_world
//    @DistributedLock(lockNamePre = "#order", lockNamePost = "#param2")
//    @GetMapping(value = "/test3")
    public void test3(String param1, String param2) {
        System.out.println("执行事务");
    }
}
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/config/RedissonConfig.java
New file
@@ -0,0 +1,57 @@
package com.panzhihua.sangeshenbian.config;
import org.apache.commons.lang3.StringUtils;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.redisson.config.SingleServerConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
 * @Desecription:
 */
@Configuration
public class RedissonConfig {
    @Value("${spring.redis.host}")
    private String host;
    @Value("${spring.redis.port}")
    private String port;
    @Value("${spring.redis.database}")
    private int database;
    @Value("${spring.redis.timeout}")
    private String timeout;
    @Value("${spring.redis.password}")
    private String password;
    /**
     * @Descreption: RedissonClient, 单机模式
     */
    @Bean(destroyMethod = "shutdown")
    public RedissonClient redisson() {
        Config config = new Config();
        SingleServerConfig singleServerConfig = config.useSingleServer();
        singleServerConfig.setAddress("redis://" + host + ":" + port);
        singleServerConfig.setTimeout(10000);
        singleServerConfig.setDatabase(database);
        singleServerConfig.setRetryInterval(1000);
        singleServerConfig.setPingConnectionInterval(1000);
        if (StringUtils.isNotBlank(password)) {
            singleServerConfig.setPassword(password);
        }
        return Redisson.create(config);
    }
//    @Bean
//    public RedissonLocker redissonLocker(RedissonClient redissonClient) {
//        RedissonLocker locker = new RedissonLocker(redissonClient);
//        redissonClient.getlo
//        //设置LockUtil的锁处理对象
//        LockUtils.setLocker(locker);
//        return locker;
//    }
}
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/controller/TestController.java
File was deleted
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/enums/AuditStatusEnum.java
New file
@@ -0,0 +1,36 @@
package com.panzhihua.sangeshenbian.enums;
import lombok.Data;
// 审核状态枚举类
public enum AuditStatusEnum {
    PENDING(0, "待审核"),
    APPROVED(1, "审核通过"),
    REJECTED(2, "审核驳回");
    private final int code;
    private final String description;
    AuditStatusEnum(int code, String description) {
        this.code = code;
        this.description = description;
    }
    public int getCode() {
        return code;
    }
    public String getDescription() {
        return description;
    }
    public static String getDescriptionByCode(int code) {
        for (AuditStatusEnum status : AuditStatusEnum.values()) {
            if (status.getCode() == code) {
                return status.getDescription();
            }
        }
        return null;
    }
}
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/enums/ProcessStatusEnum.java
New file
@@ -0,0 +1,34 @@
package com.panzhihua.sangeshenbian.enums;
// 流转状态枚举类(更名为 ProcessStatusEnum)
public enum ProcessStatusEnum {
    PROCESSING(0, "正在办理"),
    EXTENDED(1, "延期办理"),
    OVERDUE(2, "超时办理"),
    COMPLETED(3, "已办结");
    private final int code;
    private final String description;
    ProcessStatusEnum(int code, String description) {
        this.code = code;
        this.description = description;
    }
    public int getCode() {
        return code;
    }
    public String getDescription() {
        return description;
    }
    public static String getDescriptionByCode(int code) {
        for (ProcessStatusEnum status : ProcessStatusEnum.values()) {
            if (status.getCode() == code) {
                return status.getDescription();
            }
        }
        return null;
    }
}
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/vo/WorkOrderVO.java
New file
@@ -0,0 +1,8 @@
package com.panzhihua.sangeshenbian.vo;
import lombok.Data;
@Data
public class WorkOrderVO {
    private Long id;
}