package com.controller.librarycatalog;

import com.config.BaseController;
import com.config.ControllerInterface;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.model.Book;
import com.service.BookService;
import com.utils.CommonUtils;

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


@ControllerInterface(path="/libraryCatalog")
public class LibraryCatalogController extends BaseController {

    BookService service = BookService.me;

    /**
     * 馆藏查询接口
     */
    public void findBookList(){
        Book bean = getBean(Book.class,"");
        success(service.paginate(this.getParaToInt("pageNumber"),this.getParaToInt("pageSize"),this.getParaToInt("pageSize",PAGESIZE),null,bean,  "1","",null,null));
    }

    /**
     * 查询详情接口
     */
    public void findBookDetailList(){
        if(CommonUtils.isNullOrEmpty(getPara("orgid")) || CommonUtils.isNullOrEmpty(getPara("bookid"))) {
            fail(1,"参数不能为空");
            return;
        }
        int orgid = getParaToInt("orgid");
        int bookid = getParaToInt("bookid");
        Record record = Db.findFirst("select title,author,publisher,publishdate from t_book where id = ? and orgid = ?",bookid,orgid);
        List list = Db.find("select barcode,l.library,status from t_book_detail d left join t_library l on d.libraryid = l.id where bookid = ?",bookid);
        Map map = new HashMap();
        map.put("bookinfo",record);
        map.put("bookDetailList",list);
        success(map);
    }
}
