2024-05-16 10:13:39 +00:00
|
|
|
|
using Admin.NET.Core.Service;
|
|
|
|
|
using Admin.NET.Application.Const;
|
|
|
|
|
using Admin.NET.Application.Entity;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
2024-05-24 10:22:01 +00:00
|
|
|
|
using Admin.NET.Application.Utils;
|
|
|
|
|
|
2024-05-16 10:13:39 +00:00
|
|
|
|
namespace Admin.NET.Application;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 打印信息服务
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ApiDescriptionSettings(ApplicationConst.GroupName, Order = 100)]
|
|
|
|
|
public class PrintDataService : IDynamicApiController, ITransient
|
|
|
|
|
{
|
|
|
|
|
private readonly SqlSugarRepository<PrintData> _rep;
|
2024-05-24 10:22:01 +00:00
|
|
|
|
private readonly CodeElementService _codeElementService;
|
|
|
|
|
private readonly CodeElementPropService _codeElementPropService;
|
2024-06-24 10:21:52 +00:00
|
|
|
|
private readonly CodePakageConfigurationService _codePakageConfigurationService;
|
2024-05-24 10:22:01 +00:00
|
|
|
|
public PrintDataService(SqlSugarRepository<PrintData> rep,
|
|
|
|
|
CodeElementService codeElementService,
|
2024-06-24 10:21:52 +00:00
|
|
|
|
CodeElementPropService codeElementPropService,
|
|
|
|
|
CodePakageConfigurationService codePakageConfigurationService)
|
2024-05-16 10:13:39 +00:00
|
|
|
|
{
|
|
|
|
|
_rep = rep;
|
2024-05-24 10:22:01 +00:00
|
|
|
|
_codeElementService = codeElementService;
|
|
|
|
|
_codeElementPropService = codeElementPropService;
|
2024-06-24 10:21:52 +00:00
|
|
|
|
_codePakageConfigurationService = codePakageConfigurationService;
|
2024-05-16 10:13:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 分页查询打印信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ApiDescriptionSettings(Name = "Page")]
|
|
|
|
|
public async Task<SqlSugarPagedList<PrintData>> Page(PrintDataInput input)
|
|
|
|
|
{
|
|
|
|
|
var query = _rep.AsQueryable()
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.SearchKey), u =>
|
|
|
|
|
u.BarCode.Contains(input.SearchKey.Trim())
|
|
|
|
|
|| u.QrCode.Contains(input.SearchKey.Trim())
|
|
|
|
|
|| u.Remark.Contains(input.SearchKey.Trim())
|
|
|
|
|
)
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.BarCode), u => u.BarCode.Contains(input.BarCode.Trim()))
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.QrCode), u => u.QrCode.Contains(input.QrCode.Trim()))
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Remark), u => u.Remark.Contains(input.Remark.Trim()))
|
|
|
|
|
.Select<PrintData>();
|
|
|
|
|
return await query.OrderBuilder(input).ToPagedListAsync(input.Page, input.PageSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 增加打印信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ApiDescriptionSettings(Name = "Add")]
|
|
|
|
|
public async Task<long> Add(PrintData input)
|
|
|
|
|
{
|
|
|
|
|
var entity = input.Adapt<PrintData>();
|
|
|
|
|
await _rep.InsertAsync(entity);
|
|
|
|
|
return entity.Id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除打印信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ApiDescriptionSettings(Name = "Delete")]
|
|
|
|
|
public async Task Delete(long id)
|
|
|
|
|
{
|
|
|
|
|
var entity = await _rep.GetFirstAsync(u => u.Id == id) ?? throw Oops.Oh(ErrorCodeEnum.D1002);
|
|
|
|
|
//await _rep.FakeDeleteAsync(entity); //假删除
|
|
|
|
|
await _rep.DeleteAsync(entity); //真删除
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 更新打印信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ApiDescriptionSettings(Name = "Update")]
|
|
|
|
|
public async Task Update(PrintDataInput input)
|
|
|
|
|
{
|
|
|
|
|
var entity = input.Adapt<PrintData>();
|
|
|
|
|
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取打印信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[ApiDescriptionSettings(Name = "Detail")]
|
|
|
|
|
public async Task<PrintData> Detail([FromQuery] long id)
|
|
|
|
|
{
|
|
|
|
|
return await _rep.GetFirstAsync(u => u.Id == id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取打印信息列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ApiDescriptionSettings(Name = "GetPrintDataList")]
|
|
|
|
|
public async Task<List<PrintData>> GetPrintDataList(PrintDataMaterialsInput input)
|
2024-05-25 10:46:26 +00:00
|
|
|
|
{
|
2024-06-24 10:21:52 +00:00
|
|
|
|
return await GetPrintDatas(input.UnitGroupId, input.CodeHead, input.CodeType, input.Count);
|
2024-05-25 10:46:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-06-24 10:21:52 +00:00
|
|
|
|
public async Task<List<PrintData>> GetPrintDatas(long? unitGroupId, string codeName,string codeType,int count)
|
2024-05-16 10:13:39 +00:00
|
|
|
|
{
|
|
|
|
|
var result = new List<PrintData>();
|
2024-05-25 10:46:26 +00:00
|
|
|
|
if (string.IsNullOrEmpty(codeName))
|
2024-05-16 10:13:39 +00:00
|
|
|
|
{
|
2024-05-24 10:22:01 +00:00
|
|
|
|
return result;
|
2024-05-16 10:13:39 +00:00
|
|
|
|
}
|
2024-06-24 10:21:52 +00:00
|
|
|
|
var elem = await _codeElementService.GetElementByName(codeName, unitGroupId);
|
2024-05-24 10:22:01 +00:00
|
|
|
|
if (elem == null)
|
|
|
|
|
{ return result; }
|
2024-06-24 10:21:52 +00:00
|
|
|
|
var config = await _codePakageConfigurationService.GetConfigByName(codeName, unitGroupId);
|
|
|
|
|
if (config == null)
|
|
|
|
|
{ return result; }
|
2024-05-24 10:22:01 +00:00
|
|
|
|
var elemProp = await _codeElementPropService.CodePropByElement(new CodeElementOutput() { Id = elem.Id, CodeLength = elem.CodeLength });
|
2024-05-25 10:46:26 +00:00
|
|
|
|
if (elemProp.Count > 0)
|
2024-05-16 10:13:39 +00:00
|
|
|
|
{
|
2024-06-24 10:21:52 +00:00
|
|
|
|
var prefix = (string.IsNullOrEmpty(config.CodePrefix) || codeType == "条形码") ? "" : config.CodePrefix;
|
2024-05-24 10:22:01 +00:00
|
|
|
|
elemProp = elemProp.OrderBy(a => a.Index).ToList();
|
2024-05-25 10:46:26 +00:00
|
|
|
|
for (int i = 0; i < count; i++)
|
2024-05-16 10:13:39 +00:00
|
|
|
|
{
|
2024-06-24 10:21:52 +00:00
|
|
|
|
var code = prefix + GetCodeNumByProp(elemProp, i + 1);
|
2024-05-25 10:46:26 +00:00
|
|
|
|
if (codeType == "条形码")
|
2024-05-24 10:22:01 +00:00
|
|
|
|
{
|
|
|
|
|
result.Add(new PrintData() { BarCode = code });
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result.Add(new PrintData() { QrCode = code });
|
|
|
|
|
}
|
2024-05-16 10:13:39 +00:00
|
|
|
|
}
|
2024-05-24 10:22:01 +00:00
|
|
|
|
}
|
2024-05-25 10:46:26 +00:00
|
|
|
|
return result;
|
2024-05-24 10:22:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetCodeNumByProp(List<CodeElementPropOutput> lists,int index)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var result = string.Empty;
|
|
|
|
|
for (int i = 0; i < lists.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
var item = lists[i];
|
|
|
|
|
var format = "";
|
|
|
|
|
for (int j = 0; j < item.Length; j++)
|
|
|
|
|
{
|
|
|
|
|
format += "0";
|
|
|
|
|
}
|
|
|
|
|
switch (item.CodeType)
|
2024-05-16 10:13:39 +00:00
|
|
|
|
{
|
2024-05-24 10:22:01 +00:00
|
|
|
|
case "序号":
|
|
|
|
|
result += (Convert.ToInt32(item.CodeValue) + index).ToString(format);
|
|
|
|
|
break;
|
|
|
|
|
case "随机数":
|
|
|
|
|
result += CodeHelper.GetCodeRandom(item.Length);
|
|
|
|
|
break;
|
|
|
|
|
case "固定字符串":
|
|
|
|
|
result += item.CodeValue;
|
|
|
|
|
break;
|
|
|
|
|
case "随机字母数字":
|
|
|
|
|
result += CodeHelper.GetCodeLetterNum(item.Length);
|
|
|
|
|
break;
|
|
|
|
|
case "随机大小写字母":
|
|
|
|
|
result += CodeHelper.GetCodeLetter(item.Length);
|
|
|
|
|
break;
|
|
|
|
|
case "随机大写字母":
|
|
|
|
|
result += CodeHelper.GetCodeUpLetter(item.Length);
|
|
|
|
|
break;
|
|
|
|
|
case "随机小写字母":
|
|
|
|
|
result += CodeHelper.GetCodeDownLetter(item.Length);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
result += (Convert.ToInt32(item.CodeValue) + 1).ToString(format);
|
|
|
|
|
break;
|
2024-05-16 10:13:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-24 10:22:01 +00:00
|
|
|
|
return result;
|
2024-05-16 10:13:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-24 10:22:01 +00:00
|
|
|
|
|
2024-05-16 10:13:39 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取打印信息列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[ApiDescriptionSettings(Name = "List")]
|
|
|
|
|
public async Task<List<PrintData>> List()
|
|
|
|
|
{
|
|
|
|
|
return await _rep.AsQueryable().ToListAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|