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

namespace Hh.Mes.Service.ApiService
{
    public partial class UpstreamService
    {
        public dynamic SendSupplier(SupplierEntity entity)
        {
            var response = new ResponseUpstream<string>(entity.plmeid);
            return ExceptionsHelp.Instance.ExecuteT(() =>
            {
                var supplier = new base_supplier
                {
                    plmeid = entity.plmeid,
                    factoryCode = entity.factory,
                    supplierCode = entity.supplier_code,
                    supplierName = entity.supplier_name,
                    address = entity.address,
                    telePhone = entity.tele_phone,

                    isDelete = AddOrUpdateFlag
                };
                var resultCount = 0;
                if (entity.type == EnumAction.I.ToString())
                {
                    supplier.createTime = DateTime.Now;
                    supplier.createBy = SystemVariable.DefaultCreated;
                    var resultCrudBefore = Context.Queryable<base_supplier>().Any(x => x.supplierCode.Equals(supplier.supplierCode) && x.isDelete == AddOrUpdateFlag);
                    if (resultCrudBefore)
                        return response.ResponseError($"【MOM】供应商数据:[{nameof(entity.supplier_code)}]“{supplier.supplierCode}”已经存在!");
                    resultCount = Context.Insertable(supplier).ExecuteCommand();
                }
                else if (entity.type == EnumAction.U.ToString())
                {
                    supplier.updateTime = DateTime.Now;
                    supplier.updateBy = SystemVariable.DefaultCreated;
                    resultCount = Context.Updateable(supplier)
                                         .IgnoreColumns(it => new { it.createBy, it.createTime })
                                         .Where(x => x.supplierCode == supplier.supplierCode && x.isDelete == AddOrUpdateFlag)
                                         .ExecuteCommand();
                }
                else if (entity.type == EnumAction.D.ToString())
                {
                    supplier.isDelete = DeleteFlag;
                    resultCount = Context.Updateable(supplier).UpdateColumns(x => new { x.isDelete })
                    .Where(x => x.supplierCode == supplier.supplierCode && x.isDelete == AddOrUpdateFlag)
                    .ExecuteCommand();
                }
                return resultCount > 0 ? response.ResponseSuccess() : response.ResponseError();
            });
        }
    }
}