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

import com.jfinal.aop.Inject;
import com.jfinal.core.Controller;
import com.jfinal.kit.Ret;
import com.jzdsh.auto.biz.BsTypeService;
import com.jzdsh.auto.biz.QualityService;
import com.jzdsh.auto.model.Owner;
import com.jzdsh.auto.model.Quality;

/**
 * @ProjectName: auto
 * @Package: com.jzdsh.auto.app.controller.admin
 * @ClassName: AdminQualityController
 * @Author: Jzdsh
 * @Description: 品质管理
 * @Date: 2020/3/28 17:41
 * @Version: 1.0
 */
public class AdminQualityController extends Controller {


    @Inject
    QualityService qualityService;

    @Inject
    BsTypeService bsTypeService;

    public void index( ) {
        setAttr("qualityPage", qualityService.page(getInt("pageNum", 1), 2));
    }

    public void add( ) {
        setAttr("type", bsTypeService.getByStatus(4));
        setAttr("quality", new Owner( ).setTypeId(0));
        render("add_edit.html");
    }

    public void save( ) {
        boolean save = getBean(Quality.class).save( );
        if (save) {
            renderJson(Ret.ok("msg", "创建成功!"));
        } else {
            renderJson(Ret.fail("msg", "创建失败!"));
        }
    }

    public void edit( ) {
        setAttr("quality", Quality.dao.findById(getInt( )));
        setAttr("type", bsTypeService.getByStatus(4));
        render("add_edit.html");
    }


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

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


}
