11
啊鑫
2024-10-30 b957cfb89c9968f47cc5ce9795e6ffb05bc57fd8
MES.Service/service/BasicData/MesCustomerManager.cs
@@ -23,14 +23,11 @@
                    if (UpdateCustomerStatus(db, entity.Id, "B"))
                        return 1;
                    break;
                case "2":
                    if (InsertCustomer(db, entity))
                        return 1;
                    break;
                case "3":
                    if (DeleteCustomer(db, entity.Id))
                        return 1;
                    break;
                case "2":
                case "4":
                    if (InsertOrUpdate(db, entity))
                        return 1;
@@ -65,14 +62,11 @@
                                "B"))
                            throw new NotImplementedException("禁用失败");
                        break;
                    case "2":
                        if (!InsertCustomerBatch(db, customerGroup.Value))
                            throw new NotImplementedException("插入失败");
                        break;
                    case "3":
                        if (!DeleteCustomerBatch(db, customerGroup.Value))
                            throw new NotImplementedException("删除失败");
                        break;
                    case "2":
                    case "4":
                        if (!InsertOrUpdateBatch(db, customerGroup.Value))
                            throw new NotImplementedException("同步失败");
@@ -110,8 +104,8 @@
    private bool DeleteCustomer(SqlSugarScope db, decimal customerId)
    {
        var deleteById = db.Deleteable<MesCustomer>().In(customerId)
            .ExecuteCommand();
        var deleteById = db.Deleteable<MesCustomer>()
            .Where(s => s.Id == customerId).ExecuteCommand();
        if (deleteById > 0)
            return true;
@@ -128,18 +122,19 @@
            CustNo = customer.FNumber,
            CustSname = customer.FShortName,
            CustName = customer.FName,
            Anred = customer.Fcontact,
            Anred = customer.FTContact,
            Telf1 = customer.Fmobilephone,
            Fseller = customer.Fseller,
            Fforbidstatus = customer.FForbidStatus,
            Remarks = customer.FDescription,
            Remark = customer.FDescription,
            FSubsidiary = customer.FUseOrgId,
            Fumbrella = customer.FCreateOrgId,
            CreateDate = DateTime.Now,
            LastupdateDate = DateTime.Now,
            Company = "1000",
            Factory = "1000",
            DataType = customer.FDocumentStatus
            DataType = customer.FDocumentStatus,
            Type = customer.Type
        };
    }
@@ -171,7 +166,8 @@
        List<MesCustomer> customerList)
    {
        var ids = customerList.Select(it => it.Id).ToArray();
        var deleteByIds = db.Deleteable<MesCustomer>().In(ids).ExecuteCommand();
        var deleteByIds = db.Deleteable<MesCustomer>()
            .Where(s => ids.Contains(s.Id)).ExecuteCommand();
        if (deleteByIds > 0)
            return true;
@@ -180,30 +176,17 @@
    private bool InsertOrUpdate(SqlSugarScope db, MesCustomer entity)
    {
        var exists = db.Queryable<MesCustomer>().Any(e => e.Id == entity.Id);
        if (exists)
        {
            var update = db.Updateable(entity).ExecuteCommand();
            if (update > 0)
                return true;
        }
        else
        {
            var insert = db.Insertable(entity).ExecuteCommand();
            if (insert > 0)
                return true;
        }
        db.Deleteable<MesCustomer>().Where(s => s.Id == entity.Id)
            .ExecuteCommand();
        return false;
        var insert = db.Insertable(entity).ExecuteCommand();
        return insert > 0;
    }
    private bool InsertOrUpdateBatch(SqlSugarScope db,
        List<MesCustomer> customerList)
    {
        foreach (var entity in customerList)
            if (!InsertOrUpdate(db, entity))
                return false;
        return true;
        return customerList.All(entity => InsertOrUpdate(db, entity));
    }
}