AuthController.cs 33 KB

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