Exemplo n.º 1
0
        public IActionResult Get(Guid id)
        {
            var entity = _dataFinder.RetrieveById("notice", id);

            if (entity.NotEmpty())
            {
                //如果所有者等于当前用户,则设为已读
                if (entity.GetGuidValue("ownerid").Equals(CurrentUser.SystemUserId))
                {
                    var updEntity = new Entity("notice");
                    updEntity.SetIdValue(id);
                    updEntity.SetAttributeValue("isread", true);
                    _dataUpdater.Update(updEntity);
                }

                //if (entity.GetStringValue("linkto").IsNotEmpty())
                //{
                //    return Redirect("/" + XmsWebContext.OrganizationUniqueName + entity.GetStringValue("linkto"));
                //}
                //else
                //{
                //    return Redirect("/" + XmsWebContext.OrganizationUniqueName + "/entity/create?entityname=notice&recordid=" + id);
                //}
                return(JOk(entity));
            }
            return(NotFound());
        }
Exemplo n.º 2
0
        public IActionResult SetUserHomePage(string homePage)
        {
            if (homePage.IsEmpty())
            {
                return(JError(T["parameter_error"]));
            }
            Entity entity = new Entity("SystemUserSettings");

            entity.SetIdValue(CurrentUser.SystemUserId)
            .SetAttributeValue("homepagearea", homePage);

            return(_dataUpdater.Update(entity).UpdateResult(T));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 更新业务对象的处理状态
        /// </summary>
        /// <param name="entityId"></param>
        /// <param name="objectId"></param>
        /// <param name="state"></param>
        /// <param name="entityName"></param>
        private void Update(Schema.Domain.Entity entityMetaData, Guid objectId, WorkFlowProcessState state)
        {
            var entity = new Core.Data.Entity(entityMetaData.Name);

            entity.SetIdValue(objectId);
            entity.SetAttributeValue("ProcessState", new OptionSetValue((int)state));
            _dataUpdater.Update(entity, true);
        }
Exemplo n.º 4
0
        public async Task <bool> WriteJson(Guid accountId, string data)
        {
            if (!data.IsValidJson())
            {
                return(false);
            }
            if (!data.IsValidContentModel())
            {
                return(false);
            }

            // Get content key
            Guid contentKey = data.ExtractContentKey();

            // 1. get all links
            var links = await _linkReader.GetLinks(accountId, contentKey);

            // 2. if there are no links, add a root link and a content item
            if (!links.Any())
            {
                links.Add(await GenerateRootContent(accountId, contentKey, data));
            }

            // 3. for all linked content items, update 'data' and store
            TableBatchOperation batchOperation = new TableBatchOperation();

            foreach (var link in links)
            {
                Guid contentId = Guid.Parse(link.RowKey.FirstPartOfCompositeIndex());
                var  content   = await _contentReader.ReadData(accountId, contentId);

                var mergedData = _dataUpdater.Update(content, contentId, data);
                BatchInsertContent(accountId, contentId, mergedData, batchOperation);
            }

            // commit batch update
            IList <TableResult> insertContentResults = await _contentTable.ExecuteBatchAsync(batchOperation);

            if (insertContentResults.Any(r => !r.HttpStatusCode.IsSuccessfulHttpStatusCode()))
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 5
0
        public IActionResult Post(EditOrganizationModel model)
        {
            string msg = string.Empty;

            if (ModelState.IsValid)
            {
                Entity entity = new Entity("organization");
                entity.SetIdValue(model.OrganizationId.Value);
                entity.SetAttributeValue("Name", model.Name);
                entity.SetAttributeValue("LanguageId", (int)model.LanguageId);
                //entity.SetAttributeValue("State", model.State);
                entity.SetAttributeValue("Description", model.Description);
                entity.SetAttributeValue("BaseCurrencyId", new EntityReference("currency", model.BaseCurrencyId));
                entity.SetAttributeValue("ManagerId", model.ManagerId);
                _dataUpdater.Update(entity);
                return(JOk(T["saved_success"]));
            }
            msg = GetModelErrors(ModelState);
            return(JError(T["saved_error"] + ": " + msg));
        }
Exemplo n.º 6
0
        public void UpdateDataSerialized <T>(string path, IDataUpdater <T> updater)
        {
            Stat stat = new Stat();
            bool retry;

            do
            {
                retry = false;
                try
                {
                    T oldData = ReadData <T>(path, stat);
                    T newData = updater.Update(oldData);
                    WriteData(path, newData, stat.Version);
                }
                catch (ZKBadVersionException e)
                {
                    retry = true;
                }
            } while (retry);
        }
        public bool UpdateBack(Guid workFlowId, Guid instanceId, Guid processStageId, Guid recordId)
        {
            var bpfInstance = _businessProcessFlowInstanceRepository.Find(n => n.BusinessProcessFlowInstanceId == instanceId && n.WorkFlowId == workFlowId);

            if (bpfInstance == null)
            {
                return(false);
            }
            var stages = _processStageService.Query(n => n
                                                    .Where(f => f.WorkFlowId == workFlowId)
                                                    .Sort(s => s.SortAscending(f => f.StageOrder)));

            var currentStage = stages.Find(n => n.ProcessStageId == processStageId);
            var entityIds    = stages.Select(n => n.EntityId).Distinct().ToList();
            int entityIndex  = entityIds.FindIndex(n => n.Equals(currentStage.EntityId)) + 1;
            //var _bpfService = new BusinessProcessFlowInstanceService(User);
            var originalStage = stages.Find(n => n.ProcessStageId == bpfInstance.ProcessStageId);
            //var _organizationServiceProxy = new SDK.OrganizationServiceProxy(User);
            var eidMeta = _entityFinder.FindById(originalStage.EntityId);
            var filter  = new Dictionary <string, object>();

            if (entityIndex == 1)
            {
                this.Update(n => n
                            .Set(f => f.ProcessStageId, currentStage.ProcessStageId)
                            .Set(f => f.ProcessEntityId, currentStage.EntityId)
                            .Set(f => f.Entity2Id, null)
                            .Set(f => f.Entity3Id, null)
                            .Set(f => f.Entity4Id, null)
                            .Set(f => f.Entity5Id, null)
                            .Where(w => w.BusinessProcessFlowInstanceId == bpfInstance.BusinessProcessFlowInstanceId)
                            );
                filter.Add(eidMeta.Name + "id", bpfInstance.Entity2Id);
            }
            else if (entityIndex == 2)
            {
                this.Update(n => n
                            .Set(f => f.ProcessStageId, currentStage.ProcessStageId)
                            .Set(f => f.ProcessEntityId, currentStage.EntityId)
                            .Set(f => f.Entity3Id, null)
                            .Set(f => f.Entity4Id, null)
                            .Set(f => f.Entity5Id, null)
                            .Where(w => w.BusinessProcessFlowInstanceId == bpfInstance.BusinessProcessFlowInstanceId)
                            );
                filter.Add(eidMeta.Name + "id", bpfInstance.Entity3Id);
            }
            else if (entityIndex == 3)
            {
                this.Update(n => n
                            .Set(f => f.ProcessStageId, currentStage.ProcessStageId)
                            .Set(f => f.ProcessEntityId, currentStage.EntityId)
                            .Set(f => f.Entity4Id, null)
                            .Set(f => f.Entity5Id, null)
                            .Where(w => w.BusinessProcessFlowInstanceId == bpfInstance.BusinessProcessFlowInstanceId)
                            );
                filter.Add(eidMeta.Name + "id", bpfInstance.Entity4Id);
            }
            else if (entityIndex == 4)
            {
                this.Update(n => n
                            .Set(f => f.ProcessStageId, currentStage.ProcessStageId)
                            .Set(f => f.ProcessEntityId, currentStage.EntityId)
                            .Set(f => f.Entity5Id, null)
                            .Where(w => w.BusinessProcessFlowInstanceId == bpfInstance.BusinessProcessFlowInstanceId)
                            );
                filter.Add(eidMeta.Name + "id", bpfInstance.Entity5Id);
            }
            if (!originalStage.EntityId.Equals(currentStage.EntityId))
            {
                //更新原阶段对应的实体记录的阶段
                var originalData = _dataFinder.RetrieveByAttribute(eidMeta.Name, filter);
                if (originalData.NotEmpty())
                {
                    var updOgnData = new Entity(originalData.Name);
                    updOgnData.SetIdValue(originalData.GetIdValue());
                    updOgnData.SetAttributeValue("stageid", null);
                    _dataUpdater.Update(updOgnData);
                }
            }

            return(true);
        }
Exemplo n.º 8
0
        public IActionResult Post(SaveDataModel model)
        {
            if (model.EntityId.Equals(Guid.Empty))
            {
                return(NotFound());
            }
            var entityMetaData = _entityFinder.FindById(model.EntityId);

            if (entityMetaData == null)
            {
                return(NotFound());
            }
            var  attributeMetaDatas = _attributeFinder.FindByEntityId(model.EntityId);
            bool isNew  = !(model.RecordId.HasValue && !model.RecordId.Value.Equals(Guid.Empty));
            var  thisId = Guid.Empty;

            try
            {
                Core.Data.Entity entity   = new Core.Data.Entity(entityMetaData.Name);
                dynamic          headData = JObject.Parse(model.Data);
                foreach (JProperty p in headData)
                {
                    var attr = attributeMetaDatas.Find(n => n.Name.IsCaseInsensitiveEqual(p.Name));
                    if (attr != null && p.Value != null)
                    {
                        entity.SetAttributeValue(p.Name.ToString().ToLower(), entity.WrapAttributeValue(_entityFinder, attr, p.Value.ToString()));
                    }
                }
                if (isNew)
                {
                    if (model.RelationShipName.IsNotEmpty() && model.ReferencedRecordId.HasValue)//如果存在关联关系
                    {
                        var relationShipMetas = _relationShipFinder.FindByName(model.RelationShipName);
                        if (null != relationShipMetas && relationShipMetas.ReferencingEntityId == model.EntityId && entity.GetStringValue(relationShipMetas.ReferencingAttributeName).IsEmpty())
                        {
                            //设置当前记录关联字段的值
                            entity.SetAttributeValue(relationShipMetas.ReferencingAttributeName, new EntityReference(relationShipMetas.ReferencedEntityName, model.ReferencedRecordId.Value));
                        }
                    }
                    if (!model.StageId.Equals(Guid.Empty))//业务流程的阶段
                    {
                        entity.SetAttributeValue("StageId", model.StageId);
                    }
                    thisId = _dataCreater.Create(entity);
                    if (!model.StageId.Equals(Guid.Empty))//业务流程的阶段
                    {
                        _businessProcessFlowInstanceUpdater.UpdateForward(model.BusinessFlowId, model.BusinessFlowInstanceId, model.StageId, thisId);
                    }
                }
                else
                {
                    thisId = model.RecordId.Value;
                    entity.SetIdValue(model.RecordId.Value);
                    _dataUpdater.Update(entity);
                }
                //单据体
                if (model.Child.IsNotEmpty())
                {
                    var childs = JArray.Parse(model.Child.UrlDecode());
                    if (childs.Count > 0)
                    {
                        List <Core.Data.Entity> childEntities = new List <Core.Data.Entity>();
                        List <string>           entityNames   = new List <string>();
                        foreach (var c in childs)
                        {
                            dynamic root = JObject.Parse(c.ToString());
                            string  name = root.name, relationshipname = root.relationshipname, refname = string.Empty;
                            if (!entityNames.Exists(n => n.IsCaseInsensitiveEqual(name)))
                            {
                                entityNames.Add(name);
                            }

                            var data            = root.data;
                            var childAttributes = _attributeFinder.FindByEntityName(name);
                            if (relationshipname.IsNotEmpty())
                            {
                                var relationShipMetas = _relationShipFinder.FindByName(relationshipname);
                                if (null != relationShipMetas && relationShipMetas.ReferencedEntityId == model.EntityId)
                                {
                                    refname = relationShipMetas.ReferencingAttributeName;
                                }
                            }
                            Core.Data.Entity detail = new Core.Data.Entity(name);
                            foreach (JProperty p in data)
                            {
                                var attr = childAttributes.Find(n => n.Name.IsCaseInsensitiveEqual(p.Name));
                                if (attr != null && p.Value != null)
                                {
                                    detail.SetAttributeValue(p.Name.ToString().ToLower(), detail.WrapAttributeValue(_entityFinder, attr, p.Value.ToString()));
                                }
                            }
                            //关联主记录ID
                            if (refname.IsNotEmpty())
                            {
                                detail.SetAttributeValue(refname, new EntityReference(entityMetaData.Name, thisId));
                            }
                            childEntities.Add(detail);
                        }
                        //批量创建记录
                        if (childEntities.NotEmpty())
                        {
                            foreach (var item in entityNames)
                            {
                                var items           = childEntities.Where(n => n.Name.IsCaseInsensitiveEqual(item)).ToList();
                                var creatingRecords = items.Where(n => n.Name.IsCaseInsensitiveEqual(item) && n.GetIdValue().Equals(Guid.Empty)).ToList();
                                if (creatingRecords.NotEmpty())
                                {
                                    _dataCreater.CreateMany(creatingRecords);
                                }
                                if (!isNew)
                                {
                                    foreach (var updItem in items.Where(n => n.Name.IsCaseInsensitiveEqual(item) && !n.GetIdValue().Equals(Guid.Empty)))
                                    {
                                        _dataUpdater.Update(updItem);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                return(JError(ex.InnerException != null ? ex.InnerException.Message : ex.Message));
            }
            if (isNew)
            {
                return(CreateSuccess(new { id = thisId }));
            }
            return(UpdateSuccess(new { id = thisId }));
        }
Exemplo n.º 9
0
        public IActionResult ForwardAndAppend(Guid entityid, Guid referencedrecordid, Guid workflowid, Guid stageid, Guid?instanceId, string relationshipname)
        {
            if (entityid.Equals(Guid.Empty) || referencedrecordid.Equals(Guid.Empty) || workflowid.Equals(Guid.Empty) || stageid.Equals(Guid.Empty))
            {
                return(JError(T["parameter_error"]));
            }
            var entityMeta = _entityFinder.FindById(entityid);

            if (entityMeta == null)
            {
                return(NotFound());
            }
            var flowInfo = _workFlowFinder.Find(n => n.WorkFlowId == workflowid);

            if (flowInfo == null)
            {
                return(NotFound());
            }
            var stages = _processStageService.Query(n => n
                                                    .Where(f => f.WorkFlowId == flowInfo.WorkFlowId)
                                                    .Sort(s => s.SortAscending(f => f.StageOrder)));

            var currentStage = stages.Find(n => n.ProcessStageId == stageid);
            var prevStage    = stages.Find(n => n.StageOrder == currentStage.StageOrder - 1);

            if (currentStage.EntityId.Equals(prevStage.EntityId))
            {
                return(JError(T["parameter_error"]));
            }
            BusinessProcessFlowInstance bpfInstance = null;

            if (instanceId.HasValue && !instanceId.Value.Equals(Guid.Empty))
            {
                bpfInstance = _businessProcessFlowInstanceService.Find(n => n.BusinessProcessFlowInstanceId == instanceId && n.WorkFlowId == workflowid);
                if (bpfInstance == null)
                {
                    return(NotFound());
                }
            }
            if (bpfInstance == null)
            {
                instanceId  = Guid.NewGuid();
                bpfInstance = new BusinessProcessFlowInstance();
                bpfInstance.BusinessProcessFlowInstanceId = instanceId.Value;
                bpfInstance.WorkFlowId      = workflowid;
                bpfInstance.ProcessStageId  = stages.First().ProcessStageId;
                bpfInstance.Entity1Id       = referencedrecordid;
                bpfInstance.ProcessEntityId = entityid;
                _businessProcessFlowInstanceService.Create(bpfInstance);
            }
            //是否存在单据转换规则
            var entityMap = _entityMapFinder.Find(prevStage.EntityId, entityid);

            if (entityMap == null)
            {
                return(JOk(new
                {
                    EntityId = entityid
                    ,
                    StageId = stageid
                    ,
                    BusinessFlowId = workflowid
                    ,
                    BusinessFlowInstanceId = instanceId.Value
                    ,
                    RelationShipName = relationshipname
                    ,
                    ReferencedRecordId = referencedrecordid
                }));
            }
            var recordid = _dataMapper.Create(prevStage.EntityId, currentStage.EntityId, referencedrecordid);

            _businessProcessFlowInstanceUpdater.UpdateForward(workflowid, instanceId.Value, stageid, recordid);
            //更新当前记录的业务阶段
            var updData = new Entity(entityMeta.Name);

            updData.SetIdValue(recordid);
            updData.SetAttributeValue("stageid", stageid);
            _dataUpdater.Update(updData);

            return(JOk(new
            {
                EntityId = entityid
                ,
                RecordId = recordid
                ,
                BusinessFlowId = workflowid
                ,
                BusinessFlowInstanceId = instanceId.Value
            }));
        }
Exemplo n.º 10
0
        private bool ImportCore(ImportFile file, ImportMap map, List <dynamic> data, Action <int, object, string, int, Guid> itemProcceed)
        {
            var mappings   = new List <ColumnMapping>().DeserializeFromJson(map.MapCustomizations);
            var columns    = new List <string>().DeserializeFromJson(file.HeaderRow);
            var attributes = _attributeFinder.FindByEntityName(file.TargetEntityName);
            //更新记录时,根据哪些字段查询已存在的记录
            var updatePrimaryFields = new List <string> {
                attributes.Find(x => x.IsPrimaryField).Name
            };

            updatePrimaryFields.AddRange(mappings.Where(x => x.IsUpdatePrimaryField).Select(x => x.Mapping.Attribute));
            int rowIndex = 0, failureCount = 0;

            foreach (var d in data)
            {
                rowIndex++;
                StringBuilder rowError       = new StringBuilder();
                var           entity         = new Entity(file.TargetEntityName);
                var           retrieveFilter = new Dictionary <string, object>();
                for (int i = 0; i < columns.Count; i++)
                {
                    var value   = d[i];
                    var mapping = mappings[i].Mapping;
                    //字段
                    var attr = attributes.Find(x => x.Name.IsCaseInsensitiveEqual(mapping.Attribute));
                    //是否类型
                    if (attr.TypeIsBit() || attr.TypeIsState())
                    {
                        if (value == null)
                        {
                            if (mapping.NullHandle == "ignore")
                            {
                            }
                            else if (mapping.NullHandle == "defaultvalue")
                            {
                                value = attr.DefaultValue;
                            }
                            else if (mapping.NullHandle.IsInteger())
                            {
                                var item = _stringMapFinder.Find(x => x.AttributeId == attr.AttributeId && x.Value == int.Parse(mapping.NullHandle));
                                if (item != null)
                                {
                                    value = item.Value;
                                }
                                else
                                {
                                    //失败记录
                                    rowError.AppendLine($"\"{columns[i]}\"的值\"{value}\"不存在");
                                }
                            }
                        }
                        else
                        {
                            var v    = (string)value;
                            var item = _stringMapFinder.Find(x => x.AttributeId == attr.AttributeId && x.Name == v);
                            if (item != null)
                            {
                                value = item.Value;
                            }
                            else
                            {
                                //失败记录
                                rowError.AppendLine($"\"{columns[i]}\"的值\"{value}\"不存在");
                            }
                        }
                    }
                    //选项集类型
                    else if (attr.TypeIsPickList() || attr.TypeIsStatus())
                    {
                        if (value == null)
                        {
                            if (mapping.NullHandle == "ignore")
                            {
                            }
                            else if (mapping.NullHandle == "defaultvalue")
                            {
                                value = attr.DefaultValue;
                            }
                            else if (((string)value).IsInteger())
                            {
                                var item = attr.PickLists.Find(x => x.Value == (int)value);
                                if (item != null)
                                {
                                    value = new OptionSetValue(item.Value);
                                }
                                else
                                {
                                    //失败记录
                                    rowError.AppendLine($"\"{columns[i]}\"的值\"{value}\"不存在");
                                }
                            }
                        }
                        else
                        {
                            var v    = (string)value;
                            var item = _optionSetDetailServiceFinder.Find(x => x.OptionSetId == attr.OptionSetId && x.Name == v);
                            if (item != null)
                            {
                                value = new OptionSetValue(item.Value);
                            }
                            else
                            {
                                //失败记录
                                rowError.AppendLine($"\"{columns[i]}\"的值\"{value}\"不存在");
                            }
                        }
                    }
                    //引用类型
                    else if (attr.TypeIsLookUp() || attr.TypeIsOwner() || attr.TypeIsCustomer())
                    {
                        if (value != null)
                        {
                            var criteria = new Dictionary <string, object>();
                            if (((string)value).IsGuid())
                            {
                                criteria.Add(entity.IdName, value);
                            }
                            if (mapping.LookupName.IsNotEmpty())
                            {
                                criteria.Add(mapping.LookupName, value);
                            }
                            else
                            {
                                var primaryField = _attributeFinder.Find(x => x.EntityId == attr.ReferencedEntityId && x.IsPrimaryField == true);
                                criteria.Add(primaryField.Name, value);
                            }
                            var filter = new Sdk.Abstractions.Query.FilterExpression();
                            foreach (var c in criteria)
                            {
                                filter.AddCondition(c.Key, Sdk.Abstractions.Query.ConditionOperator.Equal, c.Value);
                            }
                            var matchedCount = _aggregateService.Count(attr.ReferencedEntityName, filter);
                            if (matchedCount > 1)
                            {
                                //失败记录
                                rowError.AppendLine($"\"{columns[i]}\"的值\"{value}\"不唯一");
                            }
                            else
                            {
                                var referenced = _dataFinder.RetrieveByAttribute(attr.ReferencedEntityName, criteria, new List <string> {
                                    attr.ReferencedEntityName + "Id"
                                });
                                if (referenced.NotEmpty())
                                {
                                    if (attr.TypeIsOwner())
                                    {
                                        value = new OwnerObject(OwnerTypes.SystemUser, referenced.Id);
                                    }
                                    else
                                    {
                                        value = new EntityReference(attr.ReferencedEntityName, referenced.Id);
                                    }
                                }
                                else
                                {
                                    //失败记录
                                    rowError.AppendLine($"\"{columns[i]}\"的值\"{value}\"不存在");
                                }
                            }
                        }
                    }
                    //金额类型
                    else if (attr.TypeIsMoney() || attr.TypeIsSmallMoney())
                    {
                        if (value != null)
                        {
                            if (decimal.TryParse((string)value, out decimal v))
                            {
                                value = new Money(v);
                            }
                            else
                            {
                                //失败记录
                                rowError.AppendLine($"\"{columns[i]}\"的值\"{value}\"格式错误");
                            }
                        }
                    }
                    //浮点型类型
                    else if (attr.TypeIsDecimal() || attr.TypeIsFloat())
                    {
                        if (value != null)
                        {
                            if (!decimal.TryParse((string)value, out _))
                            {
                                //失败记录
                                rowError.AppendLine($"\"{columns[i]}\"的值\"{value}\"格式错误");
                            }
                        }
                    }
                    //整型类型
                    else if (attr.TypeIsInt())
                    {
                        if (value != null)
                        {
                            if (!((string)value).IsInteger())
                            {
                                //失败记录
                                rowError.AppendLine($"\"{columns[i]}\"的值\"{value}\"格式错误");
                            }
                        }
                    }
                    //日期类型
                    else if (attr.TypeIsDateTime() || attr.TypeIsSmallDateTime())
                    {
                        if (value != null)
                        {
                            if (!((string)value).IsDateTime())
                            {
                                //失败记录
                                rowError.AppendLine($"\"{columns[i]}\"的值\"{value}\"格式错误");
                            }
                        }
                    }
                    else if (value != null)
                    {
                        value = (string)value;
                    }
                    if (rowError.Length == 0 && value != null)
                    {
                        entity.SetAttributeValue(attr.Name, value);
                        if (updatePrimaryFields.Exists(x => x.IsCaseInsensitiveEqual(attr.Name)))
                        {
                            retrieveFilter.Add(attr.Name, value);
                        }
                    }
                }
                int errorType = rowError.Length > 0 ? 2 : 0;//错误类型:数据=2
                //重复数据的操作
                if (retrieveFilter.Count > 0)
                {
                    var existsEntity = _dataFinder.RetrieveByAttribute(file.TargetEntityName, retrieveFilter, updatePrimaryFields, true);
                    //不导入重复数据
                    if (file.DuplicateDetection == 1 && existsEntity.NotEmpty())
                    {
                        rowError.AppendLine("记录已存在");
                    }
                    //覆盖导入
                    else if (file.DuplicateDetection == 2 && existsEntity.NotEmpty())
                    {
                        entity.SetIdValue(existsEntity.Id);
                    }
                    //仅覆盖重复数据
                    else if (file.DuplicateDetection == 3)
                    {
                        if (existsEntity.NotEmpty())
                        {
                            entity.SetIdValue(existsEntity.Id);
                        }
                        else
                        {
                            rowError.AppendLine("记录不存在");
                        }
                    }
                }
                Guid recordId = entity.Id;
                //本行数据验证通过
                if (rowError.Length == 0)
                {
                    try
                    {
                        if (recordId.IsEmpty())
                        {
                            recordId = _dataCreater.Create(entity);
                        }
                        else
                        {
                            _dataUpdater.Update(entity);
                        }
                    }
                    catch (Exception e)
                    {
                        errorType = 1;//错误类型:系统
                        rowError.AppendLine(e.Message);
                    }
                }
                if (rowError.Length > 0)
                {
                    failureCount++;
                }
                //每行导入结果
                itemProcceed(rowIndex, d, rowError.ToString(), errorType, recordId);
            }
            //文件导入结果
            file.SuccessCount = data.Count - failureCount;
            file.FailureCount = failureCount;
            _importFileService.Update(file);
            return(true);
        }
Exemplo n.º 11
0
        public bool Update(AggregateRoot aggregateRoot, Guid?systemFormId, bool ignorePermissions = false)
        {
            AggregateRootMetaData aggRootMetaData = GetAggregateRootMetaData(aggregateRoot, systemFormId);
            var result          = false;
            var originalAggroot = new AggregateRoot();

            try
            {
                _organizationDataProvider.BeginTransaction();
                InternalOnUpdate(originalAggroot, aggregateRoot, OperationStage.PreOperation, aggRootMetaData);

                var thisId = aggregateRoot.MainEntity.GetIdValue();
                foreach (var c in aggregateRoot.ChildEntities)
                {
                    string name = c.Name, relationshipname = c.Relationshipname, refname = string.Empty;
                    if (relationshipname.IsNotEmpty())
                    {
                        var relationShipMetas = _relationShipFinder.FindByName(c.Relationshipname);
                        if (null != relationShipMetas && relationShipMetas.ReferencedEntityId == c.Entityid)
                        {
                            refname = relationShipMetas.ReferencingAttributeName;
                        }
                        if (refname.IsNotEmpty())
                        {
                            c.Entity.SetAttributeValue(refname, new EntityReference(aggregateRoot.MainEntity.Name, thisId));
                        }
                    }
                }
                var childEntities = aggregateRoot.ChildEntities.Where(x => x.Entitystatus != OperationTypeEnum.Delete).Select(x => x.Entity).ToList();
                var entityNames   = childEntities.Select(n => n.Name).Distinct().ToList();
                foreach (var item in entityNames)
                {
                    var items           = childEntities.Where(n => n.Name.IsCaseInsensitiveEqual(item)).ToList();
                    var creatingRecords = items.Where(n => n.Name.IsCaseInsensitiveEqual(item) && n.GetIdValue().Equals(Guid.Empty)).ToList();
                    if (creatingRecords.NotEmpty())
                    {
                        _dataCreater.CreateMany(creatingRecords);
                    }
                    foreach (var updItem in items.Where(n => n.Name.IsCaseInsensitiveEqual(item) && !n.GetIdValue().Equals(Guid.Empty)))
                    {
                        _dataUpdater.Update(updItem);
                    }
                }
                var childEntitiesDelete = aggregateRoot.ChildEntities.Where(x => x.Entitystatus == OperationTypeEnum.Delete).Select(x => x.Entity).ToList();
                var entityNamesDelete   = childEntitiesDelete.Select(n => n.Name).Distinct().ToList();
                foreach (var item in entityNamesDelete)
                {
                    var items = childEntitiesDelete.Where(n => n.Name.IsCaseInsensitiveEqual(item)).ToList();
                    foreach (var deleteItem in items)
                    {
                        _dataDeleter.Delete(deleteItem);
                    }
                }

                result = _dataUpdater.Update(aggregateRoot.MainEntity);
                InternalOnUpdate(originalAggroot, aggregateRoot, OperationStage.PostOperation, aggRootMetaData);
                _organizationDataProvider.CommitTransaction();
            }
            catch (Exception e)
            {
                _organizationDataProvider.RollBackTransaction();
                OnException(e);
            }
            return(result);
        }
Exemplo n.º 12
0
        public IActionResult Post(DataUpdateModel model)
        {
            Schema.Domain.Entity entityMeta = null;
            if (model.EntityId.HasValue && !model.EntityId.Value.Equals(Guid.Empty))
            {
                entityMeta = _entityFinder.FindById(model.EntityId.Value);
            }
            else if (model.EntityName.IsNotEmpty())
            {
                entityMeta = _entityFinder.FindByName(model.EntityName);
            }
            if (entityMeta == null)
            {
                return(NotFound());
            }
            var childAttributes = _attributeFinder.FindByEntityName(entityMeta.Name);
            var primaryAttr     = childAttributes.Find(n => n.TypeIsPrimaryKey());

            if (model.Data.StartsWith("["))
            {
                //var details = new List<Entity>();
                var items = JArray.Parse(model.Data.UrlDecode());
                if (items.Count > 0)
                {
                    foreach (var c in items)
                    {
                        dynamic root   = JObject.Parse(c.ToString());
                        Entity  detail = new Entity(entityMeta.Name);
                        foreach (JProperty p in root)
                        {
                            if (p.Name.IsCaseInsensitiveEqual("id"))
                            {
                                detail.SetIdValue(Guid.Parse(p.Value.ToString()), primaryAttr.Name);
                            }
                            else
                            {
                                var attr = childAttributes.Find(n => n.Name.IsCaseInsensitiveEqual(p.Name));
                                if (attr != null)
                                {
                                    detail.SetAttributeValue(p.Name.ToString().ToLower(), detail.WrapAttributeValue(_entityFinder, attr, p.Value.ToString()));
                                }
                            }
                        }
                        //details.Add(detail);
                        _dataUpdater.Update(detail);
                    }
                }
                //_organizationServiceProxy.UpdateMany(details);
                return(UpdateSuccess());
            }
            else
            {
                Entity  detail = new Entity(entityMeta.Name);
                dynamic root   = JObject.Parse(model.Data.UrlDecode());
                foreach (JProperty p in root)
                {
                    if (p.Name.IsCaseInsensitiveEqual("id"))
                    {
                        detail.SetIdValue(Guid.Parse(p.Value.ToString()), primaryAttr.Name);
                    }
                    else
                    {
                        var attr = childAttributes.Find(n => n.Name.IsCaseInsensitiveEqual(p.Name));
                        if (attr != null)
                        {
                            detail.SetAttributeValue(p.Name.ToString().ToLower(), detail.WrapAttributeValue(_entityFinder, attr, p.Value.ToString()));
                        }
                    }
                }
                _dataUpdater.Update(detail);
            }
            return(UpdateSuccess());
        }