AuthController.cs 43 KB

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