ERP 调试

This commit is contained in:
qianhao.xu 2024-08-30 09:00:10 +08:00
parent c81351b8f5
commit 87f592b500
4 changed files with 196 additions and 195 deletions

View File

@ -43,7 +43,7 @@ namespace DOAN.Model.MES.base_
public string ADDCode { get; set; }
/// <summary>
/// 客户编码
/// 客户编码 customer_ code
/// </summary>
[SugarColumn(ColumnName = "customer_code")]

View File

@ -20,7 +20,7 @@ namespace DOAN.Service.MES.ERP
/// <summary>
/// 工位Service业务层处理
/// </summary>
[AppService(ServiceType = typeof(IBaseWorkStationService), ServiceLifetime = LifeTime.Transient)]
[AppService(ServiceType = typeof(IInteractERPService), ServiceLifetime = LifeTime.Transient)]
public class InteractERPService : BaseService<CustDevMesCustomer>, IInteractERPService
{

View File

@ -23,219 +23,220 @@ namespace DOAN.Service.MES.base_
/// <summary>
/// 物料清单Service业务层处理
/// </summary>
[AppService(ServiceType = typeof(IBaseMaterialBOMService), ServiceLifetime = LifeTime.Transient)]
public class BaseMaterialBOMService : BaseService<BaseMaterialList>, IBaseMaterialBOMService
{
/// <summary>
/// 查询物料清单列表
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
public PagedInfo<BaseMaterialListDto> GetList(BaseMaterialListQueryDto2 parm)
{
int[] nodes = null;
//[AppService(ServiceType = typeof(IBaseMaterialBOMService), ServiceLifetime = LifeTime.Transient)]
//public class BaseMaterialBOMService : BaseService<BaseMaterialList>, IBaseMaterialBOMService
//{
// /// <summary>
// /// 查询物料清单列表
// /// </summary>
// /// <param name="parm"></param>
// /// <returns></returns>
// public PagedInfo<BaseMaterialListDto> GetList(BaseMaterialListQueryDto2 parm)
// {
// int[] nodes = null;
if (parm.Type == 1)
{
nodes = FindLeafNodes(Context.Queryable<BaseMaterialType>().ToList(), 6).Select(it => it.Id).ToArray();
}
else if (parm.Type == 2)
{
// if (parm.Type == 1)
// {
// nodes = FindLeafNodes(Context.Queryable<BaseMaterialType>().ToList(), 6).Select(it => it.Id).ToArray();
// }
// else if (parm.Type == 2)
// {
nodes = FindLeafNodes(Context.Queryable<BaseMaterialType>().ToList(), 5).Select(it => it.Id).ToArray();
// nodes = FindLeafNodes(Context.Queryable<BaseMaterialType>().ToList(), 5).Select(it => it.Id).ToArray();
}
var predicate = Expressionable.Create<BaseMaterialList>();
// }
// var predicate = Expressionable.Create<BaseMaterialList>();
var response = Queryable()
.Where(it => nodes.Contains(it.FkTypeId.Value))
.Where(predicate.ToExpression())
.ToPage<BaseMaterialList, BaseMaterialListDto>(parm);
// var response = Queryable()
// .Where(it => nodes.Contains(it.FkTypeId.Value))
// .Where(predicate.ToExpression())
// .ToPage<BaseMaterialList, BaseMaterialListDto>(parm);
return response;
}
// return response;
// }
/// <summary>
/// 获取详情
/// </summary>
/// <param name="Id"></param>
/// <returns></returns>
public BaseMaterialList GetInfo(string Id)
{
var response = Queryable()
.Where(x => x.Id == Id)
.First();
// /// <summary>
// /// 获取详情
// /// </summary>
// /// <param name="Id"></param>
// /// <returns></returns>
// public BaseMaterialList GetInfo(string Id)
// {
// var response = Queryable()
// .Where(x => x.Id == Id)
// .First();
return response;
}
// return response;
// }
/// <summary>
/// 添加物料清单
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public BaseMaterialList AddBaseMaterialList(BaseMaterialList model)
{
return Context.Insertable(model).ExecuteReturnEntity();
}
// /// <summary>
// /// 添加物料清单
// /// </summary>
// /// <param name="model"></param>
// /// <returns></returns>
// public BaseMaterialList AddBaseMaterialList(BaseMaterialList model)
// {
// return Context.Insertable(model).ExecuteReturnEntity();
// }
/// <summary>
/// 修改物料清单
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public int UpdateBaseMaterialList(BaseMaterialList model)
{
//var response = Update(w => w.Id == model.Id, it => new BaseMaterialList()
//{
// Name = model.Name,
// Code = model.Code,
// Customer code = model.Customer code,
// Color = model.Color,
// Specification = model.Specification,
// Unit = model.Unit,
// Description = model.Description,
// ExpirationUnit = model.ExpirationUnit,
// ExpirationDate = model.ExpirationDate,
// ShelfLifeWarningDays = model.ShelfLifeWarningDays,
// IsShelfLife = model.IsShelfLife,
// StartTime = model.StartTime,
// StopTime = model.StopTime,
// BarCode = model.BarCode,
// IsBatch = model.IsBatch,
// CreatedBy = model.CreatedBy,
// CreatedTime = model.CreatedTime,
// UpdatedBy = model.UpdatedBy,
// UpdatedTime = model.UpdatedTime,
//});
//return response;
return Update(model, true);
}
// /// <summary>
// /// 修改物料清单
// /// </summary>
// /// <param name="model"></param>
// /// <returns></returns>
// public int UpdateBaseMaterialList(BaseMaterialList model)
// {
// //var response = Update(w => w.Id == model.Id, it => new BaseMaterialList()
// //{
// // Name = model.Name,
// // Code = model.Code,
// // Customer code = model.Customer code,
// // Color = model.Color,
// // Specification = model.Specification,
// // Unit = model.Unit,
// // Description = model.Description,
// // ExpirationUnit = model.ExpirationUnit,
// // ExpirationDate = model.ExpirationDate,
// // ShelfLifeWarningDays = model.ShelfLifeWarningDays,
// // IsShelfLife = model.IsShelfLife,
// // StartTime = model.StartTime,
// // StopTime = model.StopTime,
// // BarCode = model.BarCode,
// // IsBatch = model.IsBatch,
// // CreatedBy = model.CreatedBy,
// // CreatedTime = model.CreatedTime,
// // UpdatedBy = model.UpdatedBy,
// // UpdatedTime = model.UpdatedTime,
// //});
// //return response;
// return Update(model, true);
// }
/// <summary>
/// 获取bom结构
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public List<BaseMaterialListDto2> Achieve_BOM(string id)
{
var query1 = Context.Queryable<BaseMaterialBom>().Where(it => it.FkParentId == id);
return Context.Queryable(query1).LeftJoin<BaseMaterialList>((q, m) => q.FkId == m.Id)
.InnerJoin<BaseMaterialType>((q, m,t)=>m.FkTypeId==t.Id)
.Select((q, m,t) => new BaseMaterialListDto2() {
Type_Name = t.Name,
Type_Code = t.Code,
},true)
.ToList()
.Adapt<List<BaseMaterialListDto2>>()
;
// /// <summary>
// /// 获取bom结构
// /// </summary>
// /// <param name="id"></param>
// /// <returns></returns>
// public List<BaseMaterialListDto2> Achieve_BOM(string id)
// {
// var query1 = Context.Queryable<BaseMaterialBom>().Where(it => it.FkParentId == id);
// return Context.Queryable(query1).LeftJoin<BaseMaterialList>((q, m) => q.FkId == m.Id)
// .InnerJoin<BaseMaterialType>((q, m, t) => m.FkTypeId == t.Id)
// .Select((q, m, t) => new BaseMaterialListDto2()
// {
// Type_Name = t.Name,
// Type_Code = t.Code,
// }, true)
// .ToList()
// .Adapt<List<BaseMaterialListDto2>>()
// ;
}
// }
/// <summary>
/// 删除绑定关系
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public int DeleteBOMBind(string id, string parent_id)
{
return Context.Deleteable<BaseMaterialBom>().Where(it => it.FkId == id)
.Where(it => it.FkParentId == parent_id)
.ExecuteCommand();
}
/// <summary>
/// 增加绑定关系
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public int ADDBOMBind(string id, string parent_id)
{
BaseMaterialBom bom = new BaseMaterialBom();
bom.FkId = id;
bom.FkParentId = parent_id;
bom.CreatedTime = DateTime.Now;
return Context.Insertable(bom).ExecuteCommand();
}
// /// <summary>
// /// 删除绑定关系
// /// </summary>
// /// <param name="id"></param>
// /// <returns></returns>
// public int DeleteBOMBind(string id, string parent_id)
// {
// return Context.Deleteable<BaseMaterialBom>().Where(it => it.FkId == id)
// .Where(it => it.FkParentId == parent_id)
// .ExecuteCommand();
// }
// /// <summary>
// /// 增加绑定关系
// /// </summary>
// /// <param name="id"></param>
// /// <returns></returns>
// public int ADDBOMBind(string id, string parent_id)
// {
// BaseMaterialBom bom = new BaseMaterialBom();
// bom.FkId = id;
// bom.FkParentId = parent_id;
// bom.CreatedTime = DateTime.Now;
// return Context.Insertable(bom).ExecuteCommand();
// }
/// <summary>
/// 获取未绑定的BOM结构
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public PagedInfo<BaseMaterialListDto2> Achieve_BOM_no_bind(BaseMaterialListQueryDto3 query)
{
// 成品id 的Bom结构
string[] binded_array = Context.Queryable<BaseMaterialBom>().Where(it => it.FkParentId == query.Id).Select(it => it.FkId).ToArray();
//在原材料和半成品中 选择
List<BaseMaterialType> typeList = Context.Queryable<BaseMaterialType>().ToList();
int[] leaf = FindLeafNodes(typeList, 1).Select(it => it.Id).ToArray();
int[] leaf2 = FindLeafNodes(typeList, 5).Select(it => it.Id).ToArray();
int[] leaf3 = leaf.Concat(leaf2).ToArray();
var predicate = Expressionable.Create<BaseMaterialList>()
.AndIF(!string.IsNullOrEmpty(query.Name), it => it.Name.Contains(query.Name))
.AndIF(!string.IsNullOrEmpty(query.Code), it => it.Name.Contains(query.Code))
.AndIF(!string.IsNullOrEmpty(query.CustomerCode), it => it.Name.Contains(query.CustomerCode))
;
// /// <summary>
// /// 获取未绑定的BOM结构
// /// </summary>
// /// <param name="id"></param>
// /// <returns></returns>
// public PagedInfo<BaseMaterialListDto2> Achieve_BOM_no_bind(BaseMaterialListQueryDto3 query)
// {
// // 成品id 的Bom结构
// string[] binded_array = Context.Queryable<BaseMaterialBom>().Where(it => it.FkParentId == query.Id).Select(it => it.FkId).ToArray();
var qua = Context.Queryable<BaseMaterialList>().Where(it => !binded_array.Contains(it.Id))
.Where(predicate.ToExpression())
.Where(it => leaf3.Contains(it.FkTypeId.Value));
return Context.Queryable(qua).InnerJoin<BaseMaterialType>((q, t) => q.FkTypeId == t.Id)
.Select((q, t) => new BaseMaterialListDto2()
{
Type_Name = t.Name,
Type_Code = t.Code,
}, true).ToPage<BaseMaterialListDto2, BaseMaterialListDto2>(query);
// //在原材料和半成品中 选择
// List<BaseMaterialType> typeList = Context.Queryable<BaseMaterialType>().ToList();
// int[] leaf = FindLeafNodes(typeList, 1).Select(it => it.Id).ToArray();
// int[] leaf2 = FindLeafNodes(typeList, 5).Select(it => it.Id).ToArray();
// int[] leaf3 = leaf.Concat(leaf2).ToArray();
// var predicate = Expressionable.Create<BaseMaterialList>()
// .AndIF(!string.IsNullOrEmpty(query.Name), it => it.Name.Contains(query.Name))
// .AndIF(!string.IsNullOrEmpty(query.Code), it => it.Name.Contains(query.Code))
// .AndIF(!string.IsNullOrEmpty(query.CustomerCode), it => it.Name.Contains(query.CustomerCode))
// ;
// var qua = Context.Queryable<BaseMaterialList>().Where(it => !binded_array.Contains(it.Id))
// .Where(predicate.ToExpression())
// .Where(it => leaf3.Contains(it.FkTypeId.Value));
// return Context.Queryable(qua).InnerJoin<BaseMaterialType>((q, t) => q.FkTypeId == t.Id)
// .Select((q, t) => new BaseMaterialListDto2()
// {
// Type_Name = t.Name,
// Type_Code = t.Code,
// }, true).ToPage<BaseMaterialListDto2, BaseMaterialListDto2>(query);
}
// }
public static List<BaseMaterialType> FindLeafNodes( List<BaseMaterialType> nodes,int ancestorId)
{
List<BaseMaterialType> leafNodes = new List<BaseMaterialType>();
// public static List<BaseMaterialType> FindLeafNodes(List<BaseMaterialType> nodes, int ancestorId)
// {
// List<BaseMaterialType> leafNodes = new List<BaseMaterialType>();
void FindLeaves(int currentId)
{
// 查找当前ID的直接子节点
var children = nodes.Where(n => n.ParentId == currentId).ToList();
// void FindLeaves(int currentId)
// {
// // 查找当前ID的直接子节点
// var children = nodes.Where(n => n.ParentId == currentId).ToList();
// 如果没有子节点,说明是叶子节点
if (!children.Any())
{
leafNodes.Add(nodes.FirstOrDefault(n => n.Id == currentId));
}
else
{
// 对每个子节点递归调用FindLeaves
foreach (var child in children)
{
FindLeaves(child.Id);
}
}
}
// // 如果没有子节点,说明是叶子节点
// if (!children.Any())
// {
// leafNodes.Add(nodes.FirstOrDefault(n => n.Id == currentId));
// }
// else
// {
// // 对每个子节点递归调用FindLeaves
// foreach (var child in children)
// {
// FindLeaves(child.Id);
// }
// }
// }
// 从指定的祖先节点开始查找
FindLeaves(ancestorId);
// // 从指定的祖先节点开始查找
// FindLeaves(ancestorId);
return leafNodes;
}
// return leafNodes;
// }
/// <summary>
/// bom视图
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public BaseParseNode ShowBOMView(string id)
{
//TODO 获取成品id的一级子集 bom
// /// <summary>
// /// bom视图
// /// </summary>
// /// <param name="id"></param>
// /// <returns></returns>
// public BaseParseNode ShowBOMView(string id)
// {
// //TODO 获取成品id的一级子集 bom
return null;
}
// return null;
// }
}
//}
}

View File

@ -28,23 +28,23 @@ namespace DOAN.Service.MES.base_
/// <returns></returns>
public PagedInfo<BaseMaterialListDto2> GetList(BaseMaterialListQueryDto parm)
{
var predicate = Expressionable.Create<BaseMaterialList>()
.AndIF(!string.IsNullOrEmpty(parm.Name), it => it.Name == parm.Name)
.AndIF(!string.IsNullOrEmpty(parm.Code), it => it.Code == parm.Code)
.AndIF(!string.IsNullOrEmpty(parm.CustomerCode), it => it.CustomerCode == parm.CustomerCode)
.AndIF(!string.IsNullOrEmpty(parm.Description), it => it.Description == parm.Description)
.AndIF(parm.FkTypeId >= 0, it => it.FkTypeId == parm.FkTypeId)
.AndIF(!string.IsNullOrEmpty(parm.FkMaterialTypeCode) , it => it.FkMaterialTypeCode == parm.FkMaterialTypeCode)
.AndIF(parm.TimeRange != null && parm.TimeRange.Length == 2 && parm.TimeRange[0] > DateTime.MinValue, it => it.CreatedTime >= parm.TimeRange[0])
.AndIF(parm.TimeRange != null && parm.TimeRange.Length == 2 && parm.TimeRange[1] > DateTime.MinValue, it => it.CreatedTime <= parm.TimeRange[1]);
var query01 = Queryable()
.Where(predicate.ToExpression());
var response = Context.Queryable(query01).LeftJoin<BaseMaterialType>((q, t) => q.FkTypeId == t.Id)
var response = Context.Queryable(query01).LeftJoin<BaseMaterialType>((q, t) => q.FkMaterialTypeCode == t.Code)
.LeftJoin<BaseSupplier>((q, t, s) => q.FkSupplierId == s.Id)
.Select((q, t, s) => new BaseMaterialListDto2
{