Browse Source

1、物资进销存 --> CRUD( 物品信息表、入库表、领用表),等相关接口代码编写

LEIYI 6 months ago
parent
commit
081d6ad3f0

+ 1 - 1
OASystem/EntitySync/Program.cs

@@ -142,7 +142,7 @@ db.CodeFirst.SetStringDefaultLength(50).BackupTable().InitTables(new Type[]
     //typeof(Grp_VisaCommission),//签证费用录入 
     typeof(Pm_GoodsReceive),//物品领用表 
     typeof(Pm_GoodsStorage),//物品入库表 
-    typeof(Pm_GoodsInfo),//物品详细表 
+    //typeof(Pm_GoodsInfo),//物品详细表 
 
 });
 Console.WriteLine("数据库结构同步完成!");

+ 1 - 1
OASystem/OASystem.Api/Controllers/FinancialController.cs

@@ -5874,7 +5874,7 @@ Group by PriceType ", dto.diId);
                                                 x.VisitDate >= _beginDt &&
                                                 x.VisitDate <= _endDt
                                              )
-                                       .WhereIF(!string.IsNullOrEmpty(teamName), x => x.TeamName.Equals(teamName))
+                                       .WhereIF(!string.IsNullOrEmpty(teamName), x => x.TeamName.Contains(teamName))
                                        .ToList();
             var _groupIds = _groupDatas.Select(x => x.Id).ToList();
             if (_groupIds.Count < 1)

+ 126 - 6
OASystem/OASystem.Api/Controllers/PersonnelModuleController.cs

@@ -1,6 +1,8 @@
 using Aliyun.Credentials.Utils;
 using Aspose.Cells;
+using FluentValidation;
 using Microsoft.AspNetCore.SignalR;
+using Microsoft.IdentityModel.Tokens;
 using NPOI.POIFS.Crypt.Dsig;
 using OASystem.API.OAMethodLib;
 using OASystem.API.OAMethodLib.Hub.HubClients;
@@ -1786,7 +1788,7 @@ namespace OASystem.API.Controllers
 
         /// <summary>
         /// 物资进销存
-        /// 物品列表
+        /// 物品 列表
         /// </summary>
         /// <returns></returns>
         [HttpPost]
@@ -1801,7 +1803,7 @@ namespace OASystem.API.Controllers
 
         /// <summary>
         /// 物资进销存
-        /// 物品详情
+        /// 物品 详情
         /// </summary>
         /// <returns></returns>
         [HttpGet]
@@ -1837,7 +1839,22 @@ namespace OASystem.API.Controllers
 
         /// <summary>
         /// 物资进销存
-        /// 物品入库列表
+        /// 物品 Del
+        /// </summary>
+        /// <returns></returns>
+        [HttpDelete("{id}")]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> GoodsDel(int id,[FromQuery] int currUserId)
+        {
+            if (id < 1) return Ok(JsonView(false, MsgTips.Id));
+            if (currUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
+
+            return Ok(await _goodsRep.GoodsDel(id,currUserId));
+        }
+
+        /// <summary>
+        /// 物资进销存
+        /// 入库 列表
         /// </summary>
         /// <returns></returns>
         [HttpPost]
@@ -1852,7 +1869,7 @@ namespace OASystem.API.Controllers
 
         /// <summary>
         /// 物资进销存
-        /// 物品入库详情
+        /// 入库 详情
         /// </summary>
         /// <returns></returns>
         [HttpGet]
@@ -1867,7 +1884,43 @@ namespace OASystem.API.Controllers
 
         /// <summary>
         /// 物资进销存
-        /// 物品领用列表
+        /// 入库 OP(Add OR Edit)
+        /// </summary>
+        /// <returns></returns>
+        [HttpPost]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> GoodsStorageOP(GoodsStorageOPDTO _dto)
+        {
+            var vadalitor = new GoodsStorageOPDTOValidator();
+            var vadalitorRes = await vadalitor.ValidateAsync(_dto);
+            if (!vadalitorRes.IsValid)
+            {
+                var sb = new StringBuilder();
+                foreach (var error in vadalitorRes.Errors) sb.AppendLine(error.ErrorMessage);
+                return Ok(JsonView(false, sb.ToString()));
+            }
+
+            return Ok(await _goodsRep.GoodsStorageOP(_dto));
+        }
+
+        /// <summary>
+        /// 物资进销存
+        /// 入库 Del
+        /// </summary>
+        /// <returns></returns>
+        [HttpDelete("{id}")]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> GoodsStorageDel(int id, [FromQuery] int currUserId)
+        {
+            if (id < 1) return Ok(JsonView(false, MsgTips.Id));
+            if (currUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
+
+            return Ok(await _goodsRep.GoodsStorageDel(id,currUserId));
+        }
+
+        /// <summary>
+        /// 物资进销存
+        /// 领用 List
         /// </summary>
         /// <returns></returns>
         [HttpPost]
@@ -1882,7 +1935,7 @@ namespace OASystem.API.Controllers
 
         /// <summary>
         /// 物资进销存
-        /// 物品领用详情
+        /// 领用详情
         /// </summary>
         /// <returns></returns>
         [HttpGet]
@@ -1894,6 +1947,73 @@ namespace OASystem.API.Controllers
 
             return Ok(await _goodsRep.GoodsReceiveInfo(portType, id));
         }
+
+        /// <summary>
+        /// 物资进销存
+        /// 领用 OP
+        /// </summary>
+        /// <returns></returns>
+        [HttpPost]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> GoodsReceiveOP(GoodsReceiveOPDTO _dto)
+        {
+            var vadalitor = new GoodsReceiveOPDTOValidator();
+            var vadalitorRes = await vadalitor.ValidateAsync(_dto);
+            if (!vadalitorRes.IsValid)
+            {
+                var sb = new StringBuilder();
+                foreach (var error in vadalitorRes.Errors) sb.AppendLine(error.ErrorMessage);
+                return Ok(JsonView(false, sb.ToString()));
+            }
+
+            return Ok(await _goodsRep.GoodsReceiveOP(_dto));
+        }
+
+        /// <summary>
+        /// 物资进销存
+        /// 领用 审核
+        /// </summary>
+        /// <param name="_dto"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> GoodsReceiveAudit(GoodsReceiveAuditDTO _dto)
+        {
+            var vadalitor = new GoodsReceiveAuditDTOValidator();
+            var vadalitorRes = await vadalitor.ValidateAsync(_dto);
+            if (!vadalitorRes.IsValid)
+            {
+                var sb = new StringBuilder();
+                foreach (var error in vadalitorRes.Errors) sb.AppendLine(error.ErrorMessage);
+                return Ok(JsonView(false, sb.ToString()));
+            }
+            int[] idArray = _dto.Label
+                                .Split(',')
+                                .Select(x => 
+                                {
+                                    int id;
+                                    if (int.TryParse(x, out id)) return id;
+                                    else return id;
+                                })
+                                .ToArray();
+            return Ok(await _goodsRep.GoodsReceiveAudit(idArray,_dto.CurrUserId,_dto.AuditEnum));
+        }
+        
+
+        /// <summary>
+        /// 物资进销存
+        /// 领用 Del
+        /// </summary>
+        /// <returns></returns>
+        [HttpDelete("{id}")]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> GoodsReceiveDel(int id, [FromQuery] int currUserId)
+        {
+            if (id < 1) return Ok(JsonView(false, MsgTips.Id));
+            if (currUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
+
+            return Ok(await _goodsRep.GoodsReceiveDel(id, currUserId));
+        }
         #endregion
     }
 }

+ 6 - 0
OASystem/OASystem.Domain/AutoMappers/_baseMappingProfile.cs

@@ -174,6 +174,7 @@ namespace OASystem.Domain.AutoMappers
             #endregion
 
             #endregion
+
             #region Resource
 
             #region 车公司资料
@@ -274,6 +275,11 @@ namespace OASystem.Domain.AutoMappers
             CreateMap<WageSheetMonthWorkdaysAddOrEditDto, Pm_WageIssueWorkingDay>();
             CreateMap<CalendarInfoView, Sys_Calendar>();
             CreateMap<TaskAllocationAddOrEditDto, Pm_TaskAllocation>();
+
+            #region 进销存
+            CreateMap<GoodsStorageOPDTO, Pm_GoodsStorage>();
+            CreateMap<GoodsReceiveOPDTO, Pm_GoodsReceive>();
+            #endregion
             #endregion
 
             #region 倒推表

+ 186 - 5
OASystem/OASystem.Domain/Dtos/PersonnelModule/GoodsDTO.cs

@@ -1,4 +1,5 @@
 using FluentValidation;
+using OASystem.Domain.Enums;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -84,6 +85,7 @@ namespace OASystem.Domain.Dtos.PersonnelModule
     #endregion
 
 
+    #region 物品入库 DTO
 
     /// <summary>
     /// 物品入库List DTO
@@ -96,6 +98,94 @@ namespace OASystem.Domain.Dtos.PersonnelModule
         public int GoodsId { get; set; }
     }
 
+    /// <summary>
+    /// 物品入库 操作(Create Or Edit)
+    /// </summary>
+    public class GoodsStorageOPDTO
+    {
+        /// <summary>
+        /// 当前用户id
+        /// </summary>
+        public int CurrUserId { get; set; }
+
+        /// <summary>
+        /// ID编号
+        /// ID > 0 Edit
+        /// ID < 1 Add
+        /// </summary>
+        public int Id { get; set; }
+
+        /// <summary>
+        /// 商品Id
+        /// </summary>
+        public int GoodsId { get; set; }
+
+        /// <summary>
+        /// 此次入库数量
+        /// </summary>
+        public decimal Quantity { get; set; }
+
+        /// <summary>
+        /// 此次物品单价
+        /// </summary>
+        public decimal UnitPrice { get; set; }
+
+        /// <summary>
+        /// 此次物品总价
+        /// </summary>
+        public decimal TotalPrice { get; set; }
+
+        /// <summary>
+        /// 此次供应商名称
+        /// </summary>
+        public string? SupplierName { get; set; }
+
+        /// <summary>
+        /// 此次供应商电话
+        /// </summary>
+        public string? SupplierTel { get; set; }
+
+        /// <summary>
+        /// 此次供应商地址
+        /// </summary>
+        public string? SupplierAddress { get; set; }
+
+        /// <summary>
+        /// 此次供应商来源
+        /// </summary>
+        public string? SupplierSource { get; set; }
+
+        /// <summary>
+        /// 备注
+        /// </summary>
+        public string Remark { get; set; }
+
+    }
+
+    /// <summary>
+    /// 物品入库 操作(Create Or Edit) 
+    /// Validator
+    /// </summary>
+    public class GoodsStorageOPDTOValidator : AbstractValidator<GoodsStorageOPDTO>
+    {
+        /// <summary>
+        /// 初始化
+        /// </summary>
+        public GoodsStorageOPDTOValidator()
+        {
+            RuleFor(x => x.CurrUserId).Must(x => x > 0).WithMessage("请传入当前登陆用户ID!");
+            RuleFor(x => x.GoodsId).Must(x => x > 0).WithMessage("请传入有效的物品Id!");
+            RuleFor(x => x.Quantity).Must(x => x > 0).WithMessage("请传入有效的物品数量!");
+            RuleFor(x => x.UnitPrice).Must(x => x > 0).WithMessage("请传入有效的物品单价!");
+            RuleFor(x => x.TotalPrice).Must(x => x > 0).WithMessage("请传入有效的物品价格合计!");
+        }
+    }
+
+
+
+    #endregion
+
+    #region 物品领用
     /// <summary>
     /// 物品领用List DTO
     /// </summary>
@@ -106,22 +196,113 @@ namespace OASystem.Domain.Dtos.PersonnelModule
         /// 物品Id
         /// </summary>
         public int GoodsId { get; set; }
+
+        /// <summary>
+        /// 当前登录UserId
+        /// </summary>
+        public int CurrUserId { get; set; }
     }
 
     /// <summary>
-    /// 物品入库 操作(Create Or Edit) DTO
+    /// 物品领用 OP DTO
     /// </summary>
-    public class GoodsStorageOPDTO
+    public class GoodsReceiveOPDTO
     {
+        public int CurrUserId { get; set; }
+
         /// <summary>
-        /// 物品Id
+        /// ID
+        /// Id > 0 修改
+        /// Id < 1 添加
+        /// </summary>
+        public int Id { get; set; }
+
+        /// <summary>
+        /// 团组Id
+        /// Grp_DelegationInfo Id
+        /// </summary>
+        public int GroupId { get; set; }
+
+        /// <summary>
+        /// 商品Id
+        /// Pm_GoodsInfo Id
         /// </summary>
         public int GoodsId { get; set; }
 
         /// <summary>
-        /// 物品名称
+        /// 领用数量
         /// </summary>
-        public string GoodsName { get; set; }
+        public decimal Quantity { get; set; }
+
+        /// <summary>
+        /// 领用原因
+        /// </summary>
+        public string? Reason { get; set; }
+
+        /// <summary>
+        /// 备注
+        /// </summary>
+        public string? Remark { get; set; }
     }
 
+    /// <summary>
+    /// 物品领用 OP
+    /// Validator
+    /// </summary>
+    public class GoodsReceiveOPDTOValidator : AbstractValidator<GoodsReceiveOPDTO>
+    {
+        /// <summary>
+        /// 初始化
+        /// </summary>
+        public GoodsReceiveOPDTOValidator()
+        {
+            RuleFor(x => x.CurrUserId).Must(x => x > 0).WithMessage("请传入当前登陆用户ID!");
+            RuleFor(x => x.GoodsId).Must(x => x > 0).WithMessage("请传入有效的物品Id!");
+            RuleFor(x => x.Quantity).Must(x => x > 0).WithMessage("请传入有效的物品数量!");
+            RuleFor(x => x.Reason).NotEmpty().WithMessage("请填写领用原由!");
+        }
+    }
+
+    /// <summary>
+    /// 物品领用 Audit DTO
+    /// </summary>
+    public class GoodsReceiveAuditDTO
+    {
+        /// <summary>
+        /// 数据ID string
+        /// 1,2,3,4
+        /// </summary>
+        public string Label { get; set; }
+
+        /// <summary>
+        /// 用户Id
+        /// </summary>
+        public int CurrUserId { get; set; }
+
+        /// <summary>
+        /// 审核状态
+        /// </summary>
+        public GoodsAuditEnum AuditEnum { get; set; }
+    }
+
+    /// <summary>
+    /// 物品领用 Audit
+    /// Validator
+    /// </summary>
+    public class GoodsReceiveAuditDTOValidator : AbstractValidator<GoodsReceiveAuditDTO>
+    {
+        /// <summary>
+        /// 初始化
+        /// </summary>
+        public GoodsReceiveAuditDTOValidator()
+        {
+            RuleFor(x => x.CurrUserId).Must(x => x > 0).WithMessage("请传入当前登陆用户ID!");
+            RuleFor(x => x.Label).NotEmpty().WithMessage("数据ID字符串为空!");
+        }
+    }
+    #endregion
+
+
+
+
 }

+ 1 - 14
OASystem/OASystem.Domain/Entities/PersonnelModule/Pm_GoodsReceive.cs

@@ -37,22 +37,9 @@ namespace OASystem.Domain.Entities.PersonnelModule
         /// <summary>
         /// 领用原因
         /// </summary>
-        [SugarColumn(ColumnDescription = "申请人Id", IsNullable = true, ColumnDataType = "varchar(200)")]
+        [SugarColumn(ColumnDescription = "领用原因", IsNullable = true, ColumnDataType = "varchar(200)")]
         public string? Reason { get; set; }
 
-        ///// <summary>
-        ///// 申请人Id
-        ///// Sys_User Id
-        ///// </summary>
-        //[SugarColumn(ColumnDescription = "申请人Id", IsNullable = true, ColumnDataType = "int")]
-        //public int ApplicantId { get; set; }
-
-        ///// <summary>
-        ///// 申请人时间
-        ///// </summary>
-        //[SugarColumn(ColumnDescription = "申请人时间", IsNullable = true, ColumnDataType = "datetime")]
-        //public DateTime ApplicantTime { get; set; }
-
         /// <summary>
         /// 审核状态
         /// </summary>

+ 2 - 2
OASystem/OASystem.Domain/Entities/PersonnelModule/Pm_GoodsStorage.cs

@@ -22,7 +22,7 @@ namespace OASystem.Domain.Entities.PersonnelModule
         /// <summary>
         /// 此次入库数量
         /// </summary>
-        [SugarColumn(ColumnDescription = "此次入库数量", IsNullable = true, ColumnDataType = "decimal(8,2)")]
+        [SugarColumn(ColumnDescription = "此次入库数量", IsNullable = true, ColumnDataType = "decimal(10,2)")]
         public decimal Quantity { get; set; }
 
         /// <summary>
@@ -46,7 +46,7 @@ namespace OASystem.Domain.Entities.PersonnelModule
         /// <summary>
         /// 此次供应商电话
         /// </summary>
-        [SugarColumn(ColumnDescription = "此次供应商电话", IsNullable = true, ColumnDataType = "varchar(20)")]
+        [SugarColumn(ColumnDescription = "此次供应商电话", IsNullable = true, ColumnDataType = "varchar(30)")]
         public string? SupplierTel { get; set; }
 
         /// <summary>

+ 5 - 5
OASystem/OASystem.Domain/Enums/GoodsAuditEnum.cs

@@ -13,19 +13,19 @@ namespace OASystem.Domain.Enums
     public enum GoodsAuditEnum :int
     {
         /// <summary>
-        /// 待审核
+        /// 待审核
         /// </summary>
-        [Description("待审核")]
+        [Description("待审核")]
         Pending,
         /// <summary>
         /// 已通过审核
         /// </summary>
-        [Description("已通过")]
+        [Description("已通过审核")]
         Approved,
         /// <summary>
         /// 已拒绝审核
         /// </summary>
-        [Description("已拒绝")]
-        Rejected 
+        [Description("未通过审核")]
+        UnApproved
     }
 }

+ 21 - 0
OASystem/OASystem.Domain/ViewModels/PersonnelModule/GoodsInfoView.cs

@@ -1,4 +1,5 @@
 using OASystem.Domain.Entities.PersonnelModule;
+using OASystem.Domain.Enums;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -55,4 +56,24 @@ namespace OASystem.Domain.ViewModels.PersonnelModule
 
         public int IsDel { get; set; }
     }
+
+
+    public class GoodsReceiveListView
+    {
+        public int Id { get; set; }
+        public int GroupId { get; set; }
+        public int GoodsId { get; set; }
+        public string GoodsName { get; set; }
+        public decimal Quantity { get; set; }
+        public string Reason { get; set; }
+        public string Remark { get; set; }
+        public GoodsAuditEnum AuditStatus { get; set; }
+        public string AuditStatusText { get { return AuditStatus.GetEnumDescription(); } }
+        public int AuditUserId { get; set; }
+        public string AuditUserName { get; set; }
+        public DateTime AuditTime { get; set; }
+        public string CreateUserName { get; set; }
+        public DateTime CreateTime { get; set; }
+
+    }
 }

+ 413 - 55
OASystem/OASystem.Infrastructure/Repositories/PersonnelModule/GoodsRepository.cs

@@ -8,6 +8,8 @@ using System.Threading.Tasks;
 using AutoMapper;
 using OASystem.Domain.Dtos.PersonnelModule;
 using SqlSugar;
+using NPOI.SS.Formula.Functions;
+using OASystem.Domain.Entities.Groups;
 
 namespace OASystem.Infrastructure.Repositories.PersonnelModule
 {
@@ -15,14 +17,14 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
     /// 物品进销存 
     /// 仓储
     /// </summary>
-    public class GoodsRepository:BaseRepository<Pm_GoodsInfo,GoodsInfoView>
+    public class GoodsRepository : BaseRepository<Pm_GoodsInfo, GoodsInfoView>
     {
         private readonly IMapper _mapper;
         private JsonView _jv;
-        public GoodsRepository(SqlSugarClient sqlSugar,IMapper mapper):base(sqlSugar)
+        public GoodsRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
         {
             _mapper = mapper;
-            _jv = new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "无效请求!" };
+            _jv = new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "操作失败!" };
         }
 
         /// <summary>
@@ -49,17 +51,28 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
                                           //})
                                           .ToListAsync();
 
+            var groupData = await _sqlSugar.Queryable<Grp_DelegationInfo>()
+                                           .Where(x => x.IsDel == 0)
+                                           .Select(x => new
+                                           {
+                                               id = x.Id,
+                                               groupName = x.TeamName
+                                           })
+                                           .OrderByDescending(x => x.id)
+                                           .ToListAsync();
+
+
             _jv.Code = StatusCodes.Status200OK;
-            _jv.Data = typeData;
+            _jv.Data = new { goodsTypeData = typeData, groupNameData = groupData };
             _jv.Msg = $"操作成功";
             return _jv;
         }
 
-       /// <summary>
-       /// 物品列表
-       /// </summary>
-       /// <param name="_dto"></param>
-       /// <returns></returns>
+        /// <summary>
+        /// 物品列表
+        /// </summary>
+        /// <param name="_dto"></param>
+        /// <returns></returns>
         public async Task<JsonView> GoodsList(GoodsListDTO _dto)
         {
             var ids = new List<int>();
@@ -109,12 +122,12 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
         /// </summary>
         /// <param name="_dto"></param>
         /// <returns></returns>
-        public async Task<JsonView> GoodsInfo(int portType,int id)
+        public async Task<JsonView> GoodsInfo(int portType, int id)
         {
             var data = await _sqlSugar.Queryable<Pm_GoodsInfo>()
                                       .LeftJoin<Sys_SetData>((gi, sd) => gi.Type == sd.Id)
                                       .LeftJoin<Sys_Users>((gi, sd, u1) => gi.LastUpdateUserId == u1.Id)
-                                      .LeftJoin<Sys_Users>((gi, sd, u1 ,u2) => gi.CreateUserId == u2.Id)
+                                      .LeftJoin<Sys_Users>((gi, sd, u1, u2) => gi.CreateUserId == u2.Id)
                                       .Where((gi, sd, u1, u2) => gi.IsDel == 0 && gi.Id == id)
                                       .Select((gi, sd, u1, u2) => new
                                       {
@@ -176,7 +189,7 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
                                          .ExecuteCommandAsync();
                 if (upd > 0)
                 {
-                    _jv.Msg = $"修改成功!"; 
+                    _jv.Msg = $"修改成功!";
                     _jv.Code = StatusCodes.Status200OK;
                     return _jv;
                 }
@@ -201,6 +214,56 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
             return _jv;
         }
 
+        /// <summary>
+        /// 物品 Del
+        /// </summary>
+        /// <param name="id"></param>
+        /// <param name="currUserId"></param>
+        /// <returns></returns>
+        public async Task<JsonView> GoodsDel(int id, int currUserId)
+        {
+            _sqlSugar.BeginTran();
+
+            var goods = await _sqlSugar.Updateable<Pm_GoodsInfo>()
+                                       .SetColumns(x => new Pm_GoodsInfo()
+                                       {
+                                           IsDel = 1,
+                                           DeleteUserId = currUserId,
+                                           DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
+                                       })
+                                       .Where(x => x.Id == id)
+                                       .ExecuteCommandAsync();
+            if (goods < 1)
+            {
+                _sqlSugar.RollbackTran();
+                _jv.Msg = $"操作失败";
+                return _jv;
+            }
+
+            var goodsStorage = await _sqlSugar.Updateable<Pm_GoodsStorage>()
+                                              .SetColumns(x => new Pm_GoodsStorage()
+                                              {
+                                                  IsDel = 1,
+                                                  DeleteUserId = currUserId,
+                                                  DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
+                                              })
+                                              .Where(x => x.Id == id)
+                                              .ExecuteCommandAsync();
+
+            var goodsReceive = await _sqlSugar.Updateable<Pm_GoodsReceive>()
+                                              .SetColumns(x => new Pm_GoodsReceive()
+                                              {
+                                                  IsDel = 1,
+                                                  DeleteUserId = currUserId,
+                                                  DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
+                                              })
+                                              .Where(x => x.Id == id)
+                                              .ExecuteCommandAsync();
+            _sqlSugar.CommitTran();
+            _jv.Code = StatusCodes.Status200OK;
+            _jv.Msg = $"操作成功!";
+            return _jv;
+        }
 
         /// <summary>
         /// 物品入库列表
@@ -277,40 +340,151 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
             return _jv;
         }
 
-
         /// <summary>
         /// 物品入库 操作(Create Or Edit)
         /// </summary>
         /// <param name="id"></param>
         /// <returns></returns>
-        public async Task<JsonView> GoodsStorageOP(int portType, int id)
+        public async Task<JsonView> GoodsStorageOP(GoodsStorageOPDTO _dto)
         {
-            var data = await _sqlSugar.Queryable<Pm_GoodsStorage>()
-                                      .LeftJoin<Pm_GoodsInfo>((gs, gi) => gs.GoodsId == gi.Id)
-                                      .LeftJoin<Sys_Users>((gs, gi, u) => gs.CreateUserId == u.Id)
-                                      .Where((gs, gi, u) => gs.IsDel == 0)
-                                      .WhereIF(id > 0, (gs, gi, u) => gs.GoodsId == id)
-                                      .Select((gs, gi, u) => new
-                                      {
-                                          gs.Id,
-                                          gs.GoodsId,
-                                          GoodsName = gi.Name,
-                                          gs.Quantity,
-                                          gs.UnitPrice,
-                                          gs.TotalPrice,
-                                          gs.SupplierName,
-                                          gs.SupplierTel,
-                                          gs.SupplierAddress,
-                                          gs.SupplierSource,
-                                          CreateUserName = u.CnName,
-                                          gs.CreateTime,
-                                          gs.Remark
-                                      })
-                                      .FirstAsync();
+            var info = _mapper.Map<Pm_GoodsStorage>(_dto);
+            info.CreateUserId = _dto.CurrUserId;
 
-            _jv.Msg = $"操作成功!";
-            _jv.Code = StatusCodes.Status200OK;
-            _jv.Data = data;
+            decimal editAgoQauntity = 0.00M,
+                    editAgoTotalPrice = 0.00M;
+
+            _sqlSugar.BeginTran();
+            if (info.Id > 0) //修改
+            {
+                var selectInfo = await _sqlSugar.Queryable<Pm_GoodsStorage>()
+                                                .Where(x => x.Id == _dto.Id)
+                                                .FirstAsync();
+                editAgoQauntity = selectInfo.Quantity;
+                editAgoTotalPrice = selectInfo.TotalPrice;
+
+                var stoageEdit = await _sqlSugar.Updateable<Pm_GoodsStorage>(info)
+                                                .UpdateColumns(x => new
+                                                {
+                                                    x.Quantity,
+                                                    x.UnitPrice,
+                                                    x.TotalPrice,
+                                                    x.SupplierName,
+                                                    x.SupplierTel,
+                                                    x.SupplierAddress,
+                                                    x.SupplierSource,
+                                                })
+                                                .Where(x => x.Id == _dto.Id)
+                                                .ExecuteCommandAsync();
+                if (stoageEdit < 1)
+                {
+                    _sqlSugar.RollbackTran();
+                    _jv.Msg = $"修改失败!";
+                    return _jv;
+                }
+            }
+            else if (info.Id < 1) //添加
+            {
+                var stoageAdd = await _sqlSugar.Insertable(info).ExecuteCommandAsync();
+                if (stoageAdd < 1)
+                {
+                    _sqlSugar.RollbackTran();
+                    _jv.Msg = $"添加失败!";
+                    return _jv;
+                }
+            }
+            var goodsInfo = await _sqlSugar.Queryable<Pm_GoodsInfo>().FirstAsync(x => x.Id == info.GoodsId);
+            goodsInfo.SQ_Total = goodsInfo.SQ_Total - editAgoQauntity + info.Quantity;
+            goodsInfo.StockQuantity = goodsInfo.StockQuantity - editAgoQauntity + info.Quantity;
+            goodsInfo.PriceTotal = goodsInfo.PriceTotal - editAgoTotalPrice + info.TotalPrice;
+            goodsInfo.LastUpdateUserId = _dto.CurrUserId;
+            goodsInfo.LastUpdateTime = DateTime.Now;
+
+            var goodsEdit = await _sqlSugar.Updateable(goodsInfo)
+                                           .UpdateColumns(x => new
+                                           {
+                                               x.SQ_Total,
+                                               x.StockQuantity,
+                                               x.PriceTotal,
+                                               x.LastUpdateUserId,
+                                               x.LastUpdateTime,
+                                           })
+                                           .Where(x => x.Id == info.GoodsId)
+                                           .ExecuteCommandAsync();
+            if (goodsEdit > 0)
+            {
+                _sqlSugar.CommitTran();
+                _jv.Msg = $"操作成功!";
+                _jv.Code = StatusCodes.Status200OK;
+                return _jv;
+            }
+
+            _sqlSugar.RollbackTran();
+            _jv.Msg = $"操作失败!";
+            return _jv;
+        }
+
+        /// <summary>
+        /// 物品入库 Del
+        /// </summary>
+        /// <param name="id"></param>
+        /// <returns></returns>
+        public async Task<JsonView> GoodsStorageDel(int id, int userId)
+        {
+            var storageInfo = await _sqlSugar.Queryable<Pm_GoodsStorage>()
+                                                 .Where(x => x.Id == id)
+                                                 .FirstAsync();
+            if (storageInfo == null) return _jv;
+
+            decimal delAgoQauntity = storageInfo.Quantity,
+                    delAgoTotalPrice = storageInfo.TotalPrice;
+            int goodsId = storageInfo.GoodsId;
+
+            _sqlSugar.BeginTran();
+
+            var storageDel = await _sqlSugar.Updateable<Pm_GoodsStorage>()
+                                           .SetColumns(x => new Pm_GoodsStorage
+                                           {
+                                               DeleteUserId = userId,
+                                               DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
+                                               IsDel = 1
+                                           })
+                                           .Where(x => x.Id == id)
+                                           .ExecuteCommandAsync();
+            if (storageDel < 1)
+            {
+                _sqlSugar.RollbackTran();
+                _jv.Msg = $"操作失败!";
+                return _jv;
+            }
+
+            var goodsInfo = await _sqlSugar.Queryable<Pm_GoodsInfo>().FirstAsync(x => x.Id == goodsId);
+            goodsInfo.SQ_Total = goodsInfo.SQ_Total - delAgoQauntity;
+            goodsInfo.StockQuantity = goodsInfo.StockQuantity - delAgoQauntity;
+            goodsInfo.PriceTotal = goodsInfo.PriceTotal - delAgoTotalPrice;
+            goodsInfo.LastUpdateUserId = userId;
+            goodsInfo.LastUpdateTime = DateTime.Now;
+
+            var goodsEdit = await _sqlSugar.Updateable(goodsInfo)
+                                           .UpdateColumns(x => new
+                                           {
+                                               x.SQ_Total,
+                                               x.StockQuantity,
+                                               x.PriceTotal,
+                                               x.LastUpdateUserId,
+                                               x.LastUpdateTime,
+                                           })
+                                           .Where(x => x.Id == goodsId)
+                                           .ExecuteCommandAsync();
+            if (goodsEdit > 0)
+            {
+                _sqlSugar.CommitTran();
+                _jv.Msg = $"操作成功!";
+                _jv.Code = StatusCodes.Status200OK;
+                return _jv;
+            }
+
+            _sqlSugar.RollbackTran();
+            _jv.Msg = $"操作失败!";
             return _jv;
         }
 
@@ -326,30 +500,30 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
             var data = await _sqlSugar.Queryable<Pm_GoodsReceive>()
                                       .LeftJoin<Pm_GoodsInfo>((gr, gi) => gr.GoodsId == gi.Id)
                                       .LeftJoin<Sys_Users>((gr, gi, u1) => gr.AuditUserId == u1.Id)
-                                      .LeftJoin<Sys_Users>((gr, gi, u1,u2) => gr.CreateUserId == u2.Id)
+                                      .LeftJoin<Sys_Users>((gr, gi, u1, u2) => gr.CreateUserId == u2.Id)
                                       .Where((gr, gi, u1, u2) => gr.IsDel == 0)
-                                      .WhereIF(_dto.GoodsId > 0, (gr, gi, u1, u2u) => gr.GoodsId == _dto.GoodsId)
-                                      .Select((gr, gi, u1, u2) => new
+                                      .WhereIF(_dto.GoodsId > 0, (gr, gi, u1, u2) => gr.GoodsId == _dto.GoodsId)
+                                      .WhereIF(_dto.GoodsId > 0, (gr, gi, u1, u2) => gr.CreateUserId == _dto.CurrUserId)
+                                      .Select((gr, gi, u1, u2) => new GoodsReceiveListView
                                       {
-                                          gr.Id,
-                                          gr.GroupId,
-                                          gr.GoodsId,
+                                          Id = gr.Id,
+                                          GroupId = gr.GroupId,
+                                          GoodsId = gr.GoodsId,
                                           GoodsName = gi.Name,
-                                          gr.Quantity,
-                                          gr.Reason,
-                                          gr.Remark,
-                                          gr.AuditStatus,
-                                          AuditStatusText = gr.AuditStatus.GetDescription(),
-                                          gr.AuditUserId,
+                                          Quantity = gr.Quantity,
+                                          Reason = gr.Reason,
+                                          Remark = gr.Remark,
+                                          AuditStatus = gr.AuditStatus,
+                                          //AuditStatusText = gr.AuditStatus.GetEnumDescription(),
+                                          AuditUserId = gr.AuditUserId,
                                           AuditUserName = u1.CnName,
-                                          gr.AuditTime,
+                                          AuditTime = gr.AuditTime,
                                           CreateUserName = u2.CnName,
-                                          gr.CreateTime
+                                          CreateTime = gr.CreateTime
                                       })
-                                      .OrderByDescending(gs => gs.CreateTime)
+                                      .OrderByDescending(gr => gr.CreateTime)
                                       .ToPageListAsync(_dto.PageIndex, _dto.PageSize, total);
 
-
             _jv.Code = StatusCodes.Status200OK;
             _jv.Data = data;
             _jv.Count = total;
@@ -360,6 +534,7 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
         /// <summary>
         /// 物品领用详情
         /// </summary>
+        /// <param name="portType"></param>
         /// <param name="id"></param>
         /// <returns></returns>
         public async Task<JsonView> GoodsReceiveInfo(int portType, int id)
@@ -395,5 +570,188 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
             _jv.Msg = $"操作成功";
             return _jv;
         }
+
+        /// <summary>
+        /// 物品领用 OP(Add Or Edit)
+        /// </summary>
+        /// <param name="id"></param>
+        /// <returns></returns>
+        public async Task<JsonView> GoodsReceiveOP(GoodsReceiveOPDTO _dto)
+        {
+            var info = _mapper.Map<Pm_GoodsReceive>(_dto);
+            info.CreateUserId = _dto.CurrUserId;
+            _sqlSugar.BeginTran();
+
+            //物品现有库存
+            var stockQuantity = _sqlSugar.Queryable<Pm_GoodsInfo>()
+                                               .First(x => x.Id == info.GoodsId)
+                                               ?.StockQuantity;
+
+            //待审核 该物品数量
+            var waitAuditQuantity = await _sqlSugar.Queryable<Pm_GoodsReceive>()
+                                                   .Where(x => x.IsDel == 0 &&
+                                                               x.GoodsId == _dto.GoodsId &&
+                                                               x.AuditStatus == GoodsAuditEnum.Pending
+                                                         )
+                                                   .SumAsync(x => x.Quantity);
+            if (info.Id > 0) //修改
+            {
+                //审核验证
+                var selectInfo = await _sqlSugar.Queryable<Pm_GoodsReceive>().FirstAsync(x => x.Id == info.Id);
+                if (selectInfo.AuditStatus == GoodsAuditEnum.Approved)
+                {
+                    _sqlSugar.RollbackTran();
+                    _jv.Msg = $"该条数据已通过审核,不可更改!";
+                    return _jv;
+                }
+                //物品数量验证
+                decimal editAfterQuantity = waitAuditQuantity - selectInfo.Quantity + info.Quantity;
+                if (editAfterQuantity > stockQuantity)
+                {
+                    _sqlSugar.RollbackTran();
+                    _jv.Msg = $"该物品现有库存不足,不可更改!请联系采购人员购买!";
+                    return _jv;
+                }
+
+                var edit = await _sqlSugar.Updateable(info)
+                                          .UpdateColumns(x => new
+                                          {
+                                              x.GroupId,
+                                              x.Quantity,
+                                              x.Reason,
+                                              x.Remark,
+                                          })
+                                          .Where(x => x.Id == info.Id)
+                                          .ExecuteCommandAsync();
+                if (edit > 0)
+                {
+                    _sqlSugar.CommitTran();
+                    _jv.Msg = $"操作成功!";
+                    _jv.Code = StatusCodes.Status200OK;
+                    return _jv;
+                }
+            }
+            else if (info.Id < 1) //添加
+            {
+                //物品数量验证
+                decimal addAgoQuantity = waitAuditQuantity + info.Quantity;
+                if (addAgoQuantity > stockQuantity)
+                {
+                    _sqlSugar.RollbackTran();
+                    _jv.Msg = $"该物品现有库存不足,不可更改!请联系采购人员购买!";
+                    return _jv;
+                }
+
+                var add = await _sqlSugar.Insertable(info).ExecuteCommandAsync();
+                if (add > 0)
+                {
+                    _sqlSugar.CommitTran();
+                    _jv.Msg = $"操作成功!";
+                    _jv.Code = StatusCodes.Status200OK;
+                    return _jv;
+                }
+            }
+            _sqlSugar.RollbackTran();
+            return _jv;
+        }
+
+        /// <summary>
+        /// 物品领用 Audit
+        /// </summary>
+        /// <param name="idArray"></param>
+        /// <param name="userId"></param>
+        /// <param name="auditEnum"></param>
+        /// <returns></returns>
+        public async Task<JsonView> GoodsReceiveAudit(int[] idArray, int userId, GoodsAuditEnum auditEnum)
+        {
+            if (idArray.Length < 1) return _jv;
+
+            //TODO: 审核权限验证
+
+            _sqlSugar.BeginTran();
+            var receiveInfos = await _sqlSugar.Queryable<Pm_GoodsReceive>()
+                                              .Where(x => x.IsDel == 0 && idArray.Contains(x.Id))
+                                              .ToListAsync();
+
+            bool status = true;
+            foreach (var id in idArray)
+            {
+                var currInfo = receiveInfos.Find(x => x.Id == id);
+                var edit = await _sqlSugar.Updateable<Pm_GoodsReceive>()
+                                          .SetColumns(x => new Pm_GoodsReceive()
+                                          {
+                                              AuditStatus = auditEnum,
+                                              AuditUserId = userId,
+                                              AuditTime = DateTime.Now,
+                                          })
+                                          .Where(x => x.Id == id)
+                                          .ExecuteCommandAsync();
+                if (edit < 1) status = false;
+
+                var goodsInfo = await _sqlSugar.Queryable<Pm_GoodsInfo>().Where(x => x.Id == currInfo.GoodsId).FirstAsync();
+                goodsInfo.StockQuantity = goodsInfo.StockQuantity - currInfo.Quantity;
+                goodsInfo.LastUpdateTime = DateTime.Now;
+                goodsInfo.LastUpdateUserId = userId;
+
+                var editGoods = await _sqlSugar.Updateable<Pm_GoodsInfo>(goodsInfo)
+                                               .UpdateColumns(x => new
+                                               {
+                                                   x.StockQuantity,
+                                                   x.LastUpdateUserId,
+                                                   x.LastUpdateTime,
+                                               })
+                                               .Where(x => x.Id == id)
+                                               .ExecuteCommandAsync();
+                if (editGoods < 1) status = false;
+            }
+
+            if (status)
+            {
+                _sqlSugar.CommitTran();
+                _jv.Msg = $"操作成功!";
+                _jv.Code = StatusCodes.Status200OK;
+                return _jv;
+            }
+
+            _sqlSugar.RollbackTran();
+            return _jv;
+        }
+
+        /// <summary>
+        /// 物品领用 Del
+        /// </summary>
+        /// <param name="idArray"></param>
+        /// <param name="userId"></param>
+        /// <param name="auditEnum"></param>
+        /// <returns></returns>
+        public async Task<JsonView> GoodsReceiveDel(int id, int currUserId)
+        {
+            var receiveInfo = await _sqlSugar.Queryable<Pm_GoodsReceive>()
+                                             .Where(x => x.IsDel == 0 && x.Id == id)
+                                             .FirstAsync();
+            if (receiveInfo.AuditStatus == GoodsAuditEnum.Approved)
+            {
+                _jv.Msg = $"该条数据已通过审核,不可删除!";
+                return _jv;
+            }
+
+            var edit = await _sqlSugar.Updateable<Pm_GoodsReceive>()
+                                        .UpdateColumns(x => new Pm_GoodsReceive()
+                                        {
+                                            IsDel = 1,
+                                            DeleteUserId = currUserId,
+                                            DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
+                                        })
+                                        .Where(x => x.Id == id)
+                                        .ExecuteCommandAsync();
+            if (edit > 0)
+            {
+                _jv.Msg = $"操作成功!";
+                _jv.Code = StatusCodes.Status200OK;
+                return _jv;
+            }
+
+            return _jv;
+        }
     }
 }