package com.jfinal.club.ws;

import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;
import com.jfinal.club.common.controller.BaseController;
import com.jfinal.club.common.interceptor.FrontAuthInterceptor;
import com.jfinal.club.common.model.Docws;
import com.jfinal.club.common.model.Nation;
import com.jfinal.kit.Ret;

import java.util.List;

/**
 * @ClassName DocWs
 * @Description TODO
 * @Author caolong
 * @Date 2020/3/24 15:10
 */
@Before(FrontAuthInterceptor.class)
public class DocWsController extends BaseController {

    @Inject
    private DocWsService docWsService;


    public void index() {
        render("ws_1.html");
    }

    public void ws2() {
        Integer id = getParaToInt("id");
        setAttr("id", id);
        Docws docwsById = docWsService.getDocwsById(id);
        setAttr("docwsById", docwsById);
        List<Nation> nations = docWsService.saveNation();
        setAttr("nations", nations);
        render("ws_2.html");
    }

    public void ws3() {
        Integer id = getParaToInt("id");
        setAttr("id", id);
        Docws docwsById = docWsService.getDocwsById(id);
        setAttr("docwsById", docwsById);
        List<Nation> nations = docWsService.saveNation();
        setAttr("nations", nations);
        render("ws_3.html");
    }

    public void ws4() {
        Integer id = getParaToInt("id");
        setAttr("id", id);
        Docws docwsById = docWsService.getDocwsById(id);
        setAttr("docwsById", docwsById);
        render("ws_4.html");
    }


    /**
     * @return void
     * @Author Cc
     * @Description //TODO 文书步骤保存
     * @Date 2020/3/24
     * @Param []
     **/
    public void wsFrom() {
        Docws model = getModel(Docws.class);
        model.setUsersid(getloginUsersId());
        Ret ret = docWsService.saveDocws(model);
        renderJson(ret);
    }


    /**
     * @return
     * @Author Cc
     * @Description //TODO 文书上一步
     * @Date 2020/3/24
     * @Param
     **/
    public void wsPro() {
        Integer docwsid = getParaToInt("id");
        Integer levels = getParaToInt("levels");
        Docws docwsById = docWsService.getDocwsById(docwsid);
        setAttr("id", docwsid);
        setAttr("docwsById", docwsById);
        List<Nation> nations = docWsService.saveNation();
        setAttr("nations", nations);
        if (levels == 2) {
            render("ws_1.html");
        } else if (levels == 3) {
            render("ws_2.html");
        } else {
            render("ws_3.html");
        }
    }

}
