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