package com.cool.store.dao;

import com.cool.store.constants.CommonConstants;
import com.cool.store.entity.SysMenuDO;
import com.cool.store.mapper.SysMenuMapper;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zhangchenbiao
 * @FileName: SysMenuDAO
 * @Description:
 * @date 2023-06-08 16:41
 */
@Repository
public class SysMenuDAO {

    @Resource
    private SysMenuMapper sysMenuMapper;

    public List<SysMenuDO> selectMenuAll(List<Long> parentIds){
        return sysMenuMapper.selectMenuAll(parentIds);
    }

    public Long addMenu(SysMenuDO param){
        Integer sort = sysMenuMapper.selectMaxSort();
        param.setSort(sort + 1);
        sysMenuMapper.insertSelective(param);
        return param.getId();
    }

    /**
     * 批量删除
     * @param idList
     * @return
     */
    public Integer batchDeleteMenu(List<Long> idList){
        if(CollectionUtils.isEmpty(idList)){
            return CommonConstants.ZERO;
        }
        return sysMenuMapper.batchDeleteMenu(idList);
    }

    public Integer batchUpdateMenu(List<SysMenuDO> updateList) {
        if(CollectionUtils.isEmpty(updateList)){
            return CommonConstants.ZERO;
        }
        return sysMenuMapper.batchUpdateMenu(updateList);
    }
}
