package com.iailab.module.data.ind.category.service.impl;
|
|
import com.iailab.framework.common.util.object.BeanUtils;
|
import com.iailab.framework.mybatis.core.query.LambdaQueryWrapperX;
|
import com.iailab.module.data.ind.category.entity.IndItemCategoryEntity;
|
import com.iailab.module.data.ind.category.service.IndItemCategoryService;
|
import com.iailab.module.data.ind.category.vo.IndItemCategoryReqVO;
|
import com.iailab.module.data.ind.category.dao.IndItemCategoryDao;
|
import com.iailab.module.data.ind.category.vo.IndItemCategorySaveReqVO;
|
import com.iailab.module.system.enums.permission.MenuTypeEnum;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.UUID;
|
|
import static com.iailab.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static com.iailab.module.system.enums.ErrorCodeConstants.*;
|
import static com.iailab.module.data.ind.category.entity.IndItemCategoryEntity.ID_ROOT;
|
|
/**
|
* @author PanZhibao
|
* @Description
|
* @createTime 2024年09月10日
|
*/
|
@Service
|
@Slf4j
|
public class IndItemCategoryServiceImpl implements IndItemCategoryService {
|
|
@Resource
|
private IndItemCategoryDao indItemCategoryDao;
|
|
@Override
|
public List<IndItemCategoryEntity> getList(IndItemCategoryReqVO reqVO) {
|
return indItemCategoryDao.selectList(reqVO);
|
}
|
|
@Override
|
public List<IndItemCategoryEntity> getSimpleList() {
|
return indItemCategoryDao.selectList(new LambdaQueryWrapperX<IndItemCategoryEntity>());
|
}
|
|
@Override
|
public void create(IndItemCategorySaveReqVO createReqVO) {
|
// 校验父菜单存在
|
validateParentMenu(createReqVO.getPid(), null);
|
|
// 插入数据库
|
IndItemCategoryEntity entity = BeanUtils.toBean(createReqVO, IndItemCategoryEntity.class);
|
entity.setId(UUID.randomUUID().toString());
|
entity.setCreateTime(new Date());
|
indItemCategoryDao.insert(entity);
|
}
|
|
@Override
|
public void update(IndItemCategorySaveReqVO updateReqVO) {
|
// 校验父菜单存在
|
validateParentMenu(updateReqVO.getPid(), null);
|
IndItemCategoryEntity entity = BeanUtils.toBean(updateReqVO, IndItemCategoryEntity.class);
|
entity.setUpdateTime(new Date());
|
indItemCategoryDao.updateById(entity);
|
}
|
|
@Override
|
public IndItemCategoryEntity get(String id) {
|
return indItemCategoryDao.selectById(id);
|
}
|
|
@Override
|
public void delete(String id) {
|
indItemCategoryDao.deleteById(id);
|
}
|
|
private void validateParentMenu(String parentId, String childId) {
|
if (parentId == null || ID_ROOT.equals(parentId)) {
|
return;
|
}
|
// 不能设置自己为父菜单
|
if (parentId.equals(childId)) {
|
throw exception(MENU_PARENT_ERROR);
|
}
|
IndItemCategoryEntity category = indItemCategoryDao.selectById(parentId);
|
// 父菜单不存在
|
if (category == null) {
|
throw exception(MENU_PARENT_NOT_EXISTS);
|
}
|
}
|
}
|