refactor(client): 重构银行和公司相关代码
- 更新了多个类中的导入语句,替换了模型类为对应的VO类 - 优化了部分方法的参数和返回类型,使用VO类替代模型类 - 重构了自动补全功能,使用统一的泛型方法 - 添加了缓存注解,提高了数据访问性能 - 优化了部分代码结构,提高了可维护性
This commit is contained in:
@@ -1,16 +1,63 @@
|
||||
package com.ecep.contract.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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.model.Bank;
|
||||
import com.ecep.contract.util.ParamUtils;
|
||||
import com.ecep.contract.vm.BankViewModel;
|
||||
import com.ecep.contract.vo.BankVo;
|
||||
|
||||
import javafx.util.StringConverter;
|
||||
|
||||
@Service
|
||||
public class BankService extends QueryService<Bank, BankViewModel> {
|
||||
public Bank findByName(String name) {
|
||||
return null;
|
||||
@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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user