代码结构如下
代码如下
@Getter
@AllArgsConstructor
public enum AuditPlutusEnum {
BACK ( "回款" ) ,
REFUND ( "退款" ) ,
INVOICE ( "开票" ) ;
private final String name;
}
@Retention ( RetentionPolicy . RUNTIME)
@Target ( ElementType . TYPE)
@Component
public @interface AuditStrategyType {
@AliasFor ( annotation = Component . class )
String value ( ) default "" ;
AuditPlutusEnum type ( ) ;
}
* /
@Configuration
public class AuditStrategyConfig {
@Bean
public AuditStrategyRunner auditStrategyRunner ( List < AuditPlutusStrategy > strategies) {
Map < AuditPlutusEnum , AuditPlutusStrategy > strategyMap = strategies. stream ( )
. collect ( Collectors . toMap (
s -> s. getClass ( ) . getAnnotation ( AuditStrategyType . class ) . type ( ) ,
s -> s
) ) ;
return ( flag, auditPlutusRo) -> strategyMap. get ( flag) . audit ( auditPlutusRo) ;
}
}
public interface AuditStrategyRunner {
void audit ( AuditPlutusEnum type, AuditPlutusRo auditPlutusRo) ;
}
public interface AuditPlutusStrategy {
void audit ( AuditPlutusRo ro) ;
}
@AuditStrategyType ( type = AuditPlutusEnum . REFUND)
public class AuditRefundStrategy implements AuditPlutusStrategy {
@Override
public void audit ( AuditPlutusRo ro) {
}
} ```
```java
@AuditStrategyType ( type = AuditPlutusEnum . INVOICE)
public class AuditInvoiceStrategy implements AuditPlutusStrategy {
@Override
public void audit ( AuditPlutusRo ro) {
}
}
@AuditStrategyType ( type = AuditPlutusEnum . BACK)
public class AuditBackStrategy implements AuditPlutusStrategy {
@Override
public void audit ( AuditPlutusRo ro) {
}
}
调用
@Autowired
private AuditStrategyRunner auditStrategyRunner;
public ResultData < ? > auditBack ( AuditPlutusRo ro) {
log. info ( "【{}】审核-业财回调处理,审核编号为:{},传入参数为:{}" , ro. getAuditPlutusEnum ( ) . getName ( ) , ro. getAuditNo ( ) , JSON. toJSONString ( ro) ) ;
auditStrategyRunner. audit ( ro. getAuditPlutusEnum ( ) , ro) ;
return ResultData . SUCCESS;
}