Commit 7f13f955 by chenzhengpeng

code repo

parent 91115f3c
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