tangdi 2 лет назад
Родитель
Сommit
86161678f1

+ 69 - 0
MicroServices/Business/Business.Application.Contracts/Dto/BindingSubstituteDto.cs

@@ -0,0 +1,69 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Business.Dto
+{
+    public class BindingSubstituteDto
+    {
+        /// <summary>
+        /// BOM主键
+        /// </summary>
+        public long id { get; set; }
+
+        /// <summary>
+        /// 替代方案编码
+        /// </summary>
+        public string bom_number { get; set; }
+
+        /// <summary>
+        /// bom明细
+        /// </summary>
+        public List<BomDetails> bomDetail { get; set; }
+
+        /// <summary>
+        /// 租户ID
+        /// </summary>
+        public long? tenant_id { get; set; }
+
+        /// <summary>
+        /// 公司ID
+        /// </summary>
+        public long? company_id { get; set; }
+
+        /// <summary>
+        /// 工厂ID
+        /// </summary>
+        public long? factory_id { get; set; }
+
+        // <summary>
+        /// 用户id
+        /// </summary>
+        public long create_by { get; set; }
+
+        // <summary>
+        /// 用户名称
+        /// </summary>
+        public string create_by_name { get; set; }
+    }
+
+    public class BomDetails
+    {
+        /// <summary>
+        /// 替代明细主键
+        /// </summary>
+        public long? id { get; set; }
+
+        /// <summary>
+        /// 替代料编码
+        /// </summary>
+        public string icitem_number { get; set; }
+
+        /// <summary>
+        /// 替代方案
+        /// </summary>
+        public string substitute_code { get; set; }
+    }
+}

+ 7 - 0
MicroServices/Business/Business.Application.Contracts/ResourceExamineManagement/IResourceExamineAppService.cs

@@ -112,5 +112,12 @@ namespace Business.ResourceExamineManagement
         /// <returns></returns>
         Task<string> SubstituteSave(SubstituteDto dto);
 
+        /// <summary>
+        /// BOM¹ØÁªÌæ´ú·½°¸
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        Task<string> BindingSubstitute(BindingSubstituteDto dto);
+
     }
 }

+ 61 - 5
MicroServices/Business/Business.Application/ResourceExamineManagement/ResourceExamineAppService.cs

@@ -3768,7 +3768,7 @@ namespace Business.ResourceExamineManagement
                 var exm = exmResult.Find(s => s.morder_id == item.Id);
                 if (exm != null)
                 {
-                    var childs = childExamineList.Where(s => s.examine_id == exm.Id).ToList();
+                    var childs = childExamineList.Where(s => s.examine_id == exm.Id && s.is_use == true).ToList();
                     List<b_bom_child_examine> returnList = new List<b_bom_child_examine>();
                     GetWorkDetalis(childs.Where(s => s.level == 2).ToList(), returnList, childs);
                     if (returnList.Any())
@@ -4000,7 +4000,7 @@ namespace Business.ResourceExamineManagement
                     {
                         return "已存在【" + dto.scode + "】替代方案。";
                     }
-                    if (_ic_bom_child.GetListAsync(s => s.substitute_code == stt.substitute_code).Result.Count() > 0)
+                    if (_mysql_ic_bom_child.GetListAsync(s => s.substitute_code == stt.substitute_code).Result.Count() > 0)
                     {
                         return "替代方案已被关联使用,不允许修改。";
                     }
@@ -4084,11 +4084,17 @@ namespace Business.ResourceExamineManagement
                 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)
+            foreach (var r in dto.srows)
             {
-                return "同优先级群组里不允许既有标准件又有替代件。";
+                if (dto.srows.Where(s => s.field_f8988ed2955a264f8f762faaed2c5f6a == r.field_f8988ed2955a264f8f762faaed2c5f6a && s.field_83817a9f5a15a4f78686105c694b0a39 != r.field_83817a9f5a15a4f78686105c694b0a39).Count() > 0)
+                {
+                    return "同优先级群组里不允许既有标准件又有替代件。";
+                }
             }
+            /*if (dto.srows.GroupBy(s => new { s.field_f8988ed2955a264f8f762faaed2c5f6a, s.field_83817a9f5a15a4f78686105c694b0a39 }).Where(g => g.Count() > 1).Count() > 0)
+            {
+                return "同优先级群组里不允许既有标准件又有替代件。";
+            }*/
             return "ok";
         }
 
@@ -4155,5 +4161,55 @@ namespace Business.ResourceExamineManagement
             await _productionScheduleAppService.DoProductSchedule(workOrds, domain, 2);
             return "ok";
         }
+
+        /// <summary>
+        /// BOM关联替代方案
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        public async Task<string> BindingSubstitute(BindingSubstituteDto dto)
+        {
+            var list = _mysql_ic_bom_child.GetListAsync(s => s.bom_id == dto.id && s.tenant_id == dto.tenant_id && s.company_id == dto.company_id && s.factory_id == dto.factory_id).Result;
+
+            if (dto.bomDetail.Any())
+            {
+                list.ForEach(s => { s.substitute_code = ""; s.haveicsubs = 0; });
+                var codeList = dto.bomDetail.Where(s => string.IsNullOrEmpty(s.substitute_code) == false).Select(x => x.substitute_code).Distinct().ToList();
+                if (codeList.Any())
+                {
+                    var subGdtls = _mysql_ic_substitute_group.GetListAsync(s => s.tenant_id == dto.tenant_id && s.company_id == dto.company_id && s.factory_id == dto.factory_id && codeList.Contains(s.substitute_code)).Result;
+                    var subDetalis = _mysql_ic_substitute_group_detail.GetListAsync(s => s.tenant_id == dto.tenant_id && s.company_id == dto.company_id && s.factory_id == dto.factory_id && codeList.Contains(s.substitute_code)).Result;
+                    foreach (var code in codeList)
+                    {
+                        var g = subGdtls.Find(s => s.substitute_code == code && s.main_material == 1);
+                        if (g != null)
+                        {
+                            var dtls = subDetalis.Where(s => s.substitute_group_id == g.Id).ToList();
+                            foreach (var dtl in dtls)
+                            {
+                                var l = list.Find(s => s.item_number == dtl.icitem_number && s.qty == dtl.replace_qty);
+                                if (l == null)
+                                {
+                                    return "当前替代方案【" + code + "】的标准件未找到相同数量相同物料的BOM明细。";
+                                }
+                                if (string.IsNullOrEmpty(l.substitute_code))
+                                {
+                                    l.haveicsubs = 1;
+                                    l.substitute_code = code;
+                                }
+                                else {
+                                    return "当前替代方案【" + code + "】的标准件【"+l.item_number+"】与替代方案【"+ l.substitute_code + "】冲突。";
+                                }
+                            }
+                        }
+                        else {
+                            return "当前替代方案【"+ code + "】未设置标准件。";
+                        }
+                    }
+                }
+                await _mysql_ic_bom_child.UpdateManyAsync(list);
+            }
+            return "ok";
+        }
     }
 }

+ 12 - 0
MicroServices/Business/Business.HttpApi/Controllers/ResourceExamineController.cs

@@ -193,5 +193,17 @@ namespace Business.Controllers
         {
             return _ResourceExamineAppService.SubstituteSave(dto);
         }
+
+        /// <summary>
+        /// BOM关联替代方案
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [Route("BindingSubstitute")]
+        public Task<string> BindingSubstitute(BindingSubstituteDto dto)
+        {
+            return _ResourceExamineAppService.BindingSubstitute(dto);
+        }
     }
 }