From 9aa2afe228a7a3e5734916c7126587a94379c775 Mon Sep 17 00:00:00 2001
From: hao <1836460075@qq.com>
Date: 星期一, 28 四月 2025 10:42:29 +0800
Subject: [PATCH] 1
---
StandardInterface/MES.Service/Dto/webApi/ErpShzdDetail.cs | 24 ++
StandardInterface/MES.Service/service/ShtzdManager.cs | 144 ++++++++++++++
StandardInterface/MESApplication/Controllers/ShtzdController.cs | 264 ++++++++++++++++++++++++++
StandardInterface/MES.Service/Modes/Shtzd.cs | 50 +++++
StandardInterface/MES.Service/Dto/webApi/ErpShzd.cs | 14 +
StandardInterface/MES.Service/Modes/ShtzdDetail.cs | 94 +++++++++
StandardInterface/MES.Service/Dto/webApi/Sh.cs | 7
7 files changed, 597 insertions(+), 0 deletions(-)
diff --git a/StandardInterface/MES.Service/Dto/webApi/ErpShzd.cs b/StandardInterface/MES.Service/Dto/webApi/ErpShzd.cs
new file mode 100644
index 0000000..24a29ac
--- /dev/null
+++ b/StandardInterface/MES.Service/Dto/webApi/ErpShzd.cs
@@ -0,0 +1,14 @@
+锘縩amespace 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; } //鏄惁渚涘崗
+
+}
\ No newline at end of file
diff --git a/StandardInterface/MES.Service/Dto/webApi/ErpShzdDetail.cs b/StandardInterface/MES.Service/Dto/webApi/ErpShzdDetail.cs
new file mode 100644
index 0000000..4c3760b
--- /dev/null
+++ b/StandardInterface/MES.Service/Dto/webApi/ErpShzdDetail.cs
@@ -0,0 +1,24 @@
+锘縩amespace 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; } //閲囪喘鍗旾D
+ public string? FSRCENTRYID { get; set; } //閲囪喘鍗曡ID
+ public string? FXSHTH { get; set; } //閿�鍞鍗曞彿
+ public string? FMtoNo{ get; set; } //璁″垝璺熻釜鍙�
+ public string? FLot { get; set; } //鎵瑰彿
+
+
+}
\ No newline at end of file
diff --git a/StandardInterface/MES.Service/Dto/webApi/Sh.cs b/StandardInterface/MES.Service/Dto/webApi/Sh.cs
new file mode 100644
index 0000000..3c0e2d3
--- /dev/null
+++ b/StandardInterface/MES.Service/Dto/webApi/Sh.cs
@@ -0,0 +1,7 @@
+锘縩amespace MES.Service.Dto.webApi;
+
+public class Sh
+{
+ public ErpShzd ErpShtzd { get; set; }
+ public List<ErpShzdDetail> ErpShzdDetail { get; set; }
+}
\ No newline at end of file
diff --git a/StandardInterface/MES.Service/Modes/Shtzd.cs b/StandardInterface/MES.Service/Modes/Shtzd.cs
new file mode 100644
index 0000000..4e983d0
--- /dev/null
+++ b/StandardInterface/MES.Service/Modes/Shtzd.cs
@@ -0,0 +1,50 @@
+锘縰sing 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; }
+ }
+}
diff --git a/StandardInterface/MES.Service/Modes/ShtzdDetail.cs b/StandardInterface/MES.Service/Modes/ShtzdDetail.cs
new file mode 100644
index 0000000..71195c9
--- /dev/null
+++ b/StandardInterface/MES.Service/Modes/ShtzdDetail.cs
@@ -0,0 +1,94 @@
+锘縰sing 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; }
+ }
+}
diff --git a/StandardInterface/MES.Service/service/ShtzdManager.cs b/StandardInterface/MES.Service/service/ShtzdManager.cs
new file mode 100644
index 0000000..0d0ec6c
--- /dev/null
+++ b/StandardInterface/MES.Service/service/ShtzdManager.cs
@@ -0,0 +1,144 @@
+锘縰sing 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;
+ }
+ }
+}
diff --git a/StandardInterface/MESApplication/Controllers/ShtzdController.cs b/StandardInterface/MESApplication/Controllers/ShtzdController.cs
new file mode 100644
index 0000000..1463422
--- /dev/null
+++ b/StandardInterface/MESApplication/Controllers/ShtzdController.cs
@@ -0,0 +1,264 @@
+锘縰sing 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);
+ }
+ }
+ }
+}
--
Gitblit v1.9.3