package com.jzdsh.auto.app.controller.admin;

import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;
import com.jfinal.core.Controller;
import com.jfinal.kit.FileKit;
import com.jfinal.kit.PathKit;
import com.jfinal.kit.Ret;
import com.jfinal.upload.UploadFile;
import com.jzdsh.auto.app.controller.admin.mvalidator.AdminHelpInfoValidator;
import com.jzdsh.auto.app.controller.admin.mvalidator.AdminOwnerValidator;
import com.jzdsh.auto.biz.BsTypeService;
import com.jzdsh.auto.biz.HelpInfoService;
import com.jzdsh.auto.model.HelpInfo;

import java.util.Date;

/**
 * @ProjectName: auto
 * @Package: com.jzdsh.auto.app.controller.admin
 * @ClassName: AdminHelpInfoController
 * @Author: Jzdsh
 * @Description: 帮助中心
 * @Date: 2020/3/28 12:00
 * @Version: 1.0
 */
public class AdminHelpInfoController extends Controller {

    @Inject
    HelpInfoService helpInfoService;
    @Inject
    BsTypeService bsTypeService;

    public void index( ) {
        setAttr("helpInfoPage", helpInfoService.page(getInt("pageNum", 1), 10));
    }

    public void add( ) {
        setAttr("type", bsTypeService.getByStatus(2));
        setAttr("helpInfo", new HelpInfo( ).setTypeId(0));
        render("add_edit.html");
    }

    @Before(AdminHelpInfoValidator.class)
    public void save( ) {
        boolean save = getBean(HelpInfo.class).set("releaseTime", new Date( )).save( );
        if (save) {
            renderJson(Ret.ok("msg", "创建成功!"));
        } else {
            renderJson(Ret.fail("msg", "创建失败!"));
        }
    }

    public void edit( ) {
        setAttr("type", bsTypeService.getByStatus(2));
        setAttr("helpInfo", HelpInfo.dao.findById(getInt( )));
        render("add_edit.html");
    }

    @Before(AdminHelpInfoValidator.class)
    public void update( ) {
        boolean update = getBean(HelpInfo.class).update( );
        if (update) {
            renderJson(Ret.ok("msg", "更新成功!"));
        } else {
            renderJson(Ret.fail("msg", "更新失败!"));
        }
    }

    public void delete( ) {
        //删除信息
        boolean b = HelpInfo.dao.deleteById(getInt( ));
        if (b) {
            renderJson(Ret.ok("msg", "删除成功!"));
        } else {
            renderJson(Ret.fail("msg", "删除失败!"));
        }
    }

}
