AuthController.cs 44 KB

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