/**
 * 请勿将俱乐部专享资源复制给其他人，保护知识产权即是保护我们所在的行业，进而保护我们自己的利益
 * 即便是公司的同事，也请尊重 JFinal 作者的努力与付出，不要复制给同事
 * <p>
 * 如果你尚未加入俱乐部，请立即删除该项目，或者现在加入俱乐部：http://jfinal.com/club
 * <p>
 * 俱乐部将提供 jfinal-club 项目文档与设计资源、专用 QQ 群，以及作者在俱乐部定期的分享与答疑，
 * 价值远比仅仅拥有 jfinal club 项目源代码要大得多
 * <p>
 * JFinal 俱乐部是五年以来首次寻求外部资源的尝试，以便于有资源创建更加
 * 高品质的产品与服务，为大家带来更大的价值，所以请大家多多支持，不要将
 * 首次的尝试扼杀在了摇篮之中
 */

package com.jfinal.club.index;

import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;
import com.jfinal.club.common.banner.BannersService;
import com.jfinal.club.common.controller.BaseController;
import com.jfinal.club.common.interceptor.AuthCacheClearInterceptor;
import com.jfinal.club.common.model.Doc;
import com.jfinal.club.common.model.Questions;
import com.jfinal.club.common.model.Userct;
import com.jfinal.club.download.DownloadService;
import com.jfinal.club.my.ct.UserCtService;
import com.jfinal.club.my.doc.TypeIntreceptor;
import com.jfinal.club.my.doc.UsersDocService;
import com.jfinal.club.my.newsfeed.UsersInfoIntreceptor;
import com.jfinal.club.my.ques.QuestionsService;
import com.jfinal.club.ws.DocWsService;
import com.jfinal.plugin.activerecord.Page;
import org.jodconverter.core.DocumentConverter;
import org.jodconverter.core.office.OfficeException;
import org.jodconverter.core.office.OfficeUtils;
import org.jodconverter.local.JodConverter;
import org.jodconverter.local.office.LocalOfficeManager;

import java.io.File;

/**
 * 首页控制器
 */
public class IndexController extends BaseController {

    @Inject
    IndexService srv;

    @Inject
    DownloadService downloadSrv;

    @Inject
    UsersDocService usersDocService;

    @Inject
    UserCtService userCtService;

    @Inject
    QuestionsService questionsService;

    @Inject
    BannersService bannersService;

    @Inject
    DocWsService docWsService;

    /**
     * @return void
     * @Author Cc
     * @Description //TODO 首页
     * @Date 2020/3/24
     * @Param []
     **/
    @Before({TypeIntreceptor.class})
    public void index() {

        Long countCt = 0L;
        Long countDoc = 0L;
        if(getloginUsersId() != 0){
            countCt = userCtService.countCtById(getloginUsersId());
            countDoc = usersDocService.countDocById(getloginUsersId());
        }
        setAttr("docCount",countDoc);
        setAttr("ctCount",countCt);

        setAttr("banners", bannersService.selectAllBanners());

        Page<Doc> docBySort = usersDocService.getDocBySort(1, 6);
        setAttr("docBySort", docBySort.getList());
        Page<Userct> userctBySort = userCtService.getUserctBySort(1, 9);
        setAttr("userctBySort", userctBySort);
        Page<Questions> quesBySort = questionsService.getQuesBySort(1, 5);
        setAttr("quesBySort", quesBySort);

        render("index.html");
    }


    @Before(AuthCacheClearInterceptor.class)
    public void clear() {
        srv.clearCache();
        redirect("/");
    }
}
