package com.service.schoolhome;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import com.utils.CommonUtils;

import java.util.ArrayList;
import java.util.List;

public class BookRecommendService {
    public static final BookRecommendService me = new BookRecommendService();

    public Page<Record> bookNew(int pageNumber, int pagesize,Integer orgid) {
        String select = "SELECT b.title,b.author,b.publisher,b.typecode,b.imgurl ";
        StringBuilder where = new StringBuilder(" FROM t_schoolbookrecommend a LEFT JOIN t_book b ON a.bookid = b.id " +
                " WHERE a.flag = 0 AND a.deletestatus = 0 ");
        List list = new ArrayList();
        if(orgid > 0){
            where.append(" AND a.orgid = ? ");
            list.add(orgid);
        }
        return Db.paginate(pageNumber, pagesize,select,where.toString(),CommonUtils.listToArray(list));
    }

    public Page<Record> bookHot(int pageNumber, int pagesize, Integer orgid) {
        String select = "SELECT b.title,b.author,b.publisher,b.typecode,b.imgurl ";
        StringBuilder where = new StringBuilder(" FROM t_schoolbookrecommend a LEFT JOIN t_book b ON a.bookid = b.id " +
                " WHERE a.flag = 1 AND a.deletestatus = 0 ");
        List list = new ArrayList();
        if(orgid > 0){
            where.append(" AND a.orgid = ? ");
            list.add(orgid);
        }
        return Db.paginate(pageNumber, pagesize,select,where.toString(),CommonUtils.listToArray(list));
    }
}
