using learun.iapplication; using learun.util; using Microsoft.AspNetCore.Mvc; using System; using System.Threading.Tasks; namespace EC.Web.Areas.LR_OrganizationModule.Controllers { /// /// 版 本 EasyCode EC管理后台 /// Copyright (c) 2019-present EC管理有限公司 /// 创建人:tobin /// 日 期:2019.09.17 /// 描 述:用户模块控制器 /// [Area("LR_OrganizationModule")] public class UserController : MvcControllerBase { private readonly UserIBLL _userIBLL; private readonly ImgIBLL _imgIBLL; public UserController(UserIBLL userIBLL, ImgIBLL imgIBLL) { _userIBLL = userIBLL; _imgIBLL = imgIBLL; } #region 视图功能 /// /// 用户管理主页 /// /// [HttpGet] public IActionResult Index() { return View(); } /// /// 用户管理表单 /// /// [HttpGet] public IActionResult Form() { return View(); } /// /// 人员选择 /// /// [HttpGet] public IActionResult SelectForm() { return View(); } /// /// 人员选择 /// /// [HttpGet] public IActionResult SelectOnlyForm() { return View(); } #endregion 视图功能 #region 获取数据 /// /// 获取用户列表 /// /// 公司主键 /// 部门主键 /// 查询关键词 /// [HttpGet] [AjaxOnly] public async Task GetList(string companyId, string departmentId, string keyword) { var data = await _userIBLL.GetList(companyId, departmentId, keyword); return Success(data); } /// /// 获取分页数据 /// /// 分页参数 /// 关键字 /// 公司主键 /// 部门主键 /// [HttpGet] [AjaxOnly] public async Task GetPageList(string pagination, string keyword, string companyId, string departmentId) { Pagination paginationobj = pagination.ToObject(); var data = await _userIBLL.GetPageList(companyId, departmentId, paginationobj, keyword); var jsonData = new { rows = data, paginationobj.total, paginationobj.page, paginationobj.records }; return Success(jsonData); } /// /// 获取全部用户数据 /// /// 查询关键词 /// [HttpGet] [AjaxOnly] public async Task GetAllList(string keyword) { var data = await _userIBLL.GetAllList(keyword); return Success(data); } /// /// 获取用户信息列表 /// /// 用户主键串 /// [HttpGet] [AjaxOnly] public async Task GetEntityListByUserIds(string userIds) { var list = await _userIBLL.GetListByKeyValues(userIds); return Success(list); } /// /// 获取用户信息列表 /// /// 用户主键串 /// [HttpGet] [AjaxOnly] public async Task GetListByUserIds(string keyValue) { var list = await _userIBLL.GetListByKeyValues(keyValue); string text = ""; foreach (var item in list) { if (!string.IsNullOrEmpty(text)) { text += ","; } text += item.F_RealName; } return Success(text); } /// /// 获取用户信息 /// /// 用户主键 /// [HttpGet] [AjaxOnly] public async Task GetUserEntity(string userId) { var data = await _userIBLL.GetEntity(userId); return Success(data); } /// /// 获取头像文件 /// /// 账号 /// [HttpGet] public async Task HeadImg(string account) { ImgEntity imgEntity = await _imgIBLL.GetEntity(account); if (imgEntity != null && !string.IsNullOrEmpty(imgEntity.F_Content)) { string imgContent = imgEntity.F_Content.Replace("data:image/" + imgEntity.F_ExName.Replace(".", "") + ";base64,", ""); byte[] arr = Convert.FromBase64String(imgContent); return File(arr, "application/octet-stream"); } else { byte[] arr2 = FileHelper.ReadRoot("/img/header.png"); return File(arr2, "application/octet-stream"); } } #endregion 获取数据 #region 2 /// /// 获取用户列表 /// /// 查询参数,json字串 /// [HttpGet] [AjaxOnly] public async Task GetList2(string queryJson) { var queryParam = queryJson.ToJObject(); if (queryParam["CompanyId"].IsEmpty()) queryParam["CompanyId"] = CurrentUser().Result.F_CompanyId; var data = await _userIBLL.GetList(queryParam); return Success(data); } /// /// 获取分页数据 /// /// 分页参数 /// 查询参数,json字串 /// [HttpGet] [AjaxOnly] public async Task GetPageList2(string pagination, string queryJson) { var pageObj = pagination.ToObject(); var queryParam = queryJson.ToJObject(); if (queryParam["CompanyId"].IsEmpty()) queryParam["CompanyId"] = CurrentUser().Result.F_CompanyId; var list = await _userIBLL.GetPageList(pageObj, queryParam); var jsonData = new { rows = list, pageObj.total, pageObj.page, pageObj.records }; return Success(jsonData); } #endregion 2 #region 提交数据 /// /// 保存表单数据 /// /// 主键 /// 实体 /// [HttpPost] [AjaxOnly] public async Task SaveForm(string keyValue, UserEntity entity) { try { await _userIBLL.SaveEntity(keyValue, entity); return SuccessInfo("保存成功!"); } catch (Exception) { return Fail("账号不能重复"); } } /// /// 删除表单数据 /// /// 主键 /// [HttpPost] [AjaxOnly] public async Task DeleteForm(string keyValue) { await _userIBLL.Delete(keyValue); return SuccessInfo("删除成功!"); } /// /// 启用禁用账号 /// /// 主键 /// [HttpPost] [AjaxOnly] public async Task UpdateState(string keyValue, int state) { await _userIBLL.UpdateState(keyValue, state); return SuccessInfo("操作成功!"); } /// /// 重置用户账号密码 /// /// 主键 /// [HttpPost] [AjaxOnly] public async Task ResetPassword(string keyValue) { await _userIBLL.ResetPassword(keyValue); return SuccessInfo("操作成功!"); } #endregion 提交数据 #region 数据导出 /// /// 导出用户列表 /// /// [HttpGet] public async Task ExportUserList() { return File(await _userIBLL.GetExportList(), "application/ms-excel", "用户导出.xls"); } #endregion 数据导出 } }