var util = require('util');
var Dao = require('../../../common/Dao');

/**
 * 层级数据模型类
 */
var Layer = function (service) {
  Dao.call(this, service, 'sys', 'layer');
};

util.inherits(Layer, Dao);

module.exports = Layer;

/**
 * 查询层级
 * @param {Object} args 查询参数（org_id、parent_id、keyword）
 * @param {Function} cb 回调函数
 */
Layer.prototype.getList = function (req, cb) {
  var where = " 1=1 ";
  if (req.session && req.session.orgId) where += " and org_id=" + req.session.orgId;
  if (req.org_id != null) where += " and org_id=" + req.org_id;
  if (req.status != null) where += " and status in (" + req.status + ")";
  if (req.keyword != null) where += " and (code like '%" + req.keyword + "%' or name like '%" + req.keyword + "%')";

  this.query({
    where: where,
    fields: "id, org_id, code, name, status",
    order: 'code ASC, id ASC'
  }, cb);
};