public async Task <ResponseResult <ProductOrderEntity> > SyncOrder2() { var result = ResponseResult <ProductOrderEntity> .Default(); using (IDbSession session = SessionFactory.CreateSession()) { try { session.BeginTrans(); var entity = ProductOrderService.SyncOrder(session.Connection, session.Transaction); session.Commit(); //发布消息主题 var wfResult = PublishProductOrderCreateMessage(entity); if (wfResult.Status == 1) { result = ResponseResult <ProductOrderEntity> .Success(entity, string.Format("同步订单数据状态:{0}", wfResult.Status)); } else { session.Rollback(); result = ResponseResult <ProductOrderEntity> .Error( string.Format("订单消息启动流程失败失败, 错误:{0}", wfResult.Message) ); } } catch (System.Exception ex) { session.Rollback(); result = ResponseResult <ProductOrderEntity> .Error( string.Format("同步订单{0}失败, 错误:{1}", "ProductOrder", ex.Message) ); } } return(result); }
public ResponseResult TaskBind(string taskName, string routeName, string loginName, string shipName) { var result = ResponseResult.Default(); TaskService taskService = new TaskService(); try { if (string.IsNullOrEmpty(routeName)) { return(ResponseResult.Error("路径不能为空")); } if (string.IsNullOrEmpty(taskName)) { return(ResponseResult.Error("任务名称不能为空")); } if (string.IsNullOrEmpty(loginName)) { return(ResponseResult.Error("登录名称不能为空")); } if (string.IsNullOrEmpty(shipName)) { } if (taskService.RouteChange(taskName, routeName, loginName, shipName)) { return(ResponseResult.Success("绑定成功")); } else { return(ResponseResult.Error("绑定失败")); } } catch (System.Exception ex) { result = ResponseResult.Error(ex.Message); } return(result); }
public ResponseResult RunProcessApp(WfAppRunner runner) { IWorkflowService wfService = new WorkflowService(); IDbConnection conn = SessionFactory.CreateConnection(); IDbTransaction trans = null; try { trans = conn.BeginTransaction(); var result = wfService.RunProcessApp(conn, runner, trans); if (result.Status == WfExecutedStatus.Success) { trans.Commit(); return(ResponseResult.Success()); } else { trans.Rollback(); return(ResponseResult.Error(result.Message)); } } catch (WorkflowException w) { trans.Rollback(); return(ResponseResult.Error(w.Message)); } finally { trans.Dispose(); if (conn.State == ConnectionState.Open) { conn.Close(); } } }
public ResponseResult StartProcess([FromBody] WfAppRunner starter) { IWorkflowService wfService = new WorkflowService(); IDbConnection conn = SessionFactory.CreateConnection(); IDbTransaction trans = null; try { trans = conn.BeginTransaction(); WfExecutedResult result = wfService.StartProcess(conn, starter, trans); trans.Commit(); int newProcessInstanceID = result.ProcessInstanceIDStarted; if (result.Status == WfExecutedStatus.Success) { return(ResponseResult.Success()); } else { return(ResponseResult.Error(result.Message)); } } catch (WorkflowException w) { trans.Rollback(); return(ResponseResult.Error(w.Message)); } finally { trans.Dispose(); if (conn.State == ConnectionState.Open) { conn.Close(); } } }
public ResponseResult Run() { var runner = _appRunner; var result = ResponseResult.Default(); try { string amount = string.Empty; IWorkflowService wfService = new WorkflowService(); //var wfResult = wfService.CreateRunner(runner) // .Run(); var wfResult = wfService.CreateRunner(runner.UserID, runner.UserName) .UseApp(runner.AppInstanceID, runner.AppName, runner.AppInstanceCode) .UseProcess(runner.ProcessGUID, runner.Version) //.NextStep(runner.NextActivityPerformers) //.NextStepInt(NextPerformerIntTypeEnum.Single) .IfCondition(runner.Conditions) .Subscribe(EventFireTypeEnum.OnActivityExecuting, (delegateContext, delegateService) => { if (delegateContext.ActivityCode == "Task1") { delegateService.SaveVariable(ProcessVariableTypeEnum.Process, "name", "book-task1"); delegateService.SaveVariable(ProcessVariableTypeEnum.Process, "amount", "50"); } return(true); }) .Run(); result = ResponseResult.Success(wfResult.Message); } catch (System.Exception ex) { result = ResponseResult.Error(ex.Message); } return(result); }
public ResponseResult UpgradeProcess([FromBody] ProcessEntity entity) { var result = ResponseResult.Default(); try { var wfService = new WorkflowService(); var process = wfService.GetProcessByID(entity.ID); int newVersion = 1; var parsed = int.TryParse(process.Version, out newVersion); if (parsed == true) { newVersion = newVersion + 1; } wfService.UpgradeProcess(process.ProcessGUID, process.Version, newVersion.ToString()); result = ResponseResult.Success(LocalizeHelper.GetDesignerMessage("wf2xmlcontroller.upgradeprocess.success")); } catch (System.Exception ex) { result = ResponseResult.Error(LocalizeHelper.GetDesignerMessage("wf2xmlcontroller.upgradeprocess.error", ex.Message)); } return(result); }
public ResponseResult <ReturnData> AppGetReturnData(string shipId) { var result = ResponseResult <ReturnData> .Default(); AppService appService = new AppService(); try { if (string.IsNullOrEmpty(shipId)) { return(ResponseResult <ReturnData> .Error("shipId不能为空")); } else { ReturnData returndata = appService.AppGetRenturnData(Convert.ToInt32(shipId)); return(ResponseResult <ReturnData> .Success(returndata, "获取返回数据成功")); } } catch (System.Exception ex) { result = ResponseResult <ReturnData> .Error(ex.Message); } return(result); }
public ResponseResult <AppRoute> AppGetLastRoute(string shipId) { var result = ResponseResult <AppRoute> .Default(); AppService appService = new AppService(); try { if (string.IsNullOrEmpty(shipId)) { return(ResponseResult <AppRoute> .Error("shipId不能为空")); } else { AppRoute lastRoute = appService.AppGetLastRoute(Convert.ToInt32(shipId)); return(ResponseResult <AppRoute> .Success(lastRoute, "获取最新路径成功")); } } catch (System.Exception ex) { result = ResponseResult <AppRoute> .Error(ex.Message); } return(result); }
public ResponseResult <WaterData> GetDataByTN(string loginName, string taskName, string page, string limit) { var result = ResponseResult <WaterData> .Default(); WaterDataService waterService = new WaterDataService(); List <WaterData> datas = new List <WaterData>(); int newcount = 0; try { if (string.IsNullOrEmpty(loginName)) { return(ResponseResult <WaterData> .Error("登录名不能为空")); } if (string.IsNullOrEmpty(taskName)) { return(ResponseResult <WaterData> .Error("任务名不能为空")); } else { datas = waterService.GetDataByTN(loginName, taskName, Convert.ToInt32(page), Convert.ToInt32(limit)); newcount = waterService.GetDataByTNCount(loginName, taskName); result = ResponseResult <WaterData> .DataSuccess(datas, newcount, "获取数据信息成功"); if (newcount == 0) { result = ResponseResult <WaterData> .Error("无记录"); } } } catch (System.Exception ex) { result = ResponseResult <WaterData> .Error(ex.Message); } return(result); }
public ResponseResult <Users> GetUserEntity(string loginName) { var result = ResponseResult <Users> .Default(); UserService userService = new UserService(); try { if (string.IsNullOrEmpty(loginName)) { return(ResponseResult <Users> .Error("用户名不能为空!")); } else { Users user = userService.GetUserEntity(loginName); result = ResponseResult <Users> .Success(user, "获取成功"); } } catch (System.Exception ex) { result = ResponseResult <Users> .Error(ex.Message); } return(result); }
/// <summary> /// list comments on a post /// </summary> /// <param name="postId"></param> /// <returns></returns> public ResponseResult <IEnumerable <PostCommentDTO> > GetCommentsByPost(Guid postId) { try { var commentsByPost = CommentRepository .Get() .Where(c => c.IdPost == postId) .Select(c => new PostCommentDTO() { Id = c.Id, IdPerson = c.IdPerson, Comment = c.Comment, IdPost = c.IdPost, Author = c.IdPerson != null ? PersonRepository.GetById((Guid)c.IdPerson).FullName : "Anonymus" }) .ToList(); return(ResponseResult <IEnumerable <PostCommentDTO> > .Success(commentsByPost)); } catch (Exception ex) { return(ResponseResult <IEnumerable <PostCommentDTO> > .Error(ex.Message)); } }
public ResponseResult <EntityInfoEntity> InsertEntityRowFlow(dynamic eav) { var result = ResponseResult <EntityInfoEntity> .Default(); try { //先保存表单 EntityInfoWithAttrValueListItem entityAttrValueItem = JsonConvert.DeserializeObject <EntityInfoWithAttrValueListItem>( eav.EntityInfoWithAttrValueListItem.ToString()); int newID = FBDataService.InsertRow(entityAttrValueItem); var entityInfo = new EntityInfoEntity(); entityInfo.ID = newID; var wfAppRunner = JsonConvert.DeserializeObject <WfAppRunner>(eav.WfAppRunner.ToString()); wfAppRunner.AppInstanceID = newID.ToString(); WfAppInteropService wfService = new WfAppInteropService(); WfExecutedResult wfResult = wfService.StartProcess(wfAppRunner); //返回结果 if (wfResult.Status == WfExecutedStatus.Success) { result = ResponseResult <EntityInfoEntity> .Success(entityInfo, "表单数据已经保存,流程已经启动!"); } else { result = ResponseResult <EntityInfoEntity> .Error(wfResult.Message); } } catch (System.Exception ex) { result = ResponseResult <EntityInfoEntity> .Error( string.Format("保存实体及其扩展属性失败, 错误:{0}", ex.Message) ); } return(result); }
public ResponseResult <ProcessEntity> CreateProcess([FromBody] ProcessFileEntity fileEntity) { var result = ResponseResult <ProcessEntity> .Default(); try { ProcessEntity entity = null; //根据模板类型来创建流程 if (fileEntity.TemplateType == ProcessTemplateType.Blank) { entity = new ProcessEntity { ProcessGUID = fileEntity.ProcessGUID, ProcessName = fileEntity.ProcessName, ProcessCode = fileEntity.ProcessCode, Version = fileEntity.Version, IsUsing = fileEntity.IsUsing, Description = fileEntity.Description, }; var wfService = new WorkflowService(); var processID = wfService.CreateProcess(entity); entity.ID = processID; } else { //模板默认生成XML内容 entity = ProcessGraphFactory.CreateProcess(fileEntity); } result = ResponseResult <ProcessEntity> .Success(entity); } catch (System.Exception ex) { result = ResponseResult <ProcessEntity> .Error(string.Format("创建流程记录失败,错误:{0}", ex.Message)); } return(result); }
public ResponseResult DeleteInstance([FromBody] ProcessQuery query) { var result = ResponseResult.Default(); var wfService = new WorkflowService(); try { var isOK = wfService.DeleteInstanceInt(query.ProcessGUID, query.Version); if (isOK == true) { result = ResponseResult.Success("已经成功删除!"); } else { result = ResponseResult.Error("删除失败,或者记录已经为空!"); } } catch (System.Exception ex) { result = ResponseResult.Error(ex.Message); } return(result); }
public ResponseResult WithdrawProcess([FromBody] WfAppRunner runner) { var result = ResponseResult.Default(); var wfService = new WorkflowService(); try { var wfResult = wfService.WithdrawProcess(runner); if (wfResult.Status == WfExecutedStatus.Success) { result = ResponseResult.Success(wfResult.Message); } else { result = ResponseResult.Error(wfResult.Message); } } catch (System.Exception ex) { result = ResponseResult.Error(ex.Message); } return(result); }
public ResponseResult <EntityProcessView> GetEntityProcessView(int id) { var result = ResponseResult <EntityProcessView> .Default(); try { var view = new EntityProcessView(); var wfService = new WorkflowService(); var processList = wfService.GetProcessListSimple().ToList(); view.ProcessList = processList; var entityProcess = FBMasterService.GetEntityProcess(id); view.EntityProcess = entityProcess; result = ResponseResult <EntityProcessView> .Success(view); } catch (System.Exception ex) { result = ResponseResult <EntityProcessView> .Error( string.Format("获取表单绑定流程数据失败!{0}", ex.Message) ); } return(result); }
public ResponseResult <string> delBook([FromQuery] string token, int id) { claim = (JwtClaim)_accessor.HttpContext.Items["user"]; try { if (id == 0) { return(ResponseResult <string> .Error("参数异常")); } var b = SystemService.delBook(id, connstr); if (b) { return(ResponseResult <string> .Success("操作成功", "操作成功")); } else { return(ResponseResult <string> .Success("操作失败", "操作失败")); } } catch (Exception ex) { return(ResponseResult <string> .Error("系统异常")); } }
public ResponseResult GetAllDataCount(string loginName) { var result = ResponseResult.Default(); WaterDataService waterService = new WaterDataService(); string counts = null; try { if (string.IsNullOrEmpty(loginName)) { return(ResponseResult.Error("登录名不能为空")); } else { counts = waterService.GetAllDataCount(loginName).ToString(); result = ResponseResult.Success(counts); } } catch (System.Exception ex) { result = ResponseResult.Error(ex.Message); } return(result); }
public ResponseResult <List <TaskViewEntity> > QueryCompletedTasks([FromBody] TaskQuery query) { var result = ResponseResult <List <TaskViewEntity> > .Default(); try { var taskList = new List <TaskViewEntity>(); var wfService = new WorkflowService(); var itemList = wfService.GetCompletedTasks(query); if (itemList != null) { taskList = itemList.ToList(); } result = ResponseResult <List <TaskViewEntity> > .Success(taskList); } catch (System.Exception ex) { result = ResponseResult <List <TaskViewEntity> > .Error(string.Format( "获取已办任务数据失败, 异常信息:{0}", ex.Message)); } return(result); }
public IActionResult GetAllDepts() { var response = new ResponseResult <IEnumerable <DeptResult> >(); List <SysDept> dataList = null; using (_dbContext) { dataList = _dbContext.SysDept.ToList(); } if (dataList.IsEmpty()) { return(Ok(response.Error(ResponseCode.ERROR_CODE__DB__NO_ROW, "请先添加数据"))); } var menuResults = from item in dataList.Where(a => a.ParentId == 0).OrderBy(a => a.OrderNum) select new DeptResult { Id = item.Id, ParentId = item.ParentId, Ancestors = item.Ancestors, DeptName = item.DeptName, OrderNum = item.OrderNum, Leader = item.Leader, Phone = item.Phone, Email = item.Email, Status = item.Status, DelFlag = item.DelFlag, CreateBy = item.CreateBy, CreatedAt = item.CreatedAt?.ToUtcDateTimeString(), UpdateBy = item.UpdateBy, UpdatedAt = item.UpdatedAt?.ToUtcDateTimeString(), Remark = item.Remark, ChildrenList = GetChildDatas(item.Id, dataList) }; return(Ok(response.Success("数据获取成功", menuResults))); }
public ResponseResult <List <Performer> > GetUserByRole(string id) { var result = ResponseResult <List <Performer> > .Default(); try { var performList = new List <Performer>(); var wfService = new WorkflowService(); var itemList = wfService.GetUserListByRole(id).ToList(); foreach (var item in itemList) { Performer performer = new Performer(item.UserID.ToString(), item.UserName); performList.Add(performer); } result = ResponseResult <List <Performer> > .Success(performList, "成功获取流角色用户数据!"); } catch (System.Exception ex) { result = ResponseResult <List <Performer> > .Error(string.Format( "获取角色用户数据失败, 异常信息:{0}", ex.Message)); } return(result); }
// This method gets called by the runtime. Use this method to add services to the container. /// <summary> /// Configures the services. /// </summary> /// <param name="services">The services.</param> public void ConfigureServices(IServiceCollection services) { var oAuthCorsOrigins = Configuration.GetValue <string>("OAuthCorsOrigins").Split(','); //跨域请求 (CORS):https://docs.microsoft.com/zh-cn/aspnet/core/security/cors?view=aspnetcore-3.1 //Demo:https://github.com/dotnet/AspNetCore.Docs/blob/master/aspnetcore/security/cors/sample/CorsExample4/Startup.cs services.AddCors(options => { options.AddPolicy("OAuthCorsPolicy", builder => { builder.WithOrigins(oAuthCorsOrigins) .AllowAnyHeader() .AllowAnyMethod() .AllowCredentials(); //指定处理cookie }); options.AddPolicy("AllowAllOrigins", builder => { builder.AllowAnyOrigin(); //允许任何来源的主机访问 }); }); services.AddMemoryCache(); services.AddHttpContextAccessor(); services.AddSingleton <IActionContextAccessor, ActionContextAccessor>(); var appSettingsSection = Configuration.GetSection("AppSettings"); services.Configure <AppAuthenticationSettings>(appSettingsSection); // JWT var appSettings = appSettingsSection.Get <AppAuthenticationSettings>(); services.AddJwtBearerAuthentication(appSettings); services.Configure <RouteOptions>(options => options.LowercaseUrls = true); services.AddAutoMapper(typeof(Startup)); services.Configure <WebEncoderOptions>(options => options.TextEncoderSettings = new TextEncoderSettings(UnicodeRanges.BasicLatin, UnicodeRanges.CjkUnifiedIdeographs) ); //add basic MVC feature var mvcBuilder = services.AddControllers(); mvcBuilder.AddNewtonsoftJson(); //serializes JSON with camel case names by default, use this code to avoid it //mvcBuilder.AddNewtonsoftJson(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver()); mvcBuilder.ConfigureApiBehaviorOptions(options => { //模型验证自定义返回格式 options.InvalidModelStateResponseFactory = c => { var errors = string.Join('\n', c.ModelState.Values.Where(v => v.Errors.Count > 0) .SelectMany(v => v.Errors) .Select(v => v.ErrorMessage)); var response = new ResponseResult <object>(); return(new OkObjectResult(response.Error(ResponseCode.INVALID_PARAMS, errors))); }; }); //add fluent validation mvcBuilder.AddFluentValidation(configuration => { //register all available validators from Nop assemblies //var assemblies = mvcBuilder.PartManager.ApplicationParts // .OfType<AssemblyPart>() // .Where(part => part.Name.StartsWith("Nop", StringComparison.InvariantCultureIgnoreCase)) // .Select(part => part.Assembly); //configuration.RegisterValidatorsFromAssemblies(assemblies); configuration.RegisterValidatorsFromAssemblies(new Assembly[] { Assembly.GetExecutingAssembly() }); //configuration.RegisterValidatorsFromAssemblyContaining<LoginRequestValidator>(); //configuration.RegisterValidatorsFromAssemblyContaining(typeof(BaseValidator<>)); //implicit/automatic validation of child properties configuration.ImplicitlyValidateChildProperties = true; }); string dbType = Configuration.GetValue <string>("DbType"); services.AddDbContext <D2CmsDbContext>(options => { if (dbType == "MySql") { // replace with your connection string options.UseMySql(Configuration.GetConnectionString("DefaultConnection"), mySqlOptions => mySqlOptions // replace with your Server Version and Type .ServerVersion(new Version(8, 0, 18), ServerType.MySql)); } else { options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")); } // 如果使用SQL Server 2008数据库,请添加UseRowNumberForPaging的选项 // 参考资料:https://github.com/aspnet/EntityFrameworkCore/issues/4616 // 【重要说明】:2020-03-23更新,微软官方最新的Entity Framework Core已不再支持UseRowNumberForPaging(),请尽量使用SQL Server 2012 +版本 //options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"),b=>b.UseRowNumberForPaging()) options.EnableSensitiveDataLogging(); }); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "D2 CMS API", Version = "v1" }); var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); c.IncludeXmlComments(xmlPath); }); // 注入日志 services.AddLogging(config => { config.AddLog4Net(); }); }