Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
Laisi_AutoMES2
Overview
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
jiawei.su
Laisi_AutoMES2
Commits
7f13f955
Commit
7f13f955
authored
Feb 08, 2021
by
chenzhengpeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
code repo
parent
91115f3c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
182 additions
and
127 deletions
+182
-127
AutomationController.cs
Server/Apis/Siger.ApiACC/Controllers/AutomationController.cs
+90
-80
AutomationTaskListRepository.cs
...ccRepository/Repositories/AutomationTaskListRepository.cs
+92
-47
No files found.
Server/Apis/Siger.ApiACC/Controllers/AutomationController.cs
View file @
7f13f955
...
...
@@ -43,7 +43,7 @@ namespace Siger.ApiACC.Controllers
private
readonly
IProductRouteRepository
_productRoute
;
private
readonly
IAutomationSectionPropertyRepository
_automationSectionProperty
;
public
AutomationController
(
IUnitOfWork
unitOfWork
,
ISigerProjectLevelSectionRepository
sigerProjectLevelSection
,
IAutomationLineMode
automationLineMode
,
IAutomationMachineStatus
automationMachineStatus
,
ISigerDict
sigerDict
,
IAutomationTaskListRepository
automationTaskList
,
public
AutomationController
(
IUnitOfWork
unitOfWork
,
ISigerProjectLevelSectionRepository
sigerProjectLevelSection
,
IAutomationLineMode
automationLineMode
,
IAutomationMachineStatus
automationMachineStatus
,
ISigerDict
sigerDict
,
IAutomationTaskListRepository
automationTaskList
,
ISigerProjectMachineAttributionRepository
sigerProjectMachineAttribution
,
IAutomationFixtureMonitor
automationFixtureMonitor
,
IAutomationLocationRepository
automationLocation
,
IProductionBeatSetRepository
productionBeatSet
,
IAutomationFixtureToolsProductRepository
automationFixtureToolsProduct
,
IAutomationFixtureToolsRepository
automationFixtureTools
,
IProductRouteRepository
productRoute
,
IAutomationSectionPropertyRepository
automationSectionProperty
)
{
...
...
@@ -62,32 +62,34 @@ namespace Siger.ApiACC.Controllers
_productRoute
=
productRoute
;
_automationSectionProperty
=
automationSectionProperty
;
}
/// <summary>
/// 设备状态接口 用于 保存 设备当前可用状态
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[
HttpPost
]
public
IActionResult
MachineStatus
([
FromBody
]
RequestAutomationMachine
request
)
public
IActionResult
MachineStatus
([
FromBody
]
RequestAutomationMachine
request
)
{
var
machineAttr
=
_sigerProjectMachineAttribution
.
Get
(
f
=>
f
.
projectid
==
PID
&&
f
.
machine
==
request
.
machineid
&&
f
.
status
==
(
int
)
RowState
.
Valid
);
if
(
machineAttr
==
null
)
var
machineAttr
=
_sigerProjectMachineAttribution
.
Get
(
f
=>
f
.
projectid
==
PID
&&
f
.
machine
==
request
.
machineid
&&
f
.
status
==
(
int
)
RowState
.
Valid
);
if
(
machineAttr
==
null
)
{
throw
new
BadRequestException
(
ConfigEnum
.
MachineAttributionNotFound
);
}
var
exitsObj
=
_automationMachineStatus
.
Get
(
f
=>
f
.
machineid
==
request
.
machineid
);
if
(
exitsObj
==
null
)
var
exitsObj
=
_automationMachineStatus
.
Get
(
f
=>
f
.
machineid
==
request
.
machineid
);
if
(
exitsObj
==
null
)
{
_automationMachineStatus
.
Insert
(
new
siger_automation_machine_status
{
section
=
machineAttr
.
station
,
machineid
=
request
.
machineid
,
projectId
=
PID
,
updatetime
=
DateTime
.
Now
,
enable
=
request
.
enable
==
1
?
1
:
0
,
status
=
request
.
status
_automationMachineStatus
.
Insert
(
new
siger_automation_machine_status
{
section
=
machineAttr
.
station
,
machineid
=
request
.
machineid
,
projectId
=
PID
,
updatetime
=
DateTime
.
Now
,
enable
=
request
.
enable
==
1
?
1
:
0
,
status
=
request
.
status
});
}
else
}
else
{
exitsObj
.
section
=
machineAttr
.
station
;
exitsObj
.
enable
=
request
.
enable
;
...
...
@@ -95,8 +97,8 @@ namespace Siger.ApiACC.Controllers
exitsObj
.
updatetime
=
DateTime
.
Now
;
_automationMachineStatus
.
Update
(
exitsObj
);
}
if
(
_unitOfWork
.
Commit
()
>
0
)
{
// 设备空闲,或者完成时触发 自动任务
...
...
@@ -108,7 +110,7 @@ namespace Siger.ApiACC.Controllers
var
section
=
_sigerProjectLevelSection
.
Get
(
f
=>
f
.
id
==
machineAttr
.
station
);
if
(
section
!=
null
)
{
Logger
.
WriteLineInfo
(
$"
MachineStatus 设备
{
section
.
title
}
状态 触发自动任务检查
"
);
Logger
.
WriteLineInfo
(
$"
自动化业务流转--MachineStatus 设备
{
section
.
title
}
状态 触发自动任务检查 section parentid:
{
section
.
parentid
}
"
);
AutoProcess
(
section
.
parentid
);
}
}
...
...
@@ -138,7 +140,7 @@ namespace Siger.ApiACC.Controllers
{
section
=
line
,
projectId
=
PID
,
status
=
1
,
status
=
1
,
updatetime
=
DateTime
.
Now
,
mode
=
mode
});
...
...
@@ -149,7 +151,7 @@ namespace Siger.ApiACC.Controllers
exitObj
.
mode
=
mode
;
_automationLineMode
.
Update
(
exitObj
);
}
if
(
_unitOfWork
.
Commit
()
>
0
)
{
if
(
mode
==
1
)
...
...
@@ -159,7 +161,7 @@ namespace Siger.ApiACC.Controllers
var
tasklist
=
_automationTaskList
.
GetList
(
f
=>
f
.
projectId
==
PID
&&
f
.
status
<
(
int
)
TaskResultStatus
.
Complated
);
if
(!
tasklist
.
Any
())
{
Logger
.
WriteLineInfo
(
$"
LineMode Mode=1 触发自动任务检查
"
);
Logger
.
WriteLineInfo
(
$"
自动化业务流转--LineMode Mode=1 触发自动任务检查 line:
{
line
}
mode:
{
mode
}
"
);
AutoProcess
(
line
);
}
}
...
...
@@ -199,10 +201,10 @@ namespace Siger.ApiACC.Controllers
/// </summary>
/// <returns></returns>
[
HttpPost
]
public
IActionResult
TaskResult
([
FromBody
]
RequestAutomationTaskResult
request
)
public
IActionResult
TaskResult
([
FromBody
]
RequestAutomationTaskResult
request
)
{
//1.检查Tasklist
var
taskObj
=
_automationTaskList
.
Get
(
f
=>
f
.
no
==
request
.
guid
);
var
taskObj
=
_automationTaskList
.
Get
(
f
=>
f
.
no
==
request
.
guid
);
if
(
taskObj
==
null
)
{
throw
new
BadRequestException
(
CommonEnum
.
RecordNotFound
);
...
...
@@ -228,23 +230,23 @@ namespace Siger.ApiACC.Controllers
var
section
=
_sigerProjectLevelSection
.
Get
(
f
=>
f
.
id
==
taskObj
.
sectionid
);
if
(
section
!=
null
)
{
Logger
.
WriteLineInfo
(
$"
设备
{
section
.
title
}
任务编号:
{
taskObj
.
no
}
状态:
{
request
.
status
}
"
);
Logger
.
WriteLineInfo
(
$"
自动化业务流转--设备
{
section
.
title
}
任务编号:
{
taskObj
.
no
}
req状态:
{
request
.
status
}
reqGuid:
{
request
.
guid
}
"
);
AutoProcess
(
section
.
parentid
,
taskObj
);
}
return
new
ObjectResult
(
CommonEnum
.
Succefull
);
}
void
PlCfeeback
(
siger_automation_task_list
taskObj
,
int
status
)
void
PlCfeeback
(
siger_automation_task_list
taskObj
,
int
status
)
{
//2.更新状态
taskObj
.
status
=
status
;
taskObj
.
completetime
=
DateTime
.
Now
;
var
monitor
=
_automationFixtureMonitor
.
Get
(
f
=>
f
.
section
==
taskObj
.
sectionid
);
var
sectionProperty
=
_automationSectionProperty
.
Get
(
f
=>
f
.
sectionid
==
taskObj
.
sectionid
);
if
(
sectionProperty
==
null
)
if
(
sectionProperty
==
null
)
{
Logger
.
WriteLineInfo
(
$"PlCfeeback 设备属性为维护"
);
throw
new
BadRequestException
(
AccEnum
.
SectionPropertyNull
);
...
...
@@ -273,19 +275,19 @@ namespace Siger.ApiACC.Controllers
location
.
fixturetools
=
taskObj
.
fixtureguid
;
location
.
fixturename
=
taskObj
.
fixturename
;
location
.
ordernumber
=
taskObj
.
ordercode
;
location
.
productcode
=
download
?
""
:
taskObj
.
productcode
;
location
.
productid
=
download
?
0
:
taskObj
.
productid
;
location
.
routeid
=
download
?
0
:
taskObj
.
route
;
location
.
route
=
download
?
""
:
taskObj
.
route
.
ToString
();
location
.
sn
=
download
?
""
:
taskObj
.
sn
;
location
.
status
=(
int
)
LocationStatus
.
In
;
location
.
productcode
=
download
?
""
:
taskObj
.
productcode
;
location
.
productid
=
download
?
0
:
taskObj
.
productid
;
location
.
routeid
=
download
?
0
:
taskObj
.
route
;
location
.
route
=
download
?
""
:
taskObj
.
route
.
ToString
();
location
.
sn
=
download
?
""
:
taskObj
.
sn
;
location
.
status
=
(
int
)
LocationStatus
.
In
;
_automationLocation
.
Update
(
location
);
sectionProperty
.
upload
=
0
;
sectionProperty
.
down
=
0
;
_automationSectionProperty
.
Update
(
sectionProperty
);
}
//从立库储位拿SN 工件到上料位
if
(
taskObj
.
action
==
TaskAction
.
Step_LK_SXLW
)
...
...
@@ -302,7 +304,7 @@ namespace Siger.ApiACC.Controllers
}
if
(
taskObj
.
action
==
TaskAction
.
Step_LK_CJT
)
if
(
taskObj
.
action
==
TaskAction
.
Step_LK_CJT
)
{
}
...
...
@@ -336,7 +338,7 @@ namespace Siger.ApiACC.Controllers
//加工中心做完 下一站清洗机
var
cleanMachine
=
_automationSectionProperty
.
Get
(
f
=>
f
.
propertytype
==
4
);
if
(
cleanMachine
!=
null
)
if
(
cleanMachine
!=
null
)
{
taskObj
.
extend1
=
cleanMachine
.
sectionid
.
ToString
();
}
...
...
@@ -351,7 +353,7 @@ namespace Siger.ApiACC.Controllers
location
.
status
=
(
int
)
LocationStatus
.
Out
;
_automationLocation
.
Update
(
location
);
}
if
(
taskObj
.
action
==
TaskAction
.
Step_CJT_SXLW
)
if
(
taskObj
.
action
==
TaskAction
.
Step_CJT_SXLW
)
{
}
...
...
@@ -364,11 +366,11 @@ namespace Siger.ApiACC.Controllers
{
var
currenRute
=
_productRoute
.
Get
(
f
=>
f
.
id
==
taskObj
.
route
);
if
(
currenRute
==
null
)
if
(
currenRute
==
null
)
{
throw
new
BadRequestException
(
AccEnum
.
ProductRouteMissing
);
}
var
nextRoute
=
_productRoute
.
GetList
(
f
=>
f
.
productId
==
taskObj
.
productid
&&
f
.
serialNumber
>
currenRute
.
serialNumber
&&
f
.
status
==
(
int
)
RowState
.
Valid
,
"serialNumber"
,
false
).
FirstOrDefault
();
var
nextRoute
=
_productRoute
.
GetList
(
f
=>
f
.
productId
==
taskObj
.
productid
&&
f
.
serialNumber
>
currenRute
.
serialNumber
&&
f
.
status
==
(
int
)
RowState
.
Valid
,
"serialNumber"
,
false
).
FirstOrDefault
();
var
route
=
0
;
if
(
nextRoute
!=
null
)
...
...
@@ -450,15 +452,15 @@ namespace Siger.ApiACC.Controllers
/// </summary>
/// <param name="line"></param>
/// <param name="tasklist"></param>
void
AutoProcess
(
int
line
,
siger_automation_task_list
tasklist
=
null
)
void
AutoProcess
(
int
line
,
siger_automation_task_list
tasklist
=
null
)
{
var
lineMode
=
_automationLineMode
.
Get
(
f
=>
f
.
projectId
==
PID
&&
f
.
section
==
line
);
if
(
lineMode
==
null
)
if
(
lineMode
==
null
)
{
Logger
.
WriteLineInfo
(
$"AutoProcess 产线模式未找到"
);
throw
new
BadRequestException
(
AccEnum
.
LineModeNotfound
);
}
if
(
lineMode
.
mode
==
0
)
if
(
lineMode
.
mode
==
0
)
{
Logger
.
WriteLineInfo
(
$"AutoProcess 手动模式 不能创建自动任务"
);
//手动模式时 退出
...
...
@@ -478,7 +480,7 @@ namespace Siger.ApiACC.Controllers
Logger
.
WriteLineInfo
(
$"AutoProcess 设备属性未配置"
);
return
;
}
var
cncStations
=
sectionPropertys
.
Where
(
s
=>
s
.
propertytype
==
2
).
Select
(
s
=>
s
.
sectionid
).
ToList
();
var
cncStations
=
sectionPropertys
.
Where
(
s
=>
s
.
propertytype
==
2
).
Select
(
s
=>
s
.
sectionid
).
ToList
();
// 获取可用 设备状态列表 排除上料工位
var
machineStatusList
=
_automationMachineStatus
.
GetList
(
f
=>
f
.
projectId
==
PID
&&
cncStations
.
Contains
(
f
.
section
)
&&
f
.
enable
==
1
);
if
(!
machineStatusList
.
Any
())
...
...
@@ -486,15 +488,15 @@ namespace Siger.ApiACC.Controllers
Logger
.
WriteLineInfo
(
$"AutoProcess 无可用状态的设备"
);
return
;
}
var
cleanProperty
=
sectionPropertys
.
FirstOrDefault
(
f
=>
f
.
propertytype
==
4
);
if
(
cleanProperty
==
null
)
var
cleanProperty
=
sectionPropertys
.
FirstOrDefault
(
f
=>
f
.
propertytype
==
4
);
if
(
cleanProperty
==
null
)
{
Logger
.
WriteLineInfo
(
$"AutoProcess 设备属性清洗机未配置"
);
return
;
}
var
cleanMachine
=
_automationMachineStatus
.
Get
(
f
=>
f
.
section
==
cleanProperty
.
sectionid
);
if
(
cleanMachine
==
null
)
if
(
cleanMachine
==
null
)
{
Logger
.
WriteLineInfo
(
$"AutoProcess 清洗机没找到"
);
}
...
...
@@ -505,25 +507,26 @@ namespace Siger.ApiACC.Controllers
{
Logger
.
WriteLineError
(
$"AutoProcess 有清洗机
{
cleanMachine
.
section
}
完成,创建清洗机Task"
);
//取最近完成的 Task
var
lastTask
=
_automationTaskList
.
GetList
(
f
=>
f
.
extend1
==
cleanMachine
.
section
.
ToString
()
&&
f
.
status
==
(
int
)
Automation
.
TaskResultStatus
.
Complated
,
"id"
,
true
).
FirstOrDefault
();
var
lastTask
=
_automationTaskList
.
GetList
(
f
=>
f
.
extend1
==
cleanMachine
.
section
.
ToString
()
&&
f
.
status
==
(
int
)
Automation
.
TaskResultStatus
.
Complated
,
"id"
,
true
).
FirstOrDefault
();
if
(
lastTask
!=
null
)
{
lastTask
.
extend1
=
string
.
Empty
;
_automationTaskList
.
Update
(
lastTask
)
;
_automationTaskList
.
Update
(
lastTask
);
Logger
.
WriteLineInfo
(
$"自动化业务流转--AutoProcess section
{
cleanMachine
.
section
}
task:
{
TaskAction
.
Step_QXJ_LK
.
ToStr
()}
sn
{
lastTask
.
sn
}
"
);
CreateTask
(
cleanMachine
.
section
,
TaskActionType
.
Unload
,
TaskAction
.
Step_QXJ_LK
,
lastTask
.
fixtureguid
,
lastTask
.
ordercode
,
lastTask
.
sn
,
"无程序"
,
lastTask
.
productid
,
lastTask
.
productcode
,
lastTask
.
locationid
,
lastTask
.
route
);
return
;
//完成当前任务 退出
}
}
}
//优先级2 :其他设备待上料 (立库->加工中心)
var
freeMachine
=
machineStatusList
.
Where
(
f
=>
f
.
status
==
(
int
)
Automation
.
MachineStatus
.
Waiting
);
var
freeMachine
=
machineStatusList
.
Where
(
f
=>
f
.
status
==
(
int
)
Automation
.
MachineStatus
.
Waiting
);
if
(
freeMachine
!=
null
)
{
Logger
.
WriteLineError
(
$"AutoProcess 普通空闲,创建普通设备上料Task"
);
var
location
=
SelectLocation
(
freeMachine
.
Select
(
s
=>
s
.
machineid
).
ToList
());
var
location
=
SelectLocation
(
freeMachine
.
Select
(
s
=>
s
.
machineid
).
ToList
());
if
(
location
!=
null
)
{
Logger
.
WriteLineInfo
(
$"自动化业务流转--AutoProcess section
{
location
.
section
}
task:
{
TaskAction
.
Step_LK_JGZX
.
ToStr
()}
sn
{
location
.
sn
}
"
);
CreateTask
(
location
.
section
,
TaskActionType
.
Load
,
TaskAction
.
Step_LK_JGZX
,
location
.
fixture
,
location
.
ordernumber
,
location
.
sn
,
location
.
pn
,
location
.
productId
,
location
.
productCode
,
location
.
location
,
location
.
route
);
}
...
...
@@ -539,16 +542,23 @@ namespace Siger.ApiACC.Controllers
if
(
tasklist
!=
null
)
{
Logger
.
WriteLineError
(
$"AutoProcess 清洗机空闲,TaskResult触发 "
);
Logger
.
WriteLineInfo
(
$"自动化业务流转--AutoProcess section
{
fullMachine
.
section
}
task:
{
TaskAction
.
Step_JGZX_QXJ
.
ToStr
()}
sn
{
tasklist
.
sn
}
"
);
//创建CNC 下料到清洗机
CreateTask
(
fullMachine
.
section
,
TaskActionType
.
Unload
,
TaskAction
.
Step_JGZX_QXJ
,
tasklist
.
fixtureguid
,
tasklist
.
ordercode
,
tasklist
.
sn
,
tasklist
.
programnumber
,
tasklist
.
productid
,
tasklist
.
productcode
,
tasklist
.
locationid
,
tasklist
.
route
);
return
;
//完成当前任务 退出
}
else
}
else
{
Logger
.
WriteLineError
(
$"AutoProcess 清洗机空闲,MachineStatus触发 "
);
var
last
Task
=
_automationTaskList
.
GetList
(
f
=>
f
.
sectionid
==
fullMachine
.
section
&&
f
.
status
==(
int
)
Automation
.
TaskResultStatus
.
Complated
,
"id"
,
true
).
FirstOrDefault
();
if
(
last
Task
!=
null
)
var
last
MonitorItem
=
_automationFixtureMonitor
.
GetList
(
p
=>
p
.
section
==
fullMachine
.
section
).
OrderByDescending
(
p
=>
p
.
id
).
FirstOrDefault
();
if
(
last
MonitorItem
!=
null
)
{
CreateTask
(
fullMachine
.
section
,
TaskActionType
.
Unload
,
TaskAction
.
Step_JGZX_QXJ
,
lastTask
.
fixtureguid
,
lastTask
.
ordercode
,
lastTask
.
sn
,
lastTask
.
programnumber
,
lastTask
.
productid
,
lastTask
.
productcode
,
lastTask
.
locationid
,
lastTask
.
route
);
var
lastTask
=
_automationTaskList
.
GetList
(
f
=>
f
.
sectionid
==
fullMachine
.
section
&&
f
.
sn
==
lastMonitorItem
.
sn
&&
f
.
status
==
(
int
)
Automation
.
TaskResultStatus
.
Complated
,
"id"
,
true
).
FirstOrDefault
();
if
(
lastTask
!=
null
)
{
Logger
.
WriteLineInfo
(
$"自动化业务流转--AutoProcess section
{
fullMachine
.
section
}
task:
{
TaskAction
.
Step_JGZX_QXJ
.
ToStr
()}
sn
{
tasklist
.
sn
}
"
);
CreateTask
(
fullMachine
.
section
,
TaskActionType
.
Unload
,
TaskAction
.
Step_JGZX_QXJ
,
lastTask
.
fixtureguid
,
lastTask
.
ordercode
,
lastTask
.
sn
,
lastTask
.
programnumber
,
lastTask
.
productid
,
lastTask
.
productcode
,
lastTask
.
locationid
,
lastTask
.
route
);
}
}
}
}
...
...
@@ -567,13 +577,13 @@ namespace Siger.ApiACC.Controllers
/// <param name="sn">工件</param>
/// <param name="productCode">产品CODE</param>
/// <param name="locationid">储位ID</param>
void
CreateTask
(
int
section
,
TaskActionType
actionType
,
TaskAction
taskAction
,
string
guid
,
string
orderno
,
string
sn
,
string
program
,
int
productId
,
string
productCode
,
int
locationid
,
int
route
)
void
CreateTask
(
int
section
,
TaskActionType
actionType
,
TaskAction
taskAction
,
string
guid
,
string
orderno
,
string
sn
,
string
program
,
int
productId
,
string
productCode
,
int
locationid
,
int
route
)
{
var
taskNo
=
_automationTaskList
.
CrateTaskNumber
(
Automation
.
TaskTrigerType
.
Auto
);
_automationTaskList
.
Insert
(
new
siger_automation_task_list
{
no
=
taskNo
,
no
=
taskNo
,
projectId
=
PID
,
sectionid
=
section
,
trigger
=
TaskTrigerType
.
Auto
,
...
...
@@ -586,15 +596,15 @@ namespace Siger.ApiACC.Controllers
send
=
0
,
operater
=
0
,
status
=
1
,
fixtureguid
=
guid
,
fixtureguid
=
guid
,
productid
=
productId
,
productcode
=
productCode
,
programnumber
=
program
,
locationid
=
locationid
,
ordercode
=
orderno
,
sn
=
sn
,
remark
=
EnumHelper
.
GetEnumDesc
(
taskAction
),
route
=
route
,
programnumber
=
program
,
locationid
=
locationid
,
ordercode
=
orderno
,
sn
=
sn
,
remark
=
EnumHelper
.
GetEnumDesc
(
taskAction
),
route
=
route
,
});
if
(
_unitOfWork
.
Commit
()
>
0
)
Logger
.
WriteLineInfo
(
$"CreateTask sectionId:
{
section
}
工站
{
EnumHelper
.
GetEnumDesc
(
taskAction
)}
完成"
);
...
...
@@ -607,12 +617,12 @@ namespace Siger.ApiACC.Controllers
ResponseAutomationLocationRouteInfo
SelectLocation
(
List
<
int
>
machines
)
{
// 当前空闲设备能加工的产品
var
beats
=
_productionBeatSet
.
GetList
(
f
=>
f
.
projectID
==
PID
&&
machines
.
Contains
(
f
.
machineID
)
&&
f
.
status
==
(
int
)
RowState
.
Valid
).
ToList
();
var
beats
=
_productionBeatSet
.
GetList
(
f
=>
f
.
projectID
==
PID
&&
machines
.
Contains
(
f
.
machineID
)
&&
f
.
status
==
(
int
)
RowState
.
Valid
).
ToList
();
var
TempList
=
new
List
<
ResponseAutoRouteInfo
>();
foreach
(
var
b
in
beats
)
{
Logger
.
WriteLineError
(
$"SelectLocation 设备
{
b
.
machineID
}
标准节拍
{
b
.
route_number
}{
b
.
route_name
}
"
);
var
autoLocationIds
=
_automationLocation
.
GetList
(
f
=>
f
.
status
==(
int
)
RowState
.
Valid
&&
f
.
projectId
==
b
.
projectID
&&
f
.
routeid
==
b
.
route_number
.
ToInt
()
&&
f
.
productid
==
b
.
product_name
.
ToInt
());
var
autoLocationIds
=
_automationLocation
.
GetList
(
f
=>
f
.
status
==
(
int
)
RowState
.
Valid
&&
f
.
projectId
==
b
.
projectID
&&
f
.
routeid
==
b
.
route_number
.
ToInt
()
&&
f
.
productid
==
b
.
product_name
.
ToInt
());
if
(!
autoLocationIds
.
Any
())
{
Logger
.
WriteLineError
(
$"SelectLocation 设备
{
b
.
machineID
}
routeid:
{
b
.
route_number
}
-
{
b
.
route_name
}
productId:
{
b
.
product_name
}
没有匹配到当前储位"
);
...
...
@@ -631,7 +641,7 @@ namespace Siger.ApiACC.Controllers
Logger
.
WriteLineError
(
$"SelectLocation 设备
{
b
.
machineID
}
routeid:
{
b
.
route_number
}
-
{
b
.
route_name
}
productId:
{
b
.
product_name
}
储位
{
autoLocation
.
locationid
}
工件Sn:
{
autoLocation
.
sn
}
不在储位上"
);
continue
;
}
if
(
autoLocation
.
routeid
==
0
)
if
(
autoLocation
.
routeid
==
0
)
{
Logger
.
WriteLineError
(
$"SelectLocation 有效订单号
{
autoLocation
.
ordernumber
}
工序
{
b
.
route_number
}
-
{
b
.
route_name
}
完成"
);
continue
;
...
...
@@ -645,7 +655,7 @@ namespace Siger.ApiACC.Controllers
Machine
=
b
.
machineID
,
Pn
=
b
.
process_number
,
ProductId
=
b
.
product_name
.
ToInt
(),
ProductCode
=
autoLocation
.
productcode
,
ProductCode
=
autoLocation
.
productcode
,
ProductName
=
b
.
product_name_text
,
Location
=
autoLocation
.
locationid
,
Route
=
b
.
route_number
.
ToInt
(),
...
...
@@ -666,7 +676,7 @@ namespace Siger.ApiACC.Controllers
var
ordernos
=
TempList
.
Select
(
f
=>
f
.
OrderNo
).
ToList
();
// 取产品交期最近的订单
var
planOrder
=
_automationFixtureToolsProduct
.
GetDeliveryOrder
(
ordernos
,
PID
);
...
...
@@ -676,23 +686,23 @@ namespace Siger.ApiACC.Controllers
return
null
;
}
var
order
=
planOrder
.
FirstOrDefault
();
var
autoRouteInfo
=
TempList
.
Where
(
f
=>
f
.
OrderNo
==
order
.
ordernumber
).
OrderBy
(
d
=>
d
.
Sn
);
var
autoRouteInfo
=
TempList
.
Where
(
f
=>
f
.
OrderNo
==
order
.
ordernumber
).
OrderBy
(
d
=>
d
.
Sn
);
var
result
=
autoRouteInfo
.
FirstOrDefault
();
return
new
ResponseAutomationLocationRouteInfo
{
section
=
result
.
Section
,
machine
=
result
.
Machine
,
section
=
result
.
Section
,
machine
=
result
.
Machine
,
fixture
=
result
.
FixtureGuid
,
fixturename
=
result
.
FixtureName
,
ordernumber
=
result
.
OrderNo
,
location
=
result
.
Location
,
productId
=
result
.
ProductId
,
ordernumber
=
result
.
OrderNo
,
location
=
result
.
Location
,
productId
=
result
.
ProductId
,
productCode
=
result
.
ProductCode
,
productName
=
result
.
ProductName
,
sn
=
result
.
Sn
,
pn
=
result
.
Pn
,
route
=
result
.
Route
,
lid
=
result
.
LId
sn
=
result
.
Sn
,
pn
=
result
.
Pn
,
route
=
result
.
Route
,
lid
=
result
.
LId
};
}
...
...
Server/Infrastructure/Repositories/Siger.Middlelayer.AccRepository/Repositories/AutomationTaskListRepository.cs
View file @
7f13f955
using
System
;
using
System.Collections.Concurrent
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Linq.Expressions
;
...
...
@@ -25,18 +26,18 @@ namespace Siger.Middlelayer.AccRepository.Repositories
_context
=
context
;
}
public
bool
CanTask
(
int
projectId
,
int
section
)
public
bool
CanTask
(
int
projectId
,
int
section
)
{
//已经下发,并且任务完成
var
taskObjs
=
_context
.
siger_automation_task_list
.
Where
(
f
=>
f
.
projectId
==
projectId
&&
f
.
send
==
0
);
var
taskObjs
=
_context
.
siger_automation_task_list
.
Where
(
f
=>
f
.
projectId
==
projectId
&&
f
.
send
==
0
);
if
(
taskObjs
.
Any
())
{
return
false
;
}
else
{
var
unDolist
=
_context
.
siger_automation_task_list
.
Where
(
f
=>
f
.
send
==
1
&&
f
.
status
!=
(
int
)
TaskResultStatus
.
Complated
).
Count
();
if
(
unDolist
==
0
)
var
unDolist
=
_context
.
siger_automation_task_list
.
Where
(
f
=>
f
.
send
==
1
&&
f
.
status
!=
(
int
)
TaskResultStatus
.
Complated
).
Count
();
if
(
unDolist
==
0
)
return
true
;
else
return
false
;
...
...
@@ -51,18 +52,59 @@ namespace Siger.Middlelayer.AccRepository.Repositories
/// <returns></returns>
public
string
CrateTaskNumber
(
TaskTrigerType
trigerType
)
{
var
date
=
DateTime
.
Now
;
var
serinum
=
date
.
DayOfYear
+
date
.
Month
+
date
.
Day
+
date
.
Hour
+
date
.
Minute
+
date
.
Second
+
date
.
Millisecond
;
var
dayofyear
=
GetDayOfYear
(
date
);
if
(
trigerType
==
TaskTrigerType
.
Auto
)
//var date = DateTime.Now;
//var serinum = date.DayOfYear+date.Month +date.Day+ date.Hour + date.Minute + date.Second + date.Millisecond;
//var dayofyear = GetDayOfYear(date);
//if (trigerType== TaskTrigerType.Auto)
//{
// return $"A{date.Year}{dayofyear}{serinum}";
//}
//else
//{
// return $"M{date.Year}{dayofyear}{serinum}";
//}
if
(
trigerType
==
TaskTrigerType
.
Auto
)
{
return
$"A
{
GetId
()}
"
;
}
else
{
return
$"M
{
GetId
()}
"
;
}
}
public
static
object
objLock
=
new
object
();
private
static
int
defaultStepLength
=
100
;
private
static
DateTime
dtStart
=
new
DateTime
(
2020
,
1
,
1
);
private
static
ConcurrentQueue
<
string
>
stackIds
=
new
ConcurrentQueue
<
string
>();
private
static
string
GetId
()
{
if
(
stackIds
.
Count
<=
0
)
{
lock
(
objLock
)
{
if
(
stackIds
.
Count
<=
0
)
{
var
dtTs
=
(
DateTime
.
Now
-
dtStart
).
Ticks
;
for
(
int
i
=
0
;
i
<
defaultStepLength
;
i
++)
{
//todo://增加机器信息;单机暂且放弃
stackIds
.
Enqueue
((
dtTs
+
i
).
ToString
());
}
}
}
}
if
(
stackIds
.
TryDequeue
(
out
string
actIds
))
{
return
$"A
{
date
.
Year
}{
dayofyear
}{
serinum
}
"
;
return
actIds
;
}
else
{
return
$"M
{
date
.
Year
}{
dayofyear
}{
serinum
}
"
;
throw
new
Exception
(
"Id生成器报错,队列异常;"
)
;
}
}
/// <summary>
/// 工件长度10 PLC 限制
/// </summary>
...
...
@@ -70,19 +112,22 @@ namespace Siger.Middlelayer.AccRepository.Repositories
/// <returns></returns>
public
string
CreateRandonSn
(
string
productCode
)
{
var
date
=
DateTime
.
Now
;
var
serinum
=
date
.
DayOfYear
+
date
.
Month
+
date
.
Day
+
date
.
Hour
+
date
.
Minute
+
date
.
Second
+
date
.
Millisecond
;
var
dayofyear
=
GetDayOfYear
(
date
);
var
lable
=
$"
{
date
.
Year
}{
dayofyear
}{
serinum
}
"
;
//var date = DateTime.Now;
//var seriNum = $"{date.ToString("HHmmssfff")}";
//var serinum = date.DayOfYear + date.Month + date.Day + date.Hour + date.Minute + date.Second + date.Millisecond;
//var dayofyear = GetDayOfYear(date);
//var lable = $"{date.Year}{dayofyear}{serinum}";
var
lable
=
$"
{
Math
.
Abs
(
productCode
.
GetHashCode
())}{
GetId
()}
"
;
return
lable
;
}
private
string
GetDayOfYear
(
DateTime
dt
)
{
var
lable
=
dt
.
DayOfYear
.
ToString
();
var
result
=
string
.
Empty
;
for
(
int
i
=
0
;
i
<
3
-
lable
.
Length
;
i
++)
for
(
int
i
=
0
;
i
<
3
-
lable
.
Length
;
i
++)
{
result
+=
"0"
;
result
+=
"0"
;
}
return
$"
{
result
}{
lable
}
"
;
...
...
@@ -91,7 +136,7 @@ namespace Siger.Middlelayer.AccRepository.Repositories
public
IPagedCollectionResult
<
ResponseAutomationTasklist
>
GetTasklistPagedList
(
List
<
int
>
sections
,
int
taskType
,
string
productCode
,
string
TaskNo
,
string
sn
,
int
status
,
int
actionType
,
string
tirbeigin
,
string
triend
,
string
compbegin
,
string
compend
,
int
projectid
,
int
page
,
int
pagesize
,
string
toexcel
)
{
var
query
=
from
q
in
_context
.
siger_automation_task_list
var
query
=
from
q
in
_context
.
siger_automation_task_list
join
t
in
_context
.
siger_automation_fixture_tools
on
q
.
fixtureguid
equals
t
.
guid
join
r
in
_context
.
siger_project_product_route
on
q
.
route
equals
r
.
id
into
rtemp
from
r
in
rtemp
.
DefaultIfEmpty
()
...
...
@@ -100,39 +145,39 @@ namespace Siger.Middlelayer.AccRepository.Repositories
where
q
.
projectId
==
projectid
select
new
ResponseAutomationTasklist
{
id
=
q
.
id
,
taskno
=
q
.
no
,
sectionid
=
q
.
sectionid
,
section
=
$"
{
lv
.
title
}
-
{
s
.
title
}
"
,
trigger
=
EnumHelper
.
GetEnumDesc
(
q
.
trigger
),
triggervalue
=
q
.
triggertime
,
triggerTime
=
q
.
triggertime
==
DateTime
.
MinValue
?
""
:
q
.
triggertime
.
ToString
(),
complatevalue
=
q
.
completetime
,
complatetime
=
q
.
completetime
==
DateTime
.
MinValue
?
""
:
q
.
completetime
.
ToString
(),
action
=
EnumHelper
.
GetEnumDesc
(
q
.
action
),
actionType
=
EnumHelper
.
GetEnumDesc
(
q
.
actiontype
),
fixtureCode
=
t
.
code
,
fixtureName
=
t
.
name
,
location
=
q
.
locationid
.
ToString
(),
sn
=
q
.
sn
,
ordernumber
=
q
.
ordercode
,
productCode
=
q
.
productcode
,
program
=
q
.
programnumber
,
route
=
r
!=
null
?
$"
{
r
.
serialNumber
}
-
{
r
.
name
}
"
:
""
,
send
=
q
.
send
,
tasktype
=
EnumHelper
.
GetEnumDesc
(
q
.
tasktype
),
tasktypeid
=
Convert
.
ToInt32
(
q
.
tasktype
),
status
=
q
.
status
,
actionTypeid
=
Convert
.
ToInt32
(
q
.
actiontype
)
id
=
q
.
id
,
taskno
=
q
.
no
,
sectionid
=
q
.
sectionid
,
section
=
$"
{
lv
.
title
}
-
{
s
.
title
}
"
,
trigger
=
EnumHelper
.
GetEnumDesc
(
q
.
trigger
),
triggervalue
=
q
.
triggertime
,
triggerTime
=
q
.
triggertime
==
DateTime
.
MinValue
?
""
:
q
.
triggertime
.
ToString
(),
complatevalue
=
q
.
completetime
,
complatetime
=
q
.
completetime
==
DateTime
.
MinValue
?
""
:
q
.
completetime
.
ToString
(),
action
=
EnumHelper
.
GetEnumDesc
(
q
.
action
),
actionType
=
EnumHelper
.
GetEnumDesc
(
q
.
actiontype
),
fixtureCode
=
t
.
code
,
fixtureName
=
t
.
name
,
location
=
q
.
locationid
.
ToString
(),
sn
=
q
.
sn
,
ordernumber
=
q
.
ordercode
,
productCode
=
q
.
productcode
,
program
=
q
.
programnumber
,
route
=
r
!=
null
?
$"
{
r
.
serialNumber
}
-
{
r
.
name
}
"
:
""
,
send
=
q
.
send
,
tasktype
=
EnumHelper
.
GetEnumDesc
(
q
.
tasktype
),
tasktypeid
=
Convert
.
ToInt32
(
q
.
tasktype
),
status
=
q
.
status
,
actionTypeid
=
Convert
.
ToInt32
(
q
.
actiontype
)
};
Expression
<
Func
<
ResponseAutomationTasklist
,
bool
>>
sectonsExpression
=
f
=>
true
;
if
(
sections
.
Any
())
{
sectonsExpression
=
q
=>
sections
.
Contains
(
q
.
sectionid
);
sectonsExpression
=
q
=>
sections
.
Contains
(
q
.
sectionid
);
}
Expression
<
Func
<
ResponseAutomationTasklist
,
bool
>>
taskTypeExpression
=
f
=>
true
;
if
(
taskType
!=
0
)
if
(
taskType
!=
0
)
{
taskTypeExpression
=
q
=>
q
.
tasktypeid
==
taskType
;
}
...
...
@@ -152,15 +197,15 @@ namespace Siger.Middlelayer.AccRepository.Repositories
snExpression
=
q
=>
q
.
sn
.
Contains
(
sn
);
}
Expression
<
Func
<
ResponseAutomationTasklist
,
bool
>>
actionTypeExpression
=
f
=>
true
;
if
(
actionType
!=
0
)
if
(
actionType
!=
0
)
{
actionTypeExpression
=
q
=>
q
.
actionTypeid
==
actionType
;
actionTypeExpression
=
q
=>
q
.
actionTypeid
==
actionType
;
}
Expression
<
Func
<
ResponseAutomationTasklist
,
bool
>>
triggerTimeTypeExpression
=
f
=>
true
;
if
(!
string
.
IsNullOrEmpty
(
triend
)
&&
!
string
.
IsNullOrEmpty
(
tirbeigin
))
{
triggerTimeTypeExpression
=
q
=>
q
.
triggervalue
>=
tirbeigin
.
ToDateTime
()
&&
q
.
triggervalue
<=
triend
.
ToDateTime
();
triggerTimeTypeExpression
=
q
=>
q
.
triggervalue
>=
tirbeigin
.
ToDateTime
()
&&
q
.
triggervalue
<=
triend
.
ToDateTime
();
}
Expression
<
Func
<
ResponseAutomationTasklist
,
bool
>>
comptimeExpression
=
f
=>
true
;
if
(!
string
.
IsNullOrEmpty
(
compbegin
)
&&
!
string
.
IsNullOrEmpty
(
compend
))
...
...
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