using Learun.Application.Organization; using Learun.Util; using System.Collections.Generic; using System.Web.Mvc; using Learun.Application.Base.AuthorizeModule; using System.Linq; using System; using Learun.Application.Base.SystemModule; namespace Learun.Application.Web.Areas.LR_OrganizationModule.Controllers { /// /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园 /// Copyright (c) 2013-2018 北京泉江科技有限公司 /// 创建人:陈彬彬 /// 日 期:2017.03.09 /// 描 述:用户管理控制器 /// public class UserController : MvcControllerBase { private UserIBLL userIBLL = new UserBLL(); private DepartmentIBLL departmentIBLL = new DepartmentBLL(); private UserRelationIBLL userRelationIBLL = new UserRelationBLL(); private RoleIBLL roleIBLL = new RoleBLL(); #region 获取视图 [HttpGet] public ActionResult StudentIndex() { return View(); } /// /// 用户管理主页 /// /// [HttpGet] public ActionResult Index() { return View(); } /// /// 用户管理表单 /// /// [HttpGet] public ActionResult Form() { return View(); } /// /// 人员选择 /// /// [HttpGet] public ActionResult SelectForm() { return View(); } [HttpGet] public ActionResult LookForm() { return View(); } /// /// 人员选择 /// /// [HttpGet] public ActionResult SelectOnlyForm() { return View(); } #endregion #region 获取数据 /// /// 获取分页数据 /// /// 分页参数 /// 关键字 /// 公司主键 /// 部门主键 /// 0 教师 1学生 /// [HttpGet] [AjaxOnly] public ActionResult GetPageList(string pagination, string keyword, string companyId, string departmentId, string tp) { Pagination paginationobj = pagination.ToObject(); var data = userIBLL.GetPageList(companyId, departmentId, paginationobj, keyword, tp); var jsonData = new { rows = data, total = paginationobj.total, page = paginationobj.page, records = paginationobj.records, }; return JsonResult(jsonData); } /// /// 获取用户列表 /// /// 公司主键 /// 部门主键 /// 查询关键词 /// [HttpGet] [AjaxOnly] public ActionResult GetList(string companyId, string departmentId, string keyword) { if (string.IsNullOrEmpty(companyId)) { var department = departmentIBLL.GetEntity(departmentId); if (department != null) { var data = userIBLL.GetList(department.F_CompanyId, departmentId, keyword); return JsonResult(data); } else { return JsonResult(new List()); } } else { var data = userIBLL.GetList(companyId, departmentId, keyword); return JsonResult(data); } } /// /// 根据部门获取用户 /// /// 部门主键 /// [HttpGet] [AjaxOnly] public ActionResult GetListByDepartmentId(string departmentId) { var data = userIBLL.GetListByDepartmentId(departmentId); return JsonResult(data); } /// /// 根据部门获取用户 /// /// 部门主键 /// [HttpGet] [AjaxOnly] public ActionResult GetListByDepartmentIds(string departmentId) { var data = userIBLL.GetListByDepartmentIds(departmentId); return JsonResult(data); } /// /// 获取本部门的人员 /// /// 公司主键 /// 部门主键 /// 查询关键词 /// [HttpGet] [AjaxOnly] public ActionResult GetMyDepartmentList() { UserInfo userinfo = LoginUserInfo.Get(); var data = userIBLL.GetList(userinfo.companyId, userinfo.departmentId, ""); return JsonResult(data); } /// /// 获取用户信息列表 /// /// 用户主键串 /// [HttpGet] [AjaxOnly] public ActionResult GetListByUserIds(string keyValue) { var list = userIBLL.GetListByUserIds(keyValue); string text = ""; if (list != null) { foreach (var item in list) { if (!string.IsNullOrEmpty(text)) { text += ","; } text += item.F_RealName; } } return SuccessString(text); } /// /// 获取用户信息列表 /// /// 用户主键串 /// [HttpGet] [AjaxOnly] public ActionResult GetEntityListByUserIds(string keyValue) { var list = userIBLL.GetListByUserIds(keyValue); return JsonResult(list); } /// /// 获取用户信息 /// /// 用户主键 /// [HttpGet] [AjaxOnly] public ActionResult GetUserEntity(string userId) { var data = userIBLL.GetEntityByUserId(userId); return JsonResult(data); } /// /// 获取映射数据 /// /// [HttpGet] [AjaxOnly] public ActionResult GetMap(string ver) { var data = userIBLL.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); } } /// /// 获取头像 /// /// 用户主键 /// [HttpGet] public ActionResult GetImg(string userId) { userIBLL.GetImg(userId); return Success("获取成功。"); } /// /// 获取头像For大厂 /// /// /// [HttpGet] public ActionResult GetImgForDC(string userId) { userIBLL.GetImgForDC(userId); return Success("获取成功。"); } [HttpGet] public ActionResult GetRoleList(string objectId) { var roleList = userRelationIBLL.GetRoleListByUserId(objectId); var jsonResult = new { roleInfoList = roleList }; return Success(jsonResult); } [HttpGet] [AjaxOnly] public ActionResult GetLastLoginTime(string userId) { return Success(LogBLL.GetUserLogList(userId)?.F_OperateTime); } #endregion #region 提交数据 /// /// 保存表单数据 /// /// 主键 /// 实体 /// [HttpPost] [ValidateAntiForgeryToken] [AjaxOnly] public ActionResult SaveForm(string keyValue, UserEntity entity) { userIBLL.SaveEntity(keyValue, entity); return Success("保存成功!"); } /// /// 删除表单数据 /// /// 主键 /// [HttpPost] [AjaxOnly] public ActionResult DeleteForm(string keyValue) { //userIBLL.VirtualDelete(keyValue); userIBLL.VirtualDeleteBatch(keyValue); return Success("删除成功!"); } /// /// 启用禁用账号 /// /// 主键 /// [HttpPost] [AjaxOnly] public ActionResult UpdateState(string keyValue, int state) { userIBLL.UpdateState(keyValue, state); return Success("操作成功!"); } /// /// 重置用户账号密码 /// /// 主键 /// [HttpPost] [AjaxOnly] public ActionResult ResetPassword(string keyValue) { userIBLL.ResetPassword(keyValue); return Success("操作成功!"); } /// /// 重置用户账号密码(八位) /// /// 主键 /// [HttpPost] [AjaxOnly] public ActionResult ResetPasswordEight(string keyValue) { userIBLL.ResetPasswordEight(keyValue); return Success("操作成功!"); } [HttpGet] [AjaxOnly] public ActionResult ResetStudentRelation() { var allStudents = userIBLL.GetStudents(); var studentRoleId = roleIBLL.GetIdByRoleName("学生"); var hasStudentsRolePeople = userRelationIBLL.GetUserIdList(studentRoleId).Select(a => a.F_UserId); var studentList = allStudents.Where(a => !hasStudentsRolePeople.Contains(a.F_UserId)); var relationList = new List(); var userIds = ""; foreach (var item in allStudents) { if (userIds != "") { userIds += ","; } userIds += item.F_UserId; } userRelationIBLL.SaveEntityList(studentRoleId, 1, userIds); return Success("操作成功"); } #endregion #region 数据导出 /// /// 导出用户列表 /// /// [HttpGet] public ActionResult ExportUserList() { userIBLL.GetExportList(); return Success("导出成功。"); } /// /// 导出用户列表【学生】 /// /// [HttpGet] public ActionResult ExportUserListOfStudent() { userIBLL.GetExportListOfStudent(); return Success("导出成功。"); } #endregion #region 验证数据 /// /// 账号不能重复 /// /// 主键 /// 账号 /// [HttpGet] [AjaxOnly] public ActionResult ExistAccount(string keyValue, string F_Account) { bool res = userIBLL.ExistAccount(F_Account, keyValue); return JsonResult(res); } #endregion } }