123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Security.Cryptography;
- using System.Text;
- using System.Threading.Tasks;
- using Bowin.Common.ServiceToken.Permission;
- using Bowin.Common.WebModels;
- using YLShipBuildLandMap.Entity;
- using YLShipBuildLandMap.Entity.ViewModel;
- using YLShipBuildLandMap.Entity.ViewModel.SystemSetting;
- using YLShipBuildLandMap.Services.SystemSetting;
- using Microsoft.AspNetCore.Authorization;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using Newtonsoft.Json.Linq;
- using Bowin.Common.Data;
- using System.Data;
- using Bowin.Common.Office;
- namespace YLShipBuildLandMap.Web.Controllers.SystemSetting
- {
- [Route("api/systemsetting/[controller]/[action]")]
- [ApiController]
- [Authorize]
- public class UserController : ControllerBase
- {
- private IRoleService RoleService { get; set; }
- private IUserService UserService { get; set; }
- public UserController(IRoleService roleService, IUserService userService)
- {
- RoleService = roleService;
- UserService = userService;
- }
- [HttpPost]
- [FunctionCode("9903")]
- public ResultMessage GetUserList([FromBody] dynamic inputObj)
- {
- try
- {
- string userName = inputObj.userName;
- Guid? roleId = inputObj.RoleID;
- int? RecordStatus = inputObj.recordStatus;
- int? pageIndex = inputObj.pageIndex;
- int? pageSize = inputObj.pageSize;
- var userList = UserService.GetUserViewList(userName, roleId,RecordStatus,null, pageIndex, pageSize);
- return ResultMessage.Success(userList);
- }
- catch (Exception ex)
- {
- return ResultMessage.GetError(ex.Message);
- }
- }
- [HttpPost]
- [FunctionCode("9903")]
- public ResultMessage GetUser([FromBody] dynamic inputObj)
- {
- try
- {
- Guid userID = inputObj.userID;
- var user = UserService.GetUserView(userID);
- return ResultMessage.Success(user);
- }
- catch (Exception ex)
- {
- return ResultMessage.GetError(ex.Message);
- }
- }
- [HttpPost]
- [FunctionCode("990301")]
- public async Task<ResultMessage> Add([FromBody] JObject inputObj)
- {
- try
- {
- UserView user = inputObj["user"].ToObject<UserView>();
- UserView result = UserService.GetUserViewByName(user.LoginID, user.Name);
- if (result != null)
- {
- return ResultMessage.GetError("用户名或账号已存在");
- }
- await UserService.Save(user, LoginUser.Current.UserID);
- return ResultMessage.Success();
- }
- catch (Exception ex)
- {
- return ResultMessage.GetError(ex.Message);
- }
- }
- [HttpPost]
- [FunctionCode("990302")]
- public async Task<ResultMessage> Edit([FromBody] dynamic inputObj)
- {
- try
- {
- UserView user = inputObj["user"].ToObject<UserView>();
- if (!user.UserID.HasValue)
- {
- throw new Exception("实体ID不能为空。");
- }
- await UserService.Save(user, LoginUser.Current.UserID);
- return ResultMessage.Success();
- }
- catch (Exception ex)
- {
- return ResultMessage.GetError(ex.Message);
- }
- }
- [HttpPost]
- [FunctionCode("990303")]
- public async Task<ResultMessage> Delete([FromBody] dynamic inputObj)
- {
- try
- {
- List<Guid> userIDList = inputObj.userIDs.ToObject<List<Guid>>();
- await UserService.Delete(userIDList);
-
- return ResultMessage.Success();
- }
- catch (Exception ex)
- {
- return ResultMessage.GetError(ex.Message);
- }
- }
- [HttpGet]
- [FunctionCode("9903")]
- public ResultMessage GetUserListByUserName(string userName)
- {
- try
- {
- var userList = UserService.GetUserViewList(userName,null, null, null);
- var resultList = userList.rows.AsEnumerable().Select(x => new
- {
- loginId = x.LoginID,
- name = x.Name,
- id = x.UserID
- }).ToList();
- return ResultMessage.Success(resultList);
- }
- catch (Exception ex)
- {
- return ResultMessage.GetError(ex.Message);
- }
- }
- [HttpPost]
- public async Task<ResultMessage> UpdatePwd([FromBody] dynamic inputObj)
- {
- string newPassword = inputObj.newPassword;
- await UserService.UpdatePwd(LoginUser.Current.UserID, newPassword);
- return ResultMessage.Success();
- }
- [HttpGet]
- [FunctionCode("990304")]
- public async Task<ResultMessage> ResetPwd(Guid Id)
- {
- await UserService.ResetPwd(Id, LoginUser.Current.UserID);
- return ResultMessage.Success();
- }
- [HttpPost]
- public ResultMessage GetUserRoleList([FromBody] dynamic inputObj)
- {
- try
- {
- var list= UserService.GetUserRoleList();
- return ResultMessage.Success(list);
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- [HttpPost]
- [FunctionCode("990305")]
- public ResultMessage ExportPort([FromBody] dynamic inputObj)
- {
- string userName = inputObj.userName;
- Guid? roleId = inputObj.RoleID;
- int? RecordStatus = inputObj.recordStatus;
- int? pageIndex = inputObj.pageIndex;
- int? pageSize = inputObj.pageSize;
- string userId = inputObj.userId;
- List<Guid> useridList = !string.IsNullOrEmpty(userId) ? userId.Split(",").Where(s => !string.IsNullOrEmpty(s)).Select(s => Guid.Parse(s)).ToList() : null;
- var dataList = (UserService.GetUserViewList(userName, roleId, RecordStatus, useridList, pageIndex, pageSize).rows.
- Select((r, i) => new
- {
- index = (i + 1),
- r.Name,
- r.LoginID,
- r.CmWorkLinkAccountPsid,
- r.RoleNames,
- RecordStatus = r.RecordStatus == 1 ? "启用" : "停用"
- })).ToTable();
- dataList.Columns["index"].ColumnName = "序号";
- dataList.Columns["Name"].ColumnName = "用户名";
- dataList.Columns["LoginID"].ColumnName = "账号";
- dataList.Columns["CmWorkLinkAccountPsid"].ColumnName = "集团主账号";
- dataList.Columns["RoleNames"].ColumnName = "用户角色";
- dataList.Columns["RecordStatus"].ColumnName = "状态";
- List<string> headerList = new List<string>();
- foreach (DataColumn column in dataList.Columns)
- {
- headerList.Add(column.ColumnName);
- }
- AsposeExcelHelper excel = new AsposeExcelHelper();
- var fileName = excel.ExportToFile(dataList, headerList.ToArray(), Configuration.Current.AppSettings.TemplatePhysicalPath);
- return ResultMessage.Success(fileName);
- }
- }
- }
|