|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395 |
- using Learun.DataBase.Repository;
- using Learun.Util;
- using System;
- using System.Collections.Generic;
- using System.Text;
-
- namespace Learun.Application.Base.SystemModule
- {
- /// <summary>
- /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
- /// Copyright (c) 2013-2018 北京泉江科技有限公司
- /// 创建人:陈彬彬
- /// 日 期:2017.04.01
- /// 描 述:编号规则
- /// </summary>
- public class CodeRuleService : RepositoryFactory
- {
- #region 构造函数和属性
- private string fieldSql;
- public CodeRuleService()
- {
- fieldSql = @"
- t.F_RuleId,
- t.F_EnCode,
- t.F_FullName,
- t.F_CurrentNumber,
- t.F_RuleFormatJson,
- t.F_SortCode,
- t.F_DeleteMark,
- t.F_EnabledMark,
- 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>
- /// <param name="pagination">分页</param>
- /// <param name="keyword">查询参数</param>
- /// <returns></returns>
- public IEnumerable<CodeRuleEntity> GetPageList(Pagination pagination, string keyword)
- {
- try
- {
- var strSql = new StringBuilder();
- strSql.Append(" SELECT ");
- strSql.Append(fieldSql);
- strSql.Append(" FROM LR_Base_CodeRule t WHERE t.F_EnabledMark = 1 AND t.F_DeleteMark = 0 ");
- if (!string.IsNullOrEmpty(keyword)) {
- strSql.Append(" AND ( F_EnCode LIKE @keyword OR F_FullName LIKE @keyword ) ");
- keyword = '%' + keyword + '%';
- }
- return this.BaseRepository().FindList<CodeRuleEntity>(strSql.ToString(), new { keyword = keyword }, pagination);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
- /// <summary>
- /// 规则列表
- /// </summary>
- /// <returns></returns>
- public IEnumerable<CodeRuleEntity> GetList()
- {
- try
- {
- var strSql = new StringBuilder();
- strSql.Append(" SELECT ");
- strSql.Append(fieldSql);
- strSql.Append(" FROM LR_Base_CodeRule t WHERE t.F_EnabledMark = 1 AND t.F_DeleteMark = 0 ");
- return this.BaseRepository().FindList<CodeRuleEntity>(strSql.ToString());
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
- /// <summary>
- /// 规则实体
- /// </summary>
- /// <param name="keyValue">主键值</param>
- /// <returns></returns>
- public CodeRuleEntity GetEntity(string keyValue)
- {
- try
- {
- return this.BaseRepository().FindEntity<CodeRuleEntity>(keyValue);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
- /// <summary>
- /// 规则实体
- /// </summary>
- /// <param name="enCode">规则编码</param>
- /// <returns></returns>
- public CodeRuleEntity GetEntityByCode(string enCode) {
- try
- {
- return this.BaseRepository().FindEntity<CodeRuleEntity>(t => t.F_EnCode == enCode);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
- /// <summary>
- /// 获取种子
- /// </summary>
- /// <param name="ruleId"></param>
- /// <returns></returns>
- public CodeRuleSeedEntity GetSeedEntity(string ruleId)
- {
- try
- {
- return this.BaseRepository().FindEntity<CodeRuleSeedEntity>(t => t.F_RuleId == ruleId);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- #endregion
-
- #region 提交数据
- /// <summary>
- /// 删除规则
- /// </summary>
- /// <param name="keyValue">主键</param>
- public void VirtualDelete(string keyValue)
- {
- try
- {
- CodeRuleEntity entity = new CodeRuleEntity()
- {
- F_RuleId = keyValue,
- F_DeleteMark = 1
- };
- this.BaseRepository().Update(entity);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
- /// <summary>
- /// 保存规则表单(新增、修改)
- /// </summary>
- /// <param name="keyValue">主键值</param>
- /// <param name="codeRuleEntity">规则实体</param>
- /// <returns></returns>
- public void SaveEntity(string keyValue, CodeRuleEntity codeRuleEntity, UserInfo userInfo = null)
- {
- try
- {
- if (!string.IsNullOrEmpty(keyValue))
- {
- codeRuleEntity.Modify(keyValue, userInfo);
- this.BaseRepository().Update(codeRuleEntity);
- }
- else
- {
- codeRuleEntity.Create(userInfo);
- this.BaseRepository().Insert(codeRuleEntity);
- }
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
- #endregion
-
- #region 验证数据
- /// <summary>
- /// 规则编号不能重复
- /// </summary>
- /// <param name="enCode">编号</param>
- /// <param name="keyValue">主键</param>
- /// <returns></returns>
- public bool ExistEnCode(string enCode, string keyValue)
- {
- try
- {
- var strSql = new StringBuilder();
- strSql.Append(" SELECT t.F_RuleId FROM LR_Base_CodeRule t WHERE t.F_DeleteMark = 0 AND t.F_EnCode = @enCode ");
- if (!string.IsNullOrEmpty(keyValue))
- {
- strSql.Append(" AND t.F_RuleId != @keyValue ");
- }
- CodeRuleEntity entity = this.BaseRepository().FindEntity<CodeRuleEntity>(strSql.ToString(), new { enCode = enCode, keyValue = keyValue });
-
- return entity == null ? true : false;
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
- /// <summary>
- /// 规则名称不能重复
- /// </summary>
- /// <param name="fullName">名称</param>
- /// <param name="keyValue">主键</param>
- /// <returns></returns>
- public bool ExistFullName(string fullName, string keyValue)
- {
- try
- {
- var strSql = new StringBuilder();
- strSql.Append(" SELECT t.F_RuleId FROM LR_Base_CodeRule t WHERE t.F_DeleteMark = 0 AND t.F_FullName = @fullName ");
- if (!string.IsNullOrEmpty(keyValue))
- {
- strSql.Append(" AND t.F_RuleId != @keyValue ");
- }
- CodeRuleEntity entity = this.BaseRepository().FindEntity<CodeRuleEntity>(strSql.ToString(), new { fullName = fullName, keyValue = keyValue });
-
- return entity == null ? true : false;
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
- #endregion
-
- #region 单据编码处理
- /// <summary>
- /// 获取当前编号规则种子列表
- /// </summary>
- /// <param name="ruleId">编号规则主键</param>
- /// <returns></returns>
- public List<CodeRuleSeedEntity> GetSeedList(string ruleId, UserInfo userInfo)
- {
- try
- {
- //获取当前最大种子
- List<CodeRuleSeedEntity> codeRuleSeedList = (List<CodeRuleSeedEntity>)this.BaseRepository().FindList<CodeRuleSeedEntity>(t => t.F_RuleId.Equals(ruleId));
- if (codeRuleSeedList.Count == 0)
- {
- //说明没有种子,插入一条种子
- CodeRuleSeedEntity codeRuleSeedEntity = new CodeRuleSeedEntity();
- codeRuleSeedEntity.Create(userInfo);
- codeRuleSeedEntity.F_SeedValue = 1;
- codeRuleSeedEntity.F_RuleId = ruleId;
- this.BaseRepository().Insert<CodeRuleSeedEntity>(codeRuleSeedEntity);
- codeRuleSeedList.Add(codeRuleSeedEntity);
- }
- return codeRuleSeedList;
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
- /// <summary>
- /// 保存单据编号规则种子
- /// </summary>
- /// <param name="keyValue">主键</param>
- /// <param name="codeRuleSeedEntity">种子实体</param>
- public void SaveSeed(string keyValue, CodeRuleSeedEntity codeRuleSeedEntity, UserInfo userInfo)
- {
- try
- {
- if (string.IsNullOrEmpty(keyValue))
- {
- codeRuleSeedEntity.Create(userInfo);
- this.BaseRepository().Insert(codeRuleSeedEntity);
- }
- else
- {
- codeRuleSeedEntity.Modify(keyValue, userInfo);
- this.BaseRepository().Update(codeRuleSeedEntity);
- }
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
- /// <summary>
- /// 删除种子,表示被占用了
- /// </summary>
- /// <param name="userId">用户主键</param>
- /// <param name="ruleId">规则主键</param>
- public void DeleteSeed(string userId, string ruleId)
- {
- try
- {
- this.BaseRepository().Delete<CodeRuleSeedEntity>(t => t.F_UserId == userId && t.F_RuleId == ruleId);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
- #endregion
- }
- }
|