2024-01-20 14:37:32 +08:00
|
|
|
|
using Infrastructure;
|
|
|
|
|
|
using Infrastructure.Attribute;
|
|
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
|
|
using MiniExcelLibs;
|
2024-01-13 16:14:34 +08:00
|
|
|
|
using Model.DBModel;
|
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
|
using System;
|
2024-01-20 14:37:32 +08:00
|
|
|
|
using System.IO;
|
2024-01-13 16:14:34 +08:00
|
|
|
|
using ZR.Model.mes.pro;
|
2024-01-20 14:37:32 +08:00
|
|
|
|
using ZR.Model.MES.pro.DTO;
|
2024-05-31 13:22:07 +08:00
|
|
|
|
using ZR.Model.MES.wms;
|
2024-01-13 16:14:34 +08:00
|
|
|
|
using ZR.Service.mes.pro.IService;
|
|
|
|
|
|
|
|
|
|
|
|
namespace ZR.Service.mes.pro
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
[AppService(ServiceType = typeof(IProWorkplanServiceV2), ServiceLifetime = LifeTime.Transient)]
|
|
|
|
|
|
public class ProWorkplanServiceV2 : BaseService<ProWorklplan_v2>, IProWorkplanServiceV2
|
|
|
|
|
|
{
|
|
|
|
|
|
|
2024-05-31 13:22:07 +08:00
|
|
|
|
public (List<ProWorklplanDto>, int) GetAllData(int pageNum, int pageSize, int year, int week, string partNumber, string color)
|
2024-01-13 16:14:34 +08:00
|
|
|
|
{
|
|
|
|
|
|
var predicate = Expressionable.Create<ProWorklplan_v2>()
|
|
|
|
|
|
.AndIF(year > 0, it => it.Year == year)
|
|
|
|
|
|
.AndIF(week > 0, it => it.Week == week)
|
|
|
|
|
|
.AndIF(!string.IsNullOrEmpty(partNumber), it => it.Partnumber.Contains(partNumber))
|
|
|
|
|
|
.AndIF(!string.IsNullOrEmpty(color), it => it.ColorCode.Contains(color))
|
|
|
|
|
|
.ToExpression();
|
|
|
|
|
|
int totalCount = 0;
|
2024-05-31 13:22:07 +08:00
|
|
|
|
List<ProWorklplan_v2> proWorkplanList = Context.Queryable<ProWorklplan_v2>()
|
|
|
|
|
|
.Where(predicate)
|
|
|
|
|
|
.OrderBy(it => it.Id)
|
|
|
|
|
|
.ToPageList(pageNum, pageSize, ref totalCount);
|
|
|
|
|
|
// 计划正确性检查
|
|
|
|
|
|
List<ProWorklplanDto> proWorkplanDtoList = new List<ProWorklplanDto>();
|
|
|
|
|
|
foreach (ProWorklplan_v2 item in proWorkplanList)
|
|
|
|
|
|
{
|
|
|
|
|
|
ProWorklplanDto plan = new()
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = item.Id,
|
|
|
|
|
|
Week = item.Week,
|
|
|
|
|
|
Year = item.Year,
|
|
|
|
|
|
BlankNum = item.BlankNum,
|
|
|
|
|
|
Partnumber = item.Partnumber,
|
|
|
|
|
|
ProductName = item.ProductName,
|
|
|
|
|
|
Specification = item.Specification,
|
|
|
|
|
|
ColorCode = item.ColorCode,
|
|
|
|
|
|
ProductionBeat = item.ProductionBeat,
|
|
|
|
|
|
ProductTime = item.ProductTime,
|
|
|
|
|
|
NoSchedule = item.NoSchedule,
|
|
|
|
|
|
QualificationRate = item.QualificationRate,
|
|
|
|
|
|
RequireHanger = item.RequireHanger,
|
|
|
|
|
|
AllHangerNum = item.AllHangerNum,
|
|
|
|
|
|
EveryHangerNum = item.EveryHangerNum,
|
|
|
|
|
|
RequireNum = item.RequireNum,
|
|
|
|
|
|
TurnNumber = item.TurnNumber,
|
|
|
|
|
|
Remark = item.Remark,
|
|
|
|
|
|
CreatedBy = item.CreatedBy,
|
|
|
|
|
|
CreatedTime = item.CreatedTime,
|
|
|
|
|
|
UpdatedBy = item.UpdatedBy,
|
|
|
|
|
|
UpdatedTime = item.UpdatedTime,
|
|
|
|
|
|
};
|
|
|
|
|
|
plan.State = CheckWorkPlan(item);
|
|
|
|
|
|
proWorkplanDtoList.Add(plan);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (proWorkplanDtoList, totalCount);
|
2024-01-13 16:14:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-01-22 15:22:56 +08:00
|
|
|
|
public List<ProWorklplan_v2> GetProWorkplanById(string id)
|
2024-01-13 16:14:34 +08:00
|
|
|
|
{
|
2024-01-22 15:22:56 +08:00
|
|
|
|
return Context.Queryable<ProWorklplan_v2>().Where(it => it.Id == id).ToList();
|
2024-01-13 16:14:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-20 14:37:32 +08:00
|
|
|
|
|
|
|
|
|
|
|
2024-01-15 20:04:50 +08:00
|
|
|
|
public int AddWorkPlan(ProWorklplan_v2 proWorkplan)
|
2024-01-13 16:14:34 +08:00
|
|
|
|
{
|
2024-01-20 14:37:32 +08:00
|
|
|
|
proWorkplan.Id = "MP" + DateTime.Now.ToString("yyyyMMdd") + Getworkplanid_max().ToString("000");
|
|
|
|
|
|
proWorkplan.Remark = "手动插入";
|
|
|
|
|
|
return Context.Insertable(proWorkplan).ExecuteCommand();
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取生产计划id
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
private int Getworkplanid_max()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
2024-01-15 20:04:50 +08:00
|
|
|
|
ProWorklplan_v2 max_workplan = Context.Queryable<ProWorklplan_v2>().OrderBy(it => it.Id, OrderByType.Desc).First();
|
|
|
|
|
|
if (max_workplan != null && !string.IsNullOrEmpty(max_workplan.Id) && max_workplan.Id.Substring(2, 8) == DateTime.Now.ToString("yyyyMMdd"))
|
|
|
|
|
|
{
|
|
|
|
|
|
int num = Convert.ToInt32(max_workplan.Id.Substring(10)) + 1;
|
2024-01-20 14:37:32 +08:00
|
|
|
|
return num;
|
2024-01-15 20:04:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-01-20 14:37:32 +08:00
|
|
|
|
return 0;
|
2024-01-15 20:04:50 +08:00
|
|
|
|
}
|
2024-01-13 16:14:34 +08:00
|
|
|
|
|
2024-01-20 14:37:32 +08:00
|
|
|
|
|
2024-01-13 16:14:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-20 14:37:32 +08:00
|
|
|
|
// 修改
|
2024-01-15 20:04:50 +08:00
|
|
|
|
public int UpdateWorkPlan(ProWorklplan_v2 proWorkplan)
|
2024-01-13 16:14:34 +08:00
|
|
|
|
{
|
2024-01-20 14:37:32 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Context.Updateable<ProWorklplan_v2>()
|
|
|
|
|
|
.SetColumns(it => new ProWorklplan_v2()
|
|
|
|
|
|
{
|
|
|
|
|
|
BlankNum = proWorkplan.BlankNum,
|
|
|
|
|
|
Partnumber = proWorkplan.Partnumber,
|
|
|
|
|
|
ProductName = proWorkplan.ProductName,
|
|
|
|
|
|
Specification = proWorkplan.Specification,
|
|
|
|
|
|
ColorCode = proWorkplan.ColorCode,
|
|
|
|
|
|
RequireNum = proWorkplan.RequireNum,
|
|
|
|
|
|
EveryHangerNum = proWorkplan.EveryHangerNum,
|
|
|
|
|
|
ProductionBeat = proWorkplan.ProductionBeat,
|
|
|
|
|
|
AllHangerNum = proWorkplan.AllHangerNum,
|
|
|
|
|
|
TurnNumber = proWorkplan.TurnNumber,
|
|
|
|
|
|
ProductTime = proWorkplan.ProductTime,
|
|
|
|
|
|
RequireHanger = proWorkplan.RequireHanger,
|
|
|
|
|
|
})
|
|
|
|
|
|
.Where(it => it.Id == proWorkplan.Id)
|
|
|
|
|
|
.ExecuteCommand();
|
2024-01-13 16:14:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int DeleteWorkPlan(string id)
|
|
|
|
|
|
{
|
2024-01-15 20:04:50 +08:00
|
|
|
|
return Context.Deleteable<ProWorklplan_v2>().In(id).ExecuteCommand();
|
2024-01-13 16:14:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-20 14:37:32 +08:00
|
|
|
|
|
|
|
|
|
|
public string ImportExceldata(List<ProWorklplan_v2> worklplanList)
|
|
|
|
|
|
{
|
|
|
|
|
|
int max_id = Getworkplanid_max();
|
|
|
|
|
|
worklplanList.ForEach(it =>
|
|
|
|
|
|
{
|
|
|
|
|
|
it.Id = "MP" + DateTime.Now.ToString("yyyyMMdd") + max_id.ToString("000");
|
|
|
|
|
|
it.Remark = "Excel导入";
|
|
|
|
|
|
max_id++;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var x = Context.Storageable(worklplanList)
|
|
|
|
|
|
.SplitUpdate(it => it.Any())//存在更新
|
|
|
|
|
|
.SplitInsert(it => true)//否则插入(更新优先级大于插入)
|
|
|
|
|
|
.WhereColumns(it => new { it.Year, it.Week, it.Partnumber })//如果不是主键可以这样实现(多字段it=>new{it.x1,it.x2})
|
|
|
|
|
|
.ToStorage();
|
|
|
|
|
|
|
|
|
|
|
|
x.AsInsertable.ExecuteCommand();//插入可插入部分;
|
|
|
|
|
|
x.AsUpdateable.IgnoreColumns(it => it.Id).ExecuteCommand();//存在更新
|
|
|
|
|
|
|
|
|
|
|
|
string msg = string.Format(" 插入{0} 更新{1} 错误数据{2} 不计算数据{3} 删除数据{4} 总共{5}",
|
|
|
|
|
|
x.InsertList.Count,
|
|
|
|
|
|
x.UpdateList.Count,
|
|
|
|
|
|
x.ErrorList.Count,
|
|
|
|
|
|
x.IgnoreList.Count,
|
|
|
|
|
|
x.DeleteList.Count,
|
|
|
|
|
|
x.TotalList.Count);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return msg; //插入可插入部分
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 下载
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="year"></param>
|
|
|
|
|
|
/// <param name="week"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public (string, string) ExportExceldata(int year, int week)
|
|
|
|
|
|
{
|
|
|
|
|
|
//1.0 读取表数据
|
|
|
|
|
|
var list = Queryable().Where(it => it.Year == year && it.Week == week).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
//2.0 保存为excel
|
|
|
|
|
|
IWebHostEnvironment webHostEnvironment = (IWebHostEnvironment)App.ServiceProvider.GetService(typeof(IWebHostEnvironment));
|
|
|
|
|
|
string sFileName = $"{year}年{week}周计划-{DateTime.Now:MM-dd-HHmmss}.xlsx";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string fullPath = Path.Combine(webHostEnvironment.WebRootPath, "export", sFileName);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Directory.CreateDirectory(Path.GetDirectoryName(fullPath));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var Sheet1 = new
|
|
|
|
|
|
{
|
|
|
|
|
|
year = year,
|
|
|
|
|
|
week = week,
|
|
|
|
|
|
title = $"{year}年车镜实业涂装事业{week}周生产滚动表",
|
|
|
|
|
|
|
|
|
|
|
|
workplan = list
|
|
|
|
|
|
};
|
|
|
|
|
|
string templatePath = Path.Combine(webHostEnvironment.WebRootPath, "ImportTemplate", "周计划标准模板1.xlsx");
|
|
|
|
|
|
MiniExcel.SaveAsByTemplate(fullPath, templatePath, Sheet1);
|
|
|
|
|
|
// MiniExcel.SaveAs(fullPath, list);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//3.0 返回路径和文件名
|
|
|
|
|
|
return (sFileName, fullPath);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-13 16:14:34 +08:00
|
|
|
|
public List<ProWorkorder> GetWorkorderListByPlanId(string id)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Context.Queryable<ProWorkorder>().Where(it => it.FkProPlanId == id).OrderBy("priority desc ").ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<ProWorkorder> GetWorkorderListById(string id)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Context.Queryable<ProWorkorder>().Where(it => it.Id == id).ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int AddWorkorder(ProWorkorder proWorkorder)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
return Context.Insertable(proWorkorder).ExecuteCommand();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int UpdateWorkorder(ProWorkorder proWorkorder)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Context.Updateable(proWorkorder).ExecuteCommand();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int DeleteWorkorder(string id)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Context.Deleteable<ProWorkorder>().In(id).ExecuteCommand();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-01-20 14:37:32 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 周计划汇总
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
|
|
|
|
public WorkplanSummaryDto GetWeekSummary(int year, int week)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Context.Queryable<ProWorklplan_v2>().Where(it => it.Year == year && it.Week == week)
|
|
|
|
|
|
.GroupBy(it => new { it.Week })
|
|
|
|
|
|
.Select(it => new WorkplanSummaryDto
|
|
|
|
|
|
{
|
|
|
|
|
|
requireNum = SqlFunc.AggregateSum(it.RequireNum),
|
|
|
|
|
|
requireHanger = SqlFunc.AggregateSum(it.RequireHanger),
|
|
|
|
|
|
turnnum = SqlFunc.AggregateSum(it.TurnNumber),
|
|
|
|
|
|
productiontime = SqlFunc.AggregateSum(it.ProductTime),
|
|
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
.First();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 删除周计划全部
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="week"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
/// <exception cref="NotImplementedException"></exception>
|
2024-06-07 11:04:26 +08:00
|
|
|
|
public int DeleteAllWorkPlan(int year, int week)
|
2024-01-20 14:37:32 +08:00
|
|
|
|
{
|
|
|
|
|
|
return Context.Deleteable<ProWorklplan_v2>().Where(it => it.Year == year && it.Week == week).ExecuteCommand();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-31 13:22:07 +08:00
|
|
|
|
public int CheckWorkPlan(ProWorklplan_v2 proWorkplan)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
if (string.IsNullOrEmpty(proWorkplan.Partnumber))
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
WmMaterial material = Context.Queryable<WmMaterial>()
|
|
|
|
|
|
.Where(it => it.Partnumber == proWorkplan.Partnumber)
|
|
|
|
|
|
.Where(it => it.Status == 1)
|
|
|
|
|
|
.First();
|
|
|
|
|
|
// 物料号不存在
|
2024-06-07 11:04:26 +08:00
|
|
|
|
if (material == null)
|
2024-05-31 13:22:07 +08:00
|
|
|
|
{
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
// 规格与颜色异常
|
2024-06-07 11:04:26 +08:00
|
|
|
|
if (material.Specification != proWorkplan.Specification || material.Color != proWorkplan.ColorCode)
|
2024-05-31 13:22:07 +08:00
|
|
|
|
{
|
|
|
|
|
|
return 2;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
2024-06-07 11:04:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
2024-05-31 13:22:07 +08:00
|
|
|
|
{
|
|
|
|
|
|
throw new Exception(ex.Message);
|
|
|
|
|
|
}
|
2024-06-07 11:04:26 +08:00
|
|
|
|
|
2024-05-31 13:22:07 +08:00
|
|
|
|
}
|
2024-01-13 16:14:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|