package com.mosty.common.config.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mosty.common.config.entity.SysDict;
import com.mosty.common.config.entity.vo.DictPage;
import com.mosty.common.config.mapper.SysDictMapper;
import com.mosty.common.config.service.SysDictService;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 字典类别配置表 服务实现类
 * </p>
 *
 * @author kevin
 * @since 2022-02-09
 */
@Service
@AllArgsConstructor
public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> implements SysDictService {

    private final SysDictMapper sysDictMapper;

    @Override
    public IPage<SysDict> selectByPage(DictPage page) {
        QueryWrapper<SysDict> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(page.getDictName())) {
            queryWrapper.and(wrapper -> wrapper.like("zdmc", page.getDictName()));
        }
        if (StringUtils.isNotBlank(page.getDictCode())) {
            queryWrapper.and(wrapper -> wrapper.like("zdbh", page.getDictCode()));
        }
        if (page.getXtZxbz() != null) {
            queryWrapper.and(wrapper -> wrapper.eq("xt_zxbz", page.getXtZxbz()));
        }
        return getBaseMapper().selectPage(page, queryWrapper);
    }

}
