zhangxiaofeng 3 months ago
commit 3b1c97a6a5

@ -0,0 +1,85 @@
using DS.Module.Core;
using FluentValidation;
namespace DS.WMS.Core.Code.Dtos;
/// <summary>
/// 基础编码请求实体
/// </summary>
public class CodeSequenceReq
{
/// <summary>
/// 主键Id
/// </summary>
public long Id { get; set; }
/// <summary>
/// 权限ID
/// </summary>
public long PermissionId { get; set; }
/// <summary>
/// 权限实体
/// </summary>
public string PermissionEntity { get; set; }= "";
/// <summary>
/// 名称
/// </summary>
public string SequenceName { get; set; }= "";
/// <summary>
/// 分隔符
/// </summary>
public string SequenceDelimiter { get; set; }= "";
/// <summary>
/// 序号重置规则
/// </summary>
public string SequenceReset { get; set; } = "";
/// <summary>
/// 步长
/// </summary>
public int Step { get; set; } = 0;
/// <summary>
/// 当前值
/// </summary>
public int CurrentNo { get; set; }= 0;
/// <summary>
/// 当前编码
/// </summary>
public string CurrentCode { get; set; }= "";
/// <summary>
/// 当前重置依赖,即最后一次获取编码的日期
/// </summary>
public string CurrentReset { get; set; }= "";
/// <summary>
/// 排序
/// </summary>
public int? OrderNo { get; set; } = 100;
/// <summary>
/// 状态 0 启用 1 禁用
/// </summary>
public StatusEnum? Status { get; set; } = StatusEnum.Enable;
/// <summary>
/// 备注
/// </summary>
public string Note { get; set; } = "";
}
/// <summary>
/// 验证
/// </summary>
public class CodeSequenceReqValidator : AbstractValidator<CodeSequenceReq>
{
/// <summary>
/// 构造函数
/// </summary>
public CodeSequenceReqValidator()
{
this.RuleFor(o => o.PermissionId)
.NotEmpty().WithName("权限模块Id");
this.RuleFor(o => o.SequenceName)
.NotEmpty().WithName("名称");
}
}

@ -0,0 +1,71 @@
using DS.Module.Core;
namespace DS.WMS.Core.Code.Dtos;
/// <summary>
/// 基础编码返回实体
/// </summary>
public class CodeSequenceRes
{
/// <summary>
/// 主键Id
/// </summary>
public long Id { get; set; }
/// <summary>
/// 权限ID
/// </summary>
public long PermissionId { get; set; }
/// <summary>
/// 权限实体
/// </summary>
public string PermissionEntity { get; set; }= "";
/// <summary>
/// 名称
/// </summary>
public string SequenceName { get; set; }= "";
/// <summary>
/// 分隔符
/// </summary>
public string SequenceDelimiter { get; set; }= "";
/// <summary>
/// 序号重置规则
/// </summary>
public string SequenceReset { get; set; } = "";
/// <summary>
/// 步长
/// </summary>
public int Step { get; set; } = 0;
/// <summary>
/// 当前值
/// </summary>
public int CurrentNo { get; set; }= 0;
/// <summary>
/// 当前编码
/// </summary>
public string CurrentCode { get; set; }= "";
/// <summary>
/// 当前重置依赖,即最后一次获取编码的日期
/// </summary>
public string CurrentReset { get; set; }= "";
/// <summary>
/// 状态 0 启用 1 禁用
/// </summary>
public StatusEnum? Status { get; set; } = StatusEnum.Enable;
/// <summary>
/// 备注
/// </summary>
public string Note { get; set; } = "";
/// <summary>
/// 排序
/// </summary>
public int? OrderNo { get; set; } = 100;
/// <summary>
/// 创建时间
/// </summary>
public DateTime CreateTime { get; set; }
}

@ -0,0 +1,71 @@
using DS.Module.Core;
using FluentValidation;
namespace DS.WMS.Core.Code.Dtos;
/// <summary>
/// 基础编码规则请求实体
/// </summary>
public class CodeSequenceRuleReq
{
/// <summary>
/// 主键Id
/// </summary>
public long Id { get; set; }
/// <summary>
/// 单据Id
/// </summary>
public long SequenceId { get; set; }
/// <summary>
/// 取规则类别timestamp、const、number
/// </summary>
public string RuleType { get; set; }
/// <summary>
/// 规则参数,如 YYMMDD
/// </summary>
public string RuleValue { get; set; }
/// <summary>
/// 补齐方向left或right
/// </summary>
public string PaddingSide { get; set; }
/// <summary>
/// 补齐宽度
/// </summary>
public int PaddingWidth { get; set; }
/// <summary>
/// 填充字符
/// </summary>
public string PaddingChar { get; set; }
/// <summary>
/// 排序
/// </summary>
public int? OrderNo { get; set; } = 100;
/// <summary>
/// 状态 0 启用 1 禁用
/// </summary>
public StatusEnum? Status { get; set; } = StatusEnum.Enable;
/// <summary>
/// 备注
/// </summary>
public string Note { get; set; } = "";
}
/// <summary>
/// 验证
/// </summary>
public class CodeSequenceRuleReqValidator : AbstractValidator<CodeSequenceRuleReq>
{
/// <summary>
/// 构造函数
/// </summary>
public CodeSequenceRuleReqValidator()
{
this.RuleFor(o => o.RuleType)
.NotEmpty().WithName("取规则类别");
this.RuleFor(o => o.RuleValue)
.NotEmpty().WithName("规则参数");
}
}

@ -0,0 +1,57 @@
using DS.Module.Core;
namespace DS.WMS.Core.Code.Dtos;
/// <summary>
/// 基础编码规则返回实体
/// </summary>
public class CodeSequenceRuleRes
{
/// <summary>
/// 主键Id
/// </summary>
public long Id { get; set; }
/// <summary>
/// 单据Id
/// </summary>
public long SequenceId { get; set; }
/// <summary>
/// 取规则类别timestamp、const、number
/// </summary>
public string RuleType { get; set; }
/// <summary>
/// 规则参数,如 YYMMDD
/// </summary>
public string RuleValue { get; set; }
/// <summary>
/// 补齐方向left或right
/// </summary>
public string PaddingSide { get; set; }
/// <summary>
/// 补齐宽度
/// </summary>
public int PaddingWidth { get; set; }
/// <summary>
/// 填充字符
/// </summary>
public string PaddingChar { get; set; }
/// <summary>
/// 状态 0 启用 1 禁用
/// </summary>
public StatusEnum? Status { get; set; } = StatusEnum.Enable;
/// <summary>
/// 备注
/// </summary>
public string Note { get; set; } = "";
/// <summary>
/// 排序
/// </summary>
public int? OrderNo { get; set; } = 100;
/// <summary>
/// 创建时间
/// </summary>
public DateTime CreateTime { get; set; }
}

@ -0,0 +1,75 @@
using DS.Module.Core;
using DS.Module.Core.Data;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DS.WMS.Core.Code.Entity
{
/// <summary>
/// 基础编码表
/// </summary>
[SqlSugar.SugarTable("code_sequence", "基础编码表")]
public class CodeSequence : BaseOrgModel<long>
{
/// <summary>
/// 权限ID
/// </summary>
[SugarColumn(ColumnDescription = "权限ID")]
public long PermissionId { get; set; }
/// <summary>
/// 权限实体
/// </summary>
[SugarColumn(ColumnDescription = "权限实体",Length = 50)]
public string PermissionEntity { get; set; }
/// <summary>
/// 名称
/// </summary>
[SugarColumn(ColumnDescription = "名称", Length = 50)]
public string SequenceName { get; set; }
/// <summary>
/// 分隔符
/// </summary>
[SugarColumn(ColumnDescription = "分隔符", Length = 50,IsNullable = true)]
public string SequenceDelimiter { get; set; }
/// <summary>
/// 序号重置规则
/// </summary>
[SugarColumn(ColumnDescription = "分隔符", Length = 100, IsNullable = true)]
public string SequenceReset { get; set; }
/// <summary>
/// 步长
/// </summary>
[SugarColumn(ColumnDescription = "步长", DefaultValue ="1")]
public int Step { get; set; }
/// <summary>
/// 当前值
/// </summary>
[SugarColumn(ColumnDescription = "当前值")]
public int CurrentNo { get; set; }
/// <summary>
/// 当前编码
/// </summary>
[SugarColumn(ColumnDescription = "当前编码", Length = 100, IsNullable = true)]
public string CurrentCode { get; set; }
/// <summary>
/// 当前重置依赖,即最后一次获取编码的日期
/// </summary>
[SugarColumn(ColumnDescription = "当前重置依赖", Length = 100, IsNullable = true)]
public string CurrentReset { get; set; }
/// <summary>
/// 状态
/// </summary>
[SqlSugar.SugarColumn(ColumnDescription = "状态")]
public StatusEnum? Status { get; set; } = StatusEnum.Enable;
/// <summary>
/// 排序号
/// </summary>
[SugarColumn(ColumnDescription = "排序号",DefaultValue ="100")]
public int OrderNo { get; set; }
}
}

@ -0,0 +1,60 @@
using DS.Module.Core;
using DS.Module.Core.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SqlSugar;
namespace DS.WMS.Core.Code.Entity
{
/// <summary>
/// 基础编码规则表
/// </summary>
[SqlSugar.SugarTable("code_sequence_rule", "基础编码规则表")]
public class CodeSequenceRule : BaseModel<long>
{
/// <summary>
/// 单据Id
/// </summary>
[SugarColumn(ColumnDescription = "单据Id")]
public long SequenceId { get; set; }
/// <summary>
/// 取规则类别timestamp、const、number
/// </summary>
[SugarColumn(ColumnDescription = "取规则类别", Length = 100, IsNullable = false)]
public string RuleType { get; set; }
/// <summary>
/// 规则参数,如 YYMMDD
/// </summary>
[SugarColumn(ColumnDescription = "补齐方向", Length = 100, IsNullable = false)]
public string RuleValue { get; set; }
/// <summary>
/// 补齐方向left或right
/// </summary>
[SugarColumn(ColumnDescription = "补齐方向", Length = 50, IsNullable = true)]
public string PaddingSide { get; set; }
/// <summary>
/// 补齐宽度
/// </summary>
[SugarColumn(ColumnDescription = "补齐宽度")]
public int PaddingWidth { get; set; }
/// <summary>
/// 填充字符
/// </summary>
[SugarColumn(ColumnDescription = "填充字符", Length = 100, IsNullable = true)]
public string PaddingChar { get; set; }
/// <summary>
/// 状态
/// </summary>
[SqlSugar.SugarColumn(ColumnDescription = "状态")]
public StatusEnum? Status { get; set; } = StatusEnum.Enable;
/// <summary>
/// 排序号
/// </summary>
[SugarColumn(ColumnDescription = "排序号",DefaultValue ="100")]
public int OrderNo { get; set; }
}
}

@ -0,0 +1,31 @@
using DS.Module.Core;
using DS.WMS.Core.Code.Dtos;
using DS.WMS.Core.Sys.Dtos;
using DS.WMS.Core.Sys.Entity;
namespace DS.WMS.Core.Code.Interface;
public interface ICodeSequenceRuleService
{
/// <summary>
/// 列表
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
DataResult<List<CodeSequenceRuleRes>> GetListByPage(PageRequest request);
/// <summary>
/// 编辑
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
DataResult EditSequenceRule(CodeSequenceRuleReq model);
/// <summary>
/// 获取详情
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
DataResult<CodeSequenceRuleRes> GetSequenceRuleInfo(string id);
}

@ -0,0 +1,31 @@
using DS.Module.Core;
using DS.WMS.Core.Code.Dtos;
using DS.WMS.Core.Sys.Dtos;
using DS.WMS.Core.Sys.Entity;
namespace DS.WMS.Core.Code.Interface;
public interface ICodeSequenceService
{
/// <summary>
/// 列表
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
DataResult<List<CodeSequenceRes>> GetListByPage(PageRequest request);
/// <summary>
/// 编辑
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
DataResult EditSequence(CodeSequenceReq model);
/// <summary>
/// 获取详情
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
DataResult<CodeSequenceRes> GetSequenceInfo(string id);
}

@ -0,0 +1,95 @@
using DS.Module.Core;
using DS.Module.Core.Extensions;
using DS.Module.UserModule;
using DS.WMS.Core.Code.Interface;
using DS.WMS.Core.Sys.Dtos;
using DS.WMS.Core.Sys.Entity;
using DS.WMS.Core.Sys.Interface;
using Mapster;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
using DS.Module.SqlSugar;
using DS.WMS.Core.Code.Dtos;
using DS.WMS.Core.Code.Entity;
namespace DS.WMS.Core.Code.Method;
public class CodeSequenceRuleService : ICodeSequenceRuleService
{
private readonly IServiceProvider _serviceProvider;
private readonly ISqlSugarClient db;
private readonly IUser user;
private readonly ISaasDbService saasService;
/// <summary>
///
/// </summary>
/// <param name="serviceProvider"></param>
public CodeSequenceRuleService(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
user = _serviceProvider.GetRequiredService<IUser>();
saasService = _serviceProvider.GetRequiredService<ISaasDbService>();
}
/// <summary>
/// 列表
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public DataResult<List<CodeSequenceRuleRes>> GetListByPage(PageRequest request)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
//序列化查询条件
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
var data = tenantDb.Queryable<CodeSequenceRule>()
.Where(whereList)
.Select<CodeSequenceRuleRes>().ToQueryPage(request.PageCondition);
return data;
}
/// <summary>
/// 编辑
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
public DataResult EditSequenceRule(CodeSequenceRuleReq req)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (req.Id == 0)
{
if (tenantDb.Queryable<CodeSequenceRule>().Where(x=>x.SequenceId == req.SequenceId && x.RuleType == req.RuleType).Any())
{
return DataResult.Failed("基础编码规则已存在!",MultiLanguageConst.SequenceRuleExist);
}
var data = req.Adapt<CodeSequenceRule>();
var entity = tenantDb.Insertable(data).ExecuteReturnEntity();
return DataResult.Successed("添加成功!", entity.Id,MultiLanguageConst.DataCreateSuccess);
}
else
{
var info = tenantDb.Queryable<CodeSequenceRule>().Where(x => x.Id == req.Id).First();
info = req.Adapt(info);
tenantDb.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
return DataResult.Successed("更新成功!",MultiLanguageConst.DataUpdateSuccess);
}
}
/// <summary>
/// 详情
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public DataResult<CodeSequenceRuleRes> GetSequenceRuleInfo(string id)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
var data = tenantDb.Queryable<CodeSequenceRule>()
.Where(a => a.Id == long.Parse(id))
.Select<CodeSequenceRuleRes>()
.First();
return DataResult<CodeSequenceRuleRes>.Success(data,MultiLanguageConst.DataQuerySuccess);
}
}

@ -0,0 +1,97 @@
using DS.Module.Core;
using DS.Module.Core.Extensions;
using DS.Module.SqlSugar;
using DS.Module.UserModule;
using DS.WMS.Core.Code.Dtos;
using DS.WMS.Core.Code.Entity;
using DS.WMS.Core.Code.Interface;
using DS.WMS.Core.Sys.Entity;
using Mapster;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
namespace DS.WMS.Core.Code.Method;
public class CodeSequenceService : ICodeSequenceService
{
private readonly IServiceProvider _serviceProvider;
private readonly ISqlSugarClient db;
private readonly IUser user;
private readonly ISaasDbService saasService;
/// <summary>
///
/// </summary>
/// <param name="serviceProvider"></param>
public CodeSequenceService(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
user = _serviceProvider.GetRequiredService<IUser>();
saasService = _serviceProvider.GetRequiredService<ISaasDbService>();
}
/// <summary>
/// 列表
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public DataResult<List<CodeSequenceRes>> GetListByPage(PageRequest request)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
//序列化查询条件
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
var data = tenantDb.Queryable<CodeSequence>()
.LeftJoin<SysPermission>((a, b) => a.PermissionId == b.Id)
.Where(whereList)
.Select<CodeSequenceRes>().ToQueryPage(request.PageCondition);
return data;
}
/// <summary>
/// 编辑
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
public DataResult EditSequence(CodeSequenceReq req)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (req.Id == 0)
{
if (tenantDb.Queryable<CodeSequence>().Where(x => x.PermissionId == req.PermissionId && x.OrderNo == req.OrderNo).Any())
{
return DataResult.Failed("基础编码已存在!", MultiLanguageConst.SequenceExist);
}
var data = req.Adapt<CodeSequence>();
var entity = tenantDb.Insertable(data).ExecuteReturnEntity();
return DataResult.Successed("添加成功!", entity.Id, MultiLanguageConst.DataCreateSuccess);
}
else
{
var info = tenantDb.Queryable<CodeSequence>().Where(x => x.Id == req.Id).First();
info = req.Adapt(info);
tenantDb.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
return DataResult.Successed("更新成功!", MultiLanguageConst.DataUpdateSuccess);
}
}
/// <summary>
/// 详情
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public DataResult<CodeSequenceRes> GetSequenceInfo(string id)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
var data = tenantDb.Queryable<CodeSequence>()
.LeftJoin<SysPermission>((a, b) => a.PermissionId == b.Id)
.Where(a => a.Id == long.Parse(id))
.Select<CodeSequenceRes>()
.First();
return DataResult<CodeSequenceRes>.Success(data, MultiLanguageConst.DataQuerySuccess);
}
}

@ -0,0 +1,105 @@
using DS.Module.Core;
using DS.WMS.Core.Code.Dtos;
using DS.WMS.Core.Code.Interface;
using DS.WMS.Core.Sys.Dtos;
using DS.WMS.Core.Sys.Entity;
using DS.WMS.Core.Sys.Interface;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace DS.WMS.MainApi.Controllers;
/// <summary>
/// 基础编码模块
/// </summary>
public class CodeSequenceController : ApiController
{
private readonly ICodeSequenceService _invokeService;
private readonly ICodeSequenceRuleService _sequenceRuleService;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="invokeService"></param>
public CodeSequenceController(ICodeSequenceService invokeService, ICodeSequenceRuleService SequenceRuleService)
{
_invokeService = invokeService;
_sequenceRuleService = SequenceRuleService;
}
/// <summary>
/// 基础编码列表
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpPost]
[Route("GetSequenceTypeList")]
public DataResult<List<CodeSequenceRes>> GetSequenceList([FromBody] PageRequest request)
{
var res = _invokeService.GetListByPage(request);
return res;
}
/// <summary>
/// 编辑基础编码
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
[HttpPost]
[Route("EditSequence")]
public DataResult EditSequence([FromBody] CodeSequenceReq model)
{
var res = _invokeService.EditSequence(model);
return res;
}
/// <summary>
/// 编码规则列表
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpPost]
[Route("GetSequenceRuleList")]
public DataResult<List<CodeSequenceRuleRes>> GetSequenceRuleList([FromBody] PageRequest request)
{
var res = _sequenceRuleService.GetListByPage(request);
return res;
}
/// <summary>
/// 编辑 编码规则
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
[HttpPost]
[Route("EditSequenceRule")]
public DataResult EditSequenceRule([FromBody] CodeSequenceRuleReq model)
{
var res = _sequenceRuleService.EditSequenceRule(model);
return res;
}
/// <summary>
/// 基础编码详情
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet]
[Route("GetSequenceInfo")]
public DataResult<CodeSequenceRes> GetSequenceInfo([FromQuery] string id)
{
var res = _invokeService.GetSequenceInfo(id);
return res;
}
/// <summary>
/// 编码规则详情
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet]
[Route("GetSequenceRuleInfo")]
public DataResult<CodeSequenceRuleRes> GetSequenceRuleInfo([FromQuery] string id)
{
var res = _sequenceRuleService.GetSequenceRuleInfo(id);
return res;
}
}
Loading…
Cancel
Save