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); } } }