package com.jfinal.club._admin.ques;

import com.jfinal.club.common.model.Questions;
import com.jfinal.plugin.activerecord.Page;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;

/**
 * @ProjectName: jfinal-club
 * @Package: com.jfinal.club._admin.ques
 * @ClassName: QuesAdminService
 * @Author: Jzdsh
 * @Description:
 * @Date: 2020/3/31 14:07
 * @Version: 1.0
 */
public class QuesAdminService {

    Questions dao = new Questions( ).dao( );

    public Page< Questions > page(int pageNum, int pageSize, String searchName) {
        if (StringUtils.isNotBlank(searchName)) {
            searchName = "%" + searchName + "%";
        }

        try {
            if (StringUtils.isNotBlank(searchName)) {
                return dao.paginate(pageNum, pageSize, "select a.*,b.nickname", " from (select a.*,b.typename from questions a,doctype b where  a.doctype = b.id and a.quesname like ? ) a left join users b on a.usersid = b.id order by a.sort desc,a.addtime desc", searchName);
            } else {
                return dao.paginate(pageNum, pageSize, "select a.*,b.nickname", "from (select a.*,b.typename from questions a,doctype b where  a.doctype = b.id ) a left join users b on a.usersid = b.id order by a.sort desc,a.addtime desc");
            }
        } catch (Exception e) {
            e.printStackTrace( );
        }
        return null;
    }

}
