AuthController.cs 33 KB

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