hao
2025-09-18 4598e856759f043f203d45a0674626b9e2ff89b8
StandardInterface/MES.Service/service/ZZCXDManager.cs
@@ -44,8 +44,9 @@
            var entity = new ZZCX
            {
                BillNo = dto.bill_no,   // 单据编码
                Erpid = dto.erpid ,      // ERP 主表 ID
                 DjLx = dto.dj_lx,
                Erpid = string.IsNullOrEmpty(dto.erpid) ? (decimal?)null : Convert.ToDecimal(dto.erpid),
                // ERP 主表 ID
                DjLx = dto.dj_lx,
                KcZz = dto.kc_zz,
                SwLx = dto.sw_lx,
                // Time = string.IsNullOrEmpty(dto.time) ? (DateTime?)null : DateTime.Parse(dto.time),
@@ -78,27 +79,28 @@
            {
                var item = new ZZCXA
                {
                    Erpid = dto.erpid,
                 /*   BillNo = dto.bill_no,
                    DjLx = dto.dj_lx,
                    KcZz = dto.kc_zz,
                    SwLx = dto.sw_lx,
                   // Time = string.IsNullOrEmpty(dto.time) ? (DateTime?)null : DateTime.Parse(dto.time),
                    Time = dto.time,
                    Bm = dto.bm,
                    Cgy = dto.cgy,
                    Kcz = dto.kcz,
                    DjZt = dto.dj_zt,
                    Memo = dto.memo,
                    Cphzlx = dto.cphzlx,
                    Cphz = dto.cphz,
                    Zjhzlx = dto.zjhzlx,
                    Zjhz = dto.zjhz,*/
                    ItemId = dto.item_id,
                       /*   BillNo = dto.bill_no,
                       DjLx = dto.dj_lx,
                       KcZz = dto.kc_zz,
                       SwLx = dto.sw_lx,
                      // Time = string.IsNullOrEmpty(dto.time) ? (DateTime?)null : DateTime.Parse(dto.time),
                       Time = dto.time,
                       Bm = dto.bm,
                       Cgy = dto.cgy,
                       Kcz = dto.kcz,
                       DjZt = dto.dj_zt,
                       Memo = dto.memo,
                       Cphzlx = dto.cphzlx,
                       Cphz = dto.cphz,
                       Zjhzlx = dto.zjhzlx,
                       Zjhz = dto.zjhz,*/
                    Erpid = string.IsNullOrEmpty(dto.erpid) ? (decimal?)null : Convert.ToDecimal(dto.erpid),
                    YdId = string.IsNullOrEmpty(dto.yd_id) ? (decimal?)null : Convert.ToDecimal(dto.yd_id),
                    ItemId = string.IsNullOrEmpty(dto.item_id) ? (decimal?)null : Convert.ToDecimal(dto.item_id),
                    Qty = string.IsNullOrEmpty(dto.qty) ? (decimal?)null : Convert.ToDecimal(dto.qty),
                    Unit = dto.unit,
                    DepotId = dto.depot_id,
                    YdId = mainErpId
                    DepotId = string.IsNullOrEmpty(dto.depot_id) ? (decimal?)null : Convert.ToDecimal(dto.depot_id)
                };
                var existing = Db.Queryable<ZZCXA>().Where(s => s.Erpid == item.Erpid).Single();
@@ -113,14 +115,15 @@
                    {
                        var subEntity = new ZZCXB
                        {
                            Eid = subDto.eid,
                            ItemId = subDto.item_id,
                            Eid = string.IsNullOrEmpty(subDto.eid) ? (decimal?)null : Convert.ToDecimal(subDto.eid),
                            Erpid = string.IsNullOrEmpty(subDto.erpid) ? (decimal?)null : Convert.ToDecimal(subDto.erpid),
                            YdId = string.IsNullOrEmpty(subDto.yd_id) ? (decimal?)null : Convert.ToDecimal(subDto.yd_id),
                            ItemId = string.IsNullOrEmpty(subDto.item_id) ? (decimal?)null : Convert.ToDecimal(subDto.item_id),
                            Qty = string.IsNullOrEmpty(subDto.qty) ? (decimal?)null : Convert.ToDecimal(subDto.qty),
                            Unit = subDto.unit,
                            DepotId = subDto.depot_id,
                            DepotId = string.IsNullOrEmpty(subDto.depot_id) ? (decimal?)null : Convert.ToDecimal(subDto.depot_id),
                            LotNo = subDto.lot_no,
                            Memo = subDto.memo,
                            Erpid = mainErpId
                            Memo = subDto.memo
                        };
                        var existingSub = Db.Queryable<ZZCXB>().Where(s => s.Eid == subEntity.Eid).Single();
@@ -137,6 +140,15 @@
        private bool SaveOrUpdateData(SqlSugarScope db, ZZCX head, List<ZZCXA> children)
        {
            // 1. 校验是否存在领料记录(MES_INV_ITEM_OUTS)
            var hasMaterialOut = db.Queryable<MesInvItemOuts>()
                                   .Any(x => x.WorkNo == head.BillNo);
            if (hasMaterialOut)
            {
                throw new Exception($"MES已有领料记录,单号:{head.BillNo},不能更新!");
            }
            if (head.Id != null)
                base.DeleteById(head.Id);
@@ -180,6 +192,16 @@
        private bool UpdateData(SqlSugarScope db, ZZCX head, List<ZZCXA> children)
        {
            // 1. 校验是否存在领料记录(MES_INV_ITEM_OUTS)
            var hasMaterialOut = db.Queryable<MesInvItemOuts>()
                                   .Any(x => x.WorkNo == head.BillNo);
            if (hasMaterialOut)
            {
                throw new Exception($"MES已有领料记录,单号:{head.BillNo},不能删除!");
            }
            // 删除主表
            var deletedHead = db.Deleteable<ZZCX>()
                                .Where(d => d.Erpid == head.Erpid)