using Dapper; using Estsh.Core.Controllers; using Estsh.Core.Model.Result; using Estsh.Core.Models; using Estsh.Core.Services.IServices; using Estsh.Core.Util; using Microsoft.AspNetCore.Mvc; using System.Collections; /*************************************************************************************************** * * 更新人:sitong.dong * 描述:用户管理模块控制类 * 修改时间:2022.06.22 * 修改日志:系统迭代升级 * **************************************************************************************************/ namespace Estsh.Core.Web.Controllers { /// /// 用户管理模块控制类 /// public class UserController : BaseController { private IUserService service; private ICommonService CommonService; public UserController(IUserService _service, ICommonService _CommonService) { service = _service; CommonService = _CommonService; } // // GET: /User/ public ActionResult Index() { return View(); } #region 用户管理 /// /// 根据分页条件获取用户列表 /// /// /// /// /// /// public ActionResult getUserListByPage(String account, Pager pager, String direction, String sort, String enabled = "Y") { Hashtable result = new Hashtable(); result.Add("pager.pageNo", pager.pageNo); Hashtable dataHt = this.service.getUserListByPage(account, enabled, pager, direction, sort); result.Add("rows", dataHt["dataList"]); result.Add("pager.totalRows", dataHt["totalCount"]); result.Add("sort", sort); result.Add("direction", direction); return Json(result); } /// /// 获取工厂信息 /// /// public ActionResult getFactoryInfo() { Hashtable result = new Hashtable(); List list = CommonService.getFactoryInfo(); result.Add("list", list); return Json(result); } /// /// 获取部门信息 /// /// public ActionResult getDeptInfo() { Hashtable result = new Hashtable(); List list = CommonService.getDeptInfo(); result.Add("list", list); return Json(result); } /// /// 获取班别信息 /// /// public ActionResult getShiftInfo() { Hashtable result = new Hashtable(); List list = CommonService.getShiftInfo(); result.Add("list", list); return Json(result); } /// /// 获取用户的角色信息,用以给用户赋予或取消角色 /// /// /// public ActionResult getRoleLister(String emp_id) { Hashtable result = new Hashtable(); List fromList = this.service.fromRoleList(emp_id); List toList = this.service.toRoleList(emp_id); result.Add("fromList", fromList); result.Add("toList", toList); return Json(result); } /// /// 保存用户数据 /// /// public ActionResult saveUserInfo() { String editType = Request.Form["editType"].ToString(); String emp_id = Request.Form["emp_id"].ToString(); String emp_no = Request.Form["emp_no"].ToString(); String empName = Request.Form["empName"].ToString(); String factoryId = Request.Form["factory"].ToString(); String deptId = Request.Form["dept"].ToString(); String shiftId = Request.Form["shift"].ToString(); String enabled = Request.Form["enabled"].ToString(); String roles = Request.Form["lister"].ToString(); SysEmp model = new SysEmp(); model.EmpNo = emp_no; model.EmpName = empName; model.FactoryId = factoryId==null? 0 :Convert.ToInt32(factoryId); model.DeptId = deptId == null ? 0 : Convert.ToInt32(deptId); model.ShiftId = shiftId == null ? 0 : Convert.ToInt32(shiftId); model.Enabled = enabled; String message = ""; String flag = ""; if (editType != null && editType.Trim().Equals("edit")) { try { model.UpdateUserId = CurrentEmp.EmpId; model.EmpId = emp_id == null ? 0 : Convert.ToInt32(emp_id); int i = this.service.updateUserInfo(model, roles); if (i == 0) { message = "修改失败!"; flag = "Fail"; } else { message = "修改成功!"; flag = "OK"; } } catch (Exception e) { message = "修改失败!"; flag = "Fail"; } } else { try { model.CreateUserId =CurrentEmp.EmpId; int i = this.service.saveUserInfo(model,roles); if (i == 2) { message = "此用户已存在!"; flag = "Fail"; } else if (i == 0) { message = "添加失败!"; flag = "Fail"; } else { message = "添加成功!"; flag = "OK"; } } catch (Exception e) { message = "添加失败!"; flag = "Fail"; } } Hashtable result = new Hashtable(); result.Add("message", message); result.Add("flag", flag); return Json(result); } /// /// 编辑用户信息 /// /// /// public ActionResult editUserInfo(String empId) { if (!string.IsNullOrEmpty(empId)) { List userInfo = this.service.getUserDetail(empId); //Hashtable htUserInfo = (Hashtable)userInfo[0]; ViewData.Add("editType", "edit"); ViewData.Add("empId", empId); ViewData.Add("empNo", userInfo[0].EmpNo); ViewData.Add("empName", userInfo[0].EmpName); ViewData.Add("shiftId", userInfo[0].ShiftId); ViewData.Add("factoryId", userInfo[0].FactoryId); ViewData.Add("deptId", userInfo[0].DeptId); ViewData.Add("enabled", userInfo[0].Enabled); return View("editUser"); } else { ViewData.Add("editType", "new"); } return View("editUser"); } /// /// 删除用户 /// /// /// public ActionResult deleteUser(String ids) { int delCount = 0; try { delCount = this.service.deleteUser(ids); } catch (Exception e) { delCount = -1; } Hashtable result = new Hashtable(); result.Add("status", delCount); return Json(result); } /// /// 启用 /// /// /// public ActionResult onEnable(String ids) { int delCount = 0; try { delCount = this.service.EnableData(ids); } catch (Exception e) { delCount = -1; } Hashtable result = new Hashtable(); result.Add("status", delCount); return Json(result); } /// /// 禁用 /// /// /// public ActionResult onDisable(String ids) { int delCount = 0; try { delCount = this.service.DisableData(ids); } catch (Exception e) { delCount = -1; } Hashtable result = new Hashtable(); result.Add("status", delCount); return Json(result); } public ActionResult restPassWord(string userID) { int count = 0; try { count = this.service.restPassWord(userID); } catch (Exception e) { count = -1; } Hashtable result = new Hashtable(); result.Add("status", count); return Json(result); } #endregion } }