|
|
@@ -145,18 +145,33 @@ namespace Business.ResourceExamineManagement
|
|
|
private IRepository<b_purchase_occupy, long> _mysql_purchase_occupy;
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 替代群组
|
|
|
+ /// 替代方案
|
|
|
/// </summary>
|
|
|
private readonly IRepository<mo_ic_substitute,long> _ic_substitute;
|
|
|
/// <summary>
|
|
|
- /// 替代群组
|
|
|
+ /// 替代方案群组
|
|
|
/// </summary>
|
|
|
private readonly IRepository<mo_ic_substitute_group,long> _ic_substitute_group;
|
|
|
/// <summary>
|
|
|
- /// 替代群组
|
|
|
+ /// 替代明细
|
|
|
/// </summary>
|
|
|
private readonly IRepository<mo_ic_substitute_group_detail,long> _ic_substitute_group_detail;
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 替代方案
|
|
|
+ /// </summary>
|
|
|
+ private readonly IRepository<ic_substitute, long> _mysql_ic_substitute;
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 替代方案群组
|
|
|
+ /// </summary>
|
|
|
+ private readonly IRepository<ic_substitute_group, long> _mysql_ic_substitute_group;
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 替代明细
|
|
|
+ /// </summary>
|
|
|
+ private readonly IRepository<ic_substitute_group_detail, long> _mysql_ic_substitute_group_detail;
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 生产工单主表
|
|
|
/// </summary>
|
|
|
@@ -440,7 +455,10 @@ namespace Business.ResourceExamineManagement
|
|
|
ISqlRepository<ItemPackMaster> itemPackMaster,
|
|
|
ISqlRepository<GeneralizedCodeMaster> generalizedCodeMaster,
|
|
|
ISqlRepository<ScheduleResultOpMaster> scheduleResultOpMaster,
|
|
|
- IUnitOfWorkManager unitOfWorkManager
|
|
|
+ IUnitOfWorkManager unitOfWorkManager,
|
|
|
+ IRepository<ic_substitute, long> mysql_ic_substitute,
|
|
|
+ IRepository<ic_substitute_group, long> mysql_ic_substitute_group,
|
|
|
+ IRepository<ic_substitute_group_detail, long> mysql_ic_substitute_group_detail
|
|
|
)
|
|
|
{
|
|
|
_mes_technique = mes_technique;
|
|
|
@@ -460,6 +478,9 @@ namespace Business.ResourceExamineManagement
|
|
|
_ic_substitute = ic_substitute;
|
|
|
_ic_substitute_group = ic_substitute_group;
|
|
|
_ic_substitute_group_detail = ic_substitute_group_detail;
|
|
|
+ _mysql_ic_substitute = mysql_ic_substitute;
|
|
|
+ _mysql_ic_substitute_group = mysql_ic_substitute_group;
|
|
|
+ _mysql_ic_substitute_group_detail = mysql_ic_substitute_group_detail;
|
|
|
_mes_morder = mes_morder;
|
|
|
_mes_moentry = mes_moentry;
|
|
|
_mes_mooccupy = mes_mooccupy;
|
|
|
@@ -1007,8 +1028,8 @@ namespace Business.ResourceExamineManagement
|
|
|
srm_Pr.pr_psend_date = prlist.Min(s => s.pr_psend_date);//计划下单日期
|
|
|
srm_Pr.pr_parrive_date = prlist.Min(s => s.pr_parrive_date);//计划到达日期
|
|
|
srm_Pr.pr_rarrive_date = prlist.Min(s => s.pr_rarrive_date);//需求到货日期
|
|
|
- srm_Pr.pr_sysprice = prlist.Sum(s => s.pr_rqty) * prlist[0].pr_price * (1 + prlist[0].pr_rate);//系统价格(含税)
|
|
|
- srm_Pr.pr_orderprice = prlist.Sum(s => s.pr_rqty) * prlist[0].pr_price * (1 + prlist[0].pr_rate);//订单价格(含税)
|
|
|
+ //srm_Pr.pr_sysprice = prlist.Sum(s => s.pr_rqty) * prlist[0].pr_price * (1 + prlist[0].pr_rate);//系统价格(含税)
|
|
|
+ srm_Pr.pr_orderprice = prlist.Sum(s => s.pr_aqty) * prlist[0].pr_sysprice;//订单价格(含税)
|
|
|
/*srm_Pr.icitem_id = returnlist.item_id;//物料id
|
|
|
srm_Pr.icitem_name = returnlist.item_name;//物料名称
|
|
|
srm_Pr.pr_order_type = 1;//单据类型
|
|
|
@@ -1062,10 +1083,10 @@ namespace Business.ResourceExamineManagement
|
|
|
var moPrlist = ObjectMapper.Map<List<srm_pr_main>, List<mo_srm_pr_main>>(prlist);
|
|
|
foreach (var pr in prlist)
|
|
|
{
|
|
|
- bool bl = pr.sentry_id == null;
|
|
|
- //找到是否生成了新的PR
|
|
|
- //var newPr = insetPrList.Find(s => s.pr_purchaseid == pr.pr_purchaseid && s.icitem_id == pr.icitem_id && (s.sentry_id == null) == bl);
|
|
|
- var newPr = insetPrList.Find(s => s.pr_purchaseid == pr.pr_purchaseid && s.icitem_id == pr.icitem_id);
|
|
|
+ bool bl = pr.sentry_id == null;//区分是销售订单和非销售订单的合并。
|
|
|
+ //找到是否生成了新的PR 当前数据是否已经产生合并,则不再合并。
|
|
|
+ var newPr = insetPrList.Find(s => s.pr_purchaseid == pr.pr_purchaseid && s.icitem_id == pr.icitem_id && (s.sentry_id == null) == bl);
|
|
|
+ //var newPr = insetPrList.Find(s => s.pr_purchaseid == pr.pr_purchaseid && s.icitem_id == pr.icitem_id);
|
|
|
if (newPr == null)
|
|
|
{
|
|
|
//有多条才进行合并
|
|
|
@@ -1095,8 +1116,8 @@ namespace Business.ResourceExamineManagement
|
|
|
newPr.pr_sarrive_date = newPr.pr_rarrive_date;//系统建议到达日期(建议到货日期)
|
|
|
newPr.pr_parrive_date = newPr.pr_rarrive_date;//计划到达日期
|
|
|
|
|
|
- newPr.pr_sysprice = newPr.pr_rqty * pr.pr_price * (1 + pr.pr_rate);//系统价格(含税)
|
|
|
- newPr.pr_orderprice = newPr.pr_rqty * pr.pr_price * (1 + pr.pr_rate);//订单价格(含税)
|
|
|
+ //newPr.pr_sysprice = newPr.pr_rqty * pr.pr_price * (1 + pr.pr_rate);//系统价格(含税)
|
|
|
+ newPr.pr_orderprice = newPr.pr_aqty * pr.pr_sysprice;//订单价格(含税)
|
|
|
ilist.ForEach(s => { s.refer_pr_billno = newPr.pr_billno; });
|
|
|
insetPrList.Add(newPr);
|
|
|
ilist.ForEach(s => { s.state = 0; });
|
|
|
@@ -1257,7 +1278,8 @@ namespace Business.ResourceExamineManagement
|
|
|
DateTime toTime = new DateTime(2023, 7, 6);
|
|
|
DateTime starttime = toTime.AddDays(1);
|
|
|
DateTime endtime = toTime.AddDays(8);
|
|
|
- List<srm_pr_main> prlist = _mysql_srm_pr_main.GetListAsync(s => s.company_id.ToString() == companyid && s.pr_rarrive_date >= starttime && s.pr_rarrive_date <= endtime && (s.state == 1|| s.state == 2 || s.state == 3)).Result;
|
|
|
+ List<srm_pr_main> prlist = _mysql_srm_pr_main.GetListAsync(s => s.company_id.ToString() == companyid && s.IsRequireGoods == 0 && s.pr_rarrive_date >= starttime &&
|
|
|
+ s.pr_rarrive_date <= endtime && (s.state == 1|| s.state == 2 || s.state == 3)).Result;
|
|
|
|
|
|
if (prlist.Any())
|
|
|
{
|
|
|
@@ -1279,7 +1301,7 @@ namespace Business.ResourceExamineManagement
|
|
|
}
|
|
|
if (poaction.polist.Any())
|
|
|
{
|
|
|
- _businessDbContext.BulkInsert(poaction.polist);
|
|
|
+ _businessDbContext.BulkInsert(poaction.polist);
|
|
|
}
|
|
|
if (poaction.poOccupiesList.Any())
|
|
|
{
|
|
|
@@ -1288,6 +1310,7 @@ namespace Business.ResourceExamineManagement
|
|
|
|
|
|
if (poaction.poMasterList.Any())
|
|
|
{
|
|
|
+ poaction.poMasterList.ForEach(s => { s.ReqBy = "DO"; });
|
|
|
_purOrdMaster.Insert(poaction.poMasterList);
|
|
|
//快开平台用自增列RecId关联,所以需要插入后再查给明细表赋相应的值
|
|
|
List<string> nbrs = poaction.poMasterList.Select(a => a.PurOrd).ToList();
|
|
|
@@ -1303,15 +1326,15 @@ namespace Business.ResourceExamineManagement
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
unitOfWork.Dispose();
|
|
|
- new NLogHelper("ResourceExamineAppService").WriteLog("PrApprove", "采购申请单合并失败:" + e.Message, _currentTenant.Id.ToString());
|
|
|
- return JsonConvert.SerializeObject("合并失败,请联系管理员。");
|
|
|
+ new NLogHelper("ResourceExamineAppService").WriteLog("PrAutoApprove", "要货令转采购订单失败:" + e.Message, _currentTenant.Id.ToString());
|
|
|
+ return JsonConvert.SerializeObject("要货令转采购订单失败,请联系管理员。");
|
|
|
}
|
|
|
}
|
|
|
return JsonConvert.SerializeObject("ok");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- return JsonConvert.SerializeObject("没有需要审核的采购申请单。");
|
|
|
+ return JsonConvert.SerializeObject("没有需要审核的要货令。");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1322,27 +1345,30 @@ namespace Business.ResourceExamineManagement
|
|
|
/// <returns></returns>
|
|
|
public async Task<string> PrApprove(string ids)
|
|
|
{
|
|
|
- //物料、供应商为相同才允许合并。
|
|
|
var idList = AnalysisIdList(ids);
|
|
|
List<srm_pr_main> prlist = _mysql_srm_pr_main.GetListAsync(s => idList.Contains(s.Id)).Result;
|
|
|
if (!prlist.Any())
|
|
|
{
|
|
|
- return JsonConvert.SerializeObject("所选采购申请单未找到,请刷新界面重新操作。");
|
|
|
+ return JsonConvert.SerializeObject("所选要货令未找到,请刷新界面重新操作。");
|
|
|
}
|
|
|
if (prlist.Where(s => s.state == 0).Count() > 0)
|
|
|
{
|
|
|
- return JsonConvert.SerializeObject("所选包含已关闭采购申请,请重新选择。");
|
|
|
+ return JsonConvert.SerializeObject("所选包含已关闭要货令,请重新选择。");
|
|
|
}
|
|
|
if (prlist.Where(s => s.state == 3).Count() > 0)
|
|
|
{
|
|
|
- return JsonConvert.SerializeObject("所选包含评审未通过采购申请,请重新选择。");
|
|
|
+ return JsonConvert.SerializeObject("所选包含评审未通过要货令,请重新选择。");
|
|
|
+ }
|
|
|
+ if (prlist.Where(s => s.IsRequireGoods == 0).Count() > 0)
|
|
|
+ {
|
|
|
+ return JsonConvert.SerializeObject("包含采购申请,不允许与要货令转采购订单。");
|
|
|
}
|
|
|
List<srm_purchase> purchaselist = _mysql_srm_purchase.GetListAsync(s => prlist.Select(c => c.icitem_id).Contains(s.icitem_id) && prlist.Select(c => c.pr_purchaseid).Contains(s.supplier_id)).Result;
|
|
|
List<srm_supplier> itemsupplierList = _mysql_srm_supplier.GetListAsync(s => prlist.Select(c => c.pr_purchaseid).Contains(s.Id)).Result;
|
|
|
var purclist = purchaselist.GroupBy(s => new { s.supplier_type, s.supplier_id });
|
|
|
if (purclist.Count() > 1)
|
|
|
{
|
|
|
- return JsonConvert.SerializeObject("采购申请单的采购类别必须相同。");
|
|
|
+ return JsonConvert.SerializeObject("要货令的供应类别必须相同。");
|
|
|
}
|
|
|
List<ic_item> ic_Items = _mysql_ic_item.GetListAsync(s => prlist.Select(c => c.icitem_id).Contains(s.Id)).Result;
|
|
|
PoActionListDto poaction = new PoActionListDto();
|
|
|
@@ -1369,6 +1395,7 @@ namespace Business.ResourceExamineManagement
|
|
|
|
|
|
if (poaction.poMasterList.Any())
|
|
|
{
|
|
|
+ poaction.poMasterList.ForEach(s => { s.ReqBy = "DO"; });
|
|
|
_purOrdMaster.Insert(poaction.poMasterList);
|
|
|
//快开平台用自增列RecId关联,所以需要插入后再查给明细表赋相应的值
|
|
|
List<string> nbrs = poaction.poMasterList.Select(a => a.PurOrd).ToList();
|
|
|
@@ -1384,8 +1411,8 @@ namespace Business.ResourceExamineManagement
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
unitOfWork.Dispose();
|
|
|
- new NLogHelper("ResourceExamineAppService").WriteLog("PrApprove", "采购申请单合并失败:" + e.Message, _currentTenant.Id.ToString());
|
|
|
- return JsonConvert.SerializeObject("合并失败,请联系管理员。");
|
|
|
+ new NLogHelper("ResourceExamineAppService").WriteLog("PrApprove", "要货令转采购订单失败:" + e.Message, _currentTenant.Id.ToString());
|
|
|
+ return JsonConvert.SerializeObject("要货令转采购订单失败,请联系管理员。");
|
|
|
}
|
|
|
}
|
|
|
return JsonConvert.SerializeObject("ok");
|
|
|
@@ -1496,6 +1523,7 @@ namespace Business.ResourceExamineManagement
|
|
|
if (newExm != null)
|
|
|
{
|
|
|
se.progress = "3";
|
|
|
+ se.rstate = 1;
|
|
|
se.sys_material_date = newExm.sys_material_date;
|
|
|
se.sys_capacity_date = newExm.sys_capacity_date;
|
|
|
//如果计算记录有工单id,则代表有生成工单,而不是占用计划工单
|
|
|
@@ -1535,8 +1563,9 @@ namespace Business.ResourceExamineManagement
|
|
|
moderlist = ObjectMapper.Map<List<mo_mes_morder>, List<mes_morder>>(WriteMorder);
|
|
|
|
|
|
List<RoutingOpDetail> allRoutings = _routingOpDetail.Select(p => moderlist.Select(m => m.product_code).Contains(p.RoutingCode));
|
|
|
+ List<b_bom_child_examine> childExamineList = _mysql_bom_child_examine.GetListAsync(c => exmResult.Select(x => x.Id).Contains(c.examine_id.GetValueOrDefault())).Result;
|
|
|
//同步工单
|
|
|
- CreateWorkOrdDates(moderlist, allRoutings, workOrds, workOrdRoutings, workOrdDetails);
|
|
|
+ CreateWorkOrdDates(moderlist, allRoutings, workOrds, workOrdRoutings, workOrdDetails, exmResult, childExamineList);
|
|
|
}
|
|
|
//当前订单号所关联的最新计算结果里的占用记录
|
|
|
List<mo_mes_mooccupy> mooccupyList = await _mes_mooccupy.GetListAsync(s => seIds.Contains(s.moo_id_billid.Value) && bangidList.Contains(s.bang_id.Value));
|
|
|
@@ -2033,7 +2062,7 @@ namespace Business.ResourceExamineManagement
|
|
|
podetail.netprice = item.pr_price;
|
|
|
podetail.netmoney = item.pr_aqty.GetValueOrDefault() * item.pr_price.GetValueOrDefault();
|
|
|
podetail.rate = item.pr_rate;
|
|
|
- podetail.price = item.pr_orderprice / item.pr_aqty;
|
|
|
+ podetail.price = item.pr_sysprice;
|
|
|
podetail.total_price = item.pr_orderprice;
|
|
|
podetail.taxamount = item.pr_orderprice.GetValueOrDefault() - podetail.netmoney;
|
|
|
podetail.plan_qty = item.pr_aqty;
|
|
|
@@ -2102,7 +2131,7 @@ namespace Business.ResourceExamineManagement
|
|
|
srm_Po_Occupy.GenerateNewId(help.NextId());
|
|
|
//srm_Po_Occupy.bang_id = bangid;
|
|
|
srm_Po_Occupy.morder_mo = c.pr_mono;
|
|
|
- srm_Po_Occupy.qty = c.pr_aqty;
|
|
|
+ srm_Po_Occupy.qty = c.pr_rqty;
|
|
|
srm_Po_Occupy.eid = c.sentry_id;
|
|
|
srm_Po_Occupy.polist_id = p.Id;
|
|
|
srm_Po_Occupy.polist_row = p.polist_row;
|
|
|
@@ -3704,7 +3733,7 @@ namespace Business.ResourceExamineManagement
|
|
|
/// </summary>
|
|
|
/// <param name="morders"></param>
|
|
|
/// <param name="allRoutings">工艺路线数据</param>
|
|
|
- public void CreateWorkOrdDates(List<mes_morder> morders, List<RoutingOpDetail> allRoutings, List<WorkOrdMaster> workOrds, List<WorkOrdRouting> workOrdRoutings, List<WorkOrdDetail> workOrdDetails)
|
|
|
+ public void CreateWorkOrdDates(List<mes_morder> morders, List<RoutingOpDetail> allRoutings, List<WorkOrdMaster> workOrds, List<WorkOrdRouting> workOrdRoutings, List<WorkOrdDetail> workOrdDetails, List<b_examine_result> exmResult, List<b_bom_child_examine> childExamineList)
|
|
|
{
|
|
|
//工单主表
|
|
|
WorkOrdMaster workOrd;
|
|
|
@@ -3755,7 +3784,41 @@ namespace Business.ResourceExamineManagement
|
|
|
workOrdRoutings.Add(woRouting);
|
|
|
}
|
|
|
|
|
|
- List<ProductStructureMaster> curStructures = GetProductStructure(item.product_code, workOrd.QtyOrded, item.factory_id.ToString());
|
|
|
+ var exm = exmResult.Find(s => s.morder_id == item.Id);
|
|
|
+ if (exm != null)
|
|
|
+ {
|
|
|
+ var childs = childExamineList.Where(s => s.examine_id == exm.Id).ToList();
|
|
|
+ if (childs.Any())
|
|
|
+ {
|
|
|
+ foreach (var structure in childs)
|
|
|
+ {
|
|
|
+ woDetail = workOrdDetails.Find(s => s.ItemNum == structure.item_number);
|
|
|
+ if (woDetail == null)
|
|
|
+ {
|
|
|
+ //添加工单的物料信息
|
|
|
+ woDetail = new WorkOrdDetail();
|
|
|
+ woDetail.Domain = item.factory_id.ToString();
|
|
|
+ woDetail.WorkOrd = item.morder_no;
|
|
|
+ woDetail.Op = structure.Op;
|
|
|
+ woDetail.ItemNum = structure.item_number;
|
|
|
+ woDetail.QtyRequired = structure.needCount.GetValueOrDefault();
|
|
|
+ woDetail.QtyPosted = 0m;
|
|
|
+ woDetail.QtyReturned = 0m;
|
|
|
+ woDetail.FrozenBOMQty = structure.needCount.GetValueOrDefault();
|
|
|
+ woDetail.Status = "";
|
|
|
+ woDetail.IsActive = true;
|
|
|
+ woDetail.CreateTime = DateTime.Now;
|
|
|
+ workOrdDetails.Add(woDetail);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ woDetail.QtyRequired += structure.needCount.GetValueOrDefault();
|
|
|
+ woDetail.FrozenBOMQty += structure.needCount.GetValueOrDefault();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /*List<ProductStructureMaster> curStructures = GetProductStructure(item.product_code, workOrd.QtyOrded, item.factory_id.ToString());
|
|
|
foreach (var structure in curStructures)
|
|
|
{
|
|
|
woDetail = workOrdDetails.Find(s => s.ItemNum == structure.ComponentItem);
|
|
|
@@ -3776,11 +3839,12 @@ namespace Business.ResourceExamineManagement
|
|
|
woDetail.CreateTime = DateTime.Now;
|
|
|
workOrdDetails.Add(woDetail);
|
|
|
}
|
|
|
- else {
|
|
|
+ else
|
|
|
+ {
|
|
|
woDetail.QtyRequired += structure.Qty;
|
|
|
woDetail.FrozenBOMQty += structure.Qty;
|
|
|
}
|
|
|
- }
|
|
|
+ }*/
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -3864,5 +3928,211 @@ namespace Business.ResourceExamineManagement
|
|
|
}
|
|
|
_productExamineAppService.CalcSuggestTime(sentrys, kittingTimes, icitemlist);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 替代方案保存
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<string> SubstituteSave(SubstituteDto dto)
|
|
|
+ {
|
|
|
+ ic_substitute stt;
|
|
|
+ if (dto.id == null)
|
|
|
+ {
|
|
|
+ if (_mysql_ic_substitute.GetListAsync(s => s.substitute_code == dto.scode).Result.Count > 0)
|
|
|
+ {
|
|
|
+ return "已存在【" + dto.scode + "】替代方案。";
|
|
|
+ }
|
|
|
+ var check = SubstituteSaveBeforCheck(dto);
|
|
|
+ if (check != "ok")
|
|
|
+ {
|
|
|
+ return check;
|
|
|
+ }
|
|
|
+ //新增
|
|
|
+ stt = new ic_substitute();
|
|
|
+ stt.GenerateNewId(help.NextId());
|
|
|
+ stt.substitute_code = dto.scode;
|
|
|
+ stt.substitute_mode = dto.smode;
|
|
|
+ stt.substitute_strategy = dto.sstrategy;
|
|
|
+ stt.create_by= dto.create_by;
|
|
|
+ stt.create_by_name= dto.create_by_name;
|
|
|
+ stt.create_time = DateTime.Now;
|
|
|
+ stt.update_by = dto.create_by;
|
|
|
+ stt.update_by_name = dto.create_by_name;
|
|
|
+ stt.update_time = DateTime.Now;
|
|
|
+ stt.tenant_id = dto.tenant_id;
|
|
|
+ stt.company_id = dto.company_id;
|
|
|
+ stt.factory_id = dto.factory_id;
|
|
|
+ List<ic_substitute_group> glist = new List<ic_substitute_group>();
|
|
|
+ List<ic_substitute_group_detail> dlist = new List<ic_substitute_group_detail>();
|
|
|
+ SubstituteSaveGenerate(dto, stt, glist, dlist);
|
|
|
+ using (var unitOfWork = _unitOfWorkManager.Begin(false, true))
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ _businessDbContext.BulkInsert(new List<ic_substitute> { stt });
|
|
|
+ if (glist.Any())
|
|
|
+ {
|
|
|
+ _businessDbContext.BulkInsert(glist);
|
|
|
+ }
|
|
|
+ if (dlist.Any())
|
|
|
+ {
|
|
|
+ _businessDbContext.BulkInsert(dlist);
|
|
|
+ }
|
|
|
+ await unitOfWork.CompleteAsync();
|
|
|
+ return "ok";
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ new NLogHelper("ResourceExamineAppService").WriteLog("SubstituteSave", "替代方案保存失败:" + e.Message, _currentTenant.Id.ToString());
|
|
|
+ unitOfWork.Dispose();
|
|
|
+ return "保存失败,请联系管理员。";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ //修改
|
|
|
+ stt = _mysql_ic_substitute.FirstAsync(s => s.Id == dto.id.Value).Result;
|
|
|
+ if (stt != null)
|
|
|
+ {
|
|
|
+ if (_mysql_ic_substitute.GetListAsync(s => s.Id != dto.id && s.substitute_code == dto.scode && s.company_id==dto.company_id && s.factory_id==dto.factory_id).Result.Count > 0)
|
|
|
+ {
|
|
|
+ return "已存在【" + dto.scode + "】替代方案。";
|
|
|
+ }
|
|
|
+ if (_ic_bom_child.GetListAsync(s => s.substitute_code == stt.substitute_code).Result.Count() > 0)
|
|
|
+ {
|
|
|
+ return "替代方案已被关联使用,不允许修改。";
|
|
|
+ }
|
|
|
+ var check = SubstituteSaveBeforCheck(dto);
|
|
|
+ if (check != "ok")
|
|
|
+ {
|
|
|
+ return check;
|
|
|
+ }
|
|
|
+ stt.substitute_code = dto.scode;
|
|
|
+ stt.substitute_mode = dto.smode;
|
|
|
+ stt.substitute_strategy = dto.sstrategy;
|
|
|
+ stt.update_by = dto.create_by;
|
|
|
+ stt.update_by_name = dto.create_by_name;
|
|
|
+ stt.update_time = DateTime.Now;
|
|
|
+ List<ic_substitute_group> glist = new List<ic_substitute_group>();
|
|
|
+ List<ic_substitute_group_detail> dlist = new List<ic_substitute_group_detail>();
|
|
|
+ SubstituteSaveGenerate(dto, stt, glist, dlist);
|
|
|
+
|
|
|
+ var delgList = _mysql_ic_substitute_group.GetListAsync(s => s.substitute_group_id == stt.Id).Result;
|
|
|
+ var deldList = _mysql_ic_substitute_group_detail.GetListAsync(s => delgList.Select(c => c.Id).Contains(s.substitute_group_id)).Result;
|
|
|
+
|
|
|
+ using (var unitOfWork = _unitOfWorkManager.Begin(false, true))
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ _businessDbContext.BulkUpdate(new List<ic_substitute> { stt });
|
|
|
+ if (delgList.Any())
|
|
|
+ {
|
|
|
+ await _mysql_ic_substitute_group.HardDeleteAsync(delgList);
|
|
|
+ }
|
|
|
+ if (deldList.Any())
|
|
|
+ {
|
|
|
+ await _mysql_ic_substitute_group_detail.HardDeleteAsync(deldList);
|
|
|
+ }
|
|
|
+ if (glist.Any())
|
|
|
+ {
|
|
|
+ _businessDbContext.BulkInsert(glist);
|
|
|
+ }
|
|
|
+ if (dlist.Any())
|
|
|
+ {
|
|
|
+ _businessDbContext.BulkInsert(dlist);
|
|
|
+ }
|
|
|
+ return "ok";
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ new NLogHelper("ResourceExamineAppService").WriteLog("SubstituteSave", "替代方案保存失败:" + e.Message, _currentTenant.Id.ToString());
|
|
|
+ unitOfWork.Dispose();
|
|
|
+ return "保存失败,请联系管理员。";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return "当前方案已被删除,请刷新重试。";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 校验
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public string SubstituteSaveBeforCheck(SubstituteDto dto)
|
|
|
+ {
|
|
|
+ if (!dto.srows.Any())
|
|
|
+ {
|
|
|
+ return "替代明细不能为空。";
|
|
|
+ }
|
|
|
+ if (dto.srows.Where(s => s.field_83817a9f5a15a4f78686105c694b0a39 == "是").Count() == 0)
|
|
|
+ {
|
|
|
+ return "请设置替代方案里的标准件。";
|
|
|
+ }
|
|
|
+ if (dto.srows.Where(s => s.field_83817a9f5a15a4f78686105c694b0a39 == "否").Count() == 0)
|
|
|
+ {
|
|
|
+ return "请设置替代方案里的替代件。";
|
|
|
+ }
|
|
|
+ if (dto.srows.Select(s => s.field_f8988ed2955a264f8f762faaed2c5f6a.GetValueOrDefault()).Count() <2)
|
|
|
+ {
|
|
|
+ return "替代方案最低存在两个优先级。";
|
|
|
+ }
|
|
|
+ //判断同一个优先级里,相同是否标准料
|
|
|
+ //dto.srows.GroupBy(i => new { i.field_f8988ed2955a264f8f762faaed2c5f6a.GetValueOrDefault(), i.field_83817a9f5a15a4f78686105c694b0a39.GetValueOrDefault(), })//.Where(g => g.Count() > 1).Count() > 0;
|
|
|
+ if (dto.srows.GroupBy(s => new { s.field_f8988ed2955a264f8f762faaed2c5f6a, s.field_83817a9f5a15a4f78686105c694b0a39 }).Where(g => g.Count() > 1).Count() > 0)
|
|
|
+ {
|
|
|
+ return "同优先级群组里不允许既有标准件又有替代件。";
|
|
|
+ }
|
|
|
+ return "ok";
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 组装数据
|
|
|
+ /// </summary>
|
|
|
+ public void SubstituteSaveGenerate(SubstituteDto dto, ic_substitute stt, List<ic_substitute_group> glist, List<ic_substitute_group_detail> dlist)
|
|
|
+ {
|
|
|
+ dto.srows.ForEach(s =>
|
|
|
+ {
|
|
|
+ ic_substitute_group g = glist.Where(x => x.order_num == s.field_f8988ed2955a264f8f762faaed2c5f6a.GetValueOrDefault()).FirstOrDefault();
|
|
|
+ if (g == null)
|
|
|
+ {
|
|
|
+ g = new ic_substitute_group();
|
|
|
+ g.GenerateNewId(help.NextId());
|
|
|
+ g.substitute_group_id = stt.Id;
|
|
|
+ g.substitute_code = stt.substitute_code;
|
|
|
+ g.replace_name = s.substitute_code;
|
|
|
+ g.order_num = s.field_f8988ed2955a264f8f762faaed2c5f6a.GetValueOrDefault();
|
|
|
+ g.main_material = s.field_83817a9f5a15a4f78686105c694b0a39 == "是" ? 1 : 0;
|
|
|
+ g.update_by = dto.create_by;
|
|
|
+ g.update_by_name = dto.create_by_name;
|
|
|
+ g.update_time = DateTime.Now;
|
|
|
+ g.tenant_id = dto.tenant_id;
|
|
|
+ g.company_id = dto.company_id;
|
|
|
+ g.factory_id = dto.factory_id;
|
|
|
+ glist.Add(g);
|
|
|
+ }
|
|
|
+ ic_substitute_group_detail d = new ic_substitute_group_detail();
|
|
|
+ d.GenerateNewId(help.NextId());
|
|
|
+ d.substitute_group_id = g.Id;
|
|
|
+ d.substitute_code = stt.substitute_code;
|
|
|
+ d.icitem_id = s.icitem_id.GetValueOrDefault();
|
|
|
+ d.icitem_number = s.icitem_number;
|
|
|
+ d.seq = s.seq;
|
|
|
+ d.replace_qty = s.replace_qty;
|
|
|
+ d.update_by = dto.create_by;
|
|
|
+ d.update_by_name = dto.create_by_name;
|
|
|
+ d.update_time = DateTime.Now;
|
|
|
+ d.tenant_id = dto.tenant_id;
|
|
|
+ d.company_id = dto.company_id;
|
|
|
+ d.factory_id = dto.factory_id;
|
|
|
+ dlist.Add(d);
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
}
|