/// <summary> /// 保存spreadinfo /// </summary> /// <param name="spreadInfo"></param> /// <param name="isDeleteOld">是否删除同类型的旧数据</param> public void BuildSaveSpreadInfo(SpreadInfoDTO spreadInfo, bool isDeleteOld = false) { if (spreadInfo == null || spreadInfo.SpreadId == Guid.Empty || spreadInfo.SpreadCode == Guid.Empty) { return; } ContextSession contextSession = ContextFactory.CurrentThreadContext; if (isDeleteOld) { //插入SpreadInfo数据库表 var oldSpreadInfo = SpreadInfo.ObjectSet().FirstOrDefault(c => c.SpreadId == spreadInfo.SpreadId && c.IsDel == 0); if (oldSpreadInfo != null) { if ((oldSpreadInfo.SpreadId == spreadInfo.SpreadId) && (oldSpreadInfo.SpreadType == spreadInfo.SpreadType)) { oldSpreadInfo.EntityState = EntityState.Deleted; } } } SpreadInfo newSpreadInfo = SpreadInfo.CreateSpreadInfo(); newSpreadInfo.SpreadId = spreadInfo.SpreadId; newSpreadInfo.SpreadCode = spreadInfo.SpreadCode; newSpreadInfo.SpreadUrl = spreadInfo.SpreadUrl; newSpreadInfo.IsDel = spreadInfo.IsDel; newSpreadInfo.SpreadType = spreadInfo.SpreadType; newSpreadInfo.SpreadDesc = spreadInfo.SpreadDesc; newSpreadInfo.AppId = spreadInfo.AppId; contextSession.SaveObject(newSpreadInfo); UpdateRalationUserSpread(spreadInfo.SpreadId, spreadInfo.SpreadCode, spreadInfo.SpreadType); }
/// <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" }); }