public List <BaseContactEntity> GetTopList(string parentId, int topLimit, bool containContents = false) { List <BaseContactEntity> result = new List <BaseContactEntity>(); string order = BaseContactEntity.FieldPriority + "," + BaseContactEntity.FieldCreateOn + " DESC "; List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(BaseContactEntity.FieldParentId, parentId)); parameters.Add(new KeyValuePair <string, object>(BaseContactEntity.FieldEnabled, 1)); parameters.Add(new KeyValuePair <string, object>(BaseContactEntity.FieldDeletionStateCode, 0)); using (IDataReader dataReader = this.ExecuteReader(parameters, topLimit, order)) { while (dataReader.Read()) { // 2015-11-18 吉日嘎拉 消息的内容不能有,否则会出错,缓存的内容也太大 BaseContactEntity contactEntity = BaseEntity.Create <BaseContactEntity>(dataReader, false); // 是否要内容 if (!containContents) { contactEntity.Contents = null; } result.Add(contactEntity); } } return(result); }
/// <summary> /// 设置实体 /// </summary> /// <param name="entity">实体</param> private void SetEntity(SQLBuilder sqlBuilder, BaseContactEntity entity) { sqlBuilder.SetValue(BaseContactEntity.FieldParentId, entity.ParentId); sqlBuilder.SetValue(BaseContactEntity.FieldTitle, entity.Title); sqlBuilder.SetValue(BaseContactEntity.FieldColor, entity.Color); sqlBuilder.SetValue(BaseContactEntity.FieldStyle, entity.Style); sqlBuilder.SetValue(BaseContactEntity.FieldContents, entity.Contents); sqlBuilder.SetValue(BaseContactEntity.FieldPriority, entity.Priority); sqlBuilder.SetValue(BaseContactEntity.FieldCancelTopDay, entity.CancelTopDay); sqlBuilder.SetValue(BaseContactEntity.FieldSendCount, entity.SendCount); sqlBuilder.SetValue(BaseContactEntity.FieldReadCount, entity.ReadCount); sqlBuilder.SetValue(BaseContactEntity.FieldReplyCount, entity.ReplyCount); sqlBuilder.SetValue(BaseContactEntity.FieldSource, entity.Source); sqlBuilder.SetValue(BaseContactEntity.FieldIsOpen, entity.IsOpen); sqlBuilder.SetValue(BaseContactEntity.FieldCategoryCode, entity.CategoryCode); sqlBuilder.SetValue(BaseContactEntity.FieldLabelMark, entity.LabelMark); sqlBuilder.SetValue(BaseContactEntity.FieldIPAddress, entity.IPAddress); sqlBuilder.SetValue(BaseContactEntity.FieldAllowComments, entity.AllowComments); sqlBuilder.SetValue(BaseContactEntity.FieldMustRead, entity.MustRead); sqlBuilder.SetValue(BaseContactEntity.FieldMustReply, entity.MustReply); sqlBuilder.SetValue(BaseContactEntity.FieldCommentUserId, entity.CommentUserId); sqlBuilder.SetValue(BaseContactEntity.FieldCommentUserRealName, entity.CommentUserRealName); sqlBuilder.SetValue(BaseContactEntity.FieldCommentDate, entity.CommentDate); sqlBuilder.SetValue(BaseContactEntity.FieldDeletionStateCode, entity.DeletionStateCode); sqlBuilder.SetValue(BaseContactEntity.FieldAuditStatus, entity.AuditStatus); sqlBuilder.SetValue(BaseContactEntity.FieldAuditUserId, entity.AuditUserId); sqlBuilder.SetValue(BaseContactEntity.FieldAuditUserRealName, entity.AuditUserRealName); sqlBuilder.SetValue(BaseContactEntity.FieldEnabled, entity.Enabled); sqlBuilder.SetValue(BaseContactEntity.FieldCreateDepartment, entity.CreateDepartment); sqlBuilder.SetValue(BaseContactEntity.FieldCreateCompany, entity.CreateCompany); sqlBuilder.SetValue(BaseContactEntity.FieldCreateCompanyId, entity.CreateCompanyId); sqlBuilder.SetValue(BaseContactEntity.FieldSortCode, entity.SortCode); sqlBuilder.SetValue(BaseContactEntity.FieldDescription, entity.Description); }
/// <summary> /// 获取用户的通知列表 /// </summary> /// <param name="companyId">网点主键</param> /// <param name="parentId"></param> /// <param name="topLimit">获取前几个</param> /// <param name="containContents">是否包含内容</param> /// <returns>通知列表</returns> public List <BaseContactEntity> GetTopListByCompanyId(string companyId, string parentId, int topLimit, bool containContents = false) { List <BaseContactEntity> result = new List <BaseContactEntity>(); // 获取用户信息 string commandText = string.Empty; // 获取用户所在的单位的信息 BaseOrganizeEntity organizeEntity = BaseOrganizeManager.GetObjectByCache(companyId); if (organizeEntity != null) { // 2015-11-26 吉日嘎拉 需要过去数据,最近的30天的数据就可以了,太久了意义不大 commandText = " ( " + BaseContactEntity.FieldCreateOn + " > SYSDATE - 30) AND ((ParentId = '" + parentId + "' AND " + "Enabled = 1 AND DeletionStateCode = 0 AND IsOpen = 1 AND AuditStatus=2) OR (Enabled = 1 AND AuditStatus=2 AND DeletionStateCode = 0 AND Id IN ("; // 所在省 if (!string.IsNullOrEmpty(organizeEntity.ProvinceId)) { commandText += " (SELECT ContactId FROM BaseContactTarget WHERE Category = '0' AND ReceiverId = '" + organizeEntity.ProvinceId + "') "; } // 所在市 if (!string.IsNullOrEmpty(organizeEntity.CityId)) { commandText += " UNION (SELECT ContactId FROM BaseContactTarget WHERE Category = '1' AND ReceiverId = '" + organizeEntity.CityId + "') "; } // 所在县 if (!string.IsNullOrEmpty(organizeEntity.DistrictId)) { commandText += " UNION (SELECT ContactId FROM BaseContactTarget WHERE Category = '2' AND ReceiverId = '" + organizeEntity.DistrictId + "') "; } } // 发给所在单位的 if (!string.IsNullOrEmpty(companyId)) { commandText += " UNION (SELECT ContactId FROM BaseContactTarget WHERE Category = '3' AND ReceiverId = '" + companyId + "')))) "; } string order = BaseContactEntity.FieldPriority + "," + BaseContactEntity.FieldCreateOn + " DESC "; using (IDataReader dataReader = this.ExecuteReaderByWhere(commandText, null, topLimit, order)) { while (dataReader.Read()) { // 2015-11-18 吉日嘎拉 消息的内容不能有,否则会出错,缓存的内容也太大 BaseContactEntity contactEntity = BaseEntity.Create <BaseContactEntity>(dataReader, false); // 是否要内容 if (!containContents) { contactEntity.Contents = null; } result.Add(contactEntity); } } return(result); }
/// <summary> /// 更新实体 /// </summary> /// <param name="userInfo">操作员</param> /// <param name="entity">实体</param> /// <returns>影响行数</returns> public int UpdateEntity(BaseUserInfo userInfo, BaseContactEntity entity) { SQLBuilder sqlBuilder = new SQLBuilder(DbHelper); sqlBuilder.BeginUpdate(BaseContactEntity.TableName); this.SetEntity(sqlBuilder, entity); if (userInfo != null) { sqlBuilder.SetValue(BaseContactEntity.FieldModifiedUserId, userInfo.Id); sqlBuilder.SetValue(BaseContactEntity.FieldModifiedBy, userInfo.RealName); } sqlBuilder.SetDBNow(BaseContactEntity.FieldModifiedOn); sqlBuilder.SetWhere(BaseContactEntity.FieldId, entity.Id); return(sqlBuilder.EndUpdate()); }
/// <summary> /// 设置实体 /// </summary> /// <param name="entity">实体</param> private void SetObject(SQLBuilder sqlBuilder, BaseContactEntity entity) { sqlBuilder.SetValue(BaseContactEntity.FieldParentId, entity.ParentId); sqlBuilder.SetValue(BaseContactEntity.FieldTitle, entity.Title); sqlBuilder.SetValue(BaseContactEntity.FieldContents, entity.Contents); sqlBuilder.SetValue(BaseContactEntity.FieldPriority, entity.Priority); sqlBuilder.SetValue(BaseContactEntity.FieldSendCount, entity.SendCount); sqlBuilder.SetValue(BaseContactEntity.FieldReadCount, entity.ReadCount); sqlBuilder.SetValue(BaseContactEntity.FieldIsOpen, entity.IsOpen); sqlBuilder.SetValue(BaseContactEntity.FieldCommentUserId, entity.CommentUserId); sqlBuilder.SetValue(BaseContactEntity.FieldCommentUserRealname, entity.CommentUserRealname); sqlBuilder.SetValue(BaseContactEntity.FieldCommentDate, entity.CommentDate); sqlBuilder.SetValue(BaseContactEntity.FieldDeletionStateCode, entity.DeletionStateCode); sqlBuilder.SetValue(BaseContactEntity.FieldEnabled, entity.Enabled); sqlBuilder.SetValue(BaseContactEntity.FieldSortCode, entity.SortCode); sqlBuilder.SetValue(BaseContactEntity.FieldDescription, entity.Description); }
/// <summary> /// 添加实体 /// </summary> /// <param name="userInfo">操作员</param> /// <param name="entity">实体</param> /// <returns>主键</returns> public string AddEntity(BaseUserInfo userInfo, BaseContactEntity entity) { string sequence = string.Empty; sequence = entity.Id; if (entity.SortCode == 0) { BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper, this.Identity); sequence = sequenceManager.Increment(this.CurrentTableName); entity.SortCode = int.Parse(sequence); } if (entity.Id is string) { this.Identity = false; this.ReturnId = false; } SQLBuilder sqlBuilder = new SQLBuilder(DbHelper, this.Identity, this.ReturnId); sqlBuilder.BeginInsert(BaseContactEntity.TableName, BaseContactEntity.FieldId); if (!this.Identity) { sqlBuilder.SetValue(BaseContactEntity.FieldId, entity.Id); } this.SetEntity(sqlBuilder, entity); if (userInfo != null) { sqlBuilder.SetValue(BaseContactEntity.FieldCreateUserId, userInfo.Id); sqlBuilder.SetValue(BaseContactEntity.FieldCreateBy, userInfo.RealName); } sqlBuilder.SetDBNow(BaseContactEntity.FieldCreateOn); if (userInfo != null) { sqlBuilder.SetValue(BaseContactEntity.FieldModifiedUserId, userInfo.Id); sqlBuilder.SetValue(BaseContactEntity.FieldModifiedBy, userInfo.RealName); } sqlBuilder.SetDBNow(BaseContactEntity.FieldModifiedOn); if (DbHelper.CurrentDbType == CurrentDbType.SqlServer && this.Identity) { sequence = sqlBuilder.EndInsert().ToString(); } else { sqlBuilder.EndInsert(); } return(sequence); }
/// <summary> /// 邮件有评论时要进行的操作 /// </summary> /// <param name="detailsID">邮件主键</param> /// <returns>影响行数</returns> public int OnCommnet(string detailsId) { int returnValue = 0; BaseContactDetailsEntity contactDetailsEntity = this.GetEntity(detailsId); // 更新子表的其他人的通知,首先是有效的邮件,其次不是新邮件,其次不是自己的邮件 string sqlQuery = " UPDATE BaseContactDetails " + " SET NewComment = 1 " + " WHERE (Enabled = 1) " + " AND (IsNew = 0) " + " AND (ContactId = '" + contactDetailsEntity.ContactId + "') " + " AND (ID <> '" + detailsId + "')"; returnValue += DbHelper.ExecuteNonQuery(sqlQuery); BaseContactManager contactManager = new BaseContactManager(DbHelper, UserInfo); BaseContactEntity contactEntity = contactManager.GetEntity(contactDetailsEntity.ContactId); // 更新主表状态,评论人、评论时间发布上去 contactEntity.CommentDate = DateTime.Now; contactEntity.CommentUserId = UserInfo.Id; contactEntity.CommentUserRealName = UserInfo.RealName; returnValue += contactManager.Update(contactEntity); return(returnValue); }
/// <summary> /// 添加实体 /// </summary> /// <param name="entity">实体</param> /// <returns>主键</returns> public string AddEntity(BaseContactEntity entity) { return(AddEntity(this.UserInfo, entity)); }
/// <summary> /// 更新 /// </summary> /// <param name="userInfo">操作员</param> /// <param name="entity">实体</param> /// <returns>影响行数</returns> public int Update(BaseUserInfo userInfo, BaseContactEntity entity) { return(this.UpdateEntity(userInfo, entity)); }
/// <summary> /// 添加 /// </summary> /// <param name="entity">实体</param> /// <param name="identity">自增量方式</param> /// <returns>主键</returns> public string Add(BaseContactEntity entity, bool identity) { this.Identity = identity; return(this.AddEntity(entity)); }
/// <summary> /// 添加 /// </summary> /// <param name="userInfo">操作员信息</param> /// <param name="entity">实体</param> /// <returns>主键</returns> public string Add(BaseUserInfo userInfo, BaseContactEntity entity) { return(this.AddEntity(userInfo, entity)); }
/// <summary> /// 添加 /// </summary> /// <param name="entity">实体</param> /// <returns>主键</returns> public string Add(BaseContactEntity entity) { return(this.AddEntity(entity)); }
/// <summary> /// 添加实体 /// </summary> /// <param name="entity">实体</param> public string AddObject(BaseContactEntity entity) { string sequence = string.Empty; sequence = entity.Id; if (entity.SortCode == 0) { BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper, this.Identity); sequence = sequenceManager.Increment(this.CurrentTableName); entity.SortCode = int.Parse(sequence); } SQLBuilder sqlBuilder = new SQLBuilder(DbHelper, this.Identity, this.ReturnId); sqlBuilder.BeginInsert(BaseContactEntity.TableName, BaseContactEntity.FieldId); if (entity.Id is string) { this.Identity = false; } if (!this.Identity) { sqlBuilder.SetValue(BaseContactEntity.FieldId, entity.Id); } else { if (!this.ReturnId && DbHelper.CurrentDbType == CurrentDbType.Oracle) { sqlBuilder.SetFormula(BaseContactEntity.FieldId, "SEQ_" + this.CurrentTableName.ToUpper() + ".NEXTVAL "); } else { if (this.Identity && DbHelper.CurrentDbType == CurrentDbType.Oracle) { if (string.IsNullOrEmpty(sequence)) { BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper, this.Identity); sequence = sequenceManager.Increment(this.CurrentTableName); } entity.Id = sequence; sqlBuilder.SetValue(BaseContactEntity.FieldId, entity.Id); } } } this.SetObject(sqlBuilder, entity); if (UserInfo != null) { sqlBuilder.SetValue(BaseContactEntity.FieldCreateUserId, UserInfo.Id); sqlBuilder.SetValue(BaseContactEntity.FieldCreateBy, UserInfo.Realname); } sqlBuilder.SetDBNow(BaseContactEntity.FieldCreateOn); if (UserInfo != null) { sqlBuilder.SetValue(BaseContactEntity.FieldModifiedUserId, UserInfo.Id); sqlBuilder.SetValue(BaseContactEntity.FieldModifiedBy, UserInfo.Realname); } sqlBuilder.SetDBNow(BaseContactEntity.FieldModifiedOn); if (DbHelper.CurrentDbType == CurrentDbType.SqlServer && this.Identity) { sequence = sqlBuilder.EndInsert().ToString(); } else { sqlBuilder.EndInsert(); } return(sequence); }
/// <summary> /// 更新 /// </summary> /// <param name="entity">实体</param> public int Update(BaseContactEntity entity) { return(this.UpdateObject(entity)); }
/// <summary> /// 获取实体 /// </summary> /// <param name="id">主键</param> public BaseContactEntity GetEntity(string id) { BaseContactEntity baseContactEntity = new BaseContactEntity(this.GetDataTableById(id)); return(baseContactEntity); }
/// <summary> /// 更新 /// </summary> /// <param name="baseContactEntity">实体</param> public int Update(BaseContactEntity baseContactEntity) { return(this.UpdateEntity(baseContactEntity)); }