229 lines
9.6 KiB
C#
229 lines
9.6 KiB
C#
using Infrastructure.Attribute;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using SqlSugar;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Linq.Expressions;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using ZR.Common;
|
|
using ZR.Model.mes.md;
|
|
using ZR.Model.mes.pro;
|
|
using ZR.Model.MES.wm;
|
|
using ZR.Service.mes.pro.IService;
|
|
using ZR.Service.MES.md.IService;
|
|
using static System.Net.WebRequestMethods;
|
|
|
|
using JinianNet.JNTemplate;
|
|
using static Aliyun.OSS.Model.LiveChannelStat;
|
|
using ZR.Model.MES.pro.DTO;
|
|
using ZR.Model.MES.qu;
|
|
|
|
namespace ZR.Service.mes.pro
|
|
{
|
|
[AppService(ServiceType = typeof(IProWorkorderService), ServiceLifetime = LifeTime.Transient)]
|
|
public class ProWorkorderService : BaseService<ProWorkorder>, IProWorkorderService
|
|
{
|
|
|
|
public (List<ProWorkorder>, int) GetWorkorderList(int pageNum, int pageSize, int year, int week, int date, int isSchedule)
|
|
{
|
|
|
|
var predicate = Expressionable.Create<ProWorkorder>()
|
|
.AndIF(year > 0, it => it.Year == year)
|
|
.AndIF(week > 0, it => it.Week == week)
|
|
.AndIF(date > 0, it => it.Date == date)
|
|
.AndIF(isSchedule == 0, it => it.Wrokerorder_status.Equals(isSchedule))
|
|
.AndIF(isSchedule >= 1, it => it.Wrokerorder_status >= 1)
|
|
.ToExpression();
|
|
|
|
int totalCount = 0;
|
|
List<ProWorkorder> proWorkorderList = Context.Queryable<ProWorkorder>().Where(predicate).OrderBy(it => it.Order).ToPageList(pageNum, pageSize, ref totalCount);
|
|
|
|
return (proWorkorderList, totalCount);
|
|
}
|
|
|
|
public int SetWorkorderSechedule(string id, DateTime arrange_starttime, DateTime arrange_endtime)
|
|
{
|
|
//获取排序最大值
|
|
if (CacheHelper.GetCache("workorder_id_max") == null)
|
|
{
|
|
int? workorder_id_max = Context.Queryable<ProWorkorder>().OrderBy(it => it.Order, OrderByType.Desc).First().Order;
|
|
//初次
|
|
if (workorder_id_max == null || workorder_id_max == 0)
|
|
{
|
|
workorder_id_max = 1;
|
|
}
|
|
CacheHelper.SetCache("workorder_id_max", workorder_id_max);
|
|
}
|
|
CacheHelper.SetCache("workorder_id_max", (int)CacheHelper.GetCache("workorder_id_max") + 1);
|
|
|
|
|
|
TimeSpan productionTime = arrange_endtime - arrange_starttime;
|
|
return Context.Updateable<ProWorkorder>()
|
|
.SetColumns(it => new ProWorkorder() { ArrangeStarttime = arrange_starttime, ArrangeEndtime = arrange_endtime, Wrokerorder_status = 1, ProductionTime = (decimal)productionTime.TotalMinutes, Order = (int)CacheHelper.GetCache("workorder_id_max") })
|
|
.Where(it => it.Id.Equals(id))
|
|
.ExecuteCommand();
|
|
}
|
|
|
|
public int ResetWorkorderSechedule(string id)
|
|
{
|
|
return Context.Updateable<ProWorkorder>()
|
|
.SetColumns(it => it.Wrokerorder_status == 0)
|
|
.SetColumns(it => it.Order == 0)
|
|
.Where(it => it.Id.Equals(id))
|
|
.ExecuteCommand();
|
|
}
|
|
|
|
public int SortWorkorderSchedule(string id, int order)
|
|
{
|
|
return Context.Updateable<ProWorkorder>()
|
|
.SetColumns(it => it.Order == order)
|
|
.Where(it => it.Id.Equals(id))
|
|
.ExecuteCommand();
|
|
}
|
|
|
|
public int ReleaseProduction(string id, HttpContext context)
|
|
{
|
|
int result = Context.Updateable<ProWorkorder>()
|
|
.SetColumns(it => it.Wrokerorder_status == 2)
|
|
.Where(it => it.Id.Equals(id))
|
|
.ExecuteCommand();
|
|
ProWorkorder workorder = Context.Queryable<ProWorkorder>().Where(it => it.Id == id).First();
|
|
if (result == 1)
|
|
{
|
|
|
|
// 生成领料单
|
|
// 若没有此零件号的领料单,就新增,否则,修改累加
|
|
|
|
bool isExit = Context.Queryable<WmWorkorderMr>().Where(it => it.WorkorderId == workorder.Id).Any();
|
|
if (!isExit)
|
|
{
|
|
// 新增 领料单
|
|
WmMaterialrequisition materialrequisition = new WmMaterialrequisition();
|
|
materialrequisition.CreatedBy = context.User?.Identity?.Name;
|
|
materialrequisition.CreatedTime = DateTime.Now;
|
|
materialrequisition.Year = workorder.Year;
|
|
materialrequisition.Week = workorder.Week;
|
|
materialrequisition.Date = workorder.Date;
|
|
materialrequisition.Id = DateTime.Now.ToString("yyyyMMddHHmmss");
|
|
materialrequisition.Requirenum = workorder.Actualnumber;
|
|
materialrequisition.Workblankpartnumber = workorder.Workblankpartnumber;
|
|
materialrequisition.Status = "0";
|
|
Context.Insertable(materialrequisition).ExecuteCommandAsync();
|
|
// 新增工单-领料关联表
|
|
WmWorkorderMr mr = new WmWorkorderMr();
|
|
mr.Id = DateTime.Now.ToString("yyyyMMddHHmmss");
|
|
mr.WorkorderId = workorder.Id;
|
|
mr.MaterialrequisitionId = materialrequisition.Id;
|
|
mr.CreatedBy = context.User?.Identity?.Name;
|
|
mr.CreatedTime = DateTime.Now;
|
|
Context.Insertable(mr).ExecuteCommandAsync();
|
|
|
|
//新增领料单统计表
|
|
QcRough qcRough=new QcRough ();
|
|
qcRough.Id = DateTime.Now.ToString("yyyyMMddHHmmss");
|
|
qcRough.FkMaterialrequisitionId= materialrequisition.Id;
|
|
qcRough.RequireNum = materialrequisition.Requirenum;
|
|
qcRough.ActualNumber = materialrequisition.Requirenum;
|
|
qcRough.CreatedBy= context.User?.Identity?.Name;
|
|
qcRough.CreatedTime= DateTime.Now;
|
|
qcRough.OksRatio = 10;
|
|
Context.Insertable (qcRough).ExecuteCommandAsync();
|
|
}
|
|
else
|
|
{
|
|
UseTran(() =>
|
|
{
|
|
//查询当前工单下的领料数量
|
|
List<WmMaterialrequisition> wm = Context.Queryable<ProWorkorder>()
|
|
.LeftJoin<WmWorkorderMr>((m, mr) => m.Id == mr.WorkorderId)
|
|
.LeftJoin<WmMaterialrequisition>((m, mr, r) => mr.MaterialrequisitionId == r.Id)
|
|
.Where(m => m.Id == id)
|
|
.Select((m, mr, r) => r)
|
|
.ToList();
|
|
|
|
wm[0].Requirenum += workorder.Actualnumber;
|
|
wm[0].UpdatedTime = DateTime.Now;
|
|
wm[0].UpdatedBy = context.User?.Identity?.Name;
|
|
//更新领料单
|
|
Context.Updateable(wm[0]);
|
|
//更新检验表
|
|
Context.Updateable<QcRough>().SetColumns(it => it.RequireNum == wm[0].Requirenum)
|
|
.SetColumns(it => it.ActualNumber == wm[0].Requirenum)
|
|
.Where(it => it.FkMaterialrequisitionId == wm[0].Id).ExecuteCommandAsync();
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return result;
|
|
}
|
|
/// <summary>
|
|
/// 获取甘特图
|
|
/// </summary>
|
|
/// <param name="year"></param>
|
|
/// <param name="week"></param>
|
|
/// <param name="date"></param>
|
|
/// <returns></returns>
|
|
public GanttTaskDTO GetGanttList(int year, int week, int date)
|
|
{
|
|
|
|
|
|
var predicate = Expressionable.Create<ProWorkorder>()
|
|
.AndIF(year > 0, it => it.Year == year)
|
|
.AndIF(week > 0, it => it.Week == week)
|
|
.AndIF(date > 0, it => it.Date == date)
|
|
.And(it=>it.Wrokerorder_status==2) // 已经排产
|
|
.ToExpression();
|
|
|
|
|
|
List<ProWorkorder> proWorkorderList = Context.Queryable<ProWorkorder>().Where(predicate).ToList();
|
|
|
|
|
|
GanttTaskDTO ganttTask = new GanttTaskDTO();
|
|
|
|
List<GanttTask_data> ganttTask_data = new List<GanttTask_data>();
|
|
List<GanttTask_link> ganttTask_Links = new List<GanttTask_link>();
|
|
|
|
foreach (var item in proWorkorderList)
|
|
{
|
|
GanttTask_data data = new GanttTask_data();
|
|
data.id = item.Id;
|
|
data.text = item.ProductionName;
|
|
data.start_date = ((DateTime)item.ArrangeStarttime).ToString("yyyy-MM-dd");
|
|
data.duration = item.ProductionTime;
|
|
data.planned_start = ((DateTime)item.ArrangeStarttime).ToString("yyyy-MM-dd");
|
|
data.planned_end = ((DateTime)item.ArrangeEndtime).ToString("yyyy-MM-dd");
|
|
data.progress = 1;
|
|
data.show = false;
|
|
data.open = true;
|
|
data.type = "project";
|
|
|
|
|
|
GanttTask_link link = new GanttTask_link();
|
|
link.id = item.Order;
|
|
link.source = item.Order;
|
|
int index = proWorkorderList.IndexOf(item);
|
|
if (index < proWorkorderList.Count-1)
|
|
link.target = (int)proWorkorderList[index + 1]?.Order;
|
|
link.type = 0;
|
|
|
|
ganttTask_data.Add(data);
|
|
ganttTask_Links.Add(link);
|
|
|
|
|
|
}
|
|
ganttTask.Data = ganttTask_data;
|
|
ganttTask.Links = ganttTask_Links;
|
|
return ganttTask;
|
|
}
|
|
}
|
|
}
|