You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

313 lines
9.8 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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
{
/// <summary>
/// 用户管理模块控制类
/// </summary>
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 用户管理
/// <summary>
/// 根据分页条件获取用户列表
/// </summary>
/// <param name="account"></param>
/// <param name="pager"></param>
/// <param name="direction"></param>
/// <param name="sort"></param>
/// <returns></returns>
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);
}
/// <summary>
/// 获取工厂信息
/// </summary>
/// <returns></returns>
public ActionResult getFactoryInfo()
{
Hashtable result = new Hashtable();
List<KeyValueResult> list = CommonService.getFactoryInfo();
result.Add("list", list);
return Json(result);
}
/// <summary>
/// 获取部门信息
/// </summary>
/// <returns></returns>
public ActionResult getDeptInfo()
{
Hashtable result = new Hashtable();
List<KeyValueResult> list = CommonService.getDeptInfo();
result.Add("list", list);
return Json(result);
}
/// <summary>
/// 获取班别信息
/// </summary>
/// <returns></returns>
public ActionResult getShiftInfo()
{
Hashtable result = new Hashtable();
List<KeyValueResult> list = CommonService.getShiftInfo();
result.Add("list", list);
return Json(result);
}
/// <summary>
/// 获取用户的角色信息,用以给用户赋予或取消角色
/// </summary>
/// <param name="emp_id"></param>
/// <returns></returns>
public ActionResult getRoleLister(String emp_id)
{
Hashtable result = new Hashtable();
List<KeyValueResult> fromList = this.service.fromRoleList(emp_id);
List<KeyValueResult> toList = this.service.toRoleList(emp_id);
result.Add("fromList", fromList);
result.Add("toList", toList);
return Json(result);
}
/// <summary>
/// 保存用户数据
/// </summary>
/// <returns></returns>
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);
}
/// <summary>
/// 编辑用户信息
/// </summary>
/// <param name="ruid"></param>
/// <returns></returns>
public ActionResult editUserInfo(String empId)
{
if (!string.IsNullOrEmpty(empId))
{
List<SysEmp> 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");
}
/// <summary>
/// 删除用户
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
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);
}
/// <summary>
/// 启用
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
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);
}
/// <summary>
/// 禁用
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
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
}
}