StandardInterface/MES.Service/Dto/webApi/ErpShzd.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
StandardInterface/MES.Service/Dto/webApi/ErpShzdDetail.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
StandardInterface/MES.Service/Dto/webApi/Sh.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
StandardInterface/MES.Service/Modes/Shtzd.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
StandardInterface/MES.Service/Modes/ShtzdDetail.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
StandardInterface/MES.Service/service/ShtzdManager.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
StandardInterface/MESApplication/Controllers/ShtzdController.cs | ●●●●● 补丁 | 查看 | 原始文档 | 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); } } } }