use of com.hccake.ballcat.system.model.entity.SysDictItem in project ballcat by ballcat-projects.
the class SysDictManager method removeDictItemById.
/**
* 删除字典项
* @param id 字典项
* @return 执行是否成功
*/
@Transactional(rollbackFor = Exception.class)
public boolean removeDictItemById(Integer id) {
// 根据ID查询字典
SysDictItem dictItem = sysDictItemService.getById(id);
String dictCode = dictItem.getDictCode();
// 更新字典项Hash值
if (!sysDictService.updateHashCode(dictCode)) {
return false;
}
boolean result = sysDictItemService.removeById(id);
if (result) {
eventPublisher.publishEvent(new DictChangeEvent(dictCode));
}
return true;
}
use of com.hccake.ballcat.system.model.entity.SysDictItem in project ballcat by ballcat-projects.
the class SysDictManager method queryDictDataAndHashVO.
/**
* 查询字典数据
* @param dictCodes 字典标识
* @return DictDataAndHashVO
*/
public List<DictDataVO> queryDictDataAndHashVO(String[] dictCodes) {
List<DictDataVO> list = new ArrayList<>();
// 查询对应hash值,以及字典项数据
List<SysDict> sysDictList = sysDictService.listByCodes(dictCodes);
if (CollectionUtil.isNotEmpty(sysDictList)) {
for (SysDict sysDict : sysDictList) {
List<SysDictItem> dictItems = sysDictItemService.listByDictCode(sysDict.getCode());
// 排序并转换为VO
List<DictItemVO> setDictItems = dictItems.stream().sorted(Comparator.comparingInt(SysDictItem::getSort)).map(SysDictItemConverter.INSTANCE::poToItemVo).collect(Collectors.toList());
// 组装DataVO
DictDataVO dictDataVO = new DictDataVO();
dictDataVO.setValueType(sysDict.getValueType());
dictDataVO.setDictCode(sysDict.getCode());
dictDataVO.setHashCode(sysDict.getHashCode());
dictDataVO.setDictItems(setDictItems);
list.add(dictDataVO);
}
}
return list;
}
use of com.hccake.ballcat.system.model.entity.SysDictItem in project ballcat by ballcat-projects.
the class SysDictManager method updateDictItemStatusById.
/**
* 更新字典项状态
* @param itemId 字典项id
*/
@Transactional(rollbackFor = Exception.class)
public void updateDictItemStatusById(Integer itemId, Integer status) {
// 获取字典项
SysDictItem dictItem = sysDictItemService.getById(itemId);
Assert.notNull(dictItem, () -> new BusinessException(BaseResultCode.LOGIC_CHECK_ERROR.getCode(), "错误的字典项 id:" + itemId));
// 更新字典项状态
SysDictItem entity = new SysDictItem();
entity.setId(itemId);
entity.setStatus(status);
Assert.isTrue(sysDictItemService.updateById(entity), () -> new BusinessException(BaseResultCode.UPDATE_DATABASE_ERROR.getCode(), "字典项状态更新异常"));
// 更新字典 hash
String dictCode = dictItem.getDictCode();
Assert.isTrue(sysDictService.updateHashCode(dictCode), () -> new BusinessException(BaseResultCode.UPDATE_DATABASE_ERROR.getCode(), "字典 Hash 更新异常"));
// 发布字典更新事件
eventPublisher.publishEvent(new DictChangeEvent(dictCode));
}
Aggregations