AuthController.cs 32 KB

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