use of com.hccake.ballcat.codegen.model.entity.TemplateEntry in project ballcat-codegen by ballcat-projects.
the class TemplateEntryServiceImpl method updateEntry.
/**
* 更新目录项
* @param entryDTO 目录项修改传输对象
* @return success:true
*/
@Override
@Transactional(rollbackFor = Exception.class)
public boolean updateEntry(TemplateEntryUpdateDTO entryDTO) {
Integer entryId = entryDTO.getId();
String filename = entryDTO.getFilename();
// 目录项必须存在
TemplateEntry oldEntry = baseMapper.selectById(entryId);
Assert.notNull(oldEntry, "This is a nonexistent directory entry!");
// 如果更新了文件名,则进行重名校验
if (!filename.equals(oldEntry.getFilename())) {
this.duplicateNameCheck(oldEntry.getParentId(), filename);
}
// 更新 entry
TemplateEntry entry = TemplateModelConverter.INSTANCE.entryUpdateDtoToPo(entryDTO);
return SqlHelper.retBool(baseMapper.updateById(entry));
}
use of com.hccake.ballcat.codegen.model.entity.TemplateEntry in project ballcat-codegen by ballcat-projects.
the class TemplateEntryServiceImpl method createEntry.
/**
* 新建一个目录项
* @param entryDTO 目录项新建传输对象
* @return entryId
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Integer createEntry(TemplateEntryCreateDTO entryDTO) {
// 若父节点不是根,则校验父级节点是否有效
Integer parentId = entryDTO.getParentId();
Assert.isTrue(GlobalConstants.TREE_ROOT_ID.equals(parentId) || this.exists(parentId), "This is a nonexistent parent directory entry!");
// 重名校验
this.duplicateNameCheck(parentId, entryDTO.getFilename());
// 转持久层对象
TemplateEntry entity = TemplateModelConverter.INSTANCE.entryCreateDtoToPo(entryDTO);
// 落库
baseMapper.insert(entity);
return entity.getId();
}
use of com.hccake.ballcat.codegen.model.entity.TemplateEntry in project ballcat-codegen by ballcat-projects.
the class TemplateEntryServiceImpl method updateContent.
@Override
public boolean updateContent(Integer id, String content) {
TemplateEntry entry = new TemplateEntry();
entry.setId(id);
entry.setContent(content);
return SqlHelper.retBool(baseMapper.updateById(entry));
}
use of com.hccake.ballcat.codegen.model.entity.TemplateEntry in project ballcat-codegen by ballcat-projects.
the class TemplateEntryServiceImpl method move.
/**
* 移动目录项
* @param horizontalMove 是否移动到目标目录平级,否则移动到其内部
* @param entryId 被移动的目录项ID
* @param targetEntryId 目标目录项ID
* @return boolean 移动成功或者失败
*/
@Override
public boolean move(boolean horizontalMove, Integer entryId, Integer targetEntryId) {
// 目录项必须存在
TemplateEntry entry = baseMapper.selectById(entryId);
Assert.notNull(entry, "This is a nonexistent directory entry!");
TemplateEntry targetEntry = baseMapper.selectById(targetEntryId);
// 目标必须存
Assert.notNull(entry, "Target directory entry does not exist!");
// 非平级移动时,目标必须是文件夹
Assert.isTrue(horizontalMove || TemplateEntryTypeEnum.FOLDER.getType().equals(targetEntry.getType()), "The target is not a folder");
// 平级移动则目标父节点就是其父节点
Integer parentId = horizontalMove ? targetEntry.getParentId() : targetEntry.getId();
// 如果已经在该文件夹下则无需移动
Assert.isFalse(parentId.equals(entry.getParentId()), "The entry do not need to be moved");
// 重名校验
this.duplicateNameCheck(parentId, entry.getFilename());
// 更新目录项
TemplateEntry entity = new TemplateEntry();
entity.setId(entryId);
entity.setParentId(parentId);
return SqlHelper.retBool(baseMapper.updateById(entity));
}
use of com.hccake.ballcat.codegen.model.entity.TemplateEntry in project ballcat-codegen by ballcat-projects.
the class TemplateEntryServiceImpl method copy.
/**
* 复制模板目录项文件
* @param resourceGroupId 原模板组
* @param targetGroupId 模板模板组
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void copy(Integer resourceGroupId, Integer targetGroupId) {
// 1. ===============获取模板目录项==================
List<TemplateEntry> list = baseMapper.listByTemplateGroupId(resourceGroupId);
// 2. ============== 复制模板文件 ===================
Set<Integer> oldParentIdSet = new HashSet<>();
List<Integer> originEntryIds = new ArrayList<>();
for (TemplateEntry entry : list) {
originEntryIds.add(entry.getId());
oldParentIdSet.add(entry.getParentId());
entry.setGroupId(targetGroupId);
entry.setId(null);
entry.setCreateTime(null);
entry.setUpdateTime(null);
}
this.saveBatchSomeColumn(list);
// 3. =============== 获取新老ID的映射表,key: oldId, value: newId ==========
Map<Integer, Integer> idMap = new HashMap<>(originEntryIds.size());
for (int i = 0; i < originEntryIds.size(); i++) {
idMap.put(originEntryIds.get(i), list.get(i).getId());
}
// 4. =============== 更新复制出来的模板文件的父级ID ===============
// 父节点为根节点的不需要修改
oldParentIdSet.remove(GlobalConstants.TREE_ROOT_ID);
for (Integer oldParentId : oldParentIdSet) {
baseMapper.updateParentId(targetGroupId, oldParentId, idMap.get(oldParentId));
}
}
Aggregations