public async Task <BaseResponse> CronJobAdd(CronJobAddRequest request) { //查看是否有同名定时任务 var nameJob = await _cronJobRepository.FirstOrDefaultAsync(c => c.Name == request.Name); if (nameJob != null) { return(BaseResponse.Failed("已有同名任务")); } var cronJob = _mapper.Map <CronJob>(request); cronJob.CreateTime = DateTime.Now; cronJob.UpdateTime = DateTime.Now; cronJob.JobState = JobStateEnum.启用; await _cronJobRepository.InsertAsync(cronJob); await _cronJobRepository.SaveChangesAsync(); if (_jobCronTrigger.RunJob(cronJob)) { return(BaseResponse <CronJob> .Ok(cronJob)); } return(BaseResponse.Failed()); }
public async Task <BaseResponse> StartWorkBatch(string compIds) { var compStrArray = compIds.Split(','); List <Task <BaseResponse> > taskList = new List <Task <BaseResponse> >(); foreach (var item in compStrArray) { long compId = Convert.ToInt64(item); // 创建task taskList.Add(Task.Factory.StartNew(() => BaseResponse.Ok())); taskList.Add(Task.Factory.StartNew(() => BaseResponse.Ok())); } var array = taskList.ToArray(); Task.WaitAll(array); foreach (var item in array) { if (item.Result.Code != 1) { return(BaseResponse.Failed()); } } return(BaseResponse.Ok()); }
public async Task <BaseResponse> AddUser(BaseRequest request) { var userParent = await _userRepository.FirstOrDefaultAsync(c => c.Id == request.UserId); if (userParent == null) { return(BaseResponse.Failed("未找到对应父级用户")); } User user = new User { UserName = "******", UserAccount = "1233123213123", UserPassWord = "******", CertificateNo = "123131", Mobile = 13313331333, IsVerify = IsVerifyEnum.可用, LevelNum = userParent.LevelNum + 1, LevelCode = userParent.LevelCode, ParentId = userParent.Id }; await _userRepository.InsertAsync(user); using (var transaction = await _userRepository.GetDbContext().Database.BeginTransactionAsync()) { await _userRepository.SaveChangesAsync(); user.LevelCode = $"{userParent.LevelCode}{user.Id},";//左右都加逗号是防止like到冗余数据 await _userRepository.SaveChangesAsync(); transaction.Commit(); } return(BaseResponse.Ok()); }
public async Task <BaseResponse> VehicleLicenseObject( ) { String url = "https://aip.baidubce.com/rest/2.0/ocr/v1/vehicle_license?access_token=24.c469e03b92fd4fd5a8e61da8a3e2244c.2592000.1579330537.282335-17066373"; //读图片转为Base64String System.Drawing.Bitmap bmp1 = new System.Drawing.Bitmap(Path.Combine("D:\\", "1.png")); string userPhoto; using (MemoryStream ms1 = new MemoryStream()) { bmp1.Save(ms1, System.Drawing.Imaging.ImageFormat.Png); byte[] arr1 = new byte[ms1.Length]; ms1.Position = 0; ms1.Read(arr1, 0, (int)ms1.Length); ms1.Close(); userPhoto = Convert.ToBase64String(arr1); } //百度要求对base64进行编码 var encodedPhoto = System.Web.HttpUtility.UrlEncode(userPhoto); object data = new { image = encodedPhoto, detect_direction = "false", accuracy = "normal", vehicle_license_side = "front" }; string result = await _defaultClient.Client.FromCodedObjectAsync(url, data); var jObject = JObject.Parse(result); if (jObject["error_code"] != null) { return(BaseResponse.Failed(jObject["error_code"].ToString() + ";" + jObject["error_msg"].ToString())); } ; return(BaseResponse <object> .Ok(jObject)); }
public async Task <BaseResponse <PageData <User> > > GetUserList(PageRequest request) { var userThis = await _userRepository.FirstOrDefaultAsync(c => c.Id == request.UserId); if (userThis == null) { return(BaseResponse <PageData <User> > .Failed("未找到对应公司", new PageData <User>())); } return(BaseResponse <PageData <User> > .Ok(await _userRepository.GetUserList(request, userThis.LevelCode))); }
public async Task <BaseResponse> UpdateUser(UpdateUserRequest request) { var user = await _userRepository.FirstOrDefaultAsync(c => c.Id == request.UserId); if (user == null) { return(BaseResponse.Failed("未找到对应用户")); } //不重要的赋值就不模拟了 if (request.ParentId != user.ParentId) { //search parent data var userParent = await _userRepository.FirstOrDefaultAsync(c => c.Id == request.ParentId); if (userParent == null) { return(BaseResponse.Failed("未找到对应父级用户")); } string newCode = $"{userParent.LevelCode}{user.Id},"; string oldCode = user.LevelCode; int oldNum = user.LevelNum; int newNum = userParent.LevelNum + 1; int cNum = newNum - oldNum; user.LevelCode = newCode; user.LevelNum = newNum; user.ParentId = userParent.Id; //查找当前用户及其下级用户列表 var relevantUsers = await _userRepository.GetAll().Where(x => x.LevelCode.StartsWith(oldCode)).ToListAsync(); foreach (var item in relevantUsers) { if (item.Id == user.Id) { continue; } item.LevelCode = item.LevelCode.Replace(oldCode, newCode); item.LevelNum = item.LevelNum + cNum; } } await _userRepository.SaveChangesAsync(); return(BaseResponse.Ok()); }
public async Task <BaseResponse> BaiduOauth() { #region 获取token //string token; //string key =ConfigurationManager.GetValue("BaiduOauth"); //if (string.IsNullOrEmpty(key)) //{ // key="baiduOauth_token"; //} //var tokenObject = await _database.StringGetAsync(key); //if (!tokenObject.HasValue) //{ // var res=await BaiduOauth(); // if (res.Code!=1) // { // return res; // } // token=res.Data["access_token"].ToString(); // await _database.StringSetAsync(key, token, TimeSpan.FromSeconds((int)res.Data["expires_in"])); //} //else //{ // token=tokenObject.ToString(); //} #endregion String url = "https://aip.baidubce.com/oauth/2.0/token"; List <KeyValuePair <String, String> > paraList = new List <KeyValuePair <string, string> >(); paraList.Add(new KeyValuePair <string, string>("grant_type", "client_credentials")); paraList.Add(new KeyValuePair <string, string>("client_id", "dWEp78bfAvpGmcqKe7a5qY8y")); paraList.Add(new KeyValuePair <string, string>("client_secret", "XHz3WLzlbSInHfaLNUe4IGTgvFBvjopB")); string result = await _defaultClient.Client.HttpClientFromAsync(url, paraList); var jObject = JObject.Parse(result); if (jObject["error"] != null) { return(BaseResponse.Failed(jObject["error"].ToString() + ";" + jObject["error_description"].ToString())); } ; return(BaseResponse.Ok(result)); }
public async Task <BaseResponse> MessagePayNotify() { _logger.LogInformation("收到短信支付后通知"); SortedDictionary <string, string> sPara = GetRequestPost(); if (sPara.Count > 0)//判断是否有带返回参数 { Notify aliNotify = new Notify(); bool verifyResult = aliNotify.Verify(sPara, Request.Form["notify_id"], Request.Form["sign"]); string content = string.Format("交易号:{0}^订单号:{1}^交易状态:{2}^交易金额:{3}", Request.Form["trade_no"], Request.Form["out_trade_no"], Request.Form["trade_status"], Request.Form["total_fee"]); _logger.LogInformation("异步回调:" + content); if (verifyResult)//验证成功 { //商户订单号 string out_trade_no = Request.Form["out_trade_no"]; //支付宝交易号 string trade_no = Request.Form["trade_no"]; string subject = Request.Query["body"]; //交易状态 string trade_status = Request.Form["trade_status"]; if (Request.Form["trade_status"] == "TRADE_SUCCESS" || Request.Form["trade_status"] == "TRADE_FINISHED") { //判断该笔订单是否在商户网站中已经做过处理 //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序 //如果有做过处理,不执行商户的业务程序 //注意: //该种交易状态只在一种情况下出现——开通了高级即时到账,买家付款成功后。 #pragma warning disable 4014 #pragma warning restore 4014 } return(BaseResponse.Ok()); } else//验证失败 { return(BaseResponse.Failed()); } } return(BaseResponse.Failed("无通知参数")); }
public async Task <BaseResponse> StartWork(long compId) { Task <BaseResponse>[] taskArray = new Task <BaseResponse> [2]; // 创建task并启动 taskArray[0] = Task.Factory.StartNew(() => BaseResponse.Ok()); taskArray[1] = Task.Factory.StartNew(() => BaseResponse.Ok()); //会阻塞主线程,一直等待开辟的线程,直到所有子线程都执行完后再执行线程 Task.WaitAll(taskArray); if (taskArray[0].Result.Code == 1 && taskArray[1].Result.Code == 1) { return(BaseResponse.Ok()); } else { return(BaseResponse.Failed()); } }
/// <summary> /// 操作任务 /// </summary> /// <param name="jobId">任务编号</param> /// <param name="operateJobFunc">具体操作任务的委托</param> /// <returns></returns> private async Task <BaseResponse> _operateJob(long jobId, Func <CronJob, Task <bool> > operateJobFunc) { var jobDetail = await _cronJobRepository.FirstOrDefaultAsync(c => c.Id == jobId); if (jobDetail == null) { return(BaseResponse.Failed("未找到对应任务")); } else { //_setSpecificTrigger(jobDetail.TriggerType); var isSuccess = await operateJobFunc(jobDetail); if (isSuccess) { return(BaseResponse.Ok()); } return(BaseResponse.Failed()); } }
/// <summary> /// 不使用 /// </summary> /// <param name="request"></param> /// <returns></returns> public async Task <BaseResponse> CronJobUpdate(CronJobUpdateRequest request) { ////直接全更新,否可行。 ////生产语句UPDATE `cron_job` SET `CreateTime` = @p0, `CreateUser` = @p1, `CronExpress` = @p2, `Description` = @p3, `JobState` = @p4, `Name` = @p5, `RequestUrl` = @p6, `UpdateTime` = @p7, `UpdateUser` = @p8 WHERE `Id` = @p9; //_cronJobRepository.Update(request.CronJob); //await _cronJobRepository.SaveChangesAsync(); var nameJob = await _cronJobRepository.FirstOrDefaultAsync(c => c.Id == request.CronJob.Id); if (nameJob == null) { return(BaseResponse.Failed("未找到对应任务")); } //排除固定字段的更新 只更新指定改动的字段 _cronJobRepository.CompareValueAndassign(nameJob, request.CronJob); nameJob.UpdateUser = request.UserId; await _cronJobRepository.SaveChangesAsync(); return(BaseResponse <CronJob> .Ok(nameJob)); }
public async Task <BaseResponse> VehicleLicense( ) { String url = "https://aip.baidubce.com/rest/2.0/ocr/v1/vehicle_license?access_token=24.c469e03b92fd4fd5a8e61da8a3e2244c.2592000.1579330537.282335-17066373"; //读图片转为Base64String System.Drawing.Bitmap bmp1 = new System.Drawing.Bitmap(Path.Combine("D:\\", "1.png")); string userPhoto; using (MemoryStream ms1 = new MemoryStream()) { bmp1.Save(ms1, System.Drawing.Imaging.ImageFormat.Png); byte[] arr1 = new byte[ms1.Length]; ms1.Position = 0; ms1.Read(arr1, 0, (int)ms1.Length); ms1.Close(); userPhoto = Convert.ToBase64String(arr1); } List <KeyValuePair <String, String> > paraList = new List <KeyValuePair <string, string> >(); paraList.Add(new KeyValuePair <string, string>("image", userPhoto)); paraList.Add(new KeyValuePair <string, string>("detect_direction", "false")); paraList.Add(new KeyValuePair <string, string>("accuracy", "normal")); paraList.Add(new KeyValuePair <string, string>("vehicle_license_side", "front")); string result = await _defaultClient.Client.HttpClientFromAsync(url, paraList); var jObject = JObject.Parse(result); if (jObject["error_code"] != null) { return(BaseResponse.Failed(jObject["error_code"].ToString() + ";" + jObject["error_msg"].ToString())); } ; return(BaseResponse.Ok(result)); }