All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.rexsheng.springboot.faster.system.menu.application.MenuServiceImpl Maven / Gradle / Ivy

The newest version!
package com.github.rexsheng.springboot.faster.system.menu.application;

import com.github.rexsheng.springboot.faster.system.menu.application.dto.*;
import com.github.rexsheng.springboot.faster.system.menu.domain.SysMenu;
import com.github.rexsheng.springboot.faster.system.menu.domain.gateway.MenuGateway;
import com.github.rexsheng.springboot.faster.system.menu.domain.gateway.QueryMenuDO;
import jakarta.annotation.Resource;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.List;
import java.util.stream.Collectors;

@Service
@ConditionalOnClass({SqlSessionFactoryBean.class})
public class MenuServiceImpl implements MenuService{

    @Resource
    private MenuGateway menuGateway;

    @Override
    public void add(AddMenuRequest request) {
        SysMenu menu=request.toMenu();
        menuGateway.insertMenu(menu);
    }

    @Override
    public List queryList(QueryMenuRequest request) {
        QueryMenuDO queryMenuDO=new QueryMenuDO();
        queryMenuDO.setStatus(request.getStatus());
        queryMenuDO.setKeyword(request.getMenuName());
        List menuList=menuGateway.queryMenus(queryMenuDO);
        if(Boolean.TRUE.equals(request.getExcludeNonParent())){
            List sources=menuList.stream()
                    .filter(source->source.getParentId()==null || menuList.stream().anyMatch(a->a.getMenuId().equals(source.getParentId())))
                    .collect(Collectors.toList());
            return SysMenu.mapTree(sources).stream().map(MenuDetailResponse::of).collect(Collectors.toList());
        }
        return SysMenu.mapTree(menuList).stream().map(MenuDetailResponse::of).collect(Collectors.toList());
    }

    @Override
    public MenuDetailResponse get(Integer id) {
        SysMenu menu= menuGateway.getMenu(id);
        Assert.notNull(menu,"菜单不存在");
        return MenuDetailResponse.of(menu);
    }

    @Override
    public void update(UpdateMenuRequest request) {
        SysMenu menu=request.toMenu();
        menuGateway.updateMenuById(menu);
    }

    @Override
    public void updateStatus(List request) {
        List menuList=request.stream().map(UpdateMenuRequest::toMenu).collect(Collectors.toList());
        menuGateway.updateMenuStatus(menuList);
    }

    @Override
    public void delete(List ids) {
        menuGateway.deleteMenus(SysMenu.of(ids,true));
    }

    @Override
    public Boolean validCode(ValidateMenuCodeRequest request) {
        SysMenu menu=request.toMenu();
        QueryMenuDO query=new QueryMenuDO();
        query.setMenuId(menu.getMenuId());
        query.setMenuCode(menu.getMenuCode());
        return menuGateway.queryCodeCount(query)==0L;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy