using Learun.DataBase.Repository;
using Learun.Util;
using System;
using System.Collections.Generic;
using System.Text;
using Learun.Application.AppMagager.Function;
namespace Learun.Application.AppMagager
{
///
/// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
/// Copyright (c) 2013-2018 北京泉江科技有限公司
/// 创建人:陈彬彬
/// 日 期:2018.03.16
/// 描 述:移动端功能管理
///
public class FunctionSerivce: RepositoryFactory
{
#region 属性 构造函数
private string sql;
public FunctionSerivce()
{
sql = @"
t.F_Id,
t.F_Type,
t.F_FormId,
t.F_CodeId,
t.F_CreateDate,
t.F_CreateUserId,
t.F_CreateUserName,
t.F_ModifyDate,
t.F_ModifyUserId,
t.F_ModifyUserName,
t.F_Icon,
t.F_Name,
t.F_SchemeId,
t.F_EnabledMark,
t.F_SortCode,
t.F_Url,
t.F_IsSystem
";
}
#endregion
#region 获取数据
///
///
///
/// 1 target 2 list 3 chart
///
public IEnumerable GetDesktopList(string type)
{
try
{
var strSql = new StringBuilder();
strSql.Append("SELECT t.* ");
switch (type)
{
case "1":
strSql.Append(" FROM LR_DT_Target t ");
break;
case "2":
strSql.Append(" FROM LR_DT_List t ");
break;
case "3":
strSql.Append(" ,t.F_Type FROM LR_DT_Chart t ");
break;
}
return this.BaseRepository().FindList(strSql.ToString());
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 获取分页列表
///
/// 分页参数
/// 关键字
/// 分类
///
public IEnumerable GetPageList(Pagination pagination, string keyword, string type)
{
try
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(sql);
strSql.Append(" FROM LR_App_Function t where 1=1 ");
if (!string.IsNullOrEmpty(keyword))
{
strSql.Append(" AND ( t.F_Name like @keyword ) ");
keyword = "%" + keyword + "%";
}
if (!string.IsNullOrEmpty(type))
{
strSql.Append(" AND t.F_Type = @type ");
}
return this.BaseRepository().FindList(strSql.ToString(), new { keyword, type }, pagination);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 获取列表数据
///
///
public IEnumerable GetList()
{
try
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(sql);
strSql.Append(" ,s.F_Scheme FROM LR_App_Function t LEFT JOIN LR_App_FnScheme s on t.F_SchemeId = s.F_Id where t.F_EnabledMark = 1 ORDER BY F_SortCode ");
return this.BaseRepository().FindList(strSql.ToString());
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 获取移动功能模板
///
/// 主键
///
public FunctionSchemeEntity GetScheme(string keyValue)
{
try
{
return this.BaseRepository().FindEntity(keyValue);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 获取实体对象
///
/// 主键
///
public FunctionEntity GetEntity(string keyValue) {
try
{
return this.BaseRepository().FindEntity(keyValue);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
#endregion
#region 提交数据
///
/// 删除
///
/// 主键
public void Delete(string keyValue)
{
var db = this.BaseRepository().BeginTrans();
try
{
FunctionEntity entity = db.FindEntity(keyValue);
string schemeId = entity.F_SchemeId;
if (!string.IsNullOrEmpty(schemeId)) {
db.Delete(t => t.F_Id == schemeId);
}
db.Delete(t => t.F_Id == keyValue);
db.Commit();
}
catch (Exception ex)
{
db.Rollback();
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 保存
///
/// 主键
/// 功能信息
/// 功能模板信息
public void SaveEntity(string keyValue, FunctionEntity functionEntity, FunctionSchemeEntity functionSchemeEntity)
{
IRepository db = new RepositoryFactory().BaseRepository().BeginTrans();
try
{
// 如果是代码开发功能
if (functionEntity.F_IsSystem == 1)
{
if (!string.IsNullOrEmpty(functionEntity.F_SchemeId))
{
db.Delete(t => t.F_Id == functionEntity.F_SchemeId);
}
}
else
{
#region 模板信息
if (string.IsNullOrEmpty(functionEntity.F_SchemeId))
{
functionSchemeEntity.Create();
db.Insert(functionSchemeEntity);
functionEntity.F_SchemeId = functionSchemeEntity.F_Id;
}
else
{
functionSchemeEntity.Modify(functionEntity.F_SchemeId);
db.Update(functionSchemeEntity);
}
#endregion
}
if (string.IsNullOrEmpty(keyValue))
{
functionEntity.Create();
db.Insert(functionEntity);
}
else
{
functionEntity.Modify(keyValue);
db.Update(functionEntity);
}
db.Commit();
}
catch (Exception ex)
{
db.Rollback();
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 更新状态
///
/// 模板信息主键
/// 状态1启用0禁用
public void UpdateState(string keyValue, int state)
{
try
{
FunctionEntity entity = new FunctionEntity
{
F_Id = keyValue,
F_EnabledMark = state
};
this.BaseRepository().Update(entity);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
#endregion
}
}