提交 21b8444e 编写于 作者: ibizdev's avatar ibizdev

ibizdev提交

上级 79295d91
......@@ -23,15 +23,15 @@ public interface IIBZDictService{
IBZDict get(String key) ;
boolean create(IBZDict et) ;
void createBatch(List<IBZDict> list, int batchSize) ;
void createBatch(List<IBZDict> list) ;
boolean checkKey(IBZDict et) ;
IBZDict getDraft(IBZDict et) ;
boolean update(IBZDict et) ;
void updateBatch(List<IBZDict> list, int batchSize) ;
void updateBatch(List<IBZDict> list) ;
boolean remove(String key) ;
void removeBatch(Collection<String> idList, int batchSize) ;
void removeBatch(Collection<String> idList) ;
boolean save(IBZDict et) ;
void saveBatch(List<IBZDict> list, int batchSize) ;
void saveBatch(List<IBZDict> list) ;
Page<IBZDict> searchDefault(IBZDictSearchContext context) ;
......
package cn.ibizlab.core.dict.service.impl;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.Set;
import java.util.HashSet;
import java.math.BigInteger;
import java.util.Collection;
import java.util.Objects;
import java.util.Optional;
import lombok.extern.slf4j.Slf4j;
......@@ -20,6 +17,7 @@ import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.util.ObjectUtils;
import cn.ibizlab.core.dict.domain.IBZDict;
import cn.ibizlab.core.dict.filter.IBZDictSearchContext;
import cn.ibizlab.core.dict.service.IIBZDictService;
......@@ -38,93 +36,91 @@ import cn.ibizlab.core.dict.repository.IBZDictRepository;
public class IBZDictServiceImpl implements IIBZDictService {
@Autowired
IBZDictRepository repository;
@Autowired
private cn.ibizlab.core.dict.service.IIBZDictItemService iBZDictItemService;
private IBZDictRepository repository;
@Override
public IBZDict get(String dictid) {
return repository.findById(dictid).get();
}
@Override
public IBZDict get(IBZDict et) {
return null ;
@Transactional
public IBZDict get(String key) {
Optional<IBZDict> result = repository.findById(key);
if(!result.isPresent()){
et=new IBZDict();
et.setDictid(key);
}
else
et=result.get();
return et;
}
@Override
@Transactional
public boolean create(IBZDict et) {
if(!ObjectUtils.isEmpty(et.getDictid()))
et.setDictid((String)et.getDefaultKey());
repository.insert(et);
return true ;
}
@Override
public void createBatch(List<IBZDict> list) {
repository.insert(list);
}
@Override
public boolean checkKey(IBZDict et) {
return true;
return repository.findById(et.getDictid()).isPresent();
}
@Override
public IBZDict getDraft(IBZDict et) {
return et;
}
@Override
@Transactional
public boolean update(IBZDict et) {
repository.save(et);
return true ;
}
@Override
public void updateBatch(List<IBZDict> list) {
repository.saveAll(list);
}
@Override
public boolean remove(String dictid) {
repository.deleteById(dictid);
@Transactional
public boolean remove(String key) {
repository.deleteById(key);
return true ;
}
@Override
public void removeBatch(Collection<String> idList) {
repository.deleteAll(repository.findAllById(idList));
}
/**
* 查询集合 DEFAULT
*/
@Override
public Page<IBZDict> searchDefault(IBZDictSearchContext context) {
List<IBZDict> iBZDicts=repository.findAll();
return new PageImpl<IBZDict>(iBZDicts, context.getPageable(), iBZDicts.size());
@Transactional
public boolean save(IBZDict et) {
repository.save(et);
return true ;
}
//更新嵌套[字典项目]
private void _updateItems(IBZDict newIBZDict , IBZDict oldIBZDict){
Map<String,cn.ibizlab.core.dict.domain.IBZDictItem> oldMapItems = new HashMap<String,cn.ibizlab.core.dict.domain.IBZDictItem>() ;
List<cn.ibizlab.core.dict.domain.IBZDictItem> oldItems = oldIBZDict.getItems();
if(ObjectUtils.isEmpty(oldItems) || oldItems.size()==0){
return ;
}
for(cn.ibizlab.core.dict.domain.IBZDictItem iBZDictItem : oldItems){
oldMapItems.put(iBZDictItem.getItemId(),iBZDictItem);
}
@Override
public void saveBatch(List<IBZDict> list) {
repository.saveAll(list);
}
Map<String,cn.ibizlab.core.dict.domain.IBZDictItem> newMapItems = new HashMap<String,cn.ibizlab.core.dict.domain.IBZDictItem>() ;
List<cn.ibizlab.core.dict.domain.IBZDictItem> newItems = newIBZDict.getItems() ;
for(cn.ibizlab.core.dict.domain.IBZDictItem iBZDictItem : newItems){
iBZDictItem.setDictId(newIBZDict.getDictId());
if(iBZDictItem.getItemId() == null ){
iBZDictItemService.create(iBZDictItem) ;
continue ;
}
newMapItems.put(iBZDictItem.getItemId(),iBZDictItem) ;
if(oldMapItems.containsKey(iBZDictItem.getItemId())) {
iBZDictItemService.update(iBZDictItem);
}else {
iBZDictItemService.create(iBZDictItem);
}
}
//删除多余数据
for(String key : oldMapItems.keySet()){
if(!newMapItems.containsKey(key))
iBZDictItemService.remove(key) ;
}
/**
* 查询集合 DEFAULT
*/
@Override
public Page<IBZDict> searchDefault(IBZDictSearchContext context) {
return repository.findAll(context.getPageable());
}
}
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册