Skip to content

Commit bbb3e5f

Browse files
增加审批流程回退功能,更新文件:ServiceBase.cs、WorkFlowManager.cs、Sys_WorkFlowController.cs、前端viewgrid文件夹(回退使用方法见后台开发文档上审批方法)
1 parent 59c2294 commit bbb3e5f

File tree

16 files changed

+659
-192
lines changed

16 files changed

+659
-192
lines changed

.Net6版本/VOL.Core/BaseProvider/ServiceBase.cs

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ public virtual WebResponseContent Add(SaveModel saveDataModel)
535535
if (saveDataModel.DetailData == null || saveDataModel.DetailData.Count == 0)
536536
{
537537
T mainEntity = saveDataModel.MainData.DicToEntity<T>();
538+
SetAuditDefaultValue(mainEntity);
538539
if (base.AddOnExecuting != null)
539540
{
540541
Response = base.AddOnExecuting(mainEntity, null);
@@ -582,6 +583,7 @@ public WebResponseContent Add<TDetail>(T entity, List<TDetail> list = null, bool
582583
{
583584
//设置用户默认值
584585
entity.SetCreateDefaultVal();
586+
SetAuditDefaultValue(entity);
585587
if (validationEntity)
586588
{
587589
Response = entity.ValidationEntity();
@@ -631,6 +633,32 @@ public WebResponseContent Add<TDetail>(T entity, List<TDetail> list = null, bool
631633
return Response;
632634
}
633635

636+
/// <summary>
637+
/// 设置审批字段默认值
638+
/// </summary>
639+
/// <param name="entity"></param>
640+
private void SetAuditDefaultValue(T entity)
641+
{
642+
if (!WorkFlowManager.Exists<T>())
643+
{
644+
return;
645+
}
646+
var propertity = TProperties.Where(x => x.Name.ToLower() == "auditstatus").FirstOrDefault();
647+
if (propertity != null && propertity.GetValue(entity) == null)
648+
{
649+
propertity.SetValue(entity, 0);
650+
}
651+
}
652+
/// <summary>
653+
/// 写入流程
654+
/// </summary>
655+
/// <typeparam name="T"></typeparam>
656+
/// <param name="entity"></param>
657+
/// <param name="changeTableStatus">是否修改原表的审批状态</param>
658+
protected void RewriteFlow(T entity,bool changeTableStatus = true)
659+
{
660+
WorkFlowManager.AddProcese(entity, true, changeTableStatus);
661+
}
634662
private void AddProcese(T entity)
635663
{
636664
if (!CheckResponseResult() && WorkFlowManager.Exists<T>())
@@ -641,8 +669,7 @@ private void AddProcese(T entity)
641669
}
642670
//写入流程
643671
WorkFlowManager.AddProcese<T>(entity);
644-
WorkFlowManager.Audit<T>(entity,AuditStatus.审核中,null,null,null,null, init: true, initInvoke: AddWorkFlowExecuted);
645-
672+
WorkFlowManager.Audit<T>(entity, AuditStatus.审核中, null, null, null, null, init: true, initInvoke: AddWorkFlowExecuted);
646673
}
647674
}
648675

@@ -1159,8 +1186,6 @@ public virtual WebResponseContent Audit(object[] keys, int? auditStatus, string
11591186
{
11601187
if (keys == null || keys.Length == 0)
11611188
return Response.Error("未获取到参数!");
1162-
if (auditStatus != 1 && auditStatus != 2)
1163-
return Response.Error("请提求正确的审核结果!");
11641189

11651190
Expression<Func<T, bool>> whereExpression = typeof(T).GetKeyName().CreateExpression<T>(keys[0], LinqExpressionType.Equal);
11661191
T entity = repository.FindAsIQueryable(whereExpression).FirstOrDefault();
@@ -1179,8 +1204,15 @@ public virtual WebResponseContent Audit(object[] keys, int? auditStatus, string
11791204
{
11801205
return Response.Error("只能审批审核中的数据");
11811206
}
1182-
WorkFlowManager.Audit<T>(entity, status, auditReason, auditProperty, AuditWorkFlowExecuting, AuditWorkFlowExecuted);
1183-
return Response.OK("审核成功!");
1207+
Response = repository.DbContextBeginTransaction(() =>
1208+
{
1209+
return WorkFlowManager.Audit<T>(entity, status, auditReason, auditProperty, AuditWorkFlowExecuting, AuditWorkFlowExecuted);
1210+
});
1211+
if (Response.Status)
1212+
{
1213+
return Response.OK(ResponseType.AuditSuccess);
1214+
}
1215+
return Response.Error(Response.Message??"审批失败");
11841216
}
11851217

11861218

@@ -1230,13 +1262,21 @@ public virtual WebResponseContent Audit(object[] keys, int? auditStatus, string
12301262
Response = AuditOnExecuting(auditList);
12311263
if (CheckResponseResult()) return Response;
12321264
}
1233-
repository.UpdateRange(auditList, updateFileds.Select(x => x.Name).ToArray(), true);
1234-
if (base.AuditOnExecuted != null)
1265+
Response = repository.DbContextBeginTransaction(() =>
12351266
{
1236-
Response = AuditOnExecuted(auditList);
1237-
if (CheckResponseResult()) return Response;
1267+
repository.UpdateRange(auditList, updateFileds.Select(x => x.Name).ToArray(), true);
1268+
if (base.AuditOnExecuted != null)
1269+
{
1270+
Response = AuditOnExecuted(auditList);
1271+
if (CheckResponseResult()) return Response;
1272+
}
1273+
return Response.OK();
1274+
});
1275+
if (Response.Status)
1276+
{
1277+
return Response.OK(ResponseType.AuditSuccess);
12381278
}
1239-
return Response.OK(ResponseType.AuditSuccess);
1279+
return Response.Error(Response.Message);
12401280
}
12411281

12421282
public virtual (string, T, bool) ApiValidate(string bizContent, Expression<Func<T, object>> expression = null)

.Net6版本/VOL.Core/WorkFlow/WorkFlowManager.cs

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,69 @@ public static int GetAuditStatus<T>(string value)
4141
.FirstOrDefault();
4242
}
4343

44+
private static void Rewrite<T>(T entity, Sys_WorkFlow workFlow,bool changeTableStatus) where T:class
45+
{
46+
var autditProperty = typeof(T).GetProperties().Where(x => x.Name.ToLower() == "auditstatus").FirstOrDefault();
47+
if (autditProperty == null)
48+
{
49+
return;
50+
}
51+
52+
string value = typeof(T).GetKeyProperty().GetValue(entity).ToString();
53+
54+
var dbContext = DBServerProvider.DbContext;
55+
56+
57+
var workTable = dbContext.Set<Sys_WorkFlowTable>().Where(x => x.WorkTableKey == value && x.WorkFlow_Id == workFlow.WorkFlow_Id)
58+
.AsNoTracking()
59+
.Include(x => x.Sys_WorkFlowTableStep).FirstOrDefault();
60+
if (workTable == null || workFlow.Sys_WorkFlowStep == null)
61+
{
62+
Console.WriteLine($"未查到流程数据,id:{ workFlow.WorkFlow_Id}");
63+
return;
64+
}
65+
workTable.CurrentOrderId = 1;
66+
workTable.AuditStatus = (int)AuditStatus.审核中;
67+
workTable.Sys_WorkFlowTableStep.ForEach(item =>
68+
{
69+
item.Enable = 0;
70+
});
71+
72+
if (changeTableStatus)
73+
{
74+
dbContext.Entry(entity).State = EntityState.Detached;
75+
autditProperty.SetValue(entity, 0);
76+
dbContext.Entry(entity).Property(autditProperty.Name).IsModified = true;
77+
}
4478

79+
var wlowTableStep = workFlow.Sys_WorkFlowStep.OrderBy(x => x.OrderId).Select(s => new Sys_WorkFlowTableStep()
80+
{
81+
Sys_WorkFlowTableStep_Id = Guid.NewGuid(),
82+
WorkFlowTable_Id = workTable.WorkFlowTable_Id,
83+
WorkFlow_Id = s.WorkFlow_Id,
84+
StepId = s.StepId,
85+
StepName = s.StepName,
86+
AuditId = s.StepType == (int)AuditType.用户审批 ? s.StepValue : null,
87+
StepType = s.StepType,
88+
StepValue = s.StepValue,
89+
OrderId = s.OrderId,
90+
Enable = 1,
91+
CreateDate = DateTime.Now,
92+
}).ToList();
93+
dbContext.Entry(workTable).State = EntityState.Detached;
94+
dbContext.Update(workTable);
95+
dbContext.AddRange(wlowTableStep);
96+
dbContext.SaveChanges();
97+
98+
}
4599
/// <summary>
46100
/// 写入流程
47101
/// </summary>
48102
/// <typeparam name="T"></typeparam>
49103
/// <param name="entity"></param>
50-
public static void AddProcese<T>(T entity, bool rewrite = false)
104+
/// <param name="rewrite">是否重新生成流程</param>
105+
/// <param name="changeTableStatus">是否修改原表的审批状态</param>
106+
public static void AddProcese<T>(T entity, bool rewrite = false,bool changeTableStatus=true) where T:class
51107
{
52108
string workTable = typeof(T).GetEntityTableName();
53109

@@ -57,6 +113,12 @@ public static void AddProcese<T>(T entity, bool rewrite = false)
57113
.FirstOrDefault();
58114

59115
if (workFlow == null || workFlow.Sys_WorkFlowStep.Count == 0) return;
116+
//重新生成流程
117+
if (rewrite)
118+
{
119+
Rewrite(entity, workFlow,changeTableStatus);
120+
return;
121+
}
60122

61123
var userInfo = UserContext.Current.UserInfo;
62124
Guid workFlowTable_Id = Guid.NewGuid();
@@ -195,10 +257,16 @@ public static WebResponseContent Audit<T>(T entity, AuditStatus status, string r
195257
currnetStep.AuditDate = DateTime.Now;
196258
currnetStep.AuditStatus = (int)status;
197259
currnetStep.Remark = remark;
260+
261+
262+
//dbContext.Entry(workFlow).Property("CurrentOrderId").IsModified = true;
263+
//dbContext.Entry(workFlow).Property("AuditStatus").IsModified = true;
264+
265+
198266
dbContext.Set<Sys_WorkFlowTable>().Update(workFlow);
199267

200268
dbContext.SaveChanges();
201-
269+
dbContext.Entry(workFlow).State = EntityState.Detached;
202270
if (workFlowExecuted != null)
203271
{
204272
webResponse = workFlowExecuted.Invoke(entity, status, GetAuditUserIds(nextStep?.StepType ?? 0), isLast);

.Net6版本/VOL.WebApi/Controllers/System/Partial/Sys_WorkFlowController.cs

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,27 +89,33 @@ public async Task<IActionResult> GetSteps(string tableName, string id)
8989

9090
var user = UserContext.Current.UserInfo;
9191
List<int> stepValues = flow.Sys_WorkFlowTableStep.Select(s => s.StepValue ?? 0).ToList();
92-
var users = _userRepository.FindAsIQueryable(x => true)
93-
.Select(u => new { u.User_Id, u.UserTrueName });
92+
93+
var auditUsers = flow.Sys_WorkFlowTableStep.Where(x => x.AuditId > 0).Select(s => s.AuditId).ToArray();
94+
var users = await _userRepository.FindAsIQueryable(x => auditUsers.Contains(x.User_Id))
95+
.Select(u => new { u.User_Id, u.UserTrueName }).ToListAsync();
96+
97+
var steps = flow.Sys_WorkFlowTableStep
98+
.Select(c => new
99+
{
100+
c.AuditId,
101+
Auditor = users.Where(us => us.User_Id == c.AuditId).Select(us => us.UserTrueName).FirstOrDefault(),
102+
c.AuditDate,
103+
c.AuditStatus,
104+
c.Remark,
105+
c.StepValue,
106+
c.StepName,
107+
c.OrderId,
108+
c.Enable,
109+
//判断是按角色审批 还是用户帐号审批
110+
isCurrentUser = (c.AuditStatus ?? 0) == (int)AuditStatus.审核中 && c.OrderId == flow.CurrentOrderId && GetAuditStepValue(c.StepType) == c.StepValue,
111+
isCurrent = c.OrderId == flow.CurrentOrderId && c.AuditStatus != (int)AuditStatus.审核通过
112+
}).OrderBy(o => o.OrderId);
94113
var data = new
95114
{
96115
step = flow.CurrentOrderId,
97116
flow.AuditStatus,
98-
list = flow.Sys_WorkFlowTableStep
99-
.Select(c => new
100-
{
101-
c.AuditId,
102-
Auditor = users.Where(us => us.User_Id == c.AuditId).Select(us => us.UserTrueName).FirstOrDefault(),
103-
c.AuditDate,
104-
c.AuditStatus,
105-
c.Remark,
106-
c.StepValue,
107-
c.StepName,
108-
c.OrderId,
109-
//判断是按角色审批 还是用户帐号审批
110-
isCurrentUser = (c.AuditStatus ?? 0) == (int)AuditStatus.审核中 && c.OrderId == flow.CurrentOrderId && GetAuditStepValue(c.StepType) == c.StepValue,
111-
isCurrent = c.OrderId == flow.CurrentOrderId && c.AuditStatus != (int)AuditStatus.审核通过
112-
}).OrderBy(o => o.OrderId)
117+
list = steps.Where(x => (x.Enable == null || x.Enable > 0)).ToList(),
118+
his = steps.Where(x => x.AuditId > 0 &&x.AuditStatus>0 && x.Enable == 0).ToList(),
113119
};
114120

115121
return Json(data);
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<template>
2+
<vol-table
3+
:tableData="tableData"
4+
:columns="columns"
5+
:height="411"
6+
:pagination-hide="true"
7+
:load-key="false"
8+
:text-inline="false"
9+
:ck="false"
10+
></vol-table>
11+
</template>
12+
<script>
13+
import VolTable from '@/components/basic/VolTable.vue';
14+
import {
15+
defineComponent,
16+
ref,
17+
reactive,
18+
toRefs,
19+
getCurrentInstance
20+
} from 'vue';
21+
export default defineComponent({
22+
components: {
23+
VolTable
24+
},
25+
props: {
26+
tableData: {
27+
type: Array,
28+
default: () => {
29+
return [];
30+
}
31+
}
32+
},
33+
setup() {
34+
const columns = reactive([
35+
{ title: '节点', field: 'stepName' },
36+
{ title: '审批人', field: 'auditor' },
37+
{ title: '审批结果', field: 'auditStatus' },
38+
{ title: '审批时间', field: 'auditDate',width:150 },
39+
{ title: '备注', field: 'remark' }
40+
]);
41+
return {
42+
columns
43+
}
44+
}
45+
});
46+
</script>

0 commit comments

Comments
 (0)