using Edu.Common.Enum;
using Edu.Model.Entity.OKR;
using Edu.Model.ViewModel.OKR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VT.FW.DB.Dapper;
namespace Edu.Repository.OKR
{
///
/// OKR结果仓储层
///
public class RB_OKR_KeyResultRepository : BaseRepository
{
///
/// 获取分页列表
///
///
///
///
///
///
public List GetPageList(int pageIndex, int pageSize, out long rowsCount, RB_OKR_KeyResult_ViewModel demodel)
{
string where = $@" 1=1 and Status =0";
if (demodel.Group_Id > 0)
{
where += $@" and {nameof(RB_OKR_KeyResult_ViewModel.Group_Id)} ={demodel.Group_Id}";
}
if (demodel.ObjectiveId > 0)
{
where += $@" and {nameof(RB_OKR_KeyResult_ViewModel.ObjectiveId)} ={demodel.ObjectiveId}";
}
if (demodel.ProgressState > 0)
{
where += $@" and {nameof(RB_OKR_KeyResult_ViewModel.ProgressState)} ={(int)demodel.ProgressState}";
}
string sql = $@" select * from RB_OKR_KeyResult where {where} order by Id desc";
return GetPage(pageIndex, pageSize, out rowsCount, sql).ToList();
}
///
/// 获取列表
///
///
///
public List GetList(RB_OKR_KeyResult_ViewModel demodel)
{
string where = $@" 1=1 and Status =0";
if (demodel.Group_Id > 0)
{
where += $@" and {nameof(RB_OKR_KeyResult_ViewModel.Group_Id)} ={demodel.Group_Id}";
}
if (demodel.ObjectiveId > 0)
{
where += $@" and {nameof(RB_OKR_KeyResult_ViewModel.ObjectiveId)} ={demodel.ObjectiveId}";
}
if (!string.IsNullOrEmpty(demodel.ObjectiveIds))
{
where += $@" and {nameof(RB_OKR_KeyResult_ViewModel.ObjectiveId)} in({demodel.ObjectiveIds})";
}
if (demodel.ProgressState > 0)
{
where += $@" and {nameof(RB_OKR_KeyResult_ViewModel.ProgressState)} ={(int)demodel.ProgressState}";
}
if (demodel.IsUseRule == 1) {
where += $@" and {nameof(RB_OKR_KeyResult_ViewModel.RuleId)} >0";
}
string sql = $@" select * from RB_OKR_KeyResult where {where} order by Id desc";
return Get(sql).ToList();
}
///
/// 获取最大状态
///
///
///
public int GetKeyResultMaxProgressState(int objectiveId)
{
string sql = $@"SELECT MAX(ProgressState) as ProgressState FROM rb_okr_keyresult WHERE Status =0 and ObjectiveId ={objectiveId}";
var obj = ExecuteScalar(sql);
return obj == null ? 0 : Convert.ToInt32(obj);
}
///
/// 获取最大sort
///
///
///
public int GetKeyResultMaxSort(int objectiveId)
{
string sql = $@"SELECT MAX(Sort) Sort FROM rb_okr_keyresult WHERE Status =0 and ObjectiveId ={objectiveId}";
var obj = ExecuteScalar(sql);
return obj == null ? 0 : Convert.ToInt32(obj);
}
///
/// 设置排序
///
///
///
///
///
///
public bool UpdateOtherSort(int objectiveId, int id, int startSort, int endSort)
{
string sql = $@"UPDATE rb_okr_keyresult SET Sort =Sort +1 WHERE Status =0 and ObjectiveId={objectiveId} AND Id <>{id} ";
if (startSort > 0)
{
sql += $@" AND Sort > {startSort} ";
}
if (endSort > 0)
{
sql += $@" and Sort < {endSort} ";
}
return Execute(sql) > 0;
}
///
/// 设置排序
///
///
///
///
///
///
public bool UpdateOtherSortDesc(int objectiveId, int id, int startSort, int endSort)
{
string sql = $@"UPDATE rb_okr_keyresult SET Sort =Sort -1 WHERE Status =0 and ObjectiveId={objectiveId} AND Id <>{id} ";
if (startSort > 0 && endSort > 0)
{
sql += $@" AND Sort > {startSort} and Sort <= {endSort}";
}
return Execute(sql) > 0;
}
}
}