提交 3fdab763 编写于 作者: sq3536's avatar sq3536

异常接管,底层框架升级

上级 36744792
......@@ -160,6 +160,12 @@
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
......
......@@ -205,6 +205,8 @@ public class BaseData extends DataObj
public BaseData setKey(Object key)
{
if(ObjectUtils.isEmpty(key))
return this;
return this.set("_id",key);
}
......
......@@ -17,6 +17,7 @@ import com.mongodb.QueryBuilder;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
......@@ -385,11 +386,9 @@ public class FilterData<T> extends BaseData
public String getSql(String codename)
{
if(getPOSchema()==null)
throw new BadRequestAlertException("未找到存储配置","FilterData",codename);
Assert.notNull(getPOSchema(),"未找到查询片段");
POSchema.Segment segment=getPOSchema().getSegment(codename,"");
if(segment==null)
throw new BadRequestAlertException("未找到查询方法配置","FilterData",codename);
Assert.notNull(segment,"未找到查询片段"+codename);
String sql=segment.getBody();
QueryWrapper qw=this.getSearchCond();
......
package cn.ibizlab.core.data.elasticsearch;
import cn.ibizlab.core.data.model.DSLink;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient;
import org.springframework.data.elasticsearch.client.reactive.ReactiveRestClients;
import org.springframework.http.HttpHeaders;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;
public class DynamicEsContextHolder
{
public static final Map<String, ReactiveElasticsearchClient> ES_CLIENT_DB_FACTORY_MAP = new HashMap<>();
public static final ThreadLocal<ReactiveElasticsearchClient> ES_DB_FACTORY_THREAD_LOCAL =
new ThreadLocal<>();
public static ReactiveElasticsearchClient getReactiveElasticsearchClient() {
return ES_DB_FACTORY_THREAD_LOCAL.get();
}
public static void push(String name) {
ES_DB_FACTORY_THREAD_LOCAL.set(ES_CLIENT_DB_FACTORY_MAP.get(name));
}
public static void poll() {
ES_DB_FACTORY_THREAD_LOCAL.remove();
}
public static synchronized void addFactory(String ds, DSLink link)
{
addFactory(ds,link.getUrl());
}
public static synchronized void addFactory(String ds, String uri)
{
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add("some-header", "on every request");
HttpHeaders headers=new HttpHeaders();
headers.add("currentTime", LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
ClientConfiguration clientConfiguration = ClientConfiguration.builder()
.connectedTo("localhost:9200"/*, "localhost:9291"*/)
//.useSsl()
//.withProxy("localhost:8888")
//.withPathPrefix("ela")
.withConnectTimeout(Duration.ofSeconds(5))
.withSocketTimeout(Duration.ofSeconds(3))
//.withDefaultHeaders(defaultHeaders)
//.withBasicAuth(username, password)
.withDefaultHeaders(headers)
.build();
ES_CLIENT_DB_FACTORY_MAP.put(ds, ReactiveRestClients.create(clientConfiguration));
}
public static synchronized void removeFactory(String ds)
{
ES_CLIENT_DB_FACTORY_MAP.remove(ds);
}
}
package cn.ibizlab.core.data.elasticsearch;
import cn.ibizlab.core.data.mongodb.DynamicMongoContextHolder;
import com.mongodb.client.MongoDatabase;
import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient;
import org.springframework.data.elasticsearch.core.ReactiveElasticsearchTemplate;
@Slf4j
public class DynamicEsTemplate extends ReactiveElasticsearchTemplate {
public DynamicEsTemplate(ReactiveElasticsearchClient client) {
super(client);
}
@Override
protected ReactiveElasticsearchClient getClient() {
ReactiveElasticsearchClient client = DynamicEsContextHolder.getReactiveElasticsearchClient();
return client==null ? super.getClient() : client;
}
}
......@@ -142,7 +142,7 @@ public class DstSystemModel {
{
try {
if(!Files.exists(path))
throw new BadRequestAlertException("读取文件失败","DstSystem",path.toString());
throw new IllegalArgumentException("读取文件失败DstSystem:"+path.toString());
JSONObject jo=JSON.parseObject(new String(Files.readAllBytes(path), StandardCharsets.UTF_8));
this.setPssystemid(jo.getString("codeName"));
this.setPssystemname(jo.getString("logicName"));
......@@ -166,7 +166,7 @@ public class DstSystemModel {
}
this.setDynamicModelPath(path.getParent().toAbsolutePath().toString());
} catch (IOException e) {
throw new BadRequestAlertException("读取文件失败","DstSystem",path.toString());
throw new IllegalArgumentException("读取文件失败DstSystem:"+path.toString());
}
return this;
}
......
......@@ -23,6 +23,7 @@ import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
......@@ -81,16 +82,13 @@ public class DynamicModelService {
dynamicSystems=new HashMap<>();
IPSSystem iPSSystem = null;
if(StringUtils.isEmpty(strPSModelFolderPath))
throw new BadRequestAlertException("加载系统模型错误,未找到对应模型目录", "DynamicSystem", system);
Assert.hasLength(strPSModelFolderPath,"加载系统模型错误,未找到对应模型目录:"+system);
PSModelServiceImpl psModelService = new PSModelServiceImpl();
psModelService.setPSModelFolderPath(strPSModelFolderPath);
try {
iPSSystem = psModelService.getPSSystem();
if (iPSSystem == null)
throw new BadRequestAlertException("加载系统模型错误", "DynamicSystem", system);
Assert.notNull(iPSSystem,"加载系统模型错误:"+system);
dynamicSystems.put(system, iPSSystem);
if (!system.equals(iPSSystem.getCodeName()))
dynamicSystems.put(iPSSystem.getCodeName(), iPSSystem);
......@@ -98,7 +96,7 @@ public class DynamicModelService {
dynamicSystems.put(iPSSystem.getCodeName().toLowerCase(), iPSSystem);
} catch (Exception e) {
throw new BadRequestAlertException(String.format("加载系统模型错误:%s", e.getMessage()), "DynamicSystem", system);
throw new RuntimeException("加载系统模型错误"+system,e);
}
return iPSSystem;
}
......@@ -188,12 +186,10 @@ public class DynamicModelService {
public EntityModel getDynamicEntity(String system,String entity) throws Exception
{
MetaEntityModel metaEntityModel=getProxy().getEntities(system).get(entity);
if(metaEntityModel==null)
throw new BadRequestAlertException("未找到对应的实体模型","DynamicEntity",entity);
Assert.notNull(metaEntityModel,"未找到对应的实体模型:"+entity);
IPSSystem iPSSystem=getProxy().getDynamicSystem(system);
IPSDataEntity dataEntity = iPSSystem.getPSDataEntity(metaEntityModel.getEntityId(),true);
if(dataEntity==null)
throw new BadRequestAlertException("未找到对应的实体模型","DynamicEntity",entity);
Assert.notNull(dataEntity,"未找到对应的实体模型:"+entity);
EntityModel entityModel=new EntityModel();
if(dataEntity.isLogicValid())
......
......@@ -832,11 +832,11 @@ public class POSchema {
{
try {
if(!Files.exists(path))
throw new BadRequestAlertException("读取文件失败","POSchema",path.toString());
throw new IllegalArgumentException("读取文件失败POSchema:"+path.toString());
return JSON.parseObject(Files.readAllBytes(path),POSchema.class);
} catch (Exception e) {
throw new BadRequestAlertException("解析文件失败","POSchema",path.toString());
throw new RuntimeException("解析文件失败POSchema:"+path.toString());
}
}
......@@ -848,7 +848,7 @@ public class POSchema {
dir.mkdirs();
Files.write(path, JSON.toJSONBytes(poSchema));
} catch (Exception e) {
throw new BadRequestAlertException("保存文件失败","POSchema",path.toString());
throw new RuntimeException("保存文件失败POSchema:"+path.toString());
}
return poSchema;
}
......@@ -896,6 +896,8 @@ public class POSchema {
setKeyValue(data,key);
}
if(ObjectUtils.isEmpty(key))
return null;
return (Serializable)key;
}
......@@ -906,6 +908,8 @@ public class POSchema {
public BaseData setKeyValue(BaseData data,Object keyValue)
{
if(ObjectUtils.isEmpty(keyValue))
return null;
Map<String,String> keyMap= this.getKeyMap();
data.setKey(keyValue);
if(keyMap!=null)
......
......@@ -499,11 +499,11 @@ public class PojoSchema {
{
try {
if(!Files.exists(path))
throw new BadRequestAlertException("读取文件失败","PojoSchema",path.toString());
throw new IllegalArgumentException("读取文件失败PojoSchema:"+path.toString());
return JSON.parseObject(Files.readAllBytes(path),PojoSchema.class);
} catch (Exception e) {
throw new BadRequestAlertException("解析文件失败","PojoSchema",path.toString());
throw new RuntimeException("解析文件失败PojoSchema:"+path.toString());
}
}
......@@ -516,7 +516,7 @@ public class PojoSchema {
Files.write(path, JSON.toJSONBytes(pojoSchema));
} catch (Exception e) {
throw new BadRequestAlertException("保存文件失败","PojoSchema",path.toString());
throw new RuntimeException("保存文件失败PojoSchema:"+path.toString());
}
return pojoSchema;
}
......@@ -596,6 +596,8 @@ public class PojoSchema {
setKeyValue(data,key);
}
if(ObjectUtils.isEmpty(key))
return null;
return (Serializable)key;
}
......@@ -606,6 +608,8 @@ public class PojoSchema {
public BaseData setKeyValue(BaseData data,Object keyValue)
{
if(ObjectUtils.isEmpty(keyValue))
return null;
Map<String,PojoSchema> keyMap= this.getKeyMap();
data.setKey(keyValue);
if(keyMap!=null)
......
......@@ -12,6 +12,7 @@ import com.mongodb.BasicDBObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.castor.core.util.Assert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
......@@ -91,10 +92,8 @@ public class MongoDataRepository {
public Query getKeyQuery(BaseData data)
{
Query query = new Query();
if(!ObjectUtils.isEmpty(data.getKey()))
return query.addCriteria(new Criteria().and("_id").is(data.getKey()));
else
throw new BadRequestAlertException("未找到主键","mongo",null);
Assert.notNull(data.getKey(),"未找到主键");
return query.addCriteria(new Criteria().and("_id").is(data.getKey()));
}
public Query getKeyQuery(List list)
......@@ -108,9 +107,7 @@ public class MongoDataRepository {
list.forEach(item -> {
BaseData data = (BaseData) item;
Serializable key=data.getKey();
if(ObjectUtils.isEmpty(key))
throw new BadRequestAlertException("未找到主键","mongo",null);
Assert.notNull(key,"未找到主键");
ids.add(key.toString());
});
}
......@@ -265,8 +262,7 @@ public class MongoDataRepository {
BasicDBList values = new BasicDBList();
list.forEach(item->{
Serializable key=item.getKey();
if(ObjectUtils.isEmpty(key))
throw new BadRequestAlertException("未找到主键","mongo",null);
Assert.notNull(key,"未找到主键");
values.add(key);
});
BasicDBObject in = new BasicDBObject("$in", values);
......
......@@ -19,10 +19,12 @@ import org.springframework.data.domain.PageImpl;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.io.Serializable;
import java.util.*;
@Slf4j
......@@ -178,9 +180,13 @@ public class DataResource
@PathVariable(name = "parentKey2",required = false) String parentKey2,
@PathVariable(name = "entity",required = true) String entity,
@RequestParam(name = "datasource",required = false) String datasource,
@RequestBody List ids) {
List<BaseData> list = dataService.getBatch(system,scope,entity,datasource,ids);
return ResponseEntity.status(HttpStatus.OK).body(list);
@RequestBody List<Object> datas) {
if(ObjectUtils.isEmpty(datas))
return ResponseEntity.status(HttpStatus.OK).body(new ArrayList<>());
else if(datas.get(0) instanceof Map)
return ResponseEntity.status(HttpStatus.OK).body(dataService.getByMapBatch(system,scope,entity,datasource,(List)datas));
else
return ResponseEntity.status(HttpStatus.OK).body(dataService.getBatch(system,scope,entity,datasource,(List)datas));
}
@ApiOperation(value = "删除数据", tags = {"数据" }, notes = "删除数据")
......@@ -231,8 +237,8 @@ public class DataResource
@PathVariable(name = "parentKey2",required = false) String parentKey2,
@PathVariable(name = "entity",required = true) String entity,
@RequestParam(name = "datasource",required = false) String datasource,
@RequestBody List ids) {
return doRemoveBatch(system,scope,parentEntity,parentKey,parentEntity2,parentKey2,entity,datasource,ids);
@RequestBody List<Object> datas) {
return doRemoveBatch(system,scope,parentEntity,parentKey,parentEntity2,parentKey2,entity,datasource,datas);
}
@ApiOperation(value = "批量删除数据", tags = {"数据" }, notes = "批量删除数据")
......@@ -245,9 +251,13 @@ public class DataResource
@PathVariable(name = "parentKey2",required = false) String parentKey2,
@PathVariable(name = "entity",required = true) String entity,
@RequestParam(name = "datasource",required = false) String datasource,
@RequestBody List ids) {
dataService.removeBatch(system,scope,entity,datasource,ids);
return ResponseEntity.status(HttpStatus.OK).body(true);
@RequestBody List<Object> datas) {
if(ObjectUtils.isEmpty(datas))
return ResponseEntity.status(HttpStatus.OK).body(true);
else if(datas.get(0) instanceof Map)
return ResponseEntity.status(HttpStatus.OK).body(dataService.removeByMapBatch(system,scope,entity,datasource,(List)datas));
else
return ResponseEntity.status(HttpStatus.OK).body(dataService.removeBatch(system,scope,entity,datasource,(List)datas));
}
@ApiOperation(value = "更新数据", tags = {"数据" }, notes = "更新数据")
......
......@@ -77,13 +77,13 @@ public class PersistentResource
@RequestMapping(method = RequestMethod.POST, value = {"/{table}/getbatch"})
public ResponseEntity<List<BaseData>> getBatch(@PathVariable(name = "system",required = true) String system,
@PathVariable(name = "table",required = true) String table,@PathVariable(name = "datasource",required = true) String datasource,
@RequestBody List datas) {
@RequestBody List<Object> datas) {
if(ObjectUtils.isEmpty(datas))
return ResponseEntity.status(HttpStatus.OK).body(new ArrayList<>());
else if(datas.get(0) instanceof Map)
return ResponseEntity.status(HttpStatus.OK).body(persistentService.getByMapBatch(system,table,datasource,datas));
return ResponseEntity.status(HttpStatus.OK).body(persistentService.getByMapBatch(system,table,datasource,(List)datas));
else
return ResponseEntity.status(HttpStatus.OK).body(persistentService.getBatch(system,table,datasource,datas));
return ResponseEntity.status(HttpStatus.OK).body(persistentService.getBatch(system,table,datasource,(List)datas));
}
@ApiOperation(value = "删除数据", tags = {"数据" }, notes = "删除数据")
......@@ -123,13 +123,13 @@ public class PersistentResource
@RequestMapping(method = RequestMethod.POST, value = {"/{table}/removebatch"})
public ResponseEntity<Boolean> doRemoveBatch(@PathVariable(name = "system",required = true) String system,
@PathVariable(name = "table",required = true) String table,@PathVariable(name = "datasource",required = true) String datasource,
@RequestBody List datas) {
@RequestBody List<Object> datas) {
if(ObjectUtils.isEmpty(datas))
return ResponseEntity.status(HttpStatus.OK).body(true);
else if(datas.get(0) instanceof Map)
return ResponseEntity.status(HttpStatus.OK).body(persistentService.removeByMapBatch(system,table,datasource,datas));
return ResponseEntity.status(HttpStatus.OK).body(persistentService.removeByMapBatch(system,table,datasource,(List)datas));
else
return ResponseEntity.status(HttpStatus.OK).body(persistentService.removeBatch(system,table,datasource,datas));
return ResponseEntity.status(HttpStatus.OK).body(persistentService.removeBatch(system,table,datasource,(List)datas));
}
@ApiOperation(value = "更新数据", tags = {"数据" }, notes = "更新数据")
......
......@@ -27,10 +27,12 @@ public interface IDataService
boolean remove(DOModel model,String scope,DSLink dsLink, Serializable key);
boolean removeBatch(DOModel model,String scope,DSLink dsLink,List<Serializable> idList);
boolean removeByMap(DOModel model,String scope,DSLink dsLink, BaseData et);
boolean removeByMapBatch(DOModel model,String scope,DSLink dsLink,List<BaseData> list);
BaseData get(DOModel model,String scope,DSLink dsLink,Serializable key);
List<BaseData> getBatch(DOModel model,String scope,DSLink dsLink,List<Serializable> idList);
BaseData getByMap(DOModel model,String scope,DSLink dsLink,BaseData et);
List<BaseData> getByMapBatch(DOModel model,String scope,DSLink dsLink,List<BaseData> list);
BaseData getDraft(DOModel model,String scope,DSLink dsLink,BaseData et);
boolean checkKey(DOModel model,String scope,DSLink dsLink,BaseData et);
......@@ -90,6 +92,10 @@ public interface IDataService
{
return removeByMap(system,"",entity,"",et);
}
default boolean removeByMapBatch(String system,String entity,List<BaseData> list)
{
return removeByMapBatch(system,"",entity,"",list);
}
default BaseData get(String system,String entity,Serializable key)
{
return get(system,"",entity,"",key);
......@@ -102,6 +108,10 @@ public interface IDataService
{
return getByMap(system,"",entity,"",et);
}
default List<BaseData> getByMapBatch(String system,String entity,List<BaseData> list)
{
return getByMapBatch(system,"",entity,"",list);
}
default BaseData getDraft(String system,String entity,BaseData et)
{
return getDraft(system,"",entity,"",et);
......@@ -204,6 +214,13 @@ public interface IDataService
DSLink dsLink=getDSLink(datasource);
return removeByMap(model,scope,dsLink,et);
}
default boolean removeByMapBatch(String system,String scope,String entity,String datasource,List<BaseData> list)
{
DOModel model=getDOModel(system,entity);
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
DSLink dsLink=getDSLink(datasource);
return removeByMapBatch(model,scope,dsLink,list);
}
default BaseData get(String system,String scope,String entity,String datasource,Serializable key)
{
DOModel model=getDOModel(system,entity);
......@@ -225,6 +242,13 @@ public interface IDataService
DSLink dsLink=getDSLink(datasource);
return getByMap(model,scope,dsLink,et);
}
default List<BaseData> getByMapBatch(String system,String scope,String entity,String datasource,List<BaseData> list)
{
DOModel model=getDOModel(system,entity);
if(StringUtils.isEmpty(datasource))datasource=model.getDefaultDataSource();
DSLink dsLink=getDSLink(datasource);
return getByMapBatch(model,scope,dsLink,list);
}
default BaseData getDraft(String system,String scope,String entity,String datasource,BaseData et)
{
DOModel model=getDOModel(system,entity);
......
......@@ -21,6 +21,7 @@ import org.springframework.cache.annotation.Caching;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
......@@ -80,7 +81,7 @@ public class ModelService {
models=JSON.parseObject(new String(Files.readAllBytes(systemJSON), StandardCharsets.UTF_8), new TypeReference<LinkedHashMap<String, DstSystemModel>>(){});;
} catch (IOException e) {
throw new BadRequestAlertException("解析文件失败","DstSystemModel","SYSTEM.json");
throw new RuntimeException("解析文件失败SYSTEM.json",e);
}
return models;
}
......@@ -157,9 +158,7 @@ public class ModelService {
else
{
dstSystemModel=proxy.getLocalSystemModels().get(system);
if(dstSystemModel==null)
throw new BadRequestAlertException("未找到对应的系统模型","DstSystem",system);
Assert.notNull(dstSystemModel,"未找到对应的系统模型"+system);
system = dstSystemModel.getPssystemid();
File repoDir=Paths.get(getModelPath(),system,"repo").toFile();
......@@ -203,32 +202,25 @@ public class ModelService {
try {
return dynamicService.getDynamicEntity(system,entity);
} catch (Exception exception) {
exception.printStackTrace();
throw new RuntimeException("getEntityModel未找到实体"+system+"."+entity,exception);
}
throw new BadRequestAlertException("未找到实体"+system+"."+entity,"getEntityModel","");
}
public DOModel loadDOModel(String system,String entity)
{
EntityModel entityModel= proxy.getEntityModel(system,entity);
if(entityModel!=null) {
PojoSchema schema = TransUtils.EntityModelModel2Schema(entityModel);
if (schema != null) {
DOModel doModel=new DOModel();
doModel.setSchema(schema);
for (String dsType : entityModel.getDsTypes()) {
POSchema poSchema = TransUtils.EntityModelModel2PO(entityModel, dsType);
if (poSchema != null) {
doModel.addPOSchema(dsType, poSchema);
}
}
return doModel;
Assert.notNull(entityModel,"loadDOModel未找到实体"+system+"."+entity);
PojoSchema schema = TransUtils.EntityModelModel2Schema(entityModel);
Assert.notNull(schema,"loadDOModel未找到实体"+system+"."+entity);
DOModel doModel=new DOModel();
doModel.setSchema(schema);
for (String dsType : entityModel.getDsTypes()) {
POSchema poSchema = TransUtils.EntityModelModel2PO(entityModel, dsType);
if (poSchema != null) {
doModel.addPOSchema(dsType, poSchema);
}
}
throw new BadRequestAlertException("未找到实体"+system+"."+entity,"loadDOModel","");
return doModel;
}
......@@ -243,8 +235,7 @@ public class ModelService {
{
try {
String entityTag=proxy.getEntitiyIdsBySystem(system).get(entity);
if(StringUtils.isEmpty(entityTag))
throw new BadRequestAlertException("获取模型失败","DOModel",key);
Assert.hasLength(entityTag,"获取模型失败"+key);
if(!key.equals(entityTag))
{
String[] args=entityTag.split("[.]");
......@@ -253,7 +244,7 @@ public class ModelService {
storePath = Paths.get(ModelService.MODEL_PATH,system,"repo",entity,"domain",entity+".json");
}
} catch (Exception exception) {
throw new BadRequestAlertException("获取模型失败","DOModel",key);
throw new RuntimeException("获取模型失败"+key,exception);
}
}
......@@ -272,7 +263,7 @@ public class ModelService {
dir.mkdirs();
Files.write(poPath, JSON.toJSONBytes(doModel.getPoSchemas()));
} catch (Exception e) {
throw new BadRequestAlertException("保存文件失败","POSchemas",poPath.toString());
throw new RuntimeException("保存文件失败POSchemas:"+poPath.toString());
}
}
schema.writeTo(Paths.get(ModelService.MODEL_PATH,doModel.getSystemId(),"repo",doModel.getName(),"domain",doModel.getName()+".json"));
......@@ -294,11 +285,7 @@ public class ModelService {
}
}
}
if(schema==null)
throw new BadRequestAlertException("未找到对应的模型","DOModel",key);
Assert.notNull(schema,"未找到对应的模型"+key);
return doModel;
}
......@@ -330,7 +317,7 @@ public class ModelService {
}
}
throw new BadRequestAlertException("未找到对应的模型","DOModel",key);
throw new IllegalArgumentException("未找到对应的模型"+key);
}
......@@ -419,7 +406,7 @@ public class ModelService {
dir.mkdirs();
Files.write(poPath, JSON.toJSONBytes(doModel.getPoSchemas()));
} catch (Exception e) {
throw new BadRequestAlertException("保存文件失败","POSchemas",poPath.toString());
throw new RuntimeException("保存文件失败POSchemas:"+poPath.toString());
}
doModel.getPoSchemas().values().forEach(poSchema->{
mergeTableSchema(doModel.getSystemId(),poSchema,systemModify);
......
......@@ -14,6 +14,7 @@ import org.springframework.context.annotation.Primary;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
......@@ -81,8 +82,7 @@ public class BaseDataServiceImpl implements IDataService {
{
model.fillParentKey(et).fillDefaultValue(et,true);
Serializable key=model.getKeyValue(et,true);
if(ObjectUtils.isEmpty(key))
throw new BadRequestAlertException("未找到主键",model.getName(),null);
Assert.notNull(key,"未找到主键");
POSchema poSchema=model.getPOSchema(link.getType());
return poSchema.trans(getProxyService(link).create(link,poSchema,poSchema.trans2PO(et),true));
}
......@@ -94,8 +94,7 @@ public class BaseDataServiceImpl implements IDataService {
list.forEach(et-> {
model.fillParentKey(et).fillDefaultValue(et, true);
Serializable key = model.getKeyValue(et, true);
if (ObjectUtils.isEmpty(key))
throw new BadRequestAlertException("未找到主键", model.getName(), null);
Assert.notNull(key,"未找到主键");
});
return getProxyService(link).createBatch(link,poSchema,poSchema.trans2PO(list),false);
}
......@@ -105,8 +104,7 @@ public class BaseDataServiceImpl implements IDataService {
{
model.fillParentKey(et).fillDefaultValue(et,false);
Serializable key=model.getKeyValue(et,false);
if(ObjectUtils.isEmpty(key))
throw new BadRequestAlertException("未找到主键",model.getName(),null);
Assert.notNull(key,"未找到主键");
POSchema poSchema=model.getPOSchema(link.getType());
return poSchema.trans(getProxyService(link).update(link,poSchema,poSchema.trans2PO(et),true));
}
......@@ -118,8 +116,7 @@ public class BaseDataServiceImpl implements IDataService {
list.forEach(et-> {
model.fillParentKey(et).fillDefaultValue(et, false);
Serializable key = model.getKeyValue(et, false);
if (ObjectUtils.isEmpty(key))
throw new BadRequestAlertException("未找到主键", model.getName(), null);
Assert.notNull(key,"未找到主键");
});
return getProxyService(link).updateBatch(link,poSchema,poSchema.trans2PO(list),false);
}
......@@ -127,11 +124,9 @@ public class BaseDataServiceImpl implements IDataService {
@Override
public boolean remove(DOModel model, String scope, DSLink link, Serializable key)
{
if(ObjectUtils.isEmpty(key))
throw new BadRequestAlertException("未找到主键",model.getName(),null);
Assert.notNull(key,"未找到主键");
BaseData et = model.newData(key);
if(et==null)
throw new BadRequestAlertException("未找到主键",model.getName(),null);
Assert.notNull(et,"未找到主键");
POSchema poSchema=model.getPOSchema(link.getType());
return getProxyService(link).removeByMap(link,poSchema,poSchema.trans2PO(et));
}
......@@ -143,8 +138,7 @@ public class BaseDataServiceImpl implements IDataService {
List<BaseData> batch=new ArrayList<>();
idList.forEach(key->{
BaseData et = poSchema.newData(key);
if(et==null)
throw new BadRequestAlertException("未找到主键",poSchema.getName(),null);
Assert.notNull(et,"未找到主键");
batch.add(et);
});
return getProxyService(link).removeByMapBatch(link,poSchema,poSchema.trans2PO(batch));
......@@ -154,20 +148,27 @@ public class BaseDataServiceImpl implements IDataService {
public boolean removeByMap(DOModel model, String scope, DSLink link, BaseData et)
{
Serializable key=model.getKeyValue(et,false);
if(ObjectUtils.isEmpty(key))
throw new BadRequestAlertException("未找到主键",model.getName(),null);
Assert.notNull(et,"未找到主键");
POSchema poSchema=model.getPOSchema(link.getType());
return getProxyService(link).removeByMap(link,poSchema,poSchema.trans2PO(et));
}
@Override
public boolean removeByMapBatch(DOModel model, String scope, DSLink link, List<BaseData> list) {
POSchema poSchema=model.getPOSchema(link.getType());
list.forEach(et->{
Serializable key = model.getKeyValue(et, true);
Assert.notNull(key,"未找到主键");
});
return getProxyService(link).removeByMapBatch(link,poSchema,poSchema.trans2PO(list));
}
@Override
public BaseData get(DOModel model, String scope, DSLink link, Serializable key)
{
if(ObjectUtils.isEmpty(key))
throw new BadRequestAlertException("未找到主键",model.getName(),null);
Assert.notNull(key,"未找到主键");
BaseData et = model.newData(key);
if(et==null)
throw new BadRequestAlertException("未找到主键",model.getName(),null);
Assert.notNull(et,"未找到主键");
POSchema poSchema=model.getPOSchema(link.getType());
return poSchema.trans(getProxyService(link).getByMap(link,poSchema,poSchema.trans2PO(et)));
}
......@@ -179,8 +180,7 @@ public class BaseDataServiceImpl implements IDataService {
List<BaseData> batch=new ArrayList<>();
idList.forEach(key->{
BaseData et = poSchema.newData(key);
if(et==null)
throw new BadRequestAlertException("未找到主键",poSchema.getName(),null);
Assert.notNull(et,"未找到主键");
batch.add(et);
});
return poSchema.trans(getProxyService(link).getByMapBatch(link,poSchema,poSchema.trans2PO(batch)));
......@@ -190,12 +190,21 @@ public class BaseDataServiceImpl implements IDataService {
public BaseData getByMap(DOModel model, String scope, DSLink link, BaseData et)
{
Serializable key=model.getKeyValue(et,false);
if(ObjectUtils.isEmpty(key))
throw new BadRequestAlertException("未找到主键",model.getName(),null);
Assert.notNull(key,"未找到主键");
POSchema poSchema=model.getPOSchema(link.getType());
return poSchema.trans(getProxyService(link).getByMap(link,poSchema,poSchema.trans2PO(et)));
}
@Override
public List<BaseData> getByMapBatch(DOModel model, String scope, DSLink link, List<BaseData> list) {
POSchema poSchema=model.getPOSchema(link.getType());
list.forEach(et->{
Serializable key = model.getKeyValue(et, true);
Assert.notNull(key,"未找到主键");
});
return poSchema.trans(getProxyService(link).getByMapBatch(link,poSchema,poSchema.trans2PO(list)));
}
@Override
public BaseData getDraft(DOModel model, String scope, DSLink link, BaseData et)
{
......
......@@ -27,6 +27,7 @@ import org.springframework.transaction.annotation.Transactional;
import cn.ibizlab.core.data.domain.DOModel;
import cn.ibizlab.core.data.filter.DOModelSearchContext;
import cn.ibizlab.core.data.service.IDOModelService;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
......@@ -92,8 +93,7 @@ public class DOModelServiceImpl implements IDOModelService {
}
}
}
if(schema==null)
throw new BadRequestAlertException("未找到对应的模型","DOModel",key);
Assert.notNull(schema,"未找到对应的模型:"+key);
return doModel;
}
......
......@@ -81,7 +81,7 @@ public class DSSettingServiceImpl implements IDSSettingService {
}
return all;
} catch (Exception e) {
throw new BadRequestAlertException("读写文件失败","DSLinkConfig",path.toString());
throw new RuntimeException("读写文件失败DSLinkConfig:"+path.toString());
}
}
......@@ -158,7 +158,7 @@ public class DSSettingServiceImpl implements IDSSettingService {
try {
Files.write(path, JSON.toJSONBytes(newConfigs));
} catch (Exception e) {
throw new BadRequestAlertException("读写文件失败", "DSLinkConfig", path.toString());
throw new RuntimeException("读写文件失败DSLinkConfig:"+path.toString());
}
if (!StringUtils.isEmpty(et.getDsId()))
......@@ -236,7 +236,7 @@ public class DSSettingServiceImpl implements IDSSettingService {
try {
Files.write(path, JSON.toJSONBytes(newConfigs));
} catch (Exception e) {
throw new BadRequestAlertException("读写文件失败", "DSLinkConfig", path.toString());
throw new RuntimeException("读写文件失败DSLinkConfig:"+path.toString());
}
}
return true;
......
......@@ -21,6 +21,7 @@ import org.springframework.transaction.annotation.Transactional;
import cn.ibizlab.core.data.domain.DTOModel;
import cn.ibizlab.core.data.filter.DTOModelSearchContext;
import cn.ibizlab.core.data.service.IDTOModelService;
import org.springframework.util.Assert;
/**
......@@ -98,10 +99,8 @@ public class DTOModelServiceImpl implements IDTOModelService {
else
schema=PojoSchema.fromPath(storePath);
if(schema!=null)
dtoModel.setSchema(schema);
else
throw new BadRequestAlertException("未找到对应的模型","DTOModel",key);
Assert.notNull(schema,"未找到对应的模型:"+key);
dtoModel.setSchema(schema);
return dtoModel;
......
......@@ -17,6 +17,7 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import java.io.Serializable;
......@@ -95,8 +96,7 @@ public class DbPersistentServiceImpl implements IPersistentService {
@Override
public boolean remove(DSLink link, POSchema poSchema, Serializable key) {
BaseData et=poSchema.newData(key);
if(et==null)
throw new BadRequestAlertException("未找到主键",poSchema.getName(),null);
Assert.notNull(et,"未找到主键");
repository.removeData(link.getName(),poSchema,et);
return true;
}
......@@ -106,8 +106,7 @@ public class DbPersistentServiceImpl implements IPersistentService {
List<BaseData> batch=new ArrayList<>();
idList.forEach(key->{
BaseData et = poSchema.newData(key);
if(et==null)
throw new BadRequestAlertException("未找到主键",poSchema.getName(),null);
Assert.notNull(et,"未找到主键");
batch.add(et);
if(batch.size()>=BATCH_SIZE)
{
......@@ -151,11 +150,10 @@ public class DbPersistentServiceImpl implements IPersistentService {
@Override
public BaseData get(DSLink link, POSchema poSchema, Serializable key) {
BaseData et=poSchema.newData(key);
if(et==null)
throw new BadRequestAlertException("未找到主键",poSchema.getName(),null);
Assert.notNull(et,"未找到主键");
List<BaseData> list = repository.getData(link.getName(),poSchema,et);
if(ObjectUtils.isEmpty(list)||list.size()>1)
throw new BadRequestAlertException("未找到数据",poSchema.getName(),key.toString());
throw new IllegalArgumentException("未找到数据"+poSchema.getName()+":"+key);
return list.get(0);
}
......@@ -165,8 +163,7 @@ public class DbPersistentServiceImpl implements IPersistentService {
List<BaseData> batch=new ArrayList<>();
idList.forEach(key->{
BaseData et = poSchema.newData(key);
if(et==null)
throw new BadRequestAlertException("未找到主键",poSchema.getName(),null);
Assert.notNull(et,"未找到主键");
batch.add(et);
if(batch.size()>=BATCH_SIZE)
{
......@@ -186,7 +183,7 @@ public class DbPersistentServiceImpl implements IPersistentService {
public BaseData getByMap(DSLink link, POSchema poSchema, BaseData et) {
List<BaseData> list = repository.getData(link.getName(),poSchema,et);
if(ObjectUtils.isEmpty(list)||list.size()>1)
throw new BadRequestAlertException("未找到数据",poSchema.getName(),"");
throw new IllegalArgumentException("未找到数据"+poSchema.getName()+":"+et.getKey());
return list.get(0);
}
......
......@@ -14,6 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import java.io.Serializable;
......@@ -63,8 +64,7 @@ public class MongoPersistentServiceImpl implements IPersistentService {
@Override
public boolean remove(DSLink link, POSchema poSchema, Serializable key) {
BaseData et=poSchema.newData(key);
if(et==null)
throw new BadRequestAlertException("未找到主键",poSchema.getName(),null);
Assert.notNull(et,"未找到主键");
repository.removeData(link.getName(),poSchema,et);
return true;
}
......@@ -74,8 +74,7 @@ public class MongoPersistentServiceImpl implements IPersistentService {
List<BaseData> batch=new ArrayList<>();
idList.forEach(key->{
BaseData et = poSchema.newData(key);
if(et==null)
throw new BadRequestAlertException("未找到主键",poSchema.getName(),null);
Assert.notNull(et,"未找到主键");
batch.add(et);
});
if(batch.size()>0)
......@@ -101,11 +100,10 @@ public class MongoPersistentServiceImpl implements IPersistentService {
@Override
public BaseData get(DSLink link, POSchema poSchema, Serializable key) {
BaseData et=poSchema.newData(key);
if(et==null)
throw new BadRequestAlertException("未找到主键",poSchema.getName(),null);
Assert.notNull(et,"未找到主键");
List<BaseData> list = repository.getData(link.getName(),poSchema,et);
if(ObjectUtils.isEmpty(list)||list.size()>1)
throw new BadRequestAlertException("未找到数据",poSchema.getName(),key.toString());
throw new IllegalArgumentException("未找到数据"+poSchema.getName()+":"+key);
return list.get(0);
}
......@@ -114,8 +112,7 @@ public class MongoPersistentServiceImpl implements IPersistentService {
List<BaseData> batch=new ArrayList<>();
idList.forEach(key->{
BaseData et = poSchema.newData(key);
if(et==null)
throw new BadRequestAlertException("未找到主键",poSchema.getName(),null);
Assert.notNull(et,"未找到主键");
batch.add(et);
});
......@@ -126,7 +123,7 @@ public class MongoPersistentServiceImpl implements IPersistentService {
public BaseData getByMap(DSLink link, POSchema poSchema, BaseData et) {
List<BaseData> list = repository.getData(link.getName(),poSchema,et);
if(ObjectUtils.isEmpty(list)||list.size()>1)
throw new BadRequestAlertException("未找到数据",poSchema.getName(),"");
throw new IllegalArgumentException("未找到数据"+poSchema.getName()+":"+et.getKey());
return list.get(0);
}
......@@ -225,7 +222,7 @@ public class MongoPersistentServiceImpl implements IPersistentService {
@Override
public boolean execRaw(DSLink link, POSchema poSchema, String sql, BaseData param) {
throw new BadRequestAlertException("没有实现方法execRaw",poSchema.getName(),sql);
throw new IllegalArgumentException(String.format("没有实现方法execRaw,%1$s,%2$s",poSchema.getName(),sql));
}
@Override
......
package cn.ibizlab.core.util.config;
import cn.ibizlab.core.data.elasticsearch.DynamicEsContextHolder;
import cn.ibizlab.core.data.elasticsearch.DynamicEsTemplate;
import cn.ibizlab.core.data.mongodb.DynamicMongoContextHolder;
import cn.ibizlab.core.data.mongodb.DynamicMongoTemplate;
import cn.ibizlab.util.helper.JSR310DateConverters;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient;
import org.springframework.data.elasticsearch.core.ReactiveElasticsearchTemplate;
import org.springframework.data.mongodb.MongoDbFactory;
import org.springframework.data.mongodb.core.convert.MongoCustomConversions;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@Configuration
public class EsDBConfig {
@Value("${spring.data.mongodb.uri:mongodb://localhost:27017/admin}")
private String uri;
@Bean(name = "reactiveElasticsearchTemplate")
@Lazy
public ReactiveElasticsearchTemplate reactiveElasticsearchTemplate() {
if(DynamicEsContextHolder.ES_CLIENT_DB_FACTORY_MAP.size()==0)
DynamicEsContextHolder.addFactory("master",uri);
Iterator<ReactiveElasticsearchClient> iterator = DynamicEsContextHolder.ES_CLIENT_DB_FACTORY_MAP.values().iterator();
return new DynamicEsTemplate(iterator.next());
}
@Bean(name = "reactiveElasticsearchClient")
@Lazy
public ReactiveElasticsearchClient reactiveElasticsearchClient() {
Iterator<ReactiveElasticsearchClient> iterator = DynamicEsContextHolder.ES_CLIENT_DB_FACTORY_MAP.values().iterator();
return iterator.next();
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ package cn.ibizlab.core.util.config;
import cn.ibizlab.core.data.mongodb.DynamicMongoContextHolder;
import cn.ibizlab.core.data.mongodb.DynamicMongoTemplate;
import cn.ibizlab.util.helper.JSR310DateConverters;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
......@@ -54,141 +55,4 @@ public class MongoDBConfig {
return iterator.next();
}
public static class JSR310DateConverters {
private JSR310DateConverters() {
}
public static class TimestampToDateConverter implements Converter<Timestamp, Date> {
public static final TimestampToDateConverter INSTANCE = new TimestampToDateConverter();
private TimestampToDateConverter() {
}
@Override
public Date convert(Timestamp source) {
return source == null ? null : new Date(source.getTime());
}
}
public static class DateToTimestampConverter implements Converter<Date, Timestamp> {
public static final DateToTimestampConverter INSTANCE = new DateToTimestampConverter();
private DateToTimestampConverter() {
}
@Override
public Timestamp convert(Date source) {
return source == null ? null : new Timestamp(source.getTime());
}
}
public static class LocalDateToDateConverter implements Converter<LocalDate, Date> {
public static final LocalDateToDateConverter INSTANCE = new LocalDateToDateConverter();
private LocalDateToDateConverter() {
}
@Override
public Date convert(LocalDate source) {
return source == null ? null : Date.from(source.atStartOfDay(ZoneId.systemDefault()).toInstant());
}
}
public static class DateToLocalDateConverter implements Converter<Date, LocalDate> {
public static final DateToLocalDateConverter INSTANCE = new DateToLocalDateConverter();
private DateToLocalDateConverter() {
}
@Override
public LocalDate convert(Date source) {
return source == null ? null : ZonedDateTime.ofInstant(source.toInstant(), ZoneId.systemDefault())
.toLocalDate();
}
}
public static class ZonedDateTimeToDateConverter implements Converter<ZonedDateTime, Date> {
public static final ZonedDateTimeToDateConverter INSTANCE = new ZonedDateTimeToDateConverter();
private ZonedDateTimeToDateConverter() {
}
@Override
public Date convert(ZonedDateTime source) {
return source == null ? null : Date.from(source.toInstant());
}
}
public static class DateToZonedDateTimeConverter implements Converter<Date, ZonedDateTime> {
public static final DateToZonedDateTimeConverter INSTANCE = new DateToZonedDateTimeConverter();
private DateToZonedDateTimeConverter() {
}
@Override
public ZonedDateTime convert(Date source) {
return source == null ? null : ZonedDateTime.ofInstant(source.toInstant(), ZoneId.systemDefault());
}
}
public static class LocalDateTimeToDateConverter implements Converter<LocalDateTime, Date> {
public static final LocalDateTimeToDateConverter INSTANCE = new LocalDateTimeToDateConverter();
private LocalDateTimeToDateConverter() {
}
@Override
public Date convert(LocalDateTime source) {
return source == null ? null : Date.from(source.atZone(ZoneId.systemDefault()).toInstant());
}
}
public static class DateToLocalDateTimeConverter implements Converter<Date, LocalDateTime> {
public static final DateToLocalDateTimeConverter INSTANCE = new DateToLocalDateTimeConverter();
private DateToLocalDateTimeConverter() {
}
@Override
public LocalDateTime convert(Date source) {
return source == null ? null : LocalDateTime.ofInstant(source.toInstant(), ZoneId.systemDefault());
}
}
public static class DurationToLongConverter implements Converter<Duration, Long> {
public static final DurationToLongConverter INSTANCE = new DurationToLongConverter();
private DurationToLongConverter() {
}
@Override
public Long convert(Duration source) {
return source == null ? null : source.toNanos();
}
}
public static class LongToDurationConverter implements Converter<Long, Duration> {
public static final LongToDurationConverter INSTANCE = new LongToDurationConverter();
private LongToDurationConverter() {
}
@Override
public Duration convert(Long source) {
return source == null ? null : Duration.ofNanos(source);
}
}
}
}
\ No newline at end of file
package cn.ibizlab.util.helper;
import org.springframework.core.convert.converter.Converter;
import java.sql.Timestamp;
import java.time.*;
import java.util.Date;
/**
* <p>JSR310DateConverters class.</p>
*/
public final class JSR310DateConverters {
private JSR310DateConverters() {
}
public static class TimestampToDateConverter implements Converter<Timestamp, Date> {
public static final TimestampToDateConverter INSTANCE = new TimestampToDateConverter();
private TimestampToDateConverter() {
}
@Override
public Date convert(Timestamp source) {
return source == null ? null : new Date(source.getTime());
}
}
public static class DateToTimestampConverter implements Converter<Date, Timestamp> {
public static final DateToTimestampConverter INSTANCE = new DateToTimestampConverter();
private DateToTimestampConverter() {
}
@Override
public Timestamp convert(Date source) {
return source == null ? null : new Timestamp(source.getTime());
}
}
public static class LocalDateToDateConverter implements Converter<LocalDate, Date> {
public static final LocalDateToDateConverter INSTANCE = new LocalDateToDateConverter();
private LocalDateToDateConverter() {
}
@Override
public Date convert(LocalDate source) {
return source == null ? null : Date.from(source.atStartOfDay(ZoneId.systemDefault()).toInstant());
}
}
public static class DateToLocalDateConverter implements Converter<Date, LocalDate> {
public static final DateToLocalDateConverter INSTANCE = new DateToLocalDateConverter();
private DateToLocalDateConverter() {
}
@Override
public LocalDate convert(Date source) {
return source == null ? null : ZonedDateTime.ofInstant(source.toInstant(), ZoneId.systemDefault())
.toLocalDate();
}
}
public static class ZonedDateTimeToDateConverter implements Converter<ZonedDateTime, Date> {
public static final ZonedDateTimeToDateConverter INSTANCE = new ZonedDateTimeToDateConverter();
private ZonedDateTimeToDateConverter() {
}
@Override
public Date convert(ZonedDateTime source) {
return source == null ? null : Date.from(source.toInstant());
}
}
public static class DateToZonedDateTimeConverter implements Converter<Date, ZonedDateTime> {
public static final DateToZonedDateTimeConverter INSTANCE = new DateToZonedDateTimeConverter();
private DateToZonedDateTimeConverter() {
}
@Override
public ZonedDateTime convert(Date source) {
return source == null ? null : ZonedDateTime.ofInstant(source.toInstant(), ZoneId.systemDefault());
}
}
public static class LocalDateTimeToDateConverter implements Converter<LocalDateTime, Date> {
public static final LocalDateTimeToDateConverter INSTANCE = new LocalDateTimeToDateConverter();
private LocalDateTimeToDateConverter() {
}
@Override
public Date convert(LocalDateTime source) {
return source == null ? null : Date.from(source.atZone(ZoneId.systemDefault()).toInstant());
}
}
public static class DateToLocalDateTimeConverter implements Converter<Date, LocalDateTime> {
public static final DateToLocalDateTimeConverter INSTANCE = new DateToLocalDateTimeConverter();
private DateToLocalDateTimeConverter() {
}
@Override
public LocalDateTime convert(Date source) {
return source == null ? null : LocalDateTime.ofInstant(source.toInstant(), ZoneId.systemDefault());
}
}
public static class DurationToLongConverter implements Converter<Duration, Long> {
public static final DurationToLongConverter INSTANCE = new DurationToLongConverter();
private DurationToLongConverter() {
}
@Override
public Long convert(Duration source) {
return source == null ? null : source.toNanos();
}
}
public static class LongToDurationConverter implements Converter<Long, Duration> {
public static final LongToDurationConverter INSTANCE = new LongToDurationConverter();
private LongToDurationConverter() {
}
@Override
public Duration convert(Long source) {
return source == null ? null : Duration.ofNanos(source);
}
}
}
\ No newline at end of file
......@@ -15,14 +15,14 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.1.RELEASE</version>
<version>2.2.5.RELEASE</version>
</parent>
<properties>
<!-- Spring Cloud Alibaba(2.2.x.RELEASE) & Spring Cloud(Spring Cloud Greenwich) & Spring Boot(2.2.x.RELEASE) compatibility -->
<spring-cloud-alibaba.version>2.2.1.RELEASE</spring-cloud-alibaba.version>
<spring-cloud-openfeign.version>2.2.1.RELEASE</spring-cloud-openfeign.version>
<spring-cloud-openfeign.version>2.2.5.RELEASE</spring-cloud-openfeign.version>
<!-- Alibaba Druid -->
<alibaba-druid.version>1.1.21</alibaba-druid.version>
......@@ -48,7 +48,7 @@
<logstash.version>5.2</logstash.version>
<!--Zuul网关-->
<spring-cloud-starter-netflix-zuul.version>2.2.1.RELEASE</spring-cloud-starter-netflix-zuul.version>
<spring-cloud-starter-netflix-zuul.version>2.2.5.RELEASE</spring-cloud-starter-netflix-zuul.version>
<!--MapStruct高性能属性映射工具-->
<mapstruct.version>1.3.0.Final</mapstruct.version>
......@@ -75,7 +75,7 @@
<baomidou-jobs.version>1.0.3</baomidou-jobs.version>
<!-- eureka微服务注册中心 -->
<eureka-client.version>2.2.1.RELEASE</eureka-client.version>
<eureka-client.version>2.2.5.RELEASE</eureka-client.version>
<!-- 阿里sentinel熔断器 -->
<alibaba-sentinel.version>2.1.1.RELEASE</alibaba-sentinel.version>
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册