Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
Kivii.Lac.Lims.V4.5
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
陶然
Kivii.Lac.Lims.V4.5
Commits
9dbac85d
Commit
9dbac85d
authored
Jun 19, 2025
by
Neo Turing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化
parent
86c6d7b2
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
268 additions
and
396 deletions
+268
-396
Report.cs
Src/Entities/Report.cs
+16
-6
ReportItem.cs
Src/Entities/ReportItem.cs
+5
-8
ReportExtension.cs
Src/Extensions/ReportExtension.cs
+49
-112
RestfulReport.cs
Src/Transforms/RestfulReport.cs
+120
-19
RestfulReportItem.cs
Src/Transforms/RestfulReportItem.cs
+78
-251
No files found.
Src/Entities/Report.cs
View file @
9dbac85d
...
...
@@ -12,51 +12,61 @@ namespace Kivii.Lims.Entities
{
public
enum
ReportStatusType
{
[
Description
(
"草稿"
)]
Unsupported
=
0
,
/// <summary>
///
委托受理
///
待审核
/// </summary>
[
Description
(
"待审核"
)]
CommissionAccept
=
100
,
/// <summary>
/// 合同评审
/// </summary>
[
Description
(
"合同评审"
)]
ContractReview
=
200
,
/// <summary>
///
任务分派
///
文件审核
/// </summary>
[
Description
(
"文件审核"
)]
TaskAssign
=
300
,
/// <summary>
///
数据录入
///
现场评审
/// </summary>
[
Description
(
"现场评审"
)]
DataEntry
=
400
,
/// <summary>
///
报告编制
///
比对测试
/// </summary>
[
Description
(
"比对测试"
)]
ReportPreparation
=
500
,
/// <summary>
/// 报告审核
/// </summary>
[
Description
(
"报告审核"
)]
ReportReview
=
600
,
/// <summary>
///
报告
签发
///
认证
签发
/// </summary>
[
Description
(
"认证签发"
)]
ReportIssue
=
700
,
/// <summary>
/// 报告打印
/// </summary>
[
Description
(
"报告打印"
)]
ReportPrint
=
800
,
/// <summary>
///
报告归档
///
认证完成
/// </summary>
[
Description
(
"认证完成"
)]
ReportCollected
=
int
.
MaxValue
}
public
abstract
class
ReportBase
:
EntityWithMetadata
...
...
Src/Entities/ReportItem.cs
View file @
9dbac85d
...
...
@@ -46,21 +46,18 @@ namespace Kivii.Lims.Entities
public
enum
ReportItemStatusType
{
Unsupported
=
0
,
//待
检测
//待
上传
BeforeTest
=
100
,
//
分派中
//
已上传
Asigning
=
150
,
/// <summary>
/// 正在测试?
/// </summary>
//检测中
//审核中
Testing
=
200
,
//待复核
BeforeReview
=
250
,
//
已复核
//
不通过
TestFinished
=
300
,
/// <summary>
///
检测结束
///
已通过
/// </summary>
TestCollected
=
int
.
MaxValue
}
...
...
Src/Extensions/ReportExtension.cs
View file @
9dbac85d
...
...
@@ -8,6 +8,8 @@ using System.Data;
using
System.IO
;
using
System.Linq
;
using
System.Text.RegularExpressions
;
using
System.Reflection
;
using
Kivii.DataAnnotations
;
namespace
Kivii.Lac.Lims.Extensions
{
...
...
@@ -555,6 +557,39 @@ namespace Kivii.Lac.Lims.Extensions
if
(
disposeConn
)
conn
.
Dispose
();
return
reportNote
;
}
/// <summary>
/// 获取枚举值的描述特性
/// </summary>
/// <param name="value">要获取描述的枚举值</param>
/// <returns>返回枚举值的描述;如果没有描述特性,则返回枚举值的名称</returns>
/// <example>
/// <code>
/// Status status = Status.Pending;
/// string description = status.GetDescription(); // 返回 "待处理"
/// </code>
/// </example>
public
static
string
GetDescription
(
this
Enum
value
)
{
// 通过反射获取枚举值对应的字段信息
FieldInfo
field
=
value
.
GetType
().
GetField
(
value
.
ToString
());
if
(
field
!=
null
)
{
// 从字段中获取DescriptionAttribute特性
DescriptionAttribute
attribute
=
Attribute
.
GetCustomAttribute
(
field
,
typeof
(
DescriptionAttribute
))
as
DescriptionAttribute
;
if
(
attribute
!=
null
&&
!
string
.
IsNullOrEmpty
(
attribute
.
Description
))
{
// 如果找到了描述特性,则返回其Description属性值
return
attribute
.
Description
;
}
}
// 如果没有找到描述特性或字段信息为空,则返回枚举值的字符串表示
return
value
.
ToString
();
}
/// <summary>
/// 报告流程进度描述
/// </summary>
...
...
@@ -565,32 +600,35 @@ namespace Kivii.Lac.Lims.Extensions
string
description
=
""
;
switch
(
Status
)
{
case
(
int
)
ReportStatusType
.
Unsupported
:
description
=
ReportStatusType
.
Unsupported
.
GetDescription
();
// "委托受理";
break
;
case
(
int
)
ReportStatusType
.
CommissionAccept
:
description
=
"委托受理"
;
description
=
ReportStatusType
.
CommissionAccept
.
GetDescription
()
;
break
;
case
999
:
description
=
"管理部审核"
;
break
;
case
(
int
)
ReportStatusType
.
TaskAssign
:
description
=
"任务分派"
;
description
=
ReportStatusType
.
TaskAssign
.
GetDescription
()
;
break
;
case
(
int
)
ReportStatusType
.
DataEntry
:
description
=
"项目检验"
;
description
=
ReportStatusType
.
DataEntry
.
GetDescription
()
;
break
;
case
(
int
)
ReportStatusType
.
ReportPreparation
:
description
=
"报告编制"
;
description
=
ReportStatusType
.
ReportPreparation
.
GetDescription
()
;
break
;
case
(
int
)
ReportStatusType
.
ReportReview
:
description
=
"报告审核"
;
description
=
ReportStatusType
.
ReportReview
.
GetDescription
()
;
break
;
case
(
int
)
ReportStatusType
.
ReportIssue
:
description
=
"报告签发"
;
description
=
ReportStatusType
.
ReportIssue
.
GetDescription
()
;
break
;
case
(
int
)
ReportStatusType
.
ReportPrint
:
description
=
"报告打印"
;
description
=
ReportStatusType
.
ReportPrint
.
GetDescription
()
;
break
;
case
int
.
MaxValue
:
description
=
"报告归档"
;
description
=
ReportStatusType
.
ReportCollected
.
GetDescription
()
;
break
;
default
:
description
=
"报告流程异常,请与管理员联系"
;
...
...
@@ -624,12 +662,9 @@ namespace Kivii.Lac.Lims.Extensions
report
=
conn
.
SingleById
<
Report
>(
report
.
Kvid
);
report
.
ThrowIfNull
(
"未找到对应的报告信息!"
);
}
//如果当前的报告已经不再项目检验了,不能对这份单子做任何的处理
if
(
report
.
Status
>=
(
int
)
ReportStatusType
.
DataEntry
)
return
report
;
//var queryReportItems = conn.From<ReportItem>().Where(o => o.ReportKvid == report.Kvid);
//var reportItems = conn.Select(queryReportItems);
var
reportItems
=
report
.
GetOriginalReportItems
(
conn
);
int
status
=
(
int
)
statusType
;
if
(
status
<=
report
.
Status
)
return
report
;
var
reportItems
=
report
.
GetOriginalReportItems
(
conn
);
if
(
reportItems
.
IsNullOrEmpty
())
throw
new
Exception
(
$"当前委托协议(
{
report
.
ReportId
}
)还未选择检验项目,请待选择检验项目后重新操作!"
);
#
region
验证子检测项目数据结构完整性
var
reportItemKvids
=
reportItems
.
Select
(
o
=>
o
.
Kvid
).
ToList
();
...
...
@@ -640,101 +675,11 @@ namespace Kivii.Lac.Lims.Extensions
reportItems
.
RemoveAll
(
o
=>
Sql
.
In
(
o
.
Type
,
ReportItemType
.
SampleSelf
,
ReportItemType
.
SamplePart
,
ReportItemType
.
Unsupported
));
if
(
reportItems
.
IsNullOrEmpty
())
throw
new
Exception
(
$"当前委托协议(
{
report
.
ReportId
}
)还未选择检验项目,请待选择检验项目后重新操作!"
);
//****************************************************
//此处初始的status的状态 还需判断是否是打回项目进行任务下达,否则打回到委托受理状态的报告无法通过此方法下达
int
status
=
(
int
)
ReportStatusType
.
TaskAssign
;
//获取未分组检验项目的个数
var
unGrouped
=
reportItems
.
filterReportItem
().
Where
(
o
=>
o
.
WorkGroupKvid
==
Guid
.
Empty
||
o
.
WorkGroupName
.
IsNullOrEmpty
()).
Count
();
//获取未完成检验项目个数(只要没有判定结果的视为未检测)
var
unTested
=
reportItems
.
Where
(
o
=>
o
.
Type
==
ReportItemType
.
Test
&
o
.
TestValue
.
IsNullOrEmpty
()).
Count
();
(
report
.
Status
==
(
int
)
ReportStatusType
.
TaskAssign
&&
unGrouped
>
0
).
ThrowIfTrue
(
$"当前委托协议(
{
report
.
ReportId
}
)还未分组,请待检验项目全部分组后重新操作!"
);
if
(
report
.
Status
==
(
int
)
ReportStatusType
.
CommissionAccept
)
{
//加强验证,无模板的kvid,无法下达
report
.
TemplateKvid
.
ThrowIfEmpty
(
"报告模板选择异常,请重新选择报告模板!如重复遇到,请联系系统管理员!"
);
//如果有未分组的项目,就走到分派
if
(
unGrouped
>
0
||
report
.
TaskAssignDate
==
null
)
{
status
=
(
int
)
ReportStatusType
.
TaskAssign
;
}
//如果是数据录入打回报告,直接到打回的地方
//else if (report.Metadata != null && report.Metadata.ContainsKey("CallBackFrom"))
//{
// status = (int)ReportStatusType.DataEntry;
//}
//如果所有任务都完成直接到编制
else
if
(!
reportItems
.
filterReportItem
().
Exists
(
o
=>
o
.
Status
!=
int
.
MaxValue
))
{
status
=
(
int
)
ReportStatusType
.
ReportPreparation
;
//如果没有分派日期,同时更新分派日期
if
(
report
.
TaskAssignDate
==
null
)
{
report
.
TaskAssignDate
=
DateTime
.
Now
;
report
.
AddOnlyProperties
(
o
=>
o
.
TaskAssignDate
);
}
}
else
{
status
=
(
int
)
ReportStatusType
.
DataEntry
;
}
}
if
(
report
.
BizType
==
"X"
)
{
status
=
700
;
}
if
(
report
.
BizType
==
"G0"
)
{
status
=
700
;
}
//定义全局变量updateWorkGroupReportItems,用于分派统一检验组
List
<
ReportItem
>
updateWorkGroupReportItems
=
null
;
if
(
report
.
Status
==
(
int
)
ReportStatusType
.
TaskAssign
)
{
//如果所有任务都完成直接到编制
if
(!
reportItems
.
filterReportItem
().
Exists
(
o
=>
o
.
Status
!=
int
.
MaxValue
))
{
status
=
(
int
)
ReportStatusType
.
ReportPreparation
;
}
else
{
status
=
(
int
)
ReportStatusType
.
DataEntry
;
//2021-10-17新增数据处理,处理子项的检验组合大项不一样的情况。
updateWorkGroupReportItems
=
reportItems
.
SyncWorkGroup
();
}
report
.
TaskAssignDate
=
DateTime
.
Now
;
report
.
AddOnlyProperties
(
o
=>
o
.
TaskAssignDate
);
}
report
.
Status
=
status
;
report
.
AddOnlyProperties
(
o
=>
o
.
Status
);
report
.
TestStartDate
=
(
report
.
TestStartDate
!=
null
&&
report
.
TestStartDate
>
(
DateTime
?)
DateTime
.
MinValue
)
?
report
.
TestStartDate
:
DateTime
.
Now
;
report
.
AddOnlyProperties
(
o
=>
o
.
TestStartDate
);
//无论是打回的报告还是新建下达的报告,只要是经过受理下达、分派下达,都清空打回标记
//if (report.Metadata.ContainsKey("FlowCallBack"))
//{
// report.Metadata.Remove("FlowCallBack");
// report.AddOnlyProperties(o => o.Metadata);
//}
#
region
任务下达时,判断是否有打回信息,按需清除打回信息
if
(
report
.
Metadata
!=
null
&&
report
.
Metadata
.
ContainsKey
(
"CallBackTo"
)
&&
report
.
Metadata
[
"CallBackTo"
]
==
statusType
.
ToString
())
{
report
.
Metadata
[
"CallBackTo"
]
=
null
;
report
.
AddOnlyProperties
(
o
=>
o
.
Metadata
);
}
if
(
report
.
Metadata
!=
null
&&
report
.
Metadata
.
ContainsKey
(
"CallBackFrom"
)
&&
report
.
Metadata
[
"CallBackFrom"
]
==
statusType
.
ToString
())
{
report
.
Metadata
[
"CallBackFrom"
]
=
null
;
report
.
AddOnlyProperties
(
o
=>
o
.
Metadata
);
}
#
endregion
IDbTransaction
trans
=
null
;
//事务,如果外部来了Connection,不生成事务
if
(
useTransaction
)
trans
=
conn
.
OpenTransaction
(
IsolationLevel
.
ReadUncommitted
);
try
...
...
@@ -773,14 +718,6 @@ namespace Kivii.Lac.Lims.Extensions
conn
.
UpdateOnly
(
reportItem
);
}
}
//更新同步检验组信息(分派后)
if
(
updateWorkGroupReportItems
!=
null
)
{
foreach
(
var
item
in
updateWorkGroupReportItems
)
{
conn
.
UpdateOnly
(
item
);
}
}
#
endregion
#
region
流转记录相关信息创建
(
预留
)
,受理下达时创建
ReportFiles
...
...
Src/Transforms/RestfulReport.cs
View file @
9dbac85d
...
...
@@ -110,7 +110,7 @@ namespace Kivii.Lac.Lims.Transforms
//删除逻辑需要完善?????????????????????????
#
region
数据验证
//只能删除委托状态报告
if
(
dbConnection
.
Exists
<
Report
>(
o
=>
Sql
.
In
(
o
.
Kvid
,
Kvids
)
&&
o
.
Status
!=
(
int
)
ReportStatusType
.
CommissionAccept
))
throw
new
Exception
(
"待删除报告中存在非委托状态的报告,禁止删除!"
);
if
(
dbConnection
.
Exists
<
Report
>(
o
=>
Sql
.
In
(
o
.
Kvid
,
Kvids
)
&&
o
.
Status
>
(
int
)
ReportStatusType
.
CommissionAccept
))
throw
new
Exception
(
"待删除报告中存在非委托状态的报告,禁止删除!"
);
//获取待删除报告集合
var
queryReports
=
dbConnection
.
From
<
Report
>();
queryReports
.
Where
(
o
=>
Sql
.
In
(
o
.
Kvid
,
Kvids
));
...
...
@@ -635,19 +635,9 @@ namespace Kivii.Lac.Lims.Transforms
var
reports
=
conn
.
SelectByIds
<
Report
>(
ReportKvids
);
reports
.
ThrowIfNullOrEmpty
(
"未找到所选委托协议信息!"
);
reports
.
RemoveAll
(
o
=>
o
.
Status
==
int
.
MaxValue
||
o
.
Status
<
(
int
)
ReportStatusType
.
CommissionAccept
);
reports
.
RemoveAll
(
o
=>
o
.
Status
==
int
.
MaxValue
);
reports
.
ThrowIfNullOrEmpty
(
"所选报告都为归档报告无需再下达!"
);
if
(
StatusType
==
ReportStatusType
.
CommissionAccept
)
{
(
reports
.
Exists
(
o
=>
o
.
OperatorName
!=
KiviiContext
.
CurrentMember
.
FullName
)
&&
reports
.
Count
>
1
).
ThrowIfTrue
(
$"当前选择的【
{
reports
.
Count
}
】份报告中含有【
{
string
.
Join
(
","
,
reports
.
Select
(
o
=>
o
.
OperatorName
).
Distinct
().
ToList
().
ToArray
())}
】受理的报告,批量处理时不允许处理别人的报告,如需处理别人的报告,只能单个处理,请重新选择!"
);
}
//不验证数据录入的一致性
if
(
StatusType
!=
ReportStatusType
.
DataEntry
)
{
if
(
reports
.
Exists
(
o
=>
o
.
StatusType
!=
StatusType
))
throw
new
Exception
(
"存在报告状态发生变化,请刷新后重试!"
);
}
var
rtns
=
new
ReportAssignResponse
();
rtns
.
Results
=
new
List
<
Report
>();
...
...
@@ -661,16 +651,15 @@ namespace Kivii.Lac.Lims.Transforms
report
.
Metadata
[
"LogDescription"
]
=
""
;
if
(!
Description
.
IsNullOrEmpty
())
report
.
Metadata
[
"LogDescription"
]
=
Description
;
//var reportIdCount = conn.Count<Report>(o => o.ReportId == report.ReportId);
//(reportIdCount > 1).ThrowIfTrue($"报告编号[{report.ReportId}]在系统中已经存在,请及时对报告编号进行修改!");
(
report
.
ReportId
.
IsNullOrEmpty
()
||
report
.
DemanderName
.
IsNullOrEmpty
()
||
report
.
SampleName
.
IsNullOrEmpty
()
||
report
.
DeadDate
==
null
||
report
.
DealDate
==
null
).
ThrowIfTrue
(
$"当前报告[
{
report
.
ReportId
}
]的基本信息填写不完整,请填写完必填信息后重新操作!"
);
//**********************判断扫描图片是否存在,如果不存在则需提醒是否要上传样品图片
//**********************判断拍照图片是否存在
var
originalStatus
=
report
.
Status
;
//after beforeAsing,report.Tag ?=reportItmes
report
.
beforeAsign
(
StatusType
,
conn
);
//report.beforeAsign(StatusType, conn);
switch
(
report
.
Status
)
{
case
(
int
)
ReportStatusType
.
Unsupported
:
report
.
Assign
(
StatusType
);
rtns
.
Results
.
Add
(
report
);
break
;
case
(
int
)
ReportStatusType
.
CommissionAccept
:
report
.
Assign
(
StatusType
);
rtns
.
Results
.
Add
(
report
);
...
...
@@ -750,6 +739,118 @@ namespace Kivii.Lac.Lims.Transforms
return
rtns
;
}
}
[
RequiresAnyRole
(
MemberRoles
.
Everyone
)]
[
Api
(
Description
=
"任务下达2"
)]
public
class
ReportAssign2
:
RestfulExecution
<
Report
>,
IReturn
<
ReportAssignResponse
>
{
public
List
<
Guid
>
ReportKvids
{
get
;
set
;
}
public
string
Description
{
get
;
set
;
}
public
ReportStatusType
StatusType
{
get
;
set
;
}
public
DateTime
?
IssueDate
{
get
;
set
;
}
public
override
object
OnExecution
(
IRequest
req
,
IResponse
res
)
{
StatusType
.
ThrowIfNull
(
"参数错误"
);
ReportKvids
.
ThrowIfNullOrEmpty
(
"您当前还未选择需要处理的委托协议,请选择委托协议后重新操作!"
);
var
conn
=
KiviiContext
.
GetOpenedDbConnection
<
Report
>();
var
reports
=
conn
.
SelectByIds
<
Report
>(
ReportKvids
);
reports
.
ThrowIfNullOrEmpty
(
"未找到所选委托协议信息!"
);
reports
.
RemoveAll
(
o
=>
o
.
Status
==
int
.
MaxValue
);
reports
.
ThrowIfNullOrEmpty
(
"所选报告都为归档报告无需再下达!"
);
var
rtns
=
new
ReportAssignResponse
();
rtns
.
Results
=
new
List
<
Report
>();
foreach
(
var
report
in
reports
)
{
using
(
KiviiContext
.
Profiler
(
$"下达:
{
report
.
ReportId
}
"
))
{
try
{
//初始化metadata的description为空,为了下达是否带上文本内容,记录日志
report
.
Metadata
[
"LogDescription"
]
=
""
;
if
(!
Description
.
IsNullOrEmpty
())
report
.
Metadata
[
"LogDescription"
]
=
Description
;
(
report
.
ReportId
.
IsNullOrEmpty
()
||
report
.
DemanderName
.
IsNullOrEmpty
()
||
report
.
SampleName
.
IsNullOrEmpty
()
||
report
.
DeadDate
==
null
||
report
.
DealDate
==
null
).
ThrowIfTrue
(
$"当前报告[
{
report
.
ReportId
}
]的基本信息填写不完整,请填写完必填信息后重新操作!"
);
var
originalStatus
=
report
.
Status
;
report
.
Assign
(
StatusType
);
rtns
.
Results
.
Add
(
report
);
////report.beforeAsign(StatusType, conn);
//switch (report.Status)
//{
// case (int)ReportStatusType.Unsupported:
// report.Assign(StatusType);
// rtns.Results.Add(report);
// break;
// case (int)ReportStatusType.CommissionAccept:
// report.Assign(StatusType);
// rtns.Results.Add(report);
// break;
// case (int)ReportStatusType.ContractReview:
// report.Assign(StatusType);
// rtns.Results.Add(report);
// break;
// case (int)ReportStatusType.TaskAssign:
// report.Assign(StatusType);
// rtns.Results.Add(report);
// break;
// case (int)ReportStatusType.DataEntry:
// report.AssignTest(StatusType, null, UseThread);
// rtns.Results.Add(report);
// break;
// case (int)ReportStatusType.ReportPreparation:
// report.AssignPrepare(StatusType);
// rtns.Results.Add(report);
// break;
// case (int)ReportStatusType.ReportReview:
// report.AssignCheck(StatusType);
// rtns.Results.Add(report);
// break;
// case (int)ReportStatusType.ReportIssue:
// report.AssignIssue(StatusType, IssueDate);
// rtns.Results.Add(report);
// break;
// case (int)ReportStatusType.ReportPrint:
// report.AssignPrint(StatusType);
// rtns.Results.Add(report);
// break;
// //case 999:
// // report.AssignManager(conn);
// // rtns.Results.Add(report);
// // break;
// default:
// break;
//}
//是从报告打印下达就不走后面步骤了
if
(
originalStatus
>=
(
int
)
ReportStatusType
.
ReportPrint
)
continue
;
if
(
originalStatus
==
report
.
Status
)
continue
;
//报告任务下达后需要生成对应excel文件
if
(
originalStatus
>=
(
int
)
ReportStatusType
.
ReportIssue
&&
originalStatus
<
(
int
)
ReportStatusType
.
ReportPrint
)
{
report
.
GenerateReport
(
Configs
.
RouteReportGenerateSourcePath
,
originalStatus
,
false
);
}
else
{
report
.
GenerateReport
(
Configs
.
RouteReportGenerateSourcePath
,
originalStatus
);
}
//签发动作 需要合并excel
if
(
originalStatus
>=
(
int
)
ReportStatusType
.
ReportIssue
&&
originalStatus
<
(
int
)
ReportStatusType
.
ReportPrint
)
report
.
excuteCombine
(
Configs
.
RouteReportGenerateCombineSourcePath
);
}
catch
(
Exception
ex
)
{
throw
ex
;
}
}
}
rtns
.
Total
=
rtns
.
Results
.
Count
;
return
rtns
;
}
}
#
endregion
#
region
任务回收
...
...
Src/Transforms/RestfulReportItem.cs
View file @
9dbac85d
...
...
@@ -120,260 +120,87 @@ namespace Kivii.Lac.Lims.Transforms
}
}
//[RequiresAnyRole(SystemRoles.Administrator, SystemRoles.Manager, SystemRoles.Configuration)]
//[Api(Description = "更新扩展,录入实测值文件路径等")]
//public class ReportItemUpdateEx2 : RestfulExecution<ReportItem>
//{
// public ReportItem Item { get; set; }
// public List<ReportItem> Items { get; set; }
// public override object OnExecution(IRequest req, IResponse res)
// {
// (Item == null & Items.IsNullOrEmpty()).ThrowIfTrue("请传入要更新的信息!");
// if (Items.IsNullOrEmpty()) Items = new List<ReportItem>();
// if (Item != null)
// {
// if (!Items.Exists(o => o.Kvid == Item.Kvid)) Items.Add(Item);
// }
[
RequiresAnyRole
(
SystemRoles
.
Administrator
,
SystemRoles
.
Manager
,
SystemRoles
.
Configuration
)]
[
Api
(
Description
=
"更新扩展,录入实测值文件路径等"
)]
public
class
ReportItemUpdateEx2
:
RestfulExecution
<
ReportItem
>
{
public
ReportItem
Item
{
get
;
set
;
}
// var conn = KiviiContext.GetOpenedDbConnection<ReportItem>();
// var reportItems = conn.SelectByIds<ReportItem>(Items.ConvertAll(o => o.Kvid));
// reportItems.ThrowIfNullOrEmpty("未找到要更新的项目信息!");
public
List
<
ReportItem
>
Items
{
get
;
set
;
}
public
override
object
OnExecution
(
IRequest
req
,
IResponse
res
)
{
(
Item
==
null
&
Items
.
IsNullOrEmpty
()).
ThrowIfTrue
(
"请传入要更新的信息!"
);
if
(
Items
.
IsNullOrEmpty
())
Items
=
new
List
<
ReportItem
>();
if
(
Item
!=
null
)
{
if
(!
Items
.
Exists
(
o
=>
o
.
Kvid
==
Item
.
Kvid
))
Items
.
Add
(
Item
);
}
// var parentReportItems = conn.Select<ReportItem>(o => Sql.In(o.Kvid, reportItems.ConvertAll(p => p.ParentKvid)) & o.Type == ReportItemType.TestFolder);
var
conn
=
KiviiContext
.
GetOpenedDbConnection
<
ReportItem
>();
var
reportItems
=
conn
.
SelectByIds
<
ReportItem
>(
Items
.
ConvertAll
(
o
=>
o
.
Kvid
));
reportItems
.
ThrowIfNullOrEmpty
(
"未找到要更新的项目信息!"
);
// var rtns = new RestfulUpdateResponse<ReportItem>();
// rtns.Results = new List<ReportItem>();
var
parentReportItems
=
conn
.
Select
<
ReportItem
>(
o
=>
Sql
.
In
(
o
.
Kvid
,
reportItems
.
ConvertAll
(
p
=>
p
.
ParentKvid
))
&
o
.
Type
==
ReportItemType
.
TestFolder
);
// var trans = conn.OpenTransaction();
var
rtns
=
new
RestfulUpdateResponse
<
ReportItem
>();
rtns
.
Results
=
new
List
<
ReportItem
>();
// try
// {
// foreach (var _reportItem in reportItems)
// {
// var item = Items.FirstOrDefault(o => o.Kvid == _reportItem.Kvid);
// if (item == null) continue;
// //不支持同时传入实测值和复核人
// if (item.OnlyPropertiesIsExist(o => o.TestValue) && item.OnlyPropertiesIsExist(o => o.TestReviewerName)) continue;
// Test _test = null;
// List<Guid> nodeKvids = null;
// List<Guid> testKvids = null;
// //更新复核人时执行(只针对主项,其他项更新无效)
// if (item.OnlyPropertiesIsExist(o => o.TestReviewerName))
// {
// //不是待复核状态就不更新这个
// if (_reportItem.Status != (int)ReportItemStatusType.BeforeReview) continue;
// item.StatusType = ReportItemStatusType.TestFinished;
// item.AddOnlyProperties(o => o.Status);
// if (_reportItem.Type != ReportItemType.TestFolder && parentReportItems.FirstOrDefault(o => o.Kvid == _reportItem.ParentKvid & o.Type == ReportItemType.TestFolder) != null)
// {
// item.RemoveOnlyProperties(o => o.TestReviewerName);
// item.RemoveOnlyProperties(o => o.TestReviewerKvid);
// item.RemoveOnlyProperties(o => o.TestReviewTime);
// }
// else if (_reportItem.Type == ReportItemType.TestFolder)
// {
// //更新的是大项 则连同更新子项及对应Test
// var queryNodes = conn.From<ReportItem>();
// queryNodes.Where(o => o.ParentKvid == _reportItem.Kvid & o.Type == ReportItemType.Test);
// var nodes = conn.Select(queryNodes);
// nodeKvids = nodes.ConvertAll(o => o.Kvid);
// if (!nodeKvids.IsNullOrEmpty())
// {
// //更新nodes的复核
// var updateNodes = conn.From<ReportItem>();
// updateNodes = updateNodes.Update(o => new { o.TestReviewerKvid, o.TestReviewerName, o.TestReviewTime, o.Status });
// updateNodes = updateNodes.Where(o => Sql.In(o.Kvid, nodeKvids));
// conn.UpdateOnly(new ReportItem { TestReviewerKvid = item.TestReviewerKvid, TestReviewerName = item.TestReviewerName, TestReviewTime = DateTime.Now, Status = (int)ReportItemStatusType.TestFinished }, updateNodes);
// nodes.ForEach(o => { o.TestReviewerKvid = item.TestReviewerKvid; o.TestReviewerName = item.TestReviewerName; o.TestReviewTime = DateTime.Now; });
// rtns.Results.AddRange(nodes);
// }
// item.TestReviewTime = DateTime.Now;
// item.AddOnlyProperties(o => o.TestReviewTime);
// var queryTestKvids = conn.From<ReportItem>();
// queryTestKvids.Where(o => o.ParentKvid == _reportItem.Kvid & o.Type == ReportItemType.Test);
// queryTestKvids.Select(o => o.TestKvid);
// if (testKvids.IsNullOrEmpty()) testKvids = conn.Select<Guid>(queryTestKvids);
// if (!testKvids.IsNullOrEmpty())
// {
// //更新test的复核
// var updateTests = conn.From<Test>();
// updateTests = updateTests.Update(o => new { o.ReviewerKvid, o.ReviewerName, o.ReviewTime });
// updateTests = updateTests.Where(o => Sql.In(o.Kvid, testKvids));
// conn.UpdateOnly(new Test { ReviewerKvid = item.TestReviewerKvid, ReviewerName = item.TestReviewerName, ReviewTime = item.TestReviewTime }, updateTests);
// }
// }
// else if (_reportItem.Type == ReportItemType.Test)
// {
// //更新test的复核
// var updateTests = conn.From<Test>();
// updateTests = updateTests.Update(o => new { o.ReviewerKvid, o.ReviewerName, o.ReviewTime });
// updateTests = updateTests.Where(o => o.Kvid == _reportItem.TestKvid);
// conn.UpdateOnly(new Test { ReviewerKvid = item.TestReviewerKvid, ReviewerName = item.TestReviewerName, ReviewTime = item.TestReviewTime }, updateTests);
// }
// }
// //更改实测值执行(只针对Test项,其他项更新无效)
// if (item.OnlyPropertiesIsExist(o => o.TestValue))
// {
// if (_reportItem.Type != ReportItemType.Test)
// {
// item.RemoveOnlyProperties(o => o.TestValue);
// }
// //实测值不相同才更新
// else if (_reportItem.TestValue != item.TestValue)
// {
// //要是没有填值 就跳过
// //if (item.TestValue.IsNullOrEmpty()) continue;
// //经过计算,若完成判定则更新判定结果
// item.StatusType = ReportItemStatusType.BeforeReview;
// item.AddOnlyProperties(o => o.Status);
// _reportItem.TestValue = item.TestValue;
// if (_reportItem.CalculateJudgement(conn))
// {
// item.Judgement = _reportItem.Judgement;
// item.AddOnlyProperties(o => o.Judgement);
// }
// if (!item.TestValue.IsNullOrEmpty()) {
// var originalTest = conn.SingleById<Test>(_reportItem.RootKvid);
// var _testKvid = Guid.NewGuid();
// #region 创建一个Test
// _test = new Test();
// _test.StandardKvid = _reportItem.StandardKvid;
// _test.DetectionKvid = _reportItem.DetectionKvid;
// _test.Value = item.TestValue;
// _test.Kvid = _testKvid;
// _test.RootKvid = originalTest == null ? _test.Kvid : originalTest.RootKvid;
// _test.SampleKvid = _reportItem.SampleKvid;
// _test.SampleRootKvid = _reportItem.SampleRootKvid;
// _test.CreateTime = DateTime.Now;
// conn.Insert(_test);
// #endregion
// #region ReportItem 判定及更新Test相关字段
// item.TestKvid = _test.Kvid;
// item.AddOnlyProperties(o => o.TestKvid);
// item.TestRootKvid = _test.RootKvid;
// item.AddOnlyProperties(o => o.TestRootKvid);
// #endregion
// }
// }
// //要是有更新TestValue 复核人全部清空
// item.TestReviewerKvid = Guid.Empty;
// item.AddOnlyProperties(o => o.TestReviewerKvid);
// item.TestReviewerName = string.Empty;
// item.AddOnlyProperties(o => o.TestReviewerName);
// item.TestReviewTime = null;
// item.AddOnlyProperties(o => o.TestReviewTime);
// item.TestCreateTime = DateTime.Now;
// item.AddOnlyProperties(o => o.TestCreateTime);
// item.TestCreatorKvid = KiviiContext.CurrentMember.Kvid;
// item.AddOnlyProperties(o => o.TestCreatorKvid);
// item.TestCreatorName = KiviiContext.CurrentMember.FullName;
// item.AddOnlyProperties(o => o.TestCreatorName);
// item.StatusType = ReportItemStatusType.BeforeReview;
// item.AddOnlyProperties(o => o.Status);
// }
// //更新原始记录路径执行(只针对主项,其他项更新无效)
// if (item.OnlyPropertiesIsExist(o => o.TestOriginalFilePath))
// {
// if (_reportItem.Type != ReportItemType.TestFolder && parentReportItems.FirstOrDefault(o => o.Kvid == _reportItem.ParentKvid & o.Type == ReportItemType.TestFolder) != null)
// {
// item.RemoveOnlyProperties(o => o.TestOriginalFilePath);
// }
// else if (_reportItem.Type == ReportItemType.TestFolder)
// {
// //更新的是大项 则连同更新子项及对应Test
// var queryNodes = conn.From<ReportItem>();
// queryNodes.Where(o => o.ParentKvid == _reportItem.Kvid & o.Type == ReportItemType.Test);
// var nodes = conn.Select(queryNodes);
// nodeKvids = nodes.ConvertAll(o => o.Kvid);
// if (!nodeKvids.IsNullOrEmpty())
// {
// //更新nodes的路径
// var updateNodes = conn.From<ReportItem>();
// updateNodes = updateNodes.Update(o => o.TestOriginalFilePath);
// updateNodes = updateNodes.Where(o => Sql.In(o.Kvid, nodeKvids));
// conn.UpdateOnly(new ReportItem { TestOriginalFilePath = item.TestOriginalFilePath }, updateNodes);
// nodes.ForEach(o => { o.TestOriginalFilePath = item.TestOriginalFilePath; });
// rtns.Results.AddRange(nodes);
// }
// var queryTestKvids = conn.From<ReportItem>();
// queryTestKvids.Where(o => o.ParentKvid == _reportItem.Kvid & o.Type == ReportItemType.Test);
// queryTestKvids.Select(o => o.TestKvid);
// if (testKvids.IsNullOrEmpty()) testKvids = conn.Select<Guid>(queryTestKvids);
// if (!testKvids.IsNullOrEmpty())
// {
// //更新test的路径
// var updateTests = conn.From<Test>();
// updateTests = updateTests.Update(o => o.OriginalFilePath);
// updateTests = updateTests.Where(o => Sql.In(o.Kvid, testKvids));
// conn.UpdateOnly(new Test { OriginalFilePath = item.TestOriginalFilePath }, updateTests);
// }
// }
// //要是Test本身也是大项则也要处理
// else if (_reportItem.Type == ReportItemType.Test)
// {
// //更新test的路径
// var updateTests = conn.From<Test>();
// updateTests = updateTests.Update(o => o.OriginalFilePath);
// updateTests = updateTests.Where(o => o.Kvid == _reportItem.TestKvid);
// conn.UpdateOnly(new Test { OriginalFilePath = item.TestOriginalFilePath }, updateTests);
// }
// }
var
trans
=
conn
.
OpenTransaction
();
// if (item.OnlyProperties.Count <= 1) continue;
// conn.UpdateOnly(item);
// rtns.Results.Add(item);
try
{
foreach
(
var
_reportItem
in
reportItems
)
{
var
item
=
Items
.
FirstOrDefault
(
o
=>
o
.
Kvid
==
_reportItem
.
Kvid
);
if
(
item
==
null
)
continue
;
item
.
RemoveAllOnlyProperties
();
item
.
AddOnlyProperties
(
o
=>
o
.
Status
);
item
.
AddOnlyProperties
(
o
=>
o
.
StatusType
);
if
(
item
.
OnlyProperties
.
Count
<=
0
)
continue
;
conn
.
UpdateOnly
(
item
);
rtns
.
Results
.
Add
(
item
);
//
//更改实测值执行 要是实测值相同 就不执行下面操作
//
if (item.OnlyPropertiesIsExist(o => o.TestValue))
//
{
//
//判断是否需要更新大项
//
var parentReportItem = parentReportItems.FirstOrDefault(o => o.Kvid == _reportItem.ParentKvid & o.Type == ReportItemType.TestFolder);
//
if (parentReportItem != null)
//
{
//
if (parentReportItem.CalculateJudgement(conn))
//
{
//
parentReportItem.StatusType = ReportItemStatusType.BeforeReview;
//
parentReportItem.AddOnlyProperties(o => o.Status);
//
parentReportItem.AddOnlyProperties(o => o.Judgement);
//
parentReportItem.AddOnlyProperties(o => o.TestCreateTime);
//
parentReportItem.AddOnlyProperties(o => o.TestCreatorKvid);
//
parentReportItem.AddOnlyProperties(o => o.TestCreatorName);
//
//要是有更新TestValue 复核人全部清空
//
parentReportItem.TestReviewerKvid = Guid.Empty;
//
parentReportItem.AddOnlyProperties(o => o.TestReviewerKvid);
//
parentReportItem.TestReviewerName = string.Empty;
//
parentReportItem.AddOnlyProperties(o => o.TestReviewerName);
//
parentReportItem.TestReviewTime = null;
//
parentReportItem.AddOnlyProperties(o => o.TestReviewTime);
//
conn.UpdateOnly(parentReportItem);
//
rtns.Results.Add(parentReportItem);
//
}
//
}
//
}
//
}
//
trans?.Commit();
//
}
// catch
(Exception ex)
//
{
//
trans?.Rollback();
//
throw ex;
//
}
//更改实测值执行 要是实测值相同 就不执行下面操作
if
(
item
.
OnlyPropertiesIsExist
(
o
=>
o
.
TestValue
))
{
//判断是否需要更新大项
var
parentReportItem
=
parentReportItems
.
FirstOrDefault
(
o
=>
o
.
Kvid
==
_reportItem
.
ParentKvid
&
o
.
Type
==
ReportItemType
.
TestFolder
);
if
(
parentReportItem
!=
null
)
{
if
(
parentReportItem
.
CalculateJudgement
(
conn
))
{
parentReportItem
.
StatusType
=
ReportItemStatusType
.
BeforeReview
;
parentReportItem
.
AddOnlyProperties
(
o
=>
o
.
Status
);
parentReportItem
.
AddOnlyProperties
(
o
=>
o
.
Judgement
);
parentReportItem
.
AddOnlyProperties
(
o
=>
o
.
TestCreateTime
);
parentReportItem
.
AddOnlyProperties
(
o
=>
o
.
TestCreatorKvid
);
parentReportItem
.
AddOnlyProperties
(
o
=>
o
.
TestCreatorName
);
//要是有更新TestValue 复核人全部清空
parentReportItem
.
TestReviewerKvid
=
Guid
.
Empty
;
parentReportItem
.
AddOnlyProperties
(
o
=>
o
.
TestReviewerKvid
);
parentReportItem
.
TestReviewerName
=
string
.
Empty
;
parentReportItem
.
AddOnlyProperties
(
o
=>
o
.
TestReviewerName
);
parentReportItem
.
TestReviewTime
=
null
;
parentReportItem
.
AddOnlyProperties
(
o
=>
o
.
TestReviewTime
);
conn
.
UpdateOnly
(
parentReportItem
);
rtns
.
Results
.
Add
(
parentReportItem
);
}
}
}
}
trans
?.
Commit
();
}
catch
(
Exception
ex
)
{
trans
?.
Rollback
();
throw
ex
;
}
//
return rtns;
//
}
//
}
return
rtns
;
}
}
//代码初审 任天宇 20210904
...
...
@@ -2494,7 +2321,7 @@ namespace Kivii.Lac.Lims.Transforms
/// <summary>
/// 是否仅筛选传入的检验小组的检验项目,默认筛选全部项目
/// </summary>
public
Guid
WorkGroupKvid
{
get
;
set
;
}
public
string
WorkGroupName
{
get
;
set
;
}
/// <summary>
/// 是否是登录人所在组,默认false全部组
...
...
@@ -2546,12 +2373,12 @@ namespace Kivii.Lac.Lims.Transforms
else
{
//只查看登录人所在组
if
(
Owned
||
WorkGroupKvid
!=
Guid
.
Empty
)
if
(
Owned
||
!
WorkGroupName
.
IsNullOrEmpty
()
)
{
finalResults
=
new
List
<
ReportItem
>();
//所在组的全部大项
List
<
ReportItem
>
ownerPrimaryItems
=
null
;
if
(
WorkGroupKvid
!=
Guid
.
Empty
)
ownerPrimaryItems
=
primaryAllReportItems
.
Where
(
o
=>
o
.
WorkGroupKvid
==
WorkGroupKvid
).
ToList
();
if
(
!
WorkGroupName
.
IsNullOrEmpty
())
ownerPrimaryItems
=
primaryAllReportItems
.
Where
(
o
=>
o
.
WorkGroupName
==
WorkGroupName
).
ToList
();
else
if
(
Owned
)
{
//获取duty表中对应的角色
...
...
@@ -2598,13 +2425,13 @@ namespace Kivii.Lac.Lims.Transforms
if
(
Grouped
.
Value
)
{
//只留下未分组的项目
primaryItems
.
RemoveAll
(
o
=>
o
.
WorkGroupKvid
!=
Guid
.
Empty
);
primaryItems
.
RemoveAll
(
o
=>
!
o
.
WorkGroupName
.
IsNullOrEmpty
()
);
}
//只查未分组
else
{
//只留下已分组的项目
primaryItems
.
RemoveAll
(
o
=>
o
.
WorkGroup
Kvid
==
Guid
.
Empty
);
primaryItems
.
RemoveAll
(
o
=>
o
.
WorkGroup
Name
.
IsNullOrEmpty
()
);
}
//待移除的大项
var
preRemoveKvids
=
primaryItems
.
ConvertAll
(
p
=>
p
.
Kvid
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment