AuthController.cs 43 KB

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