package com.iailab.module.data.plan.category.service.impl;
|
|
import com.iailab.framework.common.util.object.BeanUtils;
|
import com.iailab.framework.mybatis.core.query.LambdaQueryWrapperX;
|
import com.iailab.module.data.plan.category.dao.PlanItemCategoryDao;
|
import com.iailab.module.data.plan.category.entity.PlanItemCategoryEntity;
|
import com.iailab.module.data.plan.category.service.PlanItemCategoryService;
|
import com.iailab.module.data.plan.category.vo.PlanItemCategoryReqVO;
|
import com.iailab.module.data.plan.category.vo.PlanItemCategorySaveReqVO;
|
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.data.plan.category.entity.PlanItemCategoryEntity.ID_ROOT;
|
import static com.iailab.module.system.enums.ErrorCodeConstants.MENU_PARENT_ERROR;
|
import static com.iailab.module.system.enums.ErrorCodeConstants.MENU_PARENT_NOT_EXISTS;
|
|
/**
|
* @author PanZhibao
|
* @Description
|
* @createTime 2024年11月01日
|
*/
|
@Service
|
@Slf4j
|
public class PlanItemCategoryServiceImpl implements PlanItemCategoryService {
|
|
@Resource
|
private PlanItemCategoryDao planItemCategoryDao;
|
|
@Override
|
public List<PlanItemCategoryEntity> getList(PlanItemCategoryReqVO reqVO) {
|
return planItemCategoryDao.selectList(reqVO);
|
}
|
|
@Override
|
public List<PlanItemCategoryEntity> getSimpleList() {
|
return planItemCategoryDao.selectList(new LambdaQueryWrapperX<PlanItemCategoryEntity>());
|
}
|
|
@Override
|
public void create(PlanItemCategorySaveReqVO createReqVO) {
|
// 校验父菜单存在
|
validateParentMenu(createReqVO.getPid(), null);
|
|
// 插入数据库
|
PlanItemCategoryEntity entity = BeanUtils.toBean(createReqVO, PlanItemCategoryEntity.class);
|
entity.setId(UUID.randomUUID().toString());
|
entity.setCreateTime(new Date());
|
planItemCategoryDao.insert(entity);
|
}
|
|
@Override
|
public void update(PlanItemCategorySaveReqVO updateReqVO) {
|
// 校验父菜单存在
|
validateParentMenu(updateReqVO.getPid(), null);
|
PlanItemCategoryEntity entity = BeanUtils.toBean(updateReqVO, PlanItemCategoryEntity.class);
|
entity.setUpdateTime(new Date());
|
planItemCategoryDao.updateById(entity);
|
}
|
|
@Override
|
public PlanItemCategoryEntity get(String id) {
|
return planItemCategoryDao.selectById(id);
|
}
|
|
@Override
|
public void delete(String id) {
|
planItemCategoryDao.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);
|
}
|
PlanItemCategoryEntity category = planItemCategoryDao.selectById(parentId);
|
// 父菜单不存在
|
if (category == null) {
|
throw exception(MENU_PARENT_NOT_EXISTS);
|
}
|
}
|
}
|