From 4e045ea0364774a6ac20a18491653ff0c9d77ea4 Mon Sep 17 00:00:00 2001
From: cdk <2441919651@qq.com>
Date: 星期二, 02 九月 2025 17:36:16 +0800
Subject: [PATCH] 增加工厂日期接口代码
---
MESApplication/Controllers/BasicData/MesFactoryDateController.cs | 223 +++++++++++++++++++++++++++
MES.Service/service/BasicData/MesFactoryDateManager.cs | 130 ++++++++++++++++
MES.Service/Modes/MesFactoryDate.cs | 53 ++++++
MES.Service/Dto/webApi/ErpFactoryDate.cs | 29 +++
4 files changed, 435 insertions(+), 0 deletions(-)
diff --git a/MES.Service/Dto/webApi/ErpFactoryDate.cs b/MES.Service/Dto/webApi/ErpFactoryDate.cs
new file mode 100644
index 0000000..76a5047
--- /dev/null
+++ b/MES.Service/Dto/webApi/ErpFactoryDate.cs
@@ -0,0 +1,29 @@
+锘縩amespace MES.Service.Dto.webApi;
+
+/// <summary>
+/// ERP宸ュ巶鏃ユ湡浼犺緭瀵硅薄
+/// </summary>
+public class ErpFactoryDate
+{
+ /// <summary>鎿嶄綔绫诲瀷</summary>
+ public string? Type { get; set; }
+ /// <summary>鍗曟嵁鐘舵��</summary>
+ public string? FDocumentStatus { get; set; }
+ /// <summary>绂佺敤鐘舵��</summary>
+ public string? FForbidStatus { get; set; }
+ /// <summary>ERP涓婚敭</summary>
+ public string? ErpId { get; set; }
+ /// <summary>搴忓彿</summary>
+ public string? FSeq { get; set; }
+ /// <summary>浣跨敤缁勭粐</summary>
+ public string? FUseOrgId { get; set; }
+ /// <summary>鏃ユ湡</summary>
+ public string? FDay { get; set; }
+ /// <summary>鏃ユ湡绫诲瀷</summary>
+ public string? FDateStyle { get; set; }
+ /// <summary>鏄惁鐢熶骇</summary>
+ public string? FIsWorkTime { get; set; }
+
+ /// <summary>鏃ユ湡鍐呯爜</summary>
+ public string? FInterId { get; set; }
+}
\ No newline at end of file
diff --git a/MES.Service/Modes/MesFactoryDate.cs b/MES.Service/Modes/MesFactoryDate.cs
new file mode 100644
index 0000000..c8e6d4d
--- /dev/null
+++ b/MES.Service/Modes/MesFactoryDate.cs
@@ -0,0 +1,53 @@
+锘縰sing SqlSugar;
+
+namespace MES.Service.Modes;
+
+/// <summary>
+/// MES宸ュ巶鏃ユ湡瀹炰綋
+/// </summary>
+[SugarTable("MES_FactoryDate")]
+public class MesFactoryDate
+{
+ /// <summary>
+ /// 榛樿鍊�: (newid())
+ /// </summary>
+ [SugarColumn(ColumnName = "guid", IsPrimaryKey = true)]
+ public Guid Guid { get; set; }
+
+ /// <summary>鍗曟嵁鐘舵��</summary>
+ [SugarColumn(ColumnName = "FDocumentStatus")]
+ public string? FDocumentStatus { get; set; }
+
+ /// <summary>鏄惁绂佺敤</summary>
+ [SugarColumn(ColumnName = "FForbidStatus")]
+ public string? FForbidStatus { get; set; }
+
+ /// <summary>ERP涓婚敭</summary>
+ [SugarColumn(ColumnName = "ErpId")]
+ public string? ErpId { get; set; }
+
+ /// <summary>搴忓彿</summary>
+ [SugarColumn(ColumnName = "Seq")]
+ public string? Seq { get; set; }
+
+ /// <summary>缁勭粐鏈烘瀯Id</summary>
+ [SugarColumn(ColumnName = "OrgId")]
+ public string? OrgId { get; set; }
+
+ /// <summary>鏃ユ湡</summary>
+ [SugarColumn(ColumnName = "FactoryDate")]
+ public string? FactoryDate { get; set; }
+
+ /// <summary>鏃ユ湡绫诲瀷</summary>
+ [SugarColumn(ColumnName = "DateType")]
+ public string? DateType { get; set; }
+
+ /// <summary>鏄惁鐢熶骇</summary>
+ [SugarColumn(ColumnName = "IsWork")]
+ public string? IsWork { get; set; }
+
+ /// <summary>鏃ユ湡鍐呯爜</summary>
+ [SugarColumn(ColumnName = "InterId")]
+ public string? InterId { get; set; }
+ [SugarColumn(IsIgnore = true)] public string? Type { get; set; }
+}
\ No newline at end of file
diff --git a/MES.Service/service/BasicData/MesFactoryDateManager.cs b/MES.Service/service/BasicData/MesFactoryDateManager.cs
new file mode 100644
index 0000000..e26672d
--- /dev/null
+++ b/MES.Service/service/BasicData/MesFactoryDateManager.cs
@@ -0,0 +1,130 @@
+锘縰sing MES.Service.DB;
+using MES.Service.Dto.webApi;
+using MES.Service.Modes;
+using SqlSugar;
+using System.ComponentModel.DataAnnotations;
+
+namespace MES.Service.service.BasicData;
+
+public class MesFactoryDateManager : Repository<MesFactoryDate>
+{
+ public bool Save(ErpFactoryDate factoryDate)
+ {
+ var entity = ConvertToEntity(factoryDate);
+
+ return UseTransaction(db =>
+ {
+ switch (factoryDate.Type)
+ {
+ case "3":
+ // 鍒犻櫎
+ return DeleteFactoryDate(db, entity.ErpId) ? 1 : 0;
+ case "2":
+ case "4":
+ // 鏂板鎴栧悓姝�
+ return InsertOrUpdate(db, entity) ? 1 : 0;
+ default:
+ throw new ArgumentNullException($"type娌℃湁{factoryDate.Type}杩欎釜绫诲瀷鐨勫弬鏁�");
+ }
+ }) > 0;
+ }
+
+ public bool SaveList(List<ErpFactoryDate> factoryDates)
+ {
+ var list = factoryDates.Select(ConvertToEntity).ToList();
+ var groupBy = list.GroupBy(s => s.Type)
+ .ToDictionary(g => g.Key, g => g.ToList());
+
+ return UseTransaction(db =>
+ {
+ foreach (var group in groupBy)
+ {
+ switch (group.Key)
+ {
+ case "3":
+ if (!DeleteFactoryDateBatch(db, group.Value))
+ throw new NotImplementedException("鍒犻櫎澶辫触");
+ break;
+ case "2":
+ case "4":
+ if (!InsertOrUpdateBatch(db, group.Value))
+ throw new NotImplementedException("鍚屾澶辫触");
+ break;
+ default:
+ throw new ArgumentNullException($"type娌℃湁{group.Key}杩欎釜绫诲瀷鐨勫弬鏁�");
+ }
+ }
+ return 1;
+ }) > 0;
+ }
+
+ private MesFactoryDate ConvertToEntity(ErpFactoryDate dto)
+ {
+ string DateType = "";
+ switch (dto.FDateStyle)
+ {
+ case "1":
+ DateType = "宸ヤ綔鏃�";
+ break;
+ case "2":
+ DateType = "浼戞伅鏃�";
+ break;
+ case "3":
+ DateType = "娉曞畾鑺傚亣鏃�";
+ break;
+ case "4":
+ DateType = "绌�";
+ break;
+ }
+ return new MesFactoryDate
+ {
+ Guid = Guid.NewGuid(),
+ Type = dto.Type,
+ FDocumentStatus = dto.FDocumentStatus,
+ FForbidStatus = dto.FForbidStatus,
+ ErpId = dto.ErpId,
+ Seq = dto.FSeq,
+ OrgId = dto.FUseOrgId,
+ FactoryDate = dto.FDay,
+ DateType = DateType,
+ IsWork = dto.FIsWorkTime,
+ InterId = dto.FInterId
+ };
+ }
+
+ private bool DeleteFactoryDate(SqlSugarScope db, string? erpId)
+ {
+ var result = db.Deleteable<MesFactoryDate>()
+ .Where(s => s.ErpId == erpId).ExecuteCommand();
+ if (result > 0)
+ return true;
+
+ throw new NotImplementedException("鍒犻櫎澶辫触");
+ }
+
+ private bool DeleteFactoryDateBatch(SqlSugarScope db, List<MesFactoryDate> list)
+ {
+ var erpIds = list.Select(it => it.ErpId).ToArray();
+ var result = db.Deleteable<MesFactoryDate>()
+ .Where(s => erpIds.Contains(s.ErpId)).ExecuteCommand();
+ if (result > 0)
+ return true;
+
+ throw new NotImplementedException("鍒犻櫎澶辫触");
+ }
+
+ private bool InsertOrUpdate(SqlSugarScope db, MesFactoryDate entity)
+ {
+ db.Deleteable<MesFactoryDate>().Where(s => s.ErpId == entity.ErpId)
+ .ExecuteCommand();
+
+ var insert = db.Insertable(entity).ExecuteCommand();
+
+ return insert > 0;
+ }
+
+ private bool InsertOrUpdateBatch(SqlSugarScope db, List<MesFactoryDate> list)
+ {
+ return list.All(entity => InsertOrUpdate(db, entity));
+ }
+}
\ No newline at end of file
diff --git a/MESApplication/Controllers/BasicData/MesFactoryDateController.cs b/MESApplication/Controllers/BasicData/MesFactoryDateController.cs
new file mode 100644
index 0000000..eddefce
--- /dev/null
+++ b/MESApplication/Controllers/BasicData/MesFactoryDateController.cs
@@ -0,0 +1,223 @@
+锘縰sing System.Dynamic;
+using MES.Service.Dto.webApi;
+using MES.Service.Modes;
+using MES.Service.service;
+using MES.Service.service.BasicData;
+using MES.Service.util;
+using Microsoft.AspNetCore.Mvc;
+using Newtonsoft.Json;
+
+namespace MESApplication.Controllers.BasicData;
+
+[ApiController]
+[Route("api/[controller]")]
+public class MesFactoryDateController : ControllerBase
+{
+ private readonly MessageCenterManager _manager = new();
+ private readonly MesFactoryDateManager m = new();
+
+ private readonly string METHOD = "POST";
+ private readonly string TableName = "MES_FACTORYDATE";
+ private readonly string URL = "http://localhost:10054/api/MesFactoryDate/";
+
+ [HttpPost("Save")]
+ public ResponseResult Save(ErpFactoryDate unit)
+ {
+ var entity = new MessageCenter();
+ entity.TableName = TableName;
+ entity.Url = URL + "Save";
+ entity.Method = METHOD;
+ entity.Data = JsonConvert.SerializeObject(unit);
+ entity.Status = 1;
+ entity.CreateBy = "PL017";
+ entity.Route = unit.ErpId;
+ try
+ {
+ dynamic resultInfos = new ExpandoObject();
+ var save = m.Save(unit);
+ 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<ErpFactoryDate> 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);
+ }
+ }
+
+ [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);
+ }
+ }
+
+ [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);
+ }
+ }
+
+ [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);
+ }
+ }
+
+ [HttpPost("Insert")]
+ public ResponseResult Add([FromBody] MesFactoryDate 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);
+ }
+ }
+
+ [HttpPost("InsertReturnIdentity")]
+ public ResponseResult InsertReturnIdentity([FromBody] MesFactoryDate 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);
+ }
+ }
+
+ [HttpPost("Update")]
+ public ResponseResult Update([FromBody] MesFactoryDate 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);
+ }
+ }
+}
\ No newline at end of file
--
Gitblit v1.9.3