Ejemplo n.º 1
0
        /// <summary>
        /// 同步车辆信息(外网-->内网)
        /// </summary>
        /// <param name="output"></param>
        /// <returns></returns>
        public void SyncCarData(string OutsideAddress, Action <string, eOutputType> output)
        {
            int res = 0;
            //调用接口获取需要同步到内网的数据
            string str = apiHelper.HttpApi(OutsideAddress + "api/services/baseinfo/CarManager/GetSyncList", "", "post");
            ApiListResult <CmcsAutotruck> result = JsonConvert.DeserializeObject <ApiListResult <CmcsAutotruck> >(str);

            if (result.success && result.result != null && result.result.items.Count > 0)
            {
                foreach (var item in result.result.items)
                {
                    int flag = 0;
                    item.SyncFlag = 1;
                    var entity = selfDber.EntitiesContainDeleted <CmcsAutotruck>(" where id='" + item.Id + "'").FirstOrDefault();
                    if (entity == null)
                    {
                        flag += selfDber.Insert(item);
                    }
                    else
                    {
                        flag += selfDber.Update(item);
                    }
                    if (flag > 0)//内网更新成功后调用外网的接口将数据更新为不需要再次同步
                    {
                        apiHelper.HttpApi(OutsideAddress + "api/services/baseinfo/CarManager/SyncDataCallBack", JsonConvert.SerializeObject(item), "post");
                    }
                    res += flag;
                }
            }
            if (res > 0)
            {
                output(string.Format("车辆管理信息同步(外网-->内网) {0} 条", res), eOutputType.Normal);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 保存矿发数据
        /// </summary>
        /// <param name="sendEntities"></param>
        /// <param name="output"></param>
        public void SaveCarSendData(List <WL_CarSendInfo> sendEntities, Action <string, eOutputType> output)
        {
            foreach (var item in sendEntities)
            {
                if (string.IsNullOrWhiteSpace(item.物流矿发编号))
                {
                    continue;
                }

                var entity = SelfDber.Entity <CmcsInNetTransport>(" where SerialNumber=:SerialNumber", new { SerialNumber = item.物流矿发编号 });
                if (entity == null)
                {
                    #region 新增
                    entity = new CmcsInNetTransport();
                    entity.SerialNumber = item.物流矿发编号;
                    entity.FactoryName  = item.所属单位名称;

                    var supplier = SelfDber.Entity <CmcsSupplier>(" where Name=:Name", new { Name = item.供应商名称 });
                    if (supplier != null)
                    {
                        entity.SupplierId = supplier.Id;
                    }
                    entity.SupplierName = item.供应商名称;

                    var mine = SelfDber.Entity <CmcsMine>(" where Name=:Name", new { Name = item.矿点名称 });
                    if (mine != null)
                    {
                        entity.MineId = mine.Id;
                    }
                    entity.MineName = item.矿点名称;

                    var fuelkind = SelfDber.Entity <CmcsFuelKind>(" where Name=:Name", new { Name = item.品种名称 });
                    if (fuelkind != null)
                    {
                        entity.FuelKindId = fuelkind.Id;
                    }
                    entity.FuelKindName = item.品种名称;

                    var transCompany = SelfDber.Entity <CmcsTransportCompany>(" where Name=:Name", new { Name = item.承运商名称 });
                    if (transCompany != null)
                    {
                        entity.TransportCompanyId = transCompany.Id;
                    }
                    entity.TransportCompanyName = item.承运商名称;

                    var autoTruck = SelfDber.Entity <CmcsAutotruck>(" where CarNumber=:CarNumber", new { CarNumber = item.车牌号 });
                    if (autoTruck != null)
                    {
                        entity.AutoTruckId = autoTruck.Id;
                    }
                    entity.CarNumber = item.车牌号;

                    entity.IDCard       = item.驾驶员身份证;
                    entity.TicketWeight = item.矿发净重;
                    entity.SealNumber   = item.封签号;
                    entity.CreationTime = item.创建时间;
                    entity.StartTime    = item.创建时间;
                    entity.StepName     = "在途";
                    entity.IsFinish     = 0;
                    entity.SyncFlag     = 0;
                    entity.Remark       = "智能物流同步";

                    if (SelfDber.Insert <CmcsInNetTransport>(entity) > 0)
                    {
                        output("始发表数据获取成功,操作:新增,数据:" + Newtonsoft.Json.JsonConvert.SerializeObject(item), eOutputType.Normal);
                        item.步完成   = 1;
                        item.步完成时间 = DateTime.Now;
                        //if (mysqlDber.Update<WL_CarSendInfo>(item) > 0)
                        if (mysqlDber.Execute(string.Format("update 始发表 set 同步完成=1,同步完成时间='{0}' where 编号={1}", DateTime.Now, item.编号)) > 0)
                        {
                            output("始发表数据获取后回写成功,数据:" + Newtonsoft.Json.JsonConvert.SerializeObject(item), eOutputType.Normal);
                        }
                    }

                    #endregion
                }
                else
                {
                    #region 修改
                    entity.FactoryName = item.所属单位名称;

                    var supplier = SelfDber.Entity <CmcsSupplier>(" where Name=:Name", new { Name = item.供应商名称 });
                    if (supplier != null)
                    {
                        entity.SupplierId = supplier.Id;
                    }
                    entity.SupplierName = item.供应商名称;

                    var mine = SelfDber.Entity <CmcsMine>(" where Name=:Name", new { Name = item.矿点名称 });
                    if (mine != null)
                    {
                        entity.MineId = mine.Id;
                    }
                    entity.MineName = item.矿点名称;

                    var fuelkind = SelfDber.Entity <CmcsFuelKind>(" where Name=:Name", new { Name = item.品种名称 });
                    if (fuelkind != null)
                    {
                        entity.FuelKindId = fuelkind.Id;
                    }
                    entity.FuelKindName = item.品种名称;

                    var transCompany = SelfDber.Entity <CmcsTransportCompany>(" where Name=:Name", new { Name = item.承运商名称 });
                    if (transCompany != null)
                    {
                        entity.TransportCompanyId = transCompany.Id;
                    }
                    entity.TransportCompanyName = item.承运商名称;

                    var autoTruck = SelfDber.Entity <CmcsAutotruck>(" where CarNumber=:CarNumber", new { CarNumber = item.车牌号 });
                    if (autoTruck != null)
                    {
                        entity.AutoTruckId = autoTruck.Id;
                    }
                    entity.CarNumber = item.车牌号;

                    entity.IDCard       = item.驾驶员身份证;
                    entity.TicketWeight = item.矿发净重;
                    entity.SealNumber   = item.封签号;
                    entity.SyncFlag     = 0;

                    if (SelfDber.Update <CmcsInNetTransport>(entity) > 0)
                    {
                        output("始发表数据获取成功,操作:更新,数据:" + Newtonsoft.Json.JsonConvert.SerializeObject(item), eOutputType.Normal);
                        item.步完成   = 1;
                        item.步完成时间 = DateTime.Now;
                        //if (mysqlDber.Update<WL_CarSendInfo>(item) > 0)
                        if (mysqlDber.Execute(string.Format("update 始发表 set 同步完成=1,同步完成时间='{0}' where 编号={1}", DateTime.Now, item.编号)) > 0)
                        {
                            output("始发表数据获取后回写成功,数据:" + Newtonsoft.Json.JsonConvert.SerializeObject(item), eOutputType.Normal);
                        }
                    }
                    #endregion
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 生成路线偏离数据
        /// </summary>
        /// <param name="output"></param>
        /// <returns></returns>
        public void SaveToCarDeciationRoute(Action <string, eOutputType> output)
        {
            DeviateWarning warning = SelfDber.Entity <DeviateWarning>("where IsDeleted=0");

            if (warning == null)
            {
                output("未设置路线偏离预警距离!", eOutputType.Error);
                return;
            }
            if (warning.Distance <= 0)
            {
                output("设置路线偏离预警距离小于等于0,请正确设置!", eOutputType.Error);
                return;
            }

            //查询所有在途的车辆,然后根据运输记录中的实时位置去判断路线的偏离
            List <ShowEntity> list = GetInRouteCars();

            if (list == null || list.Count <= 0)
            {
                output("暂无在途车辆!", eOutputType.Warn);
                return;
            }
            foreach (var item in list)
            {
                if (string.IsNullOrWhiteSpace(item.ROUTEPOINTS))
                {
                    output(string.Format("车号:{0},运输记录ID:{1}对应的发车未设置线路!", item.CARNUMBER, item.ID), eOutputType.Error);
                    continue;
                }

                //如果车辆已报修并且未处理就不管了偏不偏移了
                DataTable dtIsRepair = SelfDber.ExecuteDataTable(String.Format("select count(1) from CMCSTBCARREPAIRINFO t where t.isdeleted=0 and t.repairstatus=0 and t.carid='{0}'", item.CarId));
                if (dtIsRepair != null && dtIsRepair.Rows.Count > 0 && dtIsRepair.Rows[0][0].ToString() != "0")//车辆去修理了就不算路线偏移
                {
                    continue;
                }

                double sslng = 0;
                double sslat = 0;
                double.TryParse(item.LONGITUDE, out sslng);
                double.TryParse(item.LATITUDE, out sslat);
                if (sslng <= 0 || sslat <= 0)
                {
                    output(string.Format("车号:{0},运输记录ID:{1}暂无实时位置!", item.CARNUMBER, item.ID), eOutputType.Error);
                    continue;
                }
                string[] lnglats = item.ROUTEPOINTS.Trim('|').Split('|');
                //循环点一个一个的计算
                List <double> minDistance = new List <double>();
                foreach (var lnglat in lnglats)
                {
                    minDistance.Add(GaodeHelper.GetTwoPointDistance(sslat, sslng, double.Parse(lnglat.Split(',')[1]), double.Parse(lnglat.Split(',')[0])));
                }
                //最近的距离偏离了就算偏离
                decimal          minDis = (decimal)Math.Round(minDistance.Min(), 2, MidpointRounding.AwayFromZero);
                DeviateErrorInfo entity = SelfDber.Entity <DeviateErrorInfo>(string.Format(" where TransportRecordId='{0}' and StartTime is not null and EndTime is null order by StartTime desc", item.ID));
                if (minDis >= warning.Distance)
                {
                    //偏离了
                    //首先判断存不存在有开始时间但是没有结束时间的数据,有就不管,没有则新增一条结束时间为空,开始时间为当前时间的数据,偏离距离取最小值
                    if (entity == null)
                    {
                        entity = new DeviateErrorInfo();
                        entity.TransportRecordId = item.ID;
                        entity.Distance          = minDis;
                        entity.StartTime         = DateTime.Now;
                        entity.Remark            = string.Format("货车:{0},在{1}偏离计划路线,偏离距离{2}米", item.CARNUMBER, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), entity.Distance);
                        if (SelfDber.Insert(entity) > 0)
                        {
                            output(string.Format("车号:{0},运输记录ID:{1}发现路线偏离并记录,偏离距离:{2}!", item.CARNUMBER, item.ID, entity.Distance), eOutputType.Normal);
                            string updateSql = string.Format("update cmcstbbuyfueltransport t set t.ISDEVIATEEERR=1 where t.id='{0}'", item.ID);
                            SelfDber.Execute(updateSql);
                        }
                    }
                }
                else
                {
                    //没有偏离
                    //首先判断存不存在有开始时间但是没有结束时间的数据,有就将结束时间改为当前时间,没有就不管
                    if (entity != null)
                    {
                        entity.Distance = entity.Distance > minDis ? entity.Distance : minDis;
                        entity.EndTime  = DateTime.Now;
                        entity.Remark   = string.Format("货车:{0},在{1}偏离计划路线,于{2}回归计划路线,最大偏离距离{3}米", item.CARNUMBER, entity.StartTime.ToString("yyyy-MM-dd HH:mm:ss"), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), entity.Distance);
                        if (SelfDber.Update(entity) > 0)
                        {
                            output(string.Format("车号:{0},运输记录ID:{1}回归计划路线!", item.CARNUMBER, item.ID), eOutputType.Normal);
                            string updateSql = string.Format("update cmcstbbuyfueltransport t set t.ISDEVIATEEERR=1 where t.id='{0}'", item.ID);
                            SelfDber.Execute(updateSql);
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 生成车辆异常停留位置数据
        /// </summary>
        /// <param name="output"></param>
        /// <returns></returns>
        public void SaveToCarStopTime(Action <string, eOutputType> output, AbnormalStayWarning warning)
        {
            //查询所有在途的车辆,然后判断该车辆最近的两次经纬度是否在同一点
            List <ShowEntity> list = GetInRouteCars();

            if (list == null || list.Count <= 0)
            {
                output("暂无在途车辆!", eOutputType.Warn);
                return;
            }
            foreach (var item in list)
            {
                item.isStop = false;
                //如果车辆已报修并且未处理就不管了
                DataTable dtIsRepair = SelfDber.ExecuteDataTable(String.Format("select count(1) from CMCSTBCARREPAIRINFO t where t.isdeleted=0 and t.repairstatus=0 and t.carid='{0}'", item.CarId));
                if (dtIsRepair != null && dtIsRepair.Rows.Count > 0 && dtIsRepair.Rows[0][0].ToString() != "0")//车辆去修理了就不管
                {
                    continue;
                }

                //List<CarLongLatHistory> historyList = SelfDber.Entities<CarLongLatHistory>(string.Format(" where TransportRecordId='{0}' and CreationTime>=to_date('{1}','yyyy-mm-dd hh24:mi:ss') order by CreationTime desc", item.ID, DateTime.Now.AddMinutes(-(double)warning.StopTime)));
                List <CarLongLatHistory> historyList = SelfDber.Entities <CarLongLatHistory>(string.Format(" where TransportRecordId='{0}' and CreationTime>=to_date('{1}','yyyy-mm-dd hh24:mi:ss') order by CreationTime desc", item.ID, DateTime.Parse("2020-04-10 11:05:58").AddMinutes(-(double)warning.StopTime)));
                if (historyList.Count <= 1)
                {
                    continue;
                }

                historyList = historyList.OrderByDescending(a => a.CreationTime).ToList();
                var distance = GaodeHelper.GetTwoPointDistance((double)historyList.First().Latitude, (double)historyList.First().Longitude, (double)historyList.Last().Latitude, (double)historyList.Last().Longitude);
                if (distance <= 5)//距离在5米内默认没移动
                {
                    item.StopMintes = (historyList.First().CreationTime - historyList.Last().CreationTime).TotalMinutes;
                    item.LONGITUDE  = historyList.First().Longitude.ToString();
                    item.LATITUDE   = historyList.First().Latitude.ToString();
                    item.isStop     = true;
                }
            }

            foreach (var item in list)
            {
                StopErrorInfo entity = SelfDber.Entity <StopErrorInfo>(string.Format(" where TransportRecordId='{0}' and StartTime is not null and EndTime is null order by StartTime desc", item.ID));

                //同一批次其他的车没停,百分之几的车停了那停的车就算异常

                bool isPercent = (list.Count(a => a.MineSendId == item.MineSendId && a.isStop) < (list.Count(a => a.MineSendId == item.MineSendId) * warning.StopNumber) / 100m);

                if (item.isStop && entity == null && isPercent)
                {
                    entity = new StopErrorInfo();
                    entity.TransportRecordId = item.ID;
                    entity.StopPoint         = item.LONGITUDE + "," + item.LATITUDE;
                    string place = GaodeHelper.GetLocation(entity.StopPoint);
                    if (string.IsNullOrWhiteSpace(place))
                    {
                        continue;
                    }
                    entity.StopPlace = place;
                    entity.StopTime  = decimal.Parse(item.StopMintes.ToString("F0"));
                    entity.StopTime  = entity.StopTime > warning.StopTime ? entity.StopTime : warning.StopTime;
                    entity.StartTime = DateTime.Now;
                    entity.StopNum   = Math.Round((list.Count(a => a.MineSendId == item.MineSendId && a.isStop) / list.Count(a => a.MineSendId == item.MineSendId)) * 100m, 2, MidpointRounding.AwayFromZero);
                    entity.Remark    = string.Format("货车:{0},于{1}开始在{2}异常停留时间超过{3}分钟!", item.CARNUMBER, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), entity.StopPlace, entity.StopTime);
                    if (SelfDber.Insert(entity) > 0)
                    {
                        output(entity.Remark, eOutputType.Normal);
                        string updateSql = string.Format("update cmcstbbuyfueltransport t set t.isstoperr=1 where t.id='{0}'", item.ID);
                        SelfDber.Execute(updateSql);
                    }
                }
                else if (entity != null)//如果没有异常停留需要将异常停留信息结束
                {
                    entity.EndTime  = DateTime.Now;
                    entity.StopTime = decimal.Parse((entity.StartTime - entity.EndTime).TotalMinutes.ToString("F0"));
                    entity.Remark   = string.Format("货车:{0},于{1}至{2}在{3}异常停留{4}分钟!", item.CARNUMBER, entity.StartTime.ToString("yyyy-MM-dd HH:mm:ss"), entity.EndTime.ToString("yyyy-MM-dd HH:mm:ss"), entity.StopPlace, entity.StopTime);
                    if (SelfDber.Update(entity) > 0)
                    {
                        output(entity.Remark, eOutputType.Normal);
                        string updateSql = string.Format("update cmcstbbuyfueltransport t set t.isstoperr=1 where t.id='{0}'", item.ID);
                        SelfDber.Execute(updateSql);
                    }
                }
            }
        }