hao
2025-08-18 1a09e10891586f227bec656d92ad27382f0412a2
直接调拨申请单
已修改4个文件
已添加3个文件
383 ■■■■■ 文件已修改
.vs/slnx.sqlite 补丁 | 查看 | 原始文档 | blame | 历史
StandardInterface/MES.Service/Dto/webApi/ERPZJDB.cs 49 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
StandardInterface/MES.Service/Modes/MesInvItemDbsq.cs 38 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
StandardInterface/MES.Service/service/DbckaManager.cs 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
StandardInterface/MES.Service/service/WomcaaManager.cs 48 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
StandardInterface/MES.Service/service/ZjdbManager.cs 142 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
StandardInterface/MESApplication/Controllers/ZJdbController.cs 103 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.vs/slnx.sqlite
Binary files differ
StandardInterface/MES.Service/Dto/webApi/ERPZJDB.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,49 @@
using System.Collections.Generic;
namespace MES.Service.Dto.webApi
{
    public class ERPZJDB
    {
        public ERPZJDBA ERPZJDBA { get; set; } = new ERPZJDBA();
        public List<ERPZJDBB> ERPZJDBB { get; set; } = new List<ERPZJDBB>();
    }
    public class ERPZJDBA
    {
        public string? billno { get; set; }      // å•据编码
        public string? dj_lx { get; set; }       // å•据类型
        public string? db_lx1 { get; set; }      // è°ƒæ‹¨ç±»åž‹
        public string? db_fx { get; set; }       // è°ƒæ‹¨æ–¹å‘
        public string? db_lx { get; set; }       // è°ƒæ‹¨ç±»åž‹
        public string? yw_lx { get; set; }       // ä¸šåŠ¡ç±»åž‹
        public string? dj_zt { get; set; }       // å•据状态
        public string? sq_bm { get; set; }       // ç”³è¯·éƒ¨é—¨
        public string? dc_kc { get; set; }       // è°ƒå‡ºåº“存组织
        public string? dr_kc { get; set; }       // è°ƒå…¥åº“存组织
        public string? dc_hz { get; set; }       // è°ƒå‡ºè´§ä¸»
        public string? dr_hz { get; set; }       // è°ƒå…¥è´§ä¸»
        public string? dr_ck { get; set; }       // è°ƒå…¥ä»“库
        public string? dc_bm { get; set; }       // è°ƒå‡ºéƒ¨é—¨
        public string? dr_bm { get; set; }       // è°ƒå…¥éƒ¨é—¨
        public string? bz { get; set; }          // å¤‡æ³¨
        public string type { get; set; }        // type
        public string? erpid { get; set; }       // è°ƒæ‹¨å‡ºåº“单id
    }
    public class ERPZJDBB
    {
        public string? itemid { get; set; }      // ç‰©æ–™ç¼–码
        public string? unit { get; set; }        // å•位
        public string? quantity { get; set; }    // ç”³è¯·æ•°é‡
        public string? dc_org { get; set; }      // è°ƒå‡ºç»„织
        public string? dc_depot { get; set; }    // è°ƒå‡ºä»“库
        public string? dr_org { get; set; }      // è°ƒå…¥ç»„织
        public string? dr_depot { get; set; }    // è°ƒå…¥ä»“库
        public string? dc_hz { get; set; }       // è°ƒå‡ºè´§ä¸»
        public string? dr_hz { get; set; }       // è°ƒå…¥è´§ä¸»
        public string? bz { get; set; }          // å¤‡æ³¨
        public string? erpid { get; set; }       // è°ƒæ‹¨å‡ºåº“行id
        public string? eid { get; set; }         // è°ƒæ‹¨å‡ºåº“头id
    }
}
StandardInterface/MES.Service/Modes/MesInvItemDbsq.cs
@@ -211,5 +211,43 @@
        ///</summary>
        [SugarColumn(ColumnName = "ERPID")]
        public string? Erpid { get; set; }
        /// <summary>
        ///  è°ƒå‡ºåº“存组织
        ///</summary>
        [SugarColumn(ColumnName = "DC_KC")]
        public string? DcKc { get; set; }
        /// <summary>
        ///  è°ƒå…¥åº“存组织
        ///</summary>
        [SugarColumn(ColumnName = "DR_KC")]
        public string? DrKc { get; set; }
        /// <summary>
        ///  è°ƒå…¥è´§ä¸»
        ///</summary>
        [SugarColumn(ColumnName = "DR_HZ")]
        public string? DrHz { get; set; }
        /// <summary>
        ///  è°ƒå…¥ä»“库
        ///</summary>
        [SugarColumn(ColumnName = "DR_CK")]
        public string? DrCk { get; set; }
        /// <summary>
        ///  è°ƒå‡ºéƒ¨é—¨
        ///</summary>
        [SugarColumn(ColumnName = "DC_BM")]
        public string? DcBm { get; set; }
        /// <summary>
        ///  è°ƒå…¥éƒ¨é—¨
        ///</summary>
        [SugarColumn(ColumnName = "DR_BM")]
        public string? DrBm { get; set; }
        /// <summary>
        ///  MES类型
        ///</summary>
        [SugarColumn(ColumnName = "TYPE2")]
        public string? Type2 { get; set; }
    }
}
StandardInterface/MES.Service/service/DbckaManager.cs
@@ -59,7 +59,8 @@
                CreateDate = DateTime.Now,
                CreateBy = "System",
                DbStatus="未调拨",
                Status=1
                Status=1,
                Type2 = "分布式调拨单",
            };
            //    var single = base.GetSingle(it => it.Erpid == entity.Erpid);
StandardInterface/MES.Service/service/WomcaaManager.cs
@@ -98,8 +98,30 @@
        List<Womcab> mesWomcabs)
    {
        //定义输入参数
        var inputParam1 = new SugarParameter("P_WORK_NO", mesWomcaa.Caa001);
        // å®šä¹‰è¾“出参数
        var outParam1 = new SugarParameter("c_Result", null, true);
        var outParam2 = new SugarParameter("C_MSG", null, true);
        // ä½¿ç”¨ SqlSugar æ‰§è¡Œå­˜å‚¨è¿‡ç¨‹
        Db.Ado.ExecuteCommand(
            "BEGIN PRC_UPDATE_DAA2(:P_WORK_NO,:c_Result,:C_MSG); END;",
            inputParam1, outParam1, outParam2);
        // èŽ·å–è¾“å‡ºå‚æ•°çš„å€¼
        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();
        var decimals = mesWomcabs.Select(s => s.Id).ToArray();
@@ -119,29 +141,7 @@
        if (update && insertOrUpdate)
        {
            //定义输入参数
            var inputParam1 = new SugarParameter("P_WORK_NO", mesWomcaa.Caa001);
            // å®šä¹‰è¾“出参数
            var outParam1 = new SugarParameter("c_Result", null, true);
            var outParam2 = new SugarParameter("C_MSG", null, true);
            // ä½¿ç”¨ SqlSugar æ‰§è¡Œå­˜å‚¨è¿‡ç¨‹
            Db.Ado.ExecuteCommand(
                "BEGIN PRC_UPDATE_DAA2(:P_WORK_NO,:c_Result,:C_MSG); END;",
                inputParam1, outParam1, outParam2);
            // èŽ·å–è¾“å‡ºå‚æ•°çš„å€¼
            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("更新失败");
StandardInterface/MES.Service/service/ZjdbManager.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,142 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using MES.Service.DB;
using MES.Service.Dto.webApi;
using MES.Service.Modes;
namespace MES.Service.service
{
    public class ERPZJDBManager : Repository<MesInvItemDbsq>
    {
        public bool SaveList(List<ERPZJDB> list)
        {
            var result = list.Select(Save).ToList();
            return result.All(b => b);
        }
        public bool Save(ERPZJDB data)
        {
            var head = MapErpToMesHead(data.ERPZJDBA);
            var details = MapErpDbckbToDbckb(data.ERPZJDBB);
            return UseTransaction(db =>
            {
                switch (data.ERPZJDBA.type)
                {
                    case "3":
                        return UpdateData(db, head, details) ? 1 : 0;
                    case "2":
                    case "4":
                    case "5":
                        return SaveOrUpdateData(db, head, details) ? 1 : 0;
                    default:
                        throw new NotImplementedException($"type没有 {data.ERPZJDBA.type} è¿™ä¸ªç±»åž‹");
                }
            }) > 0;
        }
        private MesInvItemDbsq MapErpToMesHead(ERPZJDBA dto)
        {
            var entity = new MesInvItemDbsq
            {
                BillNo = dto.billno,//单据编码
                Djlx = dto.dj_lx,   //单据类型
                DbLx1 = dto.db_lx1, //调拨类型
                DbFx = dto.db_fx,   //调拨方向
                DbLx = dto.db_lx,   //调拨类型
                YwLx = dto.yw_lx,   //业务类型
                DjZt = dto.dj_zt,   //单据状态
                SqBm = dto.sq_bm,   //申请部门
                DcKc = dto.dc_kc,   //调出库存组织
                DrKc = dto.dr_kc,   //调入库存组织
                DcHz = dto.dc_hz,   //调出货主
                DrHz = dto.dr_hz,   //调入货主
                DrCk = dto.dr_ck,   //调入仓库
                DcBm = dto.dc_bm,   //调出部门
                DrBm = dto.dr_bm,   //调入部门
                Type2 = "直接调拨单",   //
                Remark = dto.bz,
                Erpid = dto.erpid,
                CreateDate = DateTime.Now,
                CreateBy = "System",
                DbStatus = "未调拨",
                Status = 1
            };
            var single = Db.Queryable<MesInvItemDbsq>()
                           .Where(it => it.Erpid == entity.Erpid)
                           .First();
            if (single != null)
                entity.Id = single.Id;
            return entity;
        }
        private List<MesInvItemDbsqItems> MapErpDbckbToDbckb(List<ERPZJDBB> list)
        {
            var result = new List<MesInvItemDbsqItems>();
            foreach (var dto in list)
            {
                var item = new MesInvItemDbsqItems
                {
                    ItemId = Convert.ToDecimal(dto.itemid),
                    ItemUnit = Convert.ToDecimal(dto.unit),
                    SqNum = decimal.TryParse(dto.quantity, out var qty) ? qty : 0,
                    DcOrg = dto.dc_org,
                    DcDepot = dto.dc_depot,
                    DrOrg = dto.dr_org,
                    DrDepot = dto.dr_depot,
                    DcHz = dto.dc_hz,
                    DrHz = dto.dr_hz,
                    Remark = dto.bz,
                    Erpid = dto.erpid,
                    Eid = dto.eid,
                };
                var existing = Db.Queryable<MesInvItemDbsqItems>().Where(s => s.Erpid == item.Erpid).Single();
                if (existing != null) item.Id = existing.Id;
                result.Add(item);
            }
            return result;
        }
        private bool SaveOrUpdateData(SqlSugarScope db, MesInvItemDbsq head, List<MesInvItemDbsqItems> details)
        {
            if (head.Id != null)
                base.DeleteById(head.Id);
            db.Deleteable<MesInvItemDbsqItems>()
              .Where(d => d.Eid == head.Erpid)
              .ExecuteCommand();
            var insertedHead = db.Insertable(head)
                .IgnoreColumns(true)
                .ExecuteReturnIdentity();
            if (insertedHead <= 0)
                throw new Exception("主表插入失败,未返回ID");
            var success = db.Insertable(details)
                .PageSize(10)
                .IgnoreColumnsNull()
                .ExecuteCommand() > 0;
            if (insertedHead >= 0 && success) return true;
            throw new NotImplementedException("插入或更新失败");
        }
        private bool UpdateData(SqlSugarScope db, MesInvItemDbsq head, List<MesInvItemDbsqItems> details)
        {
            var ids = details.Select(d => d.Id).ToArray();
            var deletedHead = base.DeleteById(head.Id);
            var deletedDetails = db.Deleteable<MesInvItemDbsqItems>().In(ids).ExecuteCommand() > 0;
            if (deletedHead && deletedDetails) return true;
            throw new NotImplementedException("更新失败");
        }
    }
}
StandardInterface/MESApplication/Controllers/ZJdbController.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,103 @@
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Dynamic;
using MES.Service.service;
using MES.Service.Dto.webApi;
using MES.Service.util;
using Newtonsoft.Json;
using MES.Service.Modes;
namespace MESApplication.Controllers
{
    [ApiController]
    [Route("api/[controller]")]
    public class ERPZJDBController : ControllerBase
    {
        private readonly ERPZJDBManager _manager = new();   // è¿™é‡Œå¯¹åº”æ–°çš„ Service
        private readonly MessageCenterManager _messageManager = new();
        private const string METHOD = "POST";
        private const string TableName = "ERPZJDB";
        private const string URL = "http://localhost:10054/api/ERPZJDB/";
        /// <summary>
        /// ä¿å­˜å•条调拨单
        /// </summary>
        [HttpPost("Save")]
        public ResponseResult Save([FromBody] ERPZJDB data)
        {
            var msg = new MessageCenter
            {
                TableName = TableName,
                Url = URL + "Save",
                Method = METHOD,
                Data = JsonConvert.SerializeObject(data),
                Status = 1,
                CreateBy = "PL017",
                Route = data.ERPZJDBA.billno   // æ³¨æ„å– billno
            };
            try
            {
                dynamic resultInfos = new ExpandoObject();
                var success = _manager.Save(data);
                resultInfos.tbBillList = success;
                msg.Result = success ? (short?)1 : (short?)0;
                msg.DealWith = 1;
                _messageManager.save(msg);
                return new ResponseResult { status = 0, message = "OK", data = resultInfos };
            }
            catch (Exception ex)
            {
                msg.Result = 0;
                msg.DealWith = 0;
                msg.ResultData = ex.Message;
                _messageManager.save(msg);
                return ResponseResult.ResponseError(ex);
            }
        }
        /// <summary>
        /// æ‰¹é‡ä¿å­˜è°ƒæ‹¨å•
        /// </summary>
        [HttpPost("SaveList")]
        public ResponseResult SaveList([FromBody] List<ERPZJDB> dataList)
        {
            var msg = new MessageCenter
            {
                TableName = TableName,
                Url = URL + "SaveList",
                Method = METHOD,
                Data = JsonConvert.SerializeObject(dataList),
                Status = 1,
                CreateBy = "PL017"
            };
            try
            {
                dynamic resultInfos = new ExpandoObject();
                var success = _manager.SaveList(dataList);
                resultInfos.tbBillList = success;
                msg.Result = success ? (short?)1 : (short?)0;
                msg.DealWith = 1;
                _messageManager.save(msg);
                return new ResponseResult { status = 0, message = "OK", data = resultInfos };
            }
            catch (Exception ex)
            {
                msg.Result = 0;
                msg.DealWith = 0;
                msg.ResultData = ex.Message;
                _messageManager.save(msg);
                return ResponseResult.ResponseError(ex);
            }
        }
    }
}