123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757 |
- using OASystem.Domain.Entities.PersonnelModule;
- using OASystem.Domain.ViewModels.PersonnelModule;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- 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
- {
- /// <summary>
- /// 物品进销存
- /// 仓储
- /// </summary>
- public class GoodsRepository : BaseRepository<Pm_GoodsInfo, GoodsInfoView>
- {
- private readonly IMapper _mapper;
- private JsonView _jv;
- public GoodsRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
- {
- _mapper = mapper;
- _jv = new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "操作失败!" };
- }
- /// <summary>
- /// 基础数据
- /// </summary>
- /// <returns></returns>
- public async Task<JsonView> InitDataSource()
- {
- var typeData = await _sqlSugar.Queryable<GoodsTypeView>()
- .Includes(x => x.SubTypeItems.Where(z => z.IsDel == 0)
- //.Select(z => new {
- // z.Id,
- // z.STid,
- // z.Name
- //})
- .ToList())
- .Where(x => x.IsDel == 0 &&
- x.Remark.Equals("GoodsType"))
- //.Select(x => new {
- // x.Id,
- // x.Name,
- // x.SubTypeItems
- //})
- .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 = new { goodsTypeData = typeData, groupNameData = groupData };
- _jv.Msg = $"操作成功";
- return _jv;
- }
- /// <summary>
- /// 物品列表
- /// </summary>
- /// <param name="_dto"></param>
- /// <returns></returns>
- public async Task<JsonView> GoodsList(GoodsListDTO _dto)
- {
- var ids = new List<int>();
- if (!string.IsNullOrEmpty(_dto.TypeIds))
- {
- var strArray = _dto.TypeIds.Split(',');
- foreach (var str in strArray)
- {
- if (int.TryParse(str, out int id))
- {
- ids.Add(id);
- }
- }
- }
- RefAsync<int> total = 0;
- var data = await _sqlSugar.Queryable<Pm_GoodsInfo>()
- .LeftJoin<Sys_SetData>((gi, sd) => gi.Type == sd.Id)
- .LeftJoin<Sys_Users>((gi, sd, u) => gi.LastUpdateUserId == u.Id)
- .Where((gi, sd, u) => gi.IsDel == 0)
- .WhereIF(ids.Count > 0, (gi, sd, u) => ids.Contains(gi.Type))
- .WhereIF(!string.IsNullOrEmpty(_dto.GoodsName), (gi, sd, u) => gi.Name.Contains(_dto.GoodsName))
- .Select((gi, sd, u) => new
- {
- gi.Id,
- gi.Name,
- gi.Type,
- TypeName = sd.Name,
- gi.StockQuantity,
- LastUpdateUserName = u.CnName,
- gi.LastUpdateTime,
- gi.Remark,
- })
- .OrderByDescending(gi => gi.LastUpdateTime)
- .ToPageListAsync(_dto.PageIndex, _dto.PageSize, total);
- _jv.Code = StatusCodes.Status200OK;
- _jv.Data = data;
- _jv.Count = total;
- _jv.Msg = $"操作成功";
- return _jv;
- }
- /// <summary>
- /// 物品Info
- /// </summary>
- /// <param name="_dto"></param>
- /// <returns></returns>
- 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)
- .Where((gi, sd, u1, u2) => gi.IsDel == 0 && gi.Id == id)
- .Select((gi, sd, u1, u2) => new
- {
- gi.Id,
- gi.Name,
- gi.Type,
- TypeName = sd.Name,
- gi.SQ_Total,
- gi.OQ_Total,
- gi.PriceTotal,
- gi.StockQuantity,
- gi.Remark,
- LastUpdateUserName = u1.CnName,
- gi.LastUpdateTime,
- CreateUserName = u2.CnName,
- gi.CreateTime,
- })
- .FirstAsync();
- _jv.Code = StatusCodes.Status200OK;
- _jv.Data = data;
- _jv.Msg = $"操作成功";
- return _jv;
- }
- /// <summary>
- /// 物品 OP(Create Or Edit)
- /// </summary>
- /// <param name="_dto"></param>
- /// <returns></returns>
- public async Task<JsonView> GoodsOP(GoodsOPDTO _dto)
- {
- var info = new Pm_GoodsInfo()
- {
- Id = _dto.Id,
- Name = _dto.Name,
- Type = _dto.Type,
- SQ_Total = 0,
- OQ_Total = 0,
- PriceTotal = 0,
- StockQuantity = 0,
- Remark = _dto.Remark,
- LastUpdateUserId = _dto.CurrUserId,
- LastUpdateTime = DateTime.Now,
- CreateUserId = _dto.CurrUserId
- };
- if (_dto.Id > 0) //Edit
- {
- var upd = await _sqlSugar.Updateable(info)
- .UpdateColumns(x => new
- {
- x.Name,
- x.Type,
- x.Remark,
- x.LastUpdateUserId,
- x.LastUpdateTime,
- })
- .ExecuteCommandAsync();
- if (upd > 0)
- {
- _jv.Msg = $"修改成功!";
- _jv.Code = StatusCodes.Status200OK;
- return _jv;
- }
- }
- else if (_dto.Id < 1) //添加
- {
- var selectInfo = await _sqlSugar.Queryable<Pm_GoodsInfo>().FirstAsync(x => x.Name.Equals(info.Name));
- if (selectInfo != null)
- {
- _jv.Msg = $"“{info.Name}”该物品已存在,请勿重新添加!";
- return _jv;
- }
- var add = await _sqlSugar.Insertable(info).ExecuteCommandAsync();
- if (add > 0)
- {
- _jv.Msg = $"添加成功!";
- _jv.Code = StatusCodes.Status200OK;
- return _jv;
- }
- }
- 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>
- /// 物品入库列表
- /// </summary>
- /// <param name="_dto"></param>
- /// <returns></returns>
- public async Task<JsonView> GoodsStorageList(GoodsStorageListDTO _dto)
- {
- RefAsync<int> total = 0;
- 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(_dto.GoodsId > 0, (gs, gi, u) => gs.GoodsId == _dto.GoodsId)
- .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,
- })
- .OrderByDescending(gs => gs.CreateTime)
- .ToPageListAsync(_dto.PageIndex, _dto.PageSize, total);
- _jv.Code = StatusCodes.Status200OK;
- _jv.Data = data;
- _jv.Count = total;
- _jv.Msg = $"操作成功";
- return _jv;
- }
- /// <summary>
- /// 物品入库详情
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public async Task<JsonView> GoodsStorageInfo(int portType, int id)
- {
- 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();
- _jv.Msg = $"操作成功!";
- _jv.Code = StatusCodes.Status200OK;
- _jv.Data = data;
- return _jv;
- }
- /// <summary>
- /// 物品入库 操作(Create Or Edit)
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public async Task<JsonView> GoodsStorageOP(GoodsStorageOPDTO _dto)
- {
- var info = _mapper.Map<Pm_GoodsStorage>(_dto);
- info.CreateUserId = _dto.CurrUserId;
- 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(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;
- }
- /// <summary>
- /// 物品领用列表
- /// </summary>
- /// <param name="_dto"></param>
- /// <returns></returns>
- public async Task<JsonView> GoodsReceiveList(GoodsReceiveListDTO _dto)
- {
- RefAsync<int> total = 0;
- 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)
- .Where((gr, gi, u1, u2) => gr.IsDel == 0)
- .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
- {
- Id = gr.Id,
- GroupId = gr.GroupId,
- GoodsId = gr.GoodsId,
- GoodsName = gi.Name,
- Quantity = gr.Quantity,
- Reason = gr.Reason,
- Remark = gr.Remark,
- AuditStatus = gr.AuditStatus,
- //AuditStatusText = gr.AuditStatus.GetEnumDescription(),
- AuditUserId = gr.AuditUserId,
- AuditUserName = u1.CnName,
- AuditTime = gr.AuditTime,
- CreateUserName = u2.CnName,
- CreateTime = gr.CreateTime
- })
- .OrderByDescending(gr => gr.CreateTime)
- .ToPageListAsync(_dto.PageIndex, _dto.PageSize, total);
- _jv.Code = StatusCodes.Status200OK;
- _jv.Data = data;
- _jv.Count = total;
- _jv.Msg = $"操作成功";
- return _jv;
- }
- /// <summary>
- /// 物品领用详情
- /// </summary>
- /// <param name="portType"></param>
- /// <param name="id"></param>
- /// <returns></returns>
- public async Task<JsonView> GoodsReceiveInfo(int portType, int id)
- {
- 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)
- .Where((gr, gi, u1, u2) => gr.IsDel == 0)
- .WhereIF(id > 0, (gr, gi, u1, u2u) => gr.GoodsId == id)
- .Select((gr, gi, u1, u2) => new
- {
- gr.Id,
- gr.GroupId,
- gr.GoodsId,
- GoodsName = gi.Name,
- gr.Quantity,
- gr.Reason,
- gr.Remark,
- gr.AuditStatus,
- AuditStatusText = gr.AuditStatus.GetDescription(),
- gr.AuditUserId,
- AuditUserName = u1.CnName,
- gr.AuditTime,
- CreateUserName = u2.CnName,
- gr.CreateTime
- })
- .FirstAsync();
- _jv.Code = StatusCodes.Status200OK;
- _jv.Data = data;
- _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;
- }
- }
- }
|