diff --git a/ZR.Admin.WebApi/Controllers/mes/wms/WmPolishInventoryController.cs b/ZR.Admin.WebApi/Controllers/mes/wms/WmPolishInventoryController.cs new file mode 100644 index 00000000..30688f13 --- /dev/null +++ b/ZR.Admin.WebApi/Controllers/mes/wms/WmPolishInventoryController.cs @@ -0,0 +1,146 @@ +using Microsoft.AspNetCore.Mvc; +using ZR.Admin.WebApi.Extensions; +using ZR.Admin.WebApi.Filters; +using ZR.Model.MES.wms; +using ZR.Model.MES.wms.Dto; +using ZR.Service.mes.wms.IService; + +//创建时间:2024-07-25 +namespace ZR.Admin.WebApi.Controllers +{ + /// + /// 工艺路线-抛光 库存表 + /// + [Verify] + [Route("/mes/wm/WmPolishInventory")] + public class WmPolishInventoryController : BaseController + { + /// + /// 工艺路线-抛光 库存表接口 + /// + private readonly IWmPolishInventoryService _WmPolishInventoryService; + + public WmPolishInventoryController(IWmPolishInventoryService WmPolishInventoryService) + { + _WmPolishInventoryService = WmPolishInventoryService; + } + + /// + /// 查询工艺路线-抛光 库存表列表 + /// + /// + /// + [HttpGet("list")] + [ActionPermissionFilter(Permission = "business:wmpolishinventory:list")] + public IActionResult QueryWmPolishInventory([FromQuery] WmPolishInventoryQueryDto parm) + { + var response = _WmPolishInventoryService.GetList(parm); + return SUCCESS(response); + } + + /// + /// 查询工艺路线-抛光 库存表详情 + /// + /// + /// + [HttpGet("{Id}")] + [ActionPermissionFilter(Permission = "business:wmpolishinventory:query")] + public IActionResult GetWmPolishInventory(string Id) + { + var response = _WmPolishInventoryService.GetInfo(Id); + + var info = response.Adapt(); + return SUCCESS(info); + } + + /// + /// 添加抛光 库存表 + /// + /// + [HttpPost] + [ActionPermissionFilter(Permission = "business:wmpolishinventory:add")] + [Log(Title = "抛光 库存表", BusinessType = BusinessType.INSERT)] + public IActionResult AddWmPolishInventory([FromBody] WmPolishInventoryDto parm) + { + var modal = parm.Adapt().ToCreate(HttpContext); + + var response = _WmPolishInventoryService.AddWmPolishInventory(modal); + + return SUCCESS(response); + } + + /// + /// 更新抛光 库存表 + /// + /// + [HttpPut] + [ActionPermissionFilter(Permission = "business:wmpolishinventory:edit")] + [Log(Title = "抛光 库存表", BusinessType = BusinessType.UPDATE)] + public IActionResult UpdateWmPolishInventory([FromBody] WmPolishInventoryDto parm) + { + var modal = parm.Adapt().ToUpdate(HttpContext); + var response = _WmPolishInventoryService.UpdateWmPolishInventory(modal); + + return ToResponse(response); + } + + /// + /// 删除抛光 库存表 + /// + /// + [HttpDelete("{ids}")] + [ActionPermissionFilter(Permission = "business:wmpolishinventory:delete")] + [Log(Title = "抛光 库存表", BusinessType = BusinessType.DELETE)] + public IActionResult DeleteWmPolishInventory(string ids) + { + string[] idsArr = ids.Split(","); + if (idsArr.Length <= 0) + { + return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); + } + + var response = _WmPolishInventoryService.Delete(idsArr); + + return ToResponse(response); + } + + /// + /// 抛光手动入库 + /// + /// + [HttpPost("doWmPolishWarehousing")] + [ActionPermissionFilter(Permission = "business:wmpolishinventory:add")] + [Log(Title = "抛光手动入库", BusinessType = BusinessType.INSERT)] + public IActionResult DoWmPolishWarehousing([FromBody] WmPolishInventoryDto parm) + { + try + { + var modal = parm.Adapt().ToCreate(HttpContext); + var response = _WmPolishInventoryService.DoWmPolishWarehousing(modal); + return ToResponse(new ApiResult(200, "手动入库成功", response)); + } + catch (Exception e) + { + return ToResponse(new ApiResult(500, "手动入库异常:" + e.Message, e.Message)); + } + } + + /// + /// 物料下拉菜单查看 + /// + /// + [HttpGet("getMaterialSelectOption")] + public IActionResult GetMaterialSelectOption([FromQuery] string query) + { + try + { + var response = _WmPolishInventoryService.GetMaterialSelectOption(query); + return ToResponse(new ApiResult(200, "获取成功", response)); + } + catch (Exception e) + { + return ToResponse(new ApiResult(500, "获取物料下拉菜单数据失败:" + e.Message, null)); + } + } + } +} diff --git a/ZR.Admin.WebApi/Controllers/mes/wms/WmPolishRecordController.cs b/ZR.Admin.WebApi/Controllers/mes/wms/WmPolishRecordController.cs new file mode 100644 index 00000000..8e999764 --- /dev/null +++ b/ZR.Admin.WebApi/Controllers/mes/wms/WmPolishRecordController.cs @@ -0,0 +1,107 @@ +using Microsoft.AspNetCore.Mvc; +using ZR.Admin.WebApi.Extensions; +using ZR.Admin.WebApi.Filters; +using ZR.Model.MES.wms; +using ZR.Model.MES.wms.Dto; +using ZR.Service.mes.wms.IService; + +//创建时间:2024-07-25 +namespace ZR.Admin.WebApi.Controllers +{ + /// + /// 工艺路线-抛光 库存变动表 + /// + [Verify] + [Route("/mes/wm/WmPolishRecord")] + public class WmPolishRecordController : BaseController + { + /// + /// 工艺路线-抛光 库存变动表接口 + /// + private readonly IWmPolishRecordService _WmPolishRecordService; + + public WmPolishRecordController(IWmPolishRecordService WmPolishRecordService) + { + _WmPolishRecordService = WmPolishRecordService; + } + + /// + /// 查询工艺路线-抛光 库存变动表列表 + /// + /// + /// + [HttpGet("list")] + [ActionPermissionFilter(Permission = "business:wmpolishrecord:list")] + public IActionResult QueryWmPolishRecord([FromQuery] WmPolishRecordQueryDto parm) + { + var response = _WmPolishRecordService.GetList(parm); + return SUCCESS(response); + } + + /// + /// 查询工艺路线-抛光 库存变动表详情 + /// + /// + /// + [HttpGet("{Id}")] + [ActionPermissionFilter(Permission = "business:wmpolishrecord:query")] + public IActionResult GetWmPolishRecord(string Id) + { + var response = _WmPolishRecordService.GetInfo(Id); + + var info = response.Adapt(); + return SUCCESS(info); + } + + /// + /// 添加工艺路线-抛光 库存变动表 + /// + /// + [HttpPost] + [ActionPermissionFilter(Permission = "business:wmpolishrecord:add")] + [Log(Title = "工艺路线-抛光 库存变动表", BusinessType = BusinessType.INSERT)] + public IActionResult AddWmPolishRecord([FromBody] WmPolishRecordDto parm) + { + var modal = parm.Adapt().ToCreate(HttpContext); + + var response = _WmPolishRecordService.AddWmPolishRecord(modal); + + return SUCCESS(response); + } + + /// + /// 更新工艺路线-抛光 库存变动表 + /// + /// + [HttpPut] + [ActionPermissionFilter(Permission = "business:wmpolishrecord:edit")] + [Log(Title = "工艺路线-抛光 库存变动表", BusinessType = BusinessType.UPDATE)] + public IActionResult UpdateWmPolishRecord([FromBody] WmPolishRecordDto parm) + { + var modal = parm.Adapt().ToUpdate(HttpContext); + var response = _WmPolishRecordService.UpdateWmPolishRecord(modal); + + return ToResponse(response); + } + + /// + /// 删除工艺路线-抛光 库存变动表 + /// + /// + [HttpDelete("{ids}")] + [ActionPermissionFilter(Permission = "business:wmpolishrecord:delete")] + [Log(Title = "工艺路线-抛光 库存变动表", BusinessType = BusinessType.DELETE)] + public IActionResult DeleteWmPolishRecord(string ids) + { + int[] idsArr = Tools.SpitIntArrary(ids); + if (idsArr.Length <= 0) + { + return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); + } + + var response = _WmPolishRecordService.Delete(idsArr); + + return ToResponse(response); + } + } +} diff --git a/ZR.Model/MES/wms/Dto/WmMaterialDto.cs b/ZR.Model/MES/wms/Dto/WmMaterialDto.cs index 68caba79..a56d137a 100644 --- a/ZR.Model/MES/wms/Dto/WmMaterialDto.cs +++ b/ZR.Model/MES/wms/Dto/WmMaterialDto.cs @@ -168,6 +168,14 @@ namespace ZR.Model.MES.wms.Dto } - + /// + /// 物料下拉查询表 + /// + public class WmMaterialSelectOptions + { + public string Key { get; set; } + public string Label { get; set; } + public string Value { get; set; } + } } \ No newline at end of file diff --git a/ZR.Model/MES/wms/Dto/WmPolishInventoryDto.cs b/ZR.Model/MES/wms/Dto/WmPolishInventoryDto.cs new file mode 100644 index 00000000..1c952dee --- /dev/null +++ b/ZR.Model/MES/wms/Dto/WmPolishInventoryDto.cs @@ -0,0 +1,66 @@ +using System.ComponentModel.DataAnnotations; + +namespace ZR.Model.MES.wms.Dto +{ + /// + /// 工艺路线-抛光 库存表查询对象 + /// + public class WmPolishInventoryQueryDto : PagerInfo + { + public string BlankNum { get; set; } + + public string Partnumber { get; set; } + + public string Description { get; set; } + + public int? Type { get; set; } + + public int? Status { get; set; } + + } + + /// + /// 工艺路线-抛光 库存表输入输出对象 + /// + public class WmPolishInventoryDto + { + public string Id { get; set; } + + public string BlankNum { get; set; } + + public string Partnumber { get; set; } + + public string Color { get; set; } + + public string Specification { get; set; } + + public string Description { get; set; } + + public int? Quantity { get; set; } + + public int? MaxNum { get; set; } + + public int? MinNum { get; set; } + + public int? WarnNum { get; set; } + + public int? Type { get; set; } + + public int? Status { get; set; } + + public string Remark { get; set; } + + public DateTime? ActionTime { get; set; } + + public string CreatedBy { get; set; } + + public DateTime? CreatedTime { get; set; } + + public string UpdatedBy { get; set; } + + public DateTime? UpdatedTime { get; set; } + + + + } +} \ No newline at end of file diff --git a/ZR.Model/MES/wms/Dto/WmPolishRecordDto.cs b/ZR.Model/MES/wms/Dto/WmPolishRecordDto.cs new file mode 100644 index 00000000..8b507951 --- /dev/null +++ b/ZR.Model/MES/wms/Dto/WmPolishRecordDto.cs @@ -0,0 +1,50 @@ +using System.ComponentModel.DataAnnotations; + +namespace ZR.Model.MES.wms.Dto +{ + /// + /// 工艺路线-抛光 库存变动表查询对象 + /// + public class WmPolishRecordQueryDto : PagerInfo + { + } + + /// + /// 工艺路线-抛光 库存变动表输入输出对象 + /// + public class WmPolishRecordDto + { + [Required(ErrorMessage = "主键不能为空")] + public string Id { get; set; } + + [Required(ErrorMessage = "库存主键不能为空")] + public string FkInventoryId { get; set; } + + public string Code { get; set; } + + public string Partnumber { get; set; } + + public string BlankNum { get; set; } + + public int? ChangeType { get; set; } + + public int? ChangeQuantity { get; set; } + + public DateTime? ActionTime { get; set; } + + public int? Status { get; set; } + + public string Remark { get; set; } + + public string CreatedBy { get; set; } + + public DateTime? CreatedTime { get; set; } + + public string UpdatedBy { get; set; } + + public DateTime? UpdatedTime { get; set; } + + + + } +} \ No newline at end of file diff --git a/ZR.Model/MES/wms/WmPolishInventory.cs b/ZR.Model/MES/wms/WmPolishInventory.cs new file mode 100644 index 00000000..f94b10d1 --- /dev/null +++ b/ZR.Model/MES/wms/WmPolishInventory.cs @@ -0,0 +1,96 @@ + +namespace ZR.Model.MES.wms +{ + /// + /// 工艺路线-抛光 库存表 + /// + [SugarTable("wm_polish_inventory")] + public class WmPolishInventory + { + /// + /// 主键 + /// + [SugarColumn(IsPrimaryKey = true, IsIdentity = false)] + public string Id { get; set; } + + /// + /// 毛坯号 + /// + [SugarColumn(ColumnName = "blank_num")] + public string BlankNum { get; set; } + + /// + /// 零件号 + /// + public string Partnumber { get; set; } + + /// + /// 库存数量 + /// + public int? Quantity { get; set; } + + /// + /// 最大库存 + /// + [SugarColumn(ColumnName = "max_num")] + public int? MaxNum { get; set; } + + /// + /// 最小库存 + /// + [SugarColumn(ColumnName = "min_num")] + public int? MinNum { get; set; } + + /// + /// 预警库存 + /// + [SugarColumn(ColumnName = "warn_num")] + public int? WarnNum { get; set; } + + /// + /// 类别(1-正常 2-返工件) + /// + public int? Type { get; set; } + + /// + /// 状态(0-停用1-启用) + /// + public int? Status { get; set; } + + /// + /// 备注 + /// + public string Remark { get; set; } + + /// + /// 操作时间 + /// + [SugarColumn(IsIgnore = true)] + public DateTime? ActionTime { get; set; } + + /// + /// 创建人 + /// + [SugarColumn(ColumnName = "cREATED_BY")] + public string CreatedBy { get; set; } + + /// + /// 创建时间 + /// + [SugarColumn(ColumnName = "cREATED_TIME")] + public DateTime? CreatedTime { get; set; } + + /// + /// 更新人 + /// + [SugarColumn(ColumnName = "uPDATED_BY")] + public string UpdatedBy { get; set; } + + /// + /// 更新时间 + /// + [SugarColumn(ColumnName = "uPDATED_TIME")] + public DateTime? UpdatedTime { get; set; } + + } +} \ No newline at end of file diff --git a/ZR.Model/MES/wms/WmPolishRecord.cs b/ZR.Model/MES/wms/WmPolishRecord.cs new file mode 100644 index 00000000..35ecc637 --- /dev/null +++ b/ZR.Model/MES/wms/WmPolishRecord.cs @@ -0,0 +1,91 @@ + +namespace ZR.Model.MES.wms +{ + /// + /// 工艺路线-抛光 库存变动表 + /// + [SugarTable("wm_polish_record")] + public class WmPolishRecord + { + /// + /// 主键 + /// + [SugarColumn(IsPrimaryKey = true, IsIdentity = false)] + public string Id { get; set; } + + /// + /// 库存主键 + /// + [SugarColumn(IsPrimaryKey = true, IsIdentity = false, ColumnName = "fk_inventory_id")] + public string FkInventoryId { get; set; } + + /// + /// 关联记录字段(4-检验时使用 group by字段) + /// + public string Code { get; set; } + + /// + /// 零件号 + /// + public string Partnumber { get; set; } + + /// + /// 毛坯号 + /// + [SugarColumn(ColumnName = "blank_num")] + public string BlankNum { get; set; } + + /// + /// 变动类别 1-入库 2-出库 3-盘点 4-检验 + /// + [SugarColumn(ColumnName = "change_type")] + public int? ChangeType { get; set; } + + /// + /// 变动数量 + /// + [SugarColumn(ColumnName = "change_quantity")] + public int? ChangeQuantity { get; set; } + + /// + /// 时间(操作时间) + /// + [SugarColumn(ColumnName = "action_time")] + public DateTime? ActionTime { get; set; } + + /// + /// 状态(暂定) + /// + public int? Status { get; set; } + + /// + /// 备注 + /// + public string Remark { get; set; } + + /// + /// 创建人 + /// + [SugarColumn(ColumnName = "cREATED_BY")] + public string CreatedBy { get; set; } + + /// + /// 创建时间 + /// + [SugarColumn(ColumnName = "cREATED_TIME")] + public DateTime? CreatedTime { get; set; } + + /// + /// 更新人 + /// + [SugarColumn(ColumnName = "uPDATED_BY")] + public string UpdatedBy { get; set; } + + /// + /// 更新时间 + /// + [SugarColumn(ColumnName = "uPDATED_TIME")] + public DateTime? UpdatedTime { get; set; } + + } +} \ No newline at end of file diff --git a/ZR.Service/mes/wms/IService/IWmPolishInventoryService.cs b/ZR.Service/mes/wms/IService/IWmPolishInventoryService.cs new file mode 100644 index 00000000..347ddc1d --- /dev/null +++ b/ZR.Service/mes/wms/IService/IWmPolishInventoryService.cs @@ -0,0 +1,40 @@ +using ZR.Model; +using ZR.Model.MES.wms; +using ZR.Model.MES.wms.Dto; + +namespace ZR.Service.mes.wms.IService +{ + /// + /// 工艺路线-抛光 库存表service接口 + /// + public interface IWmPolishInventoryService : IBaseService + { + PagedInfo GetList(WmPolishInventoryQueryDto parm); + + WmPolishInventory GetInfo(string Id); + + WmPolishInventory AddWmPolishInventory(WmPolishInventory parm); + + int UpdateWmPolishInventory(WmPolishInventory parm); + + /// + /// 抛光库,物料下拉菜单获取下拉选项 + /// + /// + /// + public List GetMaterialSelectOption(string partnumber); + /// + /// 抛光零件入库 + /// + /// + /// + int DoWmPolishWarehousing(WmPolishInventory parm); + + /// + /// 抛光零件盘点 + /// + /// + /// + int DoWmPolishStocktaking(WmPolishInventory parm); + } +} diff --git a/ZR.Service/mes/wms/IService/IWmPolishRecordService.cs b/ZR.Service/mes/wms/IService/IWmPolishRecordService.cs new file mode 100644 index 00000000..34d5cf18 --- /dev/null +++ b/ZR.Service/mes/wms/IService/IWmPolishRecordService.cs @@ -0,0 +1,20 @@ +using ZR.Model; +using ZR.Model.MES.wms; +using ZR.Model.MES.wms.Dto; + +namespace ZR.Service.mes.wms.IService +{ + /// + /// 工艺路线-抛光 库存变动表service接口 + /// + public interface IWmPolishRecordService : IBaseService + { + PagedInfo GetList(WmPolishRecordQueryDto parm); + + WmPolishRecord GetInfo(string Id); + + WmPolishRecord AddWmPolishRecord(WmPolishRecord parm); + + int UpdateWmPolishRecord(WmPolishRecord parm); + } +} diff --git a/ZR.Service/mes/wms/WmBlankInventoryService.cs b/ZR.Service/mes/wms/WmBlankInventoryService.cs index 89b88d9f..e535f1a9 100644 --- a/ZR.Service/mes/wms/WmBlankInventoryService.cs +++ b/ZR.Service/mes/wms/WmBlankInventoryService.cs @@ -48,6 +48,7 @@ namespace ZR.Service.mes.wms .Queryable() .Where(it => it.BlankNum == item.BlankNum) .Where(it => it.Type == 2) + .Where(it => it.Status == 1) .First(); if (material == null) { diff --git a/ZR.Service/mes/wms/WmPolishInventoryService.cs b/ZR.Service/mes/wms/WmPolishInventoryService.cs new file mode 100644 index 00000000..ba3c0219 --- /dev/null +++ b/ZR.Service/mes/wms/WmPolishInventoryService.cs @@ -0,0 +1,355 @@ +using System; +using Aliyun.OSS; +using Infrastructure.Attribute; +using SqlSugar; +using ZR.Model; +using ZR.Model.MES.wms; +using ZR.Model.MES.wms.Dto; +using ZR.Repository; +using ZR.Service.mes.wms.IService; + +namespace ZR.Service.mes.wms +{ + /// + /// 工艺路线-抛光 库存表Service业务层处理 + /// + [AppService( + ServiceType = typeof(IWmPolishInventoryService), + ServiceLifetime = LifeTime.Transient + )] + public class WmPolishInventoryService + : BaseService, + IWmPolishInventoryService + { + /// + /// 查询工艺路线-抛光 库存表列表 + /// + /// + /// + public PagedInfo GetList(WmPolishInventoryQueryDto parm) + { + List partnumberByDescription = new(); + if (parm != null && !string.IsNullOrEmpty(parm.Description)) + { + partnumberByDescription = Context + .Queryable() + .Where(it => it.Description.Contains(parm.Description)) + .Select(it => it.Partnumber) + .ToList(); + } + var predicate = Expressionable + .Create() + .AndIF( + !string.IsNullOrEmpty(parm.Description), + it => partnumberByDescription.Contains(it.Partnumber) + ) + .AndIF( + !string.IsNullOrEmpty(parm.Partnumber), + it => it.Partnumber.Contains(parm.Partnumber) + ) + .AndIF(parm.Status > -1, it => it.Status == parm.Status) + .AndIF(parm.Type > 0, it => it.Type == parm.Type); + + var response = Queryable() + .Where(predicate.ToExpression()) + .OrderByDescending(it => it.UpdatedTime) + .ToPage(parm); + if (response.Result.Count > 0) + { + foreach (WmPolishInventoryDto item in response.Result) + { + WmMaterial material = Context + .Queryable() + .Where(it => it.Partnumber == item.Partnumber) + .Where(it => it.Type == 1) + .Where(it => it.Status == 1) + .First(); + if (material == null) + { + item.Description = "此毛坯号不在物料清单内!"; + continue; + } + item.Color = material.Color; + item.Specification = material.Specification; + item.Description = !string.IsNullOrEmpty(material.Description) + ? material.Description + : material.ProductName; + } + } + return response; + } + + /// + /// 获取详情 + /// + /// + /// + public WmPolishInventory GetInfo(string Id) + { + var response = Queryable().Where(x => x.Id == Id).First(); + + return response; + } + + /// + /// 添加工艺路线-抛光 库存表 + /// + /// + /// + public WmPolishInventory AddWmPolishInventory(WmPolishInventory model) + { + return Context.Insertable(model).ExecuteReturnEntity(); + } + + /// + /// 修改工艺路线-抛光 库存表 + /// + /// + /// + public int UpdateWmPolishInventory(WmPolishInventory model) + { + //var response = Update(w => w.Id == model.Id, it => new WmPolishInventory() + //{ + // BlankNum = model.BlankNum, + // Partnumber = model.Partnumber, + // Quantity = model.Quantity, + // MaxNum = model.MaxNum, + // MinNum = model.MinNum, + // WarnNum = model.WarnNum, + // Type = model.Type, + // Status = model.Status, + // Remark = model.Remark, + // CreatedBy = model.CreatedBy, + // CreatedTime = model.CreatedTime, + // UpdatedBy = model.UpdatedBy, + // UpdatedTime = model.UpdatedTime, + //}); + //return response; + return Update(model, true); + } + + /// + /// 零件号下拉查询 + /// + /// 零件号或描述 + /// + public List GetMaterialSelectOption(string query) + { + var predicate = Expressionable + .Create() + .Or(it => it.Partnumber.Contains(query)) + .Or(it => it.Description.Contains(query)) + .Or(it => it.ProductName.Contains(query)) + .And(it => it.Type == 1) + .And(it => it.Status == 1); + List options = Context + .Queryable() + .Where(predicate.ToExpression()) + .Select( + (it) => + new WmMaterialSelectOptions + { + Key = it.Id, + Label = "[ " + it.Partnumber + " ] " + it.Description, + Value = it.Partnumber + } + ) + .ToList(); + return options; + } + + /// + /// 新增抛光仓库操作记录 + /// + /// 抛光仓库主键 + /// 同批功能识别编号 + /// 零件号 + /// 类别 + /// 操作数字 + /// 备注 + /// 创建人 + /// + public int AddPolishRecord( + string fkInventoryId, + string code, + string partnumber, + int type, + int? changeQuantity, + DateTime? actionTime, + string remark, + string createdBy + ) + { + WmPolishRecord newPolishRecord = + new() + { + Id = SnowFlakeSingle.Instance.NextId().ToString(), + FkInventoryId = fkInventoryId, + Code = code, + Partnumber = partnumber, + BlankNum = "", + ChangeType = type, + ChangeQuantity = changeQuantity ?? 0, + ActionTime = actionTime, + Status = 1, + Remark = remark, + CreatedBy = createdBy, + CreatedTime = DateTime.Now.ToLocalTime(), + UpdatedBy = createdBy, + UpdatedTime = DateTime.Now.ToLocalTime(), + }; + + return Context.Insertable(newPolishRecord).ExecuteCommand(); + } + + public int DoWmPolishWarehousing(WmPolishInventory parm) + { + try + { + Context.Ado.BeginTran(); + // 零件号检查 + string partnumber = parm.Partnumber; + WmMaterial material = Context + .Queryable() + .Where(it => it.Partnumber == partnumber) + .Where(it => it.Type == 1) + .Where(it => it.Status == 1) + .First(); + if (material == null) + { + Context.Ado.RollbackTran(); + throw new Exception("零件号在物料清单未查到,请到物料清单新增零件号记录"); + } + // 检查是否存在库中 + WmPolishInventory polishInventory = Context + .Queryable() + .Where(it => it.Partnumber == partnumber) + .Where(it => it.Type == parm.Type) + .Where(it => it.Status == 1) + .First(); + if (polishInventory == null) + { + // 为空则新增库 + WmPolishInventory newWmPolishInventory = + new() + { + Id = SnowFlakeSingle.Instance.NextId().ToString(), + BlankNum = "", + Partnumber = partnumber, + Type = parm.Type, + Quantity = parm.Quantity, + MaxNum = 0, + MinNum = 0, + WarnNum = 0, + Status = 1, + Remark = "系统自动创建库", + CreatedBy = parm.CreatedBy, + CreatedTime = DateTime.Now.ToLocalTime(), + UpdatedBy = parm.CreatedBy, + UpdatedTime = DateTime.Now.ToLocalTime(), + }; + WmPolishInventory addWmPolishInventory = Context + .Insertable(newWmPolishInventory) + .ExecuteReturnEntity(); + string code = SnowFlakeSingle.Instance.NextId().ToString(); + string remark = "初次创建仓库,新增手动入库数据"; + int successNum = AddPolishRecord( + addWmPolishInventory.Id, + code, + partnumber, + 1, + parm.Quantity, + parm.ActionTime, + remark, + parm.CreatedBy + ); + if (successNum == 0) + { + Context.Ado.RollbackTran(); + throw new Exception("入库日志添加失败"); + } + } + else + { + polishInventory.Quantity += parm.Quantity; + int updateNum = Context.Updateable(polishInventory).ExecuteCommand(); + if (updateNum == 0) + { + Context.Ado.RollbackTran(); + throw new Exception("修改抛光仓库数据失败"); + } + // 已有则新增记录 + string code = SnowFlakeSingle.Instance.NextId().ToString(); + string remark = "手动入库"; + int successNum = AddPolishRecord( + polishInventory.Id, + code, + partnumber, + 1, + parm.Quantity, + parm.ActionTime, + remark, + parm.CreatedBy + ); + if (successNum == 0) + { + Context.Ado.RollbackTran(); + throw new Exception("入库日志添加失败"); + } + } + Context.Ado.CommitTran(); + return 1; + } + catch (Exception e) + { + Context.Ado.RollbackTran(); + throw new Exception(e.Message); + } + } + + public int DoWmPolishStocktaking(WmPolishInventory parm) + { + if (parm.Quantity < 0) + { + throw new Exception("修改的零件数小于0"); + } + try + { + Context.Ado.BeginTran(); + // 检查是否存在库中 + WmPolishInventory polishInventory = Context + .Queryable() + .Where(it => it.Id == parm.Id) + .Where(it => it.Status == 1) + .First(); + polishInventory.Quantity = parm.Quantity; + Context.Updateable(parm).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand(); + // 已有则新增记录 + string code = SnowFlakeSingle.Instance.NextId().ToString(); + string remark = "手动盘点"; + int successNum = AddPolishRecord( + parm.Id, + code, + parm.Partnumber, + 3, + parm.Quantity, + parm.ActionTime, + remark, + parm.CreatedBy + ); + if (successNum == 0) + { + Context.Ado.RollbackTran(); + throw new Exception("盘点日志添加失败"); + } + Context.Ado.CommitTran(); + return successNum; + } + catch (Exception e) + { + Context.Ado.RollbackTran(); + throw new Exception(e.Message); + } + } + } +} diff --git a/ZR.Service/mes/wms/WmPolishRecordService.cs b/ZR.Service/mes/wms/WmPolishRecordService.cs new file mode 100644 index 00000000..fab1970b --- /dev/null +++ b/ZR.Service/mes/wms/WmPolishRecordService.cs @@ -0,0 +1,81 @@ +using Infrastructure.Attribute; +using SqlSugar; +using ZR.Model; +using ZR.Model.MES.wms; +using ZR.Model.MES.wms.Dto; +using ZR.Repository; +using ZR.Service.mes.wms.IService; + +namespace ZR.Service.mes.wms +{ + /// + /// 工艺路线-抛光 库存变动表Service业务层处理 + /// + [AppService(ServiceType = typeof(IWmPolishRecordService), ServiceLifetime = LifeTime.Transient)] + public class WmPolishRecordService : BaseService, IWmPolishRecordService + { + /// + /// 查询工艺路线-抛光 库存变动表列表 + /// + /// + /// + public PagedInfo GetList(WmPolishRecordQueryDto parm) + { + var predicate = Expressionable.Create(); + + var response = Queryable() + .Where(predicate.ToExpression()) + .ToPage(parm); + + return response; + } + + /// + /// 获取详情 + /// + /// + /// + public WmPolishRecord GetInfo(string Id) + { + var response = Queryable().Where(x => x.Id == Id).First(); + + return response; + } + + /// + /// 添加工艺路线-抛光 库存变动表 + /// + /// + /// + public WmPolishRecord AddWmPolishRecord(WmPolishRecord model) + { + return Context.Insertable(model).ExecuteReturnEntity(); + } + + /// + /// 修改工艺路线-抛光 库存变动表 + /// + /// + /// + public int UpdateWmPolishRecord(WmPolishRecord model) + { + //var response = Update(w => w.Id == model.Id, it => new WmPolishRecord() + //{ + // Code = model.Code, + // Partnumber = model.Partnumber, + // BlankNum = model.BlankNum, + // ChangeType = model.ChangeType, + // ChangeQuantity = model.ChangeQuantity, + // ActionTime = model.ActionTime, + // Status = model.Status, + // Remark = model.Remark, + // CreatedBy = model.CreatedBy, + // CreatedTime = model.CreatedTime, + // UpdatedBy = model.UpdatedBy, + // UpdatedTime = model.UpdatedTime, + //}); + //return response; + return Update(model, true); + } + } +}