package com.gkhy.safePlatform.account.service.baseService.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.gkhy.safePlatform.account.entity.user.MenuInfo; import com.gkhy.safePlatform.account.entity.user.MenuInfoDO; import com.gkhy.safePlatform.account.enums.MenuStatusEnum; import com.gkhy.safePlatform.commons.enums.ResultCodes; import com.gkhy.safePlatform.commons.exception.BusinessException; import com.gkhy.safePlatform.account.repository.MenuInfoRepository; import com.gkhy.safePlatform.account.service.baseService.MenuInfoService; import com.gkhy.safePlatform.commons.utils.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; @Service("menuInfoService") public class MenuInfoServiceImpl extends ServiceImpl implements MenuInfoService { @Autowired private MenuInfoRepository menuInfoRepository; @Override public List getAllMenu() { return menuInfoRepository.getAllMenu(); } @Override public void saveMenu(MenuInfo menu) { int i = menuInfoRepository.insertMenu(menu); if (i != 1) { throw new BusinessException(ResultCodes.SERVER_ADD_ERROR); } } @Override public void updateMenu(MenuInfo menu) { if (menu.getId() == null) { throw new BusinessException(ResultCodes.SERVER_PARAM_NULL); } int i = menuInfoRepository.updateMenu(menu); if (i == 0) { throw new BusinessException(ResultCodes.SERVER_UPDATE_DATA_NO_CHANGE); } if (i > 1) { throw new BusinessException(ResultCodes.SERVER_ADD_ERROR); } } @Override public MenuInfo getMenuById(Long id) { if (id == null) { throw new BusinessException(ResultCodes.SERVER_PARAM_NULL); } return menuInfoRepository.getMenuById(id); } @Override public Long countByParentId(Long parentMenuId) { if (parentMenuId == null) { throw new BusinessException(ResultCodes.SERVER_PARAM_NULL); } return menuInfoRepository.selectCount(new LambdaQueryWrapper() // 父id = parentMenuId .eq(MenuInfo::getParentId,parentMenuId) // 状态 .eq(MenuInfo::getStatus, MenuStatusEnum.ENABLED.getCode())); } @Override public MenuInfo getMenuInfoByName(String name) { if (StringUtils.isBlank(name)) { throw new BusinessException(ResultCodes.SERVER_PARAM_NULL); } List menuInfos = menuInfoRepository.selectList(new LambdaQueryWrapper() // name .eq(MenuInfo::getName, name) // 状态 .eq(MenuInfo::getStatus, MenuStatusEnum.ENABLED.getCode())); if (menuInfos.size() == 0) { return null; } if (menuInfos.size() > 1) { throw new BusinessException(ResultCodes.SERVER_DATABASE_DATA_DUPLICATED); } return menuInfos.get(0); } @Override public MenuInfo getMenuInfoByPath(String path) { if (StringUtils.isBlank(path)) { throw new BusinessException(ResultCodes.SERVER_PARAM_NULL); } List menuInfos = menuInfoRepository.selectList(new LambdaQueryWrapper() // path .eq(MenuInfo::getPath, path) // 状态 .eq(MenuInfo::getStatus, MenuStatusEnum.ENABLED.getCode())); if (menuInfos.size() == 0) { return null; } if (menuInfos.size() > 1) { throw new BusinessException(ResultCodes.SERVER_DATABASE_DATA_DUPLICATED); } return menuInfos.get(0); } @Override public MenuInfo getMenuInfoByComponent(String component) { if (StringUtils.isBlank(component)) { throw new BusinessException(ResultCodes.SERVER_PARAM_NULL); } List menuInfos = menuInfoRepository.selectList(new LambdaQueryWrapper() // path .eq(MenuInfo::getComponent, component) // 状态 .eq(MenuInfo::getStatus, MenuStatusEnum.ENABLED.getCode()) // 父id 不为空 .isNotNull(MenuInfo::getParentId)); if (menuInfos.size() == 0) { return null; } if (menuInfos.size() > 1) { throw new BusinessException(ResultCodes.SERVER_DATABASE_DATA_DUPLICATED); } return menuInfos.get(0); } }