快乐的昕的电脑
2 天以前 8684d3db5566311dcf7631b5da52ca3bc2228423
采购订单、生产订单优化:优化
已修改3个文件
149 ■■■■ 文件已修改
MES.Service/service/BasicData/MesRohInManager.cs 99 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MES.Service/service/WomcaaManager.cs 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MESApplication/Controllers/BasicData/MesRohInController.cs 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MES.Service/service/BasicData/MesRohInManager.cs
@@ -1,4 +1,5 @@
using Masuit.Tools;
using AngleSharp.Dom;
using Masuit.Tools;
using MES.Service.DB;
using MES.Service.Dto.webApi;
using MES.Service.Modes;
@@ -70,17 +71,17 @@
    // 插入或更新数据的方法
    private bool SaveOrUpdateData(SqlSugarScope db, MesRohIn mesRohIn,List<MesRohInData> mesRohInDatas, string type)
    {
        ////传什么,c就改成什么
        //传什么,c就改成什么
        //if (type == "3" || (mesRohIn.DocumentStatus != null && mesRohIn.DocumentStatus != "C"))//C表示已审核状态
        //{
        //    mesRohIn.BillNo = mesRohIn.BillNo + "F" + mesRohIn.EbelnK3id.ToString();
        //}
        //传什么,c就改成什么
        if (type == "3" || (mesRohIn.DocumentStatus != null && mesRohIn.DocumentStatus != "Y"))//Y表示已审核状态
        {
            mesRohIn.BillNo = mesRohIn.BillNo + "F" + mesRohIn.EbelnK3id.ToString();
        }
        ////传什么,c就改成什么
        //if (type == "3" || (mesRohIn.DocumentStatus != null && mesRohIn.DocumentStatus != "Y"))//Y表示已审核状态
        //{
        //    mesRohIn.BillNo = mesRohIn.BillNo + "F" + mesRohIn.EbelnK3id.ToString();
        //}
        if (mesRohIn.Guid != null)
            db.Deleteable<MesRohIn>().Where(s => s.Guid == mesRohIn.Guid)
@@ -138,13 +139,31 @@
        mesRohIn.EbelnK3id = eid;
        mesRohIn.BillNo = rohIn.FBillNo;
        mesRohIn.DocumentStatus = rohIn.FDocumentStatus;
        mesRohIn.DocumentType = rohIn.FBillTypeID;
        mesRohIn.BusinessType = rohIn.FBusinessType;
        ////erp传过来的Y->C,表示审核。N->A。(与金蝶逻辑保持一致)
        //mesRohIn.DocumentStatus = rohIn.FDocumentStatus;
        //erp传过来的Y->C,表示审核。N->A。(与金蝶逻辑保持一致)
        if (string.IsNullOrEmpty(rohIn.FDocumentStatus))
        {
            mesRohIn.DocumentStatus = "A";
        }
        else
        {
            mesRohIn.DocumentStatus = rohIn.FDocumentStatus == "Y" ? "C" : "A";
        }
        if (rohIn.FDate != null)
            mesRohIn.PurchaseDate = DateTime.ParseExact(rohIn.FDate,
                "yyyy-MM-dd HH:mm:ss", null);
        //供应商编码转ID
        var mesRohInSupplier = Db.Queryable<MesSupplier>()
@@ -177,10 +196,6 @@
        if (!string.IsNullOrWhiteSpace(mesRohInPurchaseDept))
        {
            mesRohIn.PurchaseDept = mesRohInPurchaseDept;
        }
        else if (!string.IsNullOrWhiteSpace(rohIn.FPurchaseDeptId))
        {
            mesRohIn.PurchaseDept = rohIn.FPurchaseDeptId;
        }
        else
        {
@@ -330,6 +345,21 @@
                SalesOrderId = s.F_UNW_Text_xsddh
            };
            //库存单位编码转ID
            //InventoryUnit = s.FStockUnitID,
            var entityInventoryUnit = Db.Queryable<MesUnit>()
                .Where(x => x.Fnumber == s.FUnitId)
                .Select(x => x.Id.ToString())
                .First();
            if (!string.IsNullOrWhiteSpace(entityInventoryUnit))
            {
                entity.InventoryUnit = entityInventoryUnit;
            }
            else
            {
                entity.InventoryUnit = "0";
            }
            //采购单位编码转ID
            var entityPurchaseUnit = Db.Queryable<MesUnit>()
                .Where(x => x.Fnumber == s.FUnitId)
@@ -338,10 +368,6 @@
            if (!string.IsNullOrWhiteSpace(entityPurchaseUnit))
            {
                entity.PurchaseUnit = entityPurchaseUnit;
            }
            else if (!string.IsNullOrWhiteSpace(s.FUnitId))
            {
                entity.PurchaseUnit = s.FUnitId;
            }
            else
            {
@@ -357,10 +383,6 @@
            {
                entity.PricingUnit = entityPricingUnit;
            }
            else if (!string.IsNullOrWhiteSpace(s.FPriceUnitId))
            {
                entity.PricingUnit = s.FPriceUnitId;
            }
            else
            {
                entity.PricingUnit = "0";
@@ -374,10 +396,6 @@
            if (!string.IsNullOrWhiteSpace(entityItemId))
            {
                entity.ItemId = entityItemId;
            }
            else if (!string.IsNullOrWhiteSpace(s.FMaterialId))
            {
                entity.ItemId = s.FMaterialId;
            }
            else
            {
@@ -414,7 +432,7 @@
            }
            //查询EbelnK3id对应的Guid,赋值给entity.Guid。实现主键复用
            var single = rohInDataManager.GetSingle(it =>it.EbelnK3id == entity.EbelnK3id);
            var single = rohInDataManager.GetSingle(it => it.EbelnK3id == entity.EbelnK3id);
            if (single != null) entity.Guid = single.Guid;
            return entity;
@@ -446,14 +464,29 @@
    {
        try
        {
            // 替换为:
            // 获取当前表中已存在的最大 EBELN_K3ID
            //var maxId = Db.Queryable<MesRohInData>().Max(x => (decimal?)x.EbelnK3id) ?? 0m;
            // 先取一个序列值
            var sequenceValueObj = Db.Ado.GetScalar("SELECT NEXT VALUE FOR MES_ROH_IN_DATA_seq");
            var sequenceValue = Convert.ToDecimal(sequenceValueObj);
            // 验证序列值是否有效
            if (sequenceValue <= 0)
            {
                throw new InvalidOperationException($"数据库序列 MES_ROH_IN_DATA_seq 返回了无效的值: {sequenceValue}");
            }
            //// 如果序列值落后于当前最大ID,持续获取直到超过 maxId
            //while (sequenceValue <= maxId || Db.Queryable<MesRohInData>().Where(x => x.EbelnK3id == sequenceValue).Any())
            //{
            //    sequenceValueObj = Db.Ado.GetScalar("SELECT NEXT VALUE FOR MES_ROH_IN_DATA_seq");
            //    sequenceValue = Convert.ToDecimal(sequenceValueObj);
            //    if (sequenceValue <= 0)
            //    {
            //        throw new InvalidOperationException($"数据库序列 MES_ROH_IN_DATA_seq 连续返回无效的值: {sequenceValue}");
            //    }
            //}
            return sequenceValue;
        }
@@ -474,6 +507,8 @@
    /// <returns>被删除的单号</returns>
    public (int outSum, string outMsg) Delete(string FBillNo, string FBillTypeID)
    {
        try
        {
        var outMsg = string.Empty;
        var outSum = 0;
@@ -488,9 +523,13 @@
        Db.Ado.UseStoredProcedure().ExecuteCommand("ERP_DeleteMesRohInByBillNo", parameters);
        outMsg = parameters[2].Value?.ToString() ?? "";
        outSum = parameters[3].Value != null ? Convert.ToInt32(parameters[2].Value) : -1;
        return (outSum, outMsg);
        outSum = parameters[3].Value != null ? Convert.ToInt32(parameters[index: 3].Value) : -1;
            return (outSum, outMsg);
        }
        catch (Exception ex)
        {
            throw new InvalidOperationException($"调用存储过程 ERP_DeleteMesRohInByBillNo 失败: {ex.Message}", ex);
        }
    }
MES.Service/service/WomcaaManager.cs
@@ -65,10 +65,30 @@
        if (StringUtil.CheckGuid(mesWomcaa.Guid))
            base.DeleteById(mesWomcaa.Guid);
        //if (mesWomcabs.Count > 0)
        //    db.Deleteable<Womcab>()
        //        .Where(s => s.Pid == mesWomcaa.Erpid).ExecuteCommand();
        // 在插入 mesWomcabs 之前,先删除所有 Guid 已存在的记录
        //var guids = mesWomcabs.Select(x => x.Guid).ToList();
        //if (guids.Count > 0)
        //{
        //    db.Deleteable<Womcab>().In(x => x.Guid, guids).ExecuteCommand();
        //}
        if (mesWomcabs.Count > 0)
        {
            // 先按 Pid 删除
            db.Deleteable<Womcab>()
                .Where(s => s.Pid == mesWomcaa.Erpid).ExecuteCommand();
            //    // 再按 Guid 删除,彻底避免主键冲突
            //    var guids = mesWomcabs.Select(x => x.Guid).ToList();
            //    db.Deleteable<Womcab>().In(x => x.Guid, guids).ExecuteCommand();
        }
        //// 检查 Guid 是否唯一
        //if (mesWomcabs.Select(x => x.Guid).Distinct().Count() != mesWomcabs.Count)
        //    throw new Exception("即将插入的Womcab数据中存在重复的Guid,请检查数据生成逻辑。");
        //单条插入忽略空字段
        var orUpdate = db.Insertable(mesWomcaa)
@@ -291,11 +311,12 @@
            }
            var entity = Db.Queryable<Womcab>()
                .Where(s => s.Eid == womcab.Eid).Single();
                .Where(s => s.Cab001 == womcab.Cab001 && s.Cab002 == womcab.Cab002 && s.Cab003 == womcab.Cab003)
                .Single();
            if (entity != null)
                womcab.Guid = entity.Guid;
            else
                womcab.Guid = Guid.NewGuid();
                womcab.Guid = Guid.NewGuid(); // 确保每条新数据唯一
            womcabList.Add(womcab);
        }
MESApplication/Controllers/BasicData/MesRohInController.cs
@@ -263,6 +263,13 @@
    [HttpPost("Delete")]
    public ResponseResult Delete([FromBody] DeleteRequestDto data)
    {
        var entity = new MessageCenter();
        entity.TableName = TableName;
        entity.Url = URL + "Delete";
        entity.Method = METHOD;
        entity.Data = JsonConvert.SerializeObject(data);
        entity.Status = 1;
        entity.CreateBy = "PL017";
        try
        {
            dynamic resultInfos = new ExpandoObject();
@@ -270,14 +277,30 @@
            var (outSum, outMsg) = m.Delete(data.FBillNo,data.FBillTypeID);
            resultInfos.OutSum = outSum;
            resultInfos.OutMsg = outMsg;
            entity.Result = 0;
            if (resultInfos.OutSum==1) entity.Result = 1;
            entity.DealWith = 1;
            _manager.save(entity);
            return new ResponseResult
            {
                status = outSum,
                //status = outSum,
                status = 0,
                message = outMsg,
            };
        }
        catch (Exception ex)
        {
            entity.Result = 0;
            entity.DealWith = 0;
            entity.ResultData = ex.Message;
            _manager.save(entity);
            return ResponseResult.ResponseError(ex);
        }
    }