Пример #1
0
        /// <summary>
        /// 职位创建
        /// </summary>
        /// <param name="context"></param>
        /// <param name="body"></param>
        public void ReqpositionEdit(Context context, ReqPositionEdit body)
        {
            //检测权限
            var db       = context.DbContext;
            var position = db.PositionEntities.FirstOrDefault(i => i.Name == body.Name);

            if (position == null)
            {
                //创建一个新的职位
                position = new PositionEntity
                {
                    Name = body.Name,

                    Department   = body.DepartmentName,
                    Describe     = body.Describe,
                    SuperiorName = body.SuperiorName,
                };
            }
            else
            {
                position.Describe     = body.Describe;
                position.Department   = body.DepartmentName;
                position.SuperiorName = body.SuperiorName;
            }
            db.SaveChanges();
        }
 public void UpdateAndDrawInParallel()
 {
     const float UpdateTimeStep = 0.2f;
     const float RenderTimeStep = 0.016f;
     var entities = new MockEntitiesRunner(typeof(MockUpdateBehavior));
     var state = new PositionEntity(Vector2D.Zero);
     float drawTime = 0.0f;
     float updateTime = 0.0f;
     float accumulator = 0.0f;
     while (drawTime < 10.0f)
     {
         drawTime += RenderTimeStep;
         accumulator += RenderTimeStep;
         while (accumulator >= UpdateTimeStep)
         {
             state.InvokeNextUpdateStarted();
             state.Update();
             updateTime += UpdateTimeStep;
             accumulator -= UpdateTimeStep;
         }
         float interpolation = accumulator / UpdateTimeStep;
         var interpolatedPosition = state.Position;
         Console.WriteLine("interpolatedPosition=" + interpolatedPosition +
             ", drawTime=" + drawTime +
             ", updateTime=" + updateTime +
             ", interpolation=" + interpolation);
     }
     entities.Dispose();
 }
Пример #3
0
        public void UpdateAndDrawInParallel()
        {
            const float UpdateTimeStep = 0.2f;
            const float RenderTimeStep = 0.016f;
            var         entities       = new MockEntitiesRunner(typeof(MockUpdateBehavior));
            var         state          = new PositionEntity(Vector2D.Zero);
            float       drawTime       = 0.0f;
            float       updateTime     = 0.0f;
            float       accumulator    = 0.0f;

            while (drawTime < 10.0f)
            {
                drawTime    += RenderTimeStep;
                accumulator += RenderTimeStep;
                while (accumulator >= UpdateTimeStep)
                {
                    state.InvokeNextUpdateStarted();
                    state.Update();
                    updateTime  += UpdateTimeStep;
                    accumulator -= UpdateTimeStep;
                }
                float interpolation        = accumulator / UpdateTimeStep;
                var   interpolatedPosition = state.Position;
                Console.WriteLine("interpolatedPosition=" + interpolatedPosition +
                                  ", drawTime=" + drawTime +
                                  ", updateTime=" + updateTime +
                                  ", interpolation=" + interpolation);
            }
            entities.Dispose();
        }
Пример #4
0
 public QuestManager()
 {
     NPCCacheList     = new List <NPCData>();
     _positionStorage = new PositionEntity();
     _processEvent    = new ProcessEvent();
     //setUP();
     Debug.Log("End building QuestManager");
 }
Пример #5
0
        public async Task <TData <string> > SaveForm(PositionEntity entity)
        {
            var obj = new TData <string>();
            await _positionService.SaveForm(entity);

            obj.Data = entity.Id.ParseToString();
            obj.Tag  = 1;
            return(obj);
        }
Пример #6
0
 public double GetProfitLoss(PositionEntity position, OrderEntity order)
 {
     if (position.Kind == PositionKind.Long)
     {
         return((order.Price - position.AveragePrice) * 1 * order.Quantity);
     }
     else
     {
         return((order.Price - position.AveragePrice) * -1 * order.Quantity);
     }
 }
        public async Task InsertAsync(Position position)
        {
            using (DataContext context = _connectionFactory.CreateDataContext())
            {
                PositionEntity entity = Mapper.Map <PositionEntity>(position);

                context.Add(entity);

                await context.SaveChangesAsync();
            }
        }
Пример #8
0
 private void RecalculateUPL(PositionEntity position, MarketUpdateDto marketUpdate)
 {
     if (position.Kind == STP.Interfaces.Enums.PositionKind.Short)
     {
         position.UnrealizedProfitLoss = (position.AveragePrice - marketUpdate.AskPrice) * position.Quantity;
     }
     if (position.Kind == STP.Interfaces.Enums.PositionKind.Long)
     {
         position.UnrealizedProfitLoss = (marketUpdate.BidPrice - position.AveragePrice) * position.Quantity;
     }
 }
Пример #9
0
        public async Task DecreaseAsync(PositionEntity position, OrderEntity order)
        {
            position.Quantity    -= order.Quantity;
            position.AveragePrice = (position.AveragePrice + order.Price) / 2;
            position.ProfitLoss  += GetProfitLoss(position, order);

            if (position.Quantity == 0)
            {
                position.Kind = PositionKind.Flat;
                _positionCache.RemovePosition(position.Id, position.MarketId);
                await _updatesManager.UnSubscribeAsync(position.MarketId);
            }
        }
Пример #10
0
 public async Task SaveForm(PositionEntity entity)
 {
     if (entity.Id.IsNullOrZero())
     {
         // 默认赋值
         entity.Id = IdGeneratorHelper.Instance.GetId();
         await _positionEntityDB.InsertNowAsync(entity);
     }
     else
     {
         await _positionEntityDB.UpdateNowAsync(entity, ignoreNullValues : true);
     }
 }
Пример #11
0
 public void SubmitForm(PositionEntity positionEntity, string keyValue)
 {
     if (!string.IsNullOrEmpty(keyValue))
     {
         positionEntity.Modify(keyValue);
         service.Update(positionEntity);
     }
     else
     {
         positionEntity.Create();
         service.Insert(positionEntity);
     }
 }
Пример #12
0
 public void AddPosition(PositionEntity position)
 {
     _marketsPositions.AddOrUpdate(position.MarketId, new List <PositionEntity> {
         position
     }, (k, existingList) =>
     {
         lock (existingList)
         {
             existingList.Add(position);
         }
         return(existingList);
     });
 }
Пример #13
0
 public bool Delete(string Id)
 {
     bool toReturn = false;
     using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
     {
         PositionEntity _PositionEntity = new PositionEntity(Id);
         if (adapter.FetchEntity(_PositionEntity))
         {
             adapter.DeleteEntity(_PositionEntity);
             toReturn = true;
         }
     }
     return toReturn;
 }
        public async Task <Position> GetByIdAsync(string positionId)
        {
            if (!Guid.TryParse(positionId, out Guid id))
            {
                throw new ArgumentException("Invalid identifier", nameof(positionId));
            }

            using (DataContext context = _connectionFactory.CreateDataContext())
            {
                PositionEntity entity = await context.Positions.FirstOrDefaultAsync(o => o.Id == id);

                return(Mapper.Map <Position>(entity));
            }
        }
Пример #15
0
        public async Task SaveForm(PositionEntity entity)
        {
            if (entity.Id.IsNullOrZero())
            {
                await entity.Create();

                await this.BaseRepository().Insert <PositionEntity>(entity);
            }
            else
            {
                await entity.Modify();

                await this.BaseRepository().Update(entity);
            }
        }
Пример #16
0
        public bool ExistPositionName(PositionEntity entity)
        {
            var expression = LinqExtensions.True <PositionEntity>();

            expression = expression.And(t => t.BaseIsDelete == 0);
            if (entity.Id.IsNullOrZero())
            {
                expression = expression.And(t => t.PositionName == entity.PositionName);
            }
            else
            {
                expression = expression.And(t => t.PositionName == entity.PositionName && t.Id != entity.Id);
            }
            return(this.BaseRepository().IQueryable(expression).Count() > 0 ? true : false);
        }
Пример #17
0
        public async Task <TData <string> > SaveForm(PositionEntity entity)
        {
            TData <string> obj = new TData <string>();

            if (positionService.ExistPositionName(entity))
            {
                obj.Message = "职位名称已经存在!";
                return(obj);
            }
            await positionService.SaveForm(entity);

            obj.Result = entity.Id.ParseToString();
            obj.Tag    = 1;
            return(obj);
        }
        public List <Employee_HistoryEntity> ListHistory(int IdEmployee, string[] arrDepartment, string[] arrPosition)
        {
            //List all employee_department theo IdEmployee
            List <Employee_Department>    ListHistory = _iplEmployee.ListDetail(IdEmployee);
            List <Employee_HistoryEntity> listHistory = new List <Employee_HistoryEntity>();

            for (int i = 0; i < arrDepartment.Count(); i++)
            {
                var countDepartment = ListHistory.Where(x => x.IdDepartment == int.Parse(arrDepartment[i])).FirstOrDefault();
                //Thêm mới phòng ban hoặc chuyển phòng
                if (countDepartment == null)
                {
                    var a = new Employee_HistoryEntity
                    {
                        EmployeeId   = IdEmployee,
                        TimeIn       = DateTime.Now,
                        DepartmentId = int.Parse(arrDepartment[i]),
                        Position     = int.Parse(arrPosition[i]),
                    };
                    listHistory.Add(a);
                }
                else
                {
                    //Chuyển chức
                    if (countDepartment.IdPosition != int.Parse(arrPosition[i]))
                    {
                        PositionEntity namePosition = _iplPosition.ViewDetail(int.Parse(arrPosition[i]));
                        var            a            = new Employee_HistoryEntity
                        {
                            EmployeeId   = IdEmployee,
                            TimeIn       = DateTime.Now,
                            DepartmentId = int.Parse(arrDepartment[i]),
                            Position     = int.Parse(arrPosition[i]),
                        };
                        listHistory.Add(a);
                    }
                    else
                    {
                        //ko có thay đổi
                    }
                }
            }
            return(listHistory);
        }
        public async Task UpdateAsync(Position position)
        {
            using (DataContext context = _connectionFactory.CreateDataContext())
            {
                Guid id = Guid.Parse(position.Id);

                PositionEntity entity = await context.Positions
                                        .FirstOrDefaultAsync(o => o.Id == id);

                if (entity != null)
                {
                    Mapper.Map(position, entity);

                    context.Positions.Update(entity);

                    await context.SaveChangesAsync();
                }
            }
        }
Пример #20
0
        private async Task CreatePositionAsync(OrderEntity order)
        {
            PositionEntity newPosition = new PositionEntity()
            {
                MarketId     = order.MarketId,
                UserId       = order.UserId,
                Quantity     = order.Quantity,
                Kind         = order.Action == OrderAction.Buy ? PositionKind.Long : PositionKind.Short,
                AveragePrice = order.Price,
                Timestamp    = DateTime.UtcNow,
                EntryOrderId = order.Id
            };
            await _positionRepository.InsertAsync(newPosition);

            await _positionRepository.UnitOfWork.SaveChangesAsync();

            _positionCache.AddPosition(newPosition);
            await _updatesManager.SubscribeAsync(newPosition.MarketId);

            _messageBus.Publish(newPosition, "exc.Position", RabbitExchangeType.DirectExchange, $"Update:{newPosition.UserId}");
        }
Пример #21
0
        public async Task <IActionResult> SaveFormJson(PositionEntity entity)
        {
            TData <string> obj = await sysPositionBLL.SaveForm(entity);

            return(Json(obj));
        }
Пример #22
0
        public async Task <TData <string> > SaveFormJson([FromForm] PositionEntity entity)
        {
            var obj = await _positionBLL.SaveForm(entity);

            return(obj);
        }
        public JsonResult NoteDepartment_Position(int IdEmployee, string[] arrDepartment, string[] arrPosition)
        {
            if (IdEmployee == 0 || arrDepartment.Count() != arrPosition.Count())
            {
                return(Json(new { status = false }, JsonRequestBehavior.AllowGet));
            }
            List <Employee_Department> ListHistory = _iplEmployee.ListDetail(IdEmployee);
            List <Employee_History>    ListNote    = new List <Employee_History>();

            for (int i = 0; i < arrDepartment.Count(); i++)
            {
                var countDepartment = ListHistory.Where(x => x.IdDepartment == int.Parse(arrDepartment[i])).FirstOrDefault();
                DepartmentEntity nameDepartmentNew = _iplDepartment.ViewDetail(int.Parse(arrDepartment[i]));
                if (ListHistory.Count() == arrDepartment.Count())
                {
                    if (countDepartment == null)
                    {
                        var a = new Employee_History
                        {
                            Note           = "Chuyển sang phòng ban " + nameDepartmentNew.Name,
                            IdDepartment   = int.Parse(arrDepartment[i]),
                            NameDepartment = "chuyển phòng " + nameDepartmentNew.Name
                        };
                        ListNote.Add(a);
                    }
                }
                else
                {
                    if (countDepartment == null)
                    {
                        var a = new Employee_History
                        {
                            Note           = "Được phân công vào phòng ban mới.",
                            IdDepartment   = int.Parse(arrDepartment[i]),
                            NameDepartment = "chuyển phòng " + nameDepartmentNew.Name
                        };
                        ListNote.Add(a);
                    }
                }
                if (countDepartment != null && countDepartment.IdPosition != int.Parse(arrPosition[i]))
                {
                    PositionEntity namePosition = _iplPosition.ViewDetail(int.Parse(arrPosition[i]));
                    if (countDepartment.IdPosition > namePosition.Id)
                    {
                        var a = new Employee_History
                        {
                            Note           = "Chuyển chức vụ từ " + countDepartment.NamePosition + " phòng " + nameDepartmentNew.Name + " lên chức vụ " + namePosition.Name + " phòng " + nameDepartmentNew.Name,
                            IdDepartment   = int.Parse(arrDepartment[i]),
                            NameDepartment = "chuyển chức " + nameDepartmentNew.Name
                        };
                        ListNote.Add(a);
                    }
                    else
                    {
                        var a = new Employee_History
                        {
                            Note           = "Chuyển chức vụ từ " + countDepartment.NamePosition + " phòng " + nameDepartmentNew.Name + " xuống chức vụ " + namePosition.Name + " phòng " + nameDepartmentNew.Name,
                            IdDepartment   = int.Parse(arrDepartment[i]),
                            NameDepartment = "chuyển chức " + nameDepartmentNew.Name
                        };
                        ListNote.Add(a);
                    }
                }
            }
            if (ListNote.Count() > 0)
            {
                return(Json(new { status = true, data = ListNote }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(new { status = false }, JsonRequestBehavior.AllowGet));
            }
        }
Пример #24
0
 public PositionEntity SelectOne(string Id)
 {
     PositionEntity toReturn = null;
     using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
     {
         PositionEntity _PositionEntity = new PositionEntity(Id);
         if (adapter.FetchEntity(_PositionEntity))
         {
             toReturn = _PositionEntity;
         }
     }
     return toReturn;
 }
Пример #25
0
        public PositionEntity Insert(string PositionName, string ParentId, int OrderIndex)
        {
            PositionEntity _PositionEntity = new PositionEntity();
            using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
            {

                _PositionEntity.PositionName = PositionName;
                _PositionEntity.ParentId = ParentId;
                _PositionEntity.OrderIndex = OrderIndex;
                adapter.SaveEntity(_PositionEntity, true);
            }
            return _PositionEntity;
        }
Пример #26
0
 private async Task IncreaseAsync(PositionEntity position, OrderEntity order)
 {
     position.Quantity    += order.Quantity;
     position.AveragePrice = (position.AveragePrice + order.Price) / 2;
 }
Пример #27
0
        public async Task PlaceOrderAsync(OrderEntity order)
        {
            PositionEntity position = _positionCache.TryGetOpenedPosition(order.MarketId, order.UserId);

            if (position == null)
            {
                await CreatePositionAsync(order);
            }
            else
            {
                long remainder = 0;
                if (order.Quantity > position.Quantity)
                {
                    remainder       = order.Quantity - position.Quantity;
                    order.Quantity -= remainder;
                }

                if (position.Kind == PositionKind.Long)
                {
                    if (order.Action == OrderAction.Buy)
                    {
                        await IncreaseAsync(position, order);
                    }
                    else // Sell
                    {
                        await DecreaseAsync(position, order);
                    }
                }
                else // Short Position
                {
                    if (order.Action == OrderAction.Buy)
                    {
                        await DecreaseAsync(position, order);
                    }
                    else // sell
                    {
                        await IncreaseAsync(position, order);
                    }
                }
                _positionRepository.Update(position);
                await _positionRepository.UnitOfWork.SaveChangesAsync();

                _messageBus.Publish(position, "exc.Position", RabbitExchangeType.DirectExchange, $"Update:{position.UserId}");
                TraderInfoEntity trader = await _traderInfoManager.GetByIdAsync(position.UserId);

                trader.ProfitLoss += position.ProfitLoss;
                await _traderInfoManager.UpdateAsync(trader);

                if (remainder > 0)
                {
                    await CreatePositionAsync(new OrderEntity()
                    {
                        Action    = order.Action,
                        MarketId  = order.MarketId,
                        Price     = order.Price,
                        Quantity  = remainder,
                        Timestamp = DateTime.UtcNow,
                        UserId    = order.UserId
                    });
                }
            }
        }
Пример #28
0
 public ActionResult SubmitForm(PositionEntity positionEntity, string keyValue)
 {
     positionApp.SubmitForm(positionEntity, keyValue);
     return(Success("操作成功。"));
 }
Пример #29
0
        public bool Update(string Id, string PositionName, string ParentId, int OrderIndex)
        {
            bool toReturn = false;
            using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
            {
                PositionEntity _PositionEntity = new PositionEntity(Id);
                if (adapter.FetchEntity(_PositionEntity))
                {

                    _PositionEntity.PositionName = PositionName;
                    _PositionEntity.ParentId = ParentId;
                    _PositionEntity.OrderIndex = OrderIndex;
                    adapter.SaveEntity(_PositionEntity, true);
                    toReturn = true;
                }
            }
            return toReturn;
        }
Пример #30
0
 public PositionEntity Insert(PositionEntity _PositionEntity)
 {
     using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
     {
         adapter.SaveEntity(_PositionEntity, true);
     }
     return _PositionEntity;
 }
Пример #31
0
 public bool Update(PositionEntity _PositionEntity, RelationPredicateBucket filter)
 {
     bool toReturn = false;
     using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
     {
         adapter.UpdateEntitiesDirectly(_PositionEntity, filter);
         toReturn = true;
     }
     return toReturn;
 }
Пример #32
0
        public bool Update(PositionEntity _PositionEntity)
        {
            bool toReturn = false;
            using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
            {
                RelationPredicateBucket filter = new RelationPredicateBucket();
                IPredicateExpression _PredicateExpression = new PredicateExpression();
                _PredicateExpression.Add(PositionFields.Id == _PositionEntity.Id);

                filter.PredicateExpression.Add(_PredicateExpression);

                adapter.UpdateEntitiesDirectly(_PositionEntity, filter);
                toReturn = true;
            }
            return toReturn;
        }