use of com.duangframework.core.exceptions.ServiceException in project duangframework by tcrct.
the class CurdService method update.
/**
* 更改记录
*/
public boolean update(T entity) throws ServiceException {
try {
updateIdEntityData(entity);
boolean isOk = getMongoDao().update(entity.getId(), entity);
if (isOk && (getCacheDao() != null)) {
T cacheEntity = (T) getCacheDao().findById(entity.getId(), getEntityClass());
ObjectKit.copyFields(entity, cacheEntity);
if (ToolsKit.isNotEmpty(entity.getCreateuserid())) {
cacheEntity.setCreateuserid(entity.getCreateuserid());
}
if (ToolsKit.isNotEmpty(entity.getCreatetime())) {
cacheEntity.setCreatetime(entity.getCreatetime());
}
if (ToolsKit.isNotEmpty(entity.getId())) {
cacheEntity.setId(entity.getId());
}
if (ToolsKit.isNotEmpty(entity.getSource())) {
cacheEntity.setSource(entity.getSource());
}
if (ToolsKit.isNotEmpty(entity.getStatus())) {
cacheEntity.setStatus(entity.getStatus());
}
if (ToolsKit.isNotEmpty(entity.getUpdatetime())) {
cacheEntity.setUpdatetime(entity.getUpdatetime());
}
if (ToolsKit.isNotEmpty(entity.getUpdateuserid())) {
cacheEntity.setUpdateuserid(entity.getUpdateuserid());
}
getCacheDao().save(cacheEntity);
}
return true;
} catch (Exception e) {
throw new ServiceException("update entity[" + entity.getId() + "] record is fail: " + e.getMessage(), e);
}
}
Aggregations