AuthController.cs 42 KB

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