feat:完成剩余修补尾巴

This commit is contained in:
wangyu 2021-12-08 08:46:11 +08:00
parent 1c51ec78ab
commit 6fc717a186
4 changed files with 38 additions and 4 deletions

View File

@ -25,5 +25,5 @@ public @interface EnableReactiveMongoRepo {
* @return 结果
*/
@AliasFor(annotation = EnableReactiveMongoRepositories.class)
String[] basePackages() default "com.flyfish.framework";
String[] basePackages() default "com.flyfish";
}

View File

@ -15,12 +15,12 @@ public class DefaultReactiveRepositoryFactory extends ReactiveMongoRepositoryFac
*/
public DefaultReactiveRepositoryFactory(ReactiveMongoOperations mongoOperations) {
super(mongoOperations);
this.setRepositoryBaseClass(DefaultReactiveRepositoryImpl.class);
this.setRepositoryBaseClass(DefaultReactiveRepositoryFactory.class);
}
@Override
@NonNull
protected Class<?> getRepositoryBaseClass(@NonNull RepositoryMetadata metadata) {
return DefaultReactiveRepositoryImpl.class;
return DefaultReactiveRepositoryFactory.class;
}
}

View File

@ -4,10 +4,14 @@ package com.flyfish.framework.dict.service;
import com.flyfish.framework.dict.domain.Dictionary;
import com.flyfish.framework.dict.repository.DictionaryRepository;
import com.flyfish.framework.service.impl.BaseReactiveServiceImpl;
import com.flyfish.framework.service.impl.BaseReactiveServiceImpl;
import com.flyfish.framework.utils.RedisOperations;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;
import javax.annotation.Resource;
import java.util.Optional;
/**
@ -18,6 +22,13 @@ import java.util.Optional;
@Service
public class DictionaryService extends BaseReactiveServiceImpl<Dictionary> {
private final String DICT_KEY = "dict-";
@Resource
private MongoOperations mongoOperations;
@Resource
private RedisOperations redisOperations;
/**
* 通过code查询
*
@ -27,4 +38,26 @@ public class DictionaryService extends BaseReactiveServiceImpl<Dictionary> {
DictionaryRepository repository = this.getRepository();
return repository.findByCode(code);
}
/**
* 通过code同步查询
*
* @param code 编码
* @return 结果
*/
public Optional<Dictionary> get(String code) {
String cacheKey = DICT_KEY + code;
if (redisOperations.hasKey(cacheKey)) {
return Optional.of(redisOperations.get(cacheKey)).map(obj -> (Dictionary) obj);
} else {
Dictionary dictionary = mongoOperations.findOne(Query.query(Criteria.where("code").is(code)).limit(1),
Dictionary.class);
if (null != dictionary) {
redisOperations.set(cacheKey, dictionary);
return Optional.of(dictionary);
} else {
return Optional.empty();
}
}
}
}

View File

@ -12,6 +12,7 @@ import com.flyfish.framework.bean.Result;
import com.flyfish.framework.configuration.annotations.PagedQuery;
import com.flyfish.framework.domain.base.Vo;
import com.flyfish.framework.service.BaseReactiveService;
import reactor.core.publisher.Mono;
@RestController
@RequestMapping("#{uri}")