271 lines
8.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Learun.Application.Base.SystemModule;
using Learun.Util;
using Learun.Util.SqlSugar;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DbType = System.Data.DbType;
namespace Learun.Application.Message
{
/// <summary>
/// 版 本 PIT-ADMS V7.0.3 敏捷开发框架
/// Copyright (c) 2013-2018 Hexagon PPM
/// 创 建:超级管理员
/// 日 期2018-10-16 16:24
/// 描 述:消息策略
/// </summary>
public class LR_StrategyInfoService
{
#region
Repository<LR_MS_StrategyInfoEntity> _strategyInfoRepository => new Repository<LR_MS_StrategyInfoEntity>();
#endregion
#region
private string fieldSql;
public LR_StrategyInfoService()
{
fieldSql=@"
t.F_Id,
t.F_StrategyName,
t.F_StrategyCode,
t.F_SendRole,
t.F_MessageType,
t.F_Description,
t.F_CreateDate,
t.F_CreateUserId,
t.F_CreateUserName,
t.F_ModifyDate,
t.F_ModifyUserId,
t.F_ModifyUserName
";
}
#endregion
#region
/// <summary>
/// 获取列表数据
/// <summary>
/// <returns></returns>
public IEnumerable<LR_MS_StrategyInfoEntity> GetList( string queryJson )
{
try
{
//参考写法
//var queryParam = queryJson.ToJObject();
// 虚拟参数
//var dp = new DynamicParameters(new { });
//dp.Add("startTime", queryParam["StartTime"].ToDate(), DbType.DateTime);
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(fieldSql);
strSql.Append(" FROM LR_MS_StrategyInfo t ");
//return this.BaseRepository().FindList<LR_MS_StrategyInfoEntity>(strSql.ToString());
return SqlSugarHelper.Db.SqlQueryable<LR_MS_StrategyInfoEntity>(strSql.ToString()).ToList();
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
/// <summary>
/// 获取列表分页数据
/// <param name="pagination">分页参数</param>
/// <summary>
/// <returns></returns>
public IEnumerable<LR_MS_StrategyInfoEntity> GetPageList(Pagination pagination, string queryJson)
{
try
{
var queryParam = queryJson.ToJObject();
//var dp = new DynamicParameters(new { });
var dp = new List<SugarParameter>();
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(fieldSql);
strSql.Append(" FROM LR_MS_StrategyInfo t where 1=1");
if (queryParam.HasValues)
{
if (!queryParam["keyword"].IsEmpty())
{
dp.Add(new SugarParameter("keyword", "%" + queryParam["keyword"].ToString() + "%", DbType.String));
strSql.Append(" AND t.F_StrategyName like @keyword or t.F_StrategyCode like @keyword");
}
if (!queryParam["dateBegin"].IsEmpty() && !queryParam["dateEnd"].IsEmpty())
{
dp.Add(new SugarParameter("dateBegin", queryParam["dateBegin"].ToString(), DbType.String));
dp.Add(new SugarParameter("dateEnd", queryParam["dateEnd"].ToString(), DbType.String));
strSql.Append(" AND (t.F_CreateDate >= @dateBegin AND t.F_CreateDate <= @dateEnd )");
}
}
//return this.BaseRepository().FindList<LR_MS_StrategyInfoEntity>(strSql.ToString(),dp,pagination);
return SqlSugarHelper.Db.SqlQueryable<LR_MS_StrategyInfoEntity>(strSql.ToString()).AddParameters(dp).ToPageList(pagination.page, pagination.rows);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
/// <summary>
/// 获取实体数据
/// <param name="keyValue">主键</param>
/// <summary>
/// <returns></returns>
public LR_MS_StrategyInfoEntity GetEntity(string keyValue)
{
try
{
return _strategyInfoRepository.GetById(keyValue);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
/// <summary>
/// 根据策略编码获取策略
/// </summary>
/// <param name="code">策略编码</param>
/// <returns></returns>
public LR_MS_StrategyInfoEntity GetEntityByCode(string code)
{
try
{
return _strategyInfoRepository.GetFirst(t=>t.F_StrategyCode==code);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
#endregion
#region
/// <summary>
/// 删除实体数据
/// <param name="keyValue">主键</param>
/// <summary>
/// <returns></returns>
public void DeleteEntity(string keyValue)
{
try
{
_strategyInfoRepository.Delete(t=>t.F_Id == keyValue);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
/// <summary>
/// 保存实体数据(新增、修改)
/// <param name="keyValue">主键</param>
/// <summary>
/// <returns></returns>
public void SaveEntity(string keyValue, LR_MS_StrategyInfoEntity entity)
{
try
{
if (!string.IsNullOrEmpty(keyValue))
{
entity.Modify(keyValue);
_strategyInfoRepository.Update(entity);
}
else
{
entity.Create();
_strategyInfoRepository.Insert(entity);
}
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
#endregion
#region
/// <summary>
///策略编码不能重复
/// </summary>
/// <param name="keyValue">主键</param>
/// <param name="F_StrategyCode">编码</param>
/// <returns></returns>
public bool ExistStrategyCode(string keyValue,string F_StrategyCode)
{
try
{
var expression = LinqExtensions.True<LR_MS_StrategyInfoEntity>();
expression = expression.And(t => t.F_StrategyCode == F_StrategyCode);
if (!string.IsNullOrEmpty(keyValue))
{
expression = expression.And(t => t.F_Id != keyValue);
}
return _strategyInfoRepository.GetList(expression).Count() == 0 ? true : false;
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
#endregion
}
}