流程跳转

This commit is contained in:
yubaolee 2016-09-05 20:07:10 +08:00
parent 8f2ae61905
commit d5d476bae4
21 changed files with 269 additions and 58 deletions

View File

@ -24,9 +24,10 @@ namespace OpenAuth.App
var user = new UserWithAccessedCtrls
{
User = _service.User,
AccessedOrgs = _service.Orgs,
Orgs = _service.Orgs,
Modules = _service.Modules.MapToList<ModuleView>(),
Resources = _service.Resources,
Roles = _service.Roles
};
foreach (var moduleView in user.Modules)

View File

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using OpenAuth.App.ViewModel;
using OpenAuth.Domain;
using OpenAuth.Domain.Interface;
@ -62,5 +61,10 @@ namespace OpenAuth.App
return result;
}
public void Del(Guid id)
{
_repository.Delete(u =>u.Id == id);
}
}
}

View File

@ -41,6 +41,10 @@
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="OptimaJet.Workflow.Core, Version=1.5.5.0, Culture=neutral, PublicKeyToken=3d29392dccd464d7, processorArchitecture=MSIL">
<HintPath>..\packages\WorkflowEngine.NET-Core.1.5.5.2\lib\net45\OptimaJet.Workflow.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
@ -99,6 +103,8 @@
<Compile Include="UserManagerApp.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="OrgManagerApp.cs" />
<Compile Include="ViewModel\CommandModel.cs" />
<Compile Include="ViewModel\GoodsApplyVM.cs" />
<Compile Include="ViewModel\GridData.cs" />
<Compile Include="ViewModel\UserWithAccessedCtrls.cs" />
<Compile Include="ViewModel\ModuleElementVM.cs" />

View File

@ -80,8 +80,7 @@ namespace OpenAuth.App
/// </summary>
private Guid[] GetSubOrgIds(Guid orgId)
{
var org = _orgRepository.FindSingle(u => u.Id == orgId);
var orgs = _orgRepository.Find(u => u.CascadeId.Contains(org.CascadeId)).Select(u => u.Id).ToArray();
var orgs = _orgRepository.GetSubOrgs(orgId).Select(u => u.Id).ToArray();
return orgs;
}
@ -116,22 +115,21 @@ namespace OpenAuth.App
_relevanceRepository.AddRelevance("RoleOrg", orgIds.ToLookup(u => role.Id));
}
public List<Role> LoadForUser(Guid userId)
{
return _repository.LoadForUser(userId).ToList();
}
public List<RoleVM> LoadForOrgAndUser(Guid orgId, Guid userId)
{
var allorgs = GetSubOrgIds(orgId);
var roles = _relevanceRepository.Find(u => u.Key == "RoleOrg"
&& allorgs.Contains(u.SecondId)).Select(u =>u.FirstId).ToList(); //机构关联的角色
var userroles = LoadForUser(userId);
var orgroles = _repository.LoadInOrgs(GetSubOrgIds(orgId)).ToList();
var roleIds = _repository.Find(u => orgId == Guid.Empty
|| (roles.Contains(u.Id))).ToList(); //从角色表里获取
var rolevms = new List<RoleVM>();
foreach (var role in roleIds)
foreach (var role in orgroles)
{
RoleVM rolevm = role;
rolevm.IsBelongUser = (_relevanceRepository.FindSingle(u => u.SecondId == role.Id
&& u.FirstId == userId
&& u.Key == "UserRole")
!= null);
rolevm.IsBelongUser = userroles.Any(u => u.Id == role.Id);
var orgs = _orgRepository.LoadByRole(role.Id);
rolevm.Organizations = string.Join(",", orgs.Select(u => u.Name).ToList());
rolevm.OrganizationIds = string.Join(",", orgs.Select(u => u.Id).ToList());

View File

@ -0,0 +1,25 @@
// ***********************************************************************
// Assembly : OpenAuth.App
// Author : yubaolee
// Created : 09-05-2016
//
// Last Modified By : yubaolee
// Last Modified On : 09-05-2016
// Contact : Microsoft
// File: CommandModel.cs
// ***********************************************************************
using OptimaJet.Workflow.Core.Model;
namespace OpenAuth.App.ViewModel
{
/// <summary>
/// workflow命令
/// </summary>
public class CommandModel
{
public string Key { get; set; }
public string Value { get; set; }
public TransitionClassifier Classifier { get; set; }
}
}

View File

@ -0,0 +1,73 @@
//------------------------------------------------------------------------------
// <autogenerated>
// This code was generated by a CodeSmith Template.
//
// DO NOT MODIFY contents of this file. Changes to this
// file will be lost if the code is regenerated.
// Author:Yubao Li
// </autogenerated>
//------------------------------------------------------------------------------
using System.Collections.Generic;
using Infrastructure;
using OpenAuth.Domain;
namespace OpenAuth.App.ViewModel
{
/// <summary>
///
/// </summary>
public class GoodsApplyVM :Entity
{
/// <summary>
///
/// </summary>
public int Sort { get; set; }
/// <summary>
///
/// </summary>
public int Number { get; set; }
/// <summary>
///
/// </summary>
public string Name { get; set; }
/// <summary>
///
/// </summary>
public string Comment { get; set; }
/// <summary>
///
/// </summary>
public string State { get; set; }
/// <summary>
///
/// </summary>
public string StateName { get; set; }
/// <summary>
///
/// </summary>
public System.Guid UserId { get; set; }
/// <summary>
///
/// </summary>
public System.Guid? ControllerUserId { get; set; }
/// <summary>
/// 可用命令
/// </summary>
public CommandModel[] Commands { get; set; }
public Dictionary<string, string> AvailiableStates { get; set; }
public static implicit operator GoodsApplyVM(GoodsApply obj)
{
return obj.MapTo<GoodsApplyVM>();
}
public static implicit operator GoodsApply(GoodsApplyVM obj)
{
return obj.MapTo<GoodsApply>();
}
}
}

View File

@ -39,10 +39,8 @@ namespace OpenAuth.App.ViewModel
/// </summary>
public List<Org> Orgs { get; set; }
/// <summary>
/// 用户可访问的机构
/// </summary>
public IEnumerable<Org> AccessedOrgs { get; set; }
public List<Role> Roles { get; set; }
}
}

View File

@ -5,4 +5,5 @@
<package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net45" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
<package id="WorkflowEngine.NET-Core" version="1.5.5.2" targetFramework="net45" />
</packages>

View File

@ -15,16 +15,9 @@ namespace OpenAuth.Domain.Interface
IEnumerable<Org> LoadByRole(Guid roleId);
/// <summary>
/// 得到全部子部门
/// 获取包括自己在内的全部子部门
/// </summary>
/// <param name="orgId">部门ID</param>
IEnumerable<Org> GetSubOrgs(Guid orgId);
/// <summary>
/// 获取包括自己在内的全部子部门
/// </summary>
/// <param name="orgId">The org identifier.</param>
/// <returns>IEnumerable&lt;Org&gt;.</returns>
IEnumerable<Org> GetSubWithOwn(Guid orgId);
}
}

View File

@ -10,6 +10,8 @@ namespace OpenAuth.Domain.Interface
int GetRoleCntInOrgs(params Guid[] orgIds);
IEnumerable<Role> LoadInOrgs(int pageindex, int pagesize, params Guid[] orgIds);
IEnumerable<Role> LoadInOrgs(params Guid[] orgId);
IEnumerable<Role> LoadForUser(Guid userId);
void Delete(Guid id);

View File

@ -29,6 +29,7 @@ namespace OpenAuth.Domain.Service
private List<ModuleElement> _moduleElements; //用户可访问的菜单
private List<Resource> _resources; //用户可访问的资源
private List<Org> _orgs; //用户可访问的机构
private List<Role> _roles; //用户角色
public AuthoriseService(IUnitWork unitWork)
{
@ -40,6 +41,11 @@ namespace OpenAuth.Domain.Service
get { return _modules; }
}
public List<Role> Roles
{
get { return _roles;}
}
public List<ModuleElement> ModuleElements
{
get { return _moduleElements; }
@ -80,7 +86,7 @@ namespace OpenAuth.Domain.Service
{
if (name == "System")
{
_user = new User{Account = "System"};
_user = new User{Account = "System", Id = Guid.Empty};
LoadForSystem();
}
else
@ -104,6 +110,7 @@ namespace OpenAuth.Domain.Service
var userRoleIds =
_unitWork.Find<Relevance>(u => u.FirstId == _user.Id && u.Key == "UserRole").Select(u => u.SecondId).ToList();
_roles = _unitWork.Find<Role>(u => userRoleIds.Contains(u.Id)).ToList();
//用户角色与自己分配到的模块ID
var moduleIds = _unitWork.Find<Relevance>(
u =>
@ -143,9 +150,8 @@ namespace OpenAuth.Domain.Service
{
_modules = _unitWork.Find<Module>(null).ToList();
_moduleElements = _unitWork.Find<ModuleElement>(null).ToList();
_roles = _unitWork.Find<Role>(null).ToList();
_resources = _unitWork.Find<Resource>(null).OrderBy(u => u.SortNo).ToList();
_orgs = _unitWork.Find<Org>(null).OrderBy(u => u.SortNo).ToList();
}
}

View File

@ -41,7 +41,7 @@ namespace OpenAuth.Domain.Service
var orgIds = _authoriseService.Orgs.Select(u => u.Id).ToArray(); //用户可访问的机构ID
var orgs = _orgRepository.GetSubWithOwn(orgId) //点击的节点与用户可访问的机构合并
var orgs = _orgRepository.GetSubOrgs(orgId) //点击的节点与用户可访问的机构合并
.Where(u => orgIds.Contains(u.Id))
.Select(u => u.Id).ToArray();

View File

@ -139,7 +139,6 @@ function del() {
$.getJSON('/GoodsApplies/Delete?Id=' + selected.Id, function (data) {
if (data.statusCode == "200") {
list.reload();
ztree.reload();
}
else {
$(this).alertmsg('warn', data.message);
@ -179,4 +178,4 @@ function refresh() {
list.reload();
}
//@@ sourceURL=StockManager.js
//@@ sourceURL=goodsApply.js

View File

@ -35,6 +35,15 @@ function wfdesignerRedraw() {
wfdesignerRedraw();
$(function () {
$(".btn-cmd")
.on("click", function () { //执行命令
$.post("/GoodsApplies/ExeCmd?id=" +$("#processId").val() +"&cmd=" +$(this).val() ,
{ name: "John", time: "2pm" },
function (data) {
console.log("Data Loaded: " + data);
});
});
});
//@@ sourceURL=processDetail.js

View File

@ -1,9 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Infrastructure;
using OpenAuth.App;
using OpenAuth.App.SSO;
using OpenAuth.App.ViewModel;
using OpenAuth.Domain;
using OpenAuth.Mvc.Models;
using OptimaJet.Workflow.Core.Runtime;
@ -50,8 +52,9 @@ namespace OpenAuth.Mvc.Controllers
{
try
{
var apply = _app.Get(id);
GoodsApplyVM apply = _app.Get(id);
CreateWorkflowIfNotExists(id);
apply.Commands = GetCommands(id);
return View(apply);
}
catch (Exception e)
@ -62,6 +65,39 @@ namespace OpenAuth.Mvc.Controllers
return View();
}
public string Delete(Guid id)
{
try
{
_app.Del(id);
}
catch (Exception ex)
{
BjuiResponse.statusCode = "300";
BjuiResponse.message = ex.Message;
throw;
}
return JsonHelper.Instance.Serialize(BjuiResponse);
}
[HttpPost]
public string ExeCmd(Guid id, string cmd)
{
try
{
ExecuteCommand(id, cmd, null);
}
catch (Exception ex)
{
BjuiResponse.statusCode = "300";
BjuiResponse.message = ex.Message;
throw;
}
return JsonHelper.Instance.Serialize(BjuiResponse);
}
private void CreateWorkflowIfNotExists(Guid id)
{
@ -77,5 +113,43 @@ namespace OpenAuth.Mvc.Controllers
sync.Wait(new TimeSpan(0, 0, 10));
}
}
/// <summary>
/// 获取当前登陆用户可执行的命令
/// </summary>
/// <param name="id">流程实体ID</param>
private CommandModel[] GetCommands(Guid id)
{
var result = new List<CommandModel>();
var commands = WorkflowInit.Runtime.GetAvailableCommands(id, AuthUtil.GetCurrentUser().User.Id.ToString());
foreach (var workflowCommand in commands) //去除相同的
{
if (result.Count(c => c.Key == workflowCommand.CommandName) == 0)
result.Add(new CommandModel() { Key = workflowCommand.CommandName, Value = workflowCommand.LocalizedName, Classifier = workflowCommand.Classifier });
}
return result.ToArray();
}
/// <summary>
/// 执行指令
/// </summary>
/// <param name="id">流程实例ID</param>
/// <param name="commandName">命令名称</param>
/// <param name="goodsApply">申请实体</param>
private void ExecuteCommand(Guid id, string commandName, GoodsApply goodsApply)
{
var currentUser =AuthUtil.GetCurrentUser().User.Id.ToString();
var commands = WorkflowInit.Runtime.GetAvailableCommands(id, currentUser);
var command =
commands.FirstOrDefault(
c => c.CommandName.Equals(commandName, StringComparison.CurrentCultureIgnoreCase));
if (command == null)
return;
WorkflowInit.Runtime.ExecuteCommand(id, currentUser, currentUser, command);
}
}
}

View File

@ -33,7 +33,7 @@ namespace OpenAuth.Mvc.Controllers
public string LoadOrg()
{
return JsonHelper.Instance.Serialize(AuthUtil.GetCurrentUser().AccessedOrgs);
return JsonHelper.Instance.Serialize(AuthUtil.GetCurrentUser().Orgs);
}
public string LoadForUser(Guid firstId)

View File

@ -34,7 +34,7 @@ namespace OpenAuth.Mvc.Models
_runtime = new WorkflowRuntime(new Guid("{8D38DB8F-F3D5-4F26-A989-4FDD40F32D9D}"))
.WithBuilder(builder)
// .WithRuleProvider(new WorkflowRuleProvider())
.WithRuleProvider(new WorkflowRuleProvider())
// .WithActionProvider(new WorkflowActionProvider())
.WithPersistenceProvider(new MSSQLProvider(connectionString))
.WithTimerManager(new TimerManager())
@ -62,12 +62,7 @@ namespace OpenAuth.Mvc.Models
var nextState = WorkflowInit.Runtime.GetLocalizedStateName(e.ProcessId, e.ProcessInstance.CurrentState);
var _app = AutofacExt.GetFromFac<GoodsApplyApp>();
var goodsapply = _app.Get(e.ProcessId);
if (goodsapply != null)
{
goodsapply.StateName = nextState;
}
_app.ChangeState(goodsapply.Id, e.ProcessInstance.CurrentState, nextState);
_app.ChangeState(e.ProcessId, e.ProcessInstance.CurrentState, nextState);
}
}

View File

@ -1,11 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using OpenAuth.App;
using OptimaJet.Workflow.Core.Model;
using OptimaJet.Workflow.Core.Runtime;
namespace OpenAuth.Mvc.Models
{
/// <summary>
/// 判断角色
/// </summary>
public class WorkflowRuleProvider : IWorkflowRuleProvider
{
private RoleManagerApp _app;
@ -15,6 +19,9 @@ namespace OpenAuth.Mvc.Models
_app = AutofacExt.GetFromFac<RoleManagerApp>();
}
/// <summary>
/// 加载角色列表,供流程设计的时候进行选择
/// </summary>
public List<string> GetRules()
{
var roles = _app.Load(Guid.Empty, 1, 100).list;
@ -26,10 +33,26 @@ namespace OpenAuth.Mvc.Models
return rolestrs;
}
/// <summary>
/// Checks the specified process instance.
/// <para>李玉宝于2016-09-05 16:43:07</para>
/// </summary>
/// <param name="processInstance">The process instance.</param>
/// <param name="runtime">The runtime.</param>
/// <param name="identityId">用户ID</param>
/// <param name="ruleName">Name of the rule.</param>
/// <param name="parameter">The parameter.</param>
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
public bool Check(ProcessInstance processInstance, WorkflowRuntime runtime, string identityId, string ruleName,
string parameter)
{
throw new NotImplementedException();
var userRole = _app.LoadForUser(Guid.Parse(identityId));
foreach (var role in userRole)
{
if (role.Name == ruleName)
return true;
}
return false;
}
public IEnumerable<string> GetIdentities(ProcessInstance processInstance, WorkflowRuntime runtime, string ruleName, string parameter)

View File

@ -1,7 +1,7 @@
@{
Layout = null;
}
@model OpenAuth.Domain.GoodsApply
@model OpenAuth.App.ViewModel.GoodsApplyVM
<script src="/Scripts/jquery.js"></script>
<script src="/Scripts/jquery-ui.js"></script>
@ -18,6 +18,11 @@
<input value="@Model.Id" id="processId" class="hidden"/>
<span class="h1">@Model.Name</span>
<span class="alert-info">数量:@Model.Number</span>
<span class="label label-default">你可以:</span>
@foreach (var cmd in Model.Commands)
{
<button type="button" class="btn btn-default btn-cmd" value="@cmd.Key">@cmd.Value</button>
}
<br/>
<div id="wfdesigner"></div>

View File

@ -54,19 +54,5 @@ namespace OpenAuth.Repository
return Find(u => u.CascadeId.Contains(cascadeId));
}
public IEnumerable<Org> GetSubWithOwn(Guid orgId)
{
string cascadeId = "0.";
if (orgId != Guid.Empty)
{
var org = FindSingle(u => u.Id == orgId);
if (org == null)
throw new Exception("未能找到指定对象信息");
cascadeId = org.CascadeId;
}
return Find(u => u.CascadeId.Contains(cascadeId));
}
}
}

View File

@ -40,5 +40,18 @@ namespace OpenAuth.Repository
return result;
}
public IEnumerable<Role> LoadForUser(Guid userId)
{
if (userId == Guid.Empty)
return Find(null);
var userRoleIds =
Context.Relevances.Where(u => u.FirstId == userId && u.Key == "UserRole")
.Select(u => u.SecondId).ToList();
return Find(u => userRoleIds.Contains(u.Id));
}
}
}