AuthController.cs 34 KB

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