SysUserController.cs 5.47 KB
using Autofac.Core;
using Hh.Mes.Common.Request;
using Hh.Mes.Pojo.System;
using Hh.Mes.POJO.Entity;
using Hh.Mes.Service;
using Hh.Mes.Service.SystemAuth;
using Hh.Mes.Service.WebService.Base;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using WebMvc.Aop;


namespace WebMvc
{
    [Area("base")]
    public class SysUserController : BaseController
    {
        private readonly SysUserService service;
        private readonly AuthStrategyContext _authStrategyContext;
        private readonly FaceLoginService faceLoginService;
        private readonly IWebHostEnvironment environment;

        public SysUserController(IAuth authUtil, SysUserService service, FaceLoginService faceLogin, IWebHostEnvironment hostingEnvironment) : base(authUtil)
        {
            _authStrategyContext = authUtil.GetCurrentUser();
            environment = hostingEnvironment;
            this.service = service;
            this.service.sysWebUser = authUtil.GetCurrentUser().User;
            this.faceLoginService = faceLogin;
            this.faceLoginService.sysWebUser = authUtil.GetCurrentUser().User;
        }

        //
        // GET: /SysUser/
        public ActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 用户列表没有组织 树形形状的
        /// </summary>
        /// <returns></returns>
        public ActionResult UserList()
        {
            return View();
        }

        /// <summary>
        /// 加载组织下面的所有用户
        /// </summary>
        [HttpPost]
        public string LoadUserListByTeamCode(string teamCode)
        {
            return Serialize(service.LoadUserListByTeamCode(teamCode));
        }

        /// <summary>
        /// 加载组织下面的所有用户
        /// </summary>
        [HttpPost]
        public string Load(PageReq request, int? orgId, string Name, string Idcard)
        {
            return Serialize(service.Load(request, orgId, Name, Idcard));
        }

        //添加用户
        [HttpPost]
        [XSSFilter]
        public string Add(SysUserView view)
        {
            return Serialize(service.Ins(view));
        }

        //修改用户
        [HttpPost]
        [XSSFilter]
        public string Update(SysUserView view)
        {
            return Serialize(service.Upd(view));
        }

        [HttpPost]
        public string Delete(int[] ids)
        {
            return Serialize(service.DeleteById(ids));
        }

        #region 获取权限数据

        /// <summary>
        /// 获取用户可访问的账号
        /// </summary>
        public string GetAccessedUsers()
        {
            IEnumerable<SysUserView> users = service.Load(new PageReq(), null, null, null).Result;
            var result = new Dictionary<int, object>();
            foreach (var user in users)
            {
                var item = new
                {
                    Account = user.Account,
                    RealName = user.Name,
                    id = user.Id,
                    text = user.Name,
                    value = user.Account,
                    parentId = "0",
                    showcheck = true,
                    img = "fa fa-user",
                };
                result.Add(user.Id, item);
            }

            return Serialize(result);
        }
        #endregion

        public ActionResult ChangePassword()
        {
            return View();
        }

        //修改个人密码
        [HttpPost]
        [XSSFilter]
        public string ChangeUserPassword(string OldPassword, string Password)
        {
            return Serialize(service.ChangeUserPassword(OldPassword, Password, _authStrategyContext.User));
        }

        //重设用户密码
        [HttpPost]
        [XSSFilter]
        public string ResetPassword(SysUser user)
        {
            return Serialize(service.ResetPassword(user));
        }


        [Authenticate]
        public ActionResult Binding()
        {
            return View();
        }

        //绑定登录方式 string account, string userImage,string jobCard ,bool edit
        [HttpPost]
        public string BindingAdd(IFormFileCollection excelfile)
        {
            var account = Request.Form["account"];
            var userImage = Request.Form["userImage"];
            var jobCard = Request.Form["jobCard"];
            var edit =bool.Parse(Request.Form["edit"]) ;
            byte[] imageBytes = { };
            if (excelfile.Count>0)
            {
                string[] str = userImage[0].Split(',');
                 imageBytes = Convert.FromBase64String(str[1]);
            }      
            Result = faceLoginService.FaceSearchAdd(account, userImage, jobCard, edit, imageBytes, environment.ContentRootPath); 
            //_app.CreateBinding(account, userImage,jobCard);
            return Serialize(Result);
        }


        /// <summary>
        /// 用户绑定项目
        /// </summary>
        [HttpPost]
        [XSSFilter]
        public string UserBindProjectRel(string userAccount, bool checkeds, string projectKeys)
        {
            return Serialize(service.UserBindProjectRel(userAccount, checkeds, projectKeys));
        }

        /// <summary>
        /// 用户关联绑定的 项目信息
        /// </summary>
        public string GetUserBindClient(string userAccount)
        {
            return Serialize(service.GetUserBindClient(userAccount));
        }
    }
}