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

com.didiglobal.logi.security.dao.impl.DeptDaoImpl Maven / Gradle / Ivy

The newest version!
package com.didiglobal.logi.security.dao.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.didiglobal.logi.security.common.entity.dept.Dept;
import com.didiglobal.logi.security.common.entity.dept.DeptBrief;
import com.didiglobal.logi.security.common.po.DeptPO;
import com.didiglobal.logi.security.dao.DeptDao;
import com.didiglobal.logi.security.dao.mapper.DeptMapper;
import com.didiglobal.logi.security.util.CopyBeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

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

/**
 * @author cjm
 */
@Component
public class DeptDaoImpl extends BaseDaoImpl implements DeptDao {

    @Autowired
    private DeptMapper deptMapper;

    private QueryWrapper wrapBriefQuery() {
        QueryWrapper queryWrapper = getQueryWrapper();
        queryWrapper.select(
                FieldConstant.ID, FieldConstant.DEPT_NAME,
                FieldConstant.LEAF, FieldConstant.LEVEL, FieldConstant.PARENT_ID
        );
        return queryWrapper;
    }

    @Override
    public List selectAllAndAscOrderByLevel() {
        QueryWrapper queryWrapper = getQueryWrapper();
        queryWrapper.orderByAsc(FieldConstant.LEVEL);
        return CopyBeanUtil.copyList(deptMapper.selectList(queryWrapper), Dept.class);
    }

    @Override
    public List selectIdListByLikeDeptName(String deptName) {
        QueryWrapper queryWrapper = getQueryWrapper();
        queryWrapper
                .select(FieldConstant.ID)
                .like(!StringUtils.isEmpty(deptName), FieldConstant.DEPT_NAME, deptName);
        List deptIdList = deptMapper.selectObjs(queryWrapper);
        return deptIdList.stream().map(Integer.class::cast).collect(Collectors.toList());
    }

    @Override
    public DeptBrief selectBriefByDeptId(Integer deptId) {
        QueryWrapper queryWrapper = wrapBriefQuery();
        queryWrapper.eq(FieldConstant.ID, deptId);
        return CopyBeanUtil.copy(deptMapper.selectOne(queryWrapper), DeptBrief.class);
    }

    @Override
    public List selectAllDeptIdList() {
        QueryWrapper queryWrapper = getQueryWrapper();
        queryWrapper.select(FieldConstant.ID);
        List deptIdList = deptMapper.selectObjs(queryWrapper);
        return deptIdList.stream().map(Integer.class::cast).collect(Collectors.toList());
    }

    @Override
    public List selectIdListByParentId(Integer deptId) {
        QueryWrapper queryWrapper = getQueryWrapper();
        queryWrapper.select(FieldConstant.ID).eq(FieldConstant.PARENT_ID, deptId);
        List deptIdList = deptMapper.selectObjs(queryWrapper);
        return deptIdList.stream().map(Integer.class::cast).collect(Collectors.toList());
    }

    @Override
    public void insertBatch(List deptList) {
        if(CollectionUtils.isEmpty(deptList)) {
            return;
        }
        List deptPOList = CopyBeanUtil.copyList(deptList, DeptPO.class);
        for(DeptPO deptPO : deptPOList) {
            deptMapper.insert(deptPO);
        }

    }
}