/// <summary> /// 生成编号 /// </summary> /// <param name="key">编码键</param> /// <param name="generateRule">规则</param> /// <param name="prefix">前缀</param> /// <param name="serialNumberLength">流水号长度</param> /// <param name="organizationID">机构ID</param> /// <returns></returns> public string GenerateCode(EnumCodeKey key, EnumCodeRule generateRule, string prefix, int serialNumberLength, int organizationID = -1) { IUnitOfWork codeRuleUnitOfWork = IOCContainer.Instance.Resolve <IUnitOfWork>(); var codeRuleRepository = codeRuleUnitOfWork.GetRepository <SYS_CodeRule>(); BaseRequest <object> request = new BaseRequest <object>(); //BaseResponse<CodeRuleModel> response = null; string codeKey = key.ToString(); var codeRule = codeRuleRepository.dbSet.Where(it => it.OrganizationID == organizationID && it.CodeKey == codeKey).FirstOrDefault(); //response = this.Get<SYS_CodeRule, CodeRuleModel>((q) => q.OrganizationID == organizationID && q.CodeKey == key.ToString()); if (codeRule == null) { codeRule = new SYS_CodeRule(); codeRule.OrganizationID = organizationID; codeRule.CodeKey = Enum.GetName(typeof(EnumCodeKey), key); codeRule.FlagRule = this.GenerateCodeRule(generateRule); codeRule.GenerateRule = prefix + (codeRule.FlagRule != "0" ? codeRule.FlagRule : "") + "{number:" + serialNumberLength + "}"; codeRule.Flag = this.ReplaceValue(codeRule.FlagRule); codeRule.SerialNumber = 0; codeRuleRepository.Insert(codeRule); } else { codeRuleRepository.Update(codeRule); } var flag = this.ReplaceValue(codeRule.FlagRule); if (string.IsNullOrEmpty(codeRule.Flag) || codeRule.Flag != flag) { codeRule.Flag = flag; codeRule.SerialNumber = 1; } else { codeRule.SerialNumber++; } codeRuleUnitOfWork.Save(); //unitOfWork.BeginTransaction(); //this.Save<SYS_CodeRule, CodeRuleModel>(response.Data, (q) => q.OrganizationID == organizationID && q.CodeKey == response.Data.CodeKey); //unitOfWork.Commit(); return(ReplaceValue(codeRule.GenerateRule, codeRule.SerialNumber)); }
/// <summary> /// 数据库未创建规则时,可在此方法中创建 /// </summary> /// <param name="orgId"></param> /// <param name="key"></param> /// <returns></returns> private bool GenerateRule(string orgId, EnumCodeKey key) { bool isGenerated = false; SYS_CODERULE rule = new SYS_CODERULE(); switch (key) { case EnumCodeKey.LCRegNo: rule.ORGID = "LCRegNo"; rule.CODEKEY = key.ToString(); rule.FLAGRULE = "0"; rule.GENERATERULE = "{number:8}"; rule.FLAG = "0"; rule.SERIALNUMBER = 10; isGenerated = true; break; case EnumCodeKey.DCRegNo: rule.ORGID = "DCRegNo"; rule.CODEKEY = key.ToString(); rule.FLAGRULE = "0"; rule.GENERATERULE = "{number:8}"; rule.FLAG = "0"; rule.SERIALNUMBER = 10; isGenerated = true; break; case EnumCodeKey.NCIEvaluate: rule.ORGID = "NCIEvaluate"; rule.CODEKEY = key.ToString(); rule.FLAGRULE = "0"; rule.GENERATERULE = "{number:11}"; rule.FLAG = "0"; rule.SERIALNUMBER = 10; isGenerated = true; break; case EnumCodeKey.OrgId: rule.ORGID = "ProduceOrg"; rule.CODEKEY = key.ToString(); rule.FLAGRULE = "0"; rule.GENERATERULE = "{number:10}"; rule.FLAG = "0"; rule.SERIALNUMBER = 1; isGenerated = true; break; case EnumCodeKey.RoleId: rule.ORGID = orgId; // orgId="RoleId" rule.CODEKEY = key.ToString(); rule.FLAGRULE = "0"; rule.GENERATERULE = "R{number:7}"; rule.FLAG = "0"; rule.SERIALNUMBER = 1; isGenerated = true; break; case EnumCodeKey.QuestionId: rule.ORGID = orgId; rule.CODEKEY = key.ToString(); rule.FLAGRULE = "0"; rule.GENERATERULE = "{number:4}"; rule.FLAG = "0"; rule.SERIALNUMBER = 13; isGenerated = true; break; case EnumCodeKey.LimitedId: rule.ORGID = orgId; rule.CODEKEY = key.ToString(); rule.FLAGRULE = "0"; rule.GENERATERULE = "{number:4}"; rule.FLAG = "0"; rule.SERIALNUMBER = 1468; isGenerated = true; break; case EnumCodeKey.EmpSysPre: rule.ORGID = orgId; rule.CODEKEY = key.ToString(); rule.FLAGRULE = "0"; rule.GENERATERULE = "EMP{number:3}"; rule.FLAG = "0"; rule.SERIALNUMBER = 1; isGenerated = true; break; case EnumCodeKey.EmpPrefix: string orgEmpSeriaNo = GenerateCode("EmpSysPre", EnumCodeKey.EmpSysPre); rule.ORGID = orgId; rule.CODEKEY = key.ToString(); rule.FLAGRULE = "1"; rule.GENERATERULE = orgEmpSeriaNo; rule.FLAG = "0"; rule.SERIALNUMBER = null; isGenerated = true; break; case EnumCodeKey.StaffId: rule.ORGID = orgId; // 集团ID rule.CODEKEY = key.ToString(); rule.FLAGRULE = "0"; rule.GENERATERULE = "{number:4}"; rule.FLAG = "0"; rule.SERIALNUMBER = 1; isGenerated = true; break; case EnumCodeKey.RoomId: rule.ORGID = "RoomId"; // 房间ID rule.CODEKEY = key.ToString(); rule.FLAGRULE = "0"; rule.GENERATERULE = "R{number:8}"; rule.FLAG = "0"; rule.SERIALNUMBER = 1; isGenerated = true; break; case EnumCodeKey.FloorId: rule.ORGID = "FloorId"; // 房间ID rule.CODEKEY = key.ToString(); rule.FLAGRULE = "0"; rule.GENERATERULE = "F{number:4}"; rule.FLAG = "0"; rule.SERIALNUMBER = 1; isGenerated = true; break; case EnumCodeKey.LeaveHospId: rule.ORGID = orgId; rule.CODEKEY = key.ToString(); rule.FLAGRULE = "0"; rule.GENERATERULE = "{number:10}"; rule.FLAG = "0"; rule.SERIALNUMBER = 1; isGenerated = true; break; case EnumCodeKey.BillNo: rule.ORGID = orgId; rule.CODEKEY = key.ToString(); rule.FLAGRULE = "0"; rule.GENERATERULE = "{number:9}"; rule.FLAG = "0"; rule.SERIALNUMBER = 1; isGenerated = true; break; case EnumCodeKey.GoodNo: rule.ORGID = orgId; rule.CODEKEY = key.ToString(); rule.FLAGRULE = "0"; rule.GENERATERULE = "{number:9}"; rule.FLAG = "0"; rule.SERIALNUMBER = 1; isGenerated = true; break; case EnumCodeKey.GoodsLoanNo: rule.ORGID = orgId; rule.CODEKEY = key.ToString(); rule.FLAGRULE = "0"; rule.GENERATERULE = "{number:9}"; rule.FLAG = "0"; rule.SERIALNUMBER = 1; isGenerated = true; break; case EnumCodeKey.GoodsSaleNo: rule.ORGID = orgId; rule.CODEKEY = key.ToString(); rule.FLAGRULE = "0"; rule.GENERATERULE = "{number:9}"; rule.FLAG = "0"; rule.SERIALNUMBER = 1; isGenerated = true; break; case EnumCodeKey.ManufactureNo: rule.ORGID = orgId; rule.CODEKEY = key.ToString(); rule.FLAGRULE = "0"; rule.GENERATERULE = "{number:9}"; rule.FLAG = "0"; rule.SERIALNUMBER = 1; isGenerated = true; break; case EnumCodeKey.PayBillNo: rule.ORGID = orgId; rule.CODEKEY = key.ToString(); rule.FLAGRULE = "0"; rule.GENERATERULE = "{number:9}"; rule.FLAG = "0"; rule.SERIALNUMBER = 1; isGenerated = true; break; case EnumCodeKey.ChargeGroupNo: rule.ORGID = orgId; rule.CODEKEY = key.ToString(); rule.FLAGRULE = "0"; rule.GENERATERULE = "{number:9}"; rule.FLAG = "0"; rule.SERIALNUMBER = 1; isGenerated = true; break; case EnumCodeKey.MeaSuredRecordId: rule.ORGID = orgId; rule.CODEKEY = key.ToString(); rule.FLAGRULE = "0"; rule.GENERATERULE = "{number:11}"; rule.FLAG = "0"; rule.SERIALNUMBER = 1; isGenerated = true; break; } if (isGenerated) { unitOfWork.GetRepository <SYS_CODERULE>().dbSet.Add(rule); unitOfWork.Save(); } return(isGenerated); }
public string GenerateCode(string orgId, EnumCodeKey key) { BaseRequest <object> request = new BaseRequest <object>(); BaseResponse <CodeRule> response = null; response = this.Get <SYS_CODERULE, CodeRule>((q) => q.ORGID == orgId && q.CODEKEY == key.ToString()); if (response.Data == null) { if (GenerateRule(orgId, key)) { response = this.Get <SYS_CODERULE, CodeRule>((q) => q.ORGID == orgId && q.CODEKEY == key.ToString()); } else { throw new Exception("编码查找创建失败!"); } } else { if (response.Data.FlagRule == "1") { //返回原值 return(ReplaceValue(response.Data.GenerateRule, response.Data.SerialNumber)); } } var flag = this.ReplaceValue(response.Data.FlagRule); //if (string.IsNullOrEmpty(response.Data.Flag) || response.Data.Flag != flag) //{ // response.Data.OrgId = orgId; // response.Data.Flag = flag; // response.Data.SerialNumber = 1; //} response.Data.SerialNumber++; unitOfWork.BeginTransaction(); this.Save <SYS_CODERULE, CodeRule>(response.Data, (q) => q.ORGID == orgId && q.CODEKEY == response.Data.CodeKey); unitOfWork.Commit(); return(ReplaceValue(response.Data.GenerateRule, response.Data.SerialNumber)); }
private string GenerateCode(int organizationID, EnumCodeKey key) { BaseRequest <object> request = new BaseRequest <object>(); BaseResponse <CodeRuleModel> response = null; response = this.Get <SYS_CodeRule, CodeRuleModel>((q) => q.OrganizationID == organizationID && q.CodeKey == key.ToString()); if (response.Data == null) { { throw new Exception("编码查找創建失败!"); } } var flag = this.ReplaceValue(response.Data.FlagRule); if (string.IsNullOrEmpty(response.Data.Flag) || response.Data.Flag != flag) { response.Data.OrganizationID = organizationID; response.Data.Flag = flag; response.Data.SerialNumber = 1; } else { response.Data.SerialNumber++; } unitOfWork.BeginTransaction(); this.Save <SYS_CodeRule, CodeRuleModel>(response.Data, (q) => q.OrganizationID == organizationID && q.CodeKey == response.Data.CodeKey); unitOfWork.Commit(); return(ReplaceValue(response.Data.GenerateRule, response.Data.SerialNumber)); }
/// <summary> /// 数据库未创建规则时,可在此方法中创建 /// </summary> /// <param name="orgId"></param> /// <param name="key"></param> /// <returns></returns> private bool GenerateRule(string orgId, EnumCodeKey key) { bool isGenerated = false; SYS_CODERULE rule = new SYS_CODERULE(); switch (key) { case EnumCodeKey.RegNo: rule.ORGID = orgId; rule.CODEKEY = key.ToString(); rule.FLAGRULE = "0"; rule.GENERATERULE = "{number:4}"; rule.FLAG = "0"; rule.SERIALNUMBER = 1; isGenerated = true; break; case EnumCodeKey.OrgId: rule.ORGID = "ProduceOrg"; rule.CODEKEY = key.ToString(); rule.FLAGRULE = "0"; rule.GENERATERULE = "{number:10}"; rule.FLAG = "0"; rule.SERIALNUMBER = 1; isGenerated = true; break; case EnumCodeKey.RoleId: rule.ORGID = orgId; // orgId="RoleId" rule.CODEKEY = key.ToString(); rule.FLAGRULE = "0"; rule.GENERATERULE = "R{number:7}"; rule.FLAG = "0"; rule.SERIALNUMBER = 1; isGenerated = true; break; case EnumCodeKey.QuestionId: rule.ORGID = orgId; rule.CODEKEY = key.ToString(); rule.FLAGRULE = "0"; rule.GENERATERULE = "{number:4}"; rule.FLAG = "0"; rule.SERIALNUMBER = 1; isGenerated = true; break; case EnumCodeKey.LimitedId: rule.ORGID = orgId; rule.CODEKEY = key.ToString(); rule.FLAGRULE = "0"; rule.GENERATERULE = "{number:4}"; rule.FLAG = "0"; rule.SERIALNUMBER = 1; isGenerated = true; break; case EnumCodeKey.EmpSysPre: rule.ORGID = orgId; rule.CODEKEY = key.ToString(); rule.FLAGRULE = "0"; rule.GENERATERULE = "EMP{number:3}"; rule.FLAG = "0"; rule.SERIALNUMBER = 1; isGenerated = true; break; case EnumCodeKey.EmpPrefix: string orgEmpSeriaNo = GenerateCode("EmpSysPre", EnumCodeKey.EmpSysPre); rule.ORGID = orgId; rule.CODEKEY = key.ToString(); rule.FLAGRULE = "1"; rule.GENERATERULE = orgEmpSeriaNo; rule.FLAG = "0"; rule.SERIALNUMBER = null; isGenerated = true; break; case EnumCodeKey.StaffId: rule.ORGID = orgId; // 集团ID rule.CODEKEY = key.ToString(); rule.FLAGRULE = "0"; rule.GENERATERULE = "{number:4}"; rule.FLAG = "0"; rule.SERIALNUMBER = 1; isGenerated = true; break; case EnumCodeKey.ApplicantId: rule.ORGID = "ApplicId"; rule.CODEKEY = key.ToString(); rule.FLAGRULE = "0"; rule.GENERATERULE = "P{time:yyyyMMdd}{number:4}"; rule.FLAG = "0"; rule.SERIALNUMBER = 100; isGenerated = true; break; case EnumCodeKey.AppcertSN: rule.ORGID = "AppcertSN"; rule.CODEKEY = key.ToString(); rule.FLAGRULE = "0"; rule.GENERATERULE = "P{time:yyyyMMdd}{number:4}"; rule.FLAG = "0"; rule.SERIALNUMBER = 100; isGenerated = true; break; case EnumCodeKey.AppHospSN: rule.ORGID = "AppHospSN"; rule.CODEKEY = key.ToString(); rule.FLAGRULE = "0"; rule.GENERATERULE = "P{time:yyyyMMdd}{number:4}"; rule.FLAG = "0"; rule.SERIALNUMBER = 100; isGenerated = true; break; case EnumCodeKey.CertNo: rule.ORGID = "CertNo"; rule.CODEKEY = key.ToString(); rule.FLAGRULE = "0"; rule.GENERATERULE = "C{time:yyyyMMdd}{number:4}"; rule.FLAG = "0"; rule.SERIALNUMBER = 100; isGenerated = true; break; case EnumCodeKey.GrantId: rule.ORGID = "GrantId"; rule.CODEKEY = key.ToString(); rule.FLAGRULE = "0"; rule.GENERATERULE = "{number:11}"; rule.FLAG = "0"; rule.SERIALNUMBER = 100; isGenerated = true; break; case EnumCodeKey.serviceId: rule.ORGID = "serviceId"; rule.CODEKEY = key.ToString(); rule.FLAGRULE = "0"; rule.GENERATERULE = "{number:11}"; rule.FLAG = "0"; rule.SERIALNUMBER = 100; isGenerated = true; break; } if (isGenerated) { unitOfWork.GetRepository <SYS_CODERULE>().dbSet.Add(rule); unitOfWork.Save(); } return(isGenerated); }