修复bug
This commit is contained in:
@@ -48,6 +48,10 @@ public static class DictConst
|
||||
/// 包装工单
|
||||
/// </summary>
|
||||
public const string PrdMoTypeBZ = "25019191681045";
|
||||
/// <summary>
|
||||
/// 物料分类
|
||||
/// </summary>
|
||||
public const string MaterialCatagoryID = "24882163283733";
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
72
BasicData/Tnb.BasicData.Entities/Entity/BasRegionMat.cs
Normal file
72
BasicData/Tnb.BasicData.Entities/Entity/BasRegionMat.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using JNPF.Common.Contracts;
|
||||
using JNPF.Common.Security;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Tnb.BasicData.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// 区域物料设定
|
||||
/// </summary>
|
||||
[SugarTable("bas_region_mat")]
|
||||
public partial class BasRegionMat : BaseEntity<string>
|
||||
{
|
||||
public BasRegionMat()
|
||||
{
|
||||
id = SnowflakeIdHelper.NextId();
|
||||
}
|
||||
/// <summary>
|
||||
/// 所属组织
|
||||
/// </summary>
|
||||
public string? org_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 区域ID
|
||||
/// </summary>
|
||||
public string region_id { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 区域代码
|
||||
/// </summary>
|
||||
public string region_code { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 物料分类
|
||||
/// </summary>
|
||||
public string material_type { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
public string? remark { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建用户
|
||||
/// </summary>
|
||||
public string create_id { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
public DateTime create_time { get; set; } = DateTime.Now;
|
||||
|
||||
/// <summary>
|
||||
/// 修改用户
|
||||
/// </summary>
|
||||
public string? modify_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 修改时间
|
||||
/// </summary>
|
||||
public DateTime? modify_time { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 扩展字段
|
||||
/// </summary>
|
||||
public string? extras { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 时间戳(用于并发控制)
|
||||
/// </summary>
|
||||
public DateTime? timestamp { get; set; }
|
||||
|
||||
}
|
||||
99
BasicData/Tnb.BasicData/BasRegionMatService.cs
Normal file
99
BasicData/Tnb.BasicData/BasRegionMatService.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Aspose.Cells.Drawing;
|
||||
using DingTalk.Api.Request;
|
||||
using JNPF.Common.Dtos.VisualDev;
|
||||
using JNPF.Common.Extension;
|
||||
using JNPF.DependencyInjection;
|
||||
using JNPF.DynamicApiController;
|
||||
using JNPF.FriendlyException;
|
||||
using JNPF.Systems.Interfaces.System;
|
||||
using JNPF.VisualDev;
|
||||
using JNPF.VisualDev.Entitys;
|
||||
using JNPF.VisualDev.Interfaces;
|
||||
using Microsoft.AspNetCore.Components.Forms;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
using Tnb.BasicData.Entities;
|
||||
|
||||
namespace Tnb.BasicData
|
||||
{
|
||||
/// <summary>
|
||||
/// 区域物料设定
|
||||
/// </summary>
|
||||
[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 701)]
|
||||
[Route("api/[area]/[controller]/[action]")]
|
||||
[OverideVisualDev(ModuleId)]
|
||||
|
||||
public class BasRegionMatService : IOverideVisualDevService, IDynamicApiController, ITransient
|
||||
{
|
||||
private const string ModuleId = "26187428200229";
|
||||
private readonly ISqlSugarClient _db;
|
||||
private readonly IRunService _runService;
|
||||
private readonly IVisualDevService _visualDevService;
|
||||
private readonly IDictionaryDataService _dataDictionaryService;
|
||||
private static Dictionary<string, object> s_materialCategoryMap = new();
|
||||
|
||||
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
|
||||
public BasRegionMatService(ISqlSugarRepository<BasRegionMat> repo,
|
||||
IRunService runService, IVisualDevService visualDevService,
|
||||
IDictionaryDataService dataDictionaryService
|
||||
)
|
||||
{
|
||||
_db = repo.AsSugarClient();
|
||||
_runService = runService;
|
||||
_visualDevService = visualDevService;
|
||||
_dataDictionaryService = dataDictionaryService;
|
||||
OverideFuncs.CreateAsync = CreateAsync;
|
||||
}
|
||||
|
||||
private async Task<dynamic> CreateAsync(VisualDevModelDataCrInput input)
|
||||
{
|
||||
Task<int> respTask = Task.FromResult(1);
|
||||
try
|
||||
{
|
||||
await _db.Ado.BeginTranAsync();
|
||||
|
||||
string? regionCode = null, materialType = null;
|
||||
if (input.data.ContainsKey(nameof(BasRegionMat.region_code)) && input.data[nameof(BasRegionMat.region_code)].IsNotEmptyOrNull())
|
||||
{
|
||||
regionCode = input.data[nameof(BasRegionMat.region_code)].ToString();
|
||||
}
|
||||
if (input.data.ContainsKey(nameof(BasRegionMat.material_type)) && input.data[nameof(BasRegionMat.material_type)].IsNotEmptyOrNull())
|
||||
{
|
||||
materialType = input.data[nameof(BasRegionMat.material_type)].ToString();
|
||||
}
|
||||
var blTrueAll = new List<bool> { regionCode.IsNullOrWhiteSpace(), materialType.IsNullOrWhiteSpace() };
|
||||
if (blTrueAll.All(b => !b))
|
||||
{
|
||||
if (s_materialCategoryMap.Count == 0)
|
||||
{
|
||||
s_materialCategoryMap = await _dataDictionaryService.GetDictionaryByTypeId(DictConst.MaterialCatagoryID);
|
||||
}
|
||||
var regionMat = await _db.Queryable<BasRegionMat>().FirstAsync(it => it.region_code == regionCode && it.material_type == materialType);
|
||||
if (regionMat != null)
|
||||
{
|
||||
throw new AppFriendlyException($"区域:【{regionCode}】,物料:【{s_materialCategoryMap[materialType]?.ToString()}】已存在", 500);
|
||||
}
|
||||
}
|
||||
await _db.Ado.CommitTranAsync();
|
||||
|
||||
VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleId, true);
|
||||
await _runService.Create(templateEntity, input);
|
||||
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
respTask = Task.FromResult(0);
|
||||
await _db.Ado.RollbackTranAsync();
|
||||
throw;
|
||||
}
|
||||
|
||||
return await respTask;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user