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
065b17ff
Commit
065b17ff
authored
Jul 05, 2023
by
任天宇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增样品迁移功能,用于已打包的样品迁移到其他包裹内
parent
0f3cbbc5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
167 additions
and
1 deletion
+167
-1
SampleExtension.cs
Src/SampleExtension.cs
+113
-0
RestfulSample.cs
Src/Transforms/RestfulSample.cs
+54
-1
No files found.
Src/SampleExtension.cs
View file @
065b17ff
...
...
@@ -520,6 +520,119 @@ namespace Kivii.Samples
}
/// <summary>
/// 样品迁移
/// </summary>
/// <param name="samples"></param>
/// <param name="package"></param>
/// <param name="location"></param>
/// <param name="route"></param>
/// <param name="conn"></param>
/// <returns></returns>
public
static
List
<
Sample
>
PackageMoving
(
this
List
<
Sample
>
samples
,
Sample
package
,
Location
location
,
Route
route
=
null
,
IDbConnection
conn
=
null
)
{
samples
.
ThrowIfNullOrEmpty
(
"请传入要移库的样品信息!"
);
package
.
ThrowIfNull
(
"请传入包裹信息!"
);
(
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
currentSamples
=
conn
.
SelectByIds
<
Sample
>(
samples
.
ConvertAll
(
p
=>
p
.
Kvid
));
currentSamples
.
ThrowIfNullOrEmpty
(
"未找到要移库的样品信息!"
);
(
currentSamples
.
Exists
(
o
=>
o
.
PackageKvid
==
Guid
.
Empty
)).
ThrowIfTrue
(
"存在未入箱的样品,无法移库!"
);
var
currentPackages
=
conn
.
SelectByIds
<
Sample
>(
currentSamples
.
ConvertAll
(
p
=>
p
.
PackageKvid
));
if
(!
currentPackages
.
IsNullOrEmpty
())
{
(
currentPackages
.
Exists
(
o
=>
o
.
Status
==
(
int
)
PackageStatus
.
Inbound
)).
ThrowIfTrue
(
"存在箱子已经入库,无法移动样品!"
);
}
var
rtns
=
new
List
<
Sample
>();
IDbTransaction
trans
=
null
;
//事务,如果外部来了Connection,不生成事务
if
(
useTransaction
)
{
trans
=
conn
.
OpenTransaction
();
}
try
{
package
.
Status
=
(
int
)
PackageStatus
.
Full
;
package
.
AddOnlyProperties
(
o
=>
o
.
Status
);
conn
.
UpdateOnly
(
package
);
foreach
(
var
item
in
currentSamples
)
{
var
currentRoute
=
item
.
GetCurrentRoute
();
//if (currentRoute != null)
//{
// //判断当前拆分地点和此样品所在地一致 要是不一致要先流转到此地
// if (currentRoute.CurrentLocationKvid != location.Kvid)
// {
// item.Assign(location, null, conn);
// currentRoute = item.GetCurrentRoute();
// }
//}
//如果当前样品存在当前路由信息就更新
//if (!currentRoutes.IsNullOrEmpty())
//{
// var currentRoute = currentRoutes.FirstOrDefault(o => o.SampleKvid == item.Kvid);
if
(
currentRoute
!=
null
)
{
currentRoute
.
NextLocationKvid
=
location
.
Kvid
;
currentRoute
.
NextLocationTitle
=
location
.
Title
;
currentRoute
.
AddOnlyProperties
(
o
=>
o
.
NextLocationKvid
);
currentRoute
.
AddOnlyProperties
(
o
=>
o
.
NextLocationTitle
);
conn
.
UpdateOnly
(
currentRoute
);
}
//}
//生成新的路由信息
Route
newRoute
=
new
Route
();
if
(
route
!=
null
)
newRoute
.
PopulateWith
(
route
);
newRoute
.
SampleRootKvid
=
item
.
RootKvid
;
newRoute
.
SampleKvid
=
item
.
Kvid
;
newRoute
.
SampleParentKvid
=
item
.
ParentKvid
;
newRoute
.
SampleName
=
item
.
Name
;
newRoute
.
BizId
=
item
.
BizId
;
newRoute
.
BizKvid
=
item
.
BizKvid
;
newRoute
.
BizType
=
item
.
BizType
;
newRoute
.
Title
=
newRoute
.
Title
.
IsNullOrEmpty
()
?
$"样品[
{
item
.
Name
}
]从[
{(
item
.
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
);
//更新样品的包裹Kvid
item
.
PackageName
=
$"
{
package
.
Name
}
"
;
item
.
AddOnlyProperties
(
o
=>
o
.
PackageName
);
item
.
PackageKvid
=
package
.
Kvid
;
item
.
AddOnlyProperties
(
o
=>
o
.
PackageKvid
);
conn
.
UpdateOnly
(
item
);
item
.
RemoveAllOnlyProperties
();
rtns
.
Add
(
item
);
}
trans
?.
Commit
();
}
catch
(
Exception
ex
)
{
trans
?.
Rollback
();
throw
ex
;
}
return
rtns
;
}
/// <summary>
/// 包裹拆分
/// </summary>
/// <param name="sample"></param>
...
...
Src/Transforms/RestfulSample.cs
View file @
065b17ff
...
...
@@ -122,12 +122,13 @@ namespace Kivii.Samples.Transforms
{
rtns
.
Result
=
exist
;
}
else
if
(
AutoCreate
)
else
if
(
AutoCreate
)
{
var
item
=
new
Sample
();
item
.
Name
=
PackageName
;
item
.
Type
=
SampleType
.
Package
;
item
.
OperateTime
=
DateTime
.
Now
;
item
.
Category
=
item
.
Type
.
ToString
();
conn
.
Insert
(
item
);
item
.
RemoveAllOnlyProperties
();
rtns
.
Result
=
item
;
...
...
@@ -586,6 +587,58 @@ namespace Kivii.Samples.Transforms
}
[
RequiresAnyRole
(
SystemRoles
.
Everyone
)]
[
Api
(
Description
=
"包裹移库,已经打包的样品迁移到其他包裹中"
)]
public
class
SamplePackageMove
:
RestfulExecution
<
Sample
>
{
public
Guid
SampleKvid
{
get
;
set
;
}
//要迁移的样品
public
List
<
Guid
>
SampleKvids
{
get
;
set
;
}
//要迁移的样品(此样品前提是已经打包的否则不允许移库)
public
Guid
PackageKvid
{
get
;
set
;
}
//目标包裹信息
public
Location
Location
{
get
;
set
;
}
//地点位置信息,只需要InternalCode
public
Route
Route
{
get
;
set
;
}
//自定义路由信息,可不填写
public
override
object
OnExecution
(
IRequest
req
,
IResponse
res
)
{
(
SampleKvid
==
Guid
.
Empty
&&
SampleKvids
.
IsNullOrEmpty
()).
ThrowIfTrue
(
"缺少要打包的样品信息!"
);
Location
.
ThrowIfNull
(
"缺少打包地点信息!"
);
(
Location
.
InternalCode
.
IsNullOrEmpty
()).
ThrowIfTrue
(
"缺少打包地点配置InternalCode信息"
);
PackageKvid
.
ThrowIfNotEmpty
(
"缺少包裹信息!"
);
var
conn
=
KiviiContext
.
GetOpenedDbConnection
<
Location
>();
var
local
=
conn
.
Single
<
Location
>(
o
=>
o
.
InternalCode
==
Location
.
InternalCode
);
(
local
==
null
).
ThrowIfTrue
(
$"未找到
{
Location
.
InternalCode
}
打包地点配置信息!"
);
Sample
package
=
conn
.
SingleById
<
Sample
>(
PackageKvid
);
if
(
SampleKvids
.
IsNullOrEmpty
())
SampleKvids
=
new
List
<
Guid
>();
if
(
SampleKvid
!=
Guid
.
Empty
)
SampleKvids
.
Add
(
SampleKvid
);
var
samples
=
new
List
<
Sample
>();
foreach
(
var
kvid
in
SampleKvids
)
{
var
sample
=
new
Sample
();
sample
.
Kvid
=
kvid
;
samples
.
Add
(
sample
);
}
var
rtns
=
new
RestfulExecutionResponse
<
Sample
>();
rtns
.
Results
=
new
List
<
Sample
>();
var
trans
=
conn
.
OpenTransaction
();
try
{
rtns
.
Results
=
samples
.
PackageMoving
(
package
,
local
,
Route
,
conn
);
trans
.
Commit
();
}
catch
(
Exception
ex
)
{
trans
.
Rollback
();
throw
ex
;
}
return
rtns
;
}
}
[
RequiresAnyRole
(
SystemRoles
.
Everyone
)]
[
Api
(
Description
=
"包裹取样"
)]
public
class
SampleUnPackaging
:
RestfulExecution
<
Sample
>
{
...
...
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