AuthController.cs 43 KB

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