/// <summary>
        /// 修改自提点
        /// </summary>
        /// <param name="selfTakeStationDTO">自提点实体</param>
        /// <returns>结果</returns>
        public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO UpdateSelfTakeStation(Jinher.AMP.BTP.Deploy.CustomDTO.SelfTakeStationAndManagerDTO selfTakeStationDTO)
        {
            //定义返回值
            Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO result;

            try
            {
                //调用代理方法
                result = base.Channel.UpdateSelfTakeStation(selfTakeStationDTO);
            }
            catch
            {
                //抛异常
                throw;
            }
            finally
            {
                //关链接
                ChannelClose();
            }            //返回结果
            return(result);
        }
 /// <summary>
 /// 修改自提点
 /// </summary>
 /// <param name="selfTakeStationDTO">自提点实体</param>
 /// <returns>结果</returns>
 public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO UpdateSelfTakeStation(Jinher.AMP.BTP.Deploy.CustomDTO.SelfTakeStationAndManagerDTO selfTakeStationDTO)
 {
     base.Do();
     return(this.Command.UpdateSelfTakeStation(selfTakeStationDTO));
 }
        /// <summary>
        /// 修改自提点
        /// </summary>
        /// <param name="selfTakeStationDTO">自提点实体(District、Remark字段暂时无用)</param>
        /// <returns>结果</returns>
        public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO UpdateSelfTakeStationExt(Jinher.AMP.BTP.Deploy.CustomDTO.SelfTakeStationAndManagerDTO selfTakeStationDTO)
        {
            if (selfTakeStationDTO == null)
            {
                return(new ResultDTO {
                    ResultCode = 1, Message = "自提点实体不能为空"
                });
            }

            if (selfTakeStationDTO.Id == Guid.Empty || selfTakeStationDTO.CityOwnerId == Guid.Empty || string.IsNullOrWhiteSpace(selfTakeStationDTO.Name) || string.IsNullOrWhiteSpace(selfTakeStationDTO.Province) || string.IsNullOrWhiteSpace(selfTakeStationDTO.Address))
            {
                return(new ResultDTO {
                    ResultCode = 1, Message = "自提点参数错误"
                });
            }
            if (string.IsNullOrWhiteSpace(selfTakeStationDTO.City))
            {
                return(new ResultDTO {
                    ResultCode = 1, Message = "自提点参数错误"
                });
            }
            if (string.IsNullOrWhiteSpace(selfTakeStationDTO.QRCodeUrl) || selfTakeStationDTO.SpreadCode == Guid.Empty)
            {
                return(new ResultDTO {
                    ResultCode = 1, Message = "自提点参数错误"
                });
            }
            if (selfTakeStationDTO.SelfTakeStationType == 1 && (!selfTakeStationDTO.AppId.HasValue || selfTakeStationDTO.AppId == Guid.Empty))
            {
                return(new ResultDTO {
                    ResultCode = 1, Message = "自提点参数错误"
                });
            }
            if (selfTakeStationDTO.selfTakeStationManager == null)
            {
                selfTakeStationDTO.selfTakeStationManager = new List <SelfTakeStationManagerSDTO>();
            }
            try
            {
                DateTime       now            = DateTime.Now;
                ContextSession contextSession = ContextFactory.CurrentThreadContext;

                SelfTakeStation selfTakeStation = SelfTakeStation.ObjectSet().FirstOrDefault(t => t.Id == selfTakeStationDTO.Id);
                if (selfTakeStation == null)
                {
                    return new ResultDTO {
                               ResultCode = 1, Message = "Error"
                    }
                }
                ;
                selfTakeStation.Name        = selfTakeStationDTO.Name;
                selfTakeStation.Province    = selfTakeStationDTO.Province;
                selfTakeStation.City        = selfTakeStationDTO.City;
                selfTakeStation.District    = "";
                selfTakeStation.Address     = selfTakeStationDTO.Address;
                selfTakeStation.SpreadUrl   = selfTakeStationDTO.SpreadUrl;
                selfTakeStation.Remark      = "";
                selfTakeStation.QRCodeUrl   = selfTakeStationDTO.QRCodeUrl;
                selfTakeStation.SpreadCode  = selfTakeStationDTO.SpreadCode;
                selfTakeStation.EntityState = System.Data.EntityState.Modified;
                contextSession.SaveObject(selfTakeStation);
                var selfManagerIdsExitsModels = SelfTakeStationManager.ObjectSet().Where(t => t.SelfTakeStationId == selfTakeStationDTO.Id && !t.IsDel).ToList();
                var exitsUserIds  = selfManagerIdsExitsModels.Select(t => t.UserId).ToList();
                var updateUserIds = selfTakeStationDTO.selfTakeStationManager.Select(t => t.UserId).ToList();

                var insertUserIds = updateUserIds.Except(exitsUserIds).ToList();
                var deleteUserIds = exitsUserIds.Except(updateUserIds).ToList();

                //删除
                foreach (var deleteUserId in deleteUserIds)
                {
                    SelfTakeStationManager selfTakeStationManager = selfManagerIdsExitsModels.First(t => t.UserId == deleteUserId);

                    selfTakeStationManager.IsDel       = true;
                    selfTakeStationManager.EntityState = System.Data.EntityState.Modified;
                    selfTakeStationManager.ModifiedOn  = now;
                }

                foreach (var selfManager in selfTakeStationDTO.selfTakeStationManager)
                {
                    //插入
                    if (insertUserIds.Contains(selfManager.UserId))
                    {
                        SelfTakeStationManager selfTakeStationManager = new SelfTakeStationManager()
                        {
                            Id                = Guid.NewGuid(),
                            UserCode          = selfManager.UserCode,
                            UserId            = selfManager.UserId,
                            SelfTakeStationId = selfTakeStationDTO.Id
                        };
                        selfTakeStationManager.EntityState = System.Data.EntityState.Added;
                        contextSession.SaveObject(selfTakeStationManager);
                    }
                }
                contextSession.SaveChanges();
            }
            catch (Exception ex)
            {
                LogHelper.Error(string.Format("修改自提点服务异常。selfTakeStationDTO:{0}", JsonHelper.JsonSerializer(selfTakeStationDTO)), ex);
                return(new ResultDTO {
                    ResultCode = 1, Message = "Error"
                });
            }

            return(new ResultDTO {
                ResultCode = 0, Message = "Success"
            });
        }
        /// <summary>
        /// 添加自提点
        /// </summary>
        /// <param name="selfTakeStationDTO">自提点实体(District、Remark字段暂时无用)</param>
        /// <returns>结果</returns>
        public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO SaveSelfTakeStationExt(Jinher.AMP.BTP.Deploy.CustomDTO.SelfTakeStationAndManagerDTO selfTakeStationDTO)
        {
            if (selfTakeStationDTO == null)
            {
                return(new ResultDTO {
                    ResultCode = 1, Message = "自提点实体不能为空"
                });
            }

            if (selfTakeStationDTO.CityOwnerId == Guid.Empty || string.IsNullOrWhiteSpace(selfTakeStationDTO.Name) || string.IsNullOrWhiteSpace(selfTakeStationDTO.Province) || string.IsNullOrWhiteSpace(selfTakeStationDTO.Address))
            {
                return(new ResultDTO {
                    ResultCode = 1, Message = "自提点参数错误"
                });
            }
            if (string.IsNullOrWhiteSpace(selfTakeStationDTO.City))
            {
                return(new ResultDTO {
                    ResultCode = 1, Message = "自提点参数错误"
                });
            }
            if (string.IsNullOrWhiteSpace(selfTakeStationDTO.QRCodeUrl) || selfTakeStationDTO.SpreadCode == Guid.Empty)
            {
                return(new ResultDTO {
                    ResultCode = 1, Message = "自提点参数错误"
                });
            }

            if (selfTakeStationDTO.SelfTakeStationType == 1 && (!selfTakeStationDTO.AppId.HasValue || selfTakeStationDTO.AppId == Guid.Empty))
            {
                return(new ResultDTO {
                    ResultCode = 1, Message = "自提点参数错误"
                });
            }

            //加入数量限制
            try
            {
                Jinher.AMP.ZPH.Deploy.CustomDTO.ProxyCabinetParam prarm = new ZPH.Deploy.CustomDTO.ProxyCabinetParam();
                prarm.ChangeOrg = selfTakeStationDTO.CityOwnerId;
                prarm.BelongTo  = selfTakeStationDTO.AppId.HasValue ? selfTakeStationDTO.AppId.Value : Guid.Empty;

                if (selfTakeStationDTO.SelfTakeStationType == 0)
                {
                    prarm.IsSelfPavilion = false;
                }
                else if (selfTakeStationDTO.SelfTakeStationType == 1)
                {
                    prarm.IsSelfPavilion = true;
                }
                LogHelper.Debug(string.Format("核查代理能否创建体验柜。prarm:{0}", JsonHelper.JsonSerializer(prarm)));
                var resultProxy = Jinher.AMP.BTP.TPS.ZPHSV.Instance.ChecksCanBeCreated(prarm);
                if (!resultProxy.isSuccess)
                {
                    return(new ResultDTO {
                        ResultCode = 1, Message = "已超过最大数量限制"
                    });
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(string.Format("核查代理能否创建体验柜服务异常。selfTakeStationDTO:{0}", JsonHelper.JsonSerializer(selfTakeStationDTO)), ex);
                return(new ResultDTO {
                    ResultCode = 1, Message = "核查代理能否创建体验柜服务异常"
                });
            }

            if (selfTakeStationDTO.selfTakeStationManager != null && selfTakeStationDTO.selfTakeStationManager.Any())
            {
                selfTakeStationDTO.selfTakeStationManager.RemoveAll(
                    checkItem =>
                    checkItem == null || checkItem.UserId == Guid.Empty || string.IsNullOrWhiteSpace(checkItem.UserCode));

                var selfManagerId = selfTakeStationDTO.selfTakeStationManager.Select(t => t.UserId).ToList();
                int count         = SelfTakeStationManager.ObjectSet().Count(t => selfManagerId.Contains(t.UserId) && !t.IsDel);

                if (count > 0)
                {
                    return(new ResultDTO {
                        ResultCode = 1, Message = "负责人已存在"
                    });
                }
            }
            try
            {
                ContextSession contextSession = ContextFactory.CurrentThreadContext;

                Guid            selfTakeStationId = Guid.NewGuid();
                SelfTakeStation selfTakeStation   = new SelfTakeStation()
                {
                    Id                  = selfTakeStationId,
                    CityOwnerId         = selfTakeStationDTO.CityOwnerId,
                    Name                = selfTakeStationDTO.Name,
                    Province            = selfTakeStationDTO.Province,
                    City                = selfTakeStationDTO.City,
                    District            = "",
                    Address             = selfTakeStationDTO.Address,
                    SpreadUrl           = selfTakeStationDTO.SpreadUrl,
                    Remark              = "",
                    QRCodeUrl           = selfTakeStationDTO.QRCodeUrl,
                    SpreadCode          = selfTakeStationDTO.SpreadCode,
                    SelfTakeStationType = selfTakeStationDTO.SelfTakeStationType,
                    AppId               = selfTakeStationDTO.AppId
                };

                selfTakeStation.EntityState = System.Data.EntityState.Added;
                contextSession.SaveObject(selfTakeStation);

                if (selfTakeStationDTO.selfTakeStationManager != null && selfTakeStationDTO.selfTakeStationManager.Count > 0)
                {
                    foreach (var selfManager in selfTakeStationDTO.selfTakeStationManager)
                    {
                        SelfTakeStationManager selfTakeStationManager = new SelfTakeStationManager()
                        {
                            Id                = Guid.NewGuid(),
                            UserCode          = selfManager.UserCode,
                            UserId            = selfManager.UserId,
                            SelfTakeStationId = selfTakeStationId
                        };
                        selfTakeStationManager.EntityState = System.Data.EntityState.Added;
                        contextSession.SaveObject(selfTakeStationManager);
                    }
                }

                //添加到SpreadInfo
                SpreadInfoDTO spreadInfo = new SpreadInfoDTO();
                spreadInfo.Id         = Guid.NewGuid();
                spreadInfo.SpreadId   = selfTakeStationDTO.CityOwnerId;
                spreadInfo.SpreadUrl  = selfTakeStationDTO.SpreadUrl;
                spreadInfo.SpreadCode = selfTakeStationDTO.SpreadCode;
                //spreadInfo.SpreadDesc
                //SpreadType 推广类型 0:推广主,1:电商馆,2:总代,3企业
                if (selfTakeStationDTO.SelfTakeStationType == 0)
                {
                    spreadInfo.SpreadType = 2;
                }
                else if (selfTakeStationDTO.SelfTakeStationType == 1)
                {
                    spreadInfo.SpreadType = 1;
                }
                spreadInfo.IsDel = 0;
                spreadInfo.AppId = selfTakeStationDTO.AppId.HasValue ? selfTakeStationDTO.AppId.Value : Guid.Empty;

                SpreadSV.Instance.BuildSaveSpreadInfo(spreadInfo);

                contextSession.SaveChanges();
            }
            catch (Exception ex)
            {
                LogHelper.Error(string.Format("添加自提点服务异常。selfTakeStationDTO:{0}", JsonHelper.JsonSerializer(selfTakeStationDTO)), ex);
                return(new ResultDTO {
                    ResultCode = 1, Message = "Error"
                });
            }

            //更新已建体验柜数量
            try
            {
                int count = 0;

                Jinher.AMP.ZPH.Deploy.CustomDTO.ProxyCabinetNumParam prarm = new ZPH.Deploy.CustomDTO.ProxyCabinetNumParam();
                prarm.ChangeOrg = selfTakeStationDTO.CityOwnerId;
                prarm.BelongTo  = selfTakeStationDTO.AppId.HasValue ? selfTakeStationDTO.AppId.Value : Guid.Empty;
                if (selfTakeStationDTO.SelfTakeStationType == 0)
                {
                    //总数量
                    count = SelfTakeStation.ObjectSet().Where(t => t.CityOwnerId == selfTakeStationDTO.CityOwnerId && t.SelfTakeStationType == selfTakeStationDTO.SelfTakeStationType && !t.IsDel).Count();
                    prarm.IsSelfPavilion = false;
                }
                else if (selfTakeStationDTO.SelfTakeStationType == 1)
                {
                    //总数量
                    count = SelfTakeStation.ObjectSet().Where(t => t.CityOwnerId == selfTakeStationDTO.CityOwnerId && t.SelfTakeStationType == selfTakeStationDTO.SelfTakeStationType && t.AppId == selfTakeStationDTO.AppId && !t.IsDel).Count();
                    prarm.IsSelfPavilion = true;
                }
                prarm.CabinetNum = count;
                LogHelper.Debug(string.Format("添加自提点时更新已建体验柜数量。prarm:{0}", JsonHelper.JsonSerializer(prarm)));
                var resultProxy = Jinher.AMP.BTP.TPS.ZPHSV.Instance.UpdateProxyCabinetNum(prarm);
                if (!resultProxy.isSuccess)
                {
                    LogHelper.Error(string.Format("添加自提点时更新已建体验柜数量服务失败。selfTakeStationDTO:{0}", JsonHelper.JsonSerializer(selfTakeStationDTO)));
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(string.Format("添加自提点时更新已建体验柜数量服务异常。selfTakeStationDTO:{0}", JsonHelper.JsonSerializer(selfTakeStationDTO)), ex);
            }

            return(new ResultDTO {
                ResultCode = 0, Message = "Success"
            });
        }
Beispiel #5
0
 /// <summary>
 /// 添加自提点
 /// </summary>
 /// <param name="selfTakeStationDTO">自提点实体</param>
 /// <returns>结果</returns>
 public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO SaveSelfTakeStation(Jinher.AMP.BTP.Deploy.CustomDTO.SelfTakeStationAndManagerDTO selfTakeStationDTO)
 {
     base.Do();
     return(this.SaveSelfTakeStationExt(selfTakeStationDTO));
 }