AuthController.cs 34 KB

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