Commit 7f13f955 by chenzhengpeng

code repo

parent 91115f3c
...@@ -43,7 +43,7 @@ namespace Siger.ApiACC.Controllers ...@@ -43,7 +43,7 @@ namespace Siger.ApiACC.Controllers
private readonly IProductRouteRepository _productRoute; private readonly IProductRouteRepository _productRoute;
private readonly IAutomationSectionPropertyRepository _automationSectionProperty; 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, ISigerProjectMachineAttributionRepository sigerProjectMachineAttribution, IAutomationFixtureMonitor automationFixtureMonitor, IAutomationLocationRepository automationLocation, IProductionBeatSetRepository productionBeatSet, IAutomationFixtureToolsProductRepository automationFixtureToolsProduct,
IAutomationFixtureToolsRepository automationFixtureTools, IProductRouteRepository productRoute, IAutomationSectionPropertyRepository automationSectionProperty) IAutomationFixtureToolsRepository automationFixtureTools, IProductRouteRepository productRoute, IAutomationSectionPropertyRepository automationSectionProperty)
{ {
...@@ -69,25 +69,27 @@ namespace Siger.ApiACC.Controllers ...@@ -69,25 +69,27 @@ namespace Siger.ApiACC.Controllers
/// <param name="request"></param> /// <param name="request"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost] [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); var machineAttr = _sigerProjectMachineAttribution.Get(f => f.projectid == PID && f.machine == request.machineid && f.status == (int)RowState.Valid);
if (machineAttr==null) if (machineAttr == null)
{ {
throw new BadRequestException(ConfigEnum.MachineAttributionNotFound); throw new BadRequestException(ConfigEnum.MachineAttributionNotFound);
} }
var exitsObj = _automationMachineStatus.Get(f => f.machineid == request.machineid ); var exitsObj = _automationMachineStatus.Get(f => f.machineid == request.machineid);
if (exitsObj==null) if (exitsObj == null)
{ {
_automationMachineStatus.Insert(new siger_automation_machine_status{ _automationMachineStatus.Insert(new siger_automation_machine_status
section=machineAttr.station, {
machineid=request.machineid, section = machineAttr.station,
projectId=PID, machineid = request.machineid,
updatetime=DateTime.Now, projectId = PID,
enable=request.enable==1?1:0, updatetime = DateTime.Now,
status=request.status enable = request.enable == 1 ? 1 : 0,
status = request.status
}); });
}else }
else
{ {
exitsObj.section = machineAttr.station; exitsObj.section = machineAttr.station;
exitsObj.enable = request.enable; exitsObj.enable = request.enable;
...@@ -108,7 +110,7 @@ namespace Siger.ApiACC.Controllers ...@@ -108,7 +110,7 @@ namespace Siger.ApiACC.Controllers
var section = _sigerProjectLevelSection.Get(f => f.id == machineAttr.station); var section = _sigerProjectLevelSection.Get(f => f.id == machineAttr.station);
if (section != null) if (section != null)
{ {
Logger.WriteLineInfo($"MachineStatus 设备 {section.title}状态 触发自动任务检查"); Logger.WriteLineInfo($"自动化业务流转--MachineStatus 设备 {section.title}状态 触发自动任务检查 section parentid:{section.parentid}");
AutoProcess(section.parentid); AutoProcess(section.parentid);
} }
} }
...@@ -159,7 +161,7 @@ namespace Siger.ApiACC.Controllers ...@@ -159,7 +161,7 @@ namespace Siger.ApiACC.Controllers
var tasklist = _automationTaskList.GetList(f => f.projectId == PID && f.status < (int)TaskResultStatus.Complated); var tasklist = _automationTaskList.GetList(f => f.projectId == PID && f.status < (int)TaskResultStatus.Complated);
if (!tasklist.Any()) if (!tasklist.Any())
{ {
Logger.WriteLineInfo($"LineMode Mode=1 触发自动任务检查"); Logger.WriteLineInfo($"自动化业务流转--LineMode Mode=1 触发自动任务检查 line:{line} mode:{mode}");
AutoProcess(line); AutoProcess(line);
} }
} }
...@@ -199,10 +201,10 @@ namespace Siger.ApiACC.Controllers ...@@ -199,10 +201,10 @@ namespace Siger.ApiACC.Controllers
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
[HttpPost] [HttpPost]
public IActionResult TaskResult([FromBody]RequestAutomationTaskResult request) public IActionResult TaskResult([FromBody] RequestAutomationTaskResult request)
{ {
//1.检查Tasklist //1.检查Tasklist
var taskObj = _automationTaskList.Get(f => f.no== request.guid); var taskObj = _automationTaskList.Get(f => f.no == request.guid);
if (taskObj == null) if (taskObj == null)
{ {
throw new BadRequestException(CommonEnum.RecordNotFound); throw new BadRequestException(CommonEnum.RecordNotFound);
...@@ -228,14 +230,14 @@ namespace Siger.ApiACC.Controllers ...@@ -228,14 +230,14 @@ namespace Siger.ApiACC.Controllers
var section = _sigerProjectLevelSection.Get(f => f.id == taskObj.sectionid); var section = _sigerProjectLevelSection.Get(f => f.id == taskObj.sectionid);
if (section != null) 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); AutoProcess(section.parentid, taskObj);
} }
return new ObjectResult(CommonEnum.Succefull); return new ObjectResult(CommonEnum.Succefull);
} }
void PlCfeeback(siger_automation_task_list taskObj,int status ) void PlCfeeback(siger_automation_task_list taskObj, int status)
{ {
//2.更新状态 //2.更新状态
taskObj.status = status; taskObj.status = status;
...@@ -244,7 +246,7 @@ namespace Siger.ApiACC.Controllers ...@@ -244,7 +246,7 @@ namespace Siger.ApiACC.Controllers
var monitor = _automationFixtureMonitor.Get(f => f.section == taskObj.sectionid); var monitor = _automationFixtureMonitor.Get(f => f.section == taskObj.sectionid);
var sectionProperty = _automationSectionProperty.Get(f => f.sectionid == taskObj.sectionid); var sectionProperty = _automationSectionProperty.Get(f => f.sectionid == taskObj.sectionid);
if(sectionProperty==null) if (sectionProperty == null)
{ {
Logger.WriteLineInfo($"PlCfeeback 设备属性为维护"); Logger.WriteLineInfo($"PlCfeeback 设备属性为维护");
throw new BadRequestException(AccEnum.SectionPropertyNull); throw new BadRequestException(AccEnum.SectionPropertyNull);
...@@ -273,12 +275,12 @@ namespace Siger.ApiACC.Controllers ...@@ -273,12 +275,12 @@ namespace Siger.ApiACC.Controllers
location.fixturetools = taskObj.fixtureguid; location.fixturetools = taskObj.fixtureguid;
location.fixturename = taskObj.fixturename; location.fixturename = taskObj.fixturename;
location.ordernumber = taskObj.ordercode; location.ordernumber = taskObj.ordercode;
location.productcode = download?"": taskObj.productcode; location.productcode = download ? "" : taskObj.productcode;
location.productid = download?0: taskObj.productid; location.productid = download ? 0 : taskObj.productid;
location.routeid = download?0: taskObj.route; location.routeid = download ? 0 : taskObj.route;
location.route = download?"": taskObj.route.ToString(); location.route = download ? "" : taskObj.route.ToString();
location.sn = download?"": taskObj.sn; location.sn = download ? "" : taskObj.sn;
location.status =(int)LocationStatus.In; location.status = (int)LocationStatus.In;
_automationLocation.Update(location); _automationLocation.Update(location);
sectionProperty.upload = 0; sectionProperty.upload = 0;
...@@ -302,7 +304,7 @@ namespace Siger.ApiACC.Controllers ...@@ -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 ...@@ -336,7 +338,7 @@ namespace Siger.ApiACC.Controllers
//加工中心做完 下一站清洗机 //加工中心做完 下一站清洗机
var cleanMachine = _automationSectionProperty.Get(f => f.propertytype == 4); var cleanMachine = _automationSectionProperty.Get(f => f.propertytype == 4);
if (cleanMachine!=null) if (cleanMachine != null)
{ {
taskObj.extend1 = cleanMachine.sectionid.ToString(); taskObj.extend1 = cleanMachine.sectionid.ToString();
} }
...@@ -351,7 +353,7 @@ namespace Siger.ApiACC.Controllers ...@@ -351,7 +353,7 @@ namespace Siger.ApiACC.Controllers
location.status = (int)LocationStatus.Out; location.status = (int)LocationStatus.Out;
_automationLocation.Update(location); _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 ...@@ -364,11 +366,11 @@ namespace Siger.ApiACC.Controllers
{ {
var currenRute = _productRoute.Get(f => f.id == taskObj.route); var currenRute = _productRoute.Get(f => f.id == taskObj.route);
if (currenRute==null) if (currenRute == null)
{ {
throw new BadRequestException(AccEnum.ProductRouteMissing); 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; var route = 0;
if (nextRoute != null) if (nextRoute != null)
...@@ -450,15 +452,15 @@ namespace Siger.ApiACC.Controllers ...@@ -450,15 +452,15 @@ namespace Siger.ApiACC.Controllers
/// </summary> /// </summary>
/// <param name="line"></param> /// <param name="line"></param>
/// <param name="tasklist"></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); var lineMode = _automationLineMode.Get(f => f.projectId == PID && f.section == line);
if (lineMode==null) if (lineMode == null)
{ {
Logger.WriteLineInfo($"AutoProcess 产线模式未找到"); Logger.WriteLineInfo($"AutoProcess 产线模式未找到");
throw new BadRequestException(AccEnum.LineModeNotfound); throw new BadRequestException(AccEnum.LineModeNotfound);
} }
if (lineMode.mode==0) if (lineMode.mode == 0)
{ {
Logger.WriteLineInfo($"AutoProcess 手动模式 不能创建自动任务"); Logger.WriteLineInfo($"AutoProcess 手动模式 不能创建自动任务");
//手动模式时 退出 //手动模式时 退出
...@@ -478,7 +480,7 @@ namespace Siger.ApiACC.Controllers ...@@ -478,7 +480,7 @@ namespace Siger.ApiACC.Controllers
Logger.WriteLineInfo($"AutoProcess 设备属性未配置"); Logger.WriteLineInfo($"AutoProcess 设备属性未配置");
return; 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); var machineStatusList = _automationMachineStatus.GetList(f => f.projectId == PID && cncStations.Contains(f.section) && f.enable == 1);
if (!machineStatusList.Any()) if (!machineStatusList.Any())
...@@ -487,14 +489,14 @@ namespace Siger.ApiACC.Controllers ...@@ -487,14 +489,14 @@ namespace Siger.ApiACC.Controllers
return; return;
} }
var cleanProperty = sectionPropertys.FirstOrDefault(f=>f.propertytype == 4); var cleanProperty = sectionPropertys.FirstOrDefault(f => f.propertytype == 4);
if (cleanProperty==null) if (cleanProperty == null)
{ {
Logger.WriteLineInfo($"AutoProcess 设备属性清洗机未配置"); Logger.WriteLineInfo($"AutoProcess 设备属性清洗机未配置");
return; return;
} }
var cleanMachine = _automationMachineStatus.Get(f => f.section == cleanProperty.sectionid); var cleanMachine = _automationMachineStatus.Get(f => f.section == cleanProperty.sectionid);
if (cleanMachine==null) if (cleanMachine == null)
{ {
Logger.WriteLineInfo($"AutoProcess 清洗机没找到"); Logger.WriteLineInfo($"AutoProcess 清洗机没找到");
} }
...@@ -505,25 +507,26 @@ namespace Siger.ApiACC.Controllers ...@@ -505,25 +507,26 @@ namespace Siger.ApiACC.Controllers
{ {
Logger.WriteLineError($"AutoProcess 有清洗机{ cleanMachine.section}完成,创建清洗机Task"); Logger.WriteLineError($"AutoProcess 有清洗机{ cleanMachine.section}完成,创建清洗机Task");
//取最近完成的 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) if (lastTask != null)
{ {
lastTask.extend1 = string.Empty; 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); CreateTask(cleanMachine.section, TaskActionType.Unload, TaskAction.Step_QXJ_LK, lastTask.fixtureguid, lastTask.ordercode, lastTask.sn, "无程序", lastTask.productid, lastTask.productcode, lastTask.locationid, lastTask.route);
return; //完成当前任务 退出 return; //完成当前任务 退出
} }
} }
} }
//优先级2 :其他设备待上料 (立库->加工中心) //优先级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) if (freeMachine != null)
{ {
Logger.WriteLineError($"AutoProcess 普通空闲,创建普通设备上料Task"); 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) 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); 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,21 +542,28 @@ namespace Siger.ApiACC.Controllers ...@@ -539,21 +542,28 @@ namespace Siger.ApiACC.Controllers
if (tasklist != null) if (tasklist != null)
{ {
Logger.WriteLineError($"AutoProcess 清洗机空闲,TaskResult触发 "); Logger.WriteLineError($"AutoProcess 清洗机空闲,TaskResult触发 ");
Logger.WriteLineInfo($"自动化业务流转--AutoProcess section{fullMachine.section} task:{TaskAction.Step_JGZX_QXJ.ToStr()} sn {tasklist.sn}");
//创建CNC 下料到清洗机 //创建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); 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; //完成当前任务 退出 return; //完成当前任务 退出
}else }
else
{ {
Logger.WriteLineError($"AutoProcess 清洗机空闲,MachineStatus触发 "); Logger.WriteLineError($"AutoProcess 清洗机空闲,MachineStatus触发 ");
var lastTask = _automationTaskList.GetList(f => f.sectionid == fullMachine.section && f.status==(int)Automation.TaskResultStatus.Complated, "id", true).FirstOrDefault(); var lastMonitorItem = _automationFixtureMonitor.GetList(p => p.section == fullMachine.section).OrderByDescending(p => p.id).FirstOrDefault();
if (lastTask!=null) if (lastMonitorItem != null)
{ {
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); 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);
} }
} }
} }
} }
} }
}
/// <summary> /// <summary>
...@@ -567,13 +577,13 @@ namespace Siger.ApiACC.Controllers ...@@ -567,13 +577,13 @@ namespace Siger.ApiACC.Controllers
/// <param name="sn">工件</param> /// <param name="sn">工件</param>
/// <param name="productCode">产品CODE</param> /// <param name="productCode">产品CODE</param>
/// <param name="locationid">储位ID</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); var taskNo = _automationTaskList.CrateTaskNumber(Automation.TaskTrigerType.Auto);
_automationTaskList.Insert(new siger_automation_task_list _automationTaskList.Insert(new siger_automation_task_list
{ {
no= taskNo, no = taskNo,
projectId = PID, projectId = PID,
sectionid = section, sectionid = section,
trigger = TaskTrigerType.Auto, trigger = TaskTrigerType.Auto,
...@@ -586,15 +596,15 @@ namespace Siger.ApiACC.Controllers ...@@ -586,15 +596,15 @@ namespace Siger.ApiACC.Controllers
send = 0, send = 0,
operater = 0, operater = 0,
status = 1, status = 1,
fixtureguid= guid, fixtureguid = guid,
productid = productId, productid = productId,
productcode = productCode, productcode = productCode,
programnumber=program, programnumber = program,
locationid= locationid, locationid = locationid,
ordercode= orderno, ordercode = orderno,
sn= sn, sn = sn,
remark= EnumHelper.GetEnumDesc(taskAction), remark = EnumHelper.GetEnumDesc(taskAction),
route=route, route = route,
}); });
if (_unitOfWork.Commit() > 0) if (_unitOfWork.Commit() > 0)
Logger.WriteLineInfo($"CreateTask sectionId:{section}工站 {EnumHelper.GetEnumDesc(taskAction)} 完成"); Logger.WriteLineInfo($"CreateTask sectionId:{section}工站 {EnumHelper.GetEnumDesc(taskAction)} 完成");
...@@ -607,12 +617,12 @@ namespace Siger.ApiACC.Controllers ...@@ -607,12 +617,12 @@ namespace Siger.ApiACC.Controllers
ResponseAutomationLocationRouteInfo SelectLocation(List<int> machines) 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>(); var TempList = new List<ResponseAutoRouteInfo>();
foreach (var b in beats) foreach (var b in beats)
{ {
Logger.WriteLineError($"SelectLocation 设备{b.machineID}标准节拍{b.route_number}{b.route_name}"); 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()) if (!autoLocationIds.Any())
{ {
Logger.WriteLineError($"SelectLocation 设备{b.machineID} routeid:{b.route_number}-{b.route_name}productId:{b.product_name} 没有匹配到当前储位"); Logger.WriteLineError($"SelectLocation 设备{b.machineID} routeid:{b.route_number}-{b.route_name}productId:{b.product_name} 没有匹配到当前储位");
...@@ -631,7 +641,7 @@ namespace Siger.ApiACC.Controllers ...@@ -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}不在储位上"); Logger.WriteLineError($"SelectLocation 设备{b.machineID} routeid:{b.route_number}-{b.route_name}productId:{b.product_name} 储位{autoLocation.locationid}工件Sn:{autoLocation.sn}不在储位上");
continue; continue;
} }
if(autoLocation.routeid==0) if (autoLocation.routeid == 0)
{ {
Logger.WriteLineError($"SelectLocation 有效订单号{autoLocation.ordernumber} 工序{b.route_number}-{b.route_name}完成"); Logger.WriteLineError($"SelectLocation 有效订单号{autoLocation.ordernumber} 工序{b.route_number}-{b.route_name}完成");
continue; continue;
...@@ -645,7 +655,7 @@ namespace Siger.ApiACC.Controllers ...@@ -645,7 +655,7 @@ namespace Siger.ApiACC.Controllers
Machine = b.machineID, Machine = b.machineID,
Pn = b.process_number, Pn = b.process_number,
ProductId = b.product_name.ToInt(), ProductId = b.product_name.ToInt(),
ProductCode=autoLocation.productcode, ProductCode = autoLocation.productcode,
ProductName = b.product_name_text, ProductName = b.product_name_text,
Location = autoLocation.locationid, Location = autoLocation.locationid,
Route = b.route_number.ToInt(), Route = b.route_number.ToInt(),
...@@ -676,23 +686,23 @@ namespace Siger.ApiACC.Controllers ...@@ -676,23 +686,23 @@ namespace Siger.ApiACC.Controllers
return null; return null;
} }
var order = planOrder.FirstOrDefault(); 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(); var result = autoRouteInfo.FirstOrDefault();
return new ResponseAutomationLocationRouteInfo return new ResponseAutomationLocationRouteInfo
{ {
section=result.Section, section = result.Section,
machine=result.Machine, machine = result.Machine,
fixture = result.FixtureGuid, fixture = result.FixtureGuid,
fixturename = result.FixtureName, fixturename = result.FixtureName,
ordernumber =result.OrderNo, ordernumber = result.OrderNo,
location=result.Location, location = result.Location,
productId=result.ProductId, productId = result.ProductId,
productCode = result.ProductCode, productCode = result.ProductCode,
productName = result.ProductName, productName = result.ProductName,
sn =result.Sn, sn = result.Sn,
pn= result.Pn, pn = result.Pn,
route=result.Route, route = result.Route,
lid=result.LId lid = result.LId
}; };
} }
......
using System; using System;
using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
...@@ -25,18 +26,18 @@ namespace Siger.Middlelayer.AccRepository.Repositories ...@@ -25,18 +26,18 @@ namespace Siger.Middlelayer.AccRepository.Repositories
_context = context; _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()) if (taskObjs.Any())
{ {
return false; return false;
} }
else else
{ {
var unDolist = _context.siger_automation_task_list.Where(f => f.send==1 && f.status !=(int)TaskResultStatus.Complated).Count(); var unDolist = _context.siger_automation_task_list.Where(f => f.send == 1 && f.status != (int)TaskResultStatus.Complated).Count();
if (unDolist==0) if (unDolist == 0)
return true; return true;
else else
return false; return false;
...@@ -51,18 +52,59 @@ namespace Siger.Middlelayer.AccRepository.Repositories ...@@ -51,18 +52,59 @@ namespace Siger.Middlelayer.AccRepository.Repositories
/// <returns></returns> /// <returns></returns>
public string CrateTaskNumber(TaskTrigerType trigerType) public string CrateTaskNumber(TaskTrigerType trigerType)
{ {
var date = DateTime.Now; //var date = DateTime.Now;
var serinum = date.DayOfYear+date.Month +date.Day+ date.Hour + date.Minute + date.Second + date.Millisecond; //var serinum = date.DayOfYear+date.Month +date.Day+ date.Hour + date.Minute + date.Second + date.Millisecond;
var dayofyear = GetDayOfYear(date); //var dayofyear = GetDayOfYear(date);
if (trigerType== TaskTrigerType.Auto) //if (trigerType== TaskTrigerType.Auto)
//{
// return $"A{date.Year}{dayofyear}{serinum}";
//}
//else
//{
// return $"M{date.Year}{dayofyear}{serinum}";
//}
if (trigerType == TaskTrigerType.Auto)
{ {
return $"A{date.Year}{dayofyear}{serinum}"; return $"A{GetId()}";
} }
else else
{ {
return $"M{date.Year}{dayofyear}{serinum}"; 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 actIds;
}
else
{
throw new Exception("Id生成器报错,队列异常;");
}
}
/// <summary> /// <summary>
/// 工件长度10 PLC 限制 /// 工件长度10 PLC 限制
/// </summary> /// </summary>
...@@ -70,19 +112,22 @@ namespace Siger.Middlelayer.AccRepository.Repositories ...@@ -70,19 +112,22 @@ namespace Siger.Middlelayer.AccRepository.Repositories
/// <returns></returns> /// <returns></returns>
public string CreateRandonSn(string productCode) public string CreateRandonSn(string productCode)
{ {
var date = DateTime.Now; //var date = DateTime.Now;
var serinum = date.DayOfYear + date.Month + date.Day + date.Hour + date.Minute + date.Second + date.Millisecond; //var seriNum = $"{date.ToString("HHmmssfff")}";
var dayofyear = GetDayOfYear(date); //var serinum = date.DayOfYear + date.Month + date.Day + date.Hour + date.Minute + date.Second + date.Millisecond;
var lable = $"{date.Year}{dayofyear}{serinum}"; //var dayofyear = GetDayOfYear(date);
//var lable = $"{date.Year}{dayofyear}{serinum}";
var lable = $"{Math.Abs(productCode.GetHashCode())}{GetId()}";
return lable; return lable;
} }
private string GetDayOfYear(DateTime dt) private string GetDayOfYear(DateTime dt)
{ {
var lable = dt.DayOfYear.ToString(); var lable = dt.DayOfYear.ToString();
var result = string.Empty; 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}"; return $"{result}{lable}";
...@@ -100,39 +145,39 @@ namespace Siger.Middlelayer.AccRepository.Repositories ...@@ -100,39 +145,39 @@ namespace Siger.Middlelayer.AccRepository.Repositories
where q.projectId == projectid where q.projectId == projectid
select new ResponseAutomationTasklist select new ResponseAutomationTasklist
{ {
id=q.id, id = q.id,
taskno=q.no, taskno = q.no,
sectionid= q.sectionid, sectionid = q.sectionid,
section=$"{lv.title}-{s.title}", section = $"{lv.title}-{s.title}",
trigger =EnumHelper.GetEnumDesc(q.trigger), trigger = EnumHelper.GetEnumDesc(q.trigger),
triggervalue=q.triggertime, triggervalue = q.triggertime,
triggerTime=q.triggertime==DateTime.MinValue?"":q.triggertime.ToString(), triggerTime = q.triggertime == DateTime.MinValue ? "" : q.triggertime.ToString(),
complatevalue=q.completetime, complatevalue = q.completetime,
complatetime=q.completetime==DateTime.MinValue?"":q.completetime.ToString(), complatetime = q.completetime == DateTime.MinValue ? "" : q.completetime.ToString(),
action=EnumHelper.GetEnumDesc(q.action), action = EnumHelper.GetEnumDesc(q.action),
actionType= EnumHelper.GetEnumDesc(q.actiontype), actionType = EnumHelper.GetEnumDesc(q.actiontype),
fixtureCode=t.code, fixtureCode = t.code,
fixtureName=t.name, fixtureName = t.name,
location=q.locationid.ToString(), location = q.locationid.ToString(),
sn=q.sn, sn = q.sn,
ordernumber=q.ordercode, ordernumber = q.ordercode,
productCode=q.productcode, productCode = q.productcode,
program=q.programnumber, program = q.programnumber,
route=r!=null?$"{r.serialNumber}-{r.name}":"", route = r != null ? $"{r.serialNumber}-{r.name}" : "",
send=q.send, send = q.send,
tasktype=EnumHelper.GetEnumDesc(q.tasktype), tasktype = EnumHelper.GetEnumDesc(q.tasktype),
tasktypeid = Convert.ToInt32(q.tasktype), tasktypeid = Convert.ToInt32(q.tasktype),
status=q.status, status = q.status,
actionTypeid = Convert.ToInt32(q.actiontype) actionTypeid = Convert.ToInt32(q.actiontype)
}; };
Expression<Func<ResponseAutomationTasklist, bool>> sectonsExpression = f => true; Expression<Func<ResponseAutomationTasklist, bool>> sectonsExpression = f => true;
if (sections.Any()) if (sections.Any())
{ {
sectonsExpression = q =>sections.Contains( q.sectionid ); sectonsExpression = q => sections.Contains(q.sectionid);
} }
Expression<Func<ResponseAutomationTasklist, bool>> taskTypeExpression = f => true; Expression<Func<ResponseAutomationTasklist, bool>> taskTypeExpression = f => true;
if (taskType != 0 ) if (taskType != 0)
{ {
taskTypeExpression = q => q.tasktypeid == taskType; taskTypeExpression = q => q.tasktypeid == taskType;
} }
...@@ -152,15 +197,15 @@ namespace Siger.Middlelayer.AccRepository.Repositories ...@@ -152,15 +197,15 @@ namespace Siger.Middlelayer.AccRepository.Repositories
snExpression = q => q.sn.Contains(sn); snExpression = q => q.sn.Contains(sn);
} }
Expression<Func<ResponseAutomationTasklist, bool>> actionTypeExpression = f => true; 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; Expression<Func<ResponseAutomationTasklist, bool>> triggerTimeTypeExpression = f => true;
if (!string.IsNullOrEmpty(triend) && !string.IsNullOrEmpty(tirbeigin)) 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; Expression<Func<ResponseAutomationTasklist, bool>> comptimeExpression = f => true;
if (!string.IsNullOrEmpty(compbegin) && !string.IsNullOrEmpty(compend)) if (!string.IsNullOrEmpty(compbegin) && !string.IsNullOrEmpty(compend))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment