feat: 添加日志配置和Logback依赖
refactor: 重构实体类equals和hashCode方法 fix: 修复WebSocketService消息发送逻辑 style: 格式化代码和优化导入 docs: 更新JacksonConfig日期序列化格式 test: 添加CompanyFilePathTableCell测试类 chore: 清理无用代码和注释
This commit is contained in:
@@ -4,6 +4,7 @@ import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -12,10 +13,12 @@ import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
import com.ecep.contract.PageArgument;
|
||||
import com.ecep.contract.WebSocketService;
|
||||
import com.ecep.contract.model.IdentityEntity;
|
||||
import com.ecep.contract.msg.SimpleMessage;
|
||||
import com.ecep.contract.vm.IdentityViewModel;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
@@ -31,8 +34,6 @@ public class QueryService<T extends IdentityEntity, TV extends IdentityViewModel
|
||||
public TV createNewViewModel() {
|
||||
try {
|
||||
Type genericSuperclass = getClass().getGenericSuperclass();
|
||||
System.out.println("genericSuperclass = " + genericSuperclass.getClass());
|
||||
|
||||
String typeName = genericSuperclass.getTypeName();
|
||||
// System.out.println("typeName = " + typeName);
|
||||
String clz = typeName.split("<")[1].split(">")[0].split(",")[1].trim();
|
||||
@@ -92,31 +93,49 @@ public class QueryService<T extends IdentityEntity, TV extends IdentityViewModel
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T findById(Integer id) {
|
||||
public CompletableFuture<T> asyncFindById(Integer id) {
|
||||
SimpleMessage msg = new SimpleMessage();
|
||||
msg.setService(getBeanName());
|
||||
msg.setMethod("findById");
|
||||
msg.setArguments(id);
|
||||
try {
|
||||
JsonNode response = webSocketService.send(msg).get(readTimeout, TimeUnit.MILLISECONDS);
|
||||
if (response != null) {
|
||||
T newEntity = createNewEntity();
|
||||
objectMapper.updateValue(newEntity, response);
|
||||
return newEntity;
|
||||
return webSocketService.send(msg).orTimeout(readTimeout, TimeUnit.MILLISECONDS).handle((response, ex) -> {
|
||||
if (ex != null) {
|
||||
return null;
|
||||
}
|
||||
if (response == null) {
|
||||
|
||||
return null;
|
||||
}
|
||||
T newEntity = createNewEntity();
|
||||
try {
|
||||
objectMapper.updateValue(newEntity, response);
|
||||
} catch (JsonMappingException e) {
|
||||
throw new RuntimeException(response.toString(), e);
|
||||
}
|
||||
return newEntity;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public T findById(Integer id) {
|
||||
try {
|
||||
return asyncFindById(id).get();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<T> findAll() {
|
||||
return findAll(null, Pageable.unpaged()).getContent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<T> findAll(Map<String, Object> params, Pageable pageable) {
|
||||
SimpleMessage msg = new SimpleMessage();
|
||||
msg.setService(getBeanName());
|
||||
msg.setMethod("findAll");
|
||||
msg.setArguments(params, pageable);
|
||||
msg.setArguments(params, PageArgument.of(pageable));
|
||||
try {
|
||||
JsonNode response = webSocketService.send(msg).get(readTimeout, TimeUnit.MILLISECONDS);
|
||||
if (response != null) {
|
||||
@@ -147,7 +166,6 @@ public class QueryService<T extends IdentityEntity, TV extends IdentityViewModel
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public List<T> search(String searchText) {
|
||||
Map<String, Object> params = getSpecification(searchText);
|
||||
List<T> list = findAll(params, Pageable.ofSize(10)).getContent();
|
||||
|
||||
Reference in New Issue
Block a user