提交 00037c66 编写于 作者: ibizdev's avatar ibizdev

ibizdev提交

上级 04f10eb5
......@@ -21,6 +21,8 @@ import org.springframework.transaction.annotation.Transactional;
import cn.ibizlab.core.dict.domain.IBZDictItem;
import cn.ibizlab.core.dict.filter.IBZDictItemSearchContext;
import cn.ibizlab.core.dict.service.IIBZDictItemService;
import cn.ibizlab.core.dict.util.helper.CachedBeanCopier;
import cn.ibizlab.util.SearchResult;
import cn.ibizlab.util.log.IBIZLog;
......@@ -46,8 +48,7 @@ public class IBZDictItemServiceImpl extends ServiceImpl<IBZDictItemMapper, IBZDi
@Transactional
public IBZDictItem get(String key) {
IBZDictItem et = getById(key);
if(et==null)
{
if(et==null){
et=new IBZDictItem();
et.setItemid(key);
}
......@@ -59,6 +60,23 @@ public class IBZDictItemServiceImpl extends ServiceImpl<IBZDictItemMapper, IBZDi
return et;
}
@Override
@Transactional
public boolean save(IBZDictItem et) {
return saveOrUpdate(et) ;
}
@Override
@Transactional(
rollbackFor = {Exception.class}
)
public boolean saveOrUpdate(IBZDictItem et) {
if (null == et) {
return false;
} else {
return checkKey(et) ? this.update(et) : this.create(et);
}
}
@Override
public boolean checkKey(IBZDictItem et) {
......@@ -66,26 +84,27 @@ public class IBZDictItemServiceImpl extends ServiceImpl<IBZDictItemMapper, IBZDi
}
@Override
@Transactional
public boolean remove(String itemid) {
boolean bOk = false ;
IBZDictItem _iBZDictItem = this.get(itemid);
bOk = removeById(itemid);
return bOk ;
public remove(String key) {
boolean ret = removeById(key);
if(!ret) return ret;
return ret ;
}
@Override
@Transactional
public boolean create(IBZDictItem et) {
boolean ret = this.retBool(this.baseMapper.insert(et));
if(!ret) return ret;
CachedBeanCopier.copy(get(et.getItemid()),et);
return ret ;
}
@Override
@Transactional
public boolean update(IBZDictItem et) {
boolean bOk = false ;
bOk = update(et, (Wrapper)et.getUpdateWrapper(true).eq("ibzdictitemid",et.getItemId()));
return bOk ;
boolean ret = update(et, et.getUpdateWrapper(true).eq("ibzdictitemid",et.getItemid()));
if(!ret) return ret;
CachedBeanCopier.copy(get(et.getItemid()),et);
return ret ;
}
/**
......
......@@ -21,6 +21,8 @@ import org.springframework.transaction.annotation.Transactional;
import cn.ibizlab.core.dict.domain.IBZDict;
import cn.ibizlab.core.dict.filter.IBZDictSearchContext;
import cn.ibizlab.core.dict.service.IIBZDictService;
import cn.ibizlab.core.dict.util.helper.CachedBeanCopier;
import cn.ibizlab.util.SearchResult;
import cn.ibizlab.util.log.IBIZLog;
......@@ -48,8 +50,7 @@ public class IBZDictServiceImpl extends ServiceImpl<IBZDictMapper, IBZDict> impl
@Transactional
public IBZDict get(String key) {
IBZDict et = getById(key);
if(et==null)
{
if(et==null){
et=new IBZDict();
et.setDictid(key);
}
......@@ -61,15 +62,15 @@ public class IBZDictServiceImpl extends ServiceImpl<IBZDictMapper, IBZDict> impl
public boolean create(IBZDict et) {
boolean ret = this.retBool(this.baseMapper.insert(et));
if(!ret) return ret;
//嵌套[字典项目]
if(et.getItems()!=null){
if(!ObjectUtils.isEmpty(et.getItems())){
for (cn.ibizlab.core.dict.domain.IBZDictItem sub: et.getItems()) {
sub.setDictid(et.getDictid())
sub.setDictid(et.getDictid());
}
if(et.getItems().size()>0)
ibzdictitemService.createBatch(sub,500) ;
et.setItems(null);
ibzdictitemService.createBatch(et.getItems(),500) ;
}
CachedBeanCopier.copy(get(et.getDictid()),et);
return ret ;
}
......@@ -85,24 +86,52 @@ public class IBZDictServiceImpl extends ServiceImpl<IBZDictMapper, IBZDict> impl
@Override
@Transactional
public boolean update(IBZDict et) {
boolean bOk = false ;
bOk = update(et, (Wrapper)et.getUpdateWrapper(true).eq("ibzdictid",et.getDictId()));
boolean ret = update(et, et.getUpdateWrapper(true).eq("ibzdictid",et.getDictid()));
if(!ret) return ret;
//嵌套[字典项目]
this._updateItems(ibzdict,get(ibzdict.getDictId()));
return bOk ;
if(!ObjectUtils.isEmpty(et.getItems())){
for (cn.ibizlab.core.dict.domain.IBZDictItem sub: et.getItems()) {
sub.setDictid(et.getDictid());
}
ibzdictitemService.saveBatch(et.getItems(),500) ;
}
CachedBeanCopier.copy(get(et.getDictid()),et);
return ret ;
}
@Override
@Transactional
public boolean remove(String dictid) {
boolean bOk = false ;
IBZDict _iBZDict = this.get(dictid);
public remove(String key) {
IBZDict et = get(key);
//嵌套[字典项目]
for (cn.ibizlab.core.dict.domain.IBZDictItem _iBZDictItem : _iBZDict.getItems()) {
iBZDictItemService.remove(_iBZDictItem.getItemId()) ;
if(!ObjectUtils.isEmpty(et.getItems())){
List<String> ids=new ArrayList<String>();
for (cn.ibizlab.core.dict.domain.IBZDictItem sub: et.getItems()) {
ids.add(sub.getDictid());
}
ibzdictitemService.removeBatch(ids,500) ;
}
boolean ret = removeById(key);
if(!ret) return ret;
return ret ;
}
@Override
@Transactional
public boolean save(IBZDict et) {
return saveOrUpdate(et) ;
}
@Override
@Transactional(
rollbackFor = {Exception.class}
)
public boolean saveOrUpdate(IBZDict et) {
if (null == et) {
return false;
} else {
return checkKey(et) ? this.update(et) : this.create(et);
}
bOk = removeById(dictid);
return bOk ;
}
......
package cn.ibizlab.util.helper;
import org.springframework.cglib.beans.BeanCopier;
import java.util.HashMap;
import java.util.Map;
public class CachedBeanCopier {
//创建过的BeanCopier实例放到缓存中,下次可以直接获取,提升性能
static final Map<String, BeanCopier> BEAN_COPIERS = new HashMap<String, BeanCopier>();
public static void copy(Object srcObj, Object destObj) {
copy(srcObj,destObj,false);
}
public static void copy(Object srcObj, Object destObj,boolean useConverter) {
if(srcObj==null||destObj==null)
return;
getCopier(srcObj,destObj,useConverter).copy(srcObj, destObj, null);
}
public synchronized static BeanCopier getCopier(Object srcObj, Object destObj,boolean useConverter) {
String key = srcObj.getClass().getName()+destObj.getClass().getName()+useConverter;
BeanCopier copier;
if (!BEAN_COPIERS.containsKey(key)) {
copier = BeanCopier.create(srcObj.getClass(), destObj.getClass(), useConverter);
BEAN_COPIERS.put(key, copier);
} else {
copier = BEAN_COPIERS.get(key);
}
return copier;
}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册