AuthController.cs 34 KB

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