- 更新了多个类中的导入语句,替换了模型类为对应的VO类 - 优化了部分方法的参数和返回类型,使用VO类替代模型类 - 重构了自动补全功能,使用统一的泛型方法 - 添加了缓存注解,提高了数据访问性能 - 优化了部分代码结构,提高了可维护性
64 lines
1.8 KiB
Java
64 lines
1.8 KiB
Java
package com.ecep.contract.service;
|
|
|
|
import org.springframework.cache.annotation.CacheConfig;
|
|
import org.springframework.cache.annotation.CacheEvict;
|
|
import org.springframework.cache.annotation.Cacheable;
|
|
import org.springframework.cache.annotation.Caching;
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Pageable;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import com.ecep.contract.util.ParamUtils;
|
|
import com.ecep.contract.vm.BankViewModel;
|
|
import com.ecep.contract.vo.BankVo;
|
|
|
|
import javafx.util.StringConverter;
|
|
|
|
@Service
|
|
@CacheConfig(cacheNames = "bank")
|
|
public class BankService extends QueryService<BankVo, BankViewModel> {
|
|
@Cacheable(key = "#p0")
|
|
@Override
|
|
public BankVo findById(Integer id) {
|
|
return super.findById(id);
|
|
}
|
|
|
|
public BankVo findByName(String name) {
|
|
Page<BankVo> page = findAll(ParamUtils.equal(name, name), Pageable.ofSize(1));
|
|
if (page.isEmpty()) {
|
|
return null;
|
|
}
|
|
return page.getContent().getFirst();
|
|
}
|
|
|
|
@Caching(evict = { @CacheEvict(key = "#p0.id") })
|
|
@Override
|
|
public BankVo save(BankVo entity) {
|
|
return super.save(entity);
|
|
}
|
|
|
|
@Caching(evict = { @CacheEvict(key = "#p0.id") })
|
|
@Override
|
|
public void delete(BankVo entity) {
|
|
super.delete(entity);
|
|
}
|
|
|
|
private StringConverter<BankVo> stringConverter = new StringConverter<BankVo>() {
|
|
@Override
|
|
public String toString(BankVo object) {
|
|
return object == null ? "" : object.getName();
|
|
}
|
|
|
|
@Override
|
|
public BankVo fromString(String string) {
|
|
return findByName(string);
|
|
}
|
|
};
|
|
|
|
@Override
|
|
public StringConverter<BankVo> getStringConverter() {
|
|
return stringConverter;
|
|
}
|
|
|
|
}
|