AuthController.cs 34 KB

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