using DTO; using IServices; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using zhengcaioa.IService; using zhengcaioa.Models; namespace zhengcaioa.Controllers { public class PltUserRoleController : Controller { private readonly ILogger _logger; private readonly IPltRoleService _pltRoleService; private readonly IUserService _userService; private readonly ISysCodeService _sysCodeService; private readonly IHrDeptService _hrDeptService; public PltUserRoleController(ILogger logger, IPltRoleService pltRoleService, IUserService userService, ISysCodeService sysCodeService , IHrDeptService hrDeptService) { _logger = logger; _pltRoleService = pltRoleService; _userService = userService; _sysCodeService = sysCodeService; _hrDeptService = hrDeptService; } [CheckLogin] public IActionResult Index() { #region 获取所有角色 var listRole = _pltRoleService.listRole(); ViewBag.listRole = listRole; #endregion #region 获取所有人员 var listUser = _userService.GetList(); var deptDTOs = _hrDeptService.GetList().ToList(); var listType = new List(); foreach (var dept in deptDTOs) { var codeDataEntity = new CodeDataEntity(); codeDataEntity.CodeSn = dept.Id; codeDataEntity.Comments = dept.DeptName; listType.Add(codeDataEntity); } //var listType = _sysCodeService.GetCodeDataAll().Where(a=>a.CodeTable == "plt_user" && a.CodeField == "user_type").ToList(); var dicTypeUser = new Dictionary>(); if (listType.Count > 0) { listType.ForEach(t => { dicTypeUser[t.CodeSn] = listUser.Where(u => u.DeptId == t.CodeSn).ToList();// u.UserType }); } ViewBag.listType = listType; ViewBag.dicTypeUser = dicTypeUser; #endregion #region 获取所有人员角色配置 var listUserRole = _pltRoleService.GetList(); var dicUserRole = new Dictionary>(); if (listRole.Count > 0) { listRole.ForEach(r => { dicUserRole[r.Id] = listUserRole.Where(u => u.RoleId == r.Id).ToList().Select(u => u.UserId).ToList(); }); } ViewBag.dicUserRole = dicUserRole; #endregion return View(); } [CheckLogin] public string Save(string roleid = "", string usersid = "") { var curentuser = JsonConvert.DeserializeObject(HttpContext.Session.GetString("User")); ViewData["curentuser"] = curentuser; var result = new ResultEntity(); #region 数据验证 if (string.IsNullOrWhiteSpace(roleid)) { result.Result = false; result.Message = "请选择角色"; return JsonConvert.SerializeObject(result); } if (string.IsNullOrWhiteSpace(usersid)) { result.Result = false; result.Message = "请选择人员"; return JsonConvert.SerializeObject(result); } #endregion return JsonConvert.SerializeObject(_pltRoleService.SaveMoreEntity(roleid, usersid, curentuser.Id)); } } }