package com.huiju.estateagents.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.huiju.estateagents.common.CommConstant;
import com.huiju.estateagents.common.StringUtils;
import com.huiju.estateagents.entity.*;
import com.huiju.estateagents.mapper.TpNewsMapper;
import com.huiju.estateagents.service.*;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 资讯表  服务实现类
 * </p>
 *
 * @author jobob
 * @since 2019-07-25
 */
@Service
public class TpNewsServiceImpl extends ServiceImpl<TpNewsMapper, TpNews> implements ITpNewsService {

    @Override
    public IPage<TpNews> getListBy(IPage<TpNews> page, Integer orgId, String newsName, Integer status,String newsTypeId) {
        QueryWrapper<TpNews> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("org_id", orgId);
        queryWrapper.eq(!StringUtils.isEmpty(newsTypeId),"news_type_id", newsTypeId);
        queryWrapper.eq(status != null, "status", status);
        queryWrapper.gt(status == null, "status", CommConstant.STATUS_DELETE);
        queryWrapper.like(!StringUtils.isEmpty(newsName), "news_name", "%" + newsName + "%");
        queryWrapper.orderByDesc("weight");
        queryWrapper.orderByDesc("create_date");

        return page(page, queryWrapper);
    }
}
