|
|
@@ -45,6 +45,7 @@ using Amazon.Runtime.Internal.Transform;
|
|
|
using System.IO.Compression;
|
|
|
using System.Collections;
|
|
|
using System.Data.SqlTypes;
|
|
|
+using Microsoft.EntityFrameworkCore.Diagnostics;
|
|
|
|
|
|
namespace Business.ResourceExamineManagement
|
|
|
{
|
|
|
@@ -391,16 +392,93 @@ namespace Business.ResourceExamineManagement
|
|
|
SnowFlake snow = new SnowFlake();
|
|
|
long bangid = snow.NextId();
|
|
|
|
|
|
+ input.tenantId = 102;
|
|
|
+ input.factoryId = 10201;
|
|
|
+
|
|
|
+ //数据准备
|
|
|
+ //await SaveChangesCompletedEventData()
|
|
|
+
|
|
|
//数据库快照-同步mysql库数据到mongoDB中
|
|
|
- await SyncData(input.tenantId,input.factoryId,bangid);
|
|
|
+ //await SyncData(input.tenantId, input.factoryId, bangid);
|
|
|
|
|
|
//产能检查
|
|
|
- await ProductiveExamine(1353957529328291842, 1000);
|
|
|
-
|
|
|
- //await GenerateMorder(14);
|
|
|
+ //await ProductiveExamine(1353957529328291842, 1000);
|
|
|
+ var id = Save(input.tenantId, input.factoryId);
|
|
|
+ await GenerateMorder(id);
|
|
|
return null;
|
|
|
throw new NotImplementedException();
|
|
|
}
|
|
|
+ public long Save(long tenantId, long factoryId)
|
|
|
+ {
|
|
|
+ //销售订单
|
|
|
+ crm_seorder crm_Seorder = new crm_seorder()
|
|
|
+ {
|
|
|
+ IsDeleted = false,
|
|
|
+ bill_no = "SO201900000020",
|
|
|
+ order_type = 1,
|
|
|
+ trade_type = 1,
|
|
|
+ sale_style = 1,
|
|
|
+ custom_id = 1001,
|
|
|
+ custom_name = "温州正泰电器科技有限公司",
|
|
|
+ custom_no = "01.0098",
|
|
|
+ date = DateTime.Now.Date,
|
|
|
+ currency = 1,
|
|
|
+ exchange_rate = 1,
|
|
|
+ biller = "张晓延",
|
|
|
+ emp_no = "8604",
|
|
|
+ emp_name = "王劲松",
|
|
|
+ auditor = "邹晓燕",
|
|
|
+ audit_date = DateTime.Now.Date,
|
|
|
+ status = 1,
|
|
|
+ closed = true,
|
|
|
+ op_time = DateTime.Now.Date,
|
|
|
+ tenant_id = tenantId,
|
|
|
+ factory_id = factoryId,
|
|
|
+ org_id = tenantId
|
|
|
+ };
|
|
|
+ crm_Seorder.GenerateNewId();
|
|
|
+ crm_seorderentry crm_Seorderentry = new crm_seorderentry()
|
|
|
+ {
|
|
|
+ IsDeleted = false,
|
|
|
+ seorder_id = crm_Seorder.Id,
|
|
|
+ bill_no = "SO201900000020",
|
|
|
+ entry_seq = 1,
|
|
|
+ map_name = "自动转换开关电器",
|
|
|
+ map_number = "L6.733036.5",
|
|
|
+ item_number = "9.1.03.01.0541",
|
|
|
+ item_name = "自动转换开关电器",
|
|
|
+ fms_number = "988123",
|
|
|
+ specification = "FDQ3-RMQ6-63/4JC1R_基本型",
|
|
|
+ bom_number = "BOM00042070",
|
|
|
+ unit = "台",
|
|
|
+ qty = 1000,
|
|
|
+ price = 100,
|
|
|
+ tax_price = 0,
|
|
|
+ amount = 0,
|
|
|
+ tax_rate = 13,
|
|
|
+ discount_amount = 0,
|
|
|
+ discount_rate = 0,
|
|
|
+ aux_price_discount = 70,
|
|
|
+ total_amount = 0,
|
|
|
+ plan_date = DateTime.Parse("2023-04-29 00:00:00"),
|
|
|
+ planner_name = "钱萍萍",
|
|
|
+ planner_no = "9022",
|
|
|
+ state = true,
|
|
|
+ rstate = 0,
|
|
|
+ is_checked = true,
|
|
|
+ deliver_count = 0,
|
|
|
+ deliver_notice_count = 0,
|
|
|
+ tenant_id = tenantId,
|
|
|
+ factory_id = factoryId,
|
|
|
+ org_id = tenantId,
|
|
|
+ };
|
|
|
+ crm_Seorderentry.GenerateNewId();
|
|
|
+
|
|
|
+ _mysql_crm_seorder.InsertAsync(crm_Seorder);
|
|
|
+ _mysql_crm_seorderentry.InsertAsync(crm_Seorderentry);
|
|
|
+
|
|
|
+ return crm_Seorderentry.Id;
|
|
|
+ }
|
|
|
|
|
|
/// <summary>
|
|
|
/// 数据库快照
|
|
|
@@ -417,44 +495,22 @@ namespace Business.ResourceExamineManagement
|
|
|
//插入数据
|
|
|
await _ic_item_stock.InsertMany(icitemStokc);
|
|
|
}
|
|
|
- ////在制工单占用记录表
|
|
|
- //var mes_mooccupy = _mysql_mes_mooccupy.GetListAsync(x => x.tenant_id == tenantId && x.factory_id == factoryId).Result;
|
|
|
- //if (mes_mooccupy.Count > 0)
|
|
|
- //{
|
|
|
- // mes_mooccupy.ForEach(item => { item.bang_id = bangid; });
|
|
|
- // await _mes_mooccupy.InsertMany(mes_mooccupy);
|
|
|
- //}
|
|
|
- ////工单主表
|
|
|
- //var mes_morder = _mysql_mes_morder.GetListAsync(x => x.tenant_id == tenantId && x.factory_id == factoryId).Result;
|
|
|
- //if (mes_morder.Count > 0)
|
|
|
- //{
|
|
|
- // mes_morder.ForEach(item => { item.bang_id = bangid; });
|
|
|
- // await _mes_morder.InsertMany(mes_morder);
|
|
|
- //}
|
|
|
- ////工单子表
|
|
|
- //var mes_moentry = _mysql_mes_moentry.GetListAsync(x => x.tenant_id == tenantId && x.factory_id == factoryId).Result;
|
|
|
- //if (mes_moentry.Count > 0)
|
|
|
- //{
|
|
|
- // mes_moentry.ForEach(item => { item.bang_id = bangid; });
|
|
|
- // await _mes_moentry.InsertMany(mes_moentry);
|
|
|
- //}
|
|
|
-
|
|
|
//在制工单占用记录表
|
|
|
- var mes_mooccupy = _mysql_mes_mooccupy.GetListAsync(x => x.factory_id == factoryId).Result;
|
|
|
+ var mes_mooccupy = _mysql_mes_mooccupy.GetListAsync(x => x.tenant_id == tenantId && x.factory_id == factoryId).Result;
|
|
|
if (mes_mooccupy.Count > 0)
|
|
|
{
|
|
|
mes_mooccupy.ForEach(item => { item.bang_id = bangid; });
|
|
|
await _mes_mooccupy.InsertMany(mes_mooccupy);
|
|
|
}
|
|
|
//工单主表
|
|
|
- var mes_morder = _mysql_mes_morder.GetListAsync(x => x.factory_id == factoryId).Result;
|
|
|
+ var mes_morder = _mysql_mes_morder.GetListAsync(x => x.tenant_id == tenantId && x.factory_id == factoryId).Result;
|
|
|
if (mes_morder.Count > 0)
|
|
|
{
|
|
|
mes_morder.ForEach(item => { item.bang_id = bangid; });
|
|
|
await _mes_morder.InsertMany(mes_morder);
|
|
|
}
|
|
|
//工单子表
|
|
|
- var mes_moentry = _mysql_mes_moentry.GetListAsync(x => x.factory_id == factoryId).Result;
|
|
|
+ var mes_moentry = _mysql_mes_moentry.GetListAsync(x => x.tenant_id == tenantId && x.factory_id == factoryId).Result;
|
|
|
if (mes_moentry.Count > 0)
|
|
|
{
|
|
|
mes_moentry.ForEach(item => { item.bang_id = bangid; });
|
|
|
@@ -463,7 +519,7 @@ namespace Business.ResourceExamineManagement
|
|
|
|
|
|
//TODO:要不要根据某些条件只同步有效的数据
|
|
|
//销售订单
|
|
|
- var crm_seorder = _mysql_crm_seorder.GetListAsync(x => x.factory_id == factoryId).Result;
|
|
|
+ var crm_seorder = _mysql_crm_seorder.GetListAsync(x => x.tenant_id == tenantId && x.factory_id == factoryId).Result;
|
|
|
if (crm_seorder.Count > 0)
|
|
|
{
|
|
|
crm_seorder.ForEach(item => { item.bang_id = bangid; });
|
|
|
@@ -471,7 +527,7 @@ namespace Business.ResourceExamineManagement
|
|
|
}
|
|
|
|
|
|
//销售订单明细
|
|
|
- var crm_seorderentry = _mysql_crm_seorderentry.GetListAsync(x => x.factory_id == factoryId).Result;
|
|
|
+ var crm_seorderentry = _mysql_crm_seorderentry.GetListAsync(x => x.tenant_id == tenantId && x.factory_id == factoryId).Result;
|
|
|
if (crm_seorderentry.Count > 0)
|
|
|
{
|
|
|
crm_seorderentry.ForEach(item => { item.bang_id = bangid; });
|
|
|
@@ -479,7 +535,7 @@ namespace Business.ResourceExamineManagement
|
|
|
}
|
|
|
|
|
|
//采购订单
|
|
|
- var srm_po_main = _mysql_srm_po_main.GetListAsync(x => x.factory_id == factoryId).Result;
|
|
|
+ var srm_po_main = _mysql_srm_po_main.GetListAsync(x => x.tenant_id == tenantId && x.factory_id == factoryId).Result;
|
|
|
if (crm_seorderentry.Count > 0)
|
|
|
{
|
|
|
srm_po_main.ForEach(item => { item.bang_id = bangid; });
|
|
|
@@ -487,7 +543,7 @@ namespace Business.ResourceExamineManagement
|
|
|
}
|
|
|
|
|
|
//采购订单明细
|
|
|
- var srm_po_list = _mysql_srm_po_list.GetListAsync(x => x.factory_id == factoryId).Result;
|
|
|
+ var srm_po_list = _mysql_srm_po_list.GetListAsync(x => x.tenant_id == tenantId && x.factory_id == factoryId).Result;
|
|
|
if (srm_po_list.Count > 0)
|
|
|
{
|
|
|
srm_po_list.ForEach(item => { item.bang_id = bangid; });
|
|
|
@@ -495,7 +551,7 @@ namespace Business.ResourceExamineManagement
|
|
|
}
|
|
|
|
|
|
//采购订单占用详情
|
|
|
- var srm_po_occupy = _mysql_srm_po_occupy.GetListAsync(x => x.factory_id == factoryId).Result;
|
|
|
+ var srm_po_occupy = _mysql_srm_po_occupy.GetListAsync(x => x.tenant_id == tenantId && x.factory_id == factoryId).Result;
|
|
|
if (srm_po_occupy.Count > 0)
|
|
|
{
|
|
|
srm_po_occupy.ForEach(item => { item.bang_id = bangid; });
|
|
|
@@ -509,7 +565,7 @@ namespace Business.ResourceExamineManagement
|
|
|
/// <param name="tech_id">工艺路径主键</param>
|
|
|
/// <param name="packages">需要生产产品件数</param>
|
|
|
/// <returns>生产时长</returns>
|
|
|
- public async Task<decimal> ProductiveExamine(long tech_id, int packages)
|
|
|
+ public async Task<decimal> ProductiveExamine(string bom_number, int packages)
|
|
|
{
|
|
|
if (packages <= 0)
|
|
|
{
|
|
|
@@ -517,14 +573,14 @@ namespace Business.ResourceExamineManagement
|
|
|
}
|
|
|
#region 1、数据准备
|
|
|
//1.1、获取工艺路径数据
|
|
|
- mes_technique tech = await _mes_technique.GetOneByID(tech_id);
|
|
|
+ mes_technique tech = _mes_technique.Find(p => p.bom == bom_number).Result.FirstOrDefault();
|
|
|
if (tech == null)
|
|
|
{
|
|
|
throw new NotImplementedException("请先配置工艺路径!");
|
|
|
}
|
|
|
|
|
|
//1.2、获取工艺路径关联工序数据
|
|
|
- List<mes_tech_process> tech_Processes = await _mes_tech_process.GetManyByCondition(x => x.tech_id == tech_id);
|
|
|
+ List<mes_tech_process> tech_Processes = await _mes_tech_process.GetManyByCondition(x => x.tech_id == tech.Id);
|
|
|
if (tech_Processes.Count == 0)
|
|
|
{
|
|
|
throw new NotImplementedException("请先配置工序!");
|
|
|
@@ -546,7 +602,7 @@ namespace Business.ResourceExamineManagement
|
|
|
//工序需要等待时间记录
|
|
|
List<StartTimeDto> starts = new List<StartTimeDto>();
|
|
|
//1、获取工艺路径下的第一层级工序
|
|
|
- List<mes_tech_process> fistChilds = tech_Processes.Where(p => p.parentprocid == tech_id).ToList();
|
|
|
+ List<mes_tech_process> fistChilds = tech_Processes.Where(p => p.parentprocid == tech.Id).ToList();
|
|
|
if (fistChilds.Count == 0)
|
|
|
{
|
|
|
throw new NotImplementedException("当前工艺路径没有配置工序,请调整!");
|
|
|
@@ -574,7 +630,7 @@ namespace Business.ResourceExamineManagement
|
|
|
}
|
|
|
sumTimes += curTakeTime;
|
|
|
//添加耗时记录
|
|
|
- dto.tech_id = tech_id;
|
|
|
+ dto.tech_id = tech.Id;
|
|
|
dto.proc_id = chd.proc_id;
|
|
|
dto.nextproc_id = chd.nextprocid;
|
|
|
dto.wait_time = curTakeTime;
|
|
|
@@ -646,7 +702,9 @@ namespace Business.ResourceExamineManagement
|
|
|
//获取销售订单信息
|
|
|
var seorder = await _mysql_crm_seorder.FindAsync(x => x.Id == seorderentry.seorder_id);
|
|
|
//物料BOM
|
|
|
- var ic_bom = _ic_bom.GetManyByCondition(x => x.bom_number == seorderentry.bom_number && x.factory_id == seorderentry.factory_id).Result.FirstOrDefault();
|
|
|
+ // var ic_bom = _ic_bom.GetManyByCondition(x => x.bom_number == seorderentry.bom_number && x.factory_id == seorderentry.factory_id).Result.FirstOrDefault();
|
|
|
+
|
|
|
+ var ic_bom = _ic_bom.GetManyByCondition(x => x.bom_number == seorderentry.bom_number).Result.FirstOrDefault();
|
|
|
|
|
|
mes_morder mes_Morder = new mes_morder();
|
|
|
mes_Morder.GenerateNewId();
|
|
|
@@ -662,7 +720,7 @@ namespace Business.ResourceExamineManagement
|
|
|
//根绝系统配置参数 取最早或者最晚开始日期
|
|
|
var StartDate = DateTime.Now.Date.AddDays(3);
|
|
|
mes_Morder.moentry_sys_stime = StartDate;
|
|
|
- var ProductiveDate = ProductiveExamine(ic_bom.tech_id, (int)(seorderentry.qty.Value));
|
|
|
+ var ProductiveDate = ProductiveExamine(ic_bom.bom_number, (int)(seorderentry.qty.Value));
|
|
|
//系统建议完工日期为 开工日期+产能检查时间=完工日期
|
|
|
var Day = ProductiveDate.Result / (60 * 10); //返回的分钟除以十个小时得出工作天数;
|
|
|
mes_Morder.moentry_sys_etime = StartDate.AddDays((double)Day);
|
|
|
@@ -1032,7 +1090,8 @@ namespace Business.ResourceExamineManagement
|
|
|
//递归将替代关系组装出来。
|
|
|
SubstitutePretreatment(sl, sal, dtl, item, returnlist, icitemlist, bomlist, bomchildlist, type);
|
|
|
}
|
|
|
- else {
|
|
|
+ else
|
|
|
+ {
|
|
|
//将主料赋值上属性
|
|
|
var dtlitem = returnlist.Find(s => s.item_id == dtl.icitem_id && s.level == item.level);
|
|
|
dtlitem.substitute_all_num = sal.order_num;//群组优先级
|
|
|
@@ -1140,7 +1199,7 @@ namespace Business.ResourceExamineManagement
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
public void calcTest(List<BomChildExamineDto> returnlist, long bangid, long orderid)
|
|
|
{
|
|
|
@@ -1210,7 +1269,7 @@ namespace Business.ResourceExamineManagement
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
|
|
|
public void calcTest2(BomChildExamineDto parent, List<BomChildExamineDto> bzlist, List<BomChildExamineDto> returnlist, List<ic_item_stockoccupy> sockoccupyList)
|
|
|
{
|
|
|
@@ -1227,7 +1286,7 @@ namespace Business.ResourceExamineManagement
|
|
|
//循环计算群组,看哪个群组满足要求,然后使用此群组,将群组的库存和子物料占用掉。
|
|
|
//计算此次群组是否有符合
|
|
|
MaterialCalc(sublist, returnlist, sockoccupyList);
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -1269,13 +1328,15 @@ namespace Business.ResourceExamineManagement
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- else {
|
|
|
+ else
|
|
|
+ {
|
|
|
g.kz = Math.Floor(g.sqty / g.qty);//自己不是BOM的情况下,算一下自己可制父级可以制造多少个,这个可制只是基于父级BOM才用来运算。
|
|
|
//todo:申老师说,如果是苏州工厂,原材料有可能也是自制的。
|
|
|
//所以这里在计算时,还可以直接拿缺料数量,去丢给苏州计算方法,得出原材料的库存加可制。
|
|
|
}
|
|
|
}
|
|
|
- else {
|
|
|
+ else
|
|
|
+ {
|
|
|
boolCount++;
|
|
|
}
|
|
|
}
|
|
|
@@ -1507,10 +1568,10 @@ namespace Business.ResourceExamineManagement
|
|
|
/// <param name="factoryid">工厂id</param>
|
|
|
/// <param name="deliveryDate">销售订单交付日期</param>
|
|
|
/// <returns></returns>
|
|
|
- private async Task<List<ICItemDateDto>> CheckOnOrder(List<BomChildExamineDto> returnlist, long factoryid,DateTime deliveryDate)
|
|
|
+ private async Task<List<ICItemDateDto>> CheckOnOrder(List<BomChildExamineDto> returnlist, long factoryid, DateTime deliveryDate)
|
|
|
{
|
|
|
//ToDo:企业Id,数据状态过滤以及isdeleted
|
|
|
- var po_list=_srm_po_list.Find(p => returnlist.Select(x => x.item_id).Contains(p.icitem_id) && p.factory_id == factoryid && p.rarrdate>=DateTime.Now && p.rarrdate<deliveryDate).Result;
|
|
|
+ var po_list = _srm_po_list.Find(p => returnlist.Select(x => x.item_id).Contains(p.icitem_id) && p.factory_id == factoryid && p.rarrdate >= DateTime.Now && p.rarrdate < deliveryDate).Result;
|
|
|
var itemlist = new List<ICItemDateDto>();//需要生成采购申请单的物料信息
|
|
|
var leadTimeList = GetLeadTime(returnlist, factoryid);//提前期列表
|
|
|
var supplierList = GetSupplier(returnlist, factoryid);//供应商列表
|
|
|
@@ -1518,10 +1579,10 @@ namespace Business.ResourceExamineManagement
|
|
|
foreach (var item in returnlist)
|
|
|
{
|
|
|
//缺料
|
|
|
- if(item.lack_qty>0)
|
|
|
+ if (item.lack_qty > 0)
|
|
|
{
|
|
|
- var itemPO =po_list.FindAll(x => x.icitem_id == item.item_id).OrderBy(v=>v.rarrdate).ToList();
|
|
|
- if(itemPO.Count<=0 || itemPO.Sum(p => (p.qty - p.esqty))<item.lack_qty)
|
|
|
+ var itemPO = po_list.FindAll(x => x.icitem_id == item.item_id).OrderBy(v => v.rarrdate).ToList();
|
|
|
+ if (itemPO.Count <= 0 || itemPO.Sum(p => (p.qty - p.esqty)) < item.lack_qty)
|
|
|
{
|
|
|
//外购生成采购申请单
|
|
|
if (item.erp_cls == 3)
|
|
|
@@ -1536,7 +1597,8 @@ namespace Business.ResourceExamineManagement
|
|
|
CreateMesOOder(item, factoryid, leadTimeList, supplierList,deliveryDate);
|
|
|
itemlist.Add(new ICItemDateDto { item_id = item.item_id, dateTime = lastTime});
|
|
|
}
|
|
|
- }else
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
decimal? itemPOQty = 0;//当前物料已抵扣数量
|
|
|
for (int i = 0; i < itemPO.Count; i++)
|
|
|
@@ -1544,7 +1606,7 @@ namespace Business.ResourceExamineManagement
|
|
|
if (itemPOQty + itemPO[i].qty - itemPO[i].esqty >= item.lack_qty)
|
|
|
{
|
|
|
//在途满足,写占用表
|
|
|
- itemlist.Add(new ICItemDateDto { item_id = itemPO[i].icitem_id, dateTime = itemPO[i].rarrdate});
|
|
|
+ itemlist.Add(new ICItemDateDto { item_id = itemPO[i].icitem_id, dateTime = itemPO[i].rarrdate });
|
|
|
srm_po_occupy po_Occupy = new srm_po_occupy();
|
|
|
po_Occupy.GenerateNewId();
|
|
|
po_Occupy.polist_id = itemPO[i].po_id;//采购订单id
|
|
|
@@ -1553,7 +1615,7 @@ namespace Business.ResourceExamineManagement
|
|
|
po_Occupy.bill_no = 111;//客户订单id
|
|
|
po_Occupy.type = "在途占用";//类型
|
|
|
po_Occupy.entry_id = 1;//行号
|
|
|
- po_Occupy.qty = item.lack_qty- itemPOQty;//占用量
|
|
|
+ po_Occupy.qty = item.lack_qty - itemPOQty;//占用量
|
|
|
po_Occupy.stime = DateTime.Now;//开始时间
|
|
|
po_Occupy.etime = deliveryDate;//结束时间
|
|
|
po_Occupy.state = 1;//占用状态
|
|
|
@@ -1616,17 +1678,17 @@ namespace Business.ResourceExamineManagement
|
|
|
oOrder.ffms_number = "1000";//fms旧料号
|
|
|
oOrder.product_name = "test";//产品名称
|
|
|
oOrder.specification_model = returnlist.model;//规格型号
|
|
|
- oOrder.bom_number ="";//bom编码
|
|
|
+ oOrder.bom_number = "";//bom编码
|
|
|
oOrder.unit = returnlist.unit;//单位
|
|
|
oOrder.morder_progress = "";//工单进度
|
|
|
oOrder.morder_production_number = 120;//工单生产数量(计划数量)
|
|
|
- oOrder.need_number =returnlist.lack_qty;//需求数量
|
|
|
+ oOrder.need_number = returnlist.lack_qty;//需求数量
|
|
|
oOrder.remaining_number = returnlist.lack_qty;//剩余可用数量
|
|
|
oOrder.work_number = 0;//报工数量
|
|
|
oOrder.inspection_number = 0;//报检数量
|
|
|
oOrder.qualified_number = 0;//合格数量
|
|
|
oOrder.inventory_number = 0;//入库数量
|
|
|
- oOrder.notice_qty =0;//已开通知单数量
|
|
|
+ oOrder.notice_qty = 0;//已开通知单数量
|
|
|
oOrder.moentry_on = 1;//启动状态
|
|
|
//oOrder.start_time = DateTime.Now;//开始时间
|
|
|
//oOrder.pause_time = DateTime.Now;//最近暂停时间
|