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.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.ecep.contract.util.ParamUtils;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
|
|
||||||
import com.ecep.contract.controller.tab.TabSkin;
|
import com.ecep.contract.controller.tab.TabSkin;
|
||||||
@@ -48,7 +50,7 @@ public class EmployeeTabSkinRole
|
|||||||
|
|
||||||
private void initializeListView() {
|
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();
|
List<EmployeeRoleVo> roles = getEmployeeRoleService().findAll(params, Pageable.ofSize(500)).getContent();
|
||||||
|
|
||||||
controller.rolesField.getSourceItems().setAll(roles);
|
controller.rolesField.getSourceItems().setAll(roles);
|
||||||
|
|||||||
@@ -39,13 +39,13 @@ public class CompanyCustomerFileTypeService
|
|||||||
return super.findAll();
|
return super.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Caching(put = { @CachePut(key = "#p0.id"), @CachePut(key = "'all'") })
|
@Caching(put = {@CachePut(key = "#p0.id"), @CachePut(key = "'all'")})
|
||||||
@Override
|
@Override
|
||||||
public CustomerFileTypeLocalVo save(CustomerFileTypeLocalVo entity) {
|
public CustomerFileTypeLocalVo save(CustomerFileTypeLocalVo entity) {
|
||||||
return super.save(entity);
|
return super.save(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Caching(put = { @CachePut(key = "#p0.id"), @CachePut(key = "'all'") })
|
@Caching(put = {@CachePut(key = "#p0.id"), @CachePut(key = "'all'")})
|
||||||
@Override
|
@Override
|
||||||
public void delete(CustomerFileTypeLocalVo entity) {
|
public void delete(CustomerFileTypeLocalVo entity) {
|
||||||
super.delete(entity);
|
super.delete(entity);
|
||||||
@@ -53,8 +53,7 @@ public class CompanyCustomerFileTypeService
|
|||||||
|
|
||||||
@Cacheable
|
@Cacheable
|
||||||
public Map<CustomerFileType, CustomerFileTypeLocalVo> findAll(Locale locale) {
|
public Map<CustomerFileType, CustomerFileTypeLocalVo> findAll(Locale locale) {
|
||||||
Map<String, Object> params = new HashMap<>();
|
Map<String, Object> params = ParamUtils.builder().equals("lang", locale.toLanguageTag()).build();
|
||||||
params.put("lang", locale.toLanguageTag());
|
|
||||||
return findAll(params, Pageable.unpaged()).stream()
|
return findAll(params, Pageable.unpaged()).stream()
|
||||||
.collect(Collectors.toMap(CustomerFileTypeLocalVo::getType, Function.identity()));
|
.collect(Collectors.toMap(CustomerFileTypeLocalVo::getType, Function.identity()));
|
||||||
}
|
}
|
||||||
@@ -66,7 +65,7 @@ public class CompanyCustomerFileTypeService
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据语言标签和参数查找单个 CustomerFileTypeLocalVo 对象
|
* 根据语言标签和参数查找单个 CustomerFileTypeLocalVo 对象
|
||||||
*
|
*
|
||||||
* @param locale 语言区域
|
* @param locale 语言区域
|
||||||
* @param key 参数键
|
* @param key 参数键
|
||||||
* @param value 参数值
|
* @param value 参数值
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.ecep.contract.service;
|
package com.ecep.contract.service;
|
||||||
|
|
||||||
|
import com.ecep.contract.util.ParamUtils;
|
||||||
import com.ecep.contract.vm.CompanyInvoiceInfoViewModel;
|
import com.ecep.contract.vm.CompanyInvoiceInfoViewModel;
|
||||||
import com.ecep.contract.vo.CompanyInvoiceInfoVo;
|
import com.ecep.contract.vo.CompanyInvoiceInfoVo;
|
||||||
import com.ecep.contract.vo.CompanyVo;
|
import com.ecep.contract.vo.CompanyVo;
|
||||||
@@ -15,9 +16,8 @@ import java.util.Map;
|
|||||||
public class CompanyInvoiceInfoService extends QueryService<CompanyInvoiceInfoVo, CompanyInvoiceInfoViewModel> {
|
public class CompanyInvoiceInfoService extends QueryService<CompanyInvoiceInfoVo, CompanyInvoiceInfoViewModel> {
|
||||||
|
|
||||||
public List<CompanyInvoiceInfoVo> searchByCompany(CompanyVo company, String searchText) {
|
public List<CompanyInvoiceInfoVo> searchByCompany(CompanyVo company, String searchText) {
|
||||||
Map<String, Object> params = new HashMap<>();
|
Map<String, Object> params = ParamUtils.builder().equals("company", company.getId())
|
||||||
params.put("company", company);
|
.search(searchText).build();
|
||||||
params.put("searchText", searchText);
|
|
||||||
return findAll(params, Pageable.unpaged()).getContent();
|
return findAll(params, Pageable.unpaged()).getContent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.ecep.contract.SpringApp;
|
import com.ecep.contract.SpringApp;
|
||||||
|
import com.ecep.contract.util.ParamUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.cache.annotation.CacheConfig;
|
import org.springframework.cache.annotation.CacheConfig;
|
||||||
import org.springframework.cache.annotation.Cacheable;
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
@@ -58,8 +59,7 @@ public class CompanyService extends QueryService<CompanyVo, CompanyViewModel> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<CompanyVo> findAllByName(String name) {
|
public List<CompanyVo> findAllByName(String name) {
|
||||||
Map<String, Object> params = new HashMap<>();
|
Map<String, Object> params = ParamUtils.builder().equals("name", name).build();
|
||||||
params.put("name", name);
|
|
||||||
return findAll(params, Pageable.unpaged()).getContent();
|
return findAll(params, Pageable.unpaged()).getContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.ecep.contract.service;
|
|||||||
import com.ecep.contract.PageArgument;
|
import com.ecep.contract.PageArgument;
|
||||||
import com.ecep.contract.PageContent;
|
import com.ecep.contract.PageContent;
|
||||||
import com.ecep.contract.WebSocketClientService;
|
import com.ecep.contract.WebSocketClientService;
|
||||||
|
import com.ecep.contract.constant.ServiceConstant;
|
||||||
import com.ecep.contract.model.IdentityEntity;
|
import com.ecep.contract.model.IdentityEntity;
|
||||||
import com.ecep.contract.model.NamedEntity;
|
import com.ecep.contract.model.NamedEntity;
|
||||||
import com.ecep.contract.util.ParamUtils;
|
import com.ecep.contract.util.ParamUtils;
|
||||||
@@ -67,7 +68,7 @@ public class QueryService<T extends IdentityEntity, TV extends IdentityViewModel
|
|||||||
@Override
|
@Override
|
||||||
public T save(T entity) {
|
public T save(T entity) {
|
||||||
try {
|
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) {
|
if (ex != null) {
|
||||||
throw new RuntimeException("保存实体失败", ex);
|
throw new RuntimeException("保存实体失败", ex);
|
||||||
}
|
}
|
||||||
@@ -88,7 +89,7 @@ public class QueryService<T extends IdentityEntity, TV extends IdentityViewModel
|
|||||||
@Override
|
@Override
|
||||||
public void delete(T entity) {
|
public void delete(T entity) {
|
||||||
try {
|
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) {
|
if (ex != null) {
|
||||||
throw new RuntimeException("删除实体失败", ex);
|
throw new RuntimeException("删除实体失败", ex);
|
||||||
}
|
}
|
||||||
@@ -117,7 +118,7 @@ public class QueryService<T extends IdentityEntity, TV extends IdentityViewModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
public CompletableFuture<T> asyncFindById(Integer id) {
|
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) {
|
if (ex != null) {
|
||||||
throw new RuntimeException("查询实体失败", ex);
|
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) {
|
public CompletableFuture<Page<T>> asyncFindAll(Map<String, Object> params, Pageable pageable) {
|
||||||
// 调用async方法发送WebSocket请求,获取异步响应结果
|
// 调用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) {
|
if (ex != null) {
|
||||||
throw new RuntimeException("远程方法+findAll+调用失败", ex);
|
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) {
|
public CompletableFuture<Long> asyncCount(Map<String, Object> params) {
|
||||||
// 调用async方法执行名为"count"的异步操作,传入参数params
|
// 调用async方法执行名为"count"的异步操作,传入参数params
|
||||||
// 使用handle方法处理异步操作的结果或异常
|
// 使用handle方法处理异步操作的结果或异常
|
||||||
return async("count", params).handle((response, ex) -> {
|
return async(ServiceConstant.COUNT_METHOD_NAME, params).handle((response, ex) -> {
|
||||||
if (ex != null) {
|
if (ex != null) {
|
||||||
throw new RuntimeException("远程方法+count+调用失败", ex);
|
throw new RuntimeException("远程方法+count+调用失败", ex);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
package com.ecep.contract.constant;
|
package com.ecep.contract.constant;
|
||||||
|
|
||||||
public class ServiceConstant {
|
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
|
@Override
|
||||||
protected String aliasFor(String field, JsonNode filterNode) {
|
protected String aliasFor(String field, JsonNode filterNode) {
|
||||||
if ("company".equals(field)) {
|
if ("company".equals(field)) {
|
||||||
return "company.id";
|
return "companyId";
|
||||||
}
|
}
|
||||||
return super.aliasFor(field, filterNode);
|
return super.aliasFor(field, filterNode);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user