package com.ema.admin.modules.system.service.impl;

import cn.hutool.core.util.StrUtil;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.ema.admin.modules.system.entity.SysDictData;
import com.ema.admin.modules.system.mapper.SysDictDataMapper;
import com.ema.admin.modules.system.service.SysDictDataService;
import com.ema.admin.modules.system.vo.SysDictDataQueryVo;
import org.springframework.stereotype.Service;

/**
 * 系统字典值表 服务层实现。
 *
 * @author lijian
 * @since 2025-07-31
 */
@Service
public class SysDictDataServiceImpl extends ServiceImpl<SysDictDataMapper, SysDictData>  implements SysDictDataService {

    @Override
    public Page<SysDictData> page(SysDictDataQueryVo queryVo) {
        QueryWrapper queryWrapper = QueryWrapper.create();
        queryWrapper.eq(SysDictData::getTypeCode, queryVo.getTypeCode(), StrUtil.isNotBlank(queryVo.getTypeCode()));
        queryWrapper.like(SysDictData::getValue, queryVo.getValue(), StrUtil.isNotBlank(queryVo.getValue()));
        queryWrapper.like(SysDictData::getCode, queryVo.getCode(), StrUtil.isNotBlank(queryVo.getCode()));
        queryWrapper.eq(SysDictData::getStatus, queryVo.getStatus(), queryVo.getStatus() != null);
        queryWrapper.orderBy(SysDictData::getSort);
        return this.page( new Page<>(queryVo.getPageNumber(), queryVo.getPageSize()),queryWrapper);
    }

    @Override
    public SysDictData getByCode(String dictTypeCode, String dictCode) {
        return this.queryChain()
                .eq(SysDictData::getTypeCode, dictTypeCode)
                .eq(SysDictData::getCode, dictCode).one();
    }
}
