1
hao
2025-04-28 9aa2afe228a7a3e5734916c7126587a94379c775
1
已添加7个文件
597 ■■■■■ 文件已修改
StandardInterface/MES.Service/Dto/webApi/ErpShzd.cs 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
StandardInterface/MES.Service/Dto/webApi/ErpShzdDetail.cs 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
StandardInterface/MES.Service/Dto/webApi/Sh.cs 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
StandardInterface/MES.Service/Modes/Shtzd.cs 50 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
StandardInterface/MES.Service/Modes/ShtzdDetail.cs 94 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
StandardInterface/MES.Service/service/ShtzdManager.cs 144 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
StandardInterface/MESApplication/Controllers/ShtzdController.cs 264 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
StandardInterface/MES.Service/Dto/webApi/ErpShzd.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,14 @@
namespace MES.Service.Dto.webApi;
public class ErpShzd
{
    public int ERPID { get; set; }
    public string? Type { get; set; }
    public string? FBillNo { get; set; }      //单据编号
    public string? FStockID { get; set; }        //仓库
    public string? FSupplierId { get; set; }      //供应商
    public string? FDate { get; set; }            //单据日期
    public string? FNote { get; set; }            //备注
    public string? F_ZJXF_sfgx { get; set; }      //是否供协
}
StandardInterface/MES.Service/Dto/webApi/ErpShzdDetail.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,24 @@
namespace MES.Service.Dto.webApi;
public class ErpShzdDetail
{
    public int ERPID { get; set; }
    public int EID { get; set; }
    public string? LineNo { get; set; }      //收料通知单分录内码
    public string?  FORDERBILLNO   { get; set; }      //采购单号
    public string?   FMATERIALID   { get; set; }      //物料编码
    public string?  FPOQTY         { get; set; }      //采购订单数量
    public string?  FACTRECEIVEQTY { get; set; }      //本次应收数量
    public string? FACTREQTY { get; set; }            //本次实收数量
    public string?  FUNITID        { get; set; }      //采购单位
    public string?  FSTOCKUNITID   { get; set; }      //库存单位
    public string?  FDESCRIPTION   { get; set; }      //备注
    public string?  FSRCBILLNO     { get; set; }      //采购单ID
    public string?  FSRCENTRYID    { get; set; }      //采购单行ID
    public string? FXSHTH { get; set; }               //销售订单号
    public string? FMtoNo{ get; set; }               //计划跟踪号
    public string? FLot { get; set; }               //批号
}
StandardInterface/MES.Service/Dto/webApi/Sh.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,7 @@
namespace MES.Service.Dto.webApi;
public class Sh
{
    public ErpShzd ErpShtzd { get; set; }
    public List<ErpShzdDetail> ErpShzdDetail { get; set; }
}
StandardInterface/MES.Service/Modes/Shtzd.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Linq;
using SqlSugar;
namespace MES.Service.Modes
{
    /// <summary>
    ///
    ///</summary>
    [SugarTable("SHTZD")]
    public class Shtzd
    {
        /// <summary>
        /// å•据编号
        ///</summary>
        [SugarColumn(ColumnName = "ID", IsPrimaryKey = true)]
        public int ID { get; set; }
        /// <summary>
        /// å•据编号
        ///</summary>
        [SugarColumn(ColumnName="DELIVERYNO"    )]
         public string Deliveryno { get; set; }
        /// <summary>
        /// ä»“库
        ///</summary>
         [SugarColumn(ColumnName="DEPOTNO"    )]
         public string Depotno { get; set; }
        /// <summary>
        /// ä¾›åº”商
        ///</summary>
         [SugarColumn(ColumnName="SUPPLIERID"    )]
         public string Supplierid { get; set; }
        /// <summary>
        /// å•据日期
        ///</summary>
         [SugarColumn(ColumnName="FDATE"    )]
         public string Fdate { get; set; }
        /// <summary>
        /// å¤‡æ³¨
        ///</summary>
         [SugarColumn(ColumnName="REMARK"    )]
         public string Remark { get; set; }
        /// <summary>
        /// æ˜¯å¦ä¾›å
        ///</summary>
         [SugarColumn(ColumnName="F_ZJXF_SFGX"    )]
         public string FZjxfSfgx { get; set; }
    }
}
StandardInterface/MES.Service/Modes/ShtzdDetail.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,94 @@
using System;
using System.Collections.Generic;
using System.Linq;
using SqlSugar;
namespace MES.Service.Modes
{
    /// <summary>
    ///
    ///</summary>
    [SugarTable("SHTZD_DETAIL")]
    public class ShtzdDetail
    {
        /// <summary>
        /// æ”¶æ–™é€šçŸ¥å•分录内码
        ///</summary>
        [SugarColumn(ColumnName = "ERPID", IsPrimaryKey = true)]
        public Int32 Erpid { get; set; }
        /// <summary>
        /// æ”¶æ–™é€šçŸ¥å•分录内码
        ///</summary>
        [SugarColumn(ColumnName = "EID")]
        public Int32 Eid { get; set; }
        /// <summary>
        /// æ”¶æ–™é€šçŸ¥å•分录内码
        ///</summary>
        [SugarColumn(ColumnName="LINENO"    )]
         public string Lineno { get; set; }
        /// <summary>
        /// è®¢å•单号
        ///</summary>
         [SugarColumn(ColumnName="FBILLNO"    )]
         public string Fbillno { get; set; }
        /// <summary>
        /// ç‰©æ–™ç¼–码
        ///</summary>
         [SugarColumn(ColumnName="PRODUCTCODE"    )]
         public string Productcode { get; set; }
        /// <summary>
        /// è®¢å•数量
        ///</summary>
         [SugarColumn(ColumnName="PURCHASEQTY"    )]
         public string Purchaseqty { get; set; }
        /// <summary>
        /// æœ¬æ¬¡åº”收数量
        ///</summary>
         [SugarColumn(ColumnName="DELIVERYQTY"    )]
         public string Deliveryqty { get; set; }
        /// <summary>
        /// äº¤è´§æ•°é‡
        ///</summary>
         [SugarColumn(ColumnName="INCLUDEQTY"    )]
         public string Includeqty { get; set; }
        /// <summary>
        /// æ”¶æ–™å•位
        ///</summary>
         [SugarColumn(ColumnName="PURCHASEUNIT"    )]
         public string Purchaseunit { get; set; }
        /// <summary>
        /// åº“存单位
        ///</summary>
         [SugarColumn(ColumnName="INVENTORYUNIT"    )]
         public string Inventoryunit { get; set; }
        /// <summary>
        /// å¤‡æ³¨
        ///</summary>
         [SugarColumn(ColumnName="REMARK"    )]
         public string Remark { get; set; }
        /// <summary>
        /// æºå•单号
        ///</summary>
         [SugarColumn(ColumnName="SALESORDERID"    )]
         public string Salesorderid { get; set; }
        /// <summary>
        /// æºå•分录内码
        ///</summary>
         [SugarColumn(ColumnName="ORDERLINEID"    )]
         public string Orderlineid { get; set; }
        /// <summary>
        /// é”€å”®è®¢å•号
        ///</summary>
         [SugarColumn(ColumnName="FXSHTH"    )]
         public string Fxshth { get; set; }
        /// <summary>
        /// è®¡åˆ’跟踪号
        ///</summary>
         [SugarColumn(ColumnName="FMTONO"    )]
         public string Fmtono { get; set; }
        /// <summary>
        /// æ‰¹å·
        ///</summary>
         [SugarColumn(ColumnName="FLOT"    )]
         public string Flot { get; set; }
    }
}
StandardInterface/MES.Service/service/ShtzdManager.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,144 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using MES.Service.DB;
using MES.Service.Modes;
using MES.Service.Dto.webApi;
namespace MES.Service.service
{
    public class ShtzdManager : Repository<Shtzd>
    {
        public bool Save(Sh sh)
        {
            var SH = sh.ErpShtzd;
            var mesShtzd = GetMesShtzd(SH);
            var shtzdDetails = GetMesShtzdDetail(sh.ErpShzdDetail);
            return UseTransaction(db =>
            {
                return SH.Type switch
                {
                    "2" or "4" or "5" => SaveOrUpdateData(db, mesShtzd, shtzdDetails) ? 1 : 0,
                    "3" => UpdateData(db, mesShtzd, shtzdDetails) ? 1 : 0,
                    _ => throw new NotImplementedException($"类型 Type = {SH.Type} ä¸å­˜åœ¨")
                };
            }) > 0;
        }
        public bool SaveList(List<Sh> shList)
        {
            return UseTransaction(db =>
            {
                foreach (var sh in shList)
                {
                    var SH = sh.ErpShtzd;
                    var mesShtzd = GetMesShtzd(SH);
                    var shtzdDetails = GetMesShtzdDetail(sh.ErpShzdDetail);
                    switch (SH.Type)
                    {
                        case "2":
                        case "4":
                        case "5":
                            SaveOrUpdateData(db, mesShtzd, shtzdDetails);
                            break;
                        case "3":
                            UpdateData(db, mesShtzd, shtzdDetails);
                            break;
                        default:
                            throw new NotImplementedException($"类型 Type = {SH.Type} æš‚不支持处理");
                    }
                }
                return shList.Count;
            }) > 0;
        }
        public Shtzd GetMesShtzd(ErpShzd sh)
        {
            return new Shtzd
            {
                ID = Convert.ToInt32(sh.ERPID),
                Deliveryno = sh.FBillNo,
                Depotno = sh.FStockID,
                Supplierid = sh.FSupplierId,
                Fdate = sh.FDate,
                Remark = sh.FNote,
                FZjxfSfgx = sh.F_ZJXF_sfgx
            };
        }
        public List<ShtzdDetail> GetMesShtzdDetail(List<ErpShzdDetail> erpShzdDetails)
        {
            return erpShzdDetails.Select(s => new ShtzdDetail
            {
                Erpid = Convert.ToInt32(s.ERPID),
                Eid = Convert.ToInt32(s.EID),
                Lineno = s.LineNo,
                Fbillno = s.FORDERBILLNO,
                Productcode = s.FMATERIALID,
                Purchaseqty = s.FPOQTY,
                Deliveryqty = s.FACTRECEIVEQTY,
                Includeqty = s.FACTREQTY,
                Purchaseunit = s.FUNITID,
                Inventoryunit = s.FSTOCKUNITID,
                Remark = s.FDESCRIPTION,
                Salesorderid = s.FSRCBILLNO,
                Orderlineid = s.FSRCENTRYID,
                Fxshth = s.FXSHTH,
                Fmtono = s.FMtoNo,
                Flot = s.FLot
            }).ToList();
        }
        protected int UseTransaction(Func<SqlSugarScope, int> action)
        {
            try
            {
                Db.Ado.BeginTran();
                var affectedRows = action.Invoke(Db);
                Db.Ado.CommitTran();
                return affectedRows;
            }
            catch (Exception)
            {
                Db.Ado.RollbackTran();
                throw;
            }
        }
        private bool SaveOrUpdateData(SqlSugarScope db, Shtzd header, List<ShtzdDetail> details)
        {
            var exists = db.Queryable<Shtzd>().Any(x => x.ID == header.ID);
            if (exists)
            {
                db.Updateable(header).ExecuteCommand();
                db.Deleteable<ShtzdDetail>().Where(x => x.Eid == header.ID).ExecuteCommand();
            }
            else
            {
                db.Insertable(header).ExecuteCommand();
            }
            foreach (var item in details)
            {
                item.Eid = header.ID;
            }
            db.Insertable(details).ExecuteCommand();
            return true;
        }
        private bool UpdateData(SqlSugarScope db, Shtzd header, List<ShtzdDetail> details)
        {
            db.Updateable(header).ExecuteCommand();
            db.Deleteable<ShtzdDetail>().Where(x => x.Eid == header.ID).ExecuteCommand();
            foreach (var item in details)
            {
                item.Eid = header.ID;
            }
            db.Insertable(details).ExecuteCommand();
            return true;
        }
    }
}
StandardInterface/MESApplication/Controllers/ShtzdController.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,264 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Dynamic;
using MES.Service.Modes;
using MES.Service.service;
using MES.Service.util;
using MES.Service.Dto.webApi;
using Newtonsoft.Json;
namespace MESApplication.Controllers
{
    [ApiController]
    [Route("api/[controller]")]
    public class ShtzdController : ControllerBase
    {
        private ShtzdManager m = new ShtzdManager();
        private readonly MessageCenterManager _manager = new();
        private readonly Shtzd Tz = new();
        private readonly string METHOD = "POST";
        private readonly string TableName = "SHTZD";
        private readonly string URL = "http://localhost:10054/api/Shtzd/";
        [HttpPost("Save")]
        public ResponseResult Save(Sh Sh)
        {
            var entity = new MessageCenter();
            entity.TableName = TableName;
            entity.Url = URL + "Save";
            entity.Method = METHOD;
            entity.Data = JsonConvert.SerializeObject(Sh);
            entity.Status = 1;
            entity.CreateBy = "PL017";
            try
            {
                dynamic resultInfos = new ExpandoObject();
                var save = m.Save(Sh);
                resultInfos.tbBillList = save;
                entity.Result = 0;
                if (save) entity.Result = 1;
                entity.DealWith = 1;
                _manager.save(entity);
                return new ResponseResult
                {
                    status = 0,
                    message = "OK",
                    data = resultInfos
                };
            }
            catch (Exception ex)
            {
                entity.Result = 0;
                entity.DealWith = 0;
                entity.ResultData = ex.Message;
                _manager.save(entity);
                return ResponseResult.ResponseError(ex);
            }
        }
        [HttpPost("SaveList")]
        public ResponseResult SaveList(List<Sh> units)
        {
            var entity = new MessageCenter();
            entity.TableName = TableName;
            entity.Url = URL + "SaveList";
            entity.Method = METHOD;
            entity.Data = JsonConvert.SerializeObject(units);
            entity.Status = 1;
            entity.CreateBy = "PL017";
            try
            {
                dynamic resultInfos = new ExpandoObject();
                var save = m.SaveList(units);
                resultInfos.tbBillList = save;
                entity.Result = 0;
                if (save) entity.Result = 1;
                entity.DealWith = 1;
                _manager.save(entity);
                return new ResponseResult
                {
                    status = 0,
                    message = "OK",
                    data = resultInfos
                };
            }
            catch (Exception ex)
            {
                entity.Result = 0;
                entity.DealWith = 0;
                entity.ResultData = ex.Message;
                _manager.save(entity);
                return ResponseResult.ResponseError(ex);
            }
        }
        /// <summary>
        /// èŽ·å–æ‰€æœ‰
        /// </summary>
        /// <returns></returns>
        [HttpPost("GetList")]
        public ResponseResult GetList()
        {
            try
            {
                dynamic resultInfos = new ExpandoObject();
                resultInfos.tbBillList = m.GetList();
                return new ResponseResult
                {
                    status = 0,
                    message = "OK",
                    data = resultInfos
                };
            }
            catch (Exception ex)
            {
                return ResponseResult.ResponseError(ex);
            }
        }
        /// <summary>
        /// æ ¹æ®ä¸»é”®èŽ·å–
        /// </summary>
        /// <returns></returns>
        [HttpPost("GetById")]
        public ResponseResult GetById(int id)
        {
            try
            {
                dynamic resultInfos = new ExpandoObject();
                resultInfos.tbBillList = m.GetById(id);
                return new ResponseResult
                {
                    status = 0,
                    message = "OK",
                    data = resultInfos
                };
            }
            catch (Exception ex)
            {
                return ResponseResult.ResponseError(ex);
            }
        }
        /// <summary>
        /// æ ¹æ®ä¸»é”®åˆ é™¤
        /// </summary>
        /// <returns></returns>
        [HttpPost("DeleteByIds")]
        public ResponseResult DeleteByIds([FromBody] object[] ids)
        {
            try
            {
                dynamic resultInfos = new ExpandoObject();
                resultInfos.tbBillList = m.DeleteByIds(ids);
                return new ResponseResult
                {
                    status = 0,
                    message = "OK",
                    data = resultInfos
                };
            }
            catch (Exception ex)
            {
                return ResponseResult.ResponseError(ex);
            }
        }
        /// <summary>
        /// æ·»åŠ 
        /// </summary>
        /// <returns></returns>
        [HttpPost("Insert")]
        public ResponseResult Add([FromBody] Shtzd data)
        {
            try
            {
                dynamic resultInfos = new ExpandoObject();
                resultInfos.tbBillList = m.Insert(data);
                return new ResponseResult
                {
                    status = 0,
                    message = "OK",
                    data = resultInfos
                };
            }
            catch (Exception ex)
            {
                return ResponseResult.ResponseError(ex);
            }
        }
        /// <summary>
        /// æ·»åŠ è¿”å›žè‡ªå¢ž
        /// </summary>
        /// <returns></returns>
        [HttpPost("InsertReturnIdentity")]
        public ResponseResult InsertReturnIdentity([FromBody] Shtzd data)
        {
            try
            {
                dynamic resultInfos = new ExpandoObject();
                resultInfos.tbBillList = m.InsertReturnIdentity(data);
                return new ResponseResult
                {
                    status = 0,
                    message = "OK",
                    data = resultInfos
                };
            }
            catch (Exception ex)
            {
                return ResponseResult.ResponseError(ex);
            }
        }
        /// <summary>
        /// ä¿®æ”¹
        /// </summary>
        /// <returns></returns>
        [HttpPost("Update")]
        public ResponseResult Update([FromBody] Shtzd data)
        {
            try
            {
                dynamic resultInfos = new ExpandoObject();
                resultInfos.tbBillList = m.Update(data);
                return new ResponseResult
                {
                    status = 0,
                    message = "OK",
                    data = resultInfos
                };
            }
            catch (Exception ex)
            {
                return ResponseResult.ResponseError(ex);
            }
        }
    }
}