package io.renren.modules.sys.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.sys.dao.SysDepartmentDao;
import io.renren.modules.sys.entity.SysConfigEntity;
import io.renren.modules.sys.entity.SysDepartmentEntity;
import io.renren.modules.sys.service.SysDepartmentService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 * 部门管理业务层
 * </p>
 *
 * @author yinhao
 * @date 2021/6/9 14:35
 */
@Service
public class SysDepartmentServiceImpl extends ServiceImpl<SysDepartmentDao, SysDepartmentEntity> implements SysDepartmentService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        String keyword = (String)params.get("keyword");

        QueryWrapper<SysDepartmentEntity> queryWrapper = new QueryWrapper<>();

        if (StringUtils.isNotEmpty(keyword)) {
            queryWrapper.and(q -> q.like("department_name",keyword)
                    .or().like("department_code",keyword));
        }

        IPage<SysDepartmentEntity> page = this.page(new Query<SysDepartmentEntity>().getPage(params), queryWrapper);

        return new PageUtils(page);
    }

}
