package com.controller;

import com.config.BaseController;
import com.config.ControllerInterface;
import com.jfinal.aop.Clear;
import com.jfinal.plugin.activerecord.Db;
import com.service.BookTypeService;

/**
 * 五大类
 * 2018-10-22
 * zj
 */
@ControllerInterface(path="/booktype")
public class BookTypeController extends BaseController {
    BookTypeService service = BookTypeService.me;
    public void index() {
        render("/view/index/index.html");
    }

    public void list(){
        try{
            String type = this.getPara("type");
            success(service.paginate(this.getParaToInt("pageNumber"),this.getParaToInt("pageSize"),type));
        }catch(Exception e){
            e.printStackTrace();
            fail();
        }
    }

    /**
     * 获取22大类数据
     */
    public void find22Type(){
        success(Db.find("select id parentid, name,1 childnode from t_booktype where parentid in ('1','2','3','4','5') and LENGTH(id) = 1"));
    }

    /**
     * 根据父节点查询子节点
     */
    public void findByParentId(){
        String parentid = this.getPara("parentid");
        reData(Db.find("select id,name,if((select count(1) from t_booktype s where s.parentid = p.id)>0,true,false) childnode from t_booktype p where parentid = ?",parentid));
    }

}
