AuthController.cs 33 KB

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