using Learun.Application.Organization;
using Learun.Util;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
namespace Learun.Application.Web.Areas.LR_OrganizationModule.Controllers
{
///
/// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
/// Copyright (c) 2013-2018 北京泉江科技有限公司
/// 创建人:陈彬彬
/// 日 期:2017.04.17
/// 描 述:部门管理
///
public class DepartmentController : MvcControllerBase
{
private DepartmentIBLL departmentIBLL = new DepartmentBLL();
private CompanyIBLL companyIBLL = new CompanyBLL();
private static DepartmentIBLL departmentIBLL_static = new DepartmentBLL();
private static Dictionary mapData = departmentIBLL_static.GetModelMap();
#region 获取视图
///
/// 主页
///
///
[HttpGet]
public ActionResult Index()
{
return View();
}
///
/// 表单
///
///
[HttpGet]
public ActionResult Form()
{
return View();
}
#endregion
#region 获取数据
///
/// 获取部门列表信息(根据公司Id)
///
/// 公司Id
/// 查询关键字
///
[HttpGet]
[AjaxOnly]
public ActionResult GetList(string companyId, string keyword)
{
var data = departmentIBLL.GetList(companyId, keyword).OrderBy(x => x.F_Order);
return JsonResult(data);
}
///
/// 获取树形数据
///
/// 公司id
/// 父级id
///
[HttpGet]
[AjaxOnly]
public ActionResult GetTree(string companyId, string parentId)
{
if (string.IsNullOrEmpty(companyId))
{
var companylist = companyIBLL.GetList();
var data = departmentIBLL.GetTree(companylist);
return JsonResult(data);
}
else
{
var data = departmentIBLL.GetTree(companyId, parentId);
return JsonResult(data);
}
}
///
/// 获取部门实体数据
///
///
///
[HttpGet]
[AjaxOnly]
public ActionResult GetEntity(string departmentId)
{
var data = departmentIBLL.GetEntity(departmentId);
return JsonResult(data);
}
[HttpGet]
[AjaxOnly]
public ActionResult GetDepartmentList(string listId)
{
var data = departmentIBLL.GetDepartmentList(listId);
return JsonResult(data);
}
///
/// 获取映射数据
///
///
[HttpGet]
[AjaxOnly]
public ActionResult GetMap(string ver)
{
var data = departmentIBLL.GetModelMap();
string md5 = Md5Helper.Encrypt(data.ToJson(), 32);
if (md5 == ver)
{
return Success("no update");
}
else
{
var jsondata = new
{
data = data,
ver = md5
};
return JsonResult(jsondata);
}
}
#endregion
#region 提交数据
///
/// 保存表单数据
///
///
///
///
[HttpPost]
[ValidateAntiForgeryToken]
[AjaxOnly]
public ActionResult SaveForm(string keyValue, DepartmentEntity entity)
{
var model = departmentIBLL.GetEntityByCode(entity.F_EnCode);
if (string.IsNullOrEmpty(keyValue))
{
if (model != null)
{
if (model.F_CompanyId == entity.F_CompanyId)
return Fail("部门编号已存在!");
}
}
else
{
if (model != null && model.F_DepartmentId != keyValue)
{
if (model.F_CompanyId == entity.F_CompanyId)
return Fail("部门编号已存在!");
}
}
if (keyValue == entity.F_ParentId)
{
return Fail("操作失败,当前项不允许");
}
//发送标识false
entity.SendFlag = false;
departmentIBLL.SaveEntity(keyValue, entity);
return Success("保存成功!");
}
///
/// 删除表单数据
///
///
///
[HttpPost]
[AjaxOnly]
public ActionResult DeleteForm(string keyValue)
{
var list = departmentIBLL.GetAllList().Where(x => x.F_ParentId == keyValue);
if (list.Count() > 0)
{
return Fail("删除失败!拥有下辖项不可直接删除");
}
else
{
departmentIBLL.VirtualDelete(keyValue);
return Success("删除成功!");
}
}
#endregion
}
}