AuthController.cs 33 KB

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