如洲 陈
2025-10-30 87bdc068d2135c27fa23732bab14ac297787e6e5
单位转换接口和委外工单变更修改
已修改1个文件
已添加4个文件
641 ■■■■■ 文件已修改
MES.Service/Dto/webApi/ErpUnitZh.cs 66 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MES.Service/Modes/MesUnitZh.cs 79 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MES.Service/service/BasicData/MesUnitZhManager.cs 183 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MES.Service/service/BasicData/ProductionOrderManager.cs 54 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MESApplication/Controllers/BasicData/MesUnitZhController.cs 259 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MES.Service/Dto/webApi/ErpUnitZh.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,66 @@
namespace MES.Service.Dto.webApi;
/// <summary>
///     ERP单位转换数据接收对象
/// </summary>
public class ErpUnitZh
{
    /// <summary>
    ///     ç‰©æ–™id (FDWA001)
    /// </summary>
    public string? FDWA001 { get; set; }
    /// <summary>
    ///     ç‰©æ–™åç§° (FDWA002)
    /// </summary>
    public string? FDWA002 { get; set; }
    /// <summary>
    ///     ç‰©æ–™ç¼–码 (FDWA003)
    /// </summary>
    public string? FDWA003 { get; set; }
    /// <summary>
    ///     æ¢ç®—分子 (FDWA004)
    /// </summary>
    public decimal? FDWA004 { get; set; }
    /// <summary>
    ///     è½¬æ¢å•位id (FDWA005)
    /// </summary>
    public string? FDWA005 { get; set; }
    /// <summary>
    ///     è½¬æ¢å•位 (FDWA006)
    /// </summary>
    public string? FDWA006 { get; set; }
    /// <summary>
    ///     æ¢ç®—关系 (FDWA007)
    /// </summary>
    public decimal? FDWA007 { get; set; }
    /// <summary>
    ///     åŸºå‡†å•位id (FDWA008)
    /// </summary>
    public string? FDWA008 { get; set; }
    /// <summary>
    ///     åŸºå‡†å•位 (FDWA009)
    /// </summary>
    public string? FDWA009 { get; set; }
    /// <summary>
    ///     ERPID (FDWA010)
    /// </summary>
    public string? FDWA010 { get; set; }
    /// <summary>
    ///     æ“ä½œç±»åž‹ (0=启用, 1=禁用, 2=新增, 3=删除, 4=更新)
    /// </summary>
    public string? Type { get; set; }
}
MES.Service/Modes/MesUnitZh.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,79 @@
using SqlSugar;
namespace MES.Service.Modes;
/// <summary>
///     å•位转换表
/// </summary>
[SugarTable("MES_UNIT_ZH")]
public class MesUnitZh
{
    /// <summary>
    ///     ä¸»é”®ID
    /// </summary>
    [SugarColumn(ColumnName = "ID", IsPrimaryKey = true)]
    public decimal Id { get; set; }
    /// <summary>
    ///     ç‰©æ–™id
    /// </summary>
    [SugarColumn(ColumnName = "DWA001")]
    public decimal? Dwa001 { get; set; }
    /// <summary>
    ///     ç‰©æ–™åç§°
    /// </summary>
    [SugarColumn(ColumnName = "DWA002")]
    public string? Dwa002 { get; set; }
    /// <summary>
    ///     ç‰©æ–™ç¼–码
    /// </summary>
    [SugarColumn(ColumnName = "DWA003")]
    public string? Dwa003 { get; set; }
    /// <summary>
    ///     æ¢ç®—分子
    /// </summary>
    [SugarColumn(ColumnName = "DWA004")]
    public decimal? Dwa004 { get; set; }
    /// <summary>
    ///     è½¬æ¢å•位id
    /// </summary>
    [SugarColumn(ColumnName = "DWA005")]
    public decimal? Dwa005 { get; set; }
    /// <summary>
    ///     è½¬æ¢å•位
    /// </summary>
    [SugarColumn(ColumnName = "DWA006")]
    public string? Dwa006 { get; set; }
    /// <summary>
    ///     æ¢ç®—关系
    /// </summary>
    [SugarColumn(ColumnName = "DWA007")]
    public decimal? Dwa007 { get; set; }
    /// <summary>
    ///     åŸºå‡†å•位id
    /// </summary>
    [SugarColumn(ColumnName = "DWA008")]
    public decimal? Dwa008 { get; set; }
    /// <summary>
    ///     åŸºå‡†å•位
    /// </summary>
    [SugarColumn(ColumnName = "DWA009")]
    public string? Dwa009 { get; set; }
    /// <summary>
    ///     ERPID
    /// </summary>
    [SugarColumn(ColumnName = "ERPID")]
    public decimal? Erpid { get; set; }
    [SugarColumn(IsIgnore = true)] public string? Type { get; set; }
}
MES.Service/service/BasicData/MesUnitZhManager.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,183 @@
using MES.Service.DB;
using MES.Service.Dto.webApi;
using MES.Service.Modes;
using SqlSugar;
namespace MES.Service.service.BasicData;
public class MesUnitZhManager : Repository<MesUnitZh>
{
    public bool Save(ErpUnitZh unit)
    {
        var entity = GetMesUnitZh(unit);
        return UseTransaction(db =>
        {
            switch (unit.Type)
            {
                case "0":
                    if (UpdateUnitZhStatus(db, entity.Id, "A"))
                        return 1;
                    break;
                case "1":
                    if (UpdateUnitZhStatus(db, entity.Id, "B"))
                        return 1;
                    break;
                case "3":
                    if (DeleteUnitZh(db, entity.Id))
                        return 1;
                    break;
                case "2":
                case "4":
                    if (InsertOrUpdate(db, entity))
                        return 1;
                    break;
                default:
                    throw new ArgumentNullException(
                        $"type没有{unit.Type}这个类型的参数");
            }
            throw new NotImplementedException("操作失败");
        }) > 0;
    }
    public bool SaveList(List<ErpUnitZh> units)
    {
        var list = units.Select(GetMesUnitZh).ToList();
        var groupBy = list.GroupBy(s => s.Type)
            .ToDictionary(g => g.Key, g => g.ToList());
        return UseTransaction(db =>
        {
            foreach (var unitGroup in groupBy)
                switch (unitGroup.Key)
                {
                    case "0":
                        if (!UpdateUnitZhStatusBatch(db, unitGroup.Value, "A"))
                            throw new NotImplementedException("启用失败");
                        break;
                    case "1":
                        if (!UpdateUnitZhStatusBatch(db, unitGroup.Value, "B"))
                            throw new NotImplementedException("禁用失败");
                        break;
                    case "3":
                        if (!DeleteUnitZhBatch(db, unitGroup.Value))
                            throw new NotImplementedException("删除失败");
                        break;
                    case "2":
                    case "4":
                        if (!InsertOrUpdateBatch(db, unitGroup.Value))
                            throw new NotImplementedException("同步失败");
                        break;
                    default:
                        throw new ArgumentNullException(
                            $"type没有{unitGroup.Key}这个类型的参数");
                }
            return 1;
        }) > 0;
    }
    private bool UpdateUnitZhStatus(SqlSugarScope db, decimal unitId,
        string status)
    {
        // æ³¨æ„ï¼šå¦‚æžœMesUnitZh表没有Fforbidstatus字段,需要根据实际情况调整
        // è¿™é‡Œå¯èƒ½éœ€è¦é€šè¿‡å…¶ä»–方式更新状态,或者暂时注释掉
        var result = db.Updateable<MesUnitZh>()
            .Where(s => s.Id == unitId).ExecuteCommand();
        if (result > 0)
            return true;
        throw new NotImplementedException(status == "A" ? "启用失败" : "禁用失败");
    }
    private bool InsertUnitZh(SqlSugarScope db, MesUnitZh entity)
    {
        var insert = db.Insertable(entity).ExecuteCommand();
        if (insert > 0)
            return true;
        throw new NotImplementedException("插入失败");
    }
    private bool DeleteUnitZh(SqlSugarScope db, decimal unitId)
    {
        var deleteById = db.Deleteable<MesUnitZh>().In(unitId).ExecuteCommand();
        if (deleteById > 0)
            return true;
        throw new NotImplementedException("删除失败");
    }
    private MesUnitZh GetMesUnitZh(ErpUnitZh unit)
    {
        return new MesUnitZh
        {
            Id = string.IsNullOrEmpty(unit.FDWA010) ? 0 : Convert.ToDecimal(unit.FDWA010),
            Dwa001 = string.IsNullOrEmpty(unit.FDWA001) ? null : Convert.ToDecimal(unit.FDWA001),
            Dwa002 = unit.FDWA002,
            Dwa003 = unit.FDWA003,
            Dwa004 = unit.FDWA004,
            Dwa005 = string.IsNullOrEmpty(unit.FDWA005) ? null : Convert.ToDecimal(unit.FDWA005),
            Dwa006 = unit.FDWA006,
            Dwa007 = unit.FDWA007,
            Dwa008 = string.IsNullOrEmpty(unit.FDWA008) ? null : Convert.ToDecimal(unit.FDWA008),
            Dwa009 = unit.FDWA009,
            Erpid = string.IsNullOrEmpty(unit.FDWA010) ? null : Convert.ToDecimal(unit.FDWA010),
            Type = unit.Type
        };
    }
    private bool UpdateUnitZhStatusBatch(SqlSugarScope db, List<MesUnitZh> unitList,
        string status)
    {
        var ids = unitList.Select(it => it.Id).ToArray();
        var result = db.Updateable<MesUnitZh>()
            .Where(s => ids.Contains(s.Id)).ExecuteCommand();
        if (result > 0)
            return true;
        throw new NotImplementedException(status == "A" ? "启用失败" : "禁用失败");
    }
    private bool InsertUnitZhBatch(SqlSugarScope db, List<MesUnitZh> unitList)
    {
        var insertRange = db.Insertable(unitList).ExecuteCommand();
        if (insertRange > 0)
            return true;
        throw new NotImplementedException("插入失败");
    }
    private bool DeleteUnitZhBatch(SqlSugarScope db, List<MesUnitZh> unitList)
    {
        var ids = unitList.Select(it => it.Id).ToArray();
        var deleteByIds = db.Deleteable<MesUnitZh>().In(ids).ExecuteCommand();
        return deleteByIds > 0;
    }
    /// <summary>
    /// æ’入或更新的方法:先删除再插入
    /// </summary>
    private bool InsertOrUpdate(SqlSugarScope db, MesUnitZh entity)
    {
        db.Deleteable<MesUnitZh>()
            .Where(s => s.Id == entity.Id)
            .ExecuteCommand();
        var insert = db.Insertable(entity).ExecuteCommand();
        return insert > 0;
    }
    private bool InsertOrUpdateBatch(SqlSugarScope db, List<MesUnitZh> unitList)
    {
        foreach (var entity in unitList)
            if (!InsertOrUpdate(db, entity))
                return false;
        return true;
    }
}
MES.Service/service/BasicData/ProductionOrderManager.cs
@@ -53,6 +53,31 @@
        womcaaWW.Caa001 = mesRohInDatas[0].Cab001;
        womcaaWW.Erpid = womcaaWW.FSUBENTRYID.ToInt32();
        //定义输入参数
        var inputParam1 = new SugarParameter("P_WORK_NO", womcaaWW.Caa001);
        // å®šä¹‰è¾“出参数
        var outParam1 = new SugarParameter("c_Result", null, true);
        var outParam2 = new SugarParameter("C_MSG", null, true);
        // ä½¿ç”¨ SqlSugar æ‰§è¡Œå­˜å‚¨è¿‡ç¨‹
        db.Ado.ExecuteCommand(
            "BEGIN PRC_UPDATE_DAA(:P_WORK_NO,:c_Result,:C_MSG); END;",
            inputParam1, outParam1, outParam2);
        // èŽ·å–è¾“å‡ºå‚æ•°çš„å€¼
        var result = int.Parse((string)outParam1.Value);
        var message = outParam2.Value == DBNull.Value
            ? string.Empty
            : (string)outParam2.Value;
        if (result == 1)
        {
            //存储过程失败则事务进行回滚
            db.Ado.RollbackTran();
            throw new Exception(message);
        }
        // æäº¤äº‹åŠ¡
        db.Ado.CommitTran();
        var decimals = mesRohInDatas.Select(s => s.Id).ToArray();
        var update = base.DeleteById(womcaaWW.Id);
        var insertOrUpdate = db
@@ -91,7 +116,34 @@
            .IgnoreColumnsNull()
            .ExecuteCommand() > 0;
        if (orUpdate && baOrUpdate) return true;
        if (orUpdate && baOrUpdate)
        {
            //定义输入参数
            var inputParam1 = new SugarParameter("P_WORK_NO", mesWomcaa.Caa001);
            // å®šä¹‰è¾“出参数
            var outParam1 = new SugarParameter("c_Result", null, true);
            var outParam2 = new SugarParameter("C_MSG", null, true);
            // ä½¿ç”¨ SqlSugar æ‰§è¡Œå­˜å‚¨è¿‡ç¨‹
            Db.Ado.ExecuteCommand(
                "BEGIN PRC_UPDATE_DAA(:P_WORK_NO,:c_Result,:C_MSG); END;",
                inputParam1, outParam1, outParam2);
            // èŽ·å–è¾“å‡ºå‚æ•°çš„å€¼
            var result = int.Parse((string)outParam1.Value);
            var message = outParam2.Value == DBNull.Value
                ? string.Empty
                : (string)outParam2.Value;
            if (result == 1)
            {
                //存储过程失败则事务进行回滚
                db.Ado.RollbackTran();
                throw new Exception(message);
            }
            // æäº¤äº‹åŠ¡
            db.Ado.CommitTran();
            return true;
        }
        throw new NotImplementedException("插入或更新失败");
    }
MESApplication/Controllers/BasicData/MesUnitZhController.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,259 @@
using 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 MesUnitZhController : ControllerBase
{
    private readonly MessageCenterManager _manager = new();
    private readonly MesUnitZhManager m = new();
    private readonly string METHOD = "POST";
    private readonly string TableName = "MES_UNIT_ZH";
    private readonly string URL = "http://localhost:10054/api/MesUnitZh/";
    [HttpPost("Save")]
    public ResponseResult Save(ErpUnitZh unit)
    {
        var entity = new MessageCenter();
        entity.TableName = TableName;
        entity.Url = URL + "Save";
        entity.Method = METHOD;
        entity.Route = unit.FDWA003;
        entity.Data = JsonConvert.SerializeObject(unit);
        entity.Status = 1;
        entity.CreateBy = "ERP";
        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<ErpUnitZh> 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 = "ERP";
        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] MesUnitZh 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] MesUnitZh 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] MesUnitZh 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);
        }
    }
}