AuthController.cs 44 KB

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