kazelee
2025-07-05 59dc2aa6e3fe7f699c4f2d03b774763142c5698d
api/ApiHelper.cs
@@ -9,6 +9,8 @@
using HH.WCS.Mobox3.AnGang.util;
using HH.WCS.Mobox3.AnGang.wms;
using Newtonsoft.Json;
using static HH.WCS.Mobox3.AnGang.api.ApiModel;
using static HH.WCS.Mobox3.AnGang.api.OtherModel;
@@ -30,7 +32,7 @@
                var startLoc = db.Queryable<TN_Location>()
                    .Where(a => a.S_CODE == model.StartLoc)
                    .Where(a => a.N_LOCK_STATE == 0 && a.S_LOCK_STATE == "无" && a.C_ENABLE == "Y")
                    //.Where(a => a.N_CURRENT_NUM == 0)
                    .Where(a => a.N_CURRENT_NUM == 0)
                    .Where(a => startAreas.Contains(a.S_AREA_CODE))
                    .First();
@@ -76,9 +78,9 @@
                    if (!int.TryParse(model.Row.Trim(), out int row)) {
                        return BuildSimpleResult(2, $"{model.Row} 不合法:无法转成整数类型");
                    }
                    // 货架排号只能是 0 - 8
                    if (row <= 0 || row > 8) {
                        return BuildSimpleResult(2, $"货架号 {model.Row} 必须是1-8之间的整数");
                    // 货架排号只能是 0 - 8(111-118)
                    if (row <= 110 || row > 118) {
                        return BuildSimpleResult(2, $"货架号 {model.Row} 必须是111-118之间的整数");
                    }
                }
@@ -202,9 +204,9 @@
                    if (!int.TryParse(model.Row.Trim(), out int row)) {
                        return BuildSimpleResult(2, $"{model.Row} 不合法:无法转成整数类型");
                    }
                    // 货架排号只能是 0 - 8
                    if (row <= 0 || row > 8) {
                        return BuildSimpleResult(2, $"货架号 {model.Row} 必须是1-8之间的整数");
                    // 货架排号只能是 0 - 8(111-118)
                    if (row <= 110 || row > 118) {
                        return BuildSimpleResult(2, $"货架号 {model.Row} 必须是111-118之间的整数");
                    }
                }
@@ -617,11 +619,25 @@
            var db = new SqlHelper<object>().GetInstance();
            try {
                var err = "";
                var cgDetailList = new List<TN_CG_Detail>();
                var recordList = new List<TN_Inbound_DataRecord>();
                if (model.stockTransactions.Count == 0) {
                    return BuildErpResult(400, "不能传入空的数据列表");
                }
                //var info = "";
                //var cgDetailList = new List<TN_CG_Detail>();
                var insetRecordList = new List<TN_Inbound_DataRecord>();
                var deleteRecordOldList = new List<TN_Inbound_DataRecord> ();
                //var errList = new List<TN_Inbound_DataRecord>();
                foreach (var transaction in model.stockTransactions) {
                    var recordOld = db.Queryable<TN_Inbound_DataRecord>()
                        .Where(r => r.S_LOCATION_CODE == transaction.locationCode).First();
                    if (recordOld != null) {
                        deleteRecordOldList.Add(recordOld);
                        //errList.Add(recordOld);
                        //continue;
                    }
                    // 写入记录表
                    var record = new TN_Inbound_DataRecord {
                        S_LOCATION_CODE = transaction.locationCode,
@@ -639,44 +655,58 @@
                        S_SUPPLIER_NAME = transaction.supplierName,
                        S_INVENTORY_MAN = transaction.inventoryManager
                    };
                    recordList.Add(record);
                    insetRecordList.Add(record);
                    // 查询对应物料
                    var cgDetail = db.Queryable<TN_Location, TN_Loc_Container, TN_CG_Detail>
                        ((l, c, d) => l.S_CODE == c.S_LOC_CODE && c.S_CNTR_CODE == d.S_CNTR_CODE)
                        .Where(l => l.S_CODE == transaction.locationCode)
                        .Select((l, c, d) => d)
                        .First();
                    //// 查询对应物料
                    //var cgDetail = db.Queryable<TN_Location, TN_Loc_Container, TN_CG_Detail>
                    //    ((l, c, d) => l.S_CODE == c.S_LOC_CODE && c.S_CNTR_CODE == d.S_CNTR_CODE)
                    //    .Where(l => l.S_CODE == transaction.locationCode)
                    //    .Select((l, c, d) => d)
                    //    .First();
                    if (cgDetail == null) {
                        err += $"储位码{transaction.locationCode}对应的货位物料不存在!";
                        continue;
                    }
                    cgDetail.S_ITEM_CODE = transaction.itemCode;
                    cgDetail.S_ITEM_NAME = transaction.itemName;
                    //if (cgDetail == null) {
                    //    err += $"储位码{transaction.locationCode}对应的货位物料不存在!";
                    //    continue;
                    //}
                    //cgDetail.S_ITEM_CODE = transaction.itemCode;
                    //cgDetail.S_ITEM_NAME = transaction.itemName;
                    cgDetailList.Add(cgDetail);
                    //cgDetailList.Add(cgDetail);
                }
                 
                using (var tran = db.Ado.UseTran()) {
                    if (db.Insertable<TN_Inbound_DataRecord>(recordList).ExecuteCommand() <= 0) {
                    if (deleteRecordOldList.Count != 0 && db.Deleteable<TN_Inbound_DataRecord>(deleteRecordOldList).ExecuteCommand() <= 0) {
                        tran.RollbackTran();
                        return BuildErpResult(500, $"写入入库记录表失败");
                        return BuildErpResult(500, $"删除旧入库记录数据失败:{JsonConvert.SerializeObject(deleteRecordOldList)}");
                    }
                    if (db.Updateable<TN_CG_Detail>(cgDetailList).ExecuteCommand() <= 0) {
                    if (db.Insertable<TN_Inbound_DataRecord>(insetRecordList).ExecuteCommand() <= 0) {
                        tran.RollbackTran();
                        return BuildErpResult(500, $"更改物料信息失败");
                        return BuildErpResult(500, $"写入入库记录表失败!");
                    }
                    //if (db.Updateable<TN_CG_Detail>(cgDetailList).ExecuteCommand() <= 0) {
                    //    tran.RollbackTran();
                    //    return BuildErpResult(500, $"更改物料信息失败!待更新物料信息数量={cgDetailList.Count}");
                    //}
                    tran.CommitTran();
                    return BuildErpResult(0, $"写入入库记录表成功!");
                }
                if (err != "") {
                    return BuildErpResult(2, err + "其他信息正常已写入");
                }
                return BuildErpResult(0, $"更改物料信息成功");
                //if (err != "") {
                //    return BuildErpResult(2, err + "其他信息正常已写入");
                //}
                //return BuildErpResult(0, $"更改物料信息成功");
                // NOTE:暂时不检查,万一ERP发错了,可以选择重发
                //if (errList.Count > 0) {
                //    info = "更改物料信息部分成功,部分失败,原因:当前货位已经给过物料信息";
                //}
                //else {
                //    info = "更改物料信息成功!";
                //}
            }
            catch (Exception ex) {
                return BuildErpResult(1, $"发生了异常:{ex.Message}");
@@ -688,11 +718,24 @@
            var db = new SqlHelper<object>().GetInstance();
            try {
                var err = "";
                var cgDetailList = new List<TN_CG_Detail>();
                var recordList = new List<TN_Outbound_DataRecord>();
                if (model.materialIssues.Count == 0) {
                    return BuildErpResult(400, "不能传入空的数据列表");
                }
                //var err = "";
                //var cgDetailList = new List<TN_CG_Detail>();
                //var recordList = new List<TN_Outbound_DataRecord>();
                var insetRecordList = new List<TN_Outbound_DataRecord>();
                var deleteRecordOldList = new List<TN_Outbound_DataRecord>();
                foreach (var issue in model.materialIssues) {
                    var recordOld = db.Queryable<TN_Outbound_DataRecord>()
                        .Where(r => r.S_LOCATION_CODE == issue.locationCode).First();
                    if (recordOld != null) {
                        deleteRecordOldList.Add(recordOld);
                        //errList.Add(recordOld);
                        //continue;
                    }
                    // 写入记录表
                    var record = new TN_Outbound_DataRecord {
                        S_LOCATION_CODE = issue.locationCode,
@@ -709,44 +752,50 @@
                        S_LINE_CODE = issue.lineCode,
                        S_BATCH_NO = issue.batchNo
                    };
                    recordList.Add(record);
                    insetRecordList.Add(record);
                    // 查询对应物料
                    var cgDetail = db.Queryable<TN_Location, TN_Loc_Container, TN_CG_Detail>
                        ((l, c, d) => l.S_CODE == c.S_LOC_CODE && c.S_CNTR_CODE == d.S_CNTR_CODE)
                        .Where(l => l.S_CODE == issue.locationCode)
                        .Select((l, c, d) => d)
                        .First();
                    //// 查询对应物料
                    //var cgDetail = db.Queryable<TN_Location, TN_Loc_Container, TN_CG_Detail>
                    //    ((l, c, d) => l.S_CODE == c.S_LOC_CODE && c.S_CNTR_CODE == d.S_CNTR_CODE)
                    //    .Where(l => l.S_CODE == issue.locationCode)
                    //    .Select((l, c, d) => d)
                    //    .First();
                    if (cgDetail == null) {
                        err += $"储位码{issue.locationCode}对应的货位物料不存在!";
                        continue;
                    }
                    //if (cgDetail == null) {
                    //    err += $"储位码{issue.locationCode}对应的货位物料不存在!";
                    //    continue;
                    //}
                    cgDetail.S_ITEM_CODE = issue.itemCode;
                    cgDetail.S_ITEM_NAME = issue.itemName;
                    //cgDetail.S_ITEM_CODE = issue.itemCode;
                    //cgDetail.S_ITEM_NAME = issue.itemName;
                    cgDetailList.Add(cgDetail);
                    //cgDetailList.Add(cgDetail);
                }
                using (var tran = db.Ado.UseTran()) {
                    if (db.Insertable<TN_Outbound_DataRecord>(recordList).ExecuteCommand() <= 0) {
                    if (deleteRecordOldList.Count != 0 && db.Deleteable<TN_Outbound_DataRecord>(deleteRecordOldList).ExecuteCommand() <= 0) {
                        tran.RollbackTran();
                        return BuildErpResult(500, $"删除旧出库记录数据失败:{JsonConvert.SerializeObject(deleteRecordOldList)}");
                    }
                    if (db.Insertable<TN_Outbound_DataRecord>(insetRecordList).ExecuteCommand() <= 0) {
                        tran.RollbackTran();
                        return BuildErpResult(500, $"写入出库记录表失败");
                    }
                    if (db.Updateable<TN_CG_Detail>(cgDetailList).ExecuteCommand() <= 0) {
                        tran.RollbackTran();
                        return BuildErpResult(500, $"更改物料信息失败");
                    }
                    //if (db.Updateable<TN_CG_Detail>(cgDetailList).ExecuteCommand() <= 0) {
                    //    tran.RollbackTran();
                    //    return BuildErpResult(500, $"更改物料信息失败");
                    //}
                    tran.CommitTran();
                    return BuildErpResult(0, $"写入出库记录表成功!");
                }
                if (err != "") {
                    return BuildErpResult(2, err + "其他信息正常已写入");
                }
                return BuildErpResult(0, $"更改物料信息成功");
                //if (err != "") {
                //    return BuildErpResult(2, err + "其他信息正常已写入");
                //}
                //return BuildErpResult(0, $"更改物料信息成功");
            }
            catch (Exception ex) {