| package com.mzl.flower.service.system; | 
|   | 
| import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
| import com.mzl.flower.constant.Constants; | 
| import com.mzl.flower.dto.request.system.CreateMenuDTO; | 
| import com.mzl.flower.dto.request.system.UpdateMenuDTO; | 
| import com.mzl.flower.dto.response.system.MenuDTO; | 
| import com.mzl.flower.dto.response.system.MenuTreeDTO; | 
| import com.mzl.flower.entity.system.Menu; | 
| import com.mzl.flower.mapper.system.MenuMapper; | 
| import com.mzl.flower.service.BaseService; | 
| import com.mzl.flower.utils.TreeBuilderUtil; | 
| import com.mzl.flower.utils.UUIDGenerator; | 
| import org.springframework.beans.BeanUtils; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.stereotype.Service; | 
| import org.springframework.transaction.annotation.Transactional; | 
|   | 
| import java.util.List; | 
|   | 
| @Service | 
| @Transactional | 
| public class MenuService extends BaseService { | 
|     @Autowired | 
|     private MenuMapper menuMapper; | 
|   | 
|     public Menu getMenu(String id) { | 
|         return menuMapper.selectById(id); | 
|     } | 
|   | 
|     public void addMenu(CreateMenuDTO dto) { | 
|         Menu menu = new Menu(); | 
|         BeanUtils.copyProperties(dto, menu); | 
|         menu.setId(UUIDGenerator.getUUID()); | 
|         menu.setIsVisible(Constants.Y); | 
|         menu.setStatus(Constants.STATUS_ACTIVE); | 
|   | 
|         menuMapper.insert(menu); | 
|     } | 
|   | 
|     public List<MenuTreeDTO> searchOperationMenu() { | 
|         List<MenuTreeDTO> treeList = menuMapper.selectListOrderBySeq(); | 
|         for (MenuTreeDTO menuTreeDTO : treeList) { | 
|             menuTreeDTO.setLabel(menuTreeDTO.getMenuName()); | 
|             menuTreeDTO.setPath(menuTreeDTO.getMenuHref()); | 
|             menuTreeDTO.setName(menuTreeDTO.getMenuName()); | 
|         } | 
|         treeList = (List<MenuTreeDTO>) TreeBuilderUtil.buildListToTree(treeList); | 
|         return treeList; | 
|     } | 
|   | 
|     public MenuDTO getMenuDetail(String id) { | 
|         Menu menu = getMenu(id); | 
|   | 
|         //返回对象 | 
|         MenuDTO menuDTO = new MenuDTO(); | 
|         if (menu != null) { | 
|             BeanUtils.copyProperties(menu, menuDTO); | 
|         } | 
|         return menuDTO; | 
|     } | 
|   | 
|     public void updateMenu(UpdateMenuDTO dto) { | 
|         Menu menu = getMenu(dto.getId()); | 
|         BeanUtils.copyProperties(dto, menu); | 
|         menuMapper.updateById(menu); | 
|     } | 
|   | 
|     public void deleteMenu(String id) { | 
|         Menu menu = getMenu(id); | 
|         menu.setStatus(Constants.STATUS_DELETED); | 
|         menuMapper.updateById(menu); | 
|   | 
|         List<Menu> menus = menuMapper.selectList(new QueryWrapper<Menu>().eq("PARENT_ID", id)); | 
|         if (menus != null && menus.size() > 0) { | 
|             for (Menu children : menus) { | 
|                 deleteMenu(children.getId()); | 
|             } | 
|         } | 
|     } | 
| } |