123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- 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;
- 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();
- _jv.Code = StatusCodes.Status200OK;
- _jv.Data = typeData;
- _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>
- /// 物品入库列表
- /// </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="_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, u2u) => gr.GoodsId == _dto.GoodsId)
- .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
- })
- .OrderByDescending(gs => gs.CreateTime)
- .ToPageListAsync(_dto.PageIndex, _dto.PageSize, total);
- _jv.Code = StatusCodes.Status200OK;
- _jv.Data = data;
- _jv.Count = total;
- _jv.Msg = $"操作成功";
- return _jv;
- }
- }
- }
|