package com.jzdsh.auto.biz;

import com.jfinal.plugin.activerecord.Db;
import com.jzdsh.auto.model.ServiceCategory;
import lombok.extern.log4j.Log4j2;

import java.util.List;

/**
 * @ProjectName: auto
 * @Package: com.jzdsh.auto.biz
 * @ClassName: ServiceCategoryService
 * @Author: Jzdsh
 * @Description: 主营业务
 * @Date: 2020/3/21 14:30
 * @Version: 1.0
 */
@Log4j2
public class ServiceCategoryService {


    /**
     * 查询层级服务
     *
     * @param role
     * @param level
     * @return
     */
    public List< ServiceCategory > getLeve(int role, int level) {
        try {
            return ServiceCategory.dao.find("select * from service_category where role = ? and status = ?", role, level);
        } catch (Exception e) {
            log.info(e);
        }
        return null;
    }

    /**
     * 查询显示在主页的层级
     *
     * @param role
     * @param level
     * @param pageSize
     * @return
     */
    public List< ServiceCategory > getLevelShow(int role, int level, int pageSize) {
        try {
            return ServiceCategory.dao.paginate(1, pageSize, "select *", "from service_category where role = ? and status = ? order by isShow desc", role, level).getList( );
        } catch (Exception e) {
            log.info(e);
        }
        return null;
    }

    /**
     *
     * @param pmName
     * @param roleTwo
     * @return
     */
    public ServiceCategory getByNameRole(String pmName, Integer roleTwo) {
        try {
            return ServiceCategory.dao.findFirst("select * from service_category where name = ? and role = ?", pmName, roleTwo);
        } catch (Exception e) {
            log.info(e);
        }
        return null;
    }

    /**
     * pid 查询
     * @param id
     * @return
     */
    public List< String > getByPid(Integer id) {
        try {
            return Db.query("select name from service_category where pId = ?", id);
        } catch (Exception e) {
            log.info(e);
        }
        return null;
    }
}
