Browse Source

修正指定人控件不能正确保存数据的问题

luocaiyang 3 years ago
parent
commit
17503454c6

+ 1 - 0
wispro.sp.api/Controllers/WorkflowEngineController.cs

@@ -21,6 +21,7 @@ namespace wispro.sp.api.Controllers
     public class WorkflowEngineController : ControllerBase
     {
         spDbContext Context;
+        
 
         public WorkflowEngineController(spDbContext context)
         {

+ 13 - 7
wispro.sp.web/Components/InputValueSetting.razor.cs

@@ -76,11 +76,11 @@ namespace wispro.sp.web.Components
             }
         }
 
-        void Delete(entity.workflowDefine.InputValueSetting setting)
+        async void Delete(entity.workflowDefine.InputValueSetting setting)
         {
-            Console.WriteLine($"begin Delete:{ System.Text.Json.JsonSerializer.Serialize(EditAction)}");
+            //Console.WriteLine($"begin Delete:{ System.Text.Json.JsonSerializer.Serialize(EditAction)}");
 
-            Console.WriteLine($"Delete Setting:{ System.Text.Json.JsonSerializer.Serialize(setting)}");
+            //Console.WriteLine($"Delete Setting:{ System.Text.Json.JsonSerializer.Serialize(setting)}");
 
             foreach (var temObj in EditAction.InputValueSettingObjects)
             {
@@ -169,14 +169,20 @@ namespace wispro.sp.web.Components
                 }
             }
 
-            Console.WriteLine($"End Delete:{ System.Text.Json.JsonSerializer.Serialize(EditAction)}");
+            if (setting.Id > 0)
+            {
+                //添加从数据库中删除代码;
+                await wfService.DeleteInputValueSetting(setting.Id);
+            }
+            //Console.WriteLine($"End Delete:{ System.Text.Json.JsonSerializer.Serialize(EditAction)}");
         }
+
         async void Delete(share.InputValueSettingObject setting)
         {
 
-            Console.WriteLine($"Begin Delete:{ System.Text.Json.JsonSerializer.Serialize(EditAction)}");
+            //Console.WriteLine($"Begin Delete:{ System.Text.Json.JsonSerializer.Serialize(EditAction)}");
 
-            Console.WriteLine($"Delete Setting:{ System.Text.Json.JsonSerializer.Serialize(setting)}");
+            //Console.WriteLine($"Delete Setting:{ System.Text.Json.JsonSerializer.Serialize(setting)}");
             //此处添加删除代码
             if (EditAction.InputValueSettingObjects.Contains(setting))
             {
@@ -238,7 +244,7 @@ namespace wispro.sp.web.Components
                 await wfService.DeleteInputValueSetting(setting.InputValueSetting.Id);
             }
 
-            Console.WriteLine($"End Delete:{ System.Text.Json.JsonSerializer.Serialize(EditAction)}");
+            //Console.WriteLine($"End Delete:{ System.Text.Json.JsonSerializer.Serialize(EditAction)}");
 
             StateHasChanged();
         }

+ 17 - 6
wispro.sp.web/Components/ResponseManCondition.razor

@@ -10,9 +10,6 @@
         </Select>
     </SpaceItem>
     <SpaceItem>
-
-
-
         @switch (UserField.UserConditionType)
         {
             case entity.workflowDefine.UserConditionType.Department:
@@ -42,13 +39,23 @@
                 break;
             case entity.workflowDefine.UserConditionType.Staff:
                 <div style="width:200px;">
-                    <wispro.sp.web.Components.UserConditionInput Workflow="Workflow" UserType="@UserField.UserType" UserValue="@UserField.UserValue" />
+
+                    <wispro.sp.web.Components.UserConditionInput 
+                                            Workflow="Workflow" 
+                                            @ref="UserConditionInput"
+                                            UserValue="@UserField.UserValue"
+                                            OnSelectedChange="OnUserValueChange"/>
                 </div>
                 break;
             case entity.workflowDefine.UserConditionType.UserDepartment:
                 <Space>
                     <SpaceItem>
-                        <div style="width:180px;"><wispro.sp.web.Components.UserConditionInput Workflow="Workflow" UserType="@UserField.UserType" UserValue="@UserField.UserValue" /></div>
+                        <div style="width:180px;">
+                        <wispro.sp.web.Components.UserConditionInput 
+                                            Workflow="Workflow" 
+                                            @ref="UserConditionInput" UserValue="@UserField.UserValue"
+                                            OnSelectedChange="OnUserValueChange"/>
+                        </div>
                     </SpaceItem>
                     <SpaceItem>
                         的部门
@@ -59,7 +66,11 @@
                 <Space>
                     <SpaceItem>
                         <div style="width:200px;">
-                            <wispro.sp.web.Components.UserConditionInput Workflow="Workflow" UserType="@UserField.UserType" UserValue="@UserField.UserValue" />
+                            <wispro.sp.web.Components.UserConditionInput 
+                                            Workflow="Workflow" 
+                                            @ref="UserConditionInput" 
+                                            UserValue="@UserField.UserValue"
+                                            OnSelectedChange="OnUserValueChange"  />
                         </div>
                     </SpaceItem>
                     <SpaceItem>

+ 7 - 1
wispro.sp.web/Components/ResponseManCondition.razor.cs

@@ -12,7 +12,7 @@ namespace wispro.sp.web.Components
 {
     public partial class ResponseManCondition
     {
-        
+        UserConditionInput UserConditionInput;
         UserConditionType userConditionType;
         
         UserType _userType;
@@ -158,5 +158,11 @@ namespace wispro.sp.web.Components
         {
             UserField.Positon = position.Id.ToString();
         }
+
+        void OnUserValueChange(UserItem userItem)
+        {
+            UserField.UserValue = userItem.Value;
+            UserField.UserType = userItem.UserType;
+        }
     }
 }

+ 1 - 1
wispro.sp.web/Components/UserConditionInput.razor

@@ -1,5 +1,5 @@
 <Select DataSource="@UserItems"
-        @bind-Value="@_selectedValue"
+        @bind-Value="@UserValue"
         ValueName="@nameof(UserItem.Value)"
         LabelName="@nameof(UserItem.Label)"
         GroupName="@nameof(UserItem.GroupName)"

+ 23 - 16
wispro.sp.web/Components/UserConditionInput.razor.cs

@@ -9,19 +9,19 @@ using wispro.sp.web.Services;
 
 namespace wispro.sp.web.Components
 {
-    public partial class UserConditionInput
+    public class UserItem
     {
-        protected class UserItem
-        {
-            public UserType UserType { get; set; }
+        public UserType UserType { get; set; }
 
-            public string Label { get; set; }
+        public string Label { get; set; }
 
-            public string Value { get; set; }
+        public string Value { get; set; }
 
-            public string GroupName { get; set; }
-        }
+        public string GroupName { get; set; }
+    }
 
+    public partial class UserConditionInput
+    {
         List<UserItem> UserItems = new List<UserItem>();
 
         UserItem SelectedUserItem;
@@ -36,13 +36,14 @@ namespace wispro.sp.web.Components
         [Parameter]
         public string UserValue { get; set; }
 
-        [Parameter]
-        public EventCallback<UserType> UserTypeChanged { get; set; }
-
-        [Parameter]
-        public EventCallback<string> UserValueChanged { get; set; }
+        //[Parameter]
+        //public EventCallback<UserType> UserTypeChanged { get; set; }
 
+        //[Parameter]
+        //public EventCallback<string> UserValueChanged { get; set; }
 
+        [Parameter]
+        public EventCallback<UserItem> OnSelectedChange { get; set; }
 
         [Inject] public WorkflowService wfService { get; set; }
 
@@ -120,9 +121,15 @@ namespace wispro.sp.web.Components
         private void OnSelectedItemChangedHandler(UserItem value)
         {
             SelectedUserItem = value;
-            UserType = SelectedUserItem.UserType;
-            UserValue = SelectedUserItem.Value;
-            //Console.WriteLine($"selected: ${value?.Name}");
+
+            if (OnSelectedChange.HasDelegate)
+            {
+                OnSelectedChange.InvokeAsync(value);
+            }
+            //UserType = SelectedUserItem.UserType;
+            //UserValue = SelectedUserItem.Value;
+            //Console.WriteLine($"selected: ${value?.Value}");
+            //Console.WriteLine(UserValue);
         }
     }
 }

+ 10 - 8
wispro.sp.web/Pages/Workflow/WorkflowDetail.razor

@@ -46,7 +46,9 @@
                                             OnClickStep="OnClickStep"
                                             OnClickTransfer="OnClickTransfer"
                                             OnDoubleClickStep="OnDblClickStep"
-                                            hSeparation="80"/>
+                                            hSeparation="60"
+                                            ChartWidth="900" ChartHeight="600"
+                                            />
     </div>
         }
     </ChildContent>
@@ -161,11 +163,11 @@
     <Form Model="EditTransfer" LabelColSpan="6"
           WrapperColSpan="16">
         <FormItem Label="从步骤">
-            <Select DataSource="@Steps"
-                    DefaultValue="@(EditTransfer.StepId.HasValue?EditTransfer.StepId.Value:0)"
+            <Select DataSource="@stepItems"
+                    DefaultValue="@(EditTransfer.StepId==null?0:EditTransfer.StepId.Value)"
                     @bind-Value="@EditTransfer.StepId"
-                    LabelName="@nameof(wispro.sp.entity.workflowDefine.Step.Name)"
-                    ValueName="@nameof(wispro.sp.entity.workflowDefine.Step.Id)"
+                    LabelName="@nameof(StepItem.Name)"
+                    ValueName="@nameof(StepItem.StepId)"
                     Style="width: 200px"
                     Placeholder="@workflow.InitAction.Name"
                     EnableSearch="true"
@@ -174,11 +176,11 @@
         </FormItem>
 
         <FormItem Label="到步骤">
-            <Select DataSource="@Steps"
+            <Select DataSource="@stepItems"
                     DefaultValue="@EditTransfer.nextStepId"
                     @bind-Value="@EditTransfer.nextStepId"
-                    LabelName="@nameof(wispro.sp.entity.workflowDefine.Step.Name)"
-                    ValueName="@nameof(wispro.sp.entity.workflowDefine.Step.Id)"
+                    LabelName="@nameof(StepItem.Name)"
+                    ValueName="@nameof(StepItem.StepId)"
                     Style="width: 200px"
                     Placeholder="请选择"
                     EnableSearch="true"

+ 28 - 3
wispro.sp.web/Pages/Workflow/WorkflowDetail.razor.cs

@@ -4,6 +4,7 @@ using Microsoft.Extensions.Configuration;
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Text.Json;
 using System.Threading.Tasks;
 using wispro.sp.entity.workflowDefine;
 using wispro.sp.web.Services;
@@ -21,6 +22,14 @@ namespace wispro.sp.web.Pages.Workflow
         List<InputValueSetting> inputValueSettings;
 
 
+        internal class StepItem
+        {
+            public string Name { get; set; }
+
+            public int? StepId { get; set; }
+            
+        }
+
         UserField userField = new UserField();
 
         [Parameter]
@@ -33,6 +42,7 @@ namespace wispro.sp.web.Pages.Workflow
         [Inject] protected IConfiguration _configuration { get; set; }
 
         string DownloadUrl;
+        List<StepItem> stepItems;
         async Task InitData()
         {
 
@@ -44,7 +54,18 @@ namespace wispro.sp.web.Pages.Workflow
 
             DownloadUrl = $"{_configuration.GetValue<string>("APIUrl")}WorkflowEngine/ExportToImage?workflowId={workflow.Id}";
 
+            stepItems = new List<StepItem>();
+            stepItems.Add(new StepItem() { Name = "开始",StepId = 0});
+
+            foreach(var step in Steps)
+            {
+                if (step.Id != workflow.EndStepId)
+                {
+                    stepItems.Add(new StepItem() { Name = step.Name, StepId = step.Id });
+                }
+            }
 
+            stepItems.Add(new StepItem() { Name = "结束", StepId = workflow.EndStepId });
         }
         
         protected async override Task OnInitializedAsync()
@@ -70,7 +91,9 @@ namespace wispro.sp.web.Pages.Workflow
             EditStep = new share.NewStepObject() { Step = step, isLastStep = b };
             try
             {
+                Console.WriteLine(step.defaultResponseSetting);
                 userField = System.Text.Json.JsonSerializer.Deserialize<UserField>(step.defaultResponseSetting);
+                Console.WriteLine($"Deserialize Result:{System.Text.Json.JsonSerializer.Serialize(userField)}" );
             }
             catch {
                 userField = new UserField();
@@ -184,9 +207,11 @@ namespace wispro.sp.web.Pages.Workflow
 
         async Task EditStepOK()
         {
-            //Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(userField));
-            EditStep.Step.defaultResponseSetting = System.Text.Json.JsonSerializer.Serialize(userField);
-            
+            JsonSerializerOptions options = new() { IgnoreNullValues = true };
+            EditStep.Step.defaultResponseSetting = System.Text.Json.JsonSerializer.Serialize(userField,options);
+            Console.WriteLine($"UsrValue={userField.UserValue},UserConditionType={userField.UserConditionType},UserType={userField.UserType}"); 
+            Console.WriteLine(EditStep.Step.defaultResponseSetting);
+
             var ret = await _wfService.SaveStep(EditStep);
             if (ret.Success)
             {