using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
namespace RoadFlow.Platform
{
public class WorkFlowComment
{
private RoadFlow.Data.Interface.IWorkFlowComment dataWorkFlowComment;
public WorkFlowComment()
{
this.dataWorkFlowComment = Data.Factory.Factory.GetWorkFlowComment();
}
///
/// 新增
///
public int Add(RoadFlow.Data.Model.WorkFlowComment model)
{
return dataWorkFlowComment.Add(model);
}
///
/// 更新
///
public int Update(RoadFlow.Data.Model.WorkFlowComment model)
{
return dataWorkFlowComment.Update(model);
}
///
/// 查询所有记录
///
public List GetAll()
{
return dataWorkFlowComment.GetAll();
}
///
/// 查询单条记录
///
public RoadFlow.Data.Model.WorkFlowComment Get(Guid id)
{
return dataWorkFlowComment.Get(id);
}
///
/// 删除
///
public int Delete(Guid id)
{
return dataWorkFlowComment.Delete(id);
}
///
/// 查询记录条数
///
public long GetCount()
{
return dataWorkFlowComment.GetCount();
}
///
/// 查询管理员的所有记录
///
public List GetManagerAll()
{
return dataWorkFlowComment.GetManagerAll();
}
///
/// 得到管理员类别的最大排序值
///
///
public int GetManagerMaxSort()
{
return dataWorkFlowComment.GetManagerMaxSort();
}
///
/// 得到一个人员的最大排序值
///
///
public int GetUserMaxSort(Guid userID)
{
return dataWorkFlowComment.GetUserMaxSort(userID);
}
///
/// 获得所有列表
///
/// 是否从缓存获取
///
private List>> GetAllList(bool fromCache = true)
{
string key = RoadFlow.Utility.Keys.CacheKeys.WorkFlowComments.ToString();
if (!fromCache)
{
return getAllListByDb();
}
else
{
object obj = RoadFlow.Cache.IO.Opation.Get(key);
if (obj == null)
{
var list = getAllListByDb();
RoadFlow.Cache.IO.Opation.Set(key, list);
return list;
}
else
{
return obj as List>>;
}
}
}
///
/// 从数据库获取所有意见列表
///
///
private List>> getAllListByDb()
{
var comments = GetAll();
Organize borganize=new Organize();
List>> list = new List>>();
foreach (var comment in comments)
{
List userList=new List();
if(!comment.MemberID.IsNullOrEmpty())
{
var users=borganize.GetAllUsers(comment.MemberID);
foreach(var user in users)
{
userList.Add(user.ID);
}
}
Tuple> tuple = new Tuple>(
comment.ID,
comment.Comment,
comment.Type,
comment.Sort,
userList
);
list.Add(tuple);
}
return list;
}
///
/// 清除缓存
///
public void ClearCache()
{
RoadFlow.Cache.IO.Opation.Remove(RoadFlow.Utility.Keys.CacheKeys.WorkFlowComments.ToString());
}
///
/// 刷新缓存
///
public void RefreshCache()
{
RoadFlow.Cache.IO.Opation.Set(RoadFlow.Utility.Keys.CacheKeys.WorkFlowComments.ToString(), getAllListByDb());
}
///
/// 得到一个用户的所有意见
///
///
///
public List GetListByUserID(Guid userID)
{
var list = GetAllList();
var list1 = list.Where(p => p.Item5.Count == 0 || p.Item5.Exists(q => q == userID)).OrderByDescending(p => p.Item3).ThenBy(p => p.Item4);
List commentsList = new List();
foreach (var li in list1.OrderBy(p=>p.Item3).ThenBy(p=>p.Item4))
{
commentsList.Add(li.Item2);
}
return commentsList;
}
///
/// 得到一个用户的所有意见选择项
///
///
///
public string GetOptionsStringByUserID(Guid userID)
{
var list = GetListByUserID(userID);
StringBuilder options = new StringBuilder();
foreach (var li in list)
{
options.AppendFormat("", li);
}
return options.ToString();
}
}
}