Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
Kivii.Biz.Samples.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.Biz.Samples.V4.5
Commits
bbc15d01
Commit
bbc15d01
authored
Jun 13, 2023
by
陶然
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加了样品包裹清空的接口,优化了包裹取样接口传递的参数,支持批量取样
parent
623a41bf
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
214 additions
and
61 deletions
+214
-61
SampleExtension.cs
Src/SampleExtension.cs
+151
-58
RestfulSample.cs
Src/Transforms/RestfulSample.cs
+63
-3
No files found.
Src/SampleExtension.cs
View file @
bbc15d01
...
...
@@ -2,6 +2,7 @@
using
Kivii.Linq.Legacy
;
using
Kivii.Samples.Entities
;
using
System
;
using
System.Collections
;
using
System.Collections.Generic
;
using
System.Data
;
using
System.Linq
;
...
...
@@ -131,26 +132,27 @@ namespace Kivii.Samples
try
{
#
region
生成新的路由信息
,
更新上一个路由信息
if
(
route
==
null
)
route
=
new
Route
();
route
.
SampleRootKvid
=
existSample
.
RootKvid
;
route
.
SampleKvid
=
existSample
.
Kvid
;
route
.
SampleParentKvid
=
existSample
.
ParentKvid
;
route
.
SampleName
=
existSample
.
Name
;
route
.
BizId
=
existSample
.
BizId
;
route
.
BizKvid
=
existSample
.
BizKvid
;
route
.
BizType
=
existSample
.
BizType
;
route
.
Title
=
route
.
Title
.
IsNullOrEmpty
()
?
$"样品[
{
existSample
.
Name
}
]流转"
:
route
.
Title
;
route
.
Type
=
route
.
Type
.
IsNullOrEmpty
()
?
"流转"
:
route
.
Type
;
route
.
CurrentLocationKvid
=
location
.
Kvid
;
route
.
CurrentLocationTitle
=
location
.
Title
;
route
.
OperateTime
=
route
.
OperateTime
==
DateTime
.
MinValue
?
DateTime
.
Now
:
route
.
OperateTime
;
existSample
.
AssignTime
=
route
.
OperateTime
;
if
(
route
.
OperatorName
.
IsNullOrEmpty
())
{
route
.
OperatorName
=
KiviiContext
.
CurrentMember
.
FullName
;
route
.
OperatorKvid
=
KiviiContext
.
CurrentMember
.
Kvid
;
}
conn
.
Insert
(
route
);
Route
newRoute
=
new
Route
();
if
(
route
!=
null
)
newRoute
.
PopulateWith
(
route
);
newRoute
.
SampleRootKvid
=
existSample
.
RootKvid
;
newRoute
.
SampleKvid
=
existSample
.
Kvid
;
newRoute
.
SampleParentKvid
=
existSample
.
ParentKvid
;
newRoute
.
SampleName
=
existSample
.
Name
;
newRoute
.
BizId
=
existSample
.
BizId
;
newRoute
.
BizKvid
=
existSample
.
BizKvid
;
newRoute
.
BizType
=
existSample
.
BizType
;
newRoute
.
Title
=
newRoute
.
Title
.
IsNullOrEmpty
()
?
$"样品[
{
existSample
.
Name
}
]流转"
:
newRoute
.
Title
;
newRoute
.
Type
=
newRoute
.
Type
.
IsNullOrEmpty
()
?
"流转"
:
newRoute
.
Type
;
newRoute
.
CurrentLocationKvid
=
location
.
Kvid
;
newRoute
.
CurrentLocationTitle
=
location
.
Title
;
newRoute
.
OperateTime
=
newRoute
.
OperateTime
==
DateTime
.
MinValue
?
DateTime
.
Now
:
newRoute
.
OperateTime
;
existSample
.
AssignTime
=
newRoute
.
OperateTime
;
if
(
newRoute
.
OperatorName
.
IsNullOrEmpty
())
{
newRoute
.
OperatorName
=
KiviiContext
.
CurrentMember
.
FullName
;
newRoute
.
OperatorKvid
=
KiviiContext
.
CurrentMember
.
Kvid
;
}
conn
.
Insert
(
newRoute
);
if
(
currentRoute
!=
null
)
{
...
...
@@ -258,6 +260,94 @@ namespace Kivii.Samples
}
/// <summary>
/// 包裹清除
/// </summary>
/// <param name="packages"></param>
/// <param name="location"></param>
/// <returns></returns>
public
static
List
<
Sample
>
PackageClear
(
this
List
<
Sample
>
packages
,
Location
location
,
Route
route
=
null
,
IDbConnection
conn
=
null
)
{
packages
.
ThrowIfNullOrEmpty
(
"请传入要清理的包裹!"
);
(
location
==
null
).
ThrowIfTrue
(
"缺少目的地点配置信息!"
);
bool
useTransaction
=
conn
==
null
;
//是否启用内部事务
if
(
conn
==
null
)
conn
=
KiviiContext
.
GetOpenedDbConnection
<
Sample
>();
conn
.
InitEntityType
<
Location
>();
if
(
location
.
Kvid
==
Guid
.
Empty
)
{
(
location
.
InternalCode
.
IsNullOrEmpty
()).
ThrowIfTrue
(
"缺少目的地点配置InternalCode信息"
);
location
=
conn
.
Single
<
Location
>(
o
=>
o
.
InternalCode
==
location
.
InternalCode
);
(
location
==
null
).
ThrowIfTrue
(
$"未找到
{
location
.
InternalCode
}
目的地点配置信息!"
);
}
var
exists
=
conn
.
SelectByIds
<
Sample
>(
packages
.
ConvertAll
(
p
=>
p
.
Kvid
));
exists
.
ThrowIfNullOrEmpty
(
"未找到要清理的包裹!"
);
exists
.
Exists
(
o
=>
o
.
Type
!=
SampleType
.
Package
).
ThrowIfTrue
(
"存在不是包裹的信息!"
);
var
samples
=
conn
.
Select
<
Sample
>(
o
=>
Sql
.
In
(
o
.
PackageKvid
,
exists
.
ConvertAll
(
p
=>
p
.
Kvid
)));
var
rtns
=
new
List
<
Sample
>();
IDbTransaction
trans
=
null
;
//事务,如果外部来了Connection,不生成事务
if
(
useTransaction
)
{
trans
=
conn
.
OpenTransaction
();
}
try
{
var
updatePackagess
=
conn
.
From
<
Sample
>();
updatePackagess
=
updatePackagess
.
Update
(
o
=>
new
{
o
.
PackageKvid
,
o
.
PackageName
,
o
.
Status
});
updatePackagess
=
updatePackagess
.
Where
(
o
=>
Sql
.
In
(
o
.
Kvid
,
exists
.
ConvertAll
(
p
=>
p
.
Kvid
)));
conn
.
UpdateOnly
<
Sample
>(
new
Sample
{
PackageKvid
=
Guid
.
Empty
,
PackageName
=
string
.
Empty
,
Status
=
(
int
)
PackageStatus
.
Empty
},
updatePackagess
);
if
(!
samples
.
IsNullOrEmpty
())
{
var
updateSampless
=
conn
.
From
<
Sample
>();
updateSampless
=
updateSampless
.
Update
(
o
=>
new
{
o
.
PackageKvid
,
o
.
PackageName
});
updateSampless
=
updateSampless
.
Where
(
o
=>
Sql
.
In
(
o
.
Kvid
,
samples
.
ConvertAll
(
p
=>
p
.
Kvid
)));
conn
.
UpdateOnly
<
Sample
>(
new
Sample
{
PackageKvid
=
Guid
.
Empty
,
PackageName
=
string
.
Empty
},
updateSampless
);
foreach
(
var
item
in
samples
)
{
var
package
=
exists
.
FirstOrDefault
(
o
=>
o
.
Kvid
==
item
.
PackageKvid
);
var
currentRoute
=
item
.
GetCurrentRoute
();
//conn.Single<Route>(o => o.SampleKvid == existSample.Kvid && o.NextLocationKvid == Guid.Empty);
if
(
route
==
null
)
route
=
new
Route
();
route
.
SampleRootKvid
=
item
.
RootKvid
;
route
.
SampleKvid
=
item
.
Kvid
;
route
.
SampleParentKvid
=
item
.
ParentKvid
;
route
.
SampleName
=
item
.
Name
;
route
.
BizId
=
item
.
BizId
;
route
.
BizKvid
=
item
.
BizKvid
;
route
.
BizType
=
item
.
BizType
;
route
.
Title
=
route
.
Title
.
IsNullOrEmpty
()
?
$"出库报废,样品[
{
item
.
Name
}
]已报废"
:
route
.
Title
;
route
.
Type
=
route
.
Type
.
IsNullOrEmpty
()
?
"出库报废"
:
route
.
Type
;
if
(
package
!=
null
)
route
.
Summary
=
$"原货区:
{
package
.
PackageName
}
,箱号:
{
package
.
Name
}
"
;
route
.
CurrentLocationKvid
=
location
.
Kvid
;
route
.
CurrentLocationTitle
=
location
.
Title
;
route
.
OperateTime
=
route
.
OperateTime
==
DateTime
.
MinValue
?
DateTime
.
Now
:
route
.
OperateTime
;
if
(
route
.
OperatorName
.
IsNullOrEmpty
())
{
route
.
OperatorName
=
KiviiContext
.
CurrentMember
.
FullName
;
route
.
OperatorKvid
=
KiviiContext
.
CurrentMember
.
Kvid
;
}
conn
.
Insert
(
route
);
if
(
currentRoute
!=
null
)
{
currentRoute
.
NextLocationKvid
=
location
.
Kvid
;
currentRoute
.
NextLocationTitle
=
location
.
Title
;
currentRoute
.
AddOnlyProperties
(
o
=>
o
.
NextLocationKvid
);
currentRoute
.
AddOnlyProperties
(
o
=>
o
.
NextLocationTitle
);
conn
.
UpdateOnly
(
currentRoute
);
}
}
rtns
.
AddRange
(
samples
);
}
trans
?.
Commit
();
}
catch
(
Exception
ex
)
{
trans
?.
Rollback
();
throw
ex
;
}
return
rtns
;
}
/// <summary>
/// 样品打包
/// </summary>
/// <param name="samples"></param>
...
...
@@ -319,25 +409,27 @@ namespace Kivii.Samples
package
.
OperateTime
=
package
.
OperateTime
==
DateTime
.
MinValue
?
DateTime
.
Now
:
package
.
OperateTime
;
package
.
Status
=
(
int
)
PackageStatus
.
Full
;
conn
.
Insert
(
package
);
if
(
packageRoute
==
null
)
packageRoute
=
new
Route
();
packageRoute
.
SampleRootKvid
=
package
.
RootKvid
;
packageRoute
.
SampleKvid
=
package
.
Kvid
;
packageRoute
.
SampleParentKvid
=
package
.
ParentKvid
;
packageRoute
.
SampleName
=
package
.
Name
;
packageRoute
.
BizId
=
package
.
BizId
;
packageRoute
.
BizKvid
=
package
.
BizKvid
;
packageRoute
.
BizType
=
package
.
BizType
;
packageRoute
.
Title
=
packageRoute
.
Title
.
IsNullOrEmpty
()
?
$"样品打包"
:
packageRoute
.
Title
;
packageRoute
.
Type
=
packageRoute
.
Type
.
IsNullOrEmpty
()
?
"打包"
:
packageRoute
.
Type
;
packageRoute
.
CurrentLocationKvid
=
location
.
Kvid
;
packageRoute
.
CurrentLocationTitle
=
location
.
Title
;
packageRoute
.
OperateTime
=
packageRoute
.
OperateTime
==
DateTime
.
MinValue
?
DateTime
.
Now
:
packageRoute
.
OperateTime
;
if
(
packageRoute
.
OperatorName
.
IsNullOrEmpty
())
{
packageRoute
.
OperatorName
=
KiviiContext
.
CurrentMember
.
FullName
;
packageRoute
.
OperatorKvid
=
KiviiContext
.
CurrentMember
.
Kvid
;
}
conn
.
Insert
(
packageRoute
);
Route
newRoute
=
new
Route
();
if
(
packageRoute
!=
null
)
newRoute
.
PopulateWith
(
packageRoute
);
//if (packageRoute == null) packageRoute = new Route();
newRoute
.
SampleRootKvid
=
package
.
RootKvid
;
newRoute
.
SampleKvid
=
package
.
Kvid
;
newRoute
.
SampleParentKvid
=
package
.
ParentKvid
;
newRoute
.
SampleName
=
package
.
Name
;
newRoute
.
BizId
=
package
.
BizId
;
newRoute
.
BizKvid
=
package
.
BizKvid
;
newRoute
.
BizType
=
package
.
BizType
;
newRoute
.
Title
=
newRoute
.
Title
.
IsNullOrEmpty
()
?
$"样品打包至:
{
package
.
Name
}{(
packageArea
.
IsNullOrEmpty
()
?
""
:
$"(
{
packageArea
}
)"
)}
"
:
newRoute
.
Title
;
newRoute
.
Type
=
newRoute
.
Type
.
IsNullOrEmpty
()
?
"打包"
:
newRoute
.
Type
;
newRoute
.
CurrentLocationKvid
=
location
.
Kvid
;
newRoute
.
CurrentLocationTitle
=
location
.
Title
;
newRoute
.
OperateTime
=
newRoute
.
OperateTime
==
DateTime
.
MinValue
?
DateTime
.
Now
:
newRoute
.
OperateTime
;
if
(
newRoute
.
OperatorName
.
IsNullOrEmpty
())
{
newRoute
.
OperatorName
=
KiviiContext
.
CurrentMember
.
FullName
;
newRoute
.
OperatorKvid
=
KiviiContext
.
CurrentMember
.
Kvid
;
}
conn
.
Insert
(
newRoute
);
}
else
{
...
...
@@ -457,25 +549,26 @@ namespace Kivii.Samples
exist
.
AddOnlyProperties
(
o
=>
o
.
PackageKvid
);
conn
.
UpdateOnly
(
exist
);
if
(
route
==
null
)
route
=
new
Route
();
route
.
SampleRootKvid
=
exist
.
RootKvid
;
route
.
SampleKvid
=
exist
.
Kvid
;
route
.
SampleParentKvid
=
exist
.
ParentKvid
;
route
.
SampleName
=
exist
.
Name
;
route
.
BizId
=
exist
.
BizId
;
route
.
BizKvid
=
exist
.
BizKvid
;
route
.
BizType
=
exist
.
BizType
;
route
.
Title
=
route
.
Title
.
IsNullOrEmpty
()
?
$"包裹取出样品[
{
exist
.
Name
}
]"
:
route
.
Title
;
route
.
Type
=
route
.
Type
.
IsNullOrEmpty
()
?
"包裹取样"
:
route
.
Type
;
route
.
CurrentLocationKvid
=
location
.
Kvid
;
route
.
CurrentLocationTitle
=
location
.
Title
;
route
.
OperateTime
=
route
.
OperateTime
==
DateTime
.
MinValue
?
DateTime
.
Now
:
route
.
OperateTime
;
if
(
route
.
OperatorName
.
IsNullOrEmpty
())
{
route
.
OperatorName
=
KiviiContext
.
CurrentMember
.
FullName
;
route
.
OperatorKvid
=
KiviiContext
.
CurrentMember
.
Kvid
;
}
conn
.
Insert
(
route
);
Route
newRoute
=
new
Route
();
if
(
route
!=
null
)
newRoute
.
PopulateWith
(
route
);
newRoute
.
SampleRootKvid
=
exist
.
RootKvid
;
newRoute
.
SampleKvid
=
exist
.
Kvid
;
newRoute
.
SampleParentKvid
=
exist
.
ParentKvid
;
newRoute
.
SampleName
=
exist
.
Name
;
newRoute
.
BizId
=
exist
.
BizId
;
newRoute
.
BizKvid
=
exist
.
BizKvid
;
newRoute
.
BizType
=
exist
.
BizType
;
newRoute
.
Title
=
newRoute
.
Title
.
IsNullOrEmpty
()
?
$"样品[
{
exist
.
Name
}
]从[
{(
package
.
PackageName
.
IsNullOrEmpty
()
?
package
.
Name
:
$"
{
package
.
PackageName
}
(
{
package
.
Name
}
)"
)}
]取出"
:
newRoute
.
Title
;
newRoute
.
Type
=
newRoute
.
Type
.
IsNullOrEmpty
()
?
"取样"
:
newRoute
.
Type
;
newRoute
.
CurrentLocationKvid
=
location
.
Kvid
;
newRoute
.
CurrentLocationTitle
=
location
.
Title
;
newRoute
.
OperateTime
=
newRoute
.
OperateTime
==
DateTime
.
MinValue
?
DateTime
.
Now
:
newRoute
.
OperateTime
;
if
(
newRoute
.
OperatorName
.
IsNullOrEmpty
())
{
newRoute
.
OperatorName
=
KiviiContext
.
CurrentMember
.
FullName
;
newRoute
.
OperatorKvid
=
KiviiContext
.
CurrentMember
.
Kvid
;
}
conn
.
Insert
(
newRoute
);
if
(
currentRoute
!=
null
)
{
...
...
Src/Transforms/RestfulSample.cs
View file @
bbc15d01
...
...
@@ -233,6 +233,53 @@ namespace Kivii.Samples.Transforms
}
[
RequiresAnyRole
(
SystemRoles
.
Everyone
)]
[
Api
(
Description
=
"包裹清空"
)]
public
class
SamplePackageClear
:
RestfulExecution
<
Sample
>
{
public
Guid
PackageKvid
{
get
;
set
;
}
//要流转样品信息
public
List
<
Guid
>
PackageKvids
{
get
;
set
;
}
//要流转样品信息
public
Location
Location
{
get
;
set
;
}
//地点位置信息,只需要InternalCode
public
Route
Route
{
get
;
set
;
}
//自定义路由信息,可不填写
public
override
object
OnExecution
(
IRequest
req
,
IResponse
res
)
{
(
PackageKvid
==
Guid
.
Empty
&&
PackageKvids
.
IsNullOrEmpty
()).
ThrowIfTrue
(
"缺少要打包的样品信息!"
);
Location
.
ThrowIfNull
(
"缺少打包地点信息!"
);
(
Location
.
InternalCode
.
IsNullOrEmpty
()).
ThrowIfTrue
(
"缺少打包地点配置InternalCode信息"
);
var
conn
=
KiviiContext
.
GetOpenedDbConnection
<
Location
>();
var
local
=
conn
.
Single
<
Location
>(
o
=>
o
.
InternalCode
==
Location
.
InternalCode
);
(
local
==
null
).
ThrowIfTrue
(
$"未找到
{
Location
.
InternalCode
}
打包地点配置信息!"
);
if
(
PackageKvids
.
IsNullOrEmpty
())
PackageKvids
=
new
List
<
Guid
>();
if
(
PackageKvid
!=
Guid
.
Empty
)
PackageKvids
.
Add
(
PackageKvid
);
var
packages
=
new
List
<
Sample
>();
foreach
(
var
kvid
in
PackageKvids
)
{
var
package
=
new
Sample
();
package
.
Kvid
=
kvid
;
packages
.
Add
(
package
);
}
var
rtns
=
new
RestfulExecutionResponse
<
Sample
>();
rtns
.
Results
=
new
List
<
Sample
>();
var
trans
=
conn
.
OpenTransaction
();
try
{
rtns
.
Results
=
packages
.
PackageClear
(
local
,
Route
,
conn
);
trans
.
Commit
();
}
catch
(
Exception
ex
)
{
trans
.
Rollback
();
throw
ex
;
}
return
rtns
;
}
}
[
RequiresAnyRole
(
SystemRoles
.
Everyone
)]
[
Api
(
Description
=
"打包样查找"
)]
public
class
SamplePrePackaging
:
RestfulExecution
<
Sample
>
{
...
...
@@ -396,20 +443,30 @@ namespace Kivii.Samples.Transforms
public
class
SampleUnPackaging
:
RestfulExecution
<
Sample
>
{
public
Guid
Kvid
{
get
;
set
;
}
//要取样品的信息
public
List
<
Guid
>
Kvids
{
get
;
set
;
}
//要取样品的信息
//public Guid Kvid { get; set; }//要取样品的信息
public
Location
Location
{
get
;
set
;
}
//地点位置信息,只需要InternalCode
public
Route
Route
{
get
;
set
;
}
//自定义路由信息,可不填写
public
override
object
OnExecution
(
IRequest
req
,
IResponse
res
)
{
(
Kvid
==
Guid
.
Empty
).
ThrowIfTrue
(
"缺少要要取样品信息!"
);
(
Kvid
==
Guid
.
Empty
&&
Kvids
.
IsNullOrEmpty
()).
ThrowIfTrue
(
"缺少要取样品的信息!"
);
//(Kvid == Guid.Empty).ThrowIfTrue("缺少要要取样品信息!");
Location
.
ThrowIfNull
(
"缺少取样地点信息!"
);
(
Location
.
InternalCode
.
IsNullOrEmpty
()).
ThrowIfTrue
(
"缺少取样地点配置InternalCode信息"
);
var
conn
=
KiviiContext
.
GetOpenedDbConnection
<
Location
>();
var
local
=
conn
.
Single
<
Location
>(
o
=>
o
.
InternalCode
==
Location
.
InternalCode
);
(
local
==
null
).
ThrowIfTrue
(
$"未找到
{
Location
.
InternalCode
}
打包地点配置信息!"
);
if
(
Kvids
.
IsNullOrEmpty
())
Kvids
=
new
List
<
Guid
>();
if
(
Kvid
!=
Guid
.
Empty
)
Kvids
.
Add
(
Kvid
);
List
<
Sample
>
samples
=
new
List
<
Sample
>();
foreach
(
var
kvid
in
Kvids
)
{
var
sample
=
new
Sample
();
sample
.
Kvid
=
Kvid
;
sample
.
Kvid
=
kvid
;
samples
.
Add
(
sample
);
}
var
rtns
=
new
RestfulExecutionResponse
<
Sample
>();
rtns
.
Results
=
new
List
<
Sample
>();
...
...
@@ -417,8 +474,11 @@ namespace Kivii.Samples.Transforms
var
trans
=
conn
.
OpenTransaction
();
try
{
var
result
=
sample
.
UnPackaging
(
local
,
Route
,
conn
);
foreach
(
var
item
in
samples
)
{
var
result
=
item
.
UnPackaging
(
local
,
Route
,
conn
);
rtns
.
Results
.
Add
(
result
);
}
trans
.
Commit
();
}
catch
(
Exception
ex
)
...
...
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