|
|
@@ -0,0 +1,109 @@
|
|
|
+using Bussiness.Model.Sale;
|
|
|
+using Bussiness.Model.SystemData;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
+using System.Text;
|
|
|
+using System.Text.RegularExpressions;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using Volo.Abp.Application.Services;
|
|
|
+using Volo.Abp.Domain.Repositories;
|
|
|
+using XCZ.Extensions;
|
|
|
+using static Business.Permissions.BusinessPermissions;
|
|
|
+
|
|
|
+namespace Business.ResourceExamineManagement
|
|
|
+{
|
|
|
+ public class SerialNumberAppService : ApplicationService, ISerialNumberAppService
|
|
|
+ {
|
|
|
+ private readonly IRepository<sys_serial_number, long> _sys_serial_number;
|
|
|
+
|
|
|
+ public SerialNumberAppService(IRepository<sys_serial_number, long> sys_serial_number) {
|
|
|
+ _sys_serial_number = sys_serial_number;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 流水号生成
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="id"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ /// <exception cref="NotImplementedException"></exception>
|
|
|
+ public string GetSerialNumber(long id)
|
|
|
+ {
|
|
|
+ var model = Get(id);
|
|
|
+ if (model == null)
|
|
|
+ {
|
|
|
+ return string.Empty;
|
|
|
+ }
|
|
|
+ int max = model.current_number + 1;
|
|
|
+ var date = DateTime.Now;
|
|
|
+ var lastDate = model.last_time;
|
|
|
+ switch (model.number_type)
|
|
|
+ {
|
|
|
+ case 1: //年流水
|
|
|
+ if (date.Year > lastDate.Year)
|
|
|
+ {
|
|
|
+ max = 1;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 2: //月流水
|
|
|
+ if (date.Year > lastDate.Year || date.Month > lastDate.Month)
|
|
|
+ {
|
|
|
+ max = 1;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 3: //日流水
|
|
|
+ if (date.Year > lastDate.Year || date.Month > lastDate.Month || date.Day > lastDate.Day)
|
|
|
+ {
|
|
|
+ max = 1;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ model.last_time = date;
|
|
|
+ model.current_number = max;
|
|
|
+ string number = max.ToString().PadLeft(model.number_size, '0');
|
|
|
+ string sn = model.format;
|
|
|
+ sn = Replace(sn);
|
|
|
+ if (sn.Contains("{number}"))
|
|
|
+ {
|
|
|
+ sn = Regex.Replace(sn, "{number}", number);
|
|
|
+ }
|
|
|
+ Update(model);
|
|
|
+ return sn;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取流水号规则配置信息
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="id"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ private sys_serial_number Get(long id)
|
|
|
+ {
|
|
|
+ return _sys_serial_number.FindAsync(id).Result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 替换通配符
|
|
|
+ /// </summary>
|
|
|
+ private string Replace(string str)
|
|
|
+ {
|
|
|
+ if (str.Contains("{DateTime<"))
|
|
|
+ {
|
|
|
+ string key = str.Substring(str.IndexOf("{DateTime<") + 10);
|
|
|
+ string key1 = key.Substring(0, key.IndexOf(">}"));
|
|
|
+ if (!string.IsNullOrWhiteSpace(key1))
|
|
|
+ {
|
|
|
+ string newChar = DateTime.Now.ToString(key1);
|
|
|
+ string old = "{DateTime<" + key1 + ">}";
|
|
|
+ return str.Replace(old, newChar);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return str;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void Update(sys_serial_number model)
|
|
|
+ {
|
|
|
+ _sys_serial_number.UpdateAsync(model);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|