设备入库领用

This commit is contained in:
qianjiawei
2023-11-29 11:44:01 +08:00
parent fc7bbf7496
commit ba7d9813b4
5 changed files with 132 additions and 3 deletions

View File

@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tnb.EquipMgr.Entities
{
public class EquipSparePartRecordInput
{
public string? equip_id { get; set; }
}
public class EquipSparePartRecordOut
{
public string? id { get; set; }
public string? code { get; set; }
public string? name { get; set; }
public string? type { get; set; }
public string? execuser { get; set; }
public string? execdatetime { get; set; }
public int? num { get; set; }
}
}

View File

@@ -8,6 +8,7 @@ namespace Tnb.EquipMgr.Entities.Dto
public string? code { get; set; }
public string? name { get; set; }
public string? specification { get; set; }
public int? num { get; set; }
}
}

View File

@@ -1,11 +1,14 @@
using System.CodeDom.Compiler;
using JNPF.Common.Core.Manager;
using JNPF.Common.Filter;
using JNPF.Common.Security;
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.Systems.Entitys.Permission;
using JNPF.Systems.Entitys.System;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using NPOI.SS.Formula.Functions;
using SqlSugar;
using Tnb.EquipMgr.Entities;
using Tnb.EquipMgr.Entities.Dto;
@@ -68,6 +71,9 @@ namespace Tnb.EquipMgr
{
queryJson = JsonConvert.DeserializeObject<Dictionary<string, string>>(input.queryJson);
}
var eqpSpareParts = await db.Queryable<EqpSpareParts>().ToListAsync();
var InstockDs= await db.Queryable<EqpSparePartsInstockD>().ToListAsync();
var RequisitionDs = await db.Queryable<EqpSparePartsRequisitionD>().ToListAsync();
SqlSugarPagedList<EquipSparePartsQueryOutput> result = await db.Queryable<EqpEquipSpareParts>()
.LeftJoin<EqpSpareParts>((a, b) => a.spare_parts_id == b.id)
.LeftJoin<DictionaryTypeEntity>((a, b, c) => c.EnCode == Tnb.BasicData.DictConst.SparePartsType && c.DeleteMark == null)
@@ -82,10 +88,68 @@ namespace Tnb.EquipMgr
type_name = d.FullName,
code = b.code,
name = b.name,
specification = b.specification
specification = b.specification,
num = 0
}).ToPagedListAsync(input.currentPage, input.pageSize);
foreach (var item in result.list)
{
try
{
var part = eqpSpareParts.Where(p => p.code == item.code).First();
var Instocknum = InstockDs.Where(p => p.spare_parts_id == part.id).Sum(p => p.quantity);
var Requisitionum = RequisitionDs.Where(p => p.spare_parts_id == part.id).Sum(p => p.quantity);
item.num = Instocknum > Requisitionum ? Instocknum - Requisitionum : 0;
}
catch (Exception)
{
}
}
return PageResult<EquipSparePartsQueryOutput>.SqlSugarPageResult(result);
}
//获取备品备件历史
[HttpPost]
public async Task<dynamic> GetEquipSparePartRecord(EquipSparePartRecordInput input)
{
ISqlSugarClient db = _repository.AsSugarClient();
var partsids = await db.Queryable<EqpEquipSpareParts>().Where(p => p.equip_id == input.equip_id).Select(p => p.spare_parts_id).ToListAsync();
var Instocks = await db.Queryable<EqpSparePartsInstockD>()
.LeftJoin<EqpSparePartsInstockH>((a, b) => a.instock_id == b.id)
.LeftJoin<EqpSpareParts>((a, b, c) => a.spare_parts_id == c.id)
.LeftJoin<UserEntity>((a, b, c, d) => b.instock_id == d.Id)
.Where((a, b, c, d) => partsids.Contains(a.spare_parts_id!))
.Select((a, b, c, d) => new EquipSparePartRecordOut()
{
id = a.id,
code = c.code,
name = c.name,
type = "入库",
execuser = d.RealName,
execdatetime = b.create_time != null ? b.create_time.ToString() : "",
num = a.quantity
})
.ToListAsync();
var Requisitions = await db.Queryable<EqpSparePartsRequisitionD>()
.LeftJoin<EqpSparePartsRequisitionH>((a, b) => a.spare_parts_requisition_id == b.id)
.LeftJoin<EqpSpareParts>((a, b, c) => a.spare_parts_id == c.id)
.LeftJoin<UserEntity>((a, b, c, d) => b.recipient_id == d.Id)
.Where((a, b, c, d) => partsids.Contains(a.spare_parts_id!))
.Select((a, b, c, d) => new EquipSparePartRecordOut()
{
id = a.id,
code = c.code,
name = c.name,
type = "领用",
execuser = d.RealName,
execdatetime = b.create_time != null ? b.create_time.ToString()!.Substring(0,19) : "",
num = a.quantity
})
.ToListAsync();
Instocks.AddRange(Requisitions);
var result = Instocks.OrderByDescending(p => DateTime.Parse(p.execdatetime!));
return result;
}
}
}