啊鑫
18 小时以前 ed05efdc17aab076146b134ebe105b6382f221d7
MES.Service/service/WomcaaWWManager.cs
@@ -2,8 +2,6 @@
using MES.Service.Dto.webApi;
using MES.Service.Modes;
using SqlSugar;
using System;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
namespace MES.Service.service;
@@ -15,8 +13,8 @@
    private readonly WomcabManager _womcabWWManager = new();
    private decimal?[] decimals;
    private bool update;
    private bool insertOrUpdate;
    private bool update;
    public bool SaveList(List<ErpWOM> rohIns)
    {
@@ -39,7 +37,9 @@
                case "1":
                case "2":
                case "4":
                    return SaveOrUpdateDataWw(db, mesWomcaa, mesWomcabs) ? 1 : 0;
                    return SaveOrUpdateDataWw(db, mesWomcaa, mesWomcabs)
                        ? 1
                        : 0;
                case "5":
                    return UpdateData(db, mesWomcaa, mesWomcabs) ? 1 : 0;
                default:
@@ -48,16 +48,14 @@
            }
        }) > 0;
    }
    private bool UpdateData(SqlSugarScope db, Womcaa mesWomcaa, List<Womcab> mesWomcabs)
    private bool UpdateData(SqlSugarScope db, Womcaa mesWomcaa,
        List<Womcab> mesWomcabs)
    {
        if (mesWomcaa.Id != null)
        {
            base.DeleteById(mesWomcaa.Id);
        }
        if (mesWomcaa.Id != null) base.DeleteById(mesWomcaa.Id);
        if (mesWomcabs.Count > 0)
        {
            db.Deleteable<Womcab>().Where(s => s.Eid == mesWomcaa.Erpid).ExecuteCommand();
        }
            db.Deleteable<Womcab>().Where(s => s.Eid == mesWomcaa.Erpid)
                .ExecuteCommand();
        var orUpdate = base.Insert(mesWomcaa);
        var baOrUpdate = _womcabWWManager.InsertRange(mesWomcabs);
        db.Ado.CommitTran();
@@ -69,33 +67,33 @@
            var outParam1 = new SugarParameter("c_Result", null, true);
            var outParam2 = new SugarParameter("C_MSG", null, true);
            // 使用 SqlSugar 执行存储过程
            Db.Ado.ExecuteCommand("BEGIN PRC_UPDATE_DAA(:P_WORK_NO,:c_Result,:C_MSG); END;", inputParam1, outParam1, outParam2);
            Db.Ado.ExecuteCommand(
                "BEGIN PRC_UPDATE_DAA(:P_WORK_NO,:c_Result,:C_MSG); END;",
                inputParam1, outParam1, outParam2);
            // 获取输出参数的值
            int result = int.Parse((string)outParam1.Value);
            string message = outParam2.Value == DBNull.Value ? string.Empty : (string)outParam2.Value;
            var result = int.Parse((string)outParam1.Value);
            var message = outParam2.Value == DBNull.Value
                ? string.Empty
                : (string)outParam2.Value;
            if (result == 1)
            {
                //存储过程失败则事务进行回滚
                //db.Ado.RollbackTran();
                throw new Exception(message);
            }
            // 提交事务
            //db.Ado.CommitTran();
            return true;
        }
        throw new NotImplementedException("插入或更新失败");
    }
    private bool SaveOrUpdateDataWw(SqlSugarScope db, Womcaa mesWomcaa, List<Womcab> mesWomcabss)
    private bool SaveOrUpdateDataWw(SqlSugarScope db, Womcaa mesWomcaa,
        List<Womcab> mesWomcabss)
    {
        if (mesWomcaa.Id != null)
        {
            base.DeleteById(mesWomcaa.Id);
        }
        if (mesWomcaa.Id != null) base.DeleteById(mesWomcaa.Id);
        if (mesWomcabss.Count > 0)
        {
            db.Deleteable<Womcab>().Where(s => s.Eid == mesWomcaa.Erpid).ExecuteCommand();
        }
            db.Deleteable<Womcab>().Where(s => s.Eid == mesWomcaa.Erpid)
                .ExecuteCommand();
        var orUpdate = base.Insert(mesWomcaa);
        var baOrUpdate = _womcabWWManager.InsertRange(mesWomcabss);
        db.Ado.CommitTran();
@@ -107,16 +105,18 @@
            var outParam1 = new SugarParameter("c_Result", null, true);
            var outParam2 = new SugarParameter("C_MSG", null, true);
            // 使用 SqlSugar 执行存储过程
            Db.Ado.ExecuteCommand("BEGIN PRC_UPDATE_DAA(:P_WORK_NO,:c_Result,:C_MSG); END;", inputParam1, outParam1, outParam2);
            Db.Ado.ExecuteCommand(
                "BEGIN PRC_UPDATE_DAA(:P_WORK_NO,:c_Result,:C_MSG); END;",
                inputParam1, outParam1, outParam2);
            // 获取输出参数的值
            int result = int.Parse((string)outParam1.Value);
            string message = outParam2.Value == DBNull.Value ? string.Empty : (string)outParam2.Value;
            var result = int.Parse((string)outParam1.Value);
            var message = outParam2.Value == DBNull.Value
                ? string.Empty
                : (string)outParam2.Value;
            if (result == 1)
            {
                //存储过程失败则事务进行回滚
                //db.Ado.RollbackTran();
                throw new Exception(message);
            }
            // 提交事务
            //db.Ado.CommitTran();
            return true;
@@ -125,19 +125,22 @@
        throw new NotImplementedException("插入或更新失败");
    }
    private bool DeleteData(SqlSugarScope db, Womcaa mesWomcaa,List<Womcab> mesWomcabs)
    private bool DeleteData(SqlSugarScope db, Womcaa mesWomcaa,
        List<Womcab> mesWomcabs)
    {
        if (mesWomcaa.Id != null)
        {
            decimals = mesWomcabs.Select(s => s.Id).ToArray();
            update = base.DeleteById(mesWomcaa.Id);
            insertOrUpdate = db.Deleteable<Womcab>().In(decimals).ExecuteCommand() > 0;
            insertOrUpdate =
                db.Deleteable<Womcab>().In(decimals).ExecuteCommand() > 0;
        }
        else
        {
            update = true;
            insertOrUpdate = true;
        }
        if (update && insertOrUpdate) return true;
        throw new NotImplementedException("更新失败");
    }
@@ -202,13 +205,9 @@
            FinishedProduct = dto.FinishedProduct
        };
        if (dto.Type == "5")
        {
            entity.IsXg = 1;
        }
        else
        {
            entity.IsXg = 0;
        }
        if (dto.FStatus == "6" || dto.FStatus == "7")
        {
@@ -253,10 +252,11 @@
                Denominator = Convert.ToDecimal(dto.FDenominator),
                SCRAPQTY = Convert.ToDecimal(dto.FFixScrapQty),
                SCRAPRATE = Convert.ToDecimal(dto.FScrapRate),
                SalesOrder = dto.F_WWC_TEXT,
                SalesOrder = dto.F_WWC_TEXT
            };
            var entity = Db.Queryable<Womcab>().Where(s => s.Erpid == womcab.Erpid).Single();
            var entity = Db.Queryable<Womcab>()
                .Where(s => s.Erpid == womcab.Erpid).Single();
            if (entity != null) womcab.Id = entity.Id;
            womcabList.Add(womcab);