package io.modules.item.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import io.modules.item.dao.ArticleDao;
import io.modules.item.dto.ArticleDTO;
import io.modules.item.entity.ArticleEntity;
import io.modules.item.service.ArticleService;
import cn.hutool.core.util.StrUtil;
import io.common.service.impl.CrudServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 文章表
 */
@Service
public class ArticleServiceImpl extends CrudServiceImpl<ArticleDao, ArticleEntity, ArticleDTO> implements ArticleService {

    @Override
    public QueryWrapper<ArticleEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");
        String type = (String)params.get("type");
        Long userId = (Long)params.get("userId");
        String audit = (String)params.get("audit");

        QueryWrapper<ArticleEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StrUtil.isNotBlank(id), "id", id);
        wrapper.eq(StrUtil.isNotBlank(type), "type", type);
        wrapper.eq(StrUtil.isNotBlank(audit), "audit", audit);
        if (userId != null){
            wrapper.eq("user_id", userId);
        }

        return wrapper;
    }



}
