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