Esempio n. 1
0
        private List<EGPSHistoryInfo> GetGPSHistoryInfoList(EHistoryDataStoreConfig tableConfig, DateTime StartTime, DateTime EndTime, int size)
        {
            if (tableConfig == null || tableConfig.StoreTable == null)
                return new List<EGPSHistoryInfo>();

            //ado.net 获取历史记录
            return DACFacade.Gps.GPSHistoryDAC.SelectList(tableConfig.StoreTable.SelectConnStr, tableConfig.StoreTable.TableName, tableConfig.VehicleCode.ToString(), StartTime, EndTime, size).ToList();
        }
        public void AddVehicleOperateTran(string tenantCode, string licenceNumber, string deviceNo, string SIMNo, EnumVehicleType vehicleType, string passportUserName, ulong groupID)
        {
            if (DACFacade.Movo.VehicleDAC.IsExist(tenantCode, licenceNumber)) throw new BusinessException("已经有相同车牌号的车辆!");


            var rep = DMRepository.Get<EVehicle>();

            var device = rep.Get(p => p.DeviceNo == deviceNo);

            if (device == null) throw new NullReferenceException("要关联的设备不存在!设备号:" + deviceNo + "");


            device.SIMNo = SIMNo;
            device.LicenceNumber = licenceNumber;
            device.GroupID = groupID;
            device.TenantCode = tenantCode;
            device.InstallTime = DateTime.Now;

            using (var dmTrans = DMContext.GetTransaction())
            {
                try
                {
                    var trans = dmTrans.BeginTransaction();
                    rep.Save(device, p => p.VehicleCode == device.VehicleCode, trans);

                    if (DACFacade.Gps.HistoryDataStoreConfigDAC.Select(device.VehicleCode) == null)
                    {
                        //新增车辆历史数据配置
                        var gpsTypeEntity = DACFacade.Gps.GpsTypeDAC.Select(device.GPSTypeID);
                        if (gpsTypeEntity == null) throw new BusinessException("设备类型不存在,请重新填写!");

                        string tableName = GetGPSCodeHelper.GetTableNameByCondition(gpsTypeEntity.PrefixCode);
                        var table = DACFacade.Gps.HistoryDataStoreConfigDAC.SelectHisotryDataStoreTableByTbName(tableName);
                        if (table == null) throw new BusinessException(string.Format("找不到对应的历史数据表[{0}],请联系DBA!", tableName));
                        var configEntity = new EHistoryDataStoreConfig();
                        configEntity.RecordID = Guid.NewGuid();
                        configEntity.CreateDate = DateTime.Now;
                        configEntity.Enable = true;
                        configEntity.StoreTable = table;
                        configEntity.VehicleCode = device.VehicleCode;

                        DACFacade.Gps.HistoryDataStoreConfigDAC.Insert(trans, configEntity);
                    }

                    if (rep.Get<EVehicleLog>(p => p.VehicleCode == device.VehicleCode) == null)
                    {
                        //新增车辆Log
                        var vehicleLog = new EVehicleLog()
                        {
                            BeginDate = DateTime.Now,
                            LogID = DACFacade.Movo.IdentityNoDAC.GetVehicleLogID(),
                            DeviceNo = device.DeviceNo,
                            EndDate = null,
                            GPSCode = device.GPSCode,
                            GPSTypeID = device.GPSTypeID,
                            InitMileage = device.InitMileage,
                            LicenceNumber = device.LicenceNumber,
                            Operator = passportUserName,
                            SIMNo = device.SIMNo,
                            TenantCode = device.TenantCode,
                            VehicleCode = device.VehicleCode,
                            GroupID = device.GroupID
                        };

                        rep.Add(vehicleLog, trans);
                    }

                    dmTrans.Commit();
                }
                catch (Exception ex)
                {
                    dmTrans.Rollback();
                    throw ex;
                }
            }
        }