AuthController.cs 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872
  1. 
  2. using OASystem.Infrastructure.Repositories.Login;
  3. using System.IdentityModel.Tokens.Jwt;
  4. using System.Security.Claims;
  5. using OASystem.Domain.Dtos.UserDto;
  6. using OASystem.API.OAMethodLib;
  7. using Serilog.Parsing;
  8. using OASystem.Domain.Dtos.System;
  9. using System.Drawing.Drawing2D;
  10. using System.Collections;
  11. using OASystem.API.OAMethodLib.JuHeAPI;
  12. using OASystem.API.OAMethodLib.QiYeWeChatAPI;
  13. using OASystem.Domain.Dtos.QiYeWeChat;
  14. using OASystem.Domain.Entities.System;
  15. using TinyPinyin;
  16. using System.Globalization;
  17. using Microsoft.AspNetCore.SignalR;
  18. using OASystem.API.OAMethodLib.Hub.Hubs;
  19. using OASystem.API.OAMethodLib.Hub.HubClients;
  20. using static OASystem.API.OAMethodLib.Hub.Hubs.ChatHub;
  21. using static OASystem.API.OAMethodLib.JWTHelper;
  22. using OASystem.Domain.Entities.Groups;
  23. namespace OASystem.API.Controllers
  24. {
  25. /// <summary>
  26. /// 鉴权相关
  27. /// </summary>
  28. [Route("api/")]
  29. public class AuthController : ControllerBase
  30. {
  31. private readonly IMapper _mapper;
  32. private readonly IConfiguration _config;
  33. private readonly LoginRepository _loginRep;
  34. private readonly MessageRepository _message;
  35. private readonly SystemMenuPermissionRepository _SystemMenuPermissionRepository;
  36. private readonly MessageRepository _messageRep;
  37. private readonly IQiYeWeChatApiService _qiYeWeChatApiServic;
  38. private readonly IHubContext<ChatHub, IChatClient> _hubContext;
  39. private readonly DeviceTokenRepository _deviceTokenRepository;
  40. public AuthController(IConfiguration config, LoginRepository loginRep, IMapper mapper, MessageRepository message,
  41. SystemMenuPermissionRepository systemMenuPermissionRepository, IQiYeWeChatApiService qiYeWeChatApiService, MessageRepository messageRep,
  42. DeviceTokenRepository deviceRep,
  43. IHubContext<ChatHub, IChatClient> hubContext)
  44. {
  45. _config = config;
  46. _loginRep = loginRep;
  47. _mapper = mapper;
  48. _message = message;
  49. _SystemMenuPermissionRepository = systemMenuPermissionRepository;
  50. _qiYeWeChatApiServic = qiYeWeChatApiService;
  51. _messageRep = messageRep;
  52. _deviceTokenRepository = deviceRep;
  53. _hubContext = hubContext;
  54. }
  55. /// <summary>
  56. /// 用户登录
  57. /// </summary>
  58. /// <param name="dto"></param>
  59. /// <returns></returns>
  60. [Route("login")]
  61. [HttpPost]
  62. [ProducesResponseType(typeof(LoginView), StatusCodes.Status200OK)]
  63. public async Task<IActionResult> LoginAsync(LoginDto dto)
  64. {
  65. if (string.IsNullOrWhiteSpace(dto.Number) || string.IsNullOrWhiteSpace(dto.Password))
  66. {
  67. return Ok(JsonView(false, "账号或密码不能为空!!"));
  68. }
  69. #region 校验用户信息
  70. var userData = _loginRep.Login(dto).Result;
  71. if (userData.Code != 0) return Ok(JsonView(false, userData.Msg));
  72. #endregion
  73. Result authData = null;
  74. string uName = string.Empty,
  75. role = string.Empty,
  76. depName = string.Empty;
  77. int uId = 0;
  78. int unReadCount = 0;
  79. int announcementUnReadCount = 0;
  80. if (userData.Data != null)
  81. {
  82. uId = (userData.Data as UserLoginInfoView).UserId;
  83. uName = (userData.Data as UserLoginInfoView).CnName;
  84. depName = (userData.Data as UserLoginInfoView).DepName;
  85. role = (userData.Data as UserLoginInfoView).JobName;
  86. authData = _SystemMenuPermissionRepository.QueryMenuLoad(uId, dto.PortType);
  87. unReadCount = await _messageRep.GetUnReadCount(uId);
  88. announcementUnReadCount = await _messageRep.GetAnnouncementUnReadCount(uId);
  89. }
  90. //_hubContext.Login(uId, uName);
  91. var view = new LoginView
  92. {
  93. UserInfo = userData == null ? null : userData.Data,
  94. AuthData = authData == null ? null : authData.Data,
  95. UnReadCount = unReadCount,
  96. AnnouncementUnReadCount = announcementUnReadCount
  97. };
  98. DateTime createZebraTime = DateTime.Now;
  99. string authorId = dto.Number + "Token";
  100. string authorToken = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>(authorId);//string 取
  101. if (authorToken != null)
  102. {
  103. #region 解析出过期时间
  104. var jwtHandler = new JwtSecurityTokenHandler();
  105. JwtSecurityToken securityToken = jwtHandler.ReadJwtToken(authorToken);
  106. DateTime expDt = (securityToken.Payload[JwtRegisteredClaimNames.Exp] ?? 0).GetInt().GetTimeSpmpToDate();
  107. #endregion
  108. if (expDt >= createZebraTime) //超时重新获取token
  109. {
  110. authorToken = await JwtHelper.IssueJwtAsync(new TokenModelJwt() { UserId = uId, UserName = uName, Department = depName, Role = role }); //
  111. }
  112. view.Expires = expDt;
  113. view.Token = authorToken;
  114. }
  115. else
  116. {
  117. view.Expires = createZebraTime.AddMinutes(30);
  118. //view.Token = await GeneralMethod.GetToken(_config, dto.Number, uId, uName, createZebraTime); //JwtHelper
  119. view.Token = await JwtHelper.IssueJwtAsync(new TokenModelJwt() { UserId = uId, UserName = uName, Department = depName, Role = role }); //
  120. TimeSpan ts = view.Expires.AddMinutes(-1) - createZebraTime; //设置redis 过期时间 比 jwt 时间 快一分钟
  121. await RedisRepository.RedisFactory.CreateRedisRepository().StringSetAsync<string>(authorId, view.Token, ts);//string 存
  122. }
  123. //#region 添加登录用户上线信息
  124. //_hubContext.SignalRLogin(uId);
  125. //#endregion
  126. #region 测试添加系统消息
  127. //await _message.AddMsg(new MessageDto()
  128. //{
  129. // Type = 1,
  130. // IssuerId = 208,
  131. // Title = "测试添加消息标题",
  132. // Content = "消息体测试",
  133. // ReleaseTime = DateTime.Now,
  134. // UIdList = new List<int> {
  135. // 5,
  136. // 208,
  137. // 219
  138. // }
  139. //});
  140. #endregion
  141. return Ok(JsonView(view));
  142. }
  143. /// <summary>
  144. /// 移动端用户登录
  145. /// </summary>
  146. /// <param name="dto"></param>
  147. /// <returns></returns>
  148. [Route("MobileLogin")]
  149. [HttpPost]
  150. [ProducesResponseType(typeof(LoginView), StatusCodes.Status200OK)]
  151. public async Task<IActionResult> MobileLoginAsync(LoginDto dto)
  152. {
  153. if (string.IsNullOrWhiteSpace(dto.Number) || string.IsNullOrWhiteSpace(dto.Password))
  154. {
  155. return Ok(JsonView(false, "账号或密码不能为空!!"));
  156. }
  157. #region 校验用户信息
  158. var userData = _loginRep.Login(dto).Result;
  159. if (userData.Code != 0) return Ok(JsonView(false, userData.Msg));
  160. #endregion
  161. Result authData = null;
  162. string uName = string.Empty;
  163. string role = string.Empty;
  164. int uId = 0;
  165. int unReadCount = 0;
  166. int announcementUnReadCount = 0;
  167. if (userData.Data != null)
  168. {
  169. uId = (userData.Data as UserLoginInfoView).UserId;
  170. uName = (userData.Data as UserLoginInfoView).CnName;
  171. role = (userData.Data as UserLoginInfoView).JobName;
  172. authData = _SystemMenuPermissionRepository.MobileMenuLoad(uId, dto.PortType);
  173. unReadCount = await _messageRep.GetUnReadCount(uId);
  174. announcementUnReadCount = await _messageRep.GetAnnouncementUnReadCount(uId);
  175. }
  176. //_hubContext.Login(uId, uName);
  177. var view = new LoginView
  178. {
  179. UserInfo = userData == null ? null : userData.Data,
  180. AuthData = authData == null ? null : authData.Data,
  181. UnReadCount = unReadCount,
  182. AnnouncementUnReadCount = announcementUnReadCount
  183. };
  184. DateTime createZebraTime = DateTime.Now;
  185. string authorId = dto.Number + "Token";
  186. string authorToken = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>(authorId);//string 取
  187. if (authorToken != null)
  188. {
  189. #region 解析出过期时间
  190. var jwtHandler = new JwtSecurityTokenHandler();
  191. JwtSecurityToken securityToken = jwtHandler.ReadJwtToken(authorToken);
  192. DateTime expDt = (securityToken.Payload[JwtRegisteredClaimNames.Exp] ?? 0).GetInt().GetTimeSpmpToDate();
  193. #endregion
  194. if (expDt >= createZebraTime) //超时重新获取token
  195. {
  196. authorToken = await JwtHelper.IssueJwtAsync(new TokenModelJwt() { UserId = uId, UserName = uName, Role = role }); //
  197. }
  198. view.Expires = expDt;
  199. view.Token = authorToken;
  200. }
  201. else
  202. {
  203. view.Expires = createZebraTime.AddMinutes(30);
  204. //view.Token = await GeneralMethod.GetToken(_config, dto.Number, uId, uName, createZebraTime); //JwtHelper
  205. view.Token = await JwtHelper.IssueJwtAsync(new TokenModelJwt() { UserId = uId, UserName = uName, Role = role }); //
  206. TimeSpan ts = view.Expires.AddMinutes(-1) - createZebraTime; //设置redis 过期时间 比 jwt 时间 快一分钟
  207. await RedisRepository.RedisFactory.CreateRedisRepository().StringSetAsync<string>(authorId, view.Token, ts);//string 存
  208. }
  209. //#region 添加登录用户上线信息
  210. //_hubContext.SignalRLogin(uId);
  211. //#endregion
  212. #region 测试添加系统消息
  213. //await _message.AddMsg(new MessageDto()
  214. //{
  215. // Type = 1,
  216. // IssuerId = 208,
  217. // Title = "测试添加消息标题",
  218. // Content = "消息体测试",
  219. // ReleaseTime = DateTime.Now,
  220. // UIdList = new List<int> {
  221. // 5,
  222. // 208,
  223. // 219
  224. // }
  225. //});
  226. #endregion
  227. return Ok(JsonView(view));
  228. }
  229. /// <summary>
  230. /// 申请注册 数据Data
  231. /// </summary>
  232. /// <param name="dto"></param>
  233. /// <returns></returns>
  234. //[Authorize]
  235. [HttpPost]
  236. [Route("register/daraSource")]
  237. public async Task<IActionResult> RegisterDataSource()
  238. {
  239. string sql = string.Format(@"Select sc.Id CompanyId,sc.CompanyName,sd.Id DepId,sd.DepName,sjp.Id JobId,sjp.JobName From Sys_Company sc
  240. Left Join Sys_Department sd On sd.IsDel = 0 And sc.Id = sd.CompanyId
  241. Left Join Sys_JobPost sjp On sjp.IsDel = 0 And sjp.DepId = sd.Id
  242. Where sc.IsDel = 0");
  243. var companyDetails = _loginRep._sqlSugar.SqlQueryable<CompanyDetailsView>(sql).ToList();
  244. List<CompanyDetailsView1> detailsView1 = new List<CompanyDetailsView1>();
  245. if (companyDetails.Count > 0)
  246. {
  247. var companyDetails1 = companyDetails.GroupBy(it => it.CompanyId).Select(it => it.First()).ToList();
  248. detailsView1 = companyDetails1.Select(it =>
  249. {
  250. CompanyDetailsView1 itemCompany = new CompanyDetailsView1();
  251. List<DepDetailsView> depDetailsView = new List<DepDetailsView>();
  252. var companyDetails2 = companyDetails.GroupBy(it => it.DepId).Select(it => it.First()).ToList();
  253. //部门
  254. depDetailsView = companyDetails2.Where(depIt => depIt.CompanyId == it.CompanyId).Select(depIt =>
  255. {
  256. DepDetailsView depDetails = new DepDetailsView();
  257. List<JobDetailsView> jobDetails = new List<JobDetailsView>();
  258. //岗位
  259. jobDetails = companyDetails.Where(jobIt => jobIt.DepId == depIt.DepId).Select(jobIt =>
  260. {
  261. JobDetailsView jobDetail = new JobDetailsView()
  262. {
  263. JobId = jobIt.JobId,
  264. JobName = jobIt.JobName,
  265. };
  266. return jobDetail;
  267. }).ToList();
  268. depDetails.DepId = depIt.DepId;
  269. depDetails.DepName = depIt.DepName;
  270. depDetails.SubJob = jobDetails;
  271. return depDetails;
  272. }).ToList();
  273. itemCompany.CompanyId = it.CompanyId;
  274. itemCompany.CompanyName = it.CompanyName;
  275. itemCompany.SubDep = depDetailsView;
  276. return itemCompany;
  277. }).ToList();
  278. }
  279. return Ok(new { Code = 200, Msg = "查询成功!", Data = detailsView1 });
  280. }
  281. /// <summary>
  282. /// 申请注册
  283. /// </summary>
  284. /// <param name="dto"></param>
  285. /// <returns></returns>
  286. //[Authorize]
  287. [HttpPost]
  288. [Route("register")]
  289. public async Task<IActionResult> Register(RegisterDto dto)
  290. {
  291. #region 企业微信添加员工
  292. //string lastName = dto.CnName.Substring(0, 1);
  293. //string lastNamePy = string.Empty;
  294. //if (PinyinHelper.IsChinese(Convert.ToChar(lastName)))
  295. //{
  296. // lastNamePy = PinyinHelper.GetPinyin(lastName);
  297. //}
  298. //string userId = string.Format("{0}.{1}", dto.EnName, lastNamePy.ToLower());
  299. //Create_Request request = new Create_Request()
  300. //{
  301. // userid = userId,
  302. // name = dto.CnName,
  303. // mobile = dto.Phone,
  304. // department = new List<long>() { dto.DepId },
  305. // position = dto.JobPostId.ToString(),
  306. // gender = dto.Sex == 0 ? 1 : dto.Sex == 1 ? 2 : 1,
  307. // biz_mail = dto.Email
  308. //};
  309. //var qiYeWeChatCreateData = await _qiYeWeChatApiServic.CreateAsync(request);
  310. #endregion
  311. var userData = _loginRep.Register(dto);
  312. if (userData.Result.Code != 0)
  313. {
  314. return Ok(JsonView(false, userData.Result.Msg));
  315. }
  316. return Ok(JsonView(true, userData.Result.Msg));
  317. }
  318. /// <summary>
  319. /// 修改密码
  320. /// </summary>
  321. /// <param name="dto"></param>
  322. /// <returns></returns>
  323. [Authorize]
  324. [HttpPost]
  325. [Route("UpdPassword")]
  326. public async Task<IActionResult> UpdateUserPassword(UpdateDto dto)
  327. {
  328. //Result result = new Result();
  329. //var httpContext = HttpContext.User.Claims.FirstOrDefault(it => it.Type == ClaimTypes.Name)?.Value;
  330. //Sys_Users sys_Users = _mapper.Map<Sys_Users>(dto);
  331. var _view = await _loginRep.ChangePassword(dto.UserId, dto.Password);
  332. if (_view.Code == 0) return Ok(JsonView(true, "操作成功!"));
  333. return Ok(JsonView(false, _view.Msg));
  334. }
  335. /// <summary>
  336. /// 保存deviceToken
  337. /// </summary>
  338. /// <param name="dto"></param>
  339. /// <returns></returns>
  340. [HttpPost("SaveDeviceToken")]
  341. [ProducesResponseType(typeof(LoginView), StatusCodes.Status200OK)]
  342. public async Task<IActionResult> SaveDeviceToken(SaveDeviceToken dto)
  343. {
  344. var view = await _deviceTokenRepository.SaveToken(dto);
  345. if (view.Code == 0) return Ok(JsonView(true, "操作成功!"));
  346. return Ok(JsonView(false, view.Msg));
  347. }
  348. /// <summary>
  349. /// 获取deviceToken
  350. /// </summary>
  351. /// <param name="dto"></param>
  352. /// <returns></returns>
  353. [HttpPost("GetDeviceToken")]
  354. [ProducesResponseType(typeof(LoginView), StatusCodes.Status200OK)]
  355. public async Task<IActionResult> GetDeviceToken(GetDeviceToken dto)
  356. {
  357. var view = await _deviceTokenRepository.GetToken(dto.account);
  358. if (view.Code == 0) return Ok(JsonView(true, "操作成功!", view.Data));
  359. return Ok(JsonView(false, view.Msg));
  360. }
  361. /// <summary>
  362. /// 测试auth
  363. /// </summary>
  364. /// <param name="dto"></param>
  365. /// <returns></returns>
  366. [OASystemAuthentication]
  367. [HttpPost("TestToken")]
  368. [ProducesResponseType(typeof(LoginView), StatusCodes.Status200OK)]
  369. public async Task<IActionResult> TestToken(LoginDto dto)
  370. {
  371. string authorId = dto.Number + "Token";
  372. // 从Redis里面取数据
  373. //string userToken = _redis.StringGet(authorId);
  374. string userToken = "";
  375. var view = new LoginView
  376. {
  377. Token = authorId + ":" + userToken
  378. };
  379. return Ok(JsonView(view));
  380. }
  381. ///// <summary>
  382. ///// 员工信息 迁移
  383. ///// Old OA To New OA
  384. ///// </summary>
  385. ///// <returns></returns>
  386. //[HttpPost("UpdateUserDataOldOAToNewOA")]
  387. //[ProducesResponseType(typeof(LoginView), StatusCodes.Status200OK)]
  388. //public async Task<IActionResult> UpdateUserDataOldOAToNewOA()
  389. //{
  390. // dynamic view = null;
  391. // try
  392. // {
  393. // var _sqlSuar = _loginRep._sqlSugar;
  394. // var oldOaUsersData = await _sqlSuar.Queryable<OA2014UsersView>().AS("OA2014.dbo.Users").ToListAsync();
  395. // var newOaCompanyData = await _sqlSuar.Queryable<Sys_Company>().ToListAsync();
  396. // var newOaDepartmentData = await _sqlSuar.Queryable<Sys_Department>().ToListAsync();
  397. // var newOaJobPostData = await _sqlSuar.Queryable<Sys_JobPost>().ToListAsync();
  398. // List<Sys_Users> newOaUserDatas = new List<Sys_Users>();
  399. // foreach (var oldUser in oldOaUsersData)
  400. // {
  401. // int depId = 0, postId = 0;
  402. // #region 处理部门岗位
  403. // int did = oldUser.Did;
  404. // string post = oldUser.Post;
  405. // switch (did)
  406. // {
  407. // case 1 : //信息部
  408. // depId = 2;
  409. // if (post.Equals("信息部经理")) postId = 4;
  410. // else if (post.Equals("美工")) { depId = 5; postId = 18; }
  411. // else if(post.Equals("网络推广")) postId = 46;
  412. // else if (post.Equals("软件开发")) postId = 5;
  413. // else if (post.Equals("平面设计师")) { depId = 5; postId = 18; }
  414. // else if (post.Equals("平面设计")) { depId = 5; postId = 18; }
  415. // else if (post.Equals("平面设计师")) { depId = 5; postId = 18; }
  416. // else if (post.Equals("软件工程师")) postId = 5;
  417. // else if (post.Equals("OP操作")) { depId = 7; postId = 28; }
  418. // else if (post.Equals("软件工程师.")) postId = 5;
  419. // else if (post.Equals(".net工程师")) postId = 5;
  420. // else if (post.Equals("安卓开发工程师")) postId = 7;
  421. // else if (post.Equals("web前端")) postId = 6;
  422. // else if (post.Equals("Web后端开发")) postId = 5;
  423. // break;
  424. // case 2 : //财务部
  425. // depId=3;
  426. // if (post.Equals("主管")) postId = 47;
  427. // else if (post.Equals("财务总监")) { postId = 9; }
  428. // else if (post.Equals("会计")) { postId = 10; }
  429. // else if (post.Equals("财务经理")) { postId = 47; }
  430. // else if (post.Equals("财务助理")) { postId = 50; }
  431. // else if (post.Equals("出纳")) { postId = 48; }
  432. // else { postId = 10; }
  433. // break;
  434. // case 3: //人事部
  435. // depId = 4;
  436. // if (post.Equals("主管")) postId = 51;
  437. // else if (post.Equals("人事部主管")) { postId = 51; }
  438. // else if (post.Equals("人事行政主管")) { postId = 51; }
  439. // else if (post.Equals("行政人事助理")) { postId = 52; }
  440. // else if (post.Equals("人事助理")) { postId = 52; }
  441. // else if (post.Equals("人事主管")) { postId = 51; }
  442. // else if (post.Equals("行政人事专员")) { postId = 12; }
  443. // else if (post.Equals("行政司机")) { postId = 14; }
  444. // else if (post.Equals("司机")) { postId = 14; }
  445. // else if (post.Equals("统筹执行")) { postId = 12; }
  446. // else if (post.Equals("培训专员")) { postId = 13; }
  447. // else if (post.Equals("人事经理")) { postId = 11; }
  448. // else if (post.Equals("前台")) { postId = 33; }
  449. // else if (post.Equals("人事行政经理")) { postId = 11; }
  450. // else if (post.Equals("人事部经理")) { postId = 11; }
  451. // else if (post.Equals("人事专员")) { postId = 12; }
  452. // else if (post.Equals("人事经理")) { postId = 11; }
  453. // else postId = 12;
  454. // break;
  455. // case 4: //国交部
  456. // //22 7 主管
  457. // //23 7 计调
  458. // //24 7 机票
  459. // //25 7 酒店
  460. // //26 7 签证
  461. // //27 7 商邀
  462. // //28 7 OP
  463. // //32 7 经理
  464. // depId = 7;
  465. // if (post.Equals("酒店")) postId = 25;
  466. // else if (post.Equals("经理")) { postId = 32; }
  467. // else if (post.Equals("OP专员")) { postId = 28; }
  468. // else if (post.Equals("酒店预订")) { postId = 25; }
  469. // else if (post.Equals("商务邀请")) { postId = 27; }
  470. // else if (post.Equals("-")) { postId = 0; }
  471. // else if (post.Equals("签证专员")) { postId = 26; }
  472. // else if (post.Equals("OP操作")) { postId = 28; }
  473. // else if (post.Equals("司机")) { postId = 14; }
  474. // else if (post.Equals("国际交流部经理")) { postId = 32; }
  475. // else if (post.Equals("机票酒店")) { postId = 24; }
  476. // else if (post.Equals("签证")) { postId = 26; }
  477. // else if (post.Equals("票房")) { postId = 24; }
  478. // else if (post.Equals("票务专员")) { postId = 24; }
  479. // else if (post.Equals("酒店/机票")) { postId = 24; }
  480. // else if (post.Equals("OP")) { postId = 28; }
  481. // else if (post.Equals("主管")) { postId = 22; }
  482. // else if (post.Equals("订票专员")) { postId = 24; }
  483. // else if (post.Equals("机票")) { postId = 24; }
  484. // else if (post.Equals("国交部经理")) { postId = 32; }
  485. // else if (post.Equals("计调")) { postId = 23; }
  486. // else if (post.Equals("票务")) { postId = 24; }
  487. // else if (post.Equals("国交部主管")) { postId = 22; }
  488. // else if (post.Equals("暂无")) { postId = 22; }
  489. // else if (post.Equals("初级OP")) { postId = 28; }
  490. // else if (post.Equals("计调")) { postId = 23; }
  491. // else { postId = 0; }
  492. // break;
  493. // case 5: //会展部
  494. // //15 5 经理
  495. // //16 5 文案策划
  496. // //17 5 活动执行
  497. // //18 5 平面设计师
  498. // //19 5 3D设计师
  499. // depId = 5;
  500. // if (post.Equals("-")) postId = 16;
  501. // break;
  502. // case 6: //市场销售部
  503. // //20 6 经理
  504. // //21 6 市场专员
  505. // //53 6 主管
  506. // depId = 6;
  507. // if (post.Equals("主管")) postId = 53;
  508. // else if (post.Equals("-")) postId = 21;
  509. // else if (post.Equals("销售总监")) postId = 53;
  510. // else if (post.Equals("市场专员")) postId = 21;
  511. // else if (post.Equals("销售专员")) postId = 54;
  512. // else if (post.Equals("市场助理")) postId = 55;
  513. // else if (post.Equals("销售")) postId = 54;
  514. // break;
  515. // case 99: //总经办
  516. // //1 1 总经理
  517. // //2 1 副总经理
  518. // //3 1 总经理助理
  519. // depId = 1;
  520. // if (post.Equals("总经理")) postId = 1;
  521. // else if (post.Equals("副总")) postId = 2;
  522. // break;
  523. // case 107: //会议会展策划部
  524. // //15 5 经理
  525. // //16 5 文案策划
  526. // //17 5 活动执行
  527. // //18 5 平面设计师
  528. // //19 5 3D设计师
  529. // //56 5 销售
  530. // //46 5 网络推广
  531. // //57 5 市场推广
  532. // depId = 5;
  533. // if (post.Equals("销售")) postId = 56;
  534. // else if (post.Equals("策划执行")) postId = 16;
  535. // else if (post.Equals("策活动划")) postId = 16;
  536. // else if (post.Equals("活动执行")) postId = 17;
  537. // else if (post.Equals("网络媒介推广")) postId = 46;
  538. // else if (post.Equals("媒介主任")) postId = 46;
  539. // else if (post.Equals("公关部经理")) postId = 15;
  540. // else if (post.Equals("项目执行")) postId = 17;
  541. // else if (post.Equals("市场推广")) postId = 57;
  542. // else if (post.Equals("策划")) postId = 16;
  543. // else if (post.Equals("3D设计师")) postId = 19;
  544. // else if (post.Equals("平面设计")) postId = 18;
  545. // else if (post.Equals("设计")) postId = 18;
  546. // else if (post.Equals("活动策划")) postId = 16;
  547. // else if (post.Equals("活动策划执行")) postId = 17;
  548. // else if (post.Equals("高级活动策划")) postId = 16;
  549. // else postId = 0;
  550. // break;
  551. // case 115:
  552. // if (post.Equals("系统管理员")) { depId = 9; postId = 31; }
  553. // else if (post.Equals("后勤专员")) { depId = 5; postId = 58; }
  554. // break;
  555. // case 287: //会展部
  556. // //59 2 17 经理
  557. // //60 2 17 主管
  558. // //61 2 17 会展专员
  559. // //62 2 17 会展销售
  560. // //63 2 17 会展策划
  561. // //64 2 17 招商专员
  562. // //65 2 17 媒介专员
  563. // depId = 17;
  564. // if (post.Equals("会展部经理")) postId = 59;
  565. // else if (post.Equals("会展专员")) postId = 61;
  566. // else if (post.Equals("会展销售")) postId = 62;
  567. // else if (post.Equals("招商招展")) postId = 63;
  568. // else if (post.Equals("会展部主管")) postId = 60;
  569. // else if (post.Equals("媒介专员")) postId = 65;
  570. // else if (post.Equals("会展策划")) postId = 63;
  571. // else if (post.Equals("招商专员")) postId = 64;
  572. // else postId = 61;
  573. // break;
  574. // case 304: //总经理助理
  575. // //1 1 总经理
  576. // //2 1 副总经理
  577. // //3 1 总经理助理
  578. // depId = 1;
  579. // postId = 3;
  580. // break;
  581. // case 323: //海外游学部
  582. // //66 3 19 游学顾问
  583. // depId = 19;
  584. // postId = 66;
  585. // break;
  586. // case 335: //会议会展策划部
  587. // //15 5 经理
  588. // //16 5 文案策划
  589. // //17 5 活动执行
  590. // //18 5 平面设计师
  591. // //19 5 3D设计师
  592. // //56 5 销售
  593. // //46 5 网络推广
  594. // //57 5 市场推广
  595. // //67 5 策划主管
  596. // depId = 5;
  597. // if (post.Equals("会展专员")) { depId = 17; postId = 61; }
  598. // else if (post.Equals("策划执行")) postId = 16;
  599. // else if (post.Equals("策划主管")) postId = 67;
  600. // else if (post.Equals("策划")) postId = 16;
  601. // else if (post.Equals("文案")) postId = 16;
  602. // else if (post.Equals("策划执行")) postId = 17;
  603. // else if (post.Equals("执行专员 ")) postId = 17;
  604. // break;
  605. // case 761://项目部
  606. // //20 6 经理
  607. // //21 6 市场专员
  608. // //53 6 主管
  609. // if (post.Equals("销售主管")) { depId = 6; postId = 20; }
  610. // else if (post.Equals("场站经理")) { depId = 6; postId = 53; }
  611. // else if (post.Equals("暂无")) { depId = 5; postId = 58; }
  612. // else
  613. // {
  614. // if (oldUser.CnName.Equals("许婷"))
  615. // {
  616. // depId = 5; postId = 16;
  617. // }
  618. // else if (oldUser.CnName.Equals("陈雪"))
  619. // {
  620. // depId = 5; postId = 17;
  621. // }
  622. // }
  623. // break;
  624. // default:
  625. // break;
  626. // }
  627. // #endregion
  628. // string idCrad = string.Empty;
  629. // string idCradNumber = string.Empty;
  630. // DateTime? birthday = null;
  631. // if (!string.IsNullOrEmpty(oldUser.IDCard))
  632. // {
  633. // idCrad = oldUser.IDCard.Trim();
  634. // #region 处理身份证Number 出生日期
  635. // if (idCrad.ValidateIdNumber())
  636. // {
  637. // idCradNumber = idCrad.ToString();
  638. // string birthDate = idCrad.Substring(6, 8); // 提取从第6位开始的8个字符,即出生日期部分
  639. // birthday = new DateTime(int.Parse(birthDate.Substring(0, 4)), int.Parse(birthDate.Substring(4, 2)), int.Parse(birthDate.Substring(6, 2)));
  640. // }
  641. // #endregion
  642. // }
  643. // DateTime? startWorkDate = null;
  644. // #region 判断是否是日期格式的字符串
  645. // string format = "yyyy-MM-dd"; // 日期格式
  646. // DateTime date;
  647. // bool isParsed = DateTime.TryParseExact(oldUser.StartWorkDate, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out date);
  648. // if (isParsed)
  649. // {
  650. // startWorkDate = date;
  651. // }
  652. // #endregion
  653. // int education = 0;
  654. // #region 处理学历
  655. // if (!string.IsNullOrEmpty(oldUser.Education))
  656. // {
  657. // //0 未设置 1 小学、2 初中、3 高中、4 专科、5 本科、6 研究生
  658. // if (oldUser.Education.Equals("本科")) education = 5;
  659. // else if (oldUser.Education.Equals("大学专科")) education = 4;
  660. // else if (oldUser.Education.Equals("大专")) education = 4;
  661. // else if (oldUser.Education.Equals("全日制本科")) education = 5;
  662. // else if (oldUser.Education.Equals("硕士")) education = 6;
  663. // else if (oldUser.Education.Equals("硕士研究生")) education = 6;
  664. // else if (oldUser.Education.Equals("学士")) education = 6;
  665. // else if (oldUser.Education.Equals("研究生")) education = 6;
  666. // else if (oldUser.Education.Equals("专科")) education = 4;
  667. // }
  668. // #endregion
  669. // int theOrAdultEducation = 0;
  670. // #region 处理统招/成人
  671. // if (!string.IsNullOrEmpty(oldUser.TheOrAdultEducation))
  672. // {
  673. // //0 未设置 1 成教 2 统招 3 留学
  674. // if (oldUser.TheOrAdultEducation.Equals("成教")) theOrAdultEducation = 1;
  675. // if (oldUser.TheOrAdultEducation.Equals("自考")) theOrAdultEducation = 1;
  676. // else if (oldUser.TheOrAdultEducation.Equals("统招")) theOrAdultEducation = 2;
  677. // else if (oldUser.TheOrAdultEducation.Equals("留学")) theOrAdultEducation = 3;
  678. // }
  679. // #endregion
  680. // Sys_Users user = new Sys_Users()
  681. // {
  682. // Id = oldUser.Id,
  683. // CnName = oldUser.CnName,
  684. // EnName = oldUser.EnName,
  685. // Number = oldUser.Number,
  686. // CompanyId = 2,
  687. // DepId = depId,
  688. // JobPostId = postId,
  689. // Password = oldUser.Password,
  690. // Sex = oldUser.Sex,
  691. // Ext = oldUser.Ext,
  692. // Phone = oldUser.Phone,
  693. // UrgentPhone = oldUser.UrgentPhone,
  694. // Email = oldUser.Email,
  695. // Address = oldUser.Address,
  696. // Edate = oldUser.Edate,
  697. // Rdate = oldUser.Rdate,
  698. // Seniority = oldUser.Seniority,
  699. // Birthday = birthday,
  700. // IDCard = idCradNumber,
  701. // StartWorkDate = startWorkDate,
  702. // GraduateInstitutions = oldUser.GraduateInstitutions,
  703. // Professional = oldUser.Professional,
  704. // Education = education,
  705. // TheOrAdultEducation = theOrAdultEducation,
  706. // MaritalStatus = oldUser.MaritalStatus,
  707. // HomeAddress = oldUser.HomeAddress,
  708. // UsePeriod = oldUser.UsePeriod,
  709. // WorkExperience = oldUser.WorkExperience,
  710. // Certificate = oldUser.Certificate,
  711. // HrAudit = 1,
  712. // CreateUserId = 208,
  713. // CreateTime = DateTime.Now,
  714. // DeleteUserId = null,
  715. // DeleteTime = string.Empty,
  716. // Remark = oldUser.Remark,
  717. // IsDel = oldUser.IsDel,
  718. // };
  719. // newOaUserDatas.Add(user);
  720. // }
  721. // if (newOaUserDatas.Count > 0)
  722. // {
  723. // //执行删除
  724. // bool resetStatus = _sqlSuar.DbMaintenance.TruncateTable<Sys_Users>();
  725. // //执行批量添加
  726. // int addTotal = await _sqlSuar.Insertable(newOaUserDatas).IgnoreColumns(it => it.Id).ExecuteCommandAsync();
  727. // }
  728. // view = new
  729. // {
  730. // Code = 200,
  731. // Msg = "操作成功!",
  732. // Data = newOaUserDatas
  733. // };
  734. // }
  735. // catch (Exception ex)
  736. // {
  737. // view = new
  738. // {
  739. // Code = 400,
  740. // Msg = ex.Message
  741. // };
  742. // }
  743. // return Ok(JsonView(view));
  744. //}
  745. /// <summary>
  746. /// 测试
  747. /// 创建员工号
  748. /// </summary>
  749. /// <param name="depId">部门Id</param>
  750. /// <returns></returns>
  751. [HttpPost("TestCreateUserNumber")]
  752. [ProducesResponseType(typeof(LoginView), StatusCodes.Status200OK)]
  753. public async Task<IActionResult> TestCreateUserNumber(int depId)
  754. {
  755. try
  756. {
  757. var number = await _loginRep.CreateNumber(depId);
  758. return Ok(JsonView(true, "操作成功!", number));
  759. }
  760. catch (Exception ex)
  761. {
  762. return Ok(JsonView(false, "操作失败!", ex.Message));
  763. }
  764. }
  765. }
  766. }