package com.service;

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

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SchoolBookRecommendService {

    public static final SchoolBookRecommendService me = new SchoolBookRecommendService();

    Schoolbookrecommend dao = new Schoolbookrecommend().dao();

    public List<Schoolbookrecommend> list(Integer type){
        String sql ="SELECT * FROM t_dict where type=?";
        return  dao.find(sql,type);
    }

    public Page<Record> findListByType(int type, int orgid,int pageNumber, int pageSize) {
        List paramList = new ArrayList();
        paramList.add(type);
        paramList.add(orgid);
        String select = "select s.*,b.title,b.isbn,b.author,b.publisher";
        StringBuffer sql = new StringBuffer();
        sql.append(" from t_schoolbookrecommend s inner join t_book b on s.bookid=b.id where s.deletestatus != 1 and s.flag = ? and s.orgid=?");
        sql.append(" order by s.createtime desc");
        Page<Record> page = Db.paginate(pageNumber,pageSize,select,sql.toString(),CommonUtils.listToArray(paramList));
        return page;
    }

    public void deleteBookRecommend(int type,int id,int orgid){
        Db.update("update t_schoolbookrecommend set deletestatus=1 where orgid=? and flag=? and id=?",orgid,type,id);
    }
}
