Esempio n. 1
0
        public virtual void ImportPositionInfoFromDelivery(int accountId, int year, int month, bool clearExisted)
        {
            var yearMonth = year * 100 + month;

            if (clearExisted)
            {
                var existedPositions = _MIPositionRepo.Table.Where(x => x.AccountId == accountId && x.YearMonth == yearMonth);

                _MIPositionRepo.Delete(existedPositions);
            }

            var dateFrom        = new DateTime(year, month, 1).AddMonths(-1);
            var dateTo          = new DateTime(year, month, 1).AddDays(-1);
            var deliveryRecords = _deliveryRecordService.GetDeliveryRecordsDetail(null, accountId, null, null, dateTo, null, null, null).GroupBy(x => x.StockCode);

            foreach (var recordByStockCode in deliveryRecords)
            {
                var firstRecord = recordByStockCode.First();

                var positionVolume = recordByStockCode.Sum(x => x.DealVolume);

                if (positionVolume != 0)
                {
                    var entity = new MIAccountPosition
                    {
                        AccountCode    = null,
                        AccountId      = accountId,
                        PositionVolume = positionVolume,
                        StockCode      = firstRecord.StockCode,
                        StockName      = firstRecord.StockName,
                        YearMonth      = yearMonth,
                    };

                    _MIPositionRepo.Insert(entity);
                }
            }
        }
Esempio n. 2
0
        public virtual void AddMIAccountPosition(int accountId, string accountCode, int year, int month, string stockCode, string stockName)
        {
            var yearMonth = year * 100 + month;

            var stockPosition = _MIPositionRepo.TableNoTracking.FirstOrDefault(x => x.AccountId == accountId && x.YearMonth == yearMonth && x.StockCode == stockCode);

            if (stockPosition == null)
            {
                var dateFrom = new DateTime(year, month, 1).AddMonths(-1);
                var dateTo   = new DateTime(year, month, 1).AddDays(-1);

                var lastInitPosition = _MIPositionRepo.TableNoTracking.FirstOrDefault(x => x.AccountId == accountId && x.YearMonth == (dateFrom.Year * 100 + dateFrom.Month) && x.StockCode == stockCode);

                decimal deliveryPositionVolume = 0;

                if (lastInitPosition == null)
                {
                    deliveryPositionVolume = _deliveryRecordService.GetDeliveryRecordsDetail(stockCode, accountId, null, null, dateTo, null, null, null).Sum(x => x.DealVolume);
                }
                else
                {
                    deliveryPositionVolume = lastInitPosition.PositionVolume + _deliveryRecordService.GetDeliveryRecordsDetail(stockCode, accountId, null, dateFrom, dateTo, null, null, null).Sum(x => x.DealVolume);
                }

                var positionInfo = new MIAccountPosition
                {
                    AccountCode    = accountCode,
                    AccountId      = accountId,
                    PositionVolume = deliveryPositionVolume,
                    StockCode      = stockCode,
                    StockName      = stockName,
                    YearMonth      = yearMonth,
                };

                _MIPositionRepo.Insert(positionInfo);
            }
        }