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

com.github.rexsheng.springboot.faster.system.menu.infrastructure.MenuGatewayImpl Maven / Gradle / Ivy

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

import com.github.rexsheng.springboot.faster.system.entity.Menu;
import com.github.rexsheng.springboot.faster.system.entity.table.MenuTableDef;
import com.github.rexsheng.springboot.faster.system.mapper.MenuMapper;
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 com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.row.Db;
import com.mybatisflex.core.update.UpdateChain;
import com.mybatisflex.core.util.UpdateEntity;
import jakarta.annotation.Resource;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;

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

@Repository
@ConditionalOnClass(BaseMapper.class)
public class MenuGatewayImpl implements MenuGateway {

    @Resource
    private MenuMapper menuMapper;

    @Override
    public void insertMenu(SysMenu menu) {
        Menu target=new Menu();
        target.setParentId(menu.getParentId());
        target.setCode(menu.getMenuCode());
        target.setName(menu.getMenuName());
        target.setPath(menu.getMenuPath());
        target.setQuery(menu.getMenuPathQuery());
        target.setOrder(menu.getMenuOrder());
        target.setType(menu.getMenuType());
        target.setIcon(menu.getMenuIcon());
        target.setComponent(menu.getComponent());
        target.setIsVisible(menu.getVisible());
        target.setIsCache(menu.getCache());
        target.setIsFrame(menu.getFrame());
        target.setIsFullscreen(menu.getFullscreen());
        target.setIsTag(menu.getTag());
        target.setStatus(menu.getStatus());
        target.setIsDel(menu.getDel());
        target.setCreateTime(menu.getCreateTime());
        target.setCreateUser(menu.getCreateUserId());
        menuMapper.insert(target);
    }

    @Override
    public List queryMenus(QueryMenuDO query) {
        QueryWrapper queryWrapper=QueryWrapper.create().select()
                .where(MenuTableDef.MENU.IS_DEL.eq(false))
                .orderBy(MenuTableDef.MENU.ORDER,true)
                .orderBy(MenuTableDef.MENU.ID,true)
                ;
        if(query.getStatus()!=null){
            queryWrapper.and(MenuTableDef.MENU.STATUS.eq(query.getStatus()));
        }
        if(StringUtils.hasText(query.getKeyword())){
            queryWrapper.and(MenuTableDef.MENU.NAME.like(query.getKeyword()).or(MenuTableDef.MENU.CODE.like(query.getKeyword())));
        }
        List dataList=menuMapper.selectListByQuery(queryWrapper);
        return dataList.stream().map(this::map).collect(Collectors.toList());
    }

    private SysMenu map(Menu source){
        SysMenu target=new SysMenu();
        target.setMenuId(source.getId());
        target.setMenuCode(source.getCode());
        target.setMenuName(source.getName());
        target.setMenuType(source.getType());
        target.setMenuOrder(source.getOrder());
        target.setMenuIcon(source.getIcon());
        target.setParentId(source.getParentId());
        target.setMenuPath(source.getPath());
        target.setMenuPathQuery(source.getQuery());
        target.setComponent(source.getComponent());
        target.setFrame(source.getIsFrame());
        target.setCache(source.getIsCache());
        target.setVisible(source.getIsVisible());
        target.setFullscreen(source.getIsFullscreen());
        target.setTag(source.getIsTag());
        target.setStatus(source.getStatus());
        target.setCreateTime(source.getCreateTime());
        target.setCreateUserId(source.getCreateUser());
        target.setUpdateTime(source.getUpdateTime());
        target.setUpdateUserId(source.getUpdateUser());
        return target;
    }

    @Override
    public SysMenu getMenu(Integer menuId) {
        Menu entity=menuMapper.selectOneById(menuId);
        return map(entity);
    }

    @Override
    public void updateMenuById(SysMenu menu) {
        Menu entity= UpdateEntity.of(Menu.class,menu.getMenuId());
        entity.setParentId(menu.getParentId());
        entity.setCode(menu.getMenuCode());
        entity.setName(menu.getMenuName());
        entity.setPath(menu.getMenuPath());
        entity.setQuery(menu.getMenuPathQuery());
        entity.setOrder(menu.getMenuOrder());
        entity.setType(menu.getMenuType());
        entity.setIcon(menu.getMenuIcon());
        entity.setComponent(menu.getComponent());
        entity.setIsVisible(menu.getVisible());
        entity.setIsCache(menu.getCache());
        entity.setIsFrame(menu.getFrame());
        entity.setIsFullscreen(menu.getFullscreen());
        entity.setIsTag(menu.getTag());
        entity.setUpdateTime(menu.getUpdateTime());
        entity.setUpdateUser(menu.getUpdateUserId());
        menuMapper.update(entity);
    }

    @Override
    public void updateMenuStatus(List menus) {
        Db.executeBatch(menus, 100, MenuMapper.class
                , (mapper, row) -> {
                    UpdateChain.of(mapper)
                            .set(Menu::getStatus, row.getStatus())
                            .set(Menu::getUpdateTime,row.getUpdateTime())
                            .set(Menu::getUpdateUser,row.getUpdateUserId())
                            .where(Menu::getId).eq(row.getMenuId())
                            .update();
                });
    }

    @Override
    public void deleteMenus(List menus) {
        Db.executeBatch(menus, 100, MenuMapper.class
                , (mapper, row) -> {
                    UpdateChain.of(mapper)
                            .set(Menu::getIsDel, row.getDel())
                            .set(Menu::getUpdateTime,row.getUpdateTime())
                            .set(Menu::getUpdateUser,row.getUpdateUserId())
                            .where(Menu::getId).eq(row.getMenuId())
                            .update();
                });
    }

    @Override
    public long queryCodeCount(QueryMenuDO query) {
        QueryWrapper queryWrapper=QueryWrapper.create().select()
                .where(MenuTableDef.MENU.IS_DEL.eq(false));
        if(StringUtils.hasText(query.getMenuCode())){
            queryWrapper.and(MenuTableDef.MENU.CODE.eq(query.getMenuCode()));
        }
        if(query.getMenuId()!=null){
            queryWrapper.and(MenuTableDef.MENU.ID.ne(query.getMenuId()));
        }
        return menuMapper.selectCountByQuery(queryWrapper);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy