using Infrastructure.Attribute; using Microsoft.Extensions.DependencyInjection; using SqlSugar; using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using ZR.Common; using ZR.Model.mes.md; using ZR.Model.mes.pro; using ZR.Service.mes.pro.IService; using ZR.Service.MES.md.IService; namespace ZR.Service.mes.pro { [AppService(ServiceType = typeof(IProWorkorderService), ServiceLifetime = LifeTime.Transient)] public class ProWorkorderService : BaseService, IProWorkorderService { public (List, int) GetWorkorderList(int pageNum, int pageSize, int year, int week, int date, string isSchedule) { var predicate = Expressionable.Create() .AndIF(year > 0, it => it.Year == year) .AndIF(week > 0, it => it.Week == week) .AndIF(date > 0, it => it.Date == date) .And(it => it.Isarrange.Equals(isSchedule)) .ToExpression(); int totalCount = 0; List proWorkorderList = Context.Queryable().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().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() .SetColumns(it => new ProWorkorder() { ArrangeStarttime = arrange_starttime, ArrangeEndtime = arrange_endtime, Isarrange = "1", ProductionTime = (decimal)productionTime.TotalMinutes,Order=(int) CacheHelper.GetCache("workorder_id_max"),Isproduction="0" }) .Where(it => it.Id.Equals(id)) .ExecuteCommand(); } public int ResetWorkorderSechedule(string id) { return Context.Updateable() .SetColumns(it => it.Isarrange == "0") .SetColumns(it => it.Order == 0) .Where(it => it.Id.Equals(id)) .ExecuteCommand(); } public int SortWorkorderSchedule(string id, int order) { return Context.Updateable() .SetColumns(it => it.Order == order) .Where(it => it.Id.Equals(id)) .ExecuteCommand(); } public int ReleaseProduction(string id) { return Context.Updateable() .SetColumns(it => it.Isproduction == "1") .Where(it => it.Id.Equals(id)) .ExecuteCommand(); } } }