public interface IImportExportStrategy {
/**
* 验证参数
*
* @param extendJson
*/
void validation(String );
/**
* 处理业务功能
*
* @param exportLog
* @return 返回对应的参数回来
*/
BeImportExportVO handlingBusiness(ExportLog exportLog);
}
@Slf4j
@Service
@RequiredArgsConstructor
public class TestImportStrategy implements IImportExportStrategy {
private final IComTestExportService comTestExportService;
@Override
public void validation(String extendJson, BusUserDTO busUserDTO) {
}
@Override
public BeImportExportVO handlingBusiness(ExportLog exportLog) throws IOException {
return comTestExportService.memberGradeImport(exportLog);
}
}
/**
* 导入导出策略
*
*/
@Component
@RequiredArgsConstructor
public class ImportExportContext {
@Autowired
private final Map<Integer, IImportExportStrategy> importExportStrategyMap;
public void validation(Integer businessType, String extendJson, BusUserDTO busUserDTO) {
IImportExportStrategy importExportStrategy = importExportStrategyMap.get(businessType);
importExportStrategy.validation(extendJson,busUserDTO);
}
public BeImportExportVO handlingBusiness(Integer businessType, ExportLog exportLog) throws IOException {
IImportExportStrategy importExportStrategy = importExportStrategyMap.get(businessType);
return importExportStrategy.handlingBusiness(exportLog);
}
}
/**
* 管理导入导出策略
*/
@Configuration
public class ImportExportStrategyConfig {
@Resource
private TestImportStrategy testImportStrategy;
@Bean
public Map<Integer, IImportExportStrategy> importExportStrategyMap() {
Map<Integer, IImportExportStrategy> beanMap = new ConcurrentHashMap<>(16);
beanMap.put(ImportExportConstants.GRADE_IMPORT, testImportStrategy);
return beanMap;
}
}