refactor: 使用常量替换硬编码方法名并优化参数构建
- 在ServiceConstant中添加常用方法名常量 - 使用ParamUtils重构多处参数构建逻辑 - 统一QueryService中的方法名调用为常量 - 修复CompanyOldNameService中的字段别名问题
This commit is contained in:
@@ -2,7 +2,9 @@ package com.ecep.contract.controller.employee;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.ecep.contract.util.ParamUtils;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
import com.ecep.contract.controller.tab.TabSkin;
|
||||
@@ -48,7 +50,7 @@ public class EmployeeTabSkinRole
|
||||
|
||||
private void initializeListView() {
|
||||
// 非系统内置账户
|
||||
HashMap<String, Object> params = new HashMap<>();
|
||||
Map<String, Object> params = ParamUtils.builder().build();
|
||||
List<EmployeeRoleVo> roles = getEmployeeRoleService().findAll(params, Pageable.ofSize(500)).getContent();
|
||||
|
||||
controller.rolesField.getSourceItems().setAll(roles);
|
||||
|
||||
@@ -53,8 +53,7 @@ public class CompanyCustomerFileTypeService
|
||||
|
||||
@Cacheable
|
||||
public Map<CustomerFileType, CustomerFileTypeLocalVo> findAll(Locale locale) {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("lang", locale.toLanguageTag());
|
||||
Map<String, Object> params = ParamUtils.builder().equals("lang", locale.toLanguageTag()).build();
|
||||
return findAll(params, Pageable.unpaged()).stream()
|
||||
.collect(Collectors.toMap(CustomerFileTypeLocalVo::getType, Function.identity()));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.ecep.contract.service;
|
||||
|
||||
import com.ecep.contract.util.ParamUtils;
|
||||
import com.ecep.contract.vm.CompanyInvoiceInfoViewModel;
|
||||
import com.ecep.contract.vo.CompanyInvoiceInfoVo;
|
||||
import com.ecep.contract.vo.CompanyVo;
|
||||
@@ -15,9 +16,8 @@ import java.util.Map;
|
||||
public class CompanyInvoiceInfoService extends QueryService<CompanyInvoiceInfoVo, CompanyInvoiceInfoViewModel> {
|
||||
|
||||
public List<CompanyInvoiceInfoVo> searchByCompany(CompanyVo company, String searchText) {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("company", company);
|
||||
params.put("searchText", searchText);
|
||||
Map<String, Object> params = ParamUtils.builder().equals("company", company.getId())
|
||||
.search(searchText).build();
|
||||
return findAll(params, Pageable.unpaged()).getContent();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.ecep.contract.SpringApp;
|
||||
import com.ecep.contract.util.ParamUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
@@ -58,8 +59,7 @@ public class CompanyService extends QueryService<CompanyVo, CompanyViewModel> {
|
||||
}
|
||||
|
||||
public List<CompanyVo> findAllByName(String name) {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("name", name);
|
||||
Map<String, Object> params = ParamUtils.builder().equals("name", name).build();
|
||||
return findAll(params, Pageable.unpaged()).getContent();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.ecep.contract.service;
|
||||
import com.ecep.contract.PageArgument;
|
||||
import com.ecep.contract.PageContent;
|
||||
import com.ecep.contract.WebSocketClientService;
|
||||
import com.ecep.contract.constant.ServiceConstant;
|
||||
import com.ecep.contract.model.IdentityEntity;
|
||||
import com.ecep.contract.model.NamedEntity;
|
||||
import com.ecep.contract.util.ParamUtils;
|
||||
@@ -67,7 +68,7 @@ public class QueryService<T extends IdentityEntity, TV extends IdentityViewModel
|
||||
@Override
|
||||
public T save(T entity) {
|
||||
try {
|
||||
return async("save", entity, entity.getClass().getName()).handle((response, ex) -> {
|
||||
return async(ServiceConstant.SAVE_METHOD_NAME, entity, entity.getClass().getName()).handle((response, ex) -> {
|
||||
if (ex != null) {
|
||||
throw new RuntimeException("保存实体失败", ex);
|
||||
}
|
||||
@@ -88,7 +89,7 @@ public class QueryService<T extends IdentityEntity, TV extends IdentityViewModel
|
||||
@Override
|
||||
public void delete(T entity) {
|
||||
try {
|
||||
async("delete", entity, entity.getClass().getName()).handle((response, ex) -> {
|
||||
async(ServiceConstant.DELETE_METHOD_NAME, entity, entity.getClass().getName()).handle((response, ex) -> {
|
||||
if (ex != null) {
|
||||
throw new RuntimeException("删除实体失败", ex);
|
||||
}
|
||||
@@ -117,7 +118,7 @@ public class QueryService<T extends IdentityEntity, TV extends IdentityViewModel
|
||||
}
|
||||
|
||||
public CompletableFuture<T> asyncFindById(Integer id) {
|
||||
return async("findById", id, Integer.class).handle((response, ex) -> {
|
||||
return async(ServiceConstant.FIND_BY_ID_METHOD_NAME, id, Integer.class).handle((response, ex) -> {
|
||||
if (ex != null) {
|
||||
throw new RuntimeException("查询实体失败", ex);
|
||||
}
|
||||
@@ -149,7 +150,7 @@ public class QueryService<T extends IdentityEntity, TV extends IdentityViewModel
|
||||
*/
|
||||
public CompletableFuture<Page<T>> asyncFindAll(Map<String, Object> params, Pageable pageable) {
|
||||
// 调用async方法发送WebSocket请求,获取异步响应结果
|
||||
return async("findAll", params, PageArgument.of(pageable)).handle((response, ex) -> {
|
||||
return async(ServiceConstant.FIND_ALL_METHOD_NAME, params, PageArgument.of(pageable)).handle((response, ex) -> {
|
||||
if (ex != null) {
|
||||
throw new RuntimeException("远程方法+findAll+调用失败", ex);
|
||||
}
|
||||
@@ -202,7 +203,7 @@ public class QueryService<T extends IdentityEntity, TV extends IdentityViewModel
|
||||
public CompletableFuture<Long> asyncCount(Map<String, Object> params) {
|
||||
// 调用async方法执行名为"count"的异步操作,传入参数params
|
||||
// 使用handle方法处理异步操作的结果或异常
|
||||
return async("count", params).handle((response, ex) -> {
|
||||
return async(ServiceConstant.COUNT_METHOD_NAME, params).handle((response, ex) -> {
|
||||
if (ex != null) {
|
||||
throw new RuntimeException("远程方法+count+调用失败", ex);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
package com.ecep.contract.constant;
|
||||
|
||||
public class ServiceConstant {
|
||||
public static final String COUNT_METHOD_NAME = "count";
|
||||
public static final String FIND_ALL_METHOD_NAME = "findAll";
|
||||
public static final String FIND_BY_ID_METHOD_NAME = "findById";
|
||||
public static final String DELETE_METHOD_NAME = "delete";
|
||||
public static final String SAVE_METHOD_NAME = "save";
|
||||
}
|
||||
|
||||
@@ -210,7 +210,7 @@ public class CompanyOldNameService extends EntityService<CompanyOldName, Company
|
||||
@Override
|
||||
protected String aliasFor(String field, JsonNode filterNode) {
|
||||
if ("company".equals(field)) {
|
||||
return "company.id";
|
||||
return "companyId";
|
||||
}
|
||||
return super.aliasFor(field, filterNode);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user