177 lines
6.2 KiB
C#
177 lines
6.2 KiB
C#
using Infrastructure.Attribute;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using ZR.Model.MES.op.ZR.Model.mes.md;
|
|
using ZR.Service.MES.op.IService;
|
|
using ZR.Service;
|
|
using ZR.Service.mes.mm.IService;
|
|
|
|
using ZR.Model.MES.mm;
|
|
using ZR.Model.MES.pro;
|
|
using System.Globalization;
|
|
using static System.Runtime.InteropServices.JavaScript.JSType;
|
|
using ZR.Model.MES.mm.Dto;
|
|
using SqlSugar;
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
namespace ZR.Service.mes.mm
|
|
{
|
|
[AppService(ServiceType = typeof(IMaterialInputService), ServiceLifetime = LifeTime.Transient)]
|
|
public class MaterialInputService : BaseService<MmAgvLocation>, IMaterialInputService
|
|
{
|
|
/// <summary>
|
|
/// 获取AGV上料起点
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public string[] Getstart_AGV_points()
|
|
{
|
|
List<MmAgvLocation> positions = Context.Queryable<MmAgvLocation>()
|
|
.Where(it => it.AreaCode == 2)
|
|
.Where(it => it.Type == 0)
|
|
.ToList();
|
|
|
|
string[] cors = new string[positions.Count];
|
|
for (int i = 0; i < positions.Count; i++) cors[i] = positions[i].Coordinate.ToString();
|
|
|
|
return cors;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取AGV上料终点
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public string[] Getend_AGV_points()
|
|
{
|
|
List<MmAgvLocation> positions = Context.Queryable<MmAgvLocation>()
|
|
.Where(it => it.AreaCode == 2)
|
|
.Where(it => it.Type == 1)
|
|
.ToList();
|
|
|
|
string[] cors = new string[positions.Count];
|
|
for (int i = 0; i < positions.Count; i++) cors[i] = positions[i].Coordinate.ToString();
|
|
|
|
return cors;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取工单列表
|
|
/// </summary>
|
|
/// <param name="datetimespan"></param>
|
|
/// <returns></returns>
|
|
public List<ProWorkorder_v2> Getworkorderlist(DateTime datetimespan)
|
|
{
|
|
|
|
// 获取年份和周数
|
|
Calendar calendar = new GregorianCalendar();
|
|
int year = calendar.GetYear(datetimespan);
|
|
int week = calendar.GetWeekOfYear(datetimespan, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Sunday);
|
|
|
|
// 获取这一周中的第几天
|
|
DayOfWeek dayOfWeek = datetimespan.DayOfWeek;
|
|
int dayOfWeekNumber = (int)dayOfWeek + 1; // 将 DayOfWeek 枚举转换为从 1 开始的数字
|
|
|
|
|
|
|
|
List<ProWorkorder_v2> WorkorderList = Context.Queryable<ProWorkorder_v2>()
|
|
.Where(it => it.Year == year)
|
|
.Where(it => it.Week == week)
|
|
.Where(it => it.Date == dayOfWeekNumber)
|
|
.Where(it => it.Remark3 == "是")
|
|
.ToList();
|
|
foreach (ProWorkorder_v2 workorder in WorkorderList)
|
|
{
|
|
bool isExist = Context.Queryable<MmFkWorkorderIngredient>()
|
|
.Where(it => it.FkWorkorder == workorder.ClientWorkorder)
|
|
.Any();
|
|
|
|
if (!isExist)
|
|
{
|
|
MmFkWorkorderIngredient ingredient = new MmFkWorkorderIngredient();
|
|
ingredient.FkWorkorder = workorder.ClientWorkorder;
|
|
ingredient.Isingredient = 0;
|
|
ingredient.Remian = workorder.PreviousNumber;
|
|
ingredient.CreatedTime = DateTime.Now;
|
|
Context.Insertable(ingredient).ExecuteCommand();
|
|
}
|
|
else
|
|
{
|
|
var ingredient = Context.Queryable<MmFkWorkorderIngredient>()
|
|
.Where(it => it.FkWorkorder == workorder.ClientWorkorder)
|
|
.First();
|
|
if (ingredient != null)
|
|
{
|
|
workorder.PreviousNumber = ingredient.Remian ?? 0;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return WorkorderList.Where(it => it.PreviousNumber > 0).ToList();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 生成任务单
|
|
/// </summary>
|
|
/// <param name="task"></param>
|
|
/// <returns></returns>
|
|
public int Generatetask(IngredientTaskDto task, string name)
|
|
{
|
|
List<MmIngredientTask> ingredientTasks = new List<MmIngredientTask>();
|
|
long taskid = SnowFlakeSingle.Instance.NextId();
|
|
foreach (var item in task.workorders)
|
|
{
|
|
//todo 更改待上料数量
|
|
int remian = item.previousNumber - item.previousNumbered;
|
|
if (remian == 0)
|
|
{
|
|
Context.Updateable<MmFkWorkorderIngredient>()
|
|
.Where(it => it.FkWorkorder == item.workorder)
|
|
.SetColumns(it => it.Remian == remian)
|
|
.SetColumns(it => it.Isingredient == 1)
|
|
.SetColumns(it => it.UpdatedTime == DateTime.Now)
|
|
.ExecuteCommand();
|
|
|
|
}
|
|
else
|
|
{
|
|
Context.Updateable<MmFkWorkorderIngredient>()
|
|
.Where(it => it.FkWorkorder == item.workorder)
|
|
.SetColumns(it => it.Remian == remian)
|
|
.SetColumns(it => it.UpdatedTime == DateTime.Now)
|
|
.ExecuteCommand();
|
|
|
|
}
|
|
|
|
|
|
MmIngredientTask ingredientTask = new MmIngredientTask();
|
|
ingredientTask.AgvPosition = task.agv_position;
|
|
ingredientTask.TaskId = taskid;
|
|
ingredientTask.Workorder = item.workorder;
|
|
ingredientTask.Partnumber = item.partnumber;
|
|
ingredientTask.PreviousNumber = item.previousNumber;
|
|
ingredientTask.PreviousNumbered = item.previousNumbered;
|
|
ingredientTask.CreatedBy = name;
|
|
ingredientTask.CreatedTime = DateTime.Now;
|
|
|
|
|
|
ingredientTasks.Add(ingredientTask);
|
|
|
|
}
|
|
|
|
return Context.Insertable(ingredientTasks).ExecuteCommand();
|
|
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
|