| | |
| | | using System.Diagnostics; |
| | | using System.Threading; |
| | | using System.Data; |
| | | using Tiger.IBusiness; |
| | | |
| | | namespace Tiger.Business |
| | | { |
| | | public partial class Biz |
| | | { |
| | | /// <summary> |
| | | /// 获取条码规则缓存 |
| | | /// </summary> |
| | | public static CodeRuleCache CodeRule => DbCacheBus.CodeRuleCache; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// BAS_CODE_RULE 扩展类 |
| | | /// </summary> |
| | |
| | | /// <returns></returns> |
| | | public static Result Verify(this BAS_CODE_RULE rule, string sn) |
| | | { |
| | | return Biz.CodeRule.Verify(sn, rule); |
| | | return Cache.CodeRule.Verify(sn, rule); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// <returns></returns> |
| | | public static Result Generate(this BAS_CODE_RULE rule, params object?[] args) |
| | | { |
| | | return Biz.CodeRule.Generate(rule.RULE_CODE, args); |
| | | return Cache.CodeRule.Generate(rule.RULE_CODE, args); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// <returns></returns> |
| | | public static Result TryGenerate(this BAS_CODE_RULE rule, params object?[] args) |
| | | { |
| | | return Biz.CodeRule.TryGenerate(rule.RULE_CODE, args); |
| | | return Cache.CodeRule.TryGenerate(rule.RULE_CODE, args); |
| | | } |
| | | }//endClass |
| | | |
| | |
| | | /// <summary> |
| | | /// 数据库关联验证 |
| | | /// </summary> |
| | | public static bool CheckDB(string key, BAS_CODE_DTL rule) |
| | | public static bool CheckDB(string key, BAS_CODE_DTL ruleDtl) |
| | | { |
| | | return rule.DATA_TYPE == BAS_CODE_DTL.DATA_TYPEs.DbCheck.GetValue() ? Biz.Db.Queryable(rule.CHECK_TABLE, "t").Where($"{rule.CHECK_FIELD} = '{key}'").Any() : true; |
| | | return ruleDtl.DATA_TYPE == BAS_CODE_DTL.DATA_TYPEs.DbCheck.GetValue() ? Biz.Db.Queryable(ruleDtl.CHECK_TABLE, "t").Where($"{ruleDtl.CHECK_FIELD} = '{key}'").Any() : true; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | //判断流水号是否符合规则 |
| | | if (IsMatch && item.DATA_TYPE == BAS_CODE_DTL.DATA_TYPEs.SerialCode.GetValue()) |
| | | { |
| | | //按取值范围判断当前流水号是否在范围内 |
| | | IsMatch &= item.SERIAL_MIN <= item.CodeValue.ToInt32() && item.CodeValue.ToInt32() <= item.SERIAL_MAX; |
| | | //当前流水号是否按设置间隔固定数值 |
| | | IsMatch &= (item.CodeValue.ToInt32() - item.SERIAL_MIN) % item.SERIAL_INTERVAL == 0; |
| | | //判断当前流水号是否跳过以设置号码结尾的流水号 |
| | | if (!item.SERIAL_IGNORE.IsNullOrEmpty()) |
| | | { |
| | | var ignoreList = item.SERIAL_IGNORE.Split(','); |
| | | foreach (var num in ignoreList) |
| | | { |
| | | IsMatch &= !item.CodeValue.EndsWith(num); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | //判断关联字段是否符合规则 |
| | |
| | | public Expression<Func<BAS_CODE_RULE, bool>> Expression { get; set; } |
| | | public Exception VerifyException { get; set; } |
| | | private List<RuleVerifier> _Verifiers = new(); |
| | | public List<RuleVerifier> Verifiers => _Verifiers.IsNullOrEmpty() ? Biz.CodeRule.Rules.WhereIF(!Predicate.IsNullOrEmpty(), Predicate).Select(q => new RuleVerifier(q)).ToList() : _Verifiers; |
| | | public List<RuleVerifier> Verifiers => _Verifiers.IsNullOrEmpty() ? Cache.CodeRule.Rules.WhereIF(!Predicate.IsNullOrEmpty(), Predicate).Select(q => new RuleVerifier(q)).ToList() : _Verifiers; |
| | | /// <summary> |
| | | /// 是否完成验证 |
| | | /// </summary> |
| | |
| | | var begin = DateTime.Now; |
| | | ElapsedTime = 0; |
| | | //Debug.WriteLine($"{Code} verify begin at {begin:T}"); |
| | | _Verifiers = Biz.CodeRule.Rules.WhereIF(!Predicate.IsNullOrEmpty(), Predicate).Select(q => new RuleVerifier(q)).ToList(); |
| | | _Verifiers = Cache.CodeRule.Rules.WhereIF(!Predicate.IsNullOrEmpty(), Predicate).Select(q => new RuleVerifier(q)).ToList(); |
| | | foreach (var item in Verifiers) |
| | | { |
| | | Work.DoAsync(() => { item.Verify(Code); }); |