schangxiang@126.com
2025-09-17 9d9c5593801ed3356f976ac499a61a6673bd67ca
增加接口
已添加2个文件
已修改4个文件
470 ■■■■■ 文件已修改
DEmon/WebWIPAPI/Controllers/MesIntegrController.cs 208 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DEmon/iWareCommon/Utils/ClassHelper.cs 38 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DEmon/iWareCommon/iWareCommon.csproj 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DEmon/iWareDataCore/BASE/Entity/MaterialViewForMesEntity.cs 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DEmon/iWareDataCore/BASE/Service/MaterialViewService.cs 205 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DEmon/iWareDataCore/iWareDataCore.csproj 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DEmon/WebWIPAPI/Controllers/MesIntegrController.cs
@@ -1,12 +1,16 @@
using iWareDataCore.BASE.Entity;
using iWareCommon.Common.Entity;
using iWareCommon.Utils;
using iWareDataCore.BASE.Entity;
using iWareDataCore.BASE.Service;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Web.Mvc;
using WebWIPAPI.Models;
using WebWIPAPI.Properties;
using WebWIPAPI.Utils;
using LogTextHelper = WebWIPAPI.Utils.LogTextHelper;
namespace WebWIPAPI.Controllers
{
@@ -19,11 +23,6 @@
        /// <summary>
        /// æä¾›åº“存信息
        /// </summary>
        /// <param name="sysCode"></param>
        /// <param name="wareHouseInfo"></param>
        /// <param name="processCardNumber"></param>
        /// <param name="wareHouseId"></param>
        /// <param name="timestamp"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult syncMaterialInfo()
@@ -58,6 +57,199 @@
            return Json(responseMessage, JsonRequestBehavior.DenyGet);
        }
        /// <summary>
        /// å¯¼å…¥å…¥åº“单
        /// </summary>
        /// <param name="inputmaterials"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult importInOrder(List<MaterialViewForMesEntity> importMaterials)
        {
            var responseMessage = new ApiResponse<string>();
            var msg = "";
            #region ä¸šåŠ¡å¤„ç†
            //第一步:先新增到物料基础表
            List<MaterialViewEntity> materials = new List<MaterialViewEntity>();
            materials = ClassHelper.RotationMapping<List<MaterialViewEntity>, List<MaterialViewForMesEntity>>(importMaterials);
            MaterialViewService.GetInstance().ImportExcelFromMes(materials, out msg);
            Thread.Sleep(400);//注意:休眠毫秒,用于数据库事务提交
            string typeName = "入库";
            List<InputMaterialEntity> inputmaterials = new List<InputMaterialEntity>();
            inputmaterials = ClassHelper.RotationMapping<List<InputMaterialEntity>, List<MaterialViewForMesEntity>>(importMaterials);
            handler_importOutOrder(typeName, inputmaterials, out msg);
            #endregion
            if (!string.IsNullOrEmpty(msg))
            {
                responseMessage = new ApiResponse<string>()
                {
                    Code = 500,
                    Success = false,
                    Message = "异常:" + msg,
                    Data = null,
                };
            }
            else
            {
                responseMessage = new ApiResponse<string>()
                {
                    Code = 200,
                    Success = true,
                    Message = "成功",
                    Data = null,
                };
            }
            //将对象转化为json格式
            var responseStr = JsonConvert.SerializeObject(responseMessage);
            LogTextHelper.WriteLine(Resources.LogDir, "WIPAPI:{0},{1}, {2}", "importInOrder", "请求参数:" + "", "响应信息;" + responseStr);
            return Json(responseMessage, JsonRequestBehavior.DenyGet);
        }
        /// <summary>
        /// å¯¼å…¥å‡ºåº“单
        /// </summary>
        /// <param name="inputmaterials"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult importOutOrder(List<InputMaterialEntity> inputmaterials)
        {
            var responseMessage = new ApiResponse<string>();
            var msg = "";
            #region ä¸šåŠ¡å¤„ç†
            string typeName = "出库";
            handler_importOutOrder(typeName, inputmaterials, out msg);
            #endregion
            if (!string.IsNullOrEmpty(msg))
            {
                responseMessage = new ApiResponse<string>()
                {
                    Code = 500,
                    Success = false,
                    Message = "异常:" + msg,
                    Data = null,
                };
            }
            else
            {
                responseMessage = new ApiResponse<string>()
                {
                    Code = 200,
                    Success = true,
                    Message = "成功",
                    Data = null,
                };
            }
            //将对象转化为json格式
            var responseStr = JsonConvert.SerializeObject(responseMessage);
            LogTextHelper.WriteLine(Resources.LogDir, "WIPAPI:{0},{1}, {2}", "importOutOrder", "请求参数:" + "", "响应信息;" + responseStr);
            return Json(responseMessage, JsonRequestBehavior.DenyGet);
        }
        /// <summary>
        /// å…¬å…±å¯¼å…¥ å…¥åº“单或出库单
        /// </summary>
        /// <param name="typeName"></param>
        /// <param name="inputmaterials"></param>
        /// <param name="msg"></param>
        private void handler_importOutOrder(string typeName, List<InputMaterialEntity> inputmaterials, out string msg)
        {
            try
            {
                #region ä¸šåŠ¡å¤„ç†
                msg = "";
                //var inputmaterials = InputMaterialService.GetInstance().QueryByParam(new QueryParam { Filter = new Dictionary<string, object> { { "Status", "未生成" } } }, out msg);
                if (inputmaterials != null && inputmaterials.Count > 0)
                {
                    var placeMaterial = PlaceMaterialViewService.GetInstance().QueryByParam(new QueryParam { }, out msg);
                    var inoutdetails = InOutListDetailViewService.GetInstance().QueryByParam(new QueryParam { }, out msg);
                    List<string> codes = new List<string>();
                    inputmaterials.ForEach(x => codes.Add(x.Code));
                    List<int> ids = new List<int>();
                    var materials = InputMaterialService.GetInstance().GetIds(codes);
                    List<InOutListDetailEntity> detail = new List<InOutListDetailEntity>();
                    for (int i = 0; i < materials.Count; i++)
                    {
                        if (typeName == "入库")
                        {
                            if (placeMaterial.Select(x => x.MaterialId).Contains(materials[i].id))
                            {
                                msg = materials[i].code + "已存在立库中,不能添加到入库单明细中!";
                                break;
                            }
                            if (inoutdetails.Select(x => x.MaterialId).Contains(materials[i].id))
                            {
                                msg = materials[i].code + "已存在之前的入库单明细中,不能添加到当前入库单明细中!";
                                break;
                            }
                        }
                        else
                        {
                            if (!placeMaterial.Select(x => x.MaterialId).Contains(materials[i].id))
                            {
                                msg = materials[i].code + "不在立库中,不能添加到出库单明细中!";
                                break;
                            }
                            if (inoutdetails.Select(x => x.MaterialId).Contains(materials[i].id))
                            {
                                var inoutdeta = inoutdetails.FirstOrDefault(x => x.MaterialId == materials[i].id);
                                if (inoutdeta.TypeName == "出库")
                                {
                                    msg = materials[i].name + "已存在之前的出库单明细中,不能添加到当前出库单明细中!";
                                    break;
                                }
                            }
                        }
                        InOutListDetailEntity inoutdetail = new InOutListDetailEntity()
                        {
                            MaterialId = materials[i].id,
                            IsFinish = 0
                        };
                        detail.Add(inoutdetail);
                    }
                    if (!string.IsNullOrEmpty(msg))
                    {
                        return;
                    }
                    InOutListService.GetInstance().CreateListAndDetial(
                        new InOutListEntity
                        {
                            ListNo = inputmaterials.First().ListNo,
                            CreateTime = DateTime.Now,
                            TypeName = typeName,
                            Status = 0,
                            Remark = "",
                            InOutListDetail = detail
                        }, out msg);
                }
                else
                {
                    msg = ("请先确保出入库单物料明细不为空!");
                }
                #endregion
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
DEmon/iWareCommon/Utils/ClassHelper.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
namespace iWareCommon.Utils
{
    public class ClassHelper
    {
        /// <summary>
        /// å®žä½“互转
        /// </summary>
        /// <typeparam name="T">新转换的实体</typeparam>
        /// <typeparam name="S">要转换的实体</typeparam>
        /// <param name="s"></param>
        /// <returns></returns>
        public static T RotationMapping<T, S>(S s)
        {
            T target = Activator.CreateInstance<T>();
            var originalObj = s.GetType();
            var targetObj = typeof(T);
            foreach (PropertyInfo original in originalObj.GetProperties())
            {
                foreach (PropertyInfo t in targetObj.GetProperties())
                {
                    if (t.Name == original.Name)
                    {
                        t.SetValue(target, original.GetValue(s, null), null);
                    }
                }
            }
            return target;
        }
    }
}
DEmon/iWareCommon/iWareCommon.csproj
@@ -106,6 +106,7 @@
      <DependentUpon>Resources.resx</DependentUpon>
    </Compile>
    <Compile Include="Utils\Base64Helper.cs" />
    <Compile Include="Utils\ClassHelper.cs" />
    <Compile Include="Utils\DESHelper.cs" />
    <Compile Include="Utils\EntityPropHelper.cs" />
    <Compile Include="Utils\FileHelper.cs" />
DEmon/iWareDataCore/BASE/Entity/MaterialViewForMesEntity.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,17 @@
using iWareCommon.Common.Entity;
using iWareCommon.Utils;
using iWareDataCore.ORM;
using System;
using System.Collections.Generic;
using System.Linq;
namespace iWareDataCore.BASE.Entity
{
    public class MaterialViewForMesEntity : MaterialViewEntity
    {
        /// 7出入库单号
        /// </summary>
        public string ListNo { get; set; }
    }
}
DEmon/iWareDataCore/BASE/Service/MaterialViewService.cs
@@ -73,7 +73,7 @@
                    var codes = new List<string>();
                    List<MaterialEntity> materlst = new List<MaterialEntity>();
                    var materialSaves = new List<MaterialEntity>();
                    var existMaterialcodes = dbModel.BASEMaterials.Select(x =>x.code).ToList();
                    var existMaterialcodes = dbModel.BASEMaterials.Select(x => x.code).ToList();
                    bool b1 = true;
                    foreach (MaterialViewEntity m in materials)
                    {
@@ -81,14 +81,14 @@
                        if (string.IsNullOrEmpty(m.Code))
                        {
                            msg = string.Format("在第{0}行,物料号不能为空,请修改后重新导入", i + 1);
                            b1= false;
                            b1 = false;
                            break;
                        }
                        if (string.IsNullOrEmpty(m.Wide))
                        {
                            msg = string.Format("在第{0}行,宽不能为空,请修改后重新导入", i + 1);
                            b1= false;
                            b1 = false;
                            break;
                        }
                        var type = types.FirstOrDefault(x => x.name == m.TypeName);
@@ -96,7 +96,7 @@
                        {
                            m.MaterialType = 5;//其他
                        }
                        else
                        else
                        {
                            m.MaterialType = type.id;
                        }
@@ -107,8 +107,8 @@
                        codes.Add(m.Code);
                        if (string.IsNullOrEmpty(m.Name)) { m.Name = m.Description; }
                        if (string.IsNullOrEmpty(m.Version)) { m.Version = "00"; }
                        MaterialEntity mt=new MaterialEntity()
                        MaterialEntity mt = new MaterialEntity()
                        {
                            ClassificationSociety = m.ClassificationSociety,
                            Code = m.Code,
@@ -135,41 +135,41 @@
                            VerticalPosition = m.VerticalPosition,
                            Wide = m.Wide
                        };
                         materialSaves.Add(mt);
                        materialSaves.Add(mt);
                    }
                    if (!b1)
                    if (!b1)
                    {
                        return b1;
                    }
                    var sql = string.Format("INSERT INTO BASEMaterial(status, name, code, materialno, version, typeid, guaranteeperiod, cost, classificationsociety, unit, serialno, description, remark, verticalposition, weight, issueprojectno, procurementprojectno, cuttingtype, pageno, thick, wide, length, markingpen, laneseparation) VALUES");
                    for (var j = 0; j < materialSaves.Count ; j++)
                    for (var j = 0; j < materialSaves.Count; j++)
                    {
                               sql += string.Format("({0}, '{1}', '{2}', '{3}', {4}, '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}', '{12}', '{13}', '{14}', '{15}','{16}' ,'{17}', '{18}', '{19}', '{20}', '{21}','{22}','{23}' ),",
                                materialSaves[j].Status,
                                StringHelper.RelpaceQuot(materialSaves[j].Name),
                                StringHelper.RelpaceQuot(materialSaves[j].Code),
                                StringHelper.RelpaceQuot(materialSaves[j].MaterialNo),
                                StringHelper.RelpaceQuot(materialSaves[j].Version),
                                materialSaves[j].TypeId,
                                StringHelper.RelpaceQuot(materialSaves[j].GuaranteePeriod),
                                materialSaves[j].Cost,
                                StringHelper.RelpaceQuot(materialSaves[j].ClassificationSociety),
                                StringHelper.RelpaceQuot(materialSaves[j].Unit),
                                StringHelper.RelpaceQuot(materialSaves[j].SerialNo),
                                StringHelper.RelpaceQuot(materialSaves[j].Description),
                                StringHelper.RelpaceQuot(materialSaves[j].Remark),
                                StringHelper.RelpaceQuot(materialSaves[j].VerticalPosition),
                                StringHelper.RelpaceQuot(materialSaves[j].Weight),
                                StringHelper.RelpaceQuot(materialSaves[j].IssueProjectNo),
                                StringHelper.RelpaceQuot(materialSaves[j].ProcurementProjectNo),
                                StringHelper.RelpaceQuot(materialSaves[j].CuttingType),
                                StringHelper.RelpaceQuot(materialSaves[j].PageNo),
                                StringHelper.RelpaceQuot(materialSaves[j].Thick),
                                StringHelper.RelpaceQuot(materialSaves[j].Wide),
                                StringHelper.RelpaceQuot(materialSaves[j].Length),
                                StringHelper.RelpaceQuot(materialSaves[j].MarkingPen),
                                StringHelper.RelpaceQuot(materialSaves[j].LaneSeparation));
                        sql += string.Format("({0}, '{1}', '{2}', '{3}', {4}, '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}', '{12}', '{13}', '{14}', '{15}','{16}' ,'{17}', '{18}', '{19}', '{20}', '{21}','{22}','{23}' ),",
                         materialSaves[j].Status,
                         StringHelper.RelpaceQuot(materialSaves[j].Name),
                         StringHelper.RelpaceQuot(materialSaves[j].Code),
                         StringHelper.RelpaceQuot(materialSaves[j].MaterialNo),
                         StringHelper.RelpaceQuot(materialSaves[j].Version),
                         materialSaves[j].TypeId,
                         StringHelper.RelpaceQuot(materialSaves[j].GuaranteePeriod),
                         materialSaves[j].Cost,
                         StringHelper.RelpaceQuot(materialSaves[j].ClassificationSociety),
                         StringHelper.RelpaceQuot(materialSaves[j].Unit),
                         StringHelper.RelpaceQuot(materialSaves[j].SerialNo),
                         StringHelper.RelpaceQuot(materialSaves[j].Description),
                         StringHelper.RelpaceQuot(materialSaves[j].Remark),
                         StringHelper.RelpaceQuot(materialSaves[j].VerticalPosition),
                         StringHelper.RelpaceQuot(materialSaves[j].Weight),
                         StringHelper.RelpaceQuot(materialSaves[j].IssueProjectNo),
                         StringHelper.RelpaceQuot(materialSaves[j].ProcurementProjectNo),
                         StringHelper.RelpaceQuot(materialSaves[j].CuttingType),
                         StringHelper.RelpaceQuot(materialSaves[j].PageNo),
                         StringHelper.RelpaceQuot(materialSaves[j].Thick),
                         StringHelper.RelpaceQuot(materialSaves[j].Wide),
                         StringHelper.RelpaceQuot(materialSaves[j].Length),
                         StringHelper.RelpaceQuot(materialSaves[j].MarkingPen),
                         StringHelper.RelpaceQuot(materialSaves[j].LaneSeparation));
                    }
                    if (sql.EndsWith(","))
                    {
@@ -190,7 +190,144 @@
        }
        /// <summary>
        /// å¯¼å…¥ç‰©æ–™åŸºç¡€æ•°æ®ï¼Œæ¥æºMES ã€Editby shaocx,2025-09-17】
        /// </summary>
        /// <param name="materials"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public bool ImportExcelFromMes(List<MaterialViewEntity> materials, out string msg)
        {
            using (var dbModel = new DbModelCore())
            {
                try
                {
                    msg = "";
                    if (materials.Count < 1)
                    {
                        msg = "物料记录数为0,请修改后重新导入";
                        return false;
                    }
                    var types = dbModel.BASEMaterialTypes.Where(x => 1 == 1).ToList();
                    var i = 0;
                    var codes = new List<string>();
                    List<MaterialEntity> materlst = new List<MaterialEntity>();
                    var materialSaves = new List<MaterialEntity>();
                    var existMaterialcodes = dbModel.BASEMaterials.Select(x => x.code).ToList();
                    bool b1 = true;
                    foreach (MaterialViewEntity m in materials)
                    {
                        i += 1;
                        if (string.IsNullOrEmpty(m.Code))
                        {
                            msg = string.Format("在第{0}行,物料号不能为空,请修改后重新导入", i + 1);
                            b1 = false;
                            break;
                        }
                        if (string.IsNullOrEmpty(m.Wide))
                        {
                            msg = string.Format("在第{0}行,宽不能为空,请修改后重新导入", i + 1);
                            b1 = false;
                            break;
                        }
                        var type = types.FirstOrDefault(x => x.name == m.TypeName);
                        if (type == null)
                        {
                            m.MaterialType = 5;//其他
                        }
                        else
                        {
                            m.MaterialType = type.id;
                        }
                        if (existMaterialcodes.Contains(m.Code))
                        {
                            continue;
                        }
                        codes.Add(m.Code);
                        if (string.IsNullOrEmpty(m.Name)) { m.Name = m.Description; }
                        if (string.IsNullOrEmpty(m.Version)) { m.Version = "00"; }
                        MaterialEntity mt = new MaterialEntity()
                        {
                            ClassificationSociety = m.ClassificationSociety,
                            Code = m.Code,
                            MaterialNo = m.MaterialNo,
                            Cost = m.Cost,
                            CuttingType = m.CuttingType,
                            Description = m.Description,
                            GuaranteePeriod = m.GuaranteePeriod,
                            IssueProjectNo = m.IssueProjectNo,
                            Length = m.Length,
                            SerialNo = m.SerialNo,
                            Name = m.Name,
                            LaneSeparation = m.Laneseparation,
                            MarkingPen = m.MarkingPen,
                            PageNo = m.PageNo,
                            Status = 1,
                            Thick = m.Thick,
                            Unit = m.Unit,
                            Remark = m.Remark,
                            ProcurementProjectNo = m.ProcurementProjectNo,
                            TypeId = m.MaterialType,
                            Version = m.Version,
                            Weight = m.Weight,
                            VerticalPosition = m.VerticalPosition,
                            Wide = m.Wide
                        };
                        materialSaves.Add(mt);
                    }
                    if (!b1)
                    {
                        return b1;
                    }
                    var sql = string.Format("INSERT INTO BASEMaterial(status, name, code, materialno, version, typeid, guaranteeperiod, cost, classificationsociety, unit, serialno, description, remark, verticalposition, weight, issueprojectno, procurementprojectno, cuttingtype, pageno, thick, wide, length, markingpen, laneseparation) VALUES");
                    for (var j = 0; j < materialSaves.Count; j++)
                    {
                        sql += string.Format("({0}, '{1}', '{2}', '{3}', {4}, '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}', '{12}', '{13}', '{14}', '{15}','{16}' ,'{17}', '{18}', '{19}', '{20}', '{21}','{22}','{23}' ),",
                         materialSaves[j].Status,
                         StringHelper.RelpaceQuot(materialSaves[j].Name),
                         StringHelper.RelpaceQuot(materialSaves[j].Code),
                         StringHelper.RelpaceQuot(materialSaves[j].MaterialNo),
                         StringHelper.RelpaceQuot(materialSaves[j].Version),
                         materialSaves[j].TypeId,
                         StringHelper.RelpaceQuot(materialSaves[j].GuaranteePeriod),
                         materialSaves[j].Cost,
                         StringHelper.RelpaceQuot(materialSaves[j].ClassificationSociety),
                         StringHelper.RelpaceQuot(materialSaves[j].Unit),
                         StringHelper.RelpaceQuot(materialSaves[j].SerialNo),
                         StringHelper.RelpaceQuot(materialSaves[j].Description),
                         StringHelper.RelpaceQuot(materialSaves[j].Remark),
                         StringHelper.RelpaceQuot(materialSaves[j].VerticalPosition),
                         StringHelper.RelpaceQuot(materialSaves[j].Weight),
                         StringHelper.RelpaceQuot(materialSaves[j].IssueProjectNo),
                         StringHelper.RelpaceQuot(materialSaves[j].ProcurementProjectNo),
                         StringHelper.RelpaceQuot(materialSaves[j].CuttingType),
                         StringHelper.RelpaceQuot(materialSaves[j].PageNo),
                         StringHelper.RelpaceQuot(materialSaves[j].Thick),
                         StringHelper.RelpaceQuot(materialSaves[j].Wide),
                         StringHelper.RelpaceQuot(materialSaves[j].Length),
                         StringHelper.RelpaceQuot(materialSaves[j].MarkingPen),
                         StringHelper.RelpaceQuot(materialSaves[j].LaneSeparation));
                    }
                    if (sql.EndsWith(","))
                    {
                        sql = sql.Substring(0, sql.Length - 1);
                    }
                    var num = dbModel.Database.ExecuteSqlCommand(sql);
                    return string.IsNullOrEmpty(msg);
                }
                catch (Exception ex)
                {
                    msg = ex.Message;
                    LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "ImportExcel", ex.Message);
                    return false;
                }
            }
        }
    }
DEmon/iWareDataCore/iWareDataCore.csproj
@@ -77,6 +77,7 @@
    <Compile Include="BASE\Entity\InOutListEntity.cs" />
    <Compile Include="BASE\Entity\EmptyPlaceViewEntity.cs" />
    <Compile Include="BASE\Entity\InputMaterialEntity.cs" />
    <Compile Include="BASE\Entity\MaterialViewForMesEntity.cs" />
    <Compile Include="BASE\Entity\WebOrderDetailViewEntity.cs" />
    <Compile Include="BASE\Entity\WebOrderDetailEntity.cs" />
    <Compile Include="BASE\Entity\MaterialClassEntity.cs" />