AuthController.cs 43 KB

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