From 18b4c6b6060d09e51382024a6e61fe9ef8f18a8c Mon Sep 17 00:00:00 2001
From: hao <1836460075@qq.com>
Date: 星期二, 16 九月 2025 10:28:20 +0800
Subject: [PATCH] 组织拆卸单测试
---
StandardInterface/MES.Service/Dto/webApi/ERPZZCXD.cs | 55 ++++++
StandardInterface/MESApplication/Controllers/ZZCXDController.cs | 103 +++++++++++
StandardInterface/MES.Service/service/ZZCXDManager.cs | 135 +++++++++++++++
StandardInterface/MES.Service/Modes/Zzcxa.cs | 132 ++++++++++++++
StandardInterface/MES.Service/Modes/Zzcxb.cs | 72 ++++++++
StandardInterface/MES.Service/Modes/MessageCenter.cs | 2
StandardInterface/MESApplication/appsettings.json | 2
7 files changed, 499 insertions(+), 2 deletions(-)
diff --git a/StandardInterface/MES.Service/Dto/webApi/ERPZZCXD.cs b/StandardInterface/MES.Service/Dto/webApi/ERPZZCXD.cs
new file mode 100644
index 0000000..214222e
--- /dev/null
+++ b/StandardInterface/MES.Service/Dto/webApi/ERPZZCXD.cs
@@ -0,0 +1,55 @@
+锘縰sing System.Collections.Generic;
+
+namespace MES.Service.Dto.webApi
+{
+ /// <summary>
+ /// ERP 浼犺緭鐨勫埗閫犳媶鍗稿崟锛堜富琛� + 鏄庣粏闆嗗悎锛�
+ /// </summary>
+ public class ERPZZCXD
+ {
+ public ERPZZCXA ERPZZCXA { get; set; } = new ERPZZCXA();
+ public List<ERPZZCXB> ERPZZCXB { get; set; } = new List<ERPZZCXB>();
+ }
+
+ /// <summary>
+ /// ERP 鍒堕�犳媶鍗稿崟 涓昏〃 DTO
+ /// </summary>
+ public class ERPZZCXA
+ {
+ public string? bill_no { get; set; } // 鍗曟嵁缂栫爜
+ public string? dj_lx { get; set; } // 鍗曟嵁绫诲瀷
+ public string? kc_zz { get; set; } // 搴撳瓨缁勭粐
+ public string? sw_lx { get; set; } // 浜嬪姟绫诲瀷
+ public string? time { get; set; } // 鏃ユ湡
+ public string? bm { get; set; } // 閮ㄩ棬
+ public string? cgy { get; set; } // 浠撶鍛�
+ public string? kcz { get; set; } // 搴撳瓨缁�
+ public string? dj_zt { get; set; } // 鍗曟嵁鐘舵��
+ public string? memo { get; set; } // 澶囨敞
+ public string? cphzlx { get; set; } // 鎴愬搧璐т富绫诲瀷
+ public string? cphz { get; set; } // 鎴愬搧璐т富
+ public string? zjhzlx { get; set; } // 瀛愪欢璐т富绫诲瀷
+ public string? zjhz { get; set; } // 瀛愪欢璐т富
+ public string? item_id { get; set; } // 鐗╂枡缂栫爜id
+ public string? qty { get; set; } // 鏁伴噺
+ public string? unit { get; set; } // 鍗曚綅
+ public string? depot_id { get; set; } // 浠撳簱
+ public string? erpid { get; set; } // ERP 涓昏〃id
+ public string? type { get; set; }
+ }
+
+ /// <summary>
+ /// ERP 鍒堕�犳媶鍗稿崟 鏄庣粏 DTO
+ /// </summary>
+ public class ERPZZCXB
+ {
+ public string? erpid { get; set; } // ERP 涓昏〃id
+ public string? eid { get; set; } // ERP 鍗曟嵁澶磇d
+ public string? item_id { get; set; } // 鐗╂枡缂栫爜id
+ public string? qty { get; set; } // 鏁伴噺
+ public string? unit { get; set; } // 鍗曚綅
+ public string? depot_id { get; set; } // 浠撳簱
+ public string? lot_no { get; set; } // 鎵瑰彿
+ public string? memo { get; set; } // 澶囨敞
+ }
+}
diff --git a/StandardInterface/MES.Service/Modes/MessageCenter.cs b/StandardInterface/MES.Service/Modes/MessageCenter.cs
index d485ada..fac11bb 100644
--- a/StandardInterface/MES.Service/Modes/MessageCenter.cs
+++ b/StandardInterface/MES.Service/Modes/MessageCenter.cs
@@ -10,7 +10,7 @@
/// <summary>
/// 瀵瑰簲搴忓垪SEQ_MSG
/// </summary>
- [SugarColumn(IsPrimaryKey = true, OracleSequenceName = "SEQ_MSG",
+ [SugarColumn(IsPrimaryKey = true, OracleSequenceName = "SEQ_MSG2",
ColumnName = "ID")]
public decimal? Id { get; set; }
diff --git a/StandardInterface/MES.Service/Modes/Zzcxa.cs b/StandardInterface/MES.Service/Modes/Zzcxa.cs
new file mode 100644
index 0000000..4b51bf0
--- /dev/null
+++ b/StandardInterface/MES.Service/Modes/Zzcxa.cs
@@ -0,0 +1,132 @@
+锘縰sing System;
+using SqlSugar;
+
+namespace MES.Service.Modes
+{
+ /// <summary>
+ /// ZZCXA 涓昏〃
+ /// </summary>
+ [SugarTable("ZZCXA")]
+ public class Zzcxa
+ {
+ /// <summary>
+ /// 涓婚敭ID
+ /// </summary>
+ [SugarColumn(ColumnName = "ID", IsPrimaryKey = true, OracleSequenceName = "SEQ_ZZCXA")]
+ public decimal? Id { get; set; }
+
+ /// <summary>
+ /// 鍗曟嵁缂栫爜
+ /// </summary>
+ [SugarColumn(ColumnName = "BILL_NO")]
+ public string BillNo { get; set; }
+
+ /// <summary>
+ /// 鍗曟嵁绫诲瀷
+ /// </summary>
+ [SugarColumn(ColumnName = "DJ_LX")]
+ public string DjLx { get; set; }
+
+ /// <summary>
+ /// 搴撳瓨缁勭粐
+ /// </summary>
+ [SugarColumn(ColumnName = "KC_ZZ")]
+ public string KcZz { get; set; }
+
+ /// <summary>
+ /// 浜嬪姟绫诲瀷
+ /// </summary>
+ [SugarColumn(ColumnName = "SW_LX")]
+ public string SwLx { get; set; }
+
+ /// <summary>
+ /// 鏃ユ湡
+ /// </summary>
+ [SugarColumn(ColumnName = "TIME")]
+ public string Time { get; set; }
+
+ /// <summary>
+ /// 閮ㄩ棬
+ /// </summary>
+ [SugarColumn(ColumnName = "BM")]
+ public string Bm { get; set; }
+
+ /// <summary>
+ /// 浠撶鍛�
+ /// </summary>
+ [SugarColumn(ColumnName = "CGY")]
+ public string Cgy { get; set; }
+
+ /// <summary>
+ /// 搴撳瓨缁�
+ /// </summary>
+ [SugarColumn(ColumnName = "KCZ")]
+ public string Kcz { get; set; }
+
+ /// <summary>
+ /// 鍗曟嵁鐘舵��
+ /// </summary>
+ [SugarColumn(ColumnName = "DJ_ZT")]
+ public string DjZt { get; set; }
+
+ /// <summary>
+ /// 澶囨敞
+ /// </summary>
+ [SugarColumn(ColumnName = "MEMO")]
+ public string Memo { get; set; }
+
+ /// <summary>
+ /// 鎴愬搧璐т富绫诲瀷
+ /// </summary>
+ [SugarColumn(ColumnName = "CPHZLX")]
+ public string Cphzlx { get; set; }
+
+ /// <summary>
+ /// 鎴愬搧璐т富
+ /// </summary>
+ [SugarColumn(ColumnName = "CPHZ")]
+ public string Cphz { get; set; }
+
+ /// <summary>
+ /// 瀛愪欢璐т富绫诲瀷
+ /// </summary>
+ [SugarColumn(ColumnName = "ZJHZLX")]
+ public string Zjhzlx { get; set; }
+
+ /// <summary>
+ /// 瀛愪欢璐т富
+ /// </summary>
+ [SugarColumn(ColumnName = "ZJHZ")]
+ public string Zjhz { get; set; }
+
+ /// <summary>
+ /// 鐗╂枡缂栫爜id
+ /// </summary>
+ [SugarColumn(ColumnName = "ITEM_ID")]
+ public decimal? ItemId { get; set; }
+
+ /// <summary>
+ /// 鏁伴噺
+ /// </summary>
+ [SugarColumn(ColumnName = "QTY")]
+ public decimal? Qty { get; set; }
+
+ /// <summary>
+ /// 鍗曚綅
+ /// </summary>
+ [SugarColumn(ColumnName = "UNIT")]
+ public string Unit { get; set; }
+
+ /// <summary>
+ /// 浠撳簱
+ /// </summary>
+ [SugarColumn(ColumnName = "DEPOT_ID")]
+ public string DepotId { get; set; }
+
+ /// <summary>
+ /// ERP 涓昏〃id
+ /// </summary>
+ [SugarColumn(ColumnName = "ERPID")]
+ public string Erpid { get; set; }
+ }
+}
diff --git a/StandardInterface/MES.Service/Modes/Zzcxb.cs b/StandardInterface/MES.Service/Modes/Zzcxb.cs
new file mode 100644
index 0000000..56d628b
--- /dev/null
+++ b/StandardInterface/MES.Service/Modes/Zzcxb.cs
@@ -0,0 +1,72 @@
+锘縰sing System;
+using SqlSugar;
+
+namespace MES.Service.Modes
+{
+ /// <summary>
+ /// ZZCXB 鏄庣粏琛�
+ /// </summary>
+ [SugarTable("ZZCXB")]
+ public class Zzcxb
+ {
+ /// <summary>
+ /// 涓婚敭ID
+ /// </summary>
+ [SugarColumn(ColumnName = "ID", IsPrimaryKey = true, OracleSequenceName = "SEQ_ZZCXB")]
+ public decimal? Id { get; set; }
+
+ /// <summary>
+ /// 涓昏〃ID
+ /// </summary>
+ [SugarColumn(ColumnName = "PID")]
+ public decimal? Pid { get; set; }
+
+ /// <summary>
+ /// ERP 涓昏〃id
+ /// </summary>
+ [SugarColumn(ColumnName = "ERPID")]
+ public string Erpid { get; set; }
+
+ /// <summary>
+ /// ERP 鍗曟嵁澶磇d
+ /// </summary>
+ [SugarColumn(ColumnName = "EID")]
+ public string Eid { get; set; }
+
+ /// <summary>
+ /// 鐗╂枡缂栫爜id
+ /// </summary>
+ [SugarColumn(ColumnName = "ITEM_ID")]
+ public decimal? ItemId { get; set; }
+
+ /// <summary>
+ /// 鏁伴噺
+ /// </summary>
+ [SugarColumn(ColumnName = "QTY")]
+ public decimal? Qty { get; set; }
+
+ /// <summary>
+ /// 鍗曚綅
+ /// </summary>
+ [SugarColumn(ColumnName = "UNIT")]
+ public string Unit { get; set; }
+
+ /// <summary>
+ /// 浠撳簱
+ /// </summary>
+ [SugarColumn(ColumnName = "DEPOT_ID")]
+ public string DepotId { get; set; }
+
+ /// <summary>
+ /// 鎵瑰彿
+ /// </summary>
+ [SugarColumn(ColumnName = "LOT_NO")]
+ public string LotNo { get; set; }
+
+ /// <summary>
+ /// 澶囨敞
+ /// </summary>
+ [SugarColumn(ColumnName = "MEMO")]
+ public string Memo { get; set; }
+ }
+}
diff --git a/StandardInterface/MES.Service/service/ZZCXDManager.cs b/StandardInterface/MES.Service/service/ZZCXDManager.cs
new file mode 100644
index 0000000..ff0136e
--- /dev/null
+++ b/StandardInterface/MES.Service/service/ZZCXDManager.cs
@@ -0,0 +1,135 @@
+锘縰sing 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 ZzcxdManager : Repository<Zzcxa>
+ {
+ public bool SaveList(List<ERPZZCXD> list)
+ {
+ var result = list.Select(Save).ToList();
+ return result.All(b => b);
+ }
+
+ public bool Save(ERPZZCXD data)
+ {
+ var head = MapErpToMesHead(data.ERPZZCXA);
+ var details = MapErpDbckbToDbckb(data.ERPZZCXB);
+
+ return UseTransaction(db =>
+ {
+ switch (data.ERPZZCXA.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.ERPZZCXA.type} 杩欎釜绫诲瀷");
+ }
+ }) > 0;
+ }
+
+ private Zzcxa MapErpToMesHead(ERPZZCXA dto)
+ {
+ var entity = new Zzcxa
+ {
+ BillNo = dto.bill_no, // 鍗曟嵁缂栫爜
+ DjLx = dto.dj_lx, // 鍗曟嵁绫诲瀷
+ KcZz = dto.kc_zz, // 搴撳瓨缁勭粐
+ SwLx = dto.sw_lx, // 浜嬪姟绫诲瀷
+ 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 = string.IsNullOrEmpty(dto.item_id) ? null : Convert.ToDecimal(dto.item_id), // 鐗╂枡缂栫爜id
+ Qty = string.IsNullOrEmpty(dto.qty) ? null : Convert.ToDecimal(dto.qty), // 鏁伴噺
+ Unit = dto.unit, // 鍗曚綅
+ DepotId = dto.depot_id, // 浠撳簱
+ Erpid = dto.erpid // ERP 涓昏〃id
+ };
+
+ var single = Db.Queryable<Zzcxa>()
+ .Where(it => it.Erpid == entity.Erpid)
+ .First();
+ if (single != null)
+ entity.Id = single.Id;
+
+ return entity;
+ }
+
+ private List<Zzcxb> MapErpDbckbToDbckb(List<ERPZZCXB> list)
+ {
+ var result = new List<Zzcxb>();
+
+ foreach (var dto in list)
+ {
+ var item = new Zzcxb
+ {
+ Erpid = dto.erpid, // ERP 涓昏〃id
+ Eid = dto.eid, // ERP 鍗曟嵁澶磇d
+ ItemId = string.IsNullOrEmpty(dto.item_id) ? null : Convert.ToDecimal(dto.item_id), // 鐗╂枡缂栫爜id
+ Qty = string.IsNullOrEmpty(dto.qty) ? null : Convert.ToDecimal(dto.qty), // 鏁伴噺
+ Unit = dto.unit, // 鍗曚綅
+ DepotId = dto.depot_id, // 浠撳簱
+ LotNo = dto.lot_no, // 鎵瑰彿
+ Memo = dto.memo // 澶囨敞
+ };
+
+ var existing = Db.Queryable<Zzcxb>().Where(s => s.Erpid == item.Erpid).Single();
+ if (existing != null) item.Id = existing.Id;
+
+ result.Add(item);
+ }
+
+ return result;
+ }
+
+ private bool SaveOrUpdateData(SqlSugarScope db, Zzcxa head, List<Zzcxb> details)
+ {
+ if (head.Id != null)
+ base.DeleteById(head.Id);
+
+ db.Deleteable<Zzcxb>()
+ .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, Zzcxa head, List<Zzcxb> details)
+ {
+ var ids = details.Select(d => d.Id).ToArray();
+ var deletedHead = base.DeleteById(head.Id);
+ var deletedDetails = db.Deleteable<Zzcxb>().In(ids).ExecuteCommand() > 0;
+
+ if (deletedHead && deletedDetails) return true;
+ throw new NotImplementedException("鏇存柊澶辫触");
+ }
+ }
+}
diff --git a/StandardInterface/MESApplication/Controllers/ZZCXDController.cs b/StandardInterface/MESApplication/Controllers/ZZCXDController.cs
new file mode 100644
index 0000000..96fe204
--- /dev/null
+++ b/StandardInterface/MESApplication/Controllers/ZZCXDController.cs
@@ -0,0 +1,103 @@
+锘縰sing 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 ZZCXDController : ControllerBase
+ {
+ private readonly ZzcxdManager _manager = new(); // 杩欓噷瀵瑰簲鏂扮殑 Service
+ private readonly MessageCenterManager _messageManager = new();
+
+ private const string METHOD = "POST";
+ private const string TableName = "ZZCXD";
+ private const string URL = "http://localhost:10054/api/ERPZZCXD/";
+
+ /// <summary>
+ /// 淇濆瓨鍗曟潯璋冩嫧鍗�
+ /// </summary>
+ [HttpPost("Save")]
+ public ResponseResult Save([FromBody] ERPZZCXD data)
+ {
+ var msg = new MessageCenter
+ {
+ TableName = TableName,
+ Url = URL + "Save",
+ Method = METHOD,
+ Data = JsonConvert.SerializeObject(data),
+ Status = 1,
+ CreateBy = "PL017",
+ Route = data.ERPZZCXA.bill_no // 娉ㄦ剰鍙� 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<ERPZZCXD> 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);
+ }
+ }
+ }
+}
diff --git a/StandardInterface/MESApplication/appsettings.json b/StandardInterface/MESApplication/appsettings.json
index 28cfc2a..59a3601 100644
--- a/StandardInterface/MESApplication/appsettings.json
+++ b/StandardInterface/MESApplication/appsettings.json
@@ -10,6 +10,6 @@
"AppSettings": {
"TestErpUrl": "http://192.168.11.120:8098/WebService1.asmx/mesToErpinfo",
"ProductionErpUrl": "http://192.168.11.120:8098/WebService1.asmx/mesToErpinfoFormal",
- "DataBaseConn": "Data Source = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.22)(PORT = 1521))(CONNECT_DATA = (SERVICE_NAME = ORCL))); Persist Security Info=True;User ID = hm_prd; Password=hmprd"
+ "DataBaseConn": "Data Source = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.22)(PORT = 1521))(CONNECT_DATA = (SERVICE_NAME = ORCL))); Persist Security Info=True;User ID = test_dev; Password=hmprd"
}
}
--
Gitblit v1.9.3