wxw
2025-10-26 17a6a93088a9bc551641c1431e4f70cc9f78813d
Wms/WMS.BLL/BllAsnServer/ArrivalNoticeServer.cs
@@ -275,7 +275,7 @@
            try
            {
                if (model.Origin == "录入")
                if (model.Origin == "录入" || model.Origin == "导入")
                {
                    model.ASNNo = new Common().GetMaxNo("ASN");
                }
@@ -290,6 +290,7 @@
                        throw new Exception("单据类型不可为空!");
                    }
                }
                
                lock (AsnLock)
                {
@@ -409,25 +410,48 @@
                        }
                        string lot1 = detailModel.Lot1;
                        string lot2 = detailModel.Lot2;
                        if (sku.IsInspect == "0")//是否免检,0:否 1:是
                        //if (sku.IsControlled == "0")//是否请验,0:是 1:否
                        //{
                        //    //需要请验物料 生产日期、有效期不能为空
                        //    DateTime lot12;
                        //    DateTime lot22;
                        //    if (!DateTime.TryParse(detailModel.Lot1, out lot12))
                        //    {
                        //        throw new Exception("需要请验物料生产日期转换失败");
                        //    }
                        //    if (!DateTime.TryParse(detailModel.Lot2, out lot22))
                        //    {
                        //        throw new Exception("需要请验料过期日期转换失败");
                        //    }
                        //    lot1 = lot12.ToString("yyyy-MM-dd");
                        //    lot2 = lot22.ToString("yyyy-MM-dd");
                        //}
                        if (!string.IsNullOrEmpty(lot1))
                        {
                            //不免检物料 生产日期、有效期不能为空
                            DateTime lot12;
                            DateTime lot22;
                            if (!DateTime.TryParse(detailModel.Lot1, out lot12))
                            {
                                throw new Exception("不免检物料生产日期转换失败");
                                throw new Exception("需要请验物料生产日期转换失败");
                            }
                            if (!DateTime.TryParse(detailModel.Lot2, out lot22))
                            {
                                throw new Exception("不免检物料过期日期转换失败");
                            }
                            lot1 = lot12.ToString();
                            lot2 = lot22.ToString();
                            lot1 = lot12.ToString("yyyy-MM-dd");
                        }
                        if (!string.IsNullOrEmpty(lot2))
                        {
                            DateTime lot22;
                            if (!DateTime.TryParse(detailModel.Lot1, out lot22))
                            {
                                throw new Exception("需要请验物料生产日期转换失败");
                            }
                            lot2 = lot22.ToString("yyyy-MM-dd");
                        }
                        if (string.IsNullOrWhiteSpace(detailModel.PackagNo))
                        {
                            throw new Exception("包装不能为空");
                            detailModel.PackagNo = sku.PackagNo;
                            if (string.IsNullOrWhiteSpace(detailModel.PackagNo))
                            {
                                throw new Exception("包装不能为空");
                            }
                        }
                        // 计算出总金额
                        detailModel.Money = detailModel.Price * detailModel.Qty;
@@ -436,7 +460,7 @@
                            ASNNo = model.ASNNo,
                            SkuNo = detailModel.SkuNo,
                            SkuName = detailModel.SkuName,
                            Standard = detailModel.Standard,
                            Standard = sku.Standard,
                            LotNo = detailModel.LotNo == null ? "" : detailModel.LotNo.Trim(),
                            LotText = detailModel.LotText,
                            Qty = (decimal)detailModel.Qty,
@@ -493,6 +517,64 @@
                        return "-2:添加失败数据回滚!";
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        //导入入库单据
        public string ImportArrivalNotice(ArrivalNoticeVms models)
        {
            string strMessage = "";
            try
            {
                if (models.ListArrivalNotice.Count <= 0)
                {
                    strMessage = "-1:文件内无数据请核实!";
                }
                var num = 0;
                int CreateUser = Convert.ToInt32(models.CreateUser);
                List<string> noticeList = new List<string>();
                foreach (ArrivalNoticeVm model in models.ListArrivalNotice)
                {
                    try
                    {
                        model.CreateUser = models.CreateUser;
                        model.Origin = "导入";
                        var msg = AddArrivalNotice(model);
                        strMessage += msg;
                        if (msg == "")
                        {
                            num += 1;
                            var hasBoxItem = noticeList.Exists(x => x == model.ASNNo);
                            if (!hasBoxItem)
                            {
                                noticeList.Add(model.ASNNo);
                            }
                        }
                    }
                    catch(Exception ex)
                    {
                        throw new Exception($"物料编码:{model.AsnDetail[0].SkuNo},物料名称:{model.AsnDetail[0].SkuName},导入失败:"+ex.Message);
                        // ignored
                    }
                }
                if (num > 0)
                {
                    new OperationASNServer().AddLogOperationAsn("入库作业", "入库单据", $"共导入了{noticeList.Count}条单据", "导入", $"共导入了{noticeList.Count}条单据", CreateUser);
                }
                if (strMessage.Contains("-1") && num > 0)
                {
                    return "部分导入成功" + strMessage;
                }
                if (num > 0)
                {
                    return "导入成功" + strMessage;
                }
                return strMessage;
            }
            catch (Exception ex)
            {
@@ -577,47 +659,67 @@
                        // 2. 将字符串类型的IsControlled转换为bool(根据实际取值规则调整)
                        // 比如:"1"表示受控,"0"表示不受控;或"True"/"False";或"是"/"否"
                        bool isControlled;
                        if (!bool.TryParse(material.IsControlled, out isControlled))
                        {
                            // 处理非标准格式(如"1"/"0")
                            isControlled = material.IsControlled == "1" ||
                                           string.Equals(material.IsControlled, "是", StringComparison.OrdinalIgnoreCase);
                        }
                        //bool isControlled;
                        //if (!bool.TryParse(material.IsControlled, out isControlled))
                        //{
                        //    // 处理非标准格式(如"1"/"0")
                        //    isControlled = material.IsControlled == "1" ||
                        //                   string.Equals(material.IsControlled, "是", StringComparison.OrdinalIgnoreCase);
                        //}
                        // 3. 根据受控状态验证日期
                        if (isControlled)
                        //if (material.IsControlled=="0")
                        //{
                        //    // 受控状态:生产日期必填
                        //    if (string.IsNullOrWhiteSpace(detailModel.Lot1))
                        //        return $"-1:物料{detailModel.SkuNo}为需请验物料,生产日期不可为空;";
                        //    // 受控状态:过期日期必填
                        //    if (string.IsNullOrWhiteSpace(detailModel.Lot2))
                        //        return $"-1:物料{detailModel.SkuNo}为需请验物料,过期日期不可为空;";
                        //    // 验证日期格式有效性
                        //    if (!DateTime.TryParse(detailModel.Lot1, out DateTime productionDate))
                        //        return $"-1:物料{detailModel.SkuNo}的生产日期格式错误,请使用有效日期格式;";
                        //    if (!DateTime.TryParse(detailModel.Lot2, out DateTime expiryDate))
                        //        return $"-1:物料{detailModel.SkuNo}的过期日期格式错误,请使用有效日期格式;";
                        //    // 验证过期日期不能早于生产日期
                        //    if (expiryDate <= productionDate)
                        //        return $"-1:物料{detailModel.SkuNo}的过期日期不能早于生产日期;";
                        //}
                        if (!string.IsNullOrEmpty(detailModel.Lot1))
                        {
                            // 受控状态:生产日期必填
                            if (string.IsNullOrWhiteSpace(detailModel.Lot1))
                                return $"-1:物料{detailModel.SkuNo}为受控物料,生产日期不可为空;";
                            // 受控状态:过期日期必填
                            if (string.IsNullOrWhiteSpace(detailModel.Lot2))
                                return $"-1:物料{detailModel.SkuNo}为受控物料,过期日期不可为空;";
                            // 验证日期格式有效性
                            if (!DateTime.TryParse(detailModel.Lot1, out DateTime productionDate))
                                return $"-1:物料{detailModel.SkuNo}的生产日期格式错误,请使用有效日期格式;";
                            if (!DateTime.TryParse(detailModel.Lot2, out DateTime expiryDate))
                                return $"-1:物料{detailModel.SkuNo}的过期日期格式错误,请使用有效日期格式;";
                            // 验证过期日期不能早于生产日期
                            if (expiryDate <= productionDate)
                                return $"-1:物料{detailModel.SkuNo}的过期日期不能早于生产日期;";
                            DateTime lot12;
                            if (!DateTime.TryParse(detailModel.Lot1, out lot12))
                            {
                                throw new Exception("需要请验物料生产日期转换失败");
                            }
                            detailModel.Lot1 = lot12.ToString("yyyy-MM-dd");
                        }
                        if (!string.IsNullOrEmpty(detailModel.Lot2))
                        {
                            DateTime lot22;
                            if (!DateTime.TryParse(detailModel.Lot1, out lot22))
                            {
                                throw new Exception("需要请验物料生产日期转换失败");
                            }
                            detailModel.Lot2 = lot22.ToString("yyyy-MM-dd");
                        }
                        // 不受控状态:日期非必填,无需验证
                        // 原有批次相关验证(保留)
                        if (TypeLot.Contains(model.Type))
                        {
                            if (string.IsNullOrWhiteSpace(detailModel.Lot1))
                                throw new Exception("生产日期不可为空!");
                        //if (TypeLot.Contains(model.Type))
                        //{
                        //    if (string.IsNullOrWhiteSpace(detailModel.Lot1))
                        //        throw new Exception("生产日期不可为空!");
                            if (string.IsNullOrWhiteSpace(detailModel.Lot2))
                                throw new Exception("过期日期不可为空!");
                        }
                        //    if (string.IsNullOrWhiteSpace(detailModel.Lot2))
                        //        throw new Exception("过期日期不可为空!");
                        //}
                        // 验证物料和批次号是否重复
                        if (dbDetailModels.Any(m => m.SkuNo == detailModel.SkuNo
@@ -630,7 +732,7 @@
                        // 处理价格默认值
                        detailModel.Price ??= 0;
                        detailModel.BoxCodeStr = detailModel.LotNo;
                        // 生成箱码(自有批次逻辑)
                        if (detailModel.Id == 0 || detailModel.Id == null || string.IsNullOrWhiteSpace(detailModel.LotNo))
                        {