UpstreamSendMaterial.cs 4.1 KB
using Hh.Mes.Common.log;
using System;
using Hh.Mes.Pojo.System;
using Hh.Mes.POJO.Entity;
using Hh.Mes.POJO.EnumEntitys;
using Hh.Mes.POJO.ApiEntity;
using Hh.Mes.POJO.Response;
using static Microsoft.AspNetCore.Hosting.Internal.HostingApplication;

namespace Hh.Mes.Service.ApiService
{
    public partial class UpstreamService
    {
        public dynamic SendMaterial(MaterialEntity entity)
        {
            var response = new ResponseUpstream<string>(entity.plmeid);
            return ExceptionsHelp.Instance.ExecuteT(() =>
            {
                int resultCount = 0;
                var material = new base_material
                {
                    keys = Guid.NewGuid(),
                    plmeId = entity.plmeid,
                    factoryCode = entity.factory_code,
                    materialCode = entity.mater_code,
                    materialName = entity.mater_name,
                    unitCode = entity.unit,
                    mtClassify = entity.mtClassify,
                    specifications = entity.format,
                    diameter=entity.diameter,
                    thickness=entity.thickness,
                    types= entity.types,
                    //crux = entity.crux == "1" ? "true" : "false",
                    //weight = entity.weight,
                    //procurement = entity.procurement_attribute,
                    isDelete = AddOrUpdateFlag
                };
                if (entity.type == EnumAction.I.ToString())
                {
                    if (base.Context.Queryable<base_factory>().Any(x => x.otherCode != material.factoryCode))
                        return response.ResponseError($"【上位系统】物料信息工厂编码[{nameof(material.factoryCode)}]“{material.factoryCode}”不存在产线系统,请核实后再发送!");

                    if (base.Context.Queryable<base_material>().Any(x => x.materialCode == material.materialCode && x.isDelete == AddOrUpdateFlag))
                        return response.ResponseError($"【上位系统】物料信息[{nameof(material.materialCode)}]“{material.materialCode}”已存在,请勿重复发送!");

                    material.createTime = DateTime.Now;
                    material.createBy = SystemVariable.DefaultCreated;
                    resultCount = base.Context.Insertable(material).ExecuteCommand();
                }
                else if (entity.type == EnumAction.U.ToString())
                {
                    if (base.Context.Queryable<base_factory>().Any(x => x.otherCode != material.factoryCode))
                        return response.ResponseError($"【上位系统】物料信息工厂编码[{nameof(material.factoryCode)}]“{material.factoryCode}”不存在产线系统,请核实后再发送!");

                    if (base.Context.Queryable<base_material>().Any(x => x.materialCode == material.materialCode && x.isDelete == AddOrUpdateFlag))
                        return response.ResponseError($"【上位系统】物料信息[{nameof(material.materialCode)}]“{material.materialCode}”已存在,请勿重复发送!");
                    material.updateTime = DateTime.Now;
                    material.updateBy = SystemVariable.DefaultCreated;
                    resultCount = base.Context.Updateable(material)
                                     .IgnoreColumns(it => new { it.keys, it.createBy, it.createTime })
                                     .Where(x => x.materialCode == material.materialCode && x.isDelete == AddOrUpdateFlag)
                                     .ExecuteCommand();
                }
                else if (entity.type == EnumAction.D.ToString())
                {
                    material.isDelete = DeleteFlag;
                    resultCount = Context.Updateable(material).UpdateColumns(x => new { x.isDelete })
                                        .Where(x => x.materialCode == material.materialCode && x.isDelete == AddOrUpdateFlag)
                                        .ExecuteCommand();
                }
                return resultCount > 0 ? response.ResponseSuccess() : response.ResponseError();
            });
        }
    }
}