package com.chushang.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.chushang.common.mybatis.page.CommonParam;
import com.chushang.common.mybatis.utils.PageResult;
import com.chushang.system.entity.dto.ListDictDTO;
import com.chushang.system.entity.po.SysDictData;
import com.chushang.system.entity.po.SysDictType;
import com.chushang.system.mapper.SysDictTypeMapper;
import com.chushang.system.service.ISysDictTypeService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @auther: zhao
 * @date: 2024/5/9 17:57
 */
@Slf4j
@Service
public class SysDictTypeServiceImpl extends ServiceImpl<SysDictTypeMapper, SysDictType> implements ISysDictTypeService {
    @Override
    public PageResult pageDictTypeList(SysDictType dictType, CommonParam commonParam) {
        IPage<SysDictType> page = this.page(
                new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(commonParam.getPage(), commonParam.getLimit()),
                buildWrapper(dictType, commonParam)
        );
        return new PageResult(page);
    }

    public LambdaQueryWrapper<SysDictType> buildWrapper(SysDictType dictType, CommonParam commonParam) {
        return new QueryWrapper<SysDictType>()
                .orderBy(true, "asc".equals(commonParam.getIsAsc()), commonParam.getOrderBy())
                .lambda()
                .eq(null != dictType.getDictId(), SysDictType::getDictId, dictType.getDictId())
                .eq(StringUtils.isNotEmpty(dictType.getDictType()), SysDictType::getDictType, dictType.getDictType())
                .eq(StringUtils.isNotEmpty(dictType.getDictName()), SysDictType::getDictName, dictType.getDictName())
                .eq(null != dictType.getStatus(), SysDictType::getStatus, dictType.getStatus());
    }
}
