AuthController.cs 44 KB

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